| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_RENDERER_EXTENSIONS_EXTENSION_DISPATCHER_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_DISPATCHER_H_ |
| 6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_DISPATCHER_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_DISPATCHER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
| 14 #include "base/timer.h" | 14 #include "base/timer.h" |
| 15 #include "content/public/renderer/render_process_observer.h" | 15 #include "content/public/renderer/render_process_observer.h" |
| 16 #include "chrome/common/extensions/extension_set.h" | 16 #include "chrome/common/extensions/extension_set.h" |
| 17 #include "chrome/common/extensions/feature.h" |
| 18 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 17 #include "chrome/renderer/extensions/chrome_v8_context_set.h" | 19 #include "chrome/renderer/extensions/chrome_v8_context_set.h" |
| 18 #include "chrome/renderer/resource_bundle_source_map.h" | 20 #include "chrome/renderer/resource_bundle_source_map.h" |
| 19 #include "v8/include/v8.h" | 21 #include "v8/include/v8.h" |
| 20 | 22 |
| 21 class ModuleSystem; | 23 class ModuleSystem; |
| 22 class GURL; | 24 class GURL; |
| 23 class URLPattern; | 25 class URLPattern; |
| 24 class UserScriptSlave; | 26 class UserScriptSlave; |
| 25 struct ExtensionMsg_Loaded_Params; | 27 struct ExtensionMsg_Loaded_Params; |
| 26 | 28 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 47 return function_names_; | 49 return function_names_; |
| 48 } | 50 } |
| 49 | 51 |
| 50 bool is_extension_process() const { return is_extension_process_; } | 52 bool is_extension_process() const { return is_extension_process_; } |
| 51 const ExtensionSet* extensions() const { return &extensions_; } | 53 const ExtensionSet* extensions() const { return &extensions_; } |
| 52 const ChromeV8ContextSet& v8_context_set() const { | 54 const ChromeV8ContextSet& v8_context_set() const { |
| 53 return v8_context_set_; | 55 return v8_context_set_; |
| 54 } | 56 } |
| 55 UserScriptSlave* user_script_slave() { return user_script_slave_.get(); } | 57 UserScriptSlave* user_script_slave() { return user_script_slave_.get(); } |
| 56 | 58 |
| 57 bool IsApplicationActive(const std::string& extension_id) const; | |
| 58 bool IsExtensionActive(const std::string& extension_id) const; | 59 bool IsExtensionActive(const std::string& extension_id) const; |
| 59 | 60 |
| 60 // Whether or not we should set up custom bindings for this api. | 61 // Finds the extension ID for the JavaScript context associated with the |
| 61 bool AllowCustomAPI(WebKit::WebFrame* frame, | 62 // specified |frame| and isolated world. If |world_id| is zero, finds the |
| 62 const std::string& custom_binding_api_name, | 63 // extension ID associated with the main world's JavaScript context. If the |
| 63 int world_id); | 64 // JavaScript context isn't from an extension, returns empty string. |
| 65 std::string GetExtensionID(WebKit::WebFrame* frame, int world_id); |
| 64 | 66 |
| 65 // See WebKit::WebPermissionClient::allowScriptExtension | 67 // See WebKit::WebPermissionClient::allowScriptExtension |
| 66 // TODO(koz): Remove once WebKit no longer calls this. | 68 // TODO(koz): Remove once WebKit no longer calls this. |
| 67 bool AllowScriptExtension(WebKit::WebFrame* frame, | 69 bool AllowScriptExtension(WebKit::WebFrame* frame, |
| 68 const std::string& v8_extension_name, | 70 const std::string& v8_extension_name, |
| 69 int extension_group); | 71 int extension_group); |
| 70 | 72 |
| 71 // TODO(koz): Remove once WebKit no longer calls this. | 73 // TODO(koz): Remove once WebKit no longer calls this. |
| 72 bool AllowScriptExtension(WebKit::WebFrame* frame, | 74 bool AllowScriptExtension(WebKit::WebFrame* frame, |
| 73 const std::string& v8_extension_name, | 75 const std::string& v8_extension_name, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 bool user_gesture); | 113 bool user_gesture); |
| 112 void OnDeliverMessage(int target_port_id, const std::string& message); | 114 void OnDeliverMessage(int target_port_id, const std::string& message); |
| 113 void OnSetFunctionNames(const std::vector<std::string>& names); | 115 void OnSetFunctionNames(const std::vector<std::string>& names); |
| 114 void OnLoaded( | 116 void OnLoaded( |
| 115 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions); | 117 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions); |
| 116 void OnUnloaded(const std::string& id); | 118 void OnUnloaded(const std::string& id); |
| 117 void OnSetScriptingWhitelist( | 119 void OnSetScriptingWhitelist( |
| 118 const Extension::ScriptingWhitelist& extension_ids); | 120 const Extension::ScriptingWhitelist& extension_ids); |
| 119 void OnPageActionsUpdated(const std::string& extension_id, | 121 void OnPageActionsUpdated(const std::string& extension_id, |
| 120 const std::vector<std::string>& page_actions); | 122 const std::vector<std::string>& page_actions); |
| 121 void OnActivateApplication(const std::string& extension_id); | |
| 122 void OnActivateExtension(const std::string& extension_id); | 123 void OnActivateExtension(const std::string& extension_id); |
| 123 void OnUpdatePermissions(int reason_id, | 124 void OnUpdatePermissions(int reason_id, |
| 124 const std::string& extension_id, | 125 const std::string& extension_id, |
| 125 const ExtensionAPIPermissionSet& apis, | 126 const ExtensionAPIPermissionSet& apis, |
| 126 const URLPatternSet& explicit_hosts, | 127 const URLPatternSet& explicit_hosts, |
| 127 const URLPatternSet& scriptable_hosts); | 128 const URLPatternSet& scriptable_hosts); |
| 128 void OnUpdateUserScripts(base::SharedMemoryHandle table); | 129 void OnUpdateUserScripts(base::SharedMemoryHandle table); |
| 129 void OnUsingWebRequestAPI( | 130 void OnUsingWebRequestAPI( |
| 130 bool adblock, | 131 bool adblock, |
| 131 bool adblock_plus, | 132 bool adblock_plus, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 144 void UpdateOriginPermissions(UpdatedExtensionPermissionsInfo::Reason reason, | 145 void UpdateOriginPermissions(UpdatedExtensionPermissionsInfo::Reason reason, |
| 145 const Extension* extension, | 146 const Extension* extension, |
| 146 const URLPatternSet& origins); | 147 const URLPatternSet& origins); |
| 147 | 148 |
| 148 void RegisterNativeHandlers(ModuleSystem* module_system, | 149 void RegisterNativeHandlers(ModuleSystem* module_system, |
| 149 ChromeV8Context* context); | 150 ChromeV8Context* context); |
| 150 | 151 |
| 151 // Inserts static source code into |source_map_|. | 152 // Inserts static source code into |source_map_|. |
| 152 void PopulateSourceMap(); | 153 void PopulateSourceMap(); |
| 153 | 154 |
| 154 // Finds the extension ID for the current context. This is determined from | 155 // Returns the Feature::Context type of context for a JavaScript context. |
| 155 // |world_id| if it's non-zero, or the URL in |frame| if it is. | 156 extensions::Feature::Context ClassifyJavaScriptContext( |
| 156 std::string GetExtensionID(WebKit::WebFrame* frame, int world_id); | 157 const std::string& extension_id, |
| 158 int extension_group, |
| 159 const ExtensionURLInfo& url_info); |
| 157 | 160 |
| 158 // True if this renderer is running extensions. | 161 // True if this renderer is running extensions. |
| 159 bool is_extension_process_; | 162 bool is_extension_process_; |
| 160 | 163 |
| 161 // Contains all loaded extensions. This is essentially the renderer | 164 // Contains all loaded extensions. This is essentially the renderer |
| 162 // counterpart to ExtensionService in the browser. It contains information | 165 // counterpart to ExtensionService in the browser. It contains information |
| 163 // about all extensions currently loaded by the browser. | 166 // about all extensions currently loaded by the browser. |
| 164 ExtensionSet extensions_; | 167 ExtensionSet extensions_; |
| 165 | 168 |
| 166 // All the bindings contexts that are currently loaded for this renderer. | 169 // All the bindings contexts that are currently loaded for this renderer. |
| 167 // There is zero or one for each v8 context. | 170 // There is zero or one for each v8 context. |
| 168 ChromeV8ContextSet v8_context_set_; | 171 ChromeV8ContextSet v8_context_set_; |
| 169 | 172 |
| 170 scoped_ptr<UserScriptSlave> user_script_slave_; | 173 scoped_ptr<UserScriptSlave> user_script_slave_; |
| 171 | 174 |
| 172 // Same as above, but on a longer timer and will run even if the process is | 175 // Same as above, but on a longer timer and will run even if the process is |
| 173 // not idle, to ensure that IdleHandle gets called eventually. | 176 // not idle, to ensure that IdleHandle gets called eventually. |
| 174 base::RepeatingTimer<content::RenderThread> forced_idle_timer_; | 177 base::RepeatingTimer<content::RenderThread> forced_idle_timer_; |
| 175 | 178 |
| 176 // The v8 extensions which are restricted to extension-related contexts. | 179 // The v8 extensions which are restricted to extension-related contexts. |
| 177 std::set<std::string> restricted_v8_extensions_; | 180 std::set<std::string> restricted_v8_extensions_; |
| 178 | 181 |
| 179 // All declared function names. | 182 // All declared function names. |
| 180 std::set<std::string> function_names_; | 183 std::set<std::string> function_names_; |
| 181 | 184 |
| 182 // The extensions that are active in this process. | 185 // The extensions and apps that are active in this process. |
| 183 std::set<std::string> active_extension_ids_; | 186 std::set<std::string> active_extension_ids_; |
| 184 | 187 |
| 185 // The applications that are active in this process. | |
| 186 std::set<std::string> active_application_ids_; | |
| 187 | |
| 188 // True once WebKit has been initialized (and it is therefore safe to poke). | 188 // True once WebKit has been initialized (and it is therefore safe to poke). |
| 189 bool is_webkit_initialized_; | 189 bool is_webkit_initialized_; |
| 190 | 190 |
| 191 std::string test_extension_id_; | 191 std::string test_extension_id_; |
| 192 | 192 |
| 193 // Status of webrequest usage for known extensions. | 193 // Status of webrequest usage for known extensions. |
| 194 // TODO(mpcomplete): remove. http://crbug.com/100411 | 194 // TODO(mpcomplete): remove. http://crbug.com/100411 |
| 195 bool webrequest_adblock_; | 195 bool webrequest_adblock_; |
| 196 bool webrequest_adblock_plus_; | 196 bool webrequest_adblock_plus_; |
| 197 bool webrequest_other_; | 197 bool webrequest_other_; |
| 198 | 198 |
| 199 ResourceBundleSourceMap source_map_; | 199 ResourceBundleSourceMap source_map_; |
| 200 | 200 |
| 201 DISALLOW_COPY_AND_ASSIGN(ExtensionDispatcher); | 201 DISALLOW_COPY_AND_ASSIGN(ExtensionDispatcher); |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_DISPATCHER_H_ | 204 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_DISPATCHER_H_ |
| OLD | NEW |