From 23dc93ca215537baf312da312ca2a32517e39890 Mon Sep 17 00:00:00 2001 From: "sky@chromium.org" Date: Fri, 28 Mar 2014 20:45:25 +0000 Subject: 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 --- content/renderer/web_ui_mojo.cc | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'content/renderer/web_ui_mojo.cc') 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(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 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()); -- cgit v1.1