summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-28 20:45:25 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-28 20:45:25 +0000
commit23dc93ca215537baf312da312ca2a32517e39890 (patch)
tree1aa4f212156b60ac8c201cf1ff0c27d6091f5066
parentefdb7f1a3e9c6b270e1a9fdc4249cd098984ee1b (diff)
downloadchromium_src-23dc93ca215537baf312da312ca2a32517e39890.zip
chromium_src-23dc93ca215537baf312da312ca2a32517e39890.tar.gz
chromium_src-23dc93ca215537baf312da312ca2a32517e39890.tar.bz2
Makes mojo WebUI run main only after page finishes loading
This way there isn't possible race conditions if main is run before the page finishes loading. BUG=none TEST=none R=darin@chromium.org Review URL: https://codereview.chromium.org/215373004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260266 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/renderer_host/render_process_host_impl.cc4
-rw-r--r--content/browser/renderer_host/render_process_host_mojo_impl.h1
-rw-r--r--content/renderer/web_ui_mojo.cc29
-rw-r--r--content/renderer/web_ui_mojo.h18
-rw-r--r--content/renderer/web_ui_mojo_context_state.cc2
5 files changed, 45 insertions, 9 deletions
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index 9fd13f2..3dc4bfc 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -2157,8 +2157,8 @@ void RenderProcessHostImpl::DecrementWorkerRefCount() {
#if defined(USE_MOJO)
void RenderProcessHostImpl::SetWebUIHandle(
-int32 view_routing_id,
-mojo::ScopedMessagePipeHandle handle) {
+ int32 view_routing_id,
+ mojo::ScopedMessagePipeHandle handle) {
if (!render_process_host_mojo_)
render_process_host_mojo_.reset(new RenderProcessHostMojoImpl(this));
render_process_host_mojo_->SetWebUIHandle(view_routing_id, handle.Pass());
diff --git a/content/browser/renderer_host/render_process_host_mojo_impl.h b/content/browser/renderer_host/render_process_host_mojo_impl.h
index cfd86c8..36d7404 100644
--- a/content/browser/renderer_host/render_process_host_mojo_impl.h
+++ b/content/browser/renderer_host/render_process_host_mojo_impl.h
@@ -15,7 +15,6 @@ namespace content {
class MojoChannelInit;
class RenderProcessHost;
-
// RenderProcessHostMojoImpl is responsible for initiating and maintaining the
// connection with the content side of RenderProcessHostMojo.
class RenderProcessHostMojoImpl : public RenderProcessHostMojo {
diff --git a/content/renderer/web_ui_mojo.cc b/content/renderer/web_ui_mojo.cc
index 21d85da..58f67a8 100644
--- a/content/renderer/web_ui_mojo.cc
+++ b/content/renderer/web_ui_mojo.cc
@@ -41,18 +41,23 @@ void WebUIMojo::MainFrameObserver::WillReleaseScriptContext(
web_ui_mojo_->DestroyContextState(context);
}
+void WebUIMojo::MainFrameObserver::DidFinishDocumentLoad() {
+ web_ui_mojo_->OnDidFinishDocumentLoad();
+}
+
WebUIMojo::WebUIMojo(RenderView* render_view)
: RenderViewObserver(render_view),
RenderViewObserverTracker<WebUIMojo>(render_view),
- main_frame_observer_(this) {
+ main_frame_observer_(this),
+ did_finish_document_load_(false) {
CreateContextState();
}
void WebUIMojo::SetBrowserHandle(mojo::ScopedMessagePipeHandle handle) {
- v8::HandleScope handle_scope(blink::mainThreadIsolate());
- WebUIMojoContextState* state = GetContextState();
- if (state)
- state->SetHandle(handle.Pass());
+ if (did_finish_document_load_)
+ SetHandleOnContextState(handle.Pass());
+ else
+ pending_handle_ = handle.Pass();
}
WebUIMojo::~WebUIMojo() {
@@ -76,6 +81,20 @@ void WebUIMojo::DestroyContextState(v8::Handle<v8::Context> context) {
context_data->RemoveUserData(kWebUIMojoContextStateKey);
}
+void WebUIMojo::OnDidFinishDocumentLoad() {
+ did_finish_document_load_ = true;
+ if (pending_handle_.is_valid())
+ SetHandleOnContextState(pending_handle_.Pass());
+}
+
+void WebUIMojo::SetHandleOnContextState(mojo::ScopedMessagePipeHandle handle) {
+ DCHECK(did_finish_document_load_);
+ v8::HandleScope handle_scope(blink::mainThreadIsolate());
+ WebUIMojoContextState* state = GetContextState();
+ if (state)
+ state->SetHandle(handle.Pass());
+}
+
WebUIMojoContextState* WebUIMojo::GetContextState() {
blink::WebFrame* frame = render_view()->GetWebView()->mainFrame();
v8::HandleScope handle_scope(blink::mainThreadIsolate());
diff --git a/content/renderer/web_ui_mojo.h b/content/renderer/web_ui_mojo.h
index 486132f..d9a7f00 100644
--- a/content/renderer/web_ui_mojo.h
+++ b/content/renderer/web_ui_mojo.h
@@ -42,6 +42,7 @@ class WebUIMojo
// RenderFrameObserver overrides:
virtual void WillReleaseScriptContext(v8::Handle<v8::Context> context,
int world_id) OVERRIDE;
+ virtual void DidFinishDocumentLoad() OVERRIDE;
private:
WebUIMojo* web_ui_mojo_;
@@ -54,6 +55,13 @@ class WebUIMojo
void CreateContextState();
void DestroyContextState(v8::Handle<v8::Context> context);
+ // Invoked when the frame finishes loading. Invokes SetHandleOnContextState()
+ // if necessary.
+ void OnDidFinishDocumentLoad();
+
+ // Invokes SetHandle() on the WebUIMojoContextState (if there is one).
+ void SetHandleOnContextState(mojo::ScopedMessagePipeHandle handle);
+
WebUIMojoContextState* GetContextState();
// RenderViewObserver overrides:
@@ -62,6 +70,16 @@ class WebUIMojo
MainFrameObserver main_frame_observer_;
+ // Set to true in DidFinishDocumentLoad(). 'main' is only executed once this
+ // happens.
+ bool did_finish_document_load_;
+
+ // If SetBrowserHandle() is invoked before the document finishes loading the
+ // MessagePipeHandle is stored here. When the document finishes loading
+ // SetHandleOnContextState() is invoked to send the handle to the
+ // WebUIMojoContextState and ultimately the page.
+ mojo::ScopedMessagePipeHandle pending_handle_;
+
DISALLOW_COPY_AND_ASSIGN(WebUIMojo);
};
diff --git a/content/renderer/web_ui_mojo_context_state.cc b/content/renderer/web_ui_mojo_context_state.cc
index 71ffe79..18c61fa 100644
--- a/content/renderer/web_ui_mojo_context_state.cc
+++ b/content/renderer/web_ui_mojo_context_state.cc
@@ -113,7 +113,7 @@ void WebUIMojoContextState::OnFetchModuleComplete(
DCHECK_EQ(kModulePrefix,
response.url().string().utf8().substr(0, arraysize(kModulePrefix) - 1));
const std::string module =
- response.url().string().utf8().substr(arraysize(kModulePrefix));
+ response.url().string().utf8().substr(arraysize(kModulePrefix) - 1);
// We can't delete fetch right now as the arguments to this function come from
// it and are used below. Instead use a scope_ptr to cleanup.
scoped_ptr<ResourceFetcher> deleter(fetcher);