| 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 #include "extensions/renderer/dispatcher.h" | 5 #include "extensions/renderer/dispatcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/containers/scoped_ptr_map.h" | 10 #include "base/containers/scoped_ptr_map.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 mutable base::Lock lock_; | 216 mutable base::Lock lock_; |
| 217 | 217 |
| 218 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptContextSet); | 218 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptContextSet); |
| 219 }; | 219 }; |
| 220 | 220 |
| 221 base::LazyInstance<ServiceWorkerScriptContextSet> | 221 base::LazyInstance<ServiceWorkerScriptContextSet> |
| 222 g_service_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; | 222 g_service_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; |
| 223 | 223 |
| 224 } // namespace | 224 } // namespace |
| 225 | 225 |
| 226 // Note that we can't use Blink public APIs in the constructor becase Blink |
| 227 // is not initialized at the point we create Dispatcher. |
| 226 Dispatcher::Dispatcher(DispatcherDelegate* delegate) | 228 Dispatcher::Dispatcher(DispatcherDelegate* delegate) |
| 227 : delegate_(delegate), | 229 : delegate_(delegate), |
| 228 content_watcher_(new ContentWatcher()), | 230 content_watcher_(new ContentWatcher()), |
| 229 source_map_(&ResourceBundle::GetSharedInstance()), | 231 source_map_(&ResourceBundle::GetSharedInstance()), |
| 230 v8_schema_registry_(new V8SchemaRegistry), | 232 v8_schema_registry_(new V8SchemaRegistry), |
| 231 is_webkit_initialized_(false), | 233 is_webkit_initialized_(false), |
| 232 user_script_set_manager_observer_(this), | 234 user_script_set_manager_observer_(this), |
| 233 webrequest_used_(false) { | 235 webrequest_used_(false) { |
| 234 const base::CommandLine& command_line = | 236 const base::CommandLine& command_line = |
| 235 *(base::CommandLine::ForCurrentProcess()); | 237 *(base::CommandLine::ForCurrentProcess()); |
| 236 set_idle_notifications_ = | 238 set_idle_notifications_ = |
| 237 command_line.HasSwitch(switches::kExtensionProcess) || | 239 command_line.HasSwitch(switches::kExtensionProcess) || |
| 238 command_line.HasSwitch(::switches::kSingleProcess); | 240 command_line.HasSwitch(::switches::kSingleProcess); |
| 239 | 241 |
| 240 if (set_idle_notifications_) { | 242 if (set_idle_notifications_) { |
| 241 RenderThread::Get()->SetIdleNotificationDelayInMs( | 243 RenderThread::Get()->SetIdleNotificationDelayInMs( |
| 242 kInitialExtensionIdleHandlerDelayMs); | 244 kInitialExtensionIdleHandlerDelayMs); |
| 243 } | 245 } |
| 244 | 246 |
| 245 script_context_set_.reset(new ScriptContextSet(&active_extension_ids_)); | 247 script_context_set_.reset(new ScriptContextSet(&active_extension_ids_)); |
| 246 user_script_set_manager_.reset(new UserScriptSetManager()); | 248 user_script_set_manager_.reset(new UserScriptSetManager()); |
| 247 script_injection_manager_.reset( | 249 script_injection_manager_.reset( |
| 248 new ScriptInjectionManager(user_script_set_manager_.get())); | 250 new ScriptInjectionManager(user_script_set_manager_.get())); |
| 249 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); | 251 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); |
| 250 request_sender_.reset(new RequestSender(this)); | 252 request_sender_.reset(new RequestSender(this)); |
| 251 PopulateSourceMap(); | 253 PopulateSourceMap(); |
| 252 WakeEventPage::Get()->Init(content::RenderThread::Get()); | 254 WakeEventPage::Get()->Init(content::RenderThread::Get()); |
| 253 | |
| 254 // WebSecurityPolicy whitelists. They should be registered for both | |
| 255 // chrome-extension: and chrome-extension-resource. | |
| 256 using RegisterFunction = void (*)(const WebString&); | |
| 257 RegisterFunction register_functions[] = { | |
| 258 // Treat as secure because communication with them is entirely in the | |
| 259 // browser, so there is no danger of manipulation or eavesdropping on | |
| 260 // communication with them by third parties. | |
| 261 WebSecurityPolicy::registerURLSchemeAsSecure, | |
| 262 // As far as Blink is concerned, they should be allowed to receive CORS | |
| 263 // requests. At the Extensions layer, requests will actually be blocked | |
| 264 // unless overridden by the web_accessible_resources manifest key. | |
| 265 // TODO(kalman): See what happens with a service worker. | |
| 266 WebSecurityPolicy::registerURLSchemeAsCORSEnabled, | |
| 267 // Resources should bypass Content Security Policy checks when included in | |
| 268 // protected resources. TODO(kalman): What are "protected resources"? | |
| 269 WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy, | |
| 270 // Extension resources are HTTP-like and safe to expose to the fetch API. | |
| 271 // The rules for the fetch API are consistent with XHR. | |
| 272 WebSecurityPolicy::registerURLSchemeAsSupportingFetchAPI, | |
| 273 }; | |
| 274 | |
| 275 WebString extension_scheme(base::ASCIIToUTF16(kExtensionScheme)); | |
| 276 WebString extension_resource_scheme(base::ASCIIToUTF16( | |
| 277 kExtensionResourceScheme)); | |
| 278 for (RegisterFunction func : register_functions) { | |
| 279 func(extension_scheme); | |
| 280 func(extension_resource_scheme); | |
| 281 } | |
| 282 } | 255 } |
| 283 | 256 |
| 284 Dispatcher::~Dispatcher() { | 257 Dispatcher::~Dispatcher() { |
| 285 } | 258 } |
| 286 | 259 |
| 287 void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { | 260 void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { |
| 288 script_injection_manager_->OnRenderFrameCreated(render_frame); | 261 script_injection_manager_->OnRenderFrameCreated(render_frame); |
| 289 } | 262 } |
| 290 | 263 |
| 291 bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { | 264 bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 ContentWatcher::OnWatchPages) | 832 ContentWatcher::OnWatchPages) |
| 860 IPC_MESSAGE_UNHANDLED(handled = false) | 833 IPC_MESSAGE_UNHANDLED(handled = false) |
| 861 IPC_END_MESSAGE_MAP() | 834 IPC_END_MESSAGE_MAP() |
| 862 | 835 |
| 863 return handled; | 836 return handled; |
| 864 } | 837 } |
| 865 | 838 |
| 866 void Dispatcher::WebKitInitialized() { | 839 void Dispatcher::WebKitInitialized() { |
| 867 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension()); | 840 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension()); |
| 868 | 841 |
| 842 // WebSecurityPolicy whitelists. They should be registered for both |
| 843 // chrome-extension: and chrome-extension-resource. |
| 844 using RegisterFunction = void (*)(const WebString&); |
| 845 RegisterFunction register_functions[] = { |
| 846 // Treat as secure because communication with them is entirely in the |
| 847 // browser, so there is no danger of manipulation or eavesdropping on |
| 848 // communication with them by third parties. |
| 849 WebSecurityPolicy::registerURLSchemeAsSecure, |
| 850 // As far as Blink is concerned, they should be allowed to receive CORS |
| 851 // requests. At the Extensions layer, requests will actually be blocked |
| 852 // unless overridden by the web_accessible_resources manifest key. |
| 853 // TODO(kalman): See what happens with a service worker. |
| 854 WebSecurityPolicy::registerURLSchemeAsCORSEnabled, |
| 855 // Resources should bypass Content Security Policy checks when included in |
| 856 // protected resources. TODO(kalman): What are "protected resources"? |
| 857 WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy, |
| 858 // Extension resources are HTTP-like and safe to expose to the fetch API. |
| 859 // The rules for the fetch API are consistent with XHR. |
| 860 WebSecurityPolicy::registerURLSchemeAsSupportingFetchAPI, |
| 861 }; |
| 862 |
| 863 WebString extension_scheme(base::ASCIIToUTF16(kExtensionScheme)); |
| 864 WebString extension_resource_scheme(base::ASCIIToUTF16( |
| 865 kExtensionResourceScheme)); |
| 866 for (RegisterFunction func : register_functions) { |
| 867 func(extension_scheme); |
| 868 func(extension_resource_scheme); |
| 869 } |
| 870 |
| 869 // For extensions, we want to ensure we call the IdleHandler every so often, | 871 // For extensions, we want to ensure we call the IdleHandler every so often, |
| 870 // even if the extension keeps up activity. | 872 // even if the extension keeps up activity. |
| 871 if (set_idle_notifications_) { | 873 if (set_idle_notifications_) { |
| 872 forced_idle_timer_.reset(new base::RepeatingTimer<content::RenderThread>); | 874 forced_idle_timer_.reset(new base::RepeatingTimer<content::RenderThread>); |
| 873 forced_idle_timer_->Start( | 875 forced_idle_timer_->Start( |
| 874 FROM_HERE, | 876 FROM_HERE, |
| 875 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), | 877 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), |
| 876 RenderThread::Get(), | 878 RenderThread::Get(), |
| 877 &RenderThread::IdleHandler); | 879 &RenderThread::IdleHandler); |
| 878 } | 880 } |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 void Dispatcher::AddChannelSpecificFeatures() { | 1569 void Dispatcher::AddChannelSpecificFeatures() { |
| 1568 // chrome-extension: resources should be allowed to register a Service Worker. | 1570 // chrome-extension: resources should be allowed to register a Service Worker. |
| 1569 if (FeatureProvider::GetBehaviorFeature(BehaviorFeature::kServiceWorker) | 1571 if (FeatureProvider::GetBehaviorFeature(BehaviorFeature::kServiceWorker) |
| 1570 ->IsAvailableToEnvironment() | 1572 ->IsAvailableToEnvironment() |
| 1571 .is_available()) | 1573 .is_available()) |
| 1572 WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers( | 1574 WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers( |
| 1573 WebString::fromUTF8(kExtensionScheme)); | 1575 WebString::fromUTF8(kExtensionScheme)); |
| 1574 } | 1576 } |
| 1575 | 1577 |
| 1576 } // namespace extensions | 1578 } // namespace extensions |
| OLD | NEW |