diff options
author | sadrul <sadrul@chromium.org> | 2015-09-28 08:47:08 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-28 15:47:53 +0000 |
commit | 367c9c47fd5dac05688ac2fe864db26d780e7c33 (patch) | |
tree | ef01b984c02f8919c1d3b580b89aa53829aaeffe /components/web_view | |
parent | 072a708b34caad4e046623c2a1c237dc751b92b9 (diff) | |
download | chromium_src-367c9c47fd5dac05688ac2fe864db26d780e7c33.zip chromium_src-367c9c47fd5dac05688ac2fe864db26d780e7c33.tar.gz chromium_src-367c9c47fd5dac05688ac2fe864db26d780e7c33.tar.bz2 |
mandoline: Make sure omnibox gets updated when navigating back/forwards.
. Change WebViewClient::TopLevelNavigate() to TopLevelNavigateRequest() to
better reflect that the client can intercept the request and do things
other than doing a navigation.
. Introduce WebViewClient::TopLevelNavigationStarted(url) to notify the
client when navigation starts. Update the omnibox from this callback.
BUG=526268
Review URL: https://codereview.chromium.org/1350223005
Cr-Commit-Position: refs/heads/master@{#351073}
Diffstat (limited to 'components/web_view')
-rw-r--r-- | components/web_view/pending_web_view_load.cc | 3 | ||||
-rw-r--r-- | components/web_view/pending_web_view_load.h | 6 | ||||
-rw-r--r-- | components/web_view/public/interfaces/web_view.mojom | 7 | ||||
-rw-r--r-- | components/web_view/test_runner/test_runner_application_delegate.cc | 4 | ||||
-rw-r--r-- | components/web_view/test_runner/test_runner_application_delegate.h | 3 | ||||
-rw-r--r-- | components/web_view/web_view_apptest.cc | 31 | ||||
-rw-r--r-- | components/web_view/web_view_impl.cc | 10 | ||||
-rw-r--r-- | components/web_view/web_view_impl.h | 4 |
8 files changed, 51 insertions, 17 deletions
diff --git a/components/web_view/pending_web_view_load.cc b/components/web_view/pending_web_view_load.cc index eca81e4..54fa39b 100644 --- a/components/web_view/pending_web_view_load.cc +++ b/components/web_view/pending_web_view_load.cc @@ -18,6 +18,7 @@ PendingWebViewLoad::~PendingWebViewLoad() {} void PendingWebViewLoad::Init(mojo::URLRequestPtr request) { DCHECK(!frame_connection_); + pending_url_ = GURL(request->url); frame_connection_.reset(new FrameConnection); frame_connection_->Init(web_view_->app_, request.Pass(), base::Bind(&PendingWebViewLoad::OnGotContentHandlerID, @@ -27,7 +28,7 @@ void PendingWebViewLoad::Init(mojo::URLRequestPtr request) { void PendingWebViewLoad::OnGotContentHandlerID() { is_content_handler_id_valid_ = true; if (web_view_->root_) - web_view_->OnLoad(); + web_view_->OnLoad(pending_url_); // The else case is handled by WebViewImpl when it gets the View (|root_|). } diff --git a/components/web_view/pending_web_view_load.h b/components/web_view/pending_web_view_load.h index 47bc831..b2a1121 100644 --- a/components/web_view/pending_web_view_load.h +++ b/components/web_view/pending_web_view_load.h @@ -5,8 +5,11 @@ #ifndef COMPONENTS_WEB_VIEW_PENDING_WEB_VIEW_LOAD_H_ #define COMPONENTS_WEB_VIEW_PENDING_WEB_VIEW_LOAD_H_ +#include <string> + #include "base/memory/scoped_ptr.h" #include "mojo/services/network/public/interfaces/url_loader.mojom.h" +#include "url/gurl.h" namespace web_view { @@ -30,11 +33,14 @@ class PendingWebViewLoad { return is_content_handler_id_valid_; } + const GURL& pending_url() const { return pending_url_; } + private: void OnGotContentHandlerID(); WebViewImpl* web_view_; + GURL pending_url_; bool is_content_handler_id_valid_; scoped_ptr<FrameConnection> frame_connection_; diff --git a/components/web_view/public/interfaces/web_view.mojom b/components/web_view/public/interfaces/web_view.mojom index d5bab2b..1385b8d 100644 --- a/components/web_view/public/interfaces/web_view.mojom +++ b/components/web_view/public/interfaces/web_view.mojom @@ -14,7 +14,12 @@ enum ButtonState { interface WebViewClient { // Page-generated request for a top level frame navigation. - TopLevelNavigate(mojo.URLRequest request); + TopLevelNavigateRequest(mojo.URLRequest request); + + // Notification that the navigation has started. This can be useful for + // navigations triggered from sources other than the page itself (e.g. + // back/forward history navigation). + TopLevelNavigationStarted(string url); // Loading and progress notifications. LoadingStateChanged(bool is_loading, double progress); diff --git a/components/web_view/test_runner/test_runner_application_delegate.cc b/components/web_view/test_runner/test_runner_application_delegate.cc index e268677..556ccde 100644 --- a/components/web_view/test_runner/test_runner_application_delegate.cc +++ b/components/web_view/test_runner/test_runner_application_delegate.cc @@ -115,11 +115,13 @@ void TestRunnerApplicationDelegate::OnConnectionLost( //////////////////////////////////////////////////////////////////////////////// // mojom::WebViewClient implementation: -void TestRunnerApplicationDelegate::TopLevelNavigate( +void TestRunnerApplicationDelegate::TopLevelNavigateRequest( mojo::URLRequestPtr request) { web_view_->web_view()->LoadRequest(request.Pass()); } +void TestRunnerApplicationDelegate::TopLevelNavigationStarted( + const mojo::String& url) {} void TestRunnerApplicationDelegate::LoadingStateChanged(bool is_loading, double progress) {} void TestRunnerApplicationDelegate::BackForwardChanged( diff --git a/components/web_view/test_runner/test_runner_application_delegate.h b/components/web_view/test_runner/test_runner_application_delegate.h index 35c41f6..48327df 100644 --- a/components/web_view/test_runner/test_runner_application_delegate.h +++ b/components/web_view/test_runner/test_runner_application_delegate.h @@ -49,7 +49,8 @@ class TestRunnerApplicationDelegate void OnConnectionLost(mus::ViewTreeConnection* connection) override; // mojom::WebViewClient: - void TopLevelNavigate(mojo::URLRequestPtr request) override; + void TopLevelNavigateRequest(mojo::URLRequestPtr request) override; + void TopLevelNavigationStarted(const mojo::String& url) override; void LoadingStateChanged(bool is_loading, double progress) override; void BackForwardChanged(mojom::ButtonState back_button, mojom::ButtonState forward_button) override; diff --git a/components/web_view/web_view_apptest.cc b/components/web_view/web_view_apptest.cc index 0c48804..130ef0a 100644 --- a/components/web_view/web_view_apptest.cc +++ b/components/web_view/web_view_apptest.cc @@ -26,6 +26,16 @@ const char kTestTwoFile[] = "test_two.html"; const char kTestTwoTitle[] = "Test Title Two"; const char kTestThreeFile[] = "test_three.html"; const char kTestThreeTitle[] = "Test Title Three"; + +GURL GetTestFileURL(const std::string& file) { + base::FilePath data_file; + CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &data_file)); + data_file = data_file.AppendASCII("components/test/data/web_view") + .AppendASCII(file) + .NormalizePathSeparators(); + CHECK(base::PathExists(data_file)); + return mojo::util::FilePathToFileURL(data_file); +} } class WebViewTest : public mus::ViewManagerTestBase, @@ -36,7 +46,8 @@ class WebViewTest : public mus::ViewManagerTestBase, mojom::WebView* web_view() { return web_view_.web_view(); } - const std::string& last_title() { return last_title_; } + const std::string& navigation_url() const { return navigation_url_; } + const std::string& last_title() const { return last_title_; } mojom::ButtonState last_back_button_state() { return last_back_button_state_; } @@ -50,13 +61,8 @@ class WebViewTest : public mus::ViewManagerTestBase, } void NavigateTo(const std::string& file) { - base::FilePath data_file; - ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_file)); - data_file = data_file.AppendASCII("components/test/data/web_view") - .AppendASCII(file).NormalizePathSeparators(); - ASSERT_TRUE(base::PathExists(data_file)); mojo::URLRequestPtr request(mojo::URLRequest::New()); - request->url = mojo::util::FilePathToFileURL(data_file).spec(); + request->url = GetTestFileURL(file).spec(); web_view()->LoadRequest(request.Pass()); StartNestedRunLoopUntilLoadingDone(); } @@ -91,7 +97,10 @@ class WebViewTest : public mus::ViewManagerTestBase, } // Overridden from web_view::mojom::WebViewClient: - void TopLevelNavigate(mojo::URLRequestPtr request) override {} + void TopLevelNavigateRequest(mojo::URLRequestPtr request) override {} + void TopLevelNavigationStarted(const mojo::String& url) override { + navigation_url_ = url.get(); + } void LoadingStateChanged(bool is_loading, double progress) override { if (is_loading == false) QuitNestedRunLoop(); @@ -113,6 +122,7 @@ class WebViewTest : public mus::ViewManagerTestBase, scoped_ptr<base::RunLoop> run_loop_; + std::string navigation_url_; std::string last_title_; mojom::ButtonState last_back_button_state_; mojom::ButtonState last_forward_button_state_; @@ -132,6 +142,7 @@ TEST_F(WebViewTest, CanGoBackAndForward) { // We can't go back on first navigation since there's nothing previously on // the stack. + EXPECT_EQ(GetTestFileURL(kTestOneFile).spec(), navigation_url()); EXPECT_EQ(kTestOneTitle, last_title()); EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED, last_back_button_state()); @@ -148,6 +159,7 @@ TEST_F(WebViewTest, CanGoBackAndForward) { web_view()->GoBack(); StartNestedRunLoopUntilLoadingDone(); + EXPECT_EQ(GetTestFileURL(kTestOneFile).spec(), navigation_url()); EXPECT_EQ(kTestOneTitle, last_title()); EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED, last_back_button_state()); @@ -156,6 +168,7 @@ TEST_F(WebViewTest, CanGoBackAndForward) { web_view()->GoForward(); StartNestedRunLoopUntilLoadingDone(); + EXPECT_EQ(GetTestFileURL(kTestTwoFile).spec(), navigation_url()); EXPECT_EQ(kTestTwoTitle, last_title()); EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED, last_back_button_state()); EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED, @@ -171,6 +184,7 @@ TEST_F(WebViewTest, NavigationClearsForward) { web_view()->GoBack(); StartNestedRunLoopUntilLoadingDone(); + EXPECT_EQ(GetTestFileURL(kTestOneFile).spec(), navigation_url()); EXPECT_EQ(kTestOneTitle, last_title()); EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED, last_back_button_state()); @@ -180,6 +194,7 @@ TEST_F(WebViewTest, NavigationClearsForward) { // Now navigate to a third file. This should clear the forward stack. ASSERT_NO_FATAL_FAILURE(NavigateTo(kTestThreeFile)); + EXPECT_EQ(GetTestFileURL(kTestThreeFile).spec(), navigation_url()); EXPECT_EQ(kTestThreeTitle, last_title()); EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED, last_back_button_state()); EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED, diff --git a/components/web_view/web_view_impl.cc b/components/web_view/web_view_impl.cc index 1c8654f..8992496 100644 --- a/components/web_view/web_view_impl.cc +++ b/components/web_view/web_view_impl.cc @@ -59,7 +59,7 @@ WebViewImpl::~WebViewImpl() { } } -void WebViewImpl::OnLoad() { +void WebViewImpl::OnLoad(const GURL& pending_url) { // Frames are uniqued based on the id of the associated View. By creating a // new View each time through we ensure the renderers get a clean id, rather // than one they may know about and try to incorrectly use. @@ -68,6 +68,8 @@ void WebViewImpl::OnLoad() { DCHECK(!content_); } + client_->TopLevelNavigationStarted(pending_url.spec()); + content_ = root_->connection()->CreateView(); content_->SetBounds(*mojo::Rect::From( gfx::Rect(0, 0, root_->bounds().width, root_->bounds().height))); @@ -131,7 +133,7 @@ void WebViewImpl::OnEmbed(mus::View* root) { root_ = root; if (pending_load_ && pending_load_->is_content_handler_id_valid()) - OnLoad(); + OnLoad(pending_load_->pending_url()); } void WebViewImpl::OnConnectionLost(mus::ViewTreeConnection* connection) { @@ -185,7 +187,7 @@ void WebViewImpl::TitleChanged(const mojo::String& title) { } void WebViewImpl::NavigateTopLevel(Frame* source, mojo::URLRequestPtr request) { - client_->TopLevelNavigate(request.Pass()); + client_->TopLevelNavigateRequest(request.Pass()); } void WebViewImpl::CanNavigateFrame(Frame* target, @@ -207,7 +209,7 @@ void WebViewImpl::DidCommitProvisionalLoad(Frame* frame) { void WebViewImpl::HandlePageNavigateRequest(const GURL& url) { mojo::URLRequestPtr request(mojo::URLRequest::New()); request->url = url.spec(); - client_->TopLevelNavigate(request.Pass()); + client_->TopLevelNavigateRequest(request.Pass()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/components/web_view/web_view_impl.h b/components/web_view/web_view_impl.h index c3aa482..c7a49d4a 100644 --- a/components/web_view/web_view_impl.h +++ b/components/web_view/web_view_impl.h @@ -5,6 +5,8 @@ #ifndef COMPONENTS_WEB_VIEW_WEB_VIEW_IMPL_H_ #define COMPONENTS_WEB_VIEW_WEB_VIEW_IMPL_H_ +#include <string> + #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "components/mus/public/cpp/view_observer.h" @@ -48,7 +50,7 @@ class WebViewImpl : public mojom::WebView, friend class PendingWebViewLoad; // See description above |pending_load_| for details. - void OnLoad(); + void OnLoad(const GURL& pending_url); // Overridden from WebView: void LoadRequest(mojo::URLRequestPtr request) override; |