summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-26 22:47:40 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-26 22:47:40 +0000
commit9d70b6adda0d7679bdc1ec82ffa1a526802d0112 (patch)
tree536390315c42aed1a888571778c7a0aea548328b /mojo
parent97ac197f96a95fcc83c2b371fe7ee7e26ad1d238 (diff)
downloadchromium_src-9d70b6adda0d7679bdc1ec82ffa1a526802d0112.zip
chromium_src-9d70b6adda0d7679bdc1ec82ffa1a526802d0112.tar.gz
chromium_src-9d70b6adda0d7679bdc1ec82ffa1a526802d0112.tar.bz2
Mojo: Plumb html_viewer.cc navigations through navigator interface.
Before it was just loading via URLLoader. Now window_manager is in the loop and knows about URL changes and can choose where to perform the nav. BUG=387216 R=darin@chromium.org Review URL: https://codereview.chromium.org/346343003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280143 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r--mojo/examples/html_viewer/html_document_view.cc63
-rw-r--r--mojo/examples/html_viewer/html_document_view.h18
-rw-r--r--mojo/examples/html_viewer/html_viewer.cc8
-rw-r--r--mojo/examples/window_manager/window_manager.cc12
-rw-r--r--mojo/public/cpp/application/lazy_interface_ptr.h39
-rw-r--r--mojo/services/public/interfaces/navigation/navigation.mojom4
6 files changed, 138 insertions, 6 deletions
diff --git a/mojo/examples/html_viewer/html_document_view.cc b/mojo/examples/html_viewer/html_document_view.cc
index b37d1e4..2f77f72 100644
--- a/mojo/examples/html_viewer/html_document_view.cc
+++ b/mojo/examples/html_viewer/html_document_view.cc
@@ -39,13 +39,49 @@ void ConfigureSettings(blink::WebSettings* settings) {
settings->setJavaScriptEnabled(true);
}
+navigation::Target WebNavigationPolicyToNavigationTarget(
+ blink::WebNavigationPolicy policy) {
+ switch (policy) {
+ case blink::WebNavigationPolicyCurrentTab:
+ return navigation::SOURCE_NODE;
+ case blink::WebNavigationPolicyNewBackgroundTab:
+ case blink::WebNavigationPolicyNewForegroundTab:
+ case blink::WebNavigationPolicyNewWindow:
+ case blink::WebNavigationPolicyNewPopup:
+ return navigation::NEW_NODE;
+ default:
+ return navigation::DEFAULT;
+ }
+}
+
+bool CanNavigateLocally(blink::WebFrame* frame,
+ const blink::WebURLRequest& request) {
+ // For now, we just load child frames locally.
+ // TODO(aa): In the future, this should use embedding to connect to a
+ // different instance of Blink if the frame is cross-origin.
+ if (frame->parent())
+ return true;
+
+ // If we have extraData() it means we already have the url response
+ // (presumably because we are being called via Navigate()). In that case we
+ // can go ahead and navigate locally.
+ if (request.extraData())
+ return true;
+
+ // Otherwise we don't know if we're the right app to handle this request. Ask
+ // host to do the navigation for us.
+ return false;
+}
+
} // namespace
-HTMLDocumentView::HTMLDocumentView(view_manager::ViewManager* view_manager)
+HTMLDocumentView::HTMLDocumentView(ServiceProvider* service_provider,
+ view_manager::ViewManager* view_manager)
: view_manager_(view_manager),
view_(view_manager::View::Create(view_manager_)),
web_view_(NULL),
repaint_pending_(false),
+ navigator_host_(service_provider),
weak_factory_(this) {
view_->AddObserver(this);
}
@@ -109,6 +145,24 @@ bool HTMLDocumentView::allowsBrokenNullLayerTreeView() const {
return true;
}
+blink::WebNavigationPolicy HTMLDocumentView::decidePolicyForNavigation(
+ blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* data,
+ const blink::WebURLRequest& request, blink::WebNavigationType nav_type,
+ blink::WebNavigationPolicy default_policy, bool is_redirect) {
+ if (CanNavigateLocally(frame, request))
+ return default_policy;
+
+ navigation::NavigationDetailsPtr nav_details(
+ navigation::NavigationDetails::New());
+ nav_details->url = request.url().string().utf8();
+ navigator_host_->RequestNavigate(
+ view_->node()->id(),
+ WebNavigationPolicyToNavigationTarget(default_policy),
+ nav_details.Pass());
+
+ return blink::WebNavigationPolicyIgnore;
+}
+
void HTMLDocumentView::didAddMessageToConsole(
const blink::WebConsoleMessage& message,
const blink::WebString& source_name,
@@ -117,6 +171,13 @@ void HTMLDocumentView::didAddMessageToConsole(
printf("### console: %s\n", std::string(message.text.utf8()).c_str());
}
+void HTMLDocumentView::didNavigateWithinPage(
+ blink::WebLocalFrame* frame, const blink::WebHistoryItem& history_item,
+ blink::WebHistoryCommitType commit_type) {
+ navigator_host_->DidNavigateLocally(view_->node()->id(),
+ history_item.urlString().utf8());
+}
+
void HTMLDocumentView::OnViewInputEvent(view_manager::View* view,
const EventPtr& event) {
scoped_ptr<blink::WebInputEvent> web_event =
diff --git a/mojo/examples/html_viewer/html_document_view.h b/mojo/examples/html_viewer/html_document_view.h
index 772a903..2f9f8e9 100644
--- a/mojo/examples/html_viewer/html_document_view.h
+++ b/mojo/examples/html_viewer/html_document_view.h
@@ -7,7 +7,10 @@
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
+#include "mojo/public/cpp/application/lazy_interface_ptr.h"
+#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/public/cpp/view_manager/view_observer.h"
+#include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
#include "mojo/services/public/interfaces/network/url_loader.mojom.h"
#include "third_party/WebKit/public/web/WebFrameClient.h"
#include "third_party/WebKit/public/web/WebViewClient.h"
@@ -27,7 +30,8 @@ class HTMLDocumentView : public blink::WebViewClient,
public blink::WebFrameClient,
public view_manager::ViewObserver {
public:
- explicit HTMLDocumentView(view_manager::ViewManager* view_manager);
+ HTMLDocumentView(ServiceProvider* service_provider,
+ view_manager::ViewManager* view_manager);
virtual ~HTMLDocumentView();
void AttachToNode(view_manager::Node* node);
@@ -44,11 +48,19 @@ class HTMLDocumentView : public blink::WebViewClient,
virtual bool allowsBrokenNullLayerTreeView() const;
// WebFrameClient methods:
+ virtual blink::WebNavigationPolicy decidePolicyForNavigation(
+ blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* data,
+ const blink::WebURLRequest& request, blink::WebNavigationType nav_type,
+ blink::WebNavigationPolicy default_policy, bool isRedirect) OVERRIDE;
virtual void didAddMessageToConsole(
const blink::WebConsoleMessage& message,
const blink::WebString& source_name,
unsigned source_line,
- const blink::WebString& stack_trace);
+ const blink::WebString& stack_trace) OVERRIDE;
+ virtual void didNavigateWithinPage(
+ blink::WebLocalFrame* frame,
+ const blink::WebHistoryItem& history_item,
+ blink::WebHistoryCommitType commit_type) OVERRIDE;
// ViewObserver methods:
virtual void OnViewInputEvent(view_manager::View* view,
@@ -60,9 +72,9 @@ class HTMLDocumentView : public blink::WebViewClient,
view_manager::View* view_;
blink::WebView* web_view_;
bool repaint_pending_;
+ LazyInterfacePtr<navigation::NavigatorHost> navigator_host_;
base::WeakPtrFactory<HTMLDocumentView> weak_factory_;
-
DISALLOW_COPY_AND_ASSIGN(HTMLDocumentView);
};
diff --git a/mojo/examples/html_viewer/html_viewer.cc b/mojo/examples/html_viewer/html_viewer.cc
index ad9bb8f..235d4ab 100644
--- a/mojo/examples/html_viewer/html_viewer.cc
+++ b/mojo/examples/html_viewer/html_viewer.cc
@@ -41,7 +41,7 @@ class NavigatorImpl : public InterfaceImpl<navigation::Navigator> {
class HTMLViewer : public ApplicationDelegate,
public view_manager::ViewManagerDelegate {
public:
- HTMLViewer() : document_view_(NULL) {
+ HTMLViewer() : application_impl_(NULL), document_view_(NULL) {
}
virtual ~HTMLViewer() {
blink::shutdown();
@@ -58,6 +58,7 @@ class HTMLViewer : public ApplicationDelegate,
private:
// Overridden from ApplicationDelegate:
virtual void Initialize(ApplicationImpl* app) OVERRIDE {
+ application_impl_ = app;
blink_platform_impl_.reset(new BlinkPlatformImpl(app));
blink::initialize(blink_platform_impl_.get());
}
@@ -72,7 +73,9 @@ class HTMLViewer : public ApplicationDelegate,
// Overridden from view_manager::ViewManagerDelegate:
virtual void OnRootAdded(view_manager::ViewManager* view_manager,
view_manager::Node* root) OVERRIDE {
- document_view_ = new HTMLDocumentView(view_manager);
+ document_view_ = new HTMLDocumentView(
+ application_impl_->ConnectToApplication("mojo://mojo_window_manager/")->
+ GetServiceProvider(), view_manager);
document_view_->AttachToNode(root);
MaybeLoad();
}
@@ -83,6 +86,7 @@ class HTMLViewer : public ApplicationDelegate,
}
scoped_ptr<BlinkPlatformImpl> blink_platform_impl_;
+ ApplicationImpl* application_impl_;
// TODO(darin): Figure out proper ownership of this instance.
HTMLDocumentView* document_view_;
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
index e737fbf..2ac4505 100644
--- a/mojo/examples/window_manager/window_manager.cc
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -85,6 +85,8 @@ class NavigatorHost : public InterfaceImpl<navigation::NavigatorHost> {
}
private:
+ virtual void DidNavigateLocally(uint32 source_node_id,
+ const mojo::String& url) OVERRIDE;
virtual void RequestNavigate(
uint32 source_node_id,
navigation::Target target,
@@ -209,6 +211,11 @@ class WindowManager : public ApplicationDelegate,
keyboard_manager_->Hide(view_id);
}
+ void DidNavigateLocally(uint32 source_node_id, const mojo::String& url) {
+ LOG(ERROR) << "DidNavigateLocally: source_node_id: " << source_node_id
+ << " url: " << url.To<std::string>();
+ }
+
void RequestNavigate(
uint32 source_node_id,
navigation::Target target,
@@ -435,6 +442,11 @@ void WindowManagerConnection::HideKeyboard(Id node_id) {
window_manager_->HideKeyboard(node_id);
}
+void NavigatorHost::DidNavigateLocally(uint32 source_node_id,
+ const mojo::String& url) {
+ window_manager_->DidNavigateLocally(source_node_id, url);
+}
+
void NavigatorHost::RequestNavigate(
uint32 source_node_id,
navigation::Target target,
diff --git a/mojo/public/cpp/application/lazy_interface_ptr.h b/mojo/public/cpp/application/lazy_interface_ptr.h
new file mode 100644
index 0000000..d8883c4
--- /dev/null
+++ b/mojo/public/cpp/application/lazy_interface_ptr.h
@@ -0,0 +1,39 @@
+// Copyright 2014 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 MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_
+#define MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_
+
+#include <string>
+
+#include "mojo/public/cpp/application/connect.h"
+#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
+
+namespace mojo {
+
+template<typename Interface>
+class LazyInterfacePtr : InterfacePtr<Interface> {
+ public:
+ LazyInterfacePtr(ServiceProvider* service_provider)
+ : service_provider_(service_provider) {
+ }
+
+ Interface* get() const {
+ if (!InterfacePtr<Interface>::get()) {
+ mojo::ConnectToService<Interface>(
+ service_provider_,
+ const_cast<LazyInterfacePtr<Interface>*>(this));
+ }
+ return InterfacePtr<Interface>::get();
+ }
+ Interface* operator->() const { return get(); }
+ Interface& operator*() const { return *get(); }
+
+ private:
+ ServiceProvider* service_provider_;
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_
diff --git a/mojo/services/public/interfaces/navigation/navigation.mojom b/mojo/services/public/interfaces/navigation/navigation.mojom
index 93da416..a08e361 100644
--- a/mojo/services/public/interfaces/navigation/navigation.mojom
+++ b/mojo/services/public/interfaces/navigation/navigation.mojom
@@ -34,6 +34,10 @@ struct ResponseDetails {
interface NavigatorHost {
RequestNavigate(uint32 source_node_id, Target target,
NavigationDetails details);
+
+ // Applications call this to inform hosts of navigations they performed
+ // locally. For example, pushState() navigations in an HTML application.
+ DidNavigateLocally(uint32 source_node_id, string url);
};
// Applications implement this interface to support navigation of their views