Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(802)

Side by Side Diff: extensions/renderer/extension_frame_helper.h

Issue 2547753002: [Extensions] Extension Port Ids and Initialization 2.0 (Closed)
Patch Set: Rob's test Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/memory/weak_ptr.h"
12 #include "content/public/common/console_message_level.h" 12 #include "content/public/common/console_message_level.h"
13 #include "content/public/renderer/render_frame_observer.h" 13 #include "content/public/renderer/render_frame_observer.h"
14 #include "content/public/renderer/render_frame_observer_tracker.h" 14 #include "content/public/renderer/render_frame_observer_tracker.h"
15 #include "extensions/common/view_type.h" 15 #include "extensions/common/view_type.h"
16 16
17 struct ExtensionMsg_ExternalConnectionInfo; 17 struct ExtensionMsg_ExternalConnectionInfo;
18 struct ExtensionMsg_TabConnectionInfo; 18 struct ExtensionMsg_TabConnectionInfo;
19 struct ExtensionMsg_TabTargetConnectionInfo;
20 19
21 namespace base { 20 namespace base {
22 class ListValue; 21 class ListValue;
23 } 22 }
24 23
25 namespace extensions { 24 namespace extensions {
26 25
27 class Dispatcher; 26 class Dispatcher;
28 struct Message; 27 struct Message;
28 struct PortId;
29 class ScriptContext; 29 class ScriptContext;
30 30
31 // RenderFrame-level plumbing for extension features. 31 // RenderFrame-level plumbing for extension features.
32 class ExtensionFrameHelper 32 class ExtensionFrameHelper
33 : public content::RenderFrameObserver, 33 : public content::RenderFrameObserver,
34 public content::RenderFrameObserverTracker<ExtensionFrameHelper> { 34 public content::RenderFrameObserverTracker<ExtensionFrameHelper> {
35 public: 35 public:
36 ExtensionFrameHelper(content::RenderFrame* render_frame, 36 ExtensionFrameHelper(content::RenderFrame* render_frame,
37 Dispatcher* extension_dispatcher); 37 Dispatcher* extension_dispatcher);
38 ~ExtensionFrameHelper() override; 38 ~ExtensionFrameHelper() override;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // Schedule a callback, to be run at the next RunScriptsAtDocumentStart 75 // Schedule a callback, to be run at the next RunScriptsAtDocumentStart
76 // notification. Only call this when you are certain that there will be such a 76 // notification. Only call this when you are certain that there will be such a
77 // notification, e.g. from RenderFrameObserver::DidCreateDocumentElement. 77 // notification, e.g. from RenderFrameObserver::DidCreateDocumentElement.
78 // Otherwise the callback is never invoked, or invoked for a document that you 78 // Otherwise the callback is never invoked, or invoked for a document that you
79 // were not expecting. 79 // were not expecting.
80 void ScheduleAtDocumentStart(const base::Closure& callback); 80 void ScheduleAtDocumentStart(const base::Closure& callback);
81 81
82 // Schedule a callback, to be run at the next RunScriptsAtDocumentEnd call. 82 // Schedule a callback, to be run at the next RunScriptsAtDocumentEnd call.
83 void ScheduleAtDocumentEnd(const base::Closure& callback); 83 void ScheduleAtDocumentEnd(const base::Closure& callback);
84 84
85 // Sends a message to the browser requesting a port id. |callback| will be
86 // invoked with the global port id when the browser responds.
87 void RequestPortId(const ExtensionMsg_ExternalConnectionInfo& info,
88 const std::string& channel_name,
89 bool include_tls_channel_id,
90 const base::Callback<void(int)>& callback);
91 void RequestTabPortId(const ExtensionMsg_TabTargetConnectionInfo& info,
92 const std::string& extension_id,
93 const std::string& channel_name,
94 const base::Callback<void(int)>& callback);
95 void RequestNativeAppPortId(const std::string& native_app_name,
96 const base::Callback<void(int)>& callback);
97 int RequestSyncPortId(const ExtensionMsg_ExternalConnectionInfo& info,
98 const std::string& channel_name,
99 bool include_tls_channel_id);
100
101 private: 85 private:
102 struct PendingPortRequest;
103
104 // RenderFrameObserver implementation. 86 // RenderFrameObserver implementation.
105 void DidCreateDocumentElement() override; 87 void DidCreateDocumentElement() override;
106 void DidCreateNewDocument() override; 88 void DidCreateNewDocument() override;
107 void DidMatchCSS( 89 void DidMatchCSS(
108 const blink::WebVector<blink::WebString>& newly_matching_selectors, 90 const blink::WebVector<blink::WebString>& newly_matching_selectors,
109 const blink::WebVector<blink::WebString>& stopped_matching_selectors) 91 const blink::WebVector<blink::WebString>& stopped_matching_selectors)
110 override; 92 override;
111 void DidStartProvisionalLoad() override; 93 void DidStartProvisionalLoad() override;
112 void DidCreateScriptContext(v8::Local<v8::Context>, 94 void DidCreateScriptContext(v8::Local<v8::Context>,
113 int extension_group, 95 int extension_group,
114 int world_id) override; 96 int world_id) override;
115 void WillReleaseScriptContext(v8::Local<v8::Context>, int world_id) override; 97 void WillReleaseScriptContext(v8::Local<v8::Context>, int world_id) override;
116 bool OnMessageReceived(const IPC::Message& message) override; 98 bool OnMessageReceived(const IPC::Message& message) override;
117 void OnDestruct() override; 99 void OnDestruct() override;
118 100
119 // IPC handlers. 101 // IPC handlers.
120 void OnExtensionValidateMessagePort(int port_id); 102 void OnExtensionValidateMessagePort(const PortId& id);
121 void OnExtensionDispatchOnConnect( 103 void OnExtensionDispatchOnConnect(
122 int target_port_id, 104 const PortId& target_port_id,
123 const std::string& channel_name, 105 const std::string& channel_name,
124 const ExtensionMsg_TabConnectionInfo& source, 106 const ExtensionMsg_TabConnectionInfo& source,
125 const ExtensionMsg_ExternalConnectionInfo& info, 107 const ExtensionMsg_ExternalConnectionInfo& info,
126 const std::string& tls_channel_id); 108 const std::string& tls_channel_id);
127 void OnExtensionDeliverMessage(int target_port_id, 109 void OnExtensionDeliverMessage(const PortId& target_port_id,
128 const Message& message); 110 const Message& message);
129 void OnExtensionDispatchOnDisconnect(int port_id, 111 void OnExtensionDispatchOnDisconnect(const PortId& id,
130 const std::string& error_message); 112 const std::string& error_message);
131 void OnExtensionSetTabId(int tab_id); 113 void OnExtensionSetTabId(int tab_id);
132 void OnUpdateBrowserWindowId(int browser_window_id); 114 void OnUpdateBrowserWindowId(int browser_window_id);
133 void OnNotifyRendererViewType(ViewType view_type); 115 void OnNotifyRendererViewType(ViewType view_type);
134 void OnExtensionResponse(int request_id, 116 void OnExtensionResponse(int request_id,
135 bool success, 117 bool success,
136 const base::ListValue& response, 118 const base::ListValue& response,
137 const std::string& error); 119 const std::string& error);
138 void OnExtensionMessageInvoke(const std::string& extension_id, 120 void OnExtensionMessageInvoke(const std::string& extension_id,
139 const std::string& module_name, 121 const std::string& module_name,
140 const std::string& function_name, 122 const std::string& function_name,
141 const base::ListValue& args); 123 const base::ListValue& args);
142 void OnAssignPortId(int port_id, int request_id);
143 124
144 // Type of view associated with the RenderFrame. 125 // Type of view associated with the RenderFrame.
145 ViewType view_type_; 126 ViewType view_type_;
146 127
147 // The id of the tab the render frame is attached to. 128 // The id of the tab the render frame is attached to.
148 int tab_id_; 129 int tab_id_;
149 130
150 // The id of the browser window the render frame is attached to. 131 // The id of the browser window the render frame is attached to.
151 int browser_window_id_; 132 int browser_window_id_;
152 133
153 Dispatcher* extension_dispatcher_; 134 Dispatcher* extension_dispatcher_;
154 135
155 // Whether or not the current document element has been created. 136 // Whether or not the current document element has been created.
156 bool did_create_current_document_element_; 137 bool did_create_current_document_element_;
157 138
158 // Callbacks to be run at the next RunScriptsAtDocumentStart notification. 139 // Callbacks to be run at the next RunScriptsAtDocumentStart notification.
159 std::vector<base::Closure> document_element_created_callbacks_; 140 std::vector<base::Closure> document_element_created_callbacks_;
160 141
161 // Callbacks to be run at the next RunScriptsAtDocumentEnd notification. 142 // Callbacks to be run at the next RunScriptsAtDocumentEnd notification.
162 std::vector<base::Closure> document_load_finished_callbacks_; 143 std::vector<base::Closure> document_load_finished_callbacks_;
163 144
164 // Counter for port requests.
165 int next_port_request_id_;
166
167 // Map of port requests to callbacks.
168 std::map<int, std::unique_ptr<PendingPortRequest>> pending_port_requests_;
169
170 bool delayed_main_world_script_initialization_ = false; 145 bool delayed_main_world_script_initialization_ = false;
171 146
172 base::WeakPtrFactory<ExtensionFrameHelper> weak_ptr_factory_; 147 base::WeakPtrFactory<ExtensionFrameHelper> weak_ptr_factory_;
173 148
174 DISALLOW_COPY_AND_ASSIGN(ExtensionFrameHelper); 149 DISALLOW_COPY_AND_ASSIGN(ExtensionFrameHelper);
175 }; 150 };
176 151
177 } // namespace extensions 152 } // namespace extensions
178 153
179 #endif // EXTENSIONS_RENDERER_EXTENSION_FRAME_HELPER_H_ 154 #endif // EXTENSIONS_RENDERER_EXTENSION_FRAME_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698