| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/web_ui_mojo.h" | 5 #include "content/renderer/web_ui_mojo.h" |
| 6 | 6 |
| 7 #include "content/common/view_messages.h" | 7 #include "content/common/view_messages.h" |
| 8 #include "content/public/common/service_registry.h" | 8 #include "content/public/common/service_registry.h" |
| 9 #include "content/public/renderer/render_frame.h" | 9 #include "content/public/renderer/render_frame.h" |
| 10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
| 11 #include "content/renderer/render_view_impl.h" |
| 11 #include "content/renderer/web_ui_mojo_context_state.h" | 12 #include "content/renderer/web_ui_mojo_context_state.h" |
| 12 #include "gin/per_context_data.h" | 13 #include "gin/per_context_data.h" |
| 13 #include "third_party/WebKit/public/web/WebKit.h" | 14 #include "third_party/WebKit/public/web/WebKit.h" |
| 14 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 15 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 15 #include "third_party/WebKit/public/web/WebView.h" | 16 #include "third_party/WebKit/public/web/WebView.h" |
| 16 #include "v8/include/v8.h" | 17 #include "v8/include/v8.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 void WebUIMojo::MainFrameObserver::WillReleaseScriptContext( | 40 void WebUIMojo::MainFrameObserver::WillReleaseScriptContext( |
| 40 v8::Handle<v8::Context> context, | 41 v8::Handle<v8::Context> context, |
| 41 int world_id) { | 42 int world_id) { |
| 42 web_ui_mojo_->DestroyContextState(context); | 43 web_ui_mojo_->DestroyContextState(context); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void WebUIMojo::MainFrameObserver::DidFinishDocumentLoad() { | 46 void WebUIMojo::MainFrameObserver::DidFinishDocumentLoad() { |
| 46 web_ui_mojo_->OnDidFinishDocumentLoad(); | 47 web_ui_mojo_->OnDidFinishDocumentLoad(); |
| 47 } | 48 } |
| 48 | 49 |
| 49 WebUIMojo::WebUIMojo(RenderView* render_view) | 50 WebUIMojo::WebUIMojo(RenderViewImpl* render_view) |
| 50 : RenderViewObserver(render_view), | 51 : RenderViewObserver(render_view), |
| 51 RenderViewObserverTracker<WebUIMojo>(render_view), | 52 RenderViewObserverTracker<WebUIMojo>(render_view), |
| 53 render_view_impl_(render_view), |
| 52 main_frame_observer_(this), | 54 main_frame_observer_(this), |
| 53 did_finish_document_load_(false) { | 55 did_finish_document_load_(false) { |
| 54 CreateContextState(); | 56 CreateContextState(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 void WebUIMojo::SetBrowserHandle(mojo::ScopedMessagePipeHandle handle) { | 59 void WebUIMojo::SetBrowserHandle(mojo::ScopedMessagePipeHandle handle) { |
| 58 if (did_finish_document_load_) | 60 if (did_finish_document_load_) |
| 59 SetHandleOnContextState(handle.Pass()); | 61 SetHandleOnContextState(handle.Pass()); |
| 60 else | 62 else |
| 61 pending_handle_ = handle.Pass(); | 63 pending_handle_ = handle.Pass(); |
| 62 } | 64 } |
| 63 | 65 |
| 64 WebUIMojo::~WebUIMojo() { | 66 WebUIMojo::~WebUIMojo() { |
| 65 } | 67 } |
| 66 | 68 |
| 67 void WebUIMojo::CreateContextState() { | 69 void WebUIMojo::CreateContextState() { |
| 68 v8::HandleScope handle_scope(blink::mainThreadIsolate()); | 70 v8::HandleScope handle_scope(blink::mainThreadIsolate()); |
| 69 blink::WebLocalFrame* frame = | 71 blink::WebLocalFrame* frame = |
| 70 render_view()->GetWebView()->mainFrame()->toWebLocalFrame(); | 72 render_view()->GetWebView()->mainFrame()->toWebLocalFrame(); |
| 71 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); | 73 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); |
| 72 gin::PerContextData* context_data = gin::PerContextData::From(context); | 74 gin::PerContextData* context_data = gin::PerContextData::From(context); |
| 73 WebUIMojoContextStateData* data = new WebUIMojoContextStateData; | 75 WebUIMojoContextStateData* data = new WebUIMojoContextStateData; |
| 74 data->state.reset(new WebUIMojoContextState( | 76 data->state.reset(new WebUIMojoContextState(render_view_impl_, context)); |
| 75 render_view()->GetWebView()->mainFrame(), context)); | |
| 76 context_data->SetUserData(kWebUIMojoContextStateKey, data); | 77 context_data->SetUserData(kWebUIMojoContextStateKey, data); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void WebUIMojo::DestroyContextState(v8::Handle<v8::Context> context) { | 80 void WebUIMojo::DestroyContextState(v8::Handle<v8::Context> context) { |
| 80 gin::PerContextData* context_data = gin::PerContextData::From(context); | 81 gin::PerContextData* context_data = gin::PerContextData::From(context); |
| 81 if (!context_data) | 82 if (!context_data) |
| 82 return; | 83 return; |
| 83 context_data->RemoveUserData(kWebUIMojoContextStateKey); | 84 context_data->RemoveUserData(kWebUIMojoContextStateKey); |
| 84 } | 85 } |
| 85 | 86 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 WebUIMojoContextState* state = GetContextState(); | 129 WebUIMojoContextState* state = GetContextState(); |
| 129 if (state && !state->module_added()) | 130 if (state && !state->module_added()) |
| 130 return; | 131 return; |
| 131 | 132 |
| 132 v8::HandleScope handle_scope(blink::mainThreadIsolate()); | 133 v8::HandleScope handle_scope(blink::mainThreadIsolate()); |
| 133 DestroyContextState(frame->mainWorldScriptContext()); | 134 DestroyContextState(frame->mainWorldScriptContext()); |
| 134 CreateContextState(); | 135 CreateContextState(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 } // namespace content | 138 } // namespace content |
| OLD | NEW |