| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/renderer/extensions/extension_dispatcher.h" | 5 #include "chrome/renderer/extensions/extension_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/common/child_process_logging.h" | 8 #include "chrome/common/child_process_logging.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/renderer/extensions/file_browser_private_bindings.h" | 22 #include "chrome/renderer/extensions/file_browser_private_bindings.h" |
| 23 #include "chrome/renderer/extensions/renderer_extension_bindings.h" | 23 #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
| 24 #include "chrome/renderer/extensions/user_script_slave.h" | 24 #include "chrome/renderer/extensions/user_script_slave.h" |
| 25 #include "content/public/renderer/render_thread.h" | 25 #include "content/public/renderer/render_thread.h" |
| 26 #include "grit/renderer_resources.h" | 26 #include "grit/renderer_resources.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 33 #include "ui/base/resource/resource_bundle.h" |
| 32 #include "v8/include/v8.h" | 34 #include "v8/include/v8.h" |
| 33 | 35 |
| 34 namespace { | 36 namespace { |
| 35 static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */; | 37 static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */; |
| 36 static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */; | 38 static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */; |
| 37 } | 39 } |
| 38 | 40 |
| 39 using WebKit::WebDataSource; | 41 using WebKit::WebDataSource; |
| 40 using WebKit::WebFrame; | 42 using WebKit::WebFrame; |
| 41 using WebKit::WebSecurityPolicy; | 43 using WebKit::WebSecurityPolicy; |
| 42 using WebKit::WebString; | 44 using WebKit::WebString; |
| 45 using WebKit::WebVector; |
| 46 using WebKit::WebView; |
| 43 using content::RenderThread; | 47 using content::RenderThread; |
| 44 | 48 |
| 45 ExtensionDispatcher::ExtensionDispatcher() | 49 ExtensionDispatcher::ExtensionDispatcher() |
| 46 : is_webkit_initialized_(false), | 50 : is_webkit_initialized_(false), |
| 47 webrequest_adblock_(false), | 51 webrequest_adblock_(false), |
| 48 webrequest_adblock_plus_(false), | 52 webrequest_adblock_plus_(false), |
| 49 webrequest_other_(false) { | 53 webrequest_other_(false) { |
| 50 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); | 54 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); |
| 51 is_extension_process_ = | 55 is_extension_process_ = |
| 52 command_line.HasSwitch(switches::kExtensionProcess) || | 56 command_line.HasSwitch(switches::kExtensionProcess) || |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 175 |
| 172 void ExtensionDispatcher::OnDeliverMessage(int target_port_id, | 176 void ExtensionDispatcher::OnDeliverMessage(int target_port_id, |
| 173 const std::string& message) { | 177 const std::string& message) { |
| 174 RendererExtensionBindings::DeliverMessage( | 178 RendererExtensionBindings::DeliverMessage( |
| 175 v8_context_set_.GetAll(), | 179 v8_context_set_.GetAll(), |
| 176 target_port_id, | 180 target_port_id, |
| 177 message, | 181 message, |
| 178 NULL); // All render views. | 182 NULL); // All render views. |
| 179 } | 183 } |
| 180 | 184 |
| 181 void ExtensionDispatcher::OnLoaded(const ExtensionMsg_Loaded_Params& params) { | 185 void ExtensionDispatcher::OnLoaded( |
| 182 scoped_refptr<const Extension> extension(params.ConvertToExtension()); | 186 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions) { |
| 183 if (!extension) { | 187 std::vector<WebString> platform_app_patterns; |
| 184 // This can happen if extension parsing fails for any reason. One reason | 188 |
| 185 // this can legitimately happen is if the | 189 std::vector<ExtensionMsg_Loaded_Params>::const_iterator i; |
| 186 // --enable-experimental-extension-apis changes at runtime, which happens | 190 for (i = loaded_extensions.begin(); i != loaded_extensions.end(); ++i) { |
| 187 // during browser tests. Existing renderers won't know about the change. | 191 scoped_refptr<const Extension> extension(i->ConvertToExtension()); |
| 188 return; | 192 if (!extension) { |
| 193 // This can happen if extension parsing fails for any reason. One reason |
| 194 // this can legitimately happen is if the |
| 195 // --enable-experimental-extension-apis changes at runtime, which happens |
| 196 // during browser tests. Existing renderers won't know about the change. |
| 197 continue; |
| 198 } |
| 199 |
| 200 extensions_.Insert(extension); |
| 201 |
| 202 if (extension->is_platform_app()) { |
| 203 platform_app_patterns.push_back( |
| 204 WebString::fromUTF8(extension->url().spec() + "*")); |
| 205 } |
| 189 } | 206 } |
| 190 | 207 |
| 191 extensions_.Insert(extension); | 208 if (!platform_app_patterns.empty()) { |
| 209 // We have collected a set of platform-app extensions, so let's tell WebKit |
| 210 // about them so that it can provide a default stylesheet for them. |
| 211 // |
| 212 // TODO(miket): consider enhancing WebView to allow removing |
| 213 // single stylesheets, or else to edit the pattern set associated |
| 214 // with one. |
| 215 WebVector<WebString> patterns; |
| 216 patterns.assign(platform_app_patterns); |
| 217 WebView::addUserStyleSheet( |
| 218 WebString::fromUTF8(ResourceBundle::GetSharedInstance(). |
| 219 GetRawDataResource(IDR_PLATFORM_APP_CSS)), |
| 220 patterns, |
| 221 WebView::UserContentInjectInAllFrames, |
| 222 WebView::UserStyleInjectInExistingDocuments); |
| 223 } |
| 192 } | 224 } |
| 193 | 225 |
| 194 void ExtensionDispatcher::OnUnloaded(const std::string& id) { | 226 void ExtensionDispatcher::OnUnloaded(const std::string& id) { |
| 195 extensions_.Remove(id); | 227 extensions_.Remove(id); |
| 196 // If the extension is later reloaded with a different set of permissions, | 228 // If the extension is later reloaded with a different set of permissions, |
| 197 // we'd like it to get a new isolated world ID, so that it can pick up the | 229 // we'd like it to get a new isolated world ID, so that it can pick up the |
| 198 // changed origin whitelist. | 230 // changed origin whitelist. |
| 199 user_script_slave_->RemoveIsolatedWorld(id); | 231 user_script_slave_->RemoveIsolatedWorld(id); |
| 232 |
| 233 // We don't do anything with existing platform-app stylesheets. They will |
| 234 // stay resident, but the URL pattern corresponding to the unloaded |
| 235 // extension's URL just won't match anything anymore. |
| 200 } | 236 } |
| 201 | 237 |
| 202 void ExtensionDispatcher::OnSetScriptingWhitelist( | 238 void ExtensionDispatcher::OnSetScriptingWhitelist( |
| 203 const Extension::ScriptingWhitelist& extension_ids) { | 239 const Extension::ScriptingWhitelist& extension_ids) { |
| 204 Extension::SetScriptingWhitelist(extension_ids); | 240 Extension::SetScriptingWhitelist(extension_ids); |
| 205 } | 241 } |
| 206 | 242 |
| 207 bool ExtensionDispatcher::IsApplicationActive( | 243 bool ExtensionDispatcher::IsApplicationActive( |
| 208 const std::string& extension_id) const { | 244 const std::string& extension_id) const { |
| 209 return active_application_ids_.find(extension_id) != | 245 return active_application_ids_.find(extension_id) != |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 | 443 |
| 408 RenderThread::Get()->RegisterExtension(extension); | 444 RenderThread::Get()->RegisterExtension(extension); |
| 409 } | 445 } |
| 410 | 446 |
| 411 void ExtensionDispatcher::OnUsingWebRequestAPI( | 447 void ExtensionDispatcher::OnUsingWebRequestAPI( |
| 412 bool adblock, bool adblock_plus, bool other) { | 448 bool adblock, bool adblock_plus, bool other) { |
| 413 webrequest_adblock_ = adblock; | 449 webrequest_adblock_ = adblock; |
| 414 webrequest_adblock_plus_ = adblock_plus; | 450 webrequest_adblock_plus_ = adblock_plus; |
| 415 webrequest_other_ = other; | 451 webrequest_other_ = other; |
| 416 } | 452 } |
| OLD | NEW |