| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 206 |
| 207 // Note that we can't use Blink public APIs in the constructor becase Blink | 207 // Note that we can't use Blink public APIs in the constructor becase Blink |
| 208 // is not initialized at the point we create Dispatcher. | 208 // is not initialized at the point we create Dispatcher. |
| 209 Dispatcher::Dispatcher(DispatcherDelegate* delegate) | 209 Dispatcher::Dispatcher(DispatcherDelegate* delegate) |
| 210 : delegate_(delegate), | 210 : delegate_(delegate), |
| 211 content_watcher_(new ContentWatcher()), | 211 content_watcher_(new ContentWatcher()), |
| 212 source_map_(&ResourceBundle::GetSharedInstance()), | 212 source_map_(&ResourceBundle::GetSharedInstance()), |
| 213 v8_schema_registry_(new V8SchemaRegistry), | 213 v8_schema_registry_(new V8SchemaRegistry), |
| 214 user_script_set_manager_observer_(this), | 214 user_script_set_manager_observer_(this), |
| 215 webrequest_used_(false), | 215 webrequest_used_(false), |
| 216 activity_logging_enabled_(false) { | 216 activity_logging_enabled_(false), |
| 217 session_type_(Feature::SESSION_TYPE_UNSPECIFIED) { |
| 217 const base::CommandLine& command_line = | 218 const base::CommandLine& command_line = |
| 218 *(base::CommandLine::ForCurrentProcess()); | 219 *(base::CommandLine::ForCurrentProcess()); |
| 219 set_idle_notifications_ = | 220 set_idle_notifications_ = |
| 220 command_line.HasSwitch(switches::kExtensionProcess) || | 221 command_line.HasSwitch(switches::kExtensionProcess) || |
| 221 command_line.HasSwitch(::switches::kSingleProcess); | 222 command_line.HasSwitch(::switches::kSingleProcess); |
| 222 | 223 |
| 223 if (set_idle_notifications_) { | 224 if (set_idle_notifications_) { |
| 224 RenderThread::Get()->SetIdleNotificationDelayInMs( | 225 RenderThread::Get()->SetIdleNotificationDelayInMs( |
| 225 kInitialExtensionIdleHandlerDelayMs); | 226 kInitialExtensionIdleHandlerDelayMs); |
| 226 } | 227 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 } | 313 } |
| 313 | 314 |
| 314 void Dispatcher::DidCreateScriptContext( | 315 void Dispatcher::DidCreateScriptContext( |
| 315 blink::WebLocalFrame* frame, | 316 blink::WebLocalFrame* frame, |
| 316 const v8::Local<v8::Context>& v8_context, | 317 const v8::Local<v8::Context>& v8_context, |
| 317 int extension_group, | 318 int extension_group, |
| 318 int world_id) { | 319 int world_id) { |
| 319 const base::TimeTicks start_time = base::TimeTicks::Now(); | 320 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 320 | 321 |
| 321 ScriptContext* context = script_context_set_->Register( | 322 ScriptContext* context = script_context_set_->Register( |
| 322 frame, v8_context, extension_group, world_id); | 323 frame, v8_context, session_type_, extension_group, world_id); |
| 323 | 324 |
| 324 // Initialize origin permissions for content scripts, which can't be | 325 // Initialize origin permissions for content scripts, which can't be |
| 325 // initialized in |OnActivateExtension|. | 326 // initialized in |OnActivateExtension|. |
| 326 if (context->context_type() == Feature::CONTENT_SCRIPT_CONTEXT) | 327 if (context->context_type() == Feature::CONTENT_SCRIPT_CONTEXT) |
| 327 InitOriginPermissions(context->extension()); | 328 InitOriginPermissions(context->extension()); |
| 328 | 329 |
| 329 { | 330 { |
| 330 std::unique_ptr<ModuleSystem> module_system( | 331 std::unique_ptr<ModuleSystem> module_system( |
| 331 new ModuleSystem(context, &source_map_)); | 332 new ModuleSystem(context, &source_map_)); |
| 332 context->set_module_system(std::move(module_system)); | 333 context->set_module_system(std::move(module_system)); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 // to find them. | 433 // to find them. |
| 433 // | 434 // |
| 434 // Perhaps this could be solved with our own event on the service worker | 435 // Perhaps this could be solved with our own event on the service worker |
| 435 // saying that an extension is ready, and documenting that extension APIs | 436 // saying that an extension is ready, and documenting that extension APIs |
| 436 // won't work before that event has fired? | 437 // won't work before that event has fired? |
| 437 return; | 438 return; |
| 438 } | 439 } |
| 439 | 440 |
| 440 ScriptContext* context = new ScriptContext( | 441 ScriptContext* context = new ScriptContext( |
| 441 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, | 442 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, |
| 442 extension, Feature::SERVICE_WORKER_CONTEXT); | 443 session_type_, extension, Feature::SERVICE_WORKER_CONTEXT); |
| 443 context->set_url(url); | 444 context->set_url(url); |
| 444 | 445 |
| 445 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) { | 446 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) { |
| 446 WorkerThreadDispatcher::Get()->AddWorkerData(embedded_worker_id); | 447 WorkerThreadDispatcher::Get()->AddWorkerData(embedded_worker_id); |
| 447 { | 448 { |
| 448 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is | 449 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is |
| 449 // safe. | 450 // safe. |
| 450 std::unique_ptr<ModuleSystem> module_system( | 451 std::unique_ptr<ModuleSystem> module_system( |
| 451 new ModuleSystem(context, &source_map_)); | 452 new ModuleSystem(context, &source_map_)); |
| 452 context->set_module_system(std::move(module_system)); | 453 context->set_module_system(std::move(module_system)); |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs) | 950 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs) |
| 950 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) | 951 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) |
| 951 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) | 952 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) |
| 952 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions, | 953 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions, |
| 953 OnUpdateTabSpecificPermissions) | 954 OnUpdateTabSpecificPermissions) |
| 954 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, | 955 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, |
| 955 OnClearTabSpecificPermissions) | 956 OnClearTabSpecificPermissions) |
| 956 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) | 957 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) |
| 957 IPC_MESSAGE_HANDLER(ExtensionMsg_SetActivityLoggingEnabled, | 958 IPC_MESSAGE_HANDLER(ExtensionMsg_SetActivityLoggingEnabled, |
| 958 OnSetActivityLoggingEnabled) | 959 OnSetActivityLoggingEnabled) |
| 960 IPC_MESSAGE_HANDLER(ExtensionMsg_SetUserSessionType, OnSetUserSessionType) |
| 959 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages, | 961 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages, |
| 960 content_watcher_.get(), | 962 content_watcher_.get(), |
| 961 ContentWatcher::OnWatchPages) | 963 ContentWatcher::OnWatchPages) |
| 962 IPC_MESSAGE_UNHANDLED(handled = false) | 964 IPC_MESSAGE_UNHANDLED(handled = false) |
| 963 IPC_END_MESSAGE_MAP() | 965 IPC_END_MESSAGE_MAP() |
| 964 | 966 |
| 965 return handled; | 967 return handled; |
| 966 } | 968 } |
| 967 void Dispatcher::IdleNotification() { | 969 void Dispatcher::IdleNotification() { |
| 968 if (set_idle_notifications_ && forced_idle_timer_) { | 970 if (set_idle_notifications_ && forced_idle_timer_) { |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 void Dispatcher::OnSetActivityLoggingEnabled(bool enabled) { | 1277 void Dispatcher::OnSetActivityLoggingEnabled(bool enabled) { |
| 1276 activity_logging_enabled_ = enabled; | 1278 activity_logging_enabled_ = enabled; |
| 1277 if (enabled) { | 1279 if (enabled) { |
| 1278 for (const std::string& id : active_extension_ids_) | 1280 for (const std::string& id : active_extension_ids_) |
| 1279 DOMActivityLogger::AttachToWorld(DOMActivityLogger::kMainWorldId, id); | 1281 DOMActivityLogger::AttachToWorld(DOMActivityLogger::kMainWorldId, id); |
| 1280 } | 1282 } |
| 1281 script_injection_manager_->set_activity_logging_enabled(enabled); | 1283 script_injection_manager_->set_activity_logging_enabled(enabled); |
| 1282 user_script_set_manager_->set_activity_logging_enabled(enabled); | 1284 user_script_set_manager_->set_activity_logging_enabled(enabled); |
| 1283 } | 1285 } |
| 1284 | 1286 |
| 1287 void Dispatcher::OnSetUserSessionType(Feature::SessionType session_type) { |
| 1288 session_type_ = session_type; |
| 1289 } |
| 1290 |
| 1285 void Dispatcher::OnUserScriptsUpdated(const std::set<HostID>& changed_hosts) { | 1291 void Dispatcher::OnUserScriptsUpdated(const std::set<HostID>& changed_hosts) { |
| 1286 UpdateActiveExtensions(); | 1292 UpdateActiveExtensions(); |
| 1287 } | 1293 } |
| 1288 | 1294 |
| 1289 void Dispatcher::UpdateActiveExtensions() { | 1295 void Dispatcher::UpdateActiveExtensions() { |
| 1290 std::set<std::string> active_extensions = active_extension_ids_; | 1296 std::set<std::string> active_extensions = active_extension_ids_; |
| 1291 user_script_set_manager_->GetAllActiveExtensionIds(&active_extensions); | 1297 user_script_set_manager_->GetAllActiveExtensionIds(&active_extensions); |
| 1292 delegate_->OnActiveExtensionsUpdated(active_extensions); | 1298 delegate_->OnActiveExtensionsUpdated(active_extensions); |
| 1293 } | 1299 } |
| 1294 | 1300 |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 // The "guestViewDeny" module must always be loaded last. It registers | 1673 // The "guestViewDeny" module must always be loaded last. It registers |
| 1668 // error-providing custom elements for the GuestView types that are not | 1674 // error-providing custom elements for the GuestView types that are not |
| 1669 // available, and thus all of those types must have been checked and loaded | 1675 // available, and thus all of those types must have been checked and loaded |
| 1670 // (or not loaded) beforehand. | 1676 // (or not loaded) beforehand. |
| 1671 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1677 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
| 1672 module_system->Require("guestViewDeny"); | 1678 module_system->Require("guestViewDeny"); |
| 1673 } | 1679 } |
| 1674 } | 1680 } |
| 1675 | 1681 |
| 1676 } // namespace extensions | 1682 } // namespace extensions |
| OLD | NEW |