| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_DISPATCHER_H_ | 5 #ifndef EXTENSIONS_RENDERER_DISPATCHER_H_ |
| 6 #define EXTENSIONS_RENDERER_DISPATCHER_H_ | 6 #define EXTENSIONS_RENDERER_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/memory/shared_memory.h" | 13 #include "base/scoped_observer.h" |
| 14 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
| 15 #include "content/public/renderer/render_process_observer.h" | 15 #include "content/public/renderer/render_process_observer.h" |
| 16 #include "extensions/common/event_filter.h" | 16 #include "extensions/common/event_filter.h" |
| 17 #include "extensions/common/extension_set.h" | 17 #include "extensions/common/extension_set.h" |
| 18 #include "extensions/common/extensions_client.h" | 18 #include "extensions/common/extensions_client.h" |
| 19 #include "extensions/common/features/feature.h" | 19 #include "extensions/common/features/feature.h" |
| 20 #include "extensions/renderer/resource_bundle_source_map.h" | 20 #include "extensions/renderer/resource_bundle_source_map.h" |
| 21 #include "extensions/renderer/script_context.h" | 21 #include "extensions/renderer/script_context.h" |
| 22 #include "extensions/renderer/script_context_set.h" | 22 #include "extensions/renderer/script_context_set.h" |
| 23 #include "extensions/renderer/user_script_injection_list.h" |
| 23 #include "extensions/renderer/v8_schema_registry.h" | 24 #include "extensions/renderer/v8_schema_registry.h" |
| 24 #include "third_party/WebKit/public/platform/WebString.h" | 25 #include "third_party/WebKit/public/platform/WebString.h" |
| 25 #include "third_party/WebKit/public/platform/WebVector.h" | 26 #include "third_party/WebKit/public/platform/WebVector.h" |
| 26 #include "v8/include/v8.h" | 27 #include "v8/include/v8.h" |
| 27 | 28 |
| 28 class ChromeRenderViewTest; | 29 class ChromeRenderViewTest; |
| 29 class GURL; | 30 class GURL; |
| 30 class ModuleSystem; | 31 class ModuleSystem; |
| 31 class URLPattern; | 32 class URLPattern; |
| 32 struct ExtensionMsg_ExternalConnectionInfo; | 33 struct ExtensionMsg_ExternalConnectionInfo; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 48 } | 49 } |
| 49 | 50 |
| 50 namespace extensions { | 51 namespace extensions { |
| 51 class ContentWatcher; | 52 class ContentWatcher; |
| 52 class DispatcherDelegate; | 53 class DispatcherDelegate; |
| 53 class Extension; | 54 class Extension; |
| 54 class FilteredEventRouter; | 55 class FilteredEventRouter; |
| 55 class ManifestPermissionSet; | 56 class ManifestPermissionSet; |
| 56 class RequestSender; | 57 class RequestSender; |
| 57 class ScriptContext; | 58 class ScriptContext; |
| 58 class UserScriptSlave; | 59 class ScriptInjectionManager; |
| 59 struct Message; | 60 struct Message; |
| 60 | 61 |
| 61 // Dispatches extension control messages sent to the renderer and stores | 62 // Dispatches extension control messages sent to the renderer and stores |
| 62 // renderer extension related state. | 63 // renderer extension related state. |
| 63 class Dispatcher : public content::RenderProcessObserver { | 64 class Dispatcher : public content::RenderProcessObserver, |
| 65 public UserScriptInjectionList::Observer { |
| 64 public: | 66 public: |
| 65 explicit Dispatcher(DispatcherDelegate* delegate); | 67 explicit Dispatcher(DispatcherDelegate* delegate); |
| 66 virtual ~Dispatcher(); | 68 virtual ~Dispatcher(); |
| 67 | 69 |
| 68 const std::set<std::string>& function_names() const { | 70 const std::set<std::string>& function_names() const { |
| 69 return function_names_; | 71 return function_names_; |
| 70 } | 72 } |
| 71 | 73 |
| 72 bool is_extension_process() const { return is_extension_process_; } | 74 bool is_extension_process() const { return is_extension_process_; } |
| 73 | 75 |
| 74 const ExtensionSet* extensions() const { return &extensions_; } | 76 const ExtensionSet* extensions() const { return &extensions_; } |
| 75 | 77 |
| 76 const ScriptContextSet& script_context_set() const { | 78 const ScriptContextSet& script_context_set() const { |
| 77 return script_context_set_; | 79 return script_context_set_; |
| 78 } | 80 } |
| 79 | 81 |
| 80 V8SchemaRegistry* v8_schema_registry() { return v8_schema_registry_.get(); } | 82 V8SchemaRegistry* v8_schema_registry() { return v8_schema_registry_.get(); } |
| 81 | 83 |
| 82 ContentWatcher* content_watcher() { return content_watcher_.get(); } | 84 ContentWatcher* content_watcher() { return content_watcher_.get(); } |
| 83 | 85 |
| 84 UserScriptSlave* user_script_slave() { return user_script_slave_.get(); } | 86 RequestSender* request_sender() { return request_sender_.get(); } |
| 85 | 87 |
| 86 RequestSender* request_sender() { return request_sender_.get(); } | 88 void OnRenderViewCreated(content::RenderView* render_view); |
| 87 | 89 |
| 88 bool IsExtensionActive(const std::string& extension_id) const; | 90 bool IsExtensionActive(const std::string& extension_id) const; |
| 89 | 91 |
| 90 // Finds the extension ID for the JavaScript context associated with the | 92 // Finds the extension ID for the JavaScript context associated with the |
| 91 // specified |frame| and isolated world. If |world_id| is zero, finds the | 93 // specified |frame| and isolated world. If |world_id| is zero, finds the |
| 92 // extension ID associated with the main world's JavaScript context. If the | 94 // extension ID associated with the main world's JavaScript context. If the |
| 93 // JavaScript context isn't from an extension, returns empty string. | 95 // JavaScript context isn't from an extension, returns empty string. |
| 94 std::string GetExtensionID(const blink::WebFrame* frame, int world_id); | 96 std::string GetExtensionID(const blink::WebFrame* frame, int world_id); |
| 95 | 97 |
| 96 void DidCreateScriptContext(blink::WebFrame* frame, | 98 void DidCreateScriptContext(blink::WebFrame* frame, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 const std::string& font_size); | 175 const std::string& font_size); |
| 174 void OnShouldSuspend(const std::string& extension_id, int sequence_id); | 176 void OnShouldSuspend(const std::string& extension_id, int sequence_id); |
| 175 void OnSuspend(const std::string& extension_id); | 177 void OnSuspend(const std::string& extension_id); |
| 176 void OnTransferBlobs(const std::vector<std::string>& blob_uuids); | 178 void OnTransferBlobs(const std::vector<std::string>& blob_uuids); |
| 177 void OnUnloaded(const std::string& id); | 179 void OnUnloaded(const std::string& id); |
| 178 void OnUpdatePermissions(const ExtensionMsg_UpdatePermissions_Params& params); | 180 void OnUpdatePermissions(const ExtensionMsg_UpdatePermissions_Params& params); |
| 179 void OnUpdateTabSpecificPermissions(int page_id, | 181 void OnUpdateTabSpecificPermissions(int page_id, |
| 180 int tab_id, | 182 int tab_id, |
| 181 const std::string& extension_id, | 183 const std::string& extension_id, |
| 182 const URLPatternSet& origin_set); | 184 const URLPatternSet& origin_set); |
| 183 void OnUpdateUserScripts(base::SharedMemoryHandle scripts, | |
| 184 const std::set<std::string>& extension_ids); | |
| 185 void OnUsingWebRequestAPI(bool adblock, | 185 void OnUsingWebRequestAPI(bool adblock, |
| 186 bool adblock_plus, | 186 bool adblock_plus, |
| 187 bool other_webrequest); | 187 bool other_webrequest); |
| 188 | 188 |
| 189 // UserScriptInjectionList::Observer implementation. |
| 190 virtual void OnUserScriptsUpdated( |
| 191 const std::set<std::string>& changed_extensions, |
| 192 const std::vector<UserScript*>& scripts) OVERRIDE; |
| 193 |
| 189 void UpdateActiveExtensions(); | 194 void UpdateActiveExtensions(); |
| 190 | 195 |
| 191 // Sets up the host permissions for |extension|. | 196 // Sets up the host permissions for |extension|. |
| 192 void InitOriginPermissions(const Extension* extension); | 197 void InitOriginPermissions(const Extension* extension); |
| 193 void UpdateOriginPermissions(UpdatedExtensionPermissionsInfo::Reason reason, | 198 void UpdateOriginPermissions(UpdatedExtensionPermissionsInfo::Reason reason, |
| 194 const Extension* extension, | 199 const Extension* extension, |
| 195 const URLPatternSet& origins); | 200 const URLPatternSet& origins); |
| 196 | 201 |
| 197 // Enable custom element whitelist in Apps. | 202 // Enable custom element whitelist in Apps. |
| 198 void EnableCustomElementWhiteList(); | 203 void EnableCustomElementWhiteList(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // The IDs of extensions that failed to load, mapped to the error message | 254 // The IDs of extensions that failed to load, mapped to the error message |
| 250 // generated on failure. | 255 // generated on failure. |
| 251 std::map<std::string, std::string> extension_load_errors_; | 256 std::map<std::string, std::string> extension_load_errors_; |
| 252 | 257 |
| 253 // All the bindings contexts that are currently loaded for this renderer. | 258 // All the bindings contexts that are currently loaded for this renderer. |
| 254 // There is zero or one for each v8 context. | 259 // There is zero or one for each v8 context. |
| 255 ScriptContextSet script_context_set_; | 260 ScriptContextSet script_context_set_; |
| 256 | 261 |
| 257 scoped_ptr<ContentWatcher> content_watcher_; | 262 scoped_ptr<ContentWatcher> content_watcher_; |
| 258 | 263 |
| 259 scoped_ptr<UserScriptSlave> user_script_slave_; | 264 scoped_ptr<ScriptInjectionManager> script_injection_manager_; |
| 260 | 265 |
| 261 // Same as above, but on a longer timer and will run even if the process is | 266 // Same as above, but on a longer timer and will run even if the process is |
| 262 // not idle, to ensure that IdleHandle gets called eventually. | 267 // not idle, to ensure that IdleHandle gets called eventually. |
| 263 scoped_ptr<base::RepeatingTimer<content::RenderThread> > forced_idle_timer_; | 268 scoped_ptr<base::RepeatingTimer<content::RenderThread> > forced_idle_timer_; |
| 264 | 269 |
| 265 // All declared function names. | 270 // All declared function names. |
| 266 std::set<std::string> function_names_; | 271 std::set<std::string> function_names_; |
| 267 | 272 |
| 268 // The extensions and apps that are active in this process. | 273 // The extensions and apps that are active in this process. |
| 269 std::set<std::string> active_extension_ids_; | 274 std::set<std::string> active_extension_ids_; |
| 270 | 275 |
| 271 ResourceBundleSourceMap source_map_; | 276 ResourceBundleSourceMap source_map_; |
| 272 | 277 |
| 273 // Cache for the v8 representation of extension API schemas. | 278 // Cache for the v8 representation of extension API schemas. |
| 274 scoped_ptr<V8SchemaRegistry> v8_schema_registry_; | 279 scoped_ptr<V8SchemaRegistry> v8_schema_registry_; |
| 275 | 280 |
| 276 // Sends API requests to the extension host. | 281 // Sends API requests to the extension host. |
| 277 scoped_ptr<RequestSender> request_sender_; | 282 scoped_ptr<RequestSender> request_sender_; |
| 278 | 283 |
| 279 // The platforms system font family and size; | 284 // The platforms system font family and size; |
| 280 std::string system_font_family_; | 285 std::string system_font_family_; |
| 281 std::string system_font_size_; | 286 std::string system_font_size_; |
| 282 | 287 |
| 283 // Mapping of port IDs to tabs. If there is no tab, the value would be -1. | 288 // Mapping of port IDs to tabs. If there is no tab, the value would be -1. |
| 284 std::map<int, int> port_to_tab_id_map_; | 289 std::map<int, int> port_to_tab_id_map_; |
| 285 | 290 |
| 286 // True once WebKit has been initialized (and it is therefore safe to poke). | 291 // True once WebKit has been initialized (and it is therefore safe to poke). |
| 287 bool is_webkit_initialized_; | 292 bool is_webkit_initialized_; |
| 288 | 293 |
| 294 // It is important for this to come after the ScriptInjectionManager, so that |
| 295 // the observer is destroyed before the UserScriptInjectionList. |
| 296 ScopedObserver<UserScriptInjectionList, UserScriptInjectionList::Observer> |
| 297 user_script_injection_list_observer_; |
| 298 |
| 289 DISALLOW_COPY_AND_ASSIGN(Dispatcher); | 299 DISALLOW_COPY_AND_ASSIGN(Dispatcher); |
| 290 }; | 300 }; |
| 291 | 301 |
| 292 } // namespace extensions | 302 } // namespace extensions |
| 293 | 303 |
| 294 #endif // EXTENSIONS_RENDERER_DISPATCHER_H_ | 304 #endif // EXTENSIONS_RENDERER_DISPATCHER_H_ |
| OLD | NEW |