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/mojo_bindings_controller.h" | 5 #include "content/renderer/mojo_bindings_controller.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/mojo_context_state.h" | 10 #include "content/renderer/mojo_context_state.h" |
11 #include "gin/per_context_data.h" | 11 #include "gin/per_context_data.h" |
12 #include "third_party/WebKit/public/web/WebKit.h" | 12 #include "third_party/WebKit/public/web/WebKit.h" |
13 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 13 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
14 #include "third_party/WebKit/public/web/WebView.h" | 14 #include "third_party/WebKit/public/web/WebView.h" |
15 #include "v8/include/v8.h" | 15 #include "v8/include/v8.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const char kMojoContextStateKey[] = "MojoContextState"; | 21 const char kMojoContextStateKey[] = "MojoContextState"; |
22 | 22 |
23 struct MojoContextStateData : public base::SupportsUserData::Data { | 23 struct MojoContextStateData : public base::SupportsUserData::Data { |
24 scoped_ptr<MojoContextState> state; | 24 scoped_ptr<MojoContextState> state; |
25 }; | 25 }; |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 MojoBindingsController::MojoBindingsController(RenderFrame* render_frame) | 29 MojoBindingsController::MojoBindingsController(RenderFrame* render_frame, |
| 30 bool for_layout_tests) |
30 : RenderFrameObserver(render_frame), | 31 : RenderFrameObserver(render_frame), |
31 RenderFrameObserverTracker<MojoBindingsController>(render_frame) {} | 32 RenderFrameObserverTracker<MojoBindingsController>(render_frame), |
| 33 for_layout_tests_(for_layout_tests) {} |
32 | 34 |
33 MojoBindingsController::~MojoBindingsController() { | 35 MojoBindingsController::~MojoBindingsController() { |
34 } | 36 } |
35 | 37 |
36 void MojoBindingsController::CreateContextState() { | 38 void MojoBindingsController::CreateContextState() { |
37 v8::HandleScope handle_scope(blink::mainThreadIsolate()); | 39 v8::HandleScope handle_scope(blink::mainThreadIsolate()); |
38 blink::WebLocalFrame* frame = | 40 blink::WebLocalFrame* frame = |
39 render_frame()->GetWebFrame()->toWebLocalFrame(); | 41 render_frame()->GetWebFrame()->toWebLocalFrame(); |
40 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 42 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
41 gin::PerContextData* context_data = gin::PerContextData::From(context); | 43 gin::PerContextData* context_data = gin::PerContextData::From(context); |
42 MojoContextStateData* data = new MojoContextStateData; | 44 MojoContextStateData* data = new MojoContextStateData; |
43 data->state.reset(new MojoContextState(frame, context)); | 45 data->state.reset(new MojoContextState(frame, context, for_layout_tests_)); |
44 context_data->SetUserData(kMojoContextStateKey, data); | 46 context_data->SetUserData(kMojoContextStateKey, data); |
45 } | 47 } |
46 | 48 |
47 void MojoBindingsController::DestroyContextState( | 49 void MojoBindingsController::DestroyContextState( |
48 v8::Local<v8::Context> context) { | 50 v8::Local<v8::Context> context) { |
49 gin::PerContextData* context_data = gin::PerContextData::From(context); | 51 gin::PerContextData* context_data = gin::PerContextData::From(context); |
50 if (!context_data) | 52 if (!context_data) |
51 return; | 53 return; |
52 context_data->RemoveUserData(kMojoContextStateKey); | 54 context_data->RemoveUserData(kMojoContextStateKey); |
53 } | 55 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // be empty and we don't need to destroy it. | 93 // be empty and we don't need to destroy it. |
92 MojoContextState* state = GetContextState(); | 94 MojoContextState* state = GetContextState(); |
93 if (state && !state->module_added()) | 95 if (state && !state->module_added()) |
94 return; | 96 return; |
95 | 97 |
96 v8::HandleScope handle_scope(blink::mainThreadIsolate()); | 98 v8::HandleScope handle_scope(blink::mainThreadIsolate()); |
97 DestroyContextState(render_frame()->GetWebFrame()->mainWorldScriptContext()); | 99 DestroyContextState(render_frame()->GetWebFrame()->mainWorldScriptContext()); |
98 } | 100 } |
99 | 101 |
100 } // namespace content | 102 } // namespace content |
OLD | NEW |