summaryrefslogtreecommitdiffstats
path: root/mandoline
diff options
context:
space:
mode:
authorben <ben@chromium.org>2015-08-17 13:59:30 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-17 21:00:07 +0000
commitd2592a31b796a09588bcae6bf13dbae472f9340f (patch)
treeb88481fcc61ae8d725d1c753b97c137cb39408c1 /mandoline
parentb309880538c512f3756f36cc038b6f275e1db29d (diff)
downloadchromium_src-d2592a31b796a09588bcae6bf13dbae472f9340f.zip
chromium_src-d2592a31b796a09588bcae6bf13dbae472f9340f.tar.gz
chromium_src-d2592a31b796a09588bcae6bf13dbae472f9340f.tar.bz2
Make an application wrapper around the mandoline/tab stuff.
BUG= Review URL: https://codereview.chromium.org/1293933002 Cr-Commit-Position: refs/heads/master@{#343749}
Diffstat (limited to 'mandoline')
-rw-r--r--mandoline/app/core_services_initialization.cc2
-rw-r--r--mandoline/services/core_services/BUILD.gn1
-rw-r--r--mandoline/services/core_services/core_services_application_delegate.cc3
-rw-r--r--mandoline/tab/BUILD.gn23
-rw-r--r--mandoline/tab/DEPS2
-rw-r--r--mandoline/tab/main.cc12
-rw-r--r--mandoline/tab/public/cpp/BUILD.gn20
-rw-r--r--mandoline/tab/public/cpp/DEPS3
-rw-r--r--mandoline/tab/public/cpp/web_view.cc33
-rw-r--r--mandoline/tab/public/cpp/web_view.h38
-rw-r--r--mandoline/tab/public/interfaces/BUILD.gn2
-rw-r--r--mandoline/tab/public/interfaces/web_view.mojom29
-rw-r--r--mandoline/tab/web_view_application_delegate.cc37
-rw-r--r--mandoline/tab/web_view_application_delegate.h47
-rw-r--r--mandoline/tab/web_view_impl.cc166
-rw-r--r--mandoline/tab/web_view_impl.h92
-rw-r--r--mandoline/ui/browser/BUILD.gn4
-rw-r--r--mandoline/ui/browser/browser.cc105
-rw-r--r--mandoline/ui/browser/browser.h33
19 files changed, 537 insertions, 115 deletions
diff --git a/mandoline/app/core_services_initialization.cc b/mandoline/app/core_services_initialization.cc
index 7f1dd12..1b3c45e 100644
--- a/mandoline/app/core_services_initialization.cc
+++ b/mandoline/app/core_services_initialization.cc
@@ -36,6 +36,8 @@ void InitCoreServicesForContext(mojo::runner::Context* context) {
GURL("mojo:omnibox"), GURL("mojo:core_services"), "Core");
#endif
manager->RegisterApplicationPackageAlias(
+ GURL("mojo:web_view"), GURL("mojo:core_services"), "Core");
+ manager->RegisterApplicationPackageAlias(
GURL("mojo:surfaces_service"), GURL("mojo:core_services"), "Surfaces");
manager->RegisterApplicationPackageAlias(
GURL("mojo:tracing"), GURL("mojo:core_services"), "Sandboxed Core");
diff --git a/mandoline/services/core_services/BUILD.gn b/mandoline/services/core_services/BUILD.gn
index cb8d9f9..4678d7f 100644
--- a/mandoline/services/core_services/BUILD.gn
+++ b/mandoline/services/core_services/BUILD.gn
@@ -47,6 +47,7 @@ source_set("sources") {
"//components/clipboard:lib",
"//components/filesystem:lib",
"//components/view_manager/surfaces:lib",
+ "//mandoline/tab:lib",
"//mandoline/ui/browser:lib",
"//mojo/application/public/cpp",
"//mojo/common:tracing_impl",
diff --git a/mandoline/services/core_services/core_services_application_delegate.cc b/mandoline/services/core_services/core_services_application_delegate.cc
index 01e4e51..80b2c7f 100644
--- a/mandoline/services/core_services/core_services_application_delegate.cc
+++ b/mandoline/services/core_services/core_services_application_delegate.cc
@@ -11,6 +11,7 @@
#include "components/filesystem/file_system_app.h"
#include "components/view_manager/surfaces/surfaces_service_application.h"
#include "mandoline/services/core_services/application_delegate_factory.h"
+#include "mandoline/tab/web_view_application_delegate.h"
#include "mandoline/ui/browser/browser_manager.h"
#include "mojo/application/public/cpp/application_connection.h"
#include "mojo/application/public/cpp/application_impl.h"
@@ -125,6 +126,8 @@ void CoreServicesApplicationDelegate::StartApplication(
delegate.reset(new surfaces::SurfacesServiceApplication);
} else if (url == "mojo://tracing/") {
delegate.reset(new tracing::TracingApp);
+ } else if (url == "mojo://web_view/") {
+ delegate.reset(new web_view::WebViewApplicationDelegate);
} else {
#if defined(USE_AURA)
delegate = CreateApplicationDelegateAura(url);
diff --git a/mandoline/tab/BUILD.gn b/mandoline/tab/BUILD.gn
index 92851cb..feb315d 100644
--- a/mandoline/tab/BUILD.gn
+++ b/mandoline/tab/BUILD.gn
@@ -4,7 +4,7 @@
import("//mojo/public/mojo_application.gni")
-source_set("tab") {
+source_set("lib") {
sources = [
"frame.cc",
"frame.h",
@@ -14,6 +14,10 @@ source_set("tab") {
"frame_tree.h",
"frame_tree_delegate.h",
"frame_user_data.h",
+ "web_view_application_delegate.cc",
+ "web_view_application_delegate.h",
+ "web_view_impl.cc",
+ "web_view_impl.h",
]
deps = [
@@ -25,6 +29,8 @@ source_set("tab") {
"//components/view_manager/public/interfaces",
"//mojo/application/public/cpp:sources",
"//mojo/application/public/interfaces",
+ "//mojo/common:common_base",
+ "//mojo/converters/geometry",
"//mojo/services/network/public/interfaces",
"//third_party/mojo/src/mojo/public/cpp/bindings",
]
@@ -38,13 +44,24 @@ source_set("tab") {
}
}
+mojo_native_application("web_view") {
+ sources = [
+ "main.cc",
+ ]
+
+ deps = [
+ ":lib",
+ "//mojo/application/public/cpp",
+ ]
+}
+
source_set("test_support") {
sources = [
"test_frame_tree_delegate.cc",
"test_frame_tree_delegate.h",
]
deps = [
- ":tab",
+ ":lib",
"//base",
]
}
@@ -57,7 +74,7 @@ mojo_native_application("mandoline_frame_apptests") {
]
deps = [
- ":tab",
+ ":lib",
":test_support",
"//base",
"//base/test:test_config",
diff --git a/mandoline/tab/DEPS b/mandoline/tab/DEPS
index 6526ae6..8c2e530 100644
--- a/mandoline/tab/DEPS
+++ b/mandoline/tab/DEPS
@@ -5,6 +5,8 @@ include_rules = [
"+components/resource_provider/public/interfaces",
"+components/view_manager/public",
"+mojo/application/public",
+ "+mojo/common",
+ "+mojo/converters/geometry",
"+mojo/services/network/public/interfaces",
"+third_party/mojo/src/mojo/public",
]
diff --git a/mandoline/tab/main.cc b/mandoline/tab/main.cc
new file mode 100644
index 0000000..005465e
--- /dev/null
+++ b/mandoline/tab/main.cc
@@ -0,0 +1,12 @@
+// 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/tab/web_view_application_delegate.h"
+#include "mojo/application/public/cpp/application_runner.h"
+#include "third_party/mojo/src/mojo/public/c/system/main.h"
+
+MojoResult MojoMain(MojoHandle shell_handle) {
+ mojo::ApplicationRunner runner(new web_view::WebViewApplicationDelegate);
+ return runner.Run(shell_handle);
+}
diff --git a/mandoline/tab/public/cpp/BUILD.gn b/mandoline/tab/public/cpp/BUILD.gn
new file mode 100644
index 0000000..294d7fa
--- /dev/null
+++ b/mandoline/tab/public/cpp/BUILD.gn
@@ -0,0 +1,20 @@
+# 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.
+
+source_set("cpp") {
+ sources = [
+ "web_view.cc",
+ "web_view.h",
+ ]
+
+ deps = [
+ "//base",
+ "//components/view_manager/public/cpp",
+ "//mandoline/tab/public/interfaces",
+ "//mojo/application/public/cpp",
+ "//mojo/converters/geometry",
+ "//third_party/mojo/src/mojo/public/cpp/bindings",
+ "//third_party/mojo/src/mojo/public/cpp/system",
+ ]
+}
diff --git a/mandoline/tab/public/cpp/DEPS b/mandoline/tab/public/cpp/DEPS
new file mode 100644
index 0000000..6cfa565
--- /dev/null
+++ b/mandoline/tab/public/cpp/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+mojo/common",
+]
diff --git a/mandoline/tab/public/cpp/web_view.cc b/mandoline/tab/public/cpp/web_view.cc
new file mode 100644
index 0000000..d8773c2
--- /dev/null
+++ b/mandoline/tab/public/cpp/web_view.cc
@@ -0,0 +1,33 @@
+// 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/tab/public/cpp/web_view.h"
+
+#include "components/view_manager/public/cpp/view.h"
+#include "mojo/application/public/cpp/application_impl.h"
+
+namespace web_view {
+
+WebView::WebView(mojom::WebViewClient* client) : binding_(client) {}
+WebView::~WebView() {}
+
+void WebView::Init(mojo::ApplicationImpl* app, mojo::View* view) {
+ mojo::URLRequestPtr request(mojo::URLRequest::New());
+ request->url = "mojo:web_view";
+
+ mojom::WebViewClientPtr client;
+ mojo::InterfaceRequest<mojom::WebViewClient> client_request =
+ GetProxy(&client);
+ binding_.Bind(client_request.Pass());
+
+ mojom::WebViewFactoryPtr factory;
+ app->ConnectToService(request.Pass(), &factory);
+ factory->CreateWebView(client.Pass(), GetProxy(&web_view_));
+
+ mojo::ViewManagerClientPtr view_manager_client;
+ web_view_->GetViewManagerClient(GetProxy(&view_manager_client));
+ view->Embed(view_manager_client.Pass());
+}
+
+} // namespace web_view
diff --git a/mandoline/tab/public/cpp/web_view.h b/mandoline/tab/public/cpp/web_view.h
new file mode 100644
index 0000000..39385f2
--- /dev/null
+++ b/mandoline/tab/public/cpp/web_view.h
@@ -0,0 +1,38 @@
+// 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_TAB_PUBLIC_CPP_WEB_VIEW_H_
+#define MANDOLINE_TAB_PUBLIC_CPP_WEB_VIEW_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "mandoline/tab/public/interfaces/web_view.mojom.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
+
+namespace mojo {
+class ApplicationImpl;
+class View;
+}
+
+namespace web_view {
+
+class WebView {
+ public:
+ explicit WebView(mojom::WebViewClient* client);
+ ~WebView();
+
+ void Init(mojo::ApplicationImpl* app, mojo::View* view);
+
+ mojom::WebView* web_view() { return web_view_.get(); }
+
+ private:
+ mojom::WebViewPtr web_view_;
+ mojo::Binding<mojom::WebViewClient> binding_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebView);
+};
+
+} // namespace web_view
+
+#endif // MANDOLINE_TAB_PUBLIC_CPP_WEB_VIEW_H_
diff --git a/mandoline/tab/public/interfaces/BUILD.gn b/mandoline/tab/public/interfaces/BUILD.gn
index 299656b..4805066 100644
--- a/mandoline/tab/public/interfaces/BUILD.gn
+++ b/mandoline/tab/public/interfaces/BUILD.gn
@@ -8,11 +8,13 @@ import("//third_party/mojo/src/mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") {
sources = [
"frame_tree.mojom",
+ "web_view.mojom",
]
import_dirs = [ mojo_network_service_root ]
deps = [
+ "//components/view_manager/public/interfaces",
"//mojo/services/network/public/interfaces",
]
}
diff --git a/mandoline/tab/public/interfaces/web_view.mojom b/mandoline/tab/public/interfaces/web_view.mojom
new file mode 100644
index 0000000..9a07036
--- /dev/null
+++ b/mandoline/tab/public/interfaces/web_view.mojom
@@ -0,0 +1,29 @@
+// 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.
+
+module web_view.mojom;
+
+import "network/public/interfaces/url_loader.mojom";
+import "components/view_manager/public/interfaces/view_manager.mojom";
+
+interface WebViewClient {
+ // Page-generated request for a top level frame navigation.
+ TopLevelNavigate(mojo.URLRequest request);
+
+ // Loading and progress notifications.
+ LoadingStateChanged(bool is_loading);
+ ProgressChanged(double progress);
+};
+
+interface WebView {
+ // Navigate the top level frame to |request|.
+ LoadRequest(mojo.URLRequest request);
+
+ // Provide a ViewManagerClient for this specific WebView.
+ GetViewManagerClient(mojo.ViewManagerClient& view_manager_client);
+};
+
+interface WebViewFactory {
+ CreateWebView(WebViewClient client, WebView& web_view);
+};
diff --git a/mandoline/tab/web_view_application_delegate.cc b/mandoline/tab/web_view_application_delegate.cc
new file mode 100644
index 0000000..bf6f085
--- /dev/null
+++ b/mandoline/tab/web_view_application_delegate.cc
@@ -0,0 +1,37 @@
+// 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/tab/web_view_application_delegate.h"
+
+#include "mandoline/tab/web_view_impl.h"
+#include "mojo/application/public/cpp/application_connection.h"
+
+namespace web_view {
+
+WebViewApplicationDelegate::WebViewApplicationDelegate() : app_(nullptr) {}
+WebViewApplicationDelegate::~WebViewApplicationDelegate() {}
+
+void WebViewApplicationDelegate::Initialize(mojo::ApplicationImpl* app) {
+ app_ = app;
+}
+
+bool WebViewApplicationDelegate::ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) {
+ connection->AddService<mojom::WebViewFactory>(this);
+ return true;
+}
+
+void WebViewApplicationDelegate::CreateWebView(
+ mojom::WebViewClientPtr client,
+ mojo::InterfaceRequest<mojom::WebView> web_view) {
+ new WebViewImpl(app_, client.Pass(), web_view.Pass());
+}
+
+void WebViewApplicationDelegate::Create(
+ mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<mojom::WebViewFactory> request) {
+ factory_bindings_.AddBinding(this, request.Pass());
+}
+
+} // namespace web_view
diff --git a/mandoline/tab/web_view_application_delegate.h b/mandoline/tab/web_view_application_delegate.h
new file mode 100644
index 0000000..c89212b
--- /dev/null
+++ b/mandoline/tab/web_view_application_delegate.h
@@ -0,0 +1,47 @@
+// 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_TAB_WEB_VIEW_APPLICATION_DELEGATE_H_
+#define MANDOLINE_TAB_WEB_VIEW_APPLICATION_DELEGATE_H_
+
+#include "base/macros.h"
+#include "mandoline/tab/public/interfaces/web_view.mojom.h"
+#include "mojo/application/public/cpp/application_delegate.h"
+#include "mojo/application/public/cpp/interface_factory.h"
+#include "mojo/common/weak_binding_set.h"
+
+namespace web_view {
+
+class WebViewApplicationDelegate
+ : public mojo::ApplicationDelegate,
+ public mojom::WebViewFactory,
+ public mojo::InterfaceFactory<mojom::WebViewFactory> {
+ public:
+ WebViewApplicationDelegate();
+ ~WebViewApplicationDelegate() override;
+
+ private:
+ // Overridden from mojo::ApplicationDelegate:
+ void Initialize(mojo::ApplicationImpl* app) override;
+ bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) override;
+
+ // Overridden from mojom::WebViewFactory:
+ void CreateWebView(mojom::WebViewClientPtr client,
+ mojo::InterfaceRequest<mojom::WebView> web_view) override;
+
+ // Overridden from mojo::InterfaceFactory<mojom::WebView>:
+ void Create(mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<mojom::WebViewFactory> request) override;
+
+ mojo::ApplicationImpl* app_;
+
+ mojo::WeakBindingSet<WebViewFactory> factory_bindings_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebViewApplicationDelegate);
+};
+
+} // namespace web_view
+
+#endif // MANDOLINE_TAB_WEB_VIEW_APPLICATION_DELEGATE_H_
diff --git a/mandoline/tab/web_view_impl.cc b/mandoline/tab/web_view_impl.cc
new file mode 100644
index 0000000..1856381
--- /dev/null
+++ b/mandoline/tab/web_view_impl.cc
@@ -0,0 +1,166 @@
+// 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/tab/web_view_impl.h"
+
+#include "components/view_manager/public/cpp/view.h"
+#include "components/view_manager/public/cpp/view_manager.h"
+#include "mandoline/tab/frame.h"
+#include "mandoline/tab/frame_connection.h"
+#include "mandoline/tab/frame_tree.h"
+#include "mojo/application/public/cpp/application_impl.h"
+#include "mojo/converters/geometry/geometry_type_converters.h"
+
+// TODO(beng): remove once these classes are in the web_view namespace.
+using mandoline::FrameTreeClient;
+using mandoline::FrameConnection;
+
+namespace web_view {
+
+////////////////////////////////////////////////////////////////////////////////
+// WebViewImpl, public:
+
+WebViewImpl::WebViewImpl(mojo::ApplicationImpl* app,
+ mojom::WebViewClientPtr client,
+ mojo::InterfaceRequest<mojom::WebView> request)
+ : app_(app),
+ client_(client.Pass()),
+ binding_(this, request.Pass()),
+ content_(nullptr),
+ view_manager_client_factory_(app->shell(), this) {
+}
+
+WebViewImpl::~WebViewImpl() {}
+
+////////////////////////////////////////////////////////////////////////////////
+// WebViewImpl, WebView implementation:
+
+void WebViewImpl::LoadRequest(mojo::URLRequestPtr request) {
+ if (!content_) {
+ // We haven't been embedded yet, store the request for when we are.
+ pending_request_ = request.Pass();
+ return;
+ }
+ scoped_ptr<FrameConnection> frame_connection(new FrameConnection);
+ mojo::ViewManagerClientPtr view_manager_client;
+ frame_connection->Init(app_, request.Pass(), &view_manager_client);
+ FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client();
+ frame_tree_.reset(new FrameTree(content_, this, frame_tree_client,
+ frame_connection.Pass()));
+ content_->Embed(view_manager_client.Pass());
+}
+
+void WebViewImpl::GetViewManagerClient(
+ mojo::InterfaceRequest<mojo::ViewManagerClient> view_manager_client) {
+ view_manager_client_factory_.Create(nullptr, view_manager_client.Pass());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// WebViewImpl, mojo::ViewManagerDelegate implementation:
+
+void WebViewImpl::OnEmbed(mojo::View* root) {
+ root->view_manager()->SetEmbedRoot();
+ root->AddObserver(this);
+ content_ = root->view_manager()->CreateView();
+ root->AddChild(content_);
+ content_->SetVisible(true);
+ content_->AddObserver(this);
+
+ if (!pending_request_.is_null())
+ LoadRequest(pending_request_.Pass());
+}
+
+void WebViewImpl::OnEmbedForDescendant(mojo::View* view,
+ mojo::URLRequestPtr request,
+ mojo::ViewManagerClientPtr* client) {
+ // TODO(sky): move this to Frame/FrameTree.
+ Frame* frame = Frame::FindFirstFrameAncestor(view);
+ if (!frame || !frame->HasAncestor(frame_tree_->root())) {
+ // TODO(sky): add requestor url so that we can return false if it's not
+ // an app we expect.
+ scoped_ptr<mojo::ApplicationConnection> connection =
+ app_->ConnectToApplication(request.Pass());
+ connection->ConnectToService(client);
+ return;
+ }
+
+ scoped_ptr<FrameConnection> frame_connection(new FrameConnection);
+ frame_connection->Init(app_, request.Pass(), client);
+ FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client();
+ frame_tree_->CreateOrReplaceFrame(frame, view, frame_tree_client,
+ frame_connection.Pass());
+}
+
+void WebViewImpl::OnViewManagerDestroyed(mojo::ViewManager* view_manager) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// WebViewImpl, mojo::ViewObserver implementation:
+
+void WebViewImpl::OnViewBoundsChanged(mojo::View* view,
+ const mojo::Rect& old_bounds,
+ const mojo::Rect& new_bounds) {
+ if (view != content_) {
+ mojo::Rect rect;
+ rect.width = new_bounds.width;
+ rect.height = new_bounds.height;
+ content_->SetBounds(rect);
+ }
+}
+
+void WebViewImpl::OnViewDestroyed(mojo::View* view) {
+ // |FrameTree| cannot outlive the content view.
+ if (view == content_)
+ frame_tree_.reset();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// WebViewImpl, mandoline::FrameTreeDelegate implementation:
+
+bool WebViewImpl::CanPostMessageEventToFrame(const Frame* source,
+ const Frame* target,
+ HTMLMessageEvent* event) {
+ return true;
+}
+
+void WebViewImpl::LoadingStateChanged(bool loading) {
+ client_->LoadingStateChanged(loading);
+}
+
+void WebViewImpl::ProgressChanged(double progress) {
+ client_->ProgressChanged(progress);
+}
+
+void WebViewImpl::RequestNavigate(Frame* source,
+ mandoline::NavigationTargetType target_type,
+ Frame* target_frame,
+ mojo::URLRequestPtr request) {
+ // TODO: this needs security checks.
+ if (target_type == mandoline::NAVIGATION_TARGET_TYPE_EXISTING_FRAME) {
+ if (target_frame && target_frame != frame_tree_->root() &&
+ target_frame->view()) {
+ NavigateExistingFrame(target_frame, request.Pass());
+ return;
+ }
+ DVLOG(1) << "RequestNavigate() targeted existing frame that doesn't exist.";
+ return;
+ }
+ client_->TopLevelNavigate(request.Pass());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// WebViewImpl, private:
+
+void WebViewImpl::NavigateExistingFrame(Frame* frame,
+ mojo::URLRequestPtr request) {
+ scoped_ptr<FrameConnection> frame_connection(new FrameConnection);
+ mojo::ViewManagerClientPtr view_manager_client;
+ frame_connection->Init(app_, request.Pass(), &view_manager_client);
+ frame->view()->Embed(view_manager_client.Pass());
+ FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client();
+ frame_tree_->CreateOrReplaceFrame(frame, frame->view(), frame_tree_client,
+ frame_connection.Pass());
+}
+
+} // namespace web_view
diff --git a/mandoline/tab/web_view_impl.h b/mandoline/tab/web_view_impl.h
new file mode 100644
index 0000000..fdd69c3
--- /dev/null
+++ b/mandoline/tab/web_view_impl.h
@@ -0,0 +1,92 @@
+// 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_TAB_WEB_VIEW_IMPL_H_
+#define MANDOLINE_TAB_WEB_VIEW_IMPL_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "components/view_manager/public/cpp/view_manager_client_factory.h"
+#include "components/view_manager/public/cpp/view_manager_delegate.h"
+#include "components/view_manager/public/cpp/view_observer.h"
+#include "mandoline/tab/frame_tree_delegate.h"
+#include "mandoline/tab/public/interfaces/web_view.mojom.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
+
+namespace mandoline {
+class Frame;
+class FrameTree;
+class HTMLMessageEvent;
+}
+
+namespace mojo {
+class ApplicationImpl;
+}
+
+// TODO(beng): remove once these classes are in the web_view namespace.
+using mandoline::Frame;
+using mandoline::FrameTree;
+using mandoline::HTMLMessageEvent;
+
+namespace web_view {
+
+class WebViewImpl : public mojom::WebView,
+ public mojo::ViewManagerDelegate,
+ public mojo::ViewObserver,
+ public mandoline::FrameTreeDelegate {
+ public:
+ WebViewImpl(mojo::ApplicationImpl* app,
+ mojom::WebViewClientPtr client,
+ mojo::InterfaceRequest<WebView> request);
+ ~WebViewImpl() override;
+
+ private:
+ // Overridden from WebView:
+ void LoadRequest(mojo::URLRequestPtr request) override;
+ void GetViewManagerClient(
+ mojo::InterfaceRequest<mojo::ViewManagerClient> view_manager_client)
+ override;
+
+ // Overridden from mojo::ViewManagerDelegate:
+ void OnEmbed(mojo::View* root) override;
+ void OnEmbedForDescendant(mojo::View* view,
+ mojo::URLRequestPtr request,
+ mojo::ViewManagerClientPtr* client) override;
+ void OnViewManagerDestroyed(mojo::ViewManager* view_manager) override;
+
+ // Overridden from mojo::ViewObserver:
+ void OnViewBoundsChanged(mojo::View* view,
+ const mojo::Rect& old_bounds,
+ const mojo::Rect& new_bounds) override;
+ void OnViewDestroyed(mojo::View* view) override;
+
+ // Overridden from mandoline::FrameTreeDelegate:
+ bool CanPostMessageEventToFrame(const Frame* source,
+ const Frame* target,
+ HTMLMessageEvent* event) override;
+ void LoadingStateChanged(bool loading) override;
+ void ProgressChanged(double progress) override;
+ void RequestNavigate(Frame* source,
+ mandoline::NavigationTargetType target_type,
+ Frame* target_frame,
+ mojo::URLRequestPtr request) override;
+
+ // Loads |request| in |frame|.
+ void NavigateExistingFrame(Frame* frame, mojo::URLRequestPtr request);
+
+ mojo::ApplicationImpl* app_;
+ mojom::WebViewClientPtr client_;
+ mojo::StrongBinding<WebView> binding_;
+ mojo::View* content_;
+ scoped_ptr<FrameTree> frame_tree_;
+ mojo::ViewManagerClientFactory view_manager_client_factory_;
+
+ mojo::URLRequestPtr pending_request_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebViewImpl);
+};
+
+} // namespace web_view
+
+#endif // MANDOLINE_TAB_WEB_VIEW_IMPL_H_
diff --git a/mandoline/ui/browser/BUILD.gn b/mandoline/ui/browser/BUILD.gn
index b0328f9..7104b23 100644
--- a/mandoline/ui/browser/BUILD.gn
+++ b/mandoline/ui/browser/BUILD.gn
@@ -37,7 +37,8 @@ source_set("lib") {
"//base",
"//components/view_manager/public/cpp",
"//mandoline/services/navigation/public/interfaces",
- "//mandoline/tab",
+ "//mandoline/tab/public/cpp",
+ "//mandoline/tab/public/interfaces",
"//mojo/application/public/cpp:sources",
"//mojo/common:common_base",
"//mojo/converters/geometry",
@@ -78,7 +79,6 @@ mojo_native_application("mandoline_browser_apptests") {
"//base",
"//base/test:test_config",
"//components/view_manager/public/cpp",
- "//mandoline/tab/public/interfaces",
"//mandoline/ui/browser:lib",
"//mojo/application/public/cpp:sources",
"//mojo/application/public/cpp:test_support",
diff --git a/mandoline/ui/browser/browser.cc b/mandoline/ui/browser/browser.cc
index def4a9f..ce30699 100644
--- a/mandoline/ui/browser/browser.cc
+++ b/mandoline/ui/browser/browser.cc
@@ -8,9 +8,6 @@
#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/tab/frame.h"
-#include "mandoline/tab/frame_connection.h"
-#include "mandoline/tab/frame_tree.h"
#include "mandoline/ui/browser/browser_delegate.h"
#include "mandoline/ui/browser/browser_ui.h"
#include "mojo/application/public/cpp/application_runner.h"
@@ -41,6 +38,7 @@ Browser::Browser(mojo::ApplicationImpl* app,
content_(nullptr),
default_url_(default_url),
navigator_host_(this),
+ web_view_(this),
app_(app),
delegate_(delegate) {
ui_.reset(BrowserUI::Create(this, app));
@@ -78,16 +76,6 @@ mojo::ApplicationConnection* Browser::GetViewManagerConnectionForTesting() {
return view_manager_init_.connection();
}
-void Browser::NavigateExistingFrame(Frame* frame, mojo::URLRequestPtr request) {
- scoped_ptr<FrameConnection> frame_connection(new FrameConnection);
- mojo::ViewManagerClientPtr view_manager_client;
- frame_connection->Init(app_, request.Pass(), &view_manager_client);
- frame->view()->Embed(view_manager_client.Pass());
- FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client();
- frame_tree_->CreateOrReplaceFrame(frame, frame->view(), frame_tree_client,
- frame_connection.Pass());
-}
-
void Browser::OnEmbed(mojo::View* root) {
// Browser does not support being embedded more than once.
CHECK(!root_);
@@ -112,40 +100,19 @@ void Browser::OnEmbed(mojo::View* root) {
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, either load a pending url or the default url.
- if (pending_request_) {
- Embed(pending_request_.Pass());
- } else if (default_url_.is_valid()) {
+ // 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::OnEmbedForDescendant(mojo::View* view,
- mojo::URLRequestPtr request,
- mojo::ViewManagerClientPtr* client) {
- // TODO(sky): move this to Frame/FrameTree.
- Frame* frame = Frame::FindFirstFrameAncestor(view);
- if (!frame || !frame->HasAncestor(frame_tree_->root())) {
- // TODO(sky): add requestor url so that we can return false if it's not
- // an app we expect.
- scoped_ptr<mojo::ApplicationConnection> connection =
- app_->ConnectToApplication(request.Pass());
- connection->ConnectToService(client);
- return;
- }
-
- scoped_ptr<FrameConnection> frame_connection(new FrameConnection);
- frame_connection->Init(app_, request.Pass(), client);
- FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client();
- frame_tree_->CreateOrReplaceFrame(frame, view, frame_tree_client,
- frame_connection.Pass());
-}
-
void Browser::OnViewManagerDestroyed(mojo::ViewManager* view_manager) {
ui_.reset();
root_ = nullptr;
@@ -158,6 +125,18 @@ void Browser::OnAccelerator(mojo::EventPtr event) {
navigator_host_.RequestNavigateHistory(-1);
}
+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) {
@@ -167,48 +146,17 @@ void Browser::Embed(mojo::URLRequestPtr request) {
return;
}
- // We can get Embed calls before we've actually been
- // embedded into the root view and content_ is created.
- // Just save the last url, we'll embed it when we're ready.
- if (!content_) {
- pending_request_ = request.Pass();
- return;
- }
-
GURL gurl(string_url);
bool changed = current_url_ != gurl;
current_url_ = gurl;
if (changed)
ui_->OnURLChanged();
- scoped_ptr<FrameConnection> frame_connection(new FrameConnection);
- mojo::ViewManagerClientPtr view_manager_client;
- frame_connection->Init(app_, request.Pass(), &view_manager_client);
- frame_connection->application_connection()->AddService<mojo::NavigatorHost>(
- this);
- FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client();
- frame_tree_.reset(new FrameTree(content_, this, frame_tree_client,
- frame_connection.Pass()));
- content_->Embed(view_manager_client.Pass());
- LoadingStateChanged(true);
+ web_view_.web_view()->LoadRequest(request.Pass());
navigator_host_.RecordNavigation(gurl.spec());
}
-bool Browser::CanPostMessageEventToFrame(const Frame* source,
- const Frame* target,
- HTMLMessageEvent* event) {
- return true;
-}
-
-void Browser::LoadingStateChanged(bool loading) {
- ui_->LoadingStateChanged(loading);
-}
-
-void Browser::ProgressChanged(double progress) {
- ui_->ProgressChanged(progress);
-}
-
void Browser::Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mojo::NavigatorHost> request) {
navigator_host_.Bind(request.Pass());
@@ -219,21 +167,4 @@ void Browser::Create(mojo::ApplicationConnection* connection,
view_embedder_bindings_.AddBinding(this, request.Pass());
}
-void Browser::RequestNavigate(Frame* source,
- NavigationTargetType target_type,
- Frame* target_frame,
- mojo::URLRequestPtr request) {
- // TODO: this needs security checks.
- if (target_type == NAVIGATION_TARGET_TYPE_EXISTING_FRAME) {
- if (target_frame && target_frame != frame_tree_->root() &&
- target_frame->view()) {
- NavigateExistingFrame(target_frame, request.Pass());
- return;
- }
- DVLOG(1) << "RequestNavigate() targeted existing frame that doesn't exist.";
- return;
- }
- ReplaceContentWithRequest(request.Pass());
-}
-
} // namespace mandoline
diff --git a/mandoline/ui/browser/browser.h b/mandoline/ui/browser/browser.h
index e55fa30..20bc4e0 100644
--- a/mandoline/ui/browser/browser.h
+++ b/mandoline/ui/browser/browser.h
@@ -11,7 +11,8 @@
#include "components/view_manager/public/cpp/view_manager_init.h"
#include "components/view_manager/public/interfaces/view_manager_root.mojom.h"
#include "mandoline/services/navigation/public/interfaces/navigation.mojom.h"
-#include "mandoline/tab/frame_tree_delegate.h"
+#include "mandoline/tab/public/cpp/web_view.h"
+#include "mandoline/tab/public/interfaces/web_view.mojom.h"
#include "mandoline/ui/browser/navigator_host_impl.h"
#include "mandoline/ui/browser/public/interfaces/omnibox.mojom.h"
#include "mandoline/ui/browser/public/interfaces/view_embedder.mojom.h"
@@ -32,12 +33,11 @@ FORWARD_DECLARE_TEST(BrowserTest, ClosingBrowserClosesAppConnection);
class BrowserDelegate;
class BrowserUI;
-class FrameTree;
class Browser : public mojo::ViewManagerDelegate,
public mojo::ViewManagerRootClient,
+ public web_view::mojom::WebViewClient,
public ViewEmbedder,
- public FrameTreeDelegate,
public mojo::InterfaceFactory<mojo::NavigatorHost>,
public mojo::InterfaceFactory<ViewEmbedder> {
public:
@@ -63,33 +63,21 @@ class Browser : public mojo::ViewManagerDelegate,
mojo::ApplicationConnection* GetViewManagerConnectionForTesting();
- // Loads |request| in |frame|.
- void NavigateExistingFrame(Frame* frame, mojo::URLRequestPtr request);
-
// Overridden from mojo::ViewManagerDelegate:
void OnEmbed(mojo::View* root) override;
- void OnEmbedForDescendant(mojo::View* view,
- mojo::URLRequestPtr request,
- mojo::ViewManagerClientPtr* client) 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 FrameTreeDelegate:
- bool CanPostMessageEventToFrame(const Frame* source,
- const Frame* target,
- HTMLMessageEvent* event) override;
- void LoadingStateChanged(bool loading) override;
- void ProgressChanged(double progress) override;
- void RequestNavigate(Frame* source,
- NavigationTargetType target_type,
- Frame* target_frame,
- mojo::URLRequestPtr request) override;
-
// Overridden from mojo::InterfaceFactory<mojo::NavigatorHost>:
void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mojo::NavigatorHost> request) override;
@@ -105,7 +93,6 @@ class Browser : public mojo::ViewManagerDelegate,
mojo::View* root_;
mojo::View* content_;
GURL default_url_;
- mojo::URLRequestPtr pending_request_;
mojo::WeakBindingSet<ViewEmbedder> view_embedder_bindings_;
@@ -113,6 +100,8 @@ class Browser : public mojo::ViewManagerDelegate,
GURL current_url_;
+ web_view::WebView web_view_;
+
OmniboxPtr omnibox_;
scoped_ptr<mojo::ApplicationConnection> omnibox_connection_;
@@ -120,8 +109,6 @@ class Browser : public mojo::ViewManagerDelegate,
mojo::ApplicationImpl* app_;
BrowserDelegate* delegate_;
- scoped_ptr<FrameTree> frame_tree_;
-
DISALLOW_COPY_AND_ASSIGN(Browser);
};