diff --git a/mash/browser/BUILD.gn b/mash/browser/BUILD.gn index d6fdaa7b42f6f7..5206b3168444bc 100644 --- a/mash/browser/BUILD.gn +++ b/mash/browser/BUILD.gn @@ -23,6 +23,7 @@ source_set("lib") { "//mash/public/interfaces", "//mojo/public/cpp/bindings", "//services/catalog/public/interfaces", + "//services/navigation/public/cpp", "//services/navigation/public/interfaces", "//services/shell/public/cpp", "//services/shell/public/interfaces", diff --git a/mash/browser/browser.cc b/mash/browser/browser.cc index c746ef0e5a76a0..20804996eeca7f 100644 --- a/mash/browser/browser.cc +++ b/mash/browser/browser.cc @@ -18,6 +18,9 @@ #include "mash/browser/debug_view.h" #include "mash/public/interfaces/launchable.mojom.h" #include "mojo/public/c/system/main.h" +#include "services/navigation/public/cpp/view.h" +#include "services/navigation/public/cpp/view_delegate.h" +#include "services/navigation/public/cpp/view_observer.h" #include "services/navigation/public/interfaces/view.mojom.h" #include "services/shell/public/cpp/application_runner.h" #include "services/shell/public/cpp/connector.h" @@ -55,18 +58,8 @@ class NavMenuModel : public ui::MenuModel { virtual void NavigateToOffset(int offset) = 0; }; - struct Entry { - Entry(const base::string16& title, int offset) - : title(title), offset(offset) {} - ~Entry() {} - - // Title of the entry in the menu. - base::string16 title; - // Offset from the currently visible page to navigate to this item. - int offset; - }; - - NavMenuModel(const std::vector& entries, Delegate* delegate) + NavMenuModel(const std::vector& entries, + Delegate* delegate) : navigation_delegate_(delegate), entries_(entries) {} ~NavMenuModel() override {} @@ -123,7 +116,7 @@ class NavMenuModel : public ui::MenuModel { ui::MenuModelDelegate* delegate_ = nullptr; Delegate* navigation_delegate_; - std::vector entries_; + std::vector entries_; DISALLOW_COPY_AND_ASSIGN(NavMenuModel); }; @@ -289,32 +282,32 @@ class Throbber : public views::View { class UI : public views::WidgetDelegateView, public views::ButtonListener, public views::TextfieldController, - public navigation::mojom::ViewClient, + public navigation::ViewDelegate, + public navigation::ViewObserver, public NavButton::ModelProvider, public NavMenuModel::Delegate { public: enum class Type { WINDOW, POPUP }; - UI(Browser* browser, - Type type, - navigation::mojom::ViewPtr view, - navigation::mojom::ViewClientRequest request) + UI(Browser* browser, Type type, std::unique_ptr view) : browser_(browser), type_(type), - back_button_(new NavButton(NavButton::Type::BACK, this, this, + back_button_(new NavButton(NavButton::Type::BACK, + this, + this, base::ASCIIToUTF16("Back"))), - forward_button_(new NavButton(NavButton::Type::FORWARD, this, this, + forward_button_(new NavButton(NavButton::Type::FORWARD, + this, + this, base::ASCIIToUTF16("Forward"))), reload_button_( new views::LabelButton(this, base::ASCIIToUTF16("Reload"))), prompt_(new views::Textfield), - debug_button_( - new views::LabelButton(this, base::ASCIIToUTF16("DV"))), + debug_button_(new views::LabelButton(this, base::ASCIIToUTF16("DV"))), throbber_(new Throbber), progress_bar_(new ProgressBar), debug_view_(new DebugView), - view_(std::move(view)), - view_client_binding_(this, std::move(request)) { + view_(std::move(view)) { set_background(views::Background::CreateStandardPanelBackground()); prompt_->set_controller(this); back_button_->set_request_focus_on_press(false); @@ -329,22 +322,28 @@ class UI : public views::WidgetDelegateView, AddChildView(progress_bar_); AddChildView(debug_view_); debug_view_->set_view(view_.get()); + view_->set_delegate(this); + view_->AddObserver(this); view_->SetResizerSize(gfx::Size(16, 16)); } - ~UI() override { browser_->RemoveWindow(GetWidget()); } + ~UI() override { + view_->RemoveObserver(this); + view_->set_delegate(nullptr); + browser_->RemoveWindow(GetWidget()); + } - void NavigateTo(const GURL& url) { view_->NavigateTo(url); } + void NavigateTo(const GURL& url) { view_->NavigateToURL(url); } private: // Overridden from views::WidgetDelegate: views::View* GetContentsView() override { return this; } base::string16 GetWindowTitle() const override { // TODO(beng): use resources. - if (current_title_.empty()) + if (view_->title().empty()) return base::ASCIIToUTF16("Browser"); base::string16 format = base::ASCIIToUTF16("%s - Browser"); base::ReplaceFirstSubstringAfterOffset(&format, 0, base::ASCIIToUTF16("%s"), - current_title_); + view_->title()); return format; } bool CanResize() const override { return true; } @@ -358,7 +357,7 @@ class UI : public views::WidgetDelegateView, } else if (sender == forward_button_) { view_->GoForward(); } else if (sender == reload_button_) { - if (is_loading_) + if (view_->is_loading()) view_->Stop(); else view_->Reload(false); @@ -433,10 +432,7 @@ class UI : public views::WidgetDelegateView, mus::Window* window = aura::GetMusWindow(GetWidget()->GetNativeWindow()); content_area_ = window->window_tree()->NewWindow(nullptr); window->AddChild(content_area_); - - mus::mojom::WindowTreeClientPtr client; - view_->GetWindowTreeClient(GetProxy(&client)); - content_area_->Embed(std::move(client)); + view_->EmbedInWindow(content_area_); } } @@ -445,7 +441,7 @@ class UI : public views::WidgetDelegateView, const ui::KeyEvent& key_event) override { switch (key_event.key_code()) { case ui::VKEY_RETURN: { - view_->NavigateTo(GURL(prompt_->text())); + view_->NavigateToURL(GURL(prompt_->text())); } break; default: break; @@ -453,103 +449,55 @@ class UI : public views::WidgetDelegateView, return false; } - // navigation::mojom::ViewClient: - void LoadingStateChanged(bool is_loading) override { - is_loading_ = is_loading; - if (is_loading_) { - reload_button_->SetText(base::ASCIIToUTF16("Stop")); - throbber_->Start(); - } else { - reload_button_->SetText(base::ASCIIToUTF16("Reload")); - throbber_->Stop(); - progress_bar_->SetProgress(0.f); - } - } - void NavigationStateChanged(const GURL& url, - const mojo::String& title, - bool can_go_back, - bool can_go_forward) override { - EnableButton(back_button_, can_go_back); - EnableButton(forward_button_, can_go_forward); - current_url_ = url; - prompt_->SetText(base::UTF8ToUTF16(current_url_.spec())); - current_title_ = base::UTF8ToUTF16(title.get()); - GetWidget()->UpdateWindowTitle(); - } - void LoadProgressChanged(double progress) override { - progress_bar_->SetProgress(progress); - } - void UpdateHoverURL(const GURL& url) override { - if (url.is_valid()) - prompt_->SetText(base::UTF8ToUTF16(url.spec())); - else - prompt_->SetText(base::UTF8ToUTF16(current_url_.spec())); - } - void ViewCreated(navigation::mojom::ViewPtr view, - navigation::mojom::ViewClientRequest request, + // navigation::ViewDelegate: + void ViewCreated(std::unique_ptr view, bool is_popup, const gfx::Rect& initial_rect, bool user_gesture) override { views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( new UI(browser_, is_popup ? UI::Type::POPUP : UI::Type::WINDOW, - std::move(view), std::move(request)), + std::move(view)), nullptr, initial_rect); window->Show(); browser_->AddWindow(window); } void Close() override { GetWidget()->Close(); } - void NavigationPending(navigation::mojom::NavigationEntryPtr entry) override { - pending_nav_ = std::move(entry); - } - void NavigationCommitted( - navigation::mojom::NavigationCommittedDetailsPtr details, - int current_index) override { - switch (details->type) { - case navigation::mojom::NavigationType::NEW_PAGE: { - navigation_list_.push_back(std::move(pending_nav_)); - navigation_list_position_ = current_index; - break; - } - case navigation::mojom::NavigationType::EXISTING_PAGE: - navigation_list_position_ = current_index; - break; - default: - break; + + // navigation::ViewObserver: + void LoadingStateChanged(navigation::View* view) override { + if (view->is_loading()) { + reload_button_->SetText(base::ASCIIToUTF16("Stop")); + throbber_->Start(); + } else { + reload_button_->SetText(base::ASCIIToUTF16("Reload")); + throbber_->Stop(); + progress_bar_->SetProgress(0.f); } } - void NavigationEntryChanged(navigation::mojom::NavigationEntryPtr entry, - int entry_index) override { - navigation_list_[entry_index] = std::move(entry); + void LoadProgressChanged(navigation::View* view, double progress) override { + progress_bar_->SetProgress(progress); + } + void NavigationStateChanged(navigation::View* view) override { + EnableButton(back_button_, view->can_go_back()); + EnableButton(forward_button_, view->can_go_forward()); + prompt_->SetText(base::UTF8ToUTF16(view->url().spec())); + GetWidget()->UpdateWindowTitle(); } - void NavigationListPruned(bool from_front, int count) override { - DCHECK(count < static_cast(navigation_list_.size())); - if (from_front) { - auto it = navigation_list_.begin() + count; - navigation_list_.erase(navigation_list_.begin(), it); - } else { - auto it = navigation_list_.end() - count; - navigation_list_.erase(it, navigation_list_.end()); - } + void HoverTargetURLChanged(navigation::View* view, const GURL& url) override { + if (url.is_valid()) + prompt_->SetText(base::UTF8ToUTF16(url.spec())); + else + prompt_->SetText(base::UTF8ToUTF16(view_->url().spec())); } // NavButton::ModelProvider: std::unique_ptr CreateMenuModel( NavButton::Type type) override { - std::vector entries; + std::vector entries; if (type == NavButton::Type::BACK) { - for (int i = navigation_list_position_ - 1, offset = -1; - i >= 0; --i, --offset) { - std::string title = navigation_list_[i]->title; - entries.push_back( - NavMenuModel::Entry(base::UTF8ToUTF16(title), offset)); - } + view_->GetBackMenuItems(&entries); } else { - for (int i = navigation_list_position_ + 1, offset = 1; - i < static_cast(navigation_list_.size()); ++i, ++offset) { - std::string title = navigation_list_[i]->title; - entries.push_back( - NavMenuModel::Entry(base::UTF8ToUTF16(title), offset)); - } + view_->GetForwardMenuItems(&entries); } return base::WrapUnique(new NavMenuModel(entries, this)); } @@ -580,16 +528,7 @@ class UI : public views::WidgetDelegateView, DebugView* debug_view_; - navigation::mojom::ViewPtr view_; - mojo::Binding view_client_binding_; - - bool is_loading_ = false; - base::string16 current_title_; - GURL current_url_; - - navigation::mojom::NavigationEntryPtr pending_nav_; - std::vector navigation_list_; - int navigation_list_position_ = 0; + std::unique_ptr view_; bool showing_debug_view_ = false; @@ -635,15 +574,10 @@ void Browser::Launch(uint32_t what, mojom::LaunchMode how) { return; } - navigation::mojom::ViewFactoryPtr view_factory; - connector_->ConnectToInterface("exe:navigation", &view_factory); - navigation::mojom::ViewPtr view; - navigation::mojom::ViewClientPtr view_client; - navigation::mojom::ViewClientRequest view_client_request = - GetProxy(&view_client); - view_factory->CreateView(std::move(view_client), GetProxy(&view)); - UI* ui = new UI(this, UI::Type::WINDOW, std::move(view), - std::move(view_client_request)); + navigation::mojom::ViewFactoryPtr factory; + connector_->ConnectToInterface("exe:navigation", &factory); + UI* ui = new UI(this, UI::Type::WINDOW, + base::WrapUnique(new navigation::View(std::move(factory)))); views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( ui, nullptr, gfx::Rect(10, 10, 1024, 600)); ui->NavigateTo(GURL("http://www.google.com/")); diff --git a/mash/browser/debug_view.h b/mash/browser/debug_view.h index e7e733b1ba7f1d..eee9bbfc56ae5c 100644 --- a/mash/browser/debug_view.h +++ b/mash/browser/debug_view.h @@ -5,7 +5,7 @@ #ifndef MASH_BROWSER_DEBUG_VIEW_H_ #define MASH_BROWSER_DEBUG_VIEW_H_ -#include "services/navigation/public/interfaces/view.mojom.h" +#include "services/navigation/public/cpp/view.h" #include "ui/views/controls/button/button.h" #include "ui/views/view.h" @@ -28,7 +28,7 @@ class DebugView : public views::View, DebugView(const DebugView&) = delete; void operator=(const DebugView&) = delete; - void set_view(navigation::mojom::View* view) { view_ = view; } + void set_view(navigation::View* view) { view_ = view; } gfx::Size GetPreferredSize() const override; @@ -36,7 +36,7 @@ class DebugView : public views::View, void OnPaint(gfx::Canvas* canvas) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override; - navigation::mojom::View* view_ = nullptr; + navigation::View* view_ = nullptr; views::View* interstitial_container_; views::Label* interstitial_label_; diff --git a/services/navigation/public/cpp/BUILD.gn b/services/navigation/public/cpp/BUILD.gn new file mode 100644 index 00000000000000..a90228a068f8fb --- /dev/null +++ b/services/navigation/public/cpp/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +static_library("cpp") { + sources = [ + "view.cc", + "view.h", + "view_delegate.h", + "view_observer.h", + ] + + deps = [ + "//base", + "//components/mus/public/cpp", + "//mojo/public/cpp/bindings", + "//services/navigation/public/interfaces", + ] +} diff --git a/services/navigation/public/cpp/view.cc b/services/navigation/public/cpp/view.cc new file mode 100644 index 00000000000000..1b311905e7c35d --- /dev/null +++ b/services/navigation/public/cpp/view.cc @@ -0,0 +1,178 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "services/navigation/public/cpp/view.h" + +#include "base/strings/utf_string_conversions.h" +#include "components/mus/public/cpp/window.h" +#include "services/navigation/public/cpp/view_delegate.h" +#include "services/navigation/public/cpp/view_observer.h" + +namespace navigation { + +//////////////////////////////////////////////////////////////////////////////// +// View, public: + +View::View(mojom::ViewFactoryPtr factory) : binding_(this) { + mojom::ViewClientPtr client; + binding_.Bind(GetProxy(&client)); + factory->CreateView(std::move(client), GetProxy(&view_)); +} + +View::View(mojom::ViewPtr view, mojom::ViewClientRequest request) + : view_(std::move(view)), binding_(this, std::move(request)) {} + +View::~View() {} + +void View::AddObserver(ViewObserver* observer) { + observers_.AddObserver(observer); +} + +void View::RemoveObserver(ViewObserver* observer) { + observers_.RemoveObserver(observer); +} + +void View::NavigateToURL(const GURL& url) { + view_->NavigateTo(url); +} + +void View::NavigateToOffset(int offset) { + view_->NavigateToOffset(offset); +} + +void View::GoBack() { + if (can_go_back_) + view_->GoBack(); +} + +void View::GoForward() { + if (can_go_forward_) + view_->GoForward(); +} + +void View::GetBackMenuItems(std::vector* items) { + DCHECK(items); + for (int i = navigation_list_cursor_ - 1, offset = -1; i >= 0; + --i, --offset) { + std::string title = navigation_list_[i]->title; + items->push_back(NavigationListItem(base::UTF8ToUTF16(title), offset)); + } +} + +void View::GetForwardMenuItems(std::vector* items) { + DCHECK(items); + for (int i = navigation_list_cursor_ + 1, offset = 1; + i < static_cast(navigation_list_.size()); ++i, ++offset) { + std::string title = navigation_list_[i]->title; + items->push_back(NavigationListItem(base::UTF8ToUTF16(title), offset)); + } +} + +void View::Reload(bool bypass_cache) { + view_->Reload(bypass_cache); +} + +void View::Stop() { + view_->Stop(); +} + +void View::ShowInterstitial(const std::string& html) { + view_->ShowInterstitial(html); +} + +void View::HideInterstitial() { + view_->HideInterstitial(); +} + +void View::SetResizerSize(const gfx::Size& size) { + view_->SetResizerSize(size); +} + +void View::EmbedInWindow(mus::Window* parent) { + mus::mojom::WindowTreeClientPtr client; + view_->GetWindowTreeClient(GetProxy(&client)); + parent->Embed(std::move(client)); +} + +//////////////////////////////////////////////////////////////////////////////// +// View, mojom::ViewClient implementation: + +void View::LoadingStateChanged(bool is_loading) { + is_loading_ = is_loading; + FOR_EACH_OBSERVER(ViewObserver, observers_, LoadingStateChanged(this)); +} + +void View::NavigationStateChanged(const GURL& url, + const mojo::String& title, + bool can_go_back, + bool can_go_forward) { + url_ = url; + title_ = base::UTF8ToUTF16(title.get()); + can_go_back_ = can_go_back; + can_go_forward_ = can_go_forward; + FOR_EACH_OBSERVER(ViewObserver, observers_, NavigationStateChanged(this)); +} + +void View::LoadProgressChanged(double progress) { + FOR_EACH_OBSERVER(ViewObserver, observers_, + LoadProgressChanged(this, progress)); +} + +void View::UpdateHoverURL(const GURL& url) { + FOR_EACH_OBSERVER(ViewObserver, observers_, HoverTargetURLChanged(this, url)); +} + +void View::ViewCreated(mojom::ViewPtr view, + mojom::ViewClientRequest request, + bool is_popup, + const gfx::Rect& initial_bounds, + bool user_gesture) { + if (delegate_) { + delegate_->ViewCreated( + base::WrapUnique(new View(std::move(view), std::move(request))), + is_popup, initial_bounds, user_gesture); + } +} + +void View::Close() { + if (delegate_) + delegate_->Close(); +} + +void View::NavigationPending(mojom::NavigationEntryPtr entry) { + pending_navigation_ = std::move(entry); +} + +void View::NavigationCommitted(mojom::NavigationCommittedDetailsPtr details, + int current_index) { + switch (details->type) { + case mojom::NavigationType::NEW_PAGE: + navigation_list_.push_back(std::move(pending_navigation_)); + navigation_list_cursor_ = current_index; + break; + case mojom::NavigationType::EXISTING_PAGE: + navigation_list_cursor_ = current_index; + break; + default: + break; + } +} + +void View::NavigationEntryChanged(mojom::NavigationEntryPtr entry, + int entry_index) { + navigation_list_[entry_index] = std::move(entry); +} + +void View::NavigationListPruned(bool from_front, int count) { + DCHECK(count < static_cast(navigation_list_.size())); + if (from_front) { + auto it = navigation_list_.begin() + count; + navigation_list_.erase(navigation_list_.begin(), it); + } else { + auto it = navigation_list_.end() - count; + navigation_list_.erase(it, navigation_list_.end()); + } +} + +} // namespace navigation diff --git a/services/navigation/public/cpp/view.h b/services/navigation/public/cpp/view.h new file mode 100644 index 00000000000000..de5b442888c5c6 --- /dev/null +++ b/services/navigation/public/cpp/view.h @@ -0,0 +1,118 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SERVICES_NAVIGATION_PUBLIC_CPP_VIEW_H_ +#define SERVICES_NAVIGATION_PUBLIC_CPP_VIEW_H_ + +#include "base/observer_list.h" +#include "base/strings/string16.h" +#include "mojo/public/cpp/bindings/binding.h" +#include "services/navigation/public/interfaces/view.mojom.h" + +namespace mus { +class Window; +} + +namespace navigation { + +class ViewDelegate; +class ViewObserver; + +// Represents an item in a View's navigation list. +struct NavigationListItem { + NavigationListItem(const base::string16& title, int offset) + : title(title), offset(offset) {} + ~NavigationListItem() {} + + base::string16 title; + // The navigation offset from the current page in the navigation list. + int offset; +}; + +class View : public mojom::ViewClient { + public: + explicit View(mojom::ViewFactoryPtr factory); + View(mojom::ViewPtr view, mojom::ViewClientRequest request); + View(const View&) = delete; + void operator=(const View&) = delete; + ~View() override; + + void set_delegate(ViewDelegate* delegate) { delegate_ = delegate; } + + void AddObserver(ViewObserver* observer); + void RemoveObserver(ViewObserver* observer); + + // Loading. + void NavigateToURL(const GURL& url); + void NavigateToOffset(int offset); + bool is_loading() const { return is_loading_; } + const GURL& url() const { return url_; } + const base::string16& title() const { return title_; } + + // Back/Forward. + void GoBack(); + void GoForward(); + bool can_go_back() const { return can_go_back_; } + bool can_go_forward() const { return can_go_forward_; } + void GetBackMenuItems(std::vector* items); + void GetForwardMenuItems(std::vector* items); + + // Reload/Stop. + void Reload(bool bypass_cache); + void Stop(); + + // Interstitials. + void ShowInterstitial(const std::string& html); + void HideInterstitial(); + + // When non-empty, specifies the size of an area in the bottom corner of the + // View that should allow the enclosing top-level window to be resized via the + // pointer. + void SetResizerSize(const gfx::Size& size); + + // Embed the View visually within |parent|. + void EmbedInWindow(mus::Window* parent); + + private: + // mojom::ViewClient: + void LoadingStateChanged(bool is_loading) override; + void NavigationStateChanged(const GURL& url, + const mojo::String& title, + bool can_go_back, + bool can_go_forward) override; + void LoadProgressChanged(double progress) override; + void UpdateHoverURL(const GURL& url) override; + void ViewCreated(mojom::ViewPtr view, + mojom::ViewClientRequest request, + bool is_popup, + const gfx::Rect& initial_bounds, + bool user_gesture) override; + void Close() override; + void NavigationPending(mojom::NavigationEntryPtr entry) override; + void NavigationCommitted(mojom::NavigationCommittedDetailsPtr details, + int current_index) override; + void NavigationEntryChanged(mojom::NavigationEntryPtr entry, + int entry_index) override; + void NavigationListPruned(bool from_front, int count) override; + + mojom::ViewPtr view_; + mojo::Binding binding_; + + ViewDelegate* delegate_ = nullptr; + base::ObserverList observers_; + + bool is_loading_ = false; + GURL url_; + base::string16 title_; + bool can_go_back_ = false; + bool can_go_forward_ = false; + + mojom::NavigationEntryPtr pending_navigation_; + std::vector navigation_list_; + int navigation_list_cursor_ = 0; +}; + +} // namespace navigation + +#endif // SERVICES_NAVIGATION_PUBLIC_CPP_VIEW_H_ diff --git a/services/navigation/public/cpp/view_delegate.h b/services/navigation/public/cpp/view_delegate.h new file mode 100644 index 00000000000000..721de68ee8177a --- /dev/null +++ b/services/navigation/public/cpp/view_delegate.h @@ -0,0 +1,41 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SERVICES_NAVIGATION_PUBLIC_CPP_VIEW_DELEGATE_H_ +#define SERVICES_NAVIGATION_PUBLIC_CPP_VIEW_DELEGATE_H_ + +#include + +namespace gfx { +class Rect; +} + +namespace navigation { + +class View; + +class ViewDelegate { + public: + // Called when an action within the page has caused a new View to be created. + // The delegate must take action to either create a new host for this View, or + // close it. + // |new_view| is the newly created View. + // |is_popup| is true if the View should be shown in a popup window instead of + // a new tab. + // |requested_bounds| are the requested bounds of the new popup. + // |user_gesture| is true if the View was created as the result of an explicit + // user input event. + virtual void ViewCreated(std::unique_ptr new_view, + bool is_popup, + const gfx::Rect& requested_bounds, + bool user_gesture) = 0; + + // Called when an action within the page has requested that the View be + // closed. + virtual void Close() = 0; +}; + +} // namespace navigation + +#endif // SERVICES_NAVIGATION_PUBLIC_CPP_VIEW_DELEGATE_H_ diff --git a/services/navigation/public/cpp/view_observer.h b/services/navigation/public/cpp/view_observer.h new file mode 100644 index 00000000000000..34a2e86d0efb3c --- /dev/null +++ b/services/navigation/public/cpp/view_observer.h @@ -0,0 +1,33 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SERVICES_NAVIGATION_PUBLIC_CPP_VIEW_OBSERVER_H_ +#define SERVICES_NAVIGATION_PUBLIC_CPP_VIEW_OBSERVER_H_ + +namespace navigation { + +class View; + +class ViewObserver { + public: + // Called when network activity for the application(s) within |view| starts or + // stops. + virtual void LoadingStateChanged(View* view) {} + + // Called when the progress of network activity for the application(s) within + // |view| changes. + virtual void LoadProgressChanged(View* view, double progress) {} + + // Called when a navigation occurs within |view|. + virtual void NavigationStateChanged(View* view) {} + + // Called when the target URL of a mouse click at the current mouse position + // changes. Will provide an empty URL if no navigation would result from such + // a click. + virtual void HoverTargetURLChanged(View* view, const GURL& target_url) {} +}; + +} // namespace navigation + +#endif // SERVICES_NAVIGATION_PUBLIC_CPP_VIEW_OBSERVER_H_