| 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/scoped_observer.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/content_watcher.h" |
| 20 #include "extensions/renderer/resource_bundle_source_map.h" | 21 #include "extensions/renderer/resource_bundle_source_map.h" |
| 21 #include "extensions/renderer/script_context.h" | 22 #include "extensions/renderer/script_context.h" |
| 22 #include "extensions/renderer/script_context_set.h" | 23 #include "extensions/renderer/script_context_set.h" |
| 23 #include "extensions/renderer/user_script_set.h" | 24 #include "extensions/renderer/user_script_set.h" |
| 24 #include "extensions/renderer/v8_schema_registry.h" | 25 #include "extensions/renderer/v8_schema_registry.h" |
| 25 #include "third_party/WebKit/public/platform/WebString.h" | 26 #include "third_party/WebKit/public/platform/WebString.h" |
| 26 #include "third_party/WebKit/public/platform/WebVector.h" | 27 #include "third_party/WebKit/public/platform/WebVector.h" |
| 27 #include "v8/include/v8.h" | 28 #include "v8/include/v8.h" |
| 28 | 29 |
| 29 class ChromeRenderViewTest; | 30 class ChromeRenderViewTest; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 42 namespace base { | 43 namespace base { |
| 43 class DictionaryValue; | 44 class DictionaryValue; |
| 44 class ListValue; | 45 class ListValue; |
| 45 } | 46 } |
| 46 | 47 |
| 47 namespace content { | 48 namespace content { |
| 48 class RenderThread; | 49 class RenderThread; |
| 49 } | 50 } |
| 50 | 51 |
| 51 namespace extensions { | 52 namespace extensions { |
| 52 class ContentWatcher; | |
| 53 class DispatcherDelegate; | 53 class DispatcherDelegate; |
| 54 class Extension; | 54 class Extension; |
| 55 class FilteredEventRouter; | 55 class FilteredEventRouter; |
| 56 class ManifestPermissionSet; | 56 class ManifestPermissionSet; |
| 57 class RequestSender; | 57 class RequestSender; |
| 58 class ScriptContext; | 58 class ScriptContext; |
| 59 class ScriptInjectionManager; | 59 class ScriptInjectionManager; |
| 60 struct Message; | 60 struct Message; |
| 61 | 61 |
| 62 // Map from RuleRegistry::event_name to associated ContentWatcher. |
| 63 typedef std::map< std::string, linked_ptr<ContentWatcher> > ContentWatcherMap; |
| 64 |
| 62 // Dispatches extension control messages sent to the renderer and stores | 65 // Dispatches extension control messages sent to the renderer and stores |
| 63 // renderer extension related state. | 66 // renderer extension related state. |
| 64 class Dispatcher : public content::RenderProcessObserver, | 67 class Dispatcher : public content::RenderProcessObserver, |
| 65 public UserScriptSet::Observer { | 68 public UserScriptSet::Observer { |
| 66 public: | 69 public: |
| 67 explicit Dispatcher(DispatcherDelegate* delegate); | 70 explicit Dispatcher(DispatcherDelegate* delegate); |
| 68 virtual ~Dispatcher(); | 71 virtual ~Dispatcher(); |
| 69 | 72 |
| 70 const std::set<std::string>& function_names() const { | 73 const std::set<std::string>& function_names() const { |
| 71 return function_names_; | 74 return function_names_; |
| 72 } | 75 } |
| 73 | 76 |
| 74 bool is_extension_process() const { return is_extension_process_; } | 77 bool is_extension_process() const { return is_extension_process_; } |
| 75 | 78 |
| 76 const ExtensionSet* extensions() const { return &extensions_; } | 79 const ExtensionSet* extensions() const { return &extensions_; } |
| 77 | 80 |
| 78 const ScriptContextSet& script_context_set() const { | 81 const ScriptContextSet& script_context_set() const { |
| 79 return script_context_set_; | 82 return script_context_set_; |
| 80 } | 83 } |
| 81 | 84 |
| 82 V8SchemaRegistry* v8_schema_registry() { return v8_schema_registry_.get(); } | 85 V8SchemaRegistry* v8_schema_registry() { return v8_schema_registry_.get(); } |
| 83 | 86 |
| 84 ContentWatcher* content_watcher() { return content_watcher_.get(); } | |
| 85 | |
| 86 RequestSender* request_sender() { return request_sender_.get(); } | 87 RequestSender* request_sender() { return request_sender_.get(); } |
| 87 | 88 |
| 88 void OnRenderViewCreated(content::RenderView* render_view); | 89 void OnRenderViewCreated(content::RenderView* render_view); |
| 89 | 90 |
| 90 bool IsExtensionActive(const std::string& extension_id) const; | 91 bool IsExtensionActive(const std::string& extension_id) const; |
| 91 | 92 |
| 92 // Finds the extension ID for the JavaScript context associated with the | 93 // Finds the extension ID for the JavaScript context associated with the |
| 93 // specified |frame| and isolated world. If |world_id| is zero, finds the | 94 // specified |frame| and isolated world. If |world_id| is zero, finds the |
| 94 // extension ID associated with the main world's JavaScript context. If the | 95 // extension ID associated with the main world's JavaScript context. If the |
| 95 // JavaScript context isn't from an extension, returns empty string. | 96 // JavaScript context isn't from an extension, returns empty string. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 int tab_id, | 183 int tab_id, |
| 183 const std::string& extension_id, | 184 const std::string& extension_id, |
| 184 const URLPatternSet& origin_set); | 185 const URLPatternSet& origin_set); |
| 185 void OnUsingWebRequestAPI(bool webrequest_used); | 186 void OnUsingWebRequestAPI(bool webrequest_used); |
| 186 | 187 |
| 187 // UserScriptSet::Observer implementation. | 188 // UserScriptSet::Observer implementation. |
| 188 virtual void OnUserScriptsUpdated( | 189 virtual void OnUserScriptsUpdated( |
| 189 const std::set<std::string>& changed_extensions, | 190 const std::set<std::string>& changed_extensions, |
| 190 const std::vector<UserScript*>& scripts) OVERRIDE; | 191 const std::vector<UserScript*>& scripts) OVERRIDE; |
| 191 | 192 |
| 193 // Handler for ExtensionMsg_WatchPages. |
| 194 void OnWatchPages(const std::string& event_name, |
| 195 const std::vector<std::string>& css_selectors); |
| 196 |
| 192 void UpdateActiveExtensions(); | 197 void UpdateActiveExtensions(); |
| 193 | 198 |
| 194 // Sets up the host permissions for |extension|. | 199 // Sets up the host permissions for |extension|. |
| 195 void InitOriginPermissions(const Extension* extension); | 200 void InitOriginPermissions(const Extension* extension); |
| 196 void UpdateOriginPermissions(UpdatedExtensionPermissionsInfo::Reason reason, | 201 void UpdateOriginPermissions(UpdatedExtensionPermissionsInfo::Reason reason, |
| 197 const Extension* extension, | 202 const Extension* extension, |
| 198 const URLPatternSet& origins); | 203 const URLPatternSet& origins); |
| 199 | 204 |
| 200 // Enable custom element whitelist in Apps. | 205 // Enable custom element whitelist in Apps. |
| 201 void EnableCustomElementWhiteList(); | 206 void EnableCustomElementWhiteList(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 ExtensionSet extensions_; | 255 ExtensionSet extensions_; |
| 251 | 256 |
| 252 // The IDs of extensions that failed to load, mapped to the error message | 257 // The IDs of extensions that failed to load, mapped to the error message |
| 253 // generated on failure. | 258 // generated on failure. |
| 254 std::map<std::string, std::string> extension_load_errors_; | 259 std::map<std::string, std::string> extension_load_errors_; |
| 255 | 260 |
| 256 // All the bindings contexts that are currently loaded for this renderer. | 261 // All the bindings contexts that are currently loaded for this renderer. |
| 257 // There is zero or one for each v8 context. | 262 // There is zero or one for each v8 context. |
| 258 ScriptContextSet script_context_set_; | 263 ScriptContextSet script_context_set_; |
| 259 | 264 |
| 260 scoped_ptr<ContentWatcher> content_watcher_; | 265 // Content watchers, keyed by event_name. |
| 266 ContentWatcherMap content_watchers_; |
| 261 | 267 |
| 262 scoped_ptr<UserScriptSet> user_script_set_; | 268 scoped_ptr<UserScriptSet> user_script_set_; |
| 263 | 269 |
| 264 scoped_ptr<ScriptInjectionManager> script_injection_manager_; | 270 scoped_ptr<ScriptInjectionManager> script_injection_manager_; |
| 265 | 271 |
| 266 // Same as above, but on a longer timer and will run even if the process is | 272 // Same as above, but on a longer timer and will run even if the process is |
| 267 // not idle, to ensure that IdleHandle gets called eventually. | 273 // not idle, to ensure that IdleHandle gets called eventually. |
| 268 scoped_ptr<base::RepeatingTimer<content::RenderThread> > forced_idle_timer_; | 274 scoped_ptr<base::RepeatingTimer<content::RenderThread> > forced_idle_timer_; |
| 269 | 275 |
| 270 // All declared function names. | 276 // All declared function names. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 295 // the observer is destroyed before the UserScriptSet. | 301 // the observer is destroyed before the UserScriptSet. |
| 296 ScopedObserver<UserScriptSet, UserScriptSet::Observer> | 302 ScopedObserver<UserScriptSet, UserScriptSet::Observer> |
| 297 user_script_set_observer_; | 303 user_script_set_observer_; |
| 298 | 304 |
| 299 DISALLOW_COPY_AND_ASSIGN(Dispatcher); | 305 DISALLOW_COPY_AND_ASSIGN(Dispatcher); |
| 300 }; | 306 }; |
| 301 | 307 |
| 302 } // namespace extensions | 308 } // namespace extensions |
| 303 | 309 |
| 304 #endif // EXTENSIONS_RENDERER_DISPATCHER_H_ | 310 #endif // EXTENSIONS_RENDERER_DISPATCHER_H_ |
| OLD | NEW |