| 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 #ifndef EXTENSIONS_RENDERER_EXTENSION_FRAME_HELPER_H_ | 5 #ifndef EXTENSIONS_RENDERER_EXTENSION_FRAME_HELPER_H_ |
| 6 #define EXTENSIONS_RENDERER_EXTENSION_FRAME_HELPER_H_ | 6 #define EXTENSIONS_RENDERER_EXTENSION_FRAME_HELPER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 11 #include "content/public/common/console_message_level.h" | 12 #include "content/public/common/console_message_level.h" |
| 12 #include "content/public/renderer/render_frame_observer.h" | 13 #include "content/public/renderer/render_frame_observer.h" |
| 13 #include "content/public/renderer/render_frame_observer_tracker.h" | 14 #include "content/public/renderer/render_frame_observer_tracker.h" |
| 14 #include "extensions/common/view_type.h" | 15 #include "extensions/common/view_type.h" |
| 15 | 16 |
| 16 struct ExtensionMsg_ExternalConnectionInfo; | 17 struct ExtensionMsg_ExternalConnectionInfo; |
| 17 struct ExtensionMsg_TabConnectionInfo; | 18 struct ExtensionMsg_TabConnectionInfo; |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 class ListValue; | 21 class ListValue; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace extensions { | 24 namespace extensions { |
| 24 | 25 |
| 25 class Dispatcher; | 26 class Dispatcher; |
| 26 struct Message; | 27 struct Message; |
| 27 class ScriptContext; | 28 class ScriptContext; |
| 28 | 29 |
| 29 // RenderFrame-level plumbing for extension features. | 30 // RenderFrame-level plumbing for extension features. |
| 30 class ExtensionFrameHelper | 31 class ExtensionFrameHelper |
| 31 : public content::RenderFrameObserver, | 32 : public content::RenderFrameObserver, |
| 32 public content::RenderFrameObserverTracker<ExtensionFrameHelper> { | 33 public content::RenderFrameObserverTracker<ExtensionFrameHelper>, |
| 34 public base::SupportsWeakPtr<ExtensionFrameHelper> { |
| 33 public: | 35 public: |
| 34 ExtensionFrameHelper(content::RenderFrame* render_frame, | 36 ExtensionFrameHelper(content::RenderFrame* render_frame, |
| 35 Dispatcher* extension_dispatcher); | 37 Dispatcher* extension_dispatcher); |
| 36 ~ExtensionFrameHelper() override; | 38 ~ExtensionFrameHelper() override; |
| 37 | 39 |
| 38 // Returns a list of extension RenderFrames that match the given filter | 40 // Returns a list of extension RenderFrames that match the given filter |
| 39 // criteria. A |browser_window_id| of extension_misc::kUnknownWindowId | 41 // criteria. A |browser_window_id| of extension_misc::kUnknownWindowId |
| 40 // specifies "all", as does a |view_type| of VIEW_TYPE_INVALID. | 42 // specifies "all", as does a |view_type| of VIEW_TYPE_INVALID. |
| 41 static std::vector<content::RenderFrame*> GetExtensionFrames( | 43 static std::vector<content::RenderFrame*> GetExtensionFrames( |
| 42 const std::string& extension_id, | 44 const std::string& extension_id, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 54 // deleted. | 56 // deleted. |
| 55 static bool IsContextForEventPage(const ScriptContext* context); | 57 static bool IsContextForEventPage(const ScriptContext* context); |
| 56 | 58 |
| 57 ViewType view_type() const { return view_type_; } | 59 ViewType view_type() const { return view_type_; } |
| 58 int tab_id() const { return tab_id_; } | 60 int tab_id() const { return tab_id_; } |
| 59 int browser_window_id() const { return browser_window_id_; } | 61 int browser_window_id() const { return browser_window_id_; } |
| 60 bool did_create_current_document_element() const { | 62 bool did_create_current_document_element() const { |
| 61 return did_create_current_document_element_; | 63 return did_create_current_document_element_; |
| 62 } | 64 } |
| 63 | 65 |
| 66 // Called when the document element has been inserted in this frame. This |
| 67 // method may invoke untrusted JavaScript code that invalidate the frame and |
| 68 // this ExtensionFrameHelper. |
| 69 void AfterDidCreateDocumentElement(); |
| 70 |
| 71 // Schedule a callback, to be run at the next AfterDidCreateDocumentElement |
| 72 // notification. Only call this when you are certain that there will be such a |
| 73 // notification, e.g. from RenderFrameObserver::DidCreateDocumentElement. |
| 74 // Otherwise the callback is never invoked, or invoked for a document that you |
| 75 // were not expecting. |
| 76 void ScheduleAfterDidCreateDocumentElement(const base::Closure& callback); |
| 77 |
| 64 private: | 78 private: |
| 65 // RenderFrameObserver implementation. | 79 // RenderFrameObserver implementation. |
| 66 void DidCreateDocumentElement() override; | 80 void DidCreateDocumentElement() override; |
| 67 void DidCreateNewDocument() override; | 81 void DidCreateNewDocument() override; |
| 68 void DidMatchCSS( | 82 void DidMatchCSS( |
| 69 const blink::WebVector<blink::WebString>& newly_matching_selectors, | 83 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
| 70 const blink::WebVector<blink::WebString>& stopped_matching_selectors) | 84 const blink::WebVector<blink::WebString>& stopped_matching_selectors) |
| 71 override; | 85 override; |
| 72 void DidCreateScriptContext(v8::Local<v8::Context>, | 86 void DidCreateScriptContext(v8::Local<v8::Context>, |
| 73 int extension_group, | 87 int extension_group, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 int tab_id_; | 120 int tab_id_; |
| 107 | 121 |
| 108 // The id of the browser window the render frame is attached to. | 122 // The id of the browser window the render frame is attached to. |
| 109 int browser_window_id_; | 123 int browser_window_id_; |
| 110 | 124 |
| 111 Dispatcher* extension_dispatcher_; | 125 Dispatcher* extension_dispatcher_; |
| 112 | 126 |
| 113 // Whether or not the current document element has been created. | 127 // Whether or not the current document element has been created. |
| 114 bool did_create_current_document_element_; | 128 bool did_create_current_document_element_; |
| 115 | 129 |
| 130 // Callbacks to be run at the next AfterDidCreateDocumentElement notification. |
| 131 std::vector<base::Closure> document_element_created_callbacks_; |
| 132 |
| 116 DISALLOW_COPY_AND_ASSIGN(ExtensionFrameHelper); | 133 DISALLOW_COPY_AND_ASSIGN(ExtensionFrameHelper); |
| 117 }; | 134 }; |
| 118 | 135 |
| 119 } // namespace extensions | 136 } // namespace extensions |
| 120 | 137 |
| 121 #endif // EXTENSIONS_RENDERER_EXTENSION_FRAME_HELPER_H_ | 138 #endif // EXTENSIONS_RENDERER_EXTENSION_FRAME_HELPER_H_ |
| OLD | NEW |