Index: content/renderer/web_ui_mojo.cc |
diff --git a/content/renderer/web_ui_mojo.cc b/content/renderer/web_ui_mojo.cc |
index 21d85dacaa867df80c28f236c7732b3006a4ee0b..58f67a85b1f8a05bea8765b447bad967b53fd9ee 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()); |