| 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 DCHECK(did_create_current_document_element_); |
| 128 base::WeakPtr<ExtensionFrameHelper> weak_self = AsWeakPtr(); |
| 129 |
| 130 // The JavaScript code can cause re-entrancy. To avoid a deadlock, don't run |
| 131 // callbacks that are added during the iteration. |
| 132 std::vector<base::Closure> callbacks; |
| 133 document_element_created_callbacks_.swap(callbacks); |
| 134 for (auto& callback : callbacks) { |
| 135 callback.Run(); |
| 136 if (!weak_self.get()) |
| 137 return; // Frame and |this| invalidated by callback. |
| 138 } |
| 139 } |
| 140 |
| 141 void ExtensionFrameHelper::ScheduleAfterDidCreateDocumentElement( |
| 142 const base::Closure& callback) { |
| 143 document_element_created_callbacks_.push_back(callback); |
| 144 } |
| 145 |
| 126 void ExtensionFrameHelper::DidMatchCSS( | 146 void ExtensionFrameHelper::DidMatchCSS( |
| 127 const blink::WebVector<blink::WebString>& newly_matching_selectors, | 147 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
| 128 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { | 148 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { |
| 129 extension_dispatcher_->content_watcher()->DidMatchCSS( | 149 extension_dispatcher_->content_watcher()->DidMatchCSS( |
| 130 render_frame()->GetWebFrame(), newly_matching_selectors, | 150 render_frame()->GetWebFrame(), newly_matching_selectors, |
| 131 stopped_matching_selectors); | 151 stopped_matching_selectors); |
| 132 } | 152 } |
| 133 | 153 |
| 134 void ExtensionFrameHelper::DidCreateScriptContext( | 154 void ExtensionFrameHelper::DidCreateScriptContext( |
| 135 v8::Local<v8::Context> context, | 155 v8::Local<v8::Context> context, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 const std::string& module_name, | 248 const std::string& module_name, |
| 229 const std::string& function_name, | 249 const std::string& function_name, |
| 230 const base::ListValue& args, | 250 const base::ListValue& args, |
| 231 bool user_gesture) { | 251 bool user_gesture) { |
| 232 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, | 252 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, |
| 233 module_name, function_name, | 253 module_name, function_name, |
| 234 args, user_gesture); | 254 args, user_gesture); |
| 235 } | 255 } |
| 236 | 256 |
| 237 } // namespace extensions | 257 } // namespace extensions |
| OLD | NEW |