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/renderer/render_frame.h" | 8 #include "content/public/renderer/render_frame.h" |
9 #include "content/public/renderer/render_view.h" | 9 #include "content/public/renderer/render_view.h" |
10 #include "content/renderer/web_ui_mojo_context_state.h" | 10 #include "content/renderer/web_ui_mojo_context_state.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 web_ui_mojo_->DestroyContextState(context); | 41 web_ui_mojo_->DestroyContextState(context); |
42 } | 42 } |
43 | 43 |
44 WebUIMojo::WebUIMojo(RenderView* render_view) | 44 WebUIMojo::WebUIMojo(RenderView* render_view) |
45 : RenderViewObserver(render_view), | 45 : RenderViewObserver(render_view), |
46 RenderViewObserverTracker<WebUIMojo>(render_view), | 46 RenderViewObserverTracker<WebUIMojo>(render_view), |
47 main_frame_observer_(this) { | 47 main_frame_observer_(this) { |
48 CreateContextState(); | 48 CreateContextState(); |
49 } | 49 } |
50 | 50 |
51 void WebUIMojo::SetBrowserHandle(mojo::ScopedMessagePipeHandle handle) { | |
52 v8::HandleScope handle_scope(blink::mainThreadIsolate()); | |
53 WebUIMojoContextState* state = GetContextState(); | |
54 if (state) | |
55 state->SetHandle(handle.Pass()); | |
56 } | |
57 | |
58 WebUIMojo::~WebUIMojo() { | 51 WebUIMojo::~WebUIMojo() { |
59 } | 52 } |
60 | 53 |
| 54 void WebUIMojo::OnSetBrowserHandle(MojoHandle handle) { |
| 55 v8::HandleScope handle_scope(blink::mainThreadIsolate()); |
| 56 WebUIMojoContextState* state = GetContextState(); |
| 57 if (state) |
| 58 state->SetHandle(mojo::MakeScopedHandle(mojo::Handle(handle))); |
| 59 } |
| 60 |
61 void WebUIMojo::CreateContextState() { | 61 void WebUIMojo::CreateContextState() { |
62 v8::HandleScope handle_scope(blink::mainThreadIsolate()); | 62 v8::HandleScope handle_scope(blink::mainThreadIsolate()); |
63 blink::WebFrame* frame = render_view()->GetWebView()->mainFrame(); | 63 blink::WebFrame* frame = render_view()->GetWebView()->mainFrame(); |
64 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); | 64 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); |
65 gin::PerContextData* context_data = gin::PerContextData::From(context); | 65 gin::PerContextData* context_data = gin::PerContextData::From(context); |
66 WebUIMojoContextStateData* data = new WebUIMojoContextStateData; | 66 WebUIMojoContextStateData* data = new WebUIMojoContextStateData; |
67 data->state.reset(new WebUIMojoContextState( | 67 data->state.reset(new WebUIMojoContextState( |
68 render_view()->GetWebView()->mainFrame(), context)); | 68 render_view()->GetWebView()->mainFrame(), context)); |
69 context_data->SetUserData(kWebUIMojoContextStateKey, data); | 69 context_data->SetUserData(kWebUIMojoContextStateKey, data); |
70 } | 70 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 WebUIMojoContextState* state = GetContextState(); | 103 WebUIMojoContextState* state = GetContextState(); |
104 if (state && !state->module_added()) | 104 if (state && !state->module_added()) |
105 return; | 105 return; |
106 | 106 |
107 v8::HandleScope handle_scope(blink::mainThreadIsolate()); | 107 v8::HandleScope handle_scope(blink::mainThreadIsolate()); |
108 DestroyContextState(frame->mainWorldScriptContext()); | 108 DestroyContextState(frame->mainWorldScriptContext()); |
109 CreateContextState(); | 109 CreateContextState(); |
110 } | 110 } |
111 | 111 |
112 } // namespace content | 112 } // namespace content |
OLD | NEW |