summaryrefslogtreecommitdiffstats
path: root/mandoline/ui
diff options
context:
space:
mode:
Diffstat (limited to 'mandoline/ui')
-rw-r--r--mandoline/ui/BUILD.gn6
-rw-r--r--mandoline/ui/browser/BUILD.gn8
-rw-r--r--mandoline/ui/browser/android/android_ui.cc59
-rw-r--r--mandoline/ui/browser/android/android_ui.h51
-rw-r--r--mandoline/ui/browser/browser.cc159
-rw-r--r--mandoline/ui/browser/browser.h105
-rw-r--r--mandoline/ui/browser/browser_apptest.cc4
-rw-r--r--mandoline/ui/browser/browser_ui.h21
-rw-r--r--mandoline/ui/browser/desktop/desktop_ui.cc204
-rw-r--r--mandoline/ui/browser/desktop/desktop_ui.h65
10 files changed, 212 insertions, 470 deletions
diff --git a/mandoline/ui/BUILD.gn b/mandoline/ui/BUILD.gn
index e6152c8..f066de5 100644
--- a/mandoline/ui/BUILD.gn
+++ b/mandoline/ui/BUILD.gn
@@ -6,10 +6,12 @@ import("//build/config/ui.gni")
group("ui") {
deps = [
- "browser",
"phone_ui",
]
if (use_aura) {
- deps += [ "omnibox" ]
+ deps += [
+ "browser",
+ "omnibox",
+ ]
}
}
diff --git a/mandoline/ui/browser/BUILD.gn b/mandoline/ui/browser/BUILD.gn
index 4557fcc..24fb5303 100644
--- a/mandoline/ui/browser/BUILD.gn
+++ b/mandoline/ui/browser/BUILD.gn
@@ -22,8 +22,6 @@ mojo_native_application("browser") {
source_set("lib") {
sources = [
- "browser.cc",
- "browser.h",
"browser_manager.cc",
"browser_manager.h",
]
@@ -55,12 +53,6 @@ source_set("lib") {
"//ui/gfx",
"//ui/views",
]
- } else {
- assert(is_android)
- sources += [
- "android/android_ui.cc",
- "android/android_ui.h",
- ]
}
}
diff --git a/mandoline/ui/browser/android/android_ui.cc b/mandoline/ui/browser/android/android_ui.cc
deleted file mode 100644
index 8849479b..0000000
--- a/mandoline/ui/browser/android/android_ui.cc
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2015 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 "mandoline/ui/browser/android/android_ui.h"
-
-#include "components/view_manager/public/cpp/view.h"
-#include "mandoline/ui/browser/browser.h"
-#include "mandoline/ui/browser/browser_manager.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "ui/gfx/geometry/rect.h"
-
-namespace mandoline {
-
-AndroidUI::AndroidUI(mojo::ApplicationImpl* application_impl,
- BrowserManager* manager)
- : browser_(application_impl, this),
- manager_(manager),
- application_impl_(application_impl),
- root_(nullptr) {}
-
-AndroidUI::~AndroidUI() {
- root_->RemoveObserver(this);
-}
-
-void AndroidUI::Init(mojo::View* root) {
- root_ = root;
- root_->AddObserver(this);
-
- browser_.content()->SetBounds(root_->bounds());
-}
-
-void AndroidUI::LoadURL(const GURL& url) {
- browser_.LoadURL(url);
-}
-
-void AndroidUI::ViewManagerDisconnected() {
- manager_->BrowserUIClosed(this);
-}
-
-void AndroidUI::EmbedOmnibox(mojo::ApplicationConnection* connection) {}
-void AndroidUI::OnURLChanged() {}
-void AndroidUI::LoadingStateChanged(bool loading) {}
-void AndroidUI::ProgressChanged(double progress) {}
-
-void AndroidUI::OnViewBoundsChanged(mojo::View* view,
- const mojo::Rect& old_bounds,
- const mojo::Rect& new_bounds) {
- browser_.content()->SetBounds(
- *mojo::Rect::From(gfx::Rect(0, 0, new_bounds.width, new_bounds.height)));
-}
-
-// static
-BrowserUI* BrowserUI::Create(mojo::ApplicationImpl* application_impl,
- BrowserManager* manager) {
- return new AndroidUI(application_impl, manager);
-}
-
-} // namespace mandoline
diff --git a/mandoline/ui/browser/android/android_ui.h b/mandoline/ui/browser/android/android_ui.h
deleted file mode 100644
index 5642151..0000000
--- a/mandoline/ui/browser/android/android_ui.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2015 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 MANDOLINE_UI_BROWSER_ANDROID_ANDROID_UI_H_
-#define MANDOLINE_UI_BROWSER_ANDROID_ANDROID_UI_H_
-
-#include "base/macros.h"
-#include "components/view_manager/public/cpp/view_observer.h"
-#include "mandoline/ui/browser/browser.h"
-#include "mandoline/ui/browser/browser_ui.h"
-
-namespace mojo {
-class Shell;
-class View;
-}
-
-namespace mandoline {
-
-class AndroidUI : public BrowserUI,
- public mojo::ViewObserver {
- public:
- AndroidUI(mojo::ApplicationImpl* application_impl, BrowserManager* manager);
- ~AndroidUI() override;
-
- private:
- // Overridden from BrowserUI:
- void Init(mojo::View* root) override;
- void LoadURL(const GURL& url) override;
- void ViewManagerDisconnected() override;
- void EmbedOmnibox(mojo::ApplicationConnection* connection) override;
- void OnURLChanged() override;
- void LoadingStateChanged(bool loading) override;
- void ProgressChanged(double progress) override;
-
- // Overriden from mojo::ViewObserver:
- virtual void OnViewBoundsChanged(mojo::View* view,
- const mojo::Rect& old_bounds,
- const mojo::Rect& new_bounds) override;
-
- Browser browser_;
- BrowserManager* manager_;
- mojo::ApplicationImpl* application_impl_;
- mojo::View* root_;
-
- DISALLOW_COPY_AND_ASSIGN(AndroidUI);
-};
-
-} // namespace mandoline
-
-#endif // MANDOLINE_UI_BROWSER_ANDROID_ANDROID_UI_H_
diff --git a/mandoline/ui/browser/browser.cc b/mandoline/ui/browser/browser.cc
deleted file mode 100644
index bfd1125..0000000
--- a/mandoline/ui/browser/browser.cc
+++ /dev/null
@@ -1,159 +0,0 @@
-// Copyright 2015 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 "mandoline/ui/browser/browser.h"
-
-#include "base/command_line.h"
-#include "base/strings/utf_string_conversions.h"
-#include "components/view_manager/public/cpp/view.h"
-#include "components/view_manager/public/cpp/view_manager_init.h"
-#include "mandoline/ui/browser/browser_ui.h"
-#include "mojo/application/public/cpp/application_runner.h"
-#include "mojo/common/common_type_converters.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "third_party/mojo/src/mojo/public/c/system/main.h"
-#include "ui/gfx/geometry/size.h"
-
-namespace mandoline {
-namespace {
-
-gfx::Size GetInitialViewportSize() {
-#if defined(OS_ANDROID)
- // Resize to match the Nexus 5 aspect ratio:
- return gfx::Size(320, 640);
-#else
- return gfx::Size(1280, 800);
-#endif
-}
-
-} // namespace
-
-Browser::Browser(mojo::ApplicationImpl* app, BrowserUI* ui)
- : app_(app),
- ui_(ui),
- view_manager_init_(app, this, this),
- root_(nullptr),
- content_(nullptr),
- web_view_(this) {
-}
-
-Browser::~Browser() {
-}
-
-void Browser::LoadURL(const GURL& url) {
- // Haven't been embedded yet, can't embed.
- // TODO(beng): remove this.
- if (!root_) {
- default_url_ = url;
- return;
- }
-
- mojo::URLRequestPtr request(mojo::URLRequest::New());
- request->url = url.spec();
- Embed(request.Pass());
-}
-
-void Browser::ShowOmnibox() {
- if (!omnibox_.get()) {
- mojo::URLRequestPtr request(mojo::URLRequest::New());
- request->url = mojo::String::From("mojo:omnibox");
- omnibox_connection_ = app_->ConnectToApplication(request.Pass());
- omnibox_connection_->AddService<ViewEmbedder>(this);
- omnibox_connection_->ConnectToService(&omnibox_);
- omnibox_connection_->SetRemoteServiceProviderConnectionErrorHandler(
- [this]() {
- // This will cause the connection to be re-established the next time
- // we come through this codepath.
- omnibox_.reset();
- });
- }
- omnibox_->ShowForURL(mojo::String::From(current_url_.spec()));
-}
-
-mojo::ApplicationConnection* Browser::GetViewManagerConnectionForTesting() {
- return view_manager_init_.connection();
-}
-
-void Browser::OnEmbed(mojo::View* root) {
- // Browser does not support being embedded more than once.
- CHECK(!root_);
-
- // Make it so we get OnWillEmbed() for any Embed()s done by other apps we
- // Embed().
- root->view_manager()->SetEmbedRoot();
-
- // TODO(beng): still unhappy with the fact that both this class & the UI class
- // know so much about these views. Figure out how to shift more to
- // the UI class.
- root_ = root;
-
- content_ = root_->view_manager()->CreateView();
- ui_->Init(root_);
-
- view_manager_init_.view_manager_root()->SetViewportSize(
- mojo::Size::From(GetInitialViewportSize()));
-
- root_->AddChild(content_);
- content_->SetVisible(true);
-
- web_view_.Init(app_, content_);
-
- view_manager_init_.view_manager_root()->AddAccelerator(
- mojo::KEYBOARD_CODE_BROWSER_BACK, mojo::EVENT_FLAGS_NONE);
-
- // Now that we're ready, load the default url.
- if (default_url_.is_valid()) {
- mojo::URLRequestPtr request(mojo::URLRequest::New());
- request->url = mojo::String::From(default_url_.spec());
- Embed(request.Pass());
- }
-}
-
-void Browser::OnViewManagerDestroyed(mojo::ViewManager* view_manager) {
- root_ = nullptr;
- ui_->ViewManagerDisconnected();
-}
-
-void Browser::OnAccelerator(mojo::EventPtr event) {
- DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK,
- event->key_data->windows_key_code);
- NOTIMPLEMENTED();
-}
-
-void Browser::TopLevelNavigate(mojo::URLRequestPtr request) {
- Embed(request.Pass());
-}
-
-void Browser::LoadingStateChanged(bool is_loading) {
- ui_->LoadingStateChanged(is_loading);
-}
-
-void Browser::ProgressChanged(double progress) {
- ui_->ProgressChanged(progress);
-}
-
-// TODO(beng): Consider moving this to the UI object as well once the frame tree
-// stuff is better encapsulated.
-void Browser::Embed(mojo::URLRequestPtr request) {
- const std::string string_url = request->url.To<std::string>();
- if (string_url == "mojo:omnibox") {
- ui_->EmbedOmnibox(omnibox_connection_.get());
- return;
- }
-
- GURL gurl(string_url);
- bool changed = current_url_ != gurl;
- current_url_ = gurl;
- if (changed)
- ui_->OnURLChanged();
-
- web_view_.web_view()->LoadRequest(request.Pass());
-}
-
-void Browser::Create(mojo::ApplicationConnection* connection,
- mojo::InterfaceRequest<ViewEmbedder> request) {
- view_embedder_bindings_.AddBinding(this, request.Pass());
-}
-
-} // namespace mandoline
diff --git a/mandoline/ui/browser/browser.h b/mandoline/ui/browser/browser.h
deleted file mode 100644
index 6cbfce4..0000000
--- a/mandoline/ui/browser/browser.h
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2015 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 MANDOLINE_UI_BROWSER_BROWSER_H_
-#define MANDOLINE_UI_BROWSER_BROWSER_H_
-
-#include "base/gtest_prod_util.h"
-#include "components/view_manager/public/cpp/view_manager.h"
-#include "components/view_manager/public/cpp/view_manager_delegate.h"
-#include "components/view_manager/public/cpp/view_manager_init.h"
-#include "components/view_manager/public/interfaces/view_manager_root.mojom.h"
-#include "mandoline/tab/public/cpp/web_view.h"
-#include "mandoline/tab/public/interfaces/web_view.mojom.h"
-#include "mandoline/ui/browser/public/interfaces/omnibox.mojom.h"
-#include "mandoline/ui/browser/public/interfaces/view_embedder.mojom.h"
-#include "mojo/application/public/cpp/application_delegate.h"
-#include "mojo/application/public/cpp/application_impl.h"
-#include "mojo/application/public/cpp/connect.h"
-#include "mojo/common/weak_binding_set.h"
-#include "ui/mojo/events/input_events.mojom.h"
-#include "url/gurl.h"
-
-namespace mojo {
-class ViewManagerInit;
-}
-
-namespace mandoline {
-
-FORWARD_DECLARE_TEST(BrowserTest, ClosingBrowserClosesAppConnection);
-
-class BrowserDelegate;
-class BrowserUI;
-
-class Browser : public mojo::ViewManagerDelegate,
- public mojo::ViewManagerRootClient,
- public web_view::mojom::WebViewClient,
- public ViewEmbedder,
- public mojo::InterfaceFactory<ViewEmbedder> {
- public:
- Browser(mojo::ApplicationImpl* app, BrowserUI* ui);
- ~Browser() override;
-
- mojo::View* content() { return content_; }
-
- const GURL& current_url() const { return current_url_; }
-
- void LoadURL(const GURL& url);
-
- // Starts the Omnibox application (if necessary) and shows it.
- void ShowOmnibox();
-
- private:
- FRIEND_TEST_ALL_PREFIXES(BrowserTest, ClosingBrowserClosesAppConnection);
- FRIEND_TEST_ALL_PREFIXES(BrowserTest, TwoBrowsers);
-
- friend class TestBrowser;
-
- mojo::ApplicationConnection* GetViewManagerConnectionForTesting();
-
- // Overridden from mojo::ViewManagerDelegate:
- void OnEmbed(mojo::View* root) override;
- void OnViewManagerDestroyed(mojo::ViewManager* view_manager) override;
-
- // Overridden from ViewManagerRootClient:
- void OnAccelerator(mojo::EventPtr event) override;
-
- // Overridden from web_view::mojom::WebViewClient:
- void TopLevelNavigate(mojo::URLRequestPtr request) override;
- void LoadingStateChanged(bool is_loading) override;
- void ProgressChanged(double progress) override;
-
- // Overridden from ViewEmbedder:
- void Embed(mojo::URLRequestPtr request) override;
-
- // Overridden from mojo::InterfaceFactory<ViewEmbedder>:
- void Create(mojo::ApplicationConnection* connection,
- mojo::InterfaceRequest<ViewEmbedder> request) override;
-
- mojo::ApplicationImpl* app_;
- BrowserUI* ui_;
-
- mojo::ViewManagerInit view_manager_init_;
-
- // Only support being embedded once, so both application-level
- // and embedding-level state are shared on the same object.
- mojo::View* root_;
- mojo::View* content_;
- GURL default_url_;
-
- mojo::WeakBindingSet<ViewEmbedder> view_embedder_bindings_;
-
- GURL current_url_;
-
- web_view::WebView web_view_;
-
- OmniboxPtr omnibox_;
- scoped_ptr<mojo::ApplicationConnection> omnibox_connection_;
-
- DISALLOW_COPY_AND_ASSIGN(Browser);
-};
-
-} // namespace mandoline
-
-#endif // MANDOLINE_UI_BROWSER_BROWSER_H_
diff --git a/mandoline/ui/browser/browser_apptest.cc b/mandoline/ui/browser/browser_apptest.cc
index e989f73..1f3ba8e 100644
--- a/mandoline/ui/browser/browser_apptest.cc
+++ b/mandoline/ui/browser/browser_apptest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// These tests are disabled pending refactoring of mandoline:browser
+#if 0
#include "mandoline/ui/browser/browser.h"
#include "base/run_loop.h"
@@ -11,8 +13,6 @@
#include "mojo/application/public/cpp/application_impl.h"
#include "mojo/application/public/cpp/application_test_base.h"
-// These tests are disabled pending refactoring of mandoline:browser
-#if 0
namespace mandoline {
class TestBrowser : public Browser {
diff --git a/mandoline/ui/browser/browser_ui.h b/mandoline/ui/browser/browser_ui.h
index 5e4f8bc..96f71c0 100644
--- a/mandoline/ui/browser/browser_ui.h
+++ b/mandoline/ui/browser/browser_ui.h
@@ -23,29 +23,8 @@ class BrowserUI {
static BrowserUI* Create(mojo::ApplicationImpl* application_impl,
BrowserManager* manager);
- // Called when the Browser UI is embedded within the specified view.
- // BrowserUI is destroyed prior to |root| being destroyed. That is, the
- // BrowserUI implementations can assume |root| is never deleted out from under
- // them.
- virtual void Init(mojo::View* root) = 0;
-
// Loads the specified URL in the active tab.
virtual void LoadURL(const GURL& url) = 0;
-
- // TODO(beng): remove this method once BrowserManager is the
- // ViewManagerDelegate.
- virtual void ViewManagerDisconnected() = 0;
-
- // Embeds the Omnibox UI. The connection object passed is an existing
- // connection to the Omnibox application from which a ViewManagerClient can be
- // obtained.
- virtual void EmbedOmnibox(mojo::ApplicationConnection* connection) = 0;
-
- virtual void OnURLChanged() = 0;
-
- virtual void LoadingStateChanged(bool loading) = 0;
-
- virtual void ProgressChanged(double progress) = 0;
};
} // namespace mandoline
diff --git a/mandoline/ui/browser/desktop/desktop_ui.cc b/mandoline/ui/browser/desktop/desktop_ui.cc
index f14d41e..f062308 100644
--- a/mandoline/ui/browser/desktop/desktop_ui.cc
+++ b/mandoline/ui/browser/desktop/desktop_ui.cc
@@ -59,80 +59,93 @@ class ProgressView : public views::View {
////////////////////////////////////////////////////////////////////////////////
// DesktopUI, public:
-DesktopUI::DesktopUI(mojo::ApplicationImpl* application_impl,
- BrowserManager* manager)
- : application_impl_(application_impl),
- browser_(application_impl, this),
+DesktopUI::DesktopUI(mojo::ApplicationImpl* app, BrowserManager* manager)
+ : app_(app),
+ view_manager_init_(app, this, this),
manager_(manager),
omnibox_launcher_(nullptr),
progress_bar_(nullptr),
root_(nullptr),
content_(nullptr),
- omnibox_(nullptr) {}
+ omnibox_view_(nullptr),
+ web_view_(this) {}
DesktopUI::~DesktopUI() {}
////////////////////////////////////////////////////////////////////////////////
// DesktopUI, BrowserUI implementation:
-void DesktopUI::Init(mojo::View* root) {
- DCHECK_GT(root->viewport_metrics().device_pixel_ratio, 0);
- if (!aura_init_)
- aura_init_.reset(new AuraInit(root, application_impl_->shell()));
+void DesktopUI::LoadURL(const GURL& url) {
+ // Haven't been embedded yet, can't embed.
+ // TODO(beng): remove this.
+ if (!root_) {
+ default_url_ = url;
+ return;
+ }
+
+ mojo::URLRequestPtr request(mojo::URLRequest::New());
+ request->url = url.spec();
+ Embed(request.Pass());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopUI, mojo::ViewManagerDelegate implementation:
+
+void DesktopUI::OnEmbed(mojo::View* root) {
+ // DesktopUI does not support being embedded more than once.
+ CHECK(!root_);
+
+ // Make it so we get OnWillEmbed() for any Embed()s done by other apps we
+ // Embed().
+ root->view_manager()->SetEmbedRoot();
root_ = root;
- omnibox_ = root_->view_manager()->CreateView();
- root_->AddChild(omnibox_);
- views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView;
- widget_delegate->GetContentsView()->set_background(
- views::Background::CreateSolidBackground(0xFFDDDDDD));
- omnibox_launcher_ =
- new views::LabelButton(this, base::ASCIIToUTF16("Open Omnibox"));
- progress_bar_ = new ProgressView;
+ content_ = root_->view_manager()->CreateView();
+ Init(root_);
- widget_delegate->GetContentsView()->AddChildView(omnibox_launcher_);
- widget_delegate->GetContentsView()->AddChildView(progress_bar_);
- widget_delegate->GetContentsView()->SetLayoutManager(this);
+ view_manager_init_.view_manager_root()->SetViewportSize(
+ mojo::Size::From(gfx::Size(1280, 800)));
- views::Widget* widget = new views::Widget;
- views::Widget::InitParams params(
- views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
- params.native_widget =
- new NativeWidgetViewManager(widget, application_impl_->shell(), root_);
- params.delegate = widget_delegate;
- params.bounds = root_->bounds().To<gfx::Rect>();
- widget->Init(params);
- widget->Show();
- root_->SetFocus();
-}
+ root_->AddChild(content_);
+ content_->SetVisible(true);
-void DesktopUI::LoadURL(const GURL& url) {
- browser_.LoadURL(url);
+ web_view_.Init(app_, content_);
+
+ view_manager_init_.view_manager_root()->AddAccelerator(
+ mojo::KEYBOARD_CODE_BROWSER_BACK, mojo::EVENT_FLAGS_NONE);
+
+ // Now that we're ready, load the default url.
+ if (default_url_.is_valid()) {
+ mojo::URLRequestPtr request(mojo::URLRequest::New());
+ request->url = mojo::String::From(default_url_.spec());
+ Embed(request.Pass());
+ }
}
-void DesktopUI::ViewManagerDisconnected() {
+void DesktopUI::OnViewManagerDestroyed(mojo::ViewManager* view_manager) {
+ root_ = nullptr;
manager_->BrowserUIClosed(this);
}
-void DesktopUI::EmbedOmnibox(mojo::ApplicationConnection* connection) {
- mojo::ViewManagerClientPtr view_manager_client;
- connection->ConnectToService(&view_manager_client);
- omnibox_->Embed(view_manager_client.Pass());
+////////////////////////////////////////////////////////////////////////////////
+// DesktopUI, mojo::ViewManagerRootClient implementation:
- // TODO(beng): This should be handled sufficiently by
- // OmniboxImpl::ShowWindow() but unfortunately view manager policy
- // currently prevents the embedded app from changing window z for
- // its own window.
- omnibox_->MoveToFront();
+void DesktopUI::OnAccelerator(mojo::EventPtr event) {
+ DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK,
+ event->key_data->windows_key_code);
+ NOTIMPLEMENTED();
}
-void DesktopUI::OnURLChanged() {
- omnibox_launcher_->SetText(base::UTF8ToUTF16(browser_.current_url().spec()));
+////////////////////////////////////////////////////////////////////////////////
+// DesktopUI, web_view::mojom::WebViewClient implementation:
+
+void DesktopUI::TopLevelNavigate(mojo::URLRequestPtr request) {
+ Embed(request.Pass());
}
-void DesktopUI::LoadingStateChanged(bool loading) {
- progress_bar_->SetIsLoading(loading);
+void DesktopUI::LoadingStateChanged(bool is_loading) {
+ progress_bar_->SetIsLoading(is_loading);
}
void DesktopUI::ProgressChanged(double progress) {
@@ -140,6 +153,33 @@ void DesktopUI::ProgressChanged(double progress) {
}
////////////////////////////////////////////////////////////////////////////////
+// DesktopUI, ViewEmbedder implementation:
+
+void DesktopUI::Embed(mojo::URLRequestPtr request) {
+ const std::string string_url = request->url.To<std::string>();
+ if (string_url == "mojo:omnibox") {
+ EmbedOmnibox(omnibox_connection_.get());
+ return;
+ }
+
+ GURL gurl(string_url);
+ bool changed = current_url_ != gurl;
+ current_url_ = gurl;
+ if (changed)
+ omnibox_launcher_->SetText(base::UTF8ToUTF16(current_url_.spec()));
+
+ web_view_.web_view()->LoadRequest(request.Pass());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopUI, mojo::InterfaceFactory<ViewEmbedder> implementation:
+
+void DesktopUI::Create(mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<ViewEmbedder> request) {
+ view_embedder_bindings_.AddBinding(this, request.Pass());
+}
+
+////////////////////////////////////////////////////////////////////////////////
// DesktopUI, views::LayoutManager implementation:
gfx::Size DesktopUI::GetPreferredSize(const views::View* view) const {
@@ -163,8 +203,8 @@ void DesktopUI::Layout(views::View* host) {
content_bounds_mojo.width = progress_bar_bounds.width();
content_bounds_mojo.height =
host->bounds().height() - content_bounds_mojo.y - 10;
- browser_.content()->SetBounds(content_bounds_mojo);
- omnibox_->SetBounds(
+ content_->SetBounds(content_bounds_mojo);
+ omnibox_view_->SetBounds(
mojo::TypeConverter<mojo::Rect, gfx::Rect>::Convert(host->bounds()));
}
@@ -173,7 +213,71 @@ void DesktopUI::Layout(views::View* host) {
void DesktopUI::ButtonPressed(views::Button* sender, const ui::Event& event) {
DCHECK_EQ(sender, omnibox_launcher_);
- browser_.ShowOmnibox();
+ ShowOmnibox();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopUI, private:
+
+void DesktopUI::Init(mojo::View* root) {
+ DCHECK_GT(root->viewport_metrics().device_pixel_ratio, 0);
+ if (!aura_init_)
+ aura_init_.reset(new AuraInit(root, app_->shell()));
+
+ root_ = root;
+ omnibox_view_ = root_->view_manager()->CreateView();
+ root_->AddChild(omnibox_view_);
+
+ views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView;
+ widget_delegate->GetContentsView()->set_background(
+ views::Background::CreateSolidBackground(0xFFDDDDDD));
+ omnibox_launcher_ =
+ new views::LabelButton(this, base::ASCIIToUTF16("Open Omnibox"));
+ progress_bar_ = new ProgressView;
+
+ widget_delegate->GetContentsView()->AddChildView(omnibox_launcher_);
+ widget_delegate->GetContentsView()->AddChildView(progress_bar_);
+ widget_delegate->GetContentsView()->SetLayoutManager(this);
+
+ views::Widget* widget = new views::Widget;
+ views::Widget::InitParams params(
+ views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
+ params.native_widget =
+ new NativeWidgetViewManager(widget, app_->shell(), root_);
+ params.delegate = widget_delegate;
+ params.bounds = root_->bounds().To<gfx::Rect>();
+ widget->Init(params);
+ widget->Show();
+ root_->SetFocus();
+}
+
+void DesktopUI::ShowOmnibox() {
+ if (!omnibox_.get()) {
+ mojo::URLRequestPtr request(mojo::URLRequest::New());
+ request->url = mojo::String::From("mojo:omnibox");
+ omnibox_connection_ = app_->ConnectToApplication(request.Pass());
+ omnibox_connection_->AddService<ViewEmbedder>(this);
+ omnibox_connection_->ConnectToService(&omnibox_);
+ omnibox_connection_->SetRemoteServiceProviderConnectionErrorHandler(
+ [this]() {
+ // This will cause the connection to be re-established the next time
+ // we come through this codepath.
+ omnibox_.reset();
+ });
+ }
+ omnibox_->ShowForURL(mojo::String::From(current_url_.spec()));
+}
+
+void DesktopUI::EmbedOmnibox(mojo::ApplicationConnection* connection) {
+ mojo::ViewManagerClientPtr view_manager_client;
+ connection->ConnectToService(&view_manager_client);
+ omnibox_view_->Embed(view_manager_client.Pass());
+
+ // TODO(beng): This should be handled sufficiently by
+ // OmniboxImpl::ShowWindow() but unfortunately view manager policy
+ // currently prevents the embedded app from changing window z for
+ // its own window.
+ omnibox_view_->MoveToFront();
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/mandoline/ui/browser/desktop/desktop_ui.h b/mandoline/ui/browser/desktop/desktop_ui.h
index a539116..f1c0ca6 100644
--- a/mandoline/ui/browser/desktop/desktop_ui.h
+++ b/mandoline/ui/browser/desktop/desktop_ui.h
@@ -5,12 +5,21 @@
#ifndef MANDOLINE_UI_BROWSER_DESKTOP_DESKTOP_UI_H_
#define MANDOLINE_UI_BROWSER_DESKTOP_DESKTOP_UI_H_
+#include "components/view_manager/public/cpp/view_manager.h"
+#include "components/view_manager/public/cpp/view_manager_delegate.h"
+#include "components/view_manager/public/cpp/view_manager_init.h"
+#include "components/view_manager/public/interfaces/view_manager_root.mojom.h"
+#include "mandoline/tab/public/cpp/web_view.h"
+#include "mandoline/tab/public/interfaces/web_view.mojom.h"
#include "mandoline/ui/aura/aura_init.h"
-#include "mandoline/ui/browser/browser.h"
#include "mandoline/ui/browser/browser_ui.h"
#include "mandoline/ui/browser/public/interfaces/omnibox.mojom.h"
+#include "mandoline/ui/browser/public/interfaces/view_embedder.mojom.h"
+#include "mojo/application/public/cpp/interface_factory.h"
+#include "mojo/common/weak_binding_set.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/layout/layout_manager.h"
+#include "url/gurl.h"
namespace mojo {
class ApplicationConnection;
@@ -24,26 +33,44 @@ class LabelButton;
namespace mandoline {
-class Browser;
class ProgressView;
class DesktopUI : public BrowserUI,
+ public mojo::ViewManagerDelegate,
+ public mojo::ViewManagerRootClient,
+ public web_view::mojom::WebViewClient,
+ public ViewEmbedder,
+ public mojo::InterfaceFactory<ViewEmbedder>,
public views::LayoutManager,
public views::ButtonListener {
public:
- DesktopUI(mojo::ApplicationImpl* application_impl, BrowserManager* manager);
+ DesktopUI(mojo::ApplicationImpl* app, BrowserManager* manager);
~DesktopUI() override;
private:
- // Overridden from BrowserUI
- void Init(mojo::View* root) override;
+ // Overridden from BrowserUI:
void LoadURL(const GURL& url) override;
- void ViewManagerDisconnected() override;
- void EmbedOmnibox(mojo::ApplicationConnection* connection) override;
- void OnURLChanged() override;
- void LoadingStateChanged(bool loading) override;
+
+ // Overridden from mojo::ViewManagerDelegate:
+ void OnEmbed(mojo::View* root) override;
+ void OnViewManagerDestroyed(mojo::ViewManager* view_manager) override;
+
+ // Overridden from ViewManagerRootClient:
+ void OnAccelerator(mojo::EventPtr event) override;
+
+ // Overridden from web_view::mojom::WebViewClient:
+ void TopLevelNavigate(mojo::URLRequestPtr request) override;
+ void LoadingStateChanged(bool is_loading) override;
void ProgressChanged(double progress) override;
+ // Overridden from ViewEmbedder:
+ void Embed(mojo::URLRequestPtr request) override;
+
+ // Overridden from mojo::InterfaceFactory<ViewEmbedder>:
+ void Create(mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<ViewEmbedder> request) override;
+
+
// Overridden from views::LayoutManager:
gfx::Size GetPreferredSize(const views::View* view) const override;
void Layout(views::View* host) override;
@@ -51,17 +78,29 @@ class DesktopUI : public BrowserUI,
// Overridden from views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
+ void Init(mojo::View* root);
void ShowOmnibox();
+ void EmbedOmnibox(mojo::ApplicationConnection* connection);
- mojo::ApplicationImpl* application_impl_;
- Browser browser_;
- BrowserManager* manager_;
+ mojo::ApplicationImpl* app_;
scoped_ptr<AuraInit> aura_init_;
+ mojo::ViewManagerInit view_manager_init_;
+ BrowserManager* manager_;
views::LabelButton* omnibox_launcher_;
ProgressView* progress_bar_;
mojo::View* root_;
mojo::View* content_;
- mojo::View* omnibox_;
+ mojo::View* omnibox_view_;
+
+ mojo::WeakBindingSet<ViewEmbedder> view_embedder_bindings_;
+
+ GURL default_url_;
+ GURL current_url_;
+
+ web_view::WebView web_view_;
+
+ OmniboxPtr omnibox_;
+ scoped_ptr<mojo::ApplicationConnection> omnibox_connection_;
DISALLOW_COPY_AND_ASSIGN(DesktopUI);
};