Chromium Code Reviews| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 } // namespace | 204 } // namespace |
| 205 | 205 |
| 206 // Note that we can't use Blink public APIs in the constructor becase Blink | 206 // Note that we can't use Blink public APIs in the constructor becase Blink |
| 207 // is not initialized at the point we create Dispatcher. | 207 // is not initialized at the point we create Dispatcher. |
| 208 Dispatcher::Dispatcher(DispatcherDelegate* delegate) | 208 Dispatcher::Dispatcher(DispatcherDelegate* delegate) |
| 209 : delegate_(delegate), | 209 : delegate_(delegate), |
| 210 content_watcher_(new ContentWatcher()), | 210 content_watcher_(new ContentWatcher()), |
| 211 source_map_(&ResourceBundle::GetSharedInstance()), | 211 source_map_(&ResourceBundle::GetSharedInstance()), |
| 212 v8_schema_registry_(new V8SchemaRegistry), | 212 v8_schema_registry_(new V8SchemaRegistry), |
| 213 user_script_set_manager_observer_(this), | 213 user_script_set_manager_observer_(this), |
| 214 webrequest_used_(false) { | 214 webrequest_used_(false), |
| 215 activity_logging_enabled_(false) { | |
| 215 const base::CommandLine& command_line = | 216 const base::CommandLine& command_line = |
| 216 *(base::CommandLine::ForCurrentProcess()); | 217 *(base::CommandLine::ForCurrentProcess()); |
| 217 set_idle_notifications_ = | 218 set_idle_notifications_ = |
| 218 command_line.HasSwitch(switches::kExtensionProcess) || | 219 command_line.HasSwitch(switches::kExtensionProcess) || |
| 219 command_line.HasSwitch(::switches::kSingleProcess); | 220 command_line.HasSwitch(::switches::kSingleProcess); |
| 220 | 221 |
| 221 if (set_idle_notifications_) { | 222 if (set_idle_notifications_) { |
| 222 RenderThread::Get()->SetIdleNotificationDelayInMs( | 223 RenderThread::Get()->SetIdleNotificationDelayInMs( |
| 223 kInitialExtensionIdleHandlerDelayMs); | 224 kInitialExtensionIdleHandlerDelayMs); |
| 224 } | 225 } |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 std::unique_ptr<NativeHandler>(MessagingBindings::Get(context))); | 884 std::unique_ptr<NativeHandler>(MessagingBindings::Get(context))); |
| 884 module_system->RegisterNativeHandler( | 885 module_system->RegisterNativeHandler( |
| 885 "apiDefinitions", std::unique_ptr<NativeHandler>( | 886 "apiDefinitions", std::unique_ptr<NativeHandler>( |
| 886 new ApiDefinitionsNatives(dispatcher, context))); | 887 new ApiDefinitionsNatives(dispatcher, context))); |
| 887 module_system->RegisterNativeHandler( | 888 module_system->RegisterNativeHandler( |
| 888 "sendRequest", std::unique_ptr<NativeHandler>( | 889 "sendRequest", std::unique_ptr<NativeHandler>( |
| 889 new SendRequestNatives(request_sender, context))); | 890 new SendRequestNatives(request_sender, context))); |
| 890 module_system->RegisterNativeHandler( | 891 module_system->RegisterNativeHandler( |
| 891 "setIcon", std::unique_ptr<NativeHandler>(new SetIconNatives(context))); | 892 "setIcon", std::unique_ptr<NativeHandler>(new SetIconNatives(context))); |
| 892 module_system->RegisterNativeHandler( | 893 module_system->RegisterNativeHandler( |
| 893 "activityLogger", | 894 "activityLogger", std::unique_ptr<NativeHandler>( |
| 894 std::unique_ptr<NativeHandler>(new APIActivityLogger(context))); | 895 new APIActivityLogger(context, dispatcher))); |
| 895 module_system->RegisterNativeHandler( | 896 module_system->RegisterNativeHandler( |
| 896 "renderFrameObserverNatives", | 897 "renderFrameObserverNatives", |
| 897 std::unique_ptr<NativeHandler>(new RenderFrameObserverNatives(context))); | 898 std::unique_ptr<NativeHandler>(new RenderFrameObserverNatives(context))); |
| 898 | 899 |
| 899 // Natives used by multiple APIs. | 900 // Natives used by multiple APIs. |
| 900 module_system->RegisterNativeHandler( | 901 module_system->RegisterNativeHandler( |
| 901 "file_system_natives", | 902 "file_system_natives", |
| 902 std::unique_ptr<NativeHandler>(new FileSystemNatives(context))); | 903 std::unique_ptr<NativeHandler>(new FileSystemNatives(context))); |
| 903 | 904 |
| 904 // Custom bindings. | 905 // Custom bindings. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 947 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend) | 948 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend) |
| 948 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend) | 949 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend) |
| 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) |
| 958 IPC_MESSAGE_HANDLER(ExtensionMsg_SetActivityLoggingEnabled, | |
| 959 OnSetActivityLoggingEnabled) | |
| 957 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages, | 960 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages, |
| 958 content_watcher_.get(), | 961 content_watcher_.get(), |
| 959 ContentWatcher::OnWatchPages) | 962 ContentWatcher::OnWatchPages) |
| 960 IPC_MESSAGE_UNHANDLED(handled = false) | 963 IPC_MESSAGE_UNHANDLED(handled = false) |
| 961 IPC_END_MESSAGE_MAP() | 964 IPC_END_MESSAGE_MAP() |
| 962 | 965 |
| 963 return handled; | 966 return handled; |
| 964 } | 967 } |
| 965 void Dispatcher::IdleNotification() { | 968 void Dispatcher::IdleNotification() { |
| 966 if (set_idle_notifications_ && forced_idle_timer_) { | 969 if (set_idle_notifications_ && forced_idle_timer_) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1008 error.c_str()); | 1011 error.c_str()); |
| 1009 LOG(FATAL) << extension_id << " was never loaded: " << error; | 1012 LOG(FATAL) << extension_id << " was never loaded: " << error; |
| 1010 } | 1013 } |
| 1011 | 1014 |
| 1012 active_extension_ids_.insert(extension_id); | 1015 active_extension_ids_.insert(extension_id); |
| 1013 | 1016 |
| 1014 // This is called when starting a new extension page, so start the idle | 1017 // This is called when starting a new extension page, so start the idle |
| 1015 // handler ticking. | 1018 // handler ticking. |
| 1016 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); | 1019 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); |
| 1017 | 1020 |
| 1018 DOMActivityLogger::AttachToWorld( | 1021 if (activity_logging_enabled_) { |
| 1019 DOMActivityLogger::kMainWorldId, extension_id); | 1022 DOMActivityLogger::AttachToWorld(DOMActivityLogger::kMainWorldId, |
| 1023 extension_id); | |
|
asargent_no_longer_on_chrome
2016/06/23 13:35:56
Does this mean that even after the first activity-
Devlin
2016/06/23 16:59:02
Good point! Added this into OnSetActivityLoggingE
| |
| 1024 } | |
| 1020 | 1025 |
| 1021 InitOriginPermissions(extension); | 1026 InitOriginPermissions(extension); |
| 1022 | 1027 |
| 1023 UpdateActiveExtensions(); | 1028 UpdateActiveExtensions(); |
| 1024 } | 1029 } |
| 1025 | 1030 |
| 1026 void Dispatcher::OnCancelSuspend(const std::string& extension_id) { | 1031 void Dispatcher::OnCancelSuspend(const std::string& extension_id) { |
| 1027 DispatchEvent(extension_id, kOnSuspendCanceledEvent); | 1032 DispatchEvent(extension_id, kOnSuspendCanceledEvent); |
| 1028 } | 1033 } |
| 1029 | 1034 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1248 extension->permissions_data()->GetEffectiveHostPermissions()); | 1253 extension->permissions_data()->GetEffectiveHostPermissions()); |
| 1249 } | 1254 } |
| 1250 } | 1255 } |
| 1251 } | 1256 } |
| 1252 } | 1257 } |
| 1253 | 1258 |
| 1254 void Dispatcher::OnUsingWebRequestAPI(bool webrequest_used) { | 1259 void Dispatcher::OnUsingWebRequestAPI(bool webrequest_used) { |
| 1255 webrequest_used_ = webrequest_used; | 1260 webrequest_used_ = webrequest_used; |
| 1256 } | 1261 } |
| 1257 | 1262 |
| 1263 void Dispatcher::OnSetActivityLoggingEnabled(bool enabled) { | |
| 1264 activity_logging_enabled_ = enabled; | |
| 1265 script_injection_manager_->set_activity_logging_enabled(enabled); | |
| 1266 user_script_set_manager_->set_activity_logging_enabled(enabled); | |
| 1267 } | |
| 1268 | |
| 1258 void Dispatcher::OnUserScriptsUpdated(const std::set<HostID>& changed_hosts, | 1269 void Dispatcher::OnUserScriptsUpdated(const std::set<HostID>& changed_hosts, |
| 1259 const std::vector<UserScript*>& scripts) { | 1270 const std::vector<UserScript*>& scripts) { |
| 1260 UpdateActiveExtensions(); | 1271 UpdateActiveExtensions(); |
| 1261 } | 1272 } |
| 1262 | 1273 |
| 1263 void Dispatcher::UpdateActiveExtensions() { | 1274 void Dispatcher::UpdateActiveExtensions() { |
| 1264 std::set<std::string> active_extensions = active_extension_ids_; | 1275 std::set<std::string> active_extensions = active_extension_ids_; |
| 1265 user_script_set_manager_->GetAllActiveExtensionIds(&active_extensions); | 1276 user_script_set_manager_->GetAllActiveExtensionIds(&active_extensions); |
| 1266 delegate_->OnActiveExtensionsUpdated(active_extensions); | 1277 delegate_->OnActiveExtensionsUpdated(active_extensions); |
| 1267 } | 1278 } |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1645 // The "guestViewDeny" module must always be loaded last. It registers | 1656 // The "guestViewDeny" module must always be loaded last. It registers |
| 1646 // error-providing custom elements for the GuestView types that are not | 1657 // error-providing custom elements for the GuestView types that are not |
| 1647 // available, and thus all of those types must have been checked and loaded | 1658 // available, and thus all of those types must have been checked and loaded |
| 1648 // (or not loaded) beforehand. | 1659 // (or not loaded) beforehand. |
| 1649 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1660 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
| 1650 module_system->Require("guestViewDeny"); | 1661 module_system->Require("guestViewDeny"); |
| 1651 } | 1662 } |
| 1652 } | 1663 } |
| 1653 | 1664 |
| 1654 } // namespace extensions | 1665 } // namespace extensions |
| OLD | NEW |