summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/frame_host/navigator_delegate.h3
-rw-r--r--content/browser/frame_host/navigator_impl.cc2
-rw-r--r--content/browser/web_contents/web_contents_impl.cc6
-rw-r--r--content/browser/web_contents/web_contents_impl.h1
-rw-r--r--content/public/browser/web_contents_observer.h13
-rw-r--r--content/test/web_contents_observer_sanity_checker.cc9
-rw-r--r--content/test/web_contents_observer_sanity_checker.h1
-rw-r--r--extensions/browser/api/app_window/app_window_api.cc11
-rw-r--r--extensions/browser/app_window/app_window.cc23
-rw-r--r--extensions/browser/app_window/app_window.h10
-rw-r--r--extensions/browser/app_window/app_window_contents.cc6
-rw-r--r--extensions/browser/app_window/app_window_contents.h1
12 files changed, 84 insertions, 2 deletions
diff --git a/content/browser/frame_host/navigator_delegate.h b/content/browser/frame_host/navigator_delegate.h
index ac8402c9..14ab69b 100644
--- a/content/browser/frame_host/navigator_delegate.h
+++ b/content/browser/frame_host/navigator_delegate.h
@@ -34,6 +34,9 @@ class CONTENT_EXPORT NavigatorDelegate {
// Called when a navigation was redirected.
virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) {}
+ // Called when the navigation is about to be committed in a renderer.
+ virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) {}
+
// Called when a navigation committed.
virtual void DidCommitNavigation(NavigationHandle* navigation_handle) {}
diff --git a/content/browser/frame_host/navigator_impl.cc b/content/browser/frame_host/navigator_impl.cc
index b2be362..53417fc 100644
--- a/content/browser/frame_host/navigator_impl.cc
+++ b/content/browser/frame_host/navigator_impl.cc
@@ -738,6 +738,7 @@ void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node,
render_frame_host, navigation_request->common_params().url);
navigation_request->TransferNavigationHandleOwnership(render_frame_host);
+ delegate_->ReadyToCommitNavigation(render_frame_host->navigation_handle());
render_frame_host->CommitNavigation(response, body.Pass(),
navigation_request->common_params(),
navigation_request->request_params());
@@ -768,6 +769,7 @@ void NavigatorImpl::FailedNavigation(FrameTreeNode* frame_tree_node,
render_frame_host, navigation_request->common_params().url);
navigation_request->TransferNavigationHandleOwnership(render_frame_host);
+ delegate_->ReadyToCommitNavigation(render_frame_host->navigation_handle());
render_frame_host->FailedNavigation(navigation_request->common_params(),
navigation_request->request_params(),
has_stale_copy_in_cache, error_code);
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 7d03dc1..78689f2 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -2796,6 +2796,12 @@ void WebContentsImpl::DidRedirectNavigation(
DidRedirectNavigation(navigation_handle));
}
+void WebContentsImpl::ReadyToCommitNavigation(
+ NavigationHandle* navigation_handle) {
+ FOR_EACH_OBSERVER(WebContentsObserver, observers_,
+ ReadyToCommitNavigation(navigation_handle));
+}
+
void WebContentsImpl::DidCommitNavigation(NavigationHandle* navigation_handle) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,
DidCommitNavigation(navigation_handle));
diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h
index c7e6fdf..d0a5670 100644
--- a/content/browser/web_contents/web_contents_impl.h
+++ b/content/browser/web_contents/web_contents_impl.h
@@ -516,6 +516,7 @@ class CONTENT_EXPORT WebContentsImpl
void DidStartNavigation(NavigationHandle* navigation_handle) override;
void DidRedirectNavigation(NavigationHandle* navigation_handle) override;
+ void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override;
void DidCommitNavigation(NavigationHandle* navigation_handle) override;
void DidFinishNavigation(NavigationHandle* navigation_handle) override;
void DidStartProvisionalLoad(RenderFrameHostImpl* render_frame_host,
diff --git a/content/public/browser/web_contents_observer.h b/content/public/browser/web_contents_observer.h
index d310cb2..6a2b1ac 100644
--- a/content/public/browser/web_contents_observer.h
+++ b/content/public/browser/web_contents_observer.h
@@ -121,8 +121,9 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Listener,
// Called when a navigation started in the WebContents. |navigation_handle|
// is unique to a specific navigation. The same |navigation_handle| will be
- // provided on subsequent calls to DidRedirect/Commit/FinishNavigation
- // related to this navigation.
+ // provided on subsequent calls to
+ // DidRedirect/Commit/FinishNavigation/ReadyToCommitNavigation related to
+ // this navigation.
//
// Note that this is fired by navigations in any frame of the WebContents,
// not just the main frame.
@@ -139,6 +140,14 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Listener,
// Called when a navigation encountered a server redirect.
virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) {}
+ // PlzNavigate
+ // Called when the navigation is ready to be committed in a renderer. This is
+ // the first point in time where a RenderFrameHost is associated with the
+ // navigation. Observers that want to initialize any renderer side
+ // structures/state before the RenderFrame is navigated, should use this
+ // method as opposed to DidCommitNavigation, which is after the fact.
+ virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) {}
+
// Called when a navigation was committed.
virtual void DidCommitNavigation(NavigationHandle* navigation_handle) {}
diff --git a/content/test/web_contents_observer_sanity_checker.cc b/content/test/web_contents_observer_sanity_checker.cc
index 09151e8..82bcb60 100644
--- a/content/test/web_contents_observer_sanity_checker.cc
+++ b/content/test/web_contents_observer_sanity_checker.cc
@@ -143,6 +143,15 @@ void WebContentsObserverSanityChecker::DidRedirectNavigation(
CHECK(!navigation_handle->HasCommittedErrorPage());
}
+void WebContentsObserverSanityChecker::ReadyToCommitNavigation(
+ NavigationHandle* navigation_handle) {
+ CHECK(NavigationIsOngoing(navigation_handle));
+ CHECK(!NavigationIsOngoingAndCommitted(navigation_handle));
+
+ CHECK(!navigation_handle->HasCommittedDocument());
+ CHECK(!navigation_handle->HasCommittedErrorPage());
+}
+
void WebContentsObserverSanityChecker::DidCommitNavigation(
NavigationHandle* navigation_handle) {
CHECK(NavigationIsOngoing(navigation_handle));
diff --git a/content/test/web_contents_observer_sanity_checker.h b/content/test/web_contents_observer_sanity_checker.h
index 347754b..e5508d3 100644
--- a/content/test/web_contents_observer_sanity_checker.h
+++ b/content/test/web_contents_observer_sanity_checker.h
@@ -42,6 +42,7 @@ class WebContentsObserverSanityChecker : public WebContentsObserver,
void FrameDeleted(RenderFrameHost* render_frame_host) override;
void DidStartNavigation(NavigationHandle* navigation_handle) override;
void DidRedirectNavigation(NavigationHandle* navigation_handle) override;
+ void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override;
void DidCommitNavigation(NavigationHandle* navigation_handle) override;
void DidFinishNavigation(NavigationHandle* navigation_handle) override;
void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
diff --git a/extensions/browser/api/app_window/app_window_api.cc b/extensions/browser/api/app_window/app_window_api.cc
index 2cd0710..7124192 100644
--- a/extensions/browser/api/app_window/app_window_api.cc
+++ b/extensions/browser/api/app_window/app_window_api.cc
@@ -14,6 +14,7 @@
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/app_window_client.h"
@@ -367,6 +368,16 @@ bool AppWindowCreateFunction::RunAsync() {
return true;
}
+ // PlzNavigate: delay sending the response until the newly created window has
+ // been told to navigate, and blink has been correctly initialized in the
+ // renderer.
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ ::switches::kEnableBrowserSideNavigation)) {
+ app_window->SetOnFirstCommitCallback(
+ base::Bind(&AppWindowCreateFunction::SendResponse, this, true));
+ return true;
+ }
+
SendResponse(true);
app_window->WindowEventsReady();
diff --git a/extensions/browser/app_window/app_window.cc b/extensions/browser/app_window/app_window.cc
index b2bfeb0..0f24847 100644
--- a/extensions/browser/app_window/app_window.cc
+++ b/extensions/browser/app_window/app_window.cc
@@ -8,9 +8,12 @@
#include <string>
#include <vector>
+#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/task_runner.h"
+#include "base/thread_task_runner_handle.h"
#include "base/values.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/browser_context.h"
@@ -442,6 +445,26 @@ void AppWindow::DidFirstVisuallyNonEmptyPaint() {
}
}
+void AppWindow::SetOnFirstCommitCallback(const base::Closure& callback) {
+ DCHECK(on_first_commit_callback_.is_null());
+ on_first_commit_callback_ = callback;
+}
+
+void AppWindow::OnReadyToCommitFirstNavigation() {
+ CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
+ ::switches::kEnableBrowserSideNavigation));
+ WindowEventsReady();
+ if (on_first_commit_callback_.is_null())
+ return;
+ // It is important that the callback executes after the calls to
+ // WebContentsObserver::ReadyToCommitNavigation have been processed. The
+ // CommitNavigation IPC that will properly set up the renderer will only be
+ // sent after these, and it must be sent before the callback gets to run,
+ // hence the use of PostTask.
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::ResetAndReturn(&on_first_commit_callback_));
+}
+
void AppWindow::OnNativeClose() {
AppWindowRegistry::Get(browser_context_)->RemoveAppWindow(this);
if (app_window_contents_) {
diff --git a/extensions/browser/app_window/app_window.h b/extensions/browser/app_window/app_window.h
index f6c330d..13ff3c3 100644
--- a/extensions/browser/app_window/app_window.h
+++ b/extensions/browser/app_window/app_window.h
@@ -242,6 +242,13 @@ class AppWindow : public content::WebContentsDelegate,
// is on startup and from within UpdateWindowTitle().
base::string16 GetTitle() const;
+ // |callback| will then be called when the first navigation in the window is
+ // ready to commit.
+ void SetOnFirstCommitCallback(const base::Closure& callback);
+
+ // Called when the first navigation in the window is ready to commit.
+ void OnReadyToCommitFirstNavigation();
+
// Call to notify ShellRegistry and delete the window. Subclasses should
// invoke this method instead of using "delete this".
void OnNativeClose();
@@ -551,6 +558,9 @@ class AppWindow : public content::WebContentsDelegate,
// Whether |is_ime_window| was set in the CreateParams.
bool is_ime_window_;
+ // PlzNavigate: this is called when the first navigation is ready to commit.
+ base::Closure on_first_commit_callback_;
+
base::WeakPtrFactory<AppWindow> image_loader_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(AppWindow);
diff --git a/extensions/browser/app_window/app_window_contents.cc b/extensions/browser/app_window/app_window_contents.cc
index 181e211..0362998 100644
--- a/extensions/browser/app_window/app_window_contents.cc
+++ b/extensions/browser/app_window/app_window_contents.cc
@@ -118,6 +118,12 @@ bool AppWindowContentsImpl::OnMessageReceived(const IPC::Message& message) {
return handled;
}
+void AppWindowContentsImpl::ReadyToCommitNavigation(
+ content::NavigationHandle* handle) {
+ if (!is_window_ready_)
+ host_->OnReadyToCommitFirstNavigation();
+}
+
void AppWindowContentsImpl::UpdateDraggableRegions(
const std::vector<DraggableRegion>& regions) {
host_->UpdateDraggableRegions(regions);
diff --git a/extensions/browser/app_window/app_window_contents.h b/extensions/browser/app_window/app_window_contents.h
index 7656a68..559bd92 100644
--- a/extensions/browser/app_window/app_window_contents.h
+++ b/extensions/browser/app_window/app_window_contents.h
@@ -42,6 +42,7 @@ class AppWindowContentsImpl : public AppWindowContents,
private:
// content::WebContentsObserver
bool OnMessageReceived(const IPC::Message& message) override;
+ void ReadyToCommitNavigation(content::NavigationHandle* handle) override;
void UpdateDraggableRegions(const std::vector<DraggableRegion>& regions);
void SuspendRenderFrameHost(content::RenderFrameHost* rfh);