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" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 context_data->GetUserData(kMojoContextStateKey)); | 64 context_data->GetUserData(kMojoContextStateKey)); |
65 return context_state ? context_state->state.get() : NULL; | 65 return context_state ? context_state->state.get() : NULL; |
66 } | 66 } |
67 | 67 |
68 void MojoBindingsController::WillReleaseScriptContext( | 68 void MojoBindingsController::WillReleaseScriptContext( |
69 v8::Local<v8::Context> context, | 69 v8::Local<v8::Context> context, |
70 int world_id) { | 70 int world_id) { |
71 DestroyContextState(context); | 71 DestroyContextState(context); |
72 } | 72 } |
73 | 73 |
74 void MojoBindingsController::DidFinishDocumentLoad() { | 74 void MojoBindingsController::RunScriptsAtDocumentStart() { |
| 75 CreateContextState(); |
| 76 } |
| 77 |
| 78 void MojoBindingsController::RunScriptsAtDocumentReady() { |
75 v8::HandleScope handle_scope(blink::mainThreadIsolate()); | 79 v8::HandleScope handle_scope(blink::mainThreadIsolate()); |
76 MojoContextState* state = GetContextState(); | 80 MojoContextState* state = GetContextState(); |
77 if (state) | 81 if (state) |
78 state->Run(); | 82 state->Run(); |
79 } | 83 } |
80 | 84 |
81 void MojoBindingsController::DidCreateDocumentElement() { | |
82 CreateContextState(); | |
83 } | |
84 | |
85 void MojoBindingsController::DidClearWindowObject() { | 85 void MojoBindingsController::DidClearWindowObject() { |
86 // NOTE: this function may be called early on twice. From the constructor | 86 // NOTE: this function may be called early on twice. From the constructor |
87 // mainWorldScriptContext() may trigger this to be called. If we are created | 87 // mainWorldScriptContext() may trigger this to be called. If we are created |
88 // before the page is loaded (which is very likely), then on first load this | 88 // before the page is loaded (which is very likely), then on first load this |
89 // is called. In the case of the latter we may have already supplied the | 89 // is called. In the case of the latter we may have already supplied the |
90 // handle to the context state so that if we destroy now the handle is | 90 // handle to the context state so that if we destroy now the handle is |
91 // lost. If this is the result of the first load then the contextstate should | 91 // lost. If this is the result of the first load then the contextstate should |
92 // be empty and we don't need to destroy it. | 92 // be empty and we don't need to destroy it. |
93 MojoContextState* state = GetContextState(); | 93 MojoContextState* state = GetContextState(); |
94 if (state && !state->module_added()) | 94 if (state && !state->module_added()) |
95 return; | 95 return; |
96 | 96 |
97 v8::HandleScope handle_scope(blink::mainThreadIsolate()); | 97 v8::HandleScope handle_scope(blink::mainThreadIsolate()); |
98 DestroyContextState(render_frame()->GetWebFrame()->mainWorldScriptContext()); | 98 DestroyContextState(render_frame()->GetWebFrame()->mainWorldScriptContext()); |
99 } | 99 } |
100 | 100 |
101 } // namespace content | 101 } // namespace content |
OLD | NEW |