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

Side by Side Diff: chrome/renderer/extensions/extension_dispatcher.h

Issue 10821133: Move c/r/extensions/* into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master for cq Created 8 years, 4 months 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_DISPATCHER_H_
6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_DISPATCHER_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/shared_memory.h"
13 #include "base/timer.h"
14 #include "content/public/renderer/render_process_observer.h"
15 #include "chrome/common/extensions/event_filter.h"
16 #include "chrome/common/extensions/extension_set.h"
17 #include "chrome/common/extensions/features/feature.h"
18 #include "chrome/renderer/extensions/chrome_v8_context.h"
19 #include "chrome/renderer/extensions/chrome_v8_context_set.h"
20 #include "chrome/renderer/extensions/v8_schema_registry.h"
21 #include "chrome/renderer/resource_bundle_source_map.h"
22 #include "v8/include/v8.h"
23
24 class ExtensionRequestSender;
25 class GURL;
26 class ModuleSystem;
27 class URLPattern;
28 struct ExtensionMsg_Loaded_Params;
29
30 namespace extensions {
31 class FilteredEventRouter;
32 class UserScriptSlave;
33 }
34
35 namespace WebKit {
36 class WebFrame;
37 }
38
39 namespace base {
40 class ListValue;
41 }
42
43 namespace content {
44 class RenderThread;
45 }
46
47 namespace extension {
48 class Extension;
49 }
50
51 // Dispatches extension control messages sent to the renderer and stores
52 // renderer extension related state.
53 class ExtensionDispatcher : public content::RenderProcessObserver {
54 public:
55 ExtensionDispatcher();
56 virtual ~ExtensionDispatcher();
57
58 const std::set<std::string>& function_names() const {
59 return function_names_;
60 }
61
62 bool is_extension_process() const { return is_extension_process_; }
63 const ExtensionSet* extensions() const { return &extensions_; }
64 const ChromeV8ContextSet& v8_context_set() const {
65 return v8_context_set_;
66 }
67 extensions::UserScriptSlave* user_script_slave() {
68 return user_script_slave_.get();
69 }
70 extensions::V8SchemaRegistry* v8_schema_registry() {
71 return &v8_schema_registry_;
72 }
73
74 bool IsExtensionActive(const std::string& extension_id) const;
75
76 // Finds the extension ID for the JavaScript context associated with the
77 // specified |frame| and isolated world. If |world_id| is zero, finds the
78 // extension ID associated with the main world's JavaScript context. If the
79 // JavaScript context isn't from an extension, returns empty string.
80 std::string GetExtensionID(const WebKit::WebFrame* frame, int world_id);
81
82 // See WebKit::WebPermissionClient::allowScriptExtension
83 // TODO(koz): Remove once WebKit no longer calls this.
84 bool AllowScriptExtension(WebKit::WebFrame* frame,
85 const std::string& v8_extension_name,
86 int extension_group);
87
88 // TODO(koz): Remove once WebKit no longer calls this.
89 bool AllowScriptExtension(WebKit::WebFrame* frame,
90 const std::string& v8_extension_name,
91 int extension_group,
92 int world_id);
93
94 void DidCreateScriptContext(WebKit::WebFrame* frame,
95 v8::Handle<v8::Context> context,
96 int extension_group,
97 int world_id);
98 void WillReleaseScriptContext(WebKit::WebFrame* frame,
99 v8::Handle<v8::Context> context,
100 int world_id);
101
102 // TODO(mpcomplete): remove. http://crbug.com/100411
103 bool IsAdblockWithWebRequestInstalled() const {
104 return webrequest_adblock_;
105 }
106 bool IsAdblockPlusWithWebRequestInstalled() const {
107 return webrequest_adblock_plus_;
108 }
109 bool IsOtherExtensionWithWebRequestInstalled() const {
110 return webrequest_other_;
111 }
112
113 void OnExtensionResponse(int request_id,
114 bool success,
115 const base::ListValue& response,
116 const std::string& error);
117
118 // Checks that the current context contains an extension that has permission
119 // to execute the specified function. If it does not, a v8 exception is thrown
120 // and the method returns false. Otherwise returns true.
121 bool CheckCurrentContextAccessToExtensionAPI(
122 const std::string& function_name) const;
123
124 private:
125 friend class RenderViewTest;
126 typedef void (*BindingInstaller)(ModuleSystem* module_system,
127 v8::Handle<v8::Object> chrome,
128 v8::Handle<v8::Object> chrome_hidden);
129
130 // RenderProcessObserver implementation:
131 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
132 virtual void WebKitInitialized() OVERRIDE;
133 virtual void IdleNotification() OVERRIDE;
134
135 void OnSetChannel(int channel);
136 void OnMessageInvoke(const std::string& extension_id,
137 const std::string& function_name,
138 const base::ListValue& args,
139 const GURL& event_url,
140 bool user_gesture);
141 void OnDispatchOnConnect(int target_port_id,
142 const std::string& channel_name,
143 const std::string& tab_json,
144 const std::string& source_extension_id,
145 const std::string& target_extension_id);
146 void OnDeliverMessage(int target_port_id, const std::string& message);
147 void OnDispatchOnDisconnect(int port_id, bool connection_error);
148 void OnSetFunctionNames(const std::vector<std::string>& names);
149 void OnLoaded(
150 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions);
151 void OnUnloaded(const std::string& id);
152 void OnSetScriptingWhitelist(
153 const extensions::Extension::ScriptingWhitelist& extension_ids);
154 void OnPageActionsUpdated(const std::string& extension_id,
155 const std::vector<std::string>& page_actions);
156 void OnActivateExtension(const std::string& extension_id);
157 void OnUpdatePermissions(int reason_id,
158 const std::string& extension_id,
159 const extensions::APIPermissionSet& apis,
160 const URLPatternSet& explicit_hosts,
161 const URLPatternSet& scriptable_hosts);
162 void OnUpdateTabSpecificPermissions(int page_id,
163 int tab_id,
164 const std::string& extension_id,
165 const URLPatternSet& origin_set);
166 void OnClearTabSpecificPermissions(
167 int tab_id,
168 const std::vector<std::string>& extension_ids);
169 void OnUpdateUserScripts(base::SharedMemoryHandle table);
170 void OnUsingWebRequestAPI(
171 bool adblock,
172 bool adblock_plus,
173 bool other_webrequest);
174 void OnShouldUnload(const std::string& extension_id, int sequence_id);
175 void OnUnload(const std::string& extension_id);
176 void OnCancelUnload(const std::string& extension_id);
177
178 // Update the list of active extensions that will be reported when we crash.
179 void UpdateActiveExtensions();
180
181 // Calls RenderThread's RegisterExtension and keeps tracks of which v8
182 // extension is for Chrome Extensions only.
183 void RegisterExtension(v8::Extension* extension, bool restrict_to_extensions);
184
185 // Sets up the host permissions for |extension|.
186 void InitOriginPermissions(const extensions::Extension* extension);
187 void AddOrRemoveOriginPermissions(
188 extensions::UpdatedExtensionPermissionsInfo::Reason reason,
189 const extensions::Extension* extension,
190 const URLPatternSet& origins);
191
192 void RegisterNativeHandlers(ModuleSystem* module_system,
193 ChromeV8Context* context);
194
195 // Inserts static source code into |source_map_|.
196 void PopulateSourceMap();
197
198 // Inserts BindingInstallers into |lazy_bindings_map_|.
199 void PopulateLazyBindingsMap();
200
201 // Sets up the bindings for the given api.
202 void InstallBindings(ModuleSystem* module_system,
203 v8::Handle<v8::Context> v8_context,
204 const std::string& api);
205
206 // Determeines whether |frame| is being run inside a platform app
207 // (this evaluates to true for iframes in platform apps).
208 bool IsWithinPlatformApp(const WebKit::WebFrame* frame);
209
210 // Returns the Feature::Context type of context for a JavaScript context.
211 extensions::Feature::Context ClassifyJavaScriptContext(
212 const std::string& extension_id,
213 int extension_group,
214 const ExtensionURLInfo& url_info);
215
216 // True if this renderer is running extensions.
217 bool is_extension_process_;
218
219 // Contains all loaded extensions. This is essentially the renderer
220 // counterpart to ExtensionService in the browser. It contains information
221 // about all extensions currently loaded by the browser.
222 ExtensionSet extensions_;
223
224 // All the bindings contexts that are currently loaded for this renderer.
225 // There is zero or one for each v8 context.
226 ChromeV8ContextSet v8_context_set_;
227
228 scoped_ptr<extensions::UserScriptSlave> user_script_slave_;
229
230 // Same as above, but on a longer timer and will run even if the process is
231 // not idle, to ensure that IdleHandle gets called eventually.
232 base::RepeatingTimer<content::RenderThread> forced_idle_timer_;
233
234 // The v8 extensions which are restricted to extension-related contexts.
235 std::set<std::string> restricted_v8_extensions_;
236
237 // All declared function names.
238 std::set<std::string> function_names_;
239
240 // The extensions and apps that are active in this process.
241 std::set<std::string> active_extension_ids_;
242
243 // True once WebKit has been initialized (and it is therefore safe to poke).
244 bool is_webkit_initialized_;
245
246 // Status of webrequest usage for known extensions.
247 // TODO(mpcomplete): remove. http://crbug.com/100411
248 bool webrequest_adblock_;
249 bool webrequest_adblock_plus_;
250 bool webrequest_other_;
251
252 ResourceBundleSourceMap source_map_;
253
254 // Cache for the v8 representation of extension API schemas.
255 extensions::V8SchemaRegistry v8_schema_registry_;
256
257 // Bindings that are defined lazily and have BindingInstallers to install
258 // them.
259 std::map<std::string, BindingInstaller> lazy_bindings_map_;
260
261 // Sends API requests to the extension host.
262 scoped_ptr<ExtensionRequestSender> request_sender_;
263
264 // The current channel. From VersionInfo::GetChannel().
265 // TODO(aa): Remove when we can restrict non-permission APIs to dev-only.
266 int chrome_channel_;
267
268 DISALLOW_COPY_AND_ASSIGN(ExtensionDispatcher);
269 };
270
271 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_DISPATCHER_H_
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/extension_custom_bindings.cc ('k') | chrome/renderer/extensions/extension_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698