Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/renderer/extension_frame_helper.h" | 5 #include "extensions/renderer/extension_frame_helper.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "content/public/renderer/render_frame.h" | 8 #include "content/public/renderer/render_frame.h" |
| 9 #include "extensions/common/api/messaging/message.h" | 9 #include "extensions/common/api/messaging/message.h" |
| 10 #include "extensions/common/constants.h" | 10 #include "extensions/common/constants.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 void ExtensionFrameHelper::DidCreateDocumentElement() { | 116 void ExtensionFrameHelper::DidCreateDocumentElement() { |
| 117 did_create_current_document_element_ = true; | 117 did_create_current_document_element_ = true; |
| 118 extension_dispatcher_->DidCreateDocumentElement( | 118 extension_dispatcher_->DidCreateDocumentElement( |
| 119 render_frame()->GetWebFrame()); | 119 render_frame()->GetWebFrame()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void ExtensionFrameHelper::DidCreateNewDocument() { | 122 void ExtensionFrameHelper::DidCreateNewDocument() { |
| 123 did_create_current_document_element_ = false; | 123 did_create_current_document_element_ = false; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void ExtensionFrameHelper::AfterDidCreateDocumentElement( | |
| 127 const base::WeakPtr<content::RenderFrame>& render_frame_weak) { | |
| 128 DCHECK_EQ(render_frame(), render_frame_weak.get()); | |
| 129 DCHECK(did_create_current_document_element_); | |
| 130 | |
| 131 // The JavaScript code can cause re-entrancy. To avoid a deadlock, don't run | |
| 132 // callbacks that are added during the iteration. | |
| 133 std::vector<base::Closure> callbacks; | |
| 134 document_element_created_callbacks_.swap(callbacks); | |
| 135 for (auto& callback : callbacks) { | |
| 136 callback.Run(); | |
| 137 if (!render_frame_weak.get()) | |
| 138 return; // Frame invalidated by callback. | |
|
ncarter (slow)
2016/02/11 22:47:32
That also means that |this| was deleted (right?).
robwu
2016/02/11 23:36:51
Yes.
| |
| 139 } | |
| 140 } | |
| 141 | |
| 142 void ExtensionFrameHelper::ScheduleAfterDidCreateDocumentElement( | |
| 143 const base::Closure& callback) { | |
| 144 document_element_created_callbacks_.push_back(callback); | |
| 145 } | |
| 146 | |
| 126 void ExtensionFrameHelper::DidMatchCSS( | 147 void ExtensionFrameHelper::DidMatchCSS( |
| 127 const blink::WebVector<blink::WebString>& newly_matching_selectors, | 148 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
| 128 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { | 149 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { |
| 129 extension_dispatcher_->content_watcher()->DidMatchCSS( | 150 extension_dispatcher_->content_watcher()->DidMatchCSS( |
| 130 render_frame()->GetWebFrame(), newly_matching_selectors, | 151 render_frame()->GetWebFrame(), newly_matching_selectors, |
| 131 stopped_matching_selectors); | 152 stopped_matching_selectors); |
| 132 } | 153 } |
| 133 | 154 |
| 134 void ExtensionFrameHelper::DidCreateScriptContext( | 155 void ExtensionFrameHelper::DidCreateScriptContext( |
| 135 v8::Local<v8::Context> context, | 156 v8::Local<v8::Context> context, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 const std::string& module_name, | 249 const std::string& module_name, |
| 229 const std::string& function_name, | 250 const std::string& function_name, |
| 230 const base::ListValue& args, | 251 const base::ListValue& args, |
| 231 bool user_gesture) { | 252 bool user_gesture) { |
| 232 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, | 253 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, |
| 233 module_name, function_name, | 254 module_name, function_name, |
| 234 args, user_gesture); | 255 args, user_gesture); |
| 235 } | 256 } |
| 236 | 257 |
| 237 } // namespace extensions | 258 } // namespace extensions |
| OLD | NEW |