| 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 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" | 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/task_scheduler/post_task.h" | 19 #include "base/task_scheduler/post_task.h" |
| 20 #include "chrome/browser/devtools/devtools_window.h" | 20 #include "chrome/browser/devtools/devtools_window.h" |
| 21 #include "chrome/browser/extensions/api/developer_private/developer_private_mang
le.h" | 21 #include "chrome/browser/extensions/api/developer_private/developer_private_mang
le.h" |
| 22 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" | 22 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" |
| 23 #include "chrome/browser/extensions/api/developer_private/extension_info_generat
or.h" | 23 #include "chrome/browser/extensions/api/developer_private/extension_info_generat
or.h" |
| 24 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialo
g_helper.h" | 24 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialo
g_helper.h" |
| 25 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | |
| 26 #include "chrome/browser/extensions/devtools_util.h" | 25 #include "chrome/browser/extensions/devtools_util.h" |
| 27 #include "chrome/browser/extensions/extension_commands_global_registry.h" | 26 #include "chrome/browser/extensions/extension_commands_global_registry.h" |
| 28 #include "chrome/browser/extensions/extension_service.h" | 27 #include "chrome/browser/extensions/extension_service.h" |
| 29 #include "chrome/browser/extensions/extension_tab_util.h" | 28 #include "chrome/browser/extensions/extension_tab_util.h" |
| 30 #include "chrome/browser/extensions/extension_ui_util.h" | 29 #include "chrome/browser/extensions/extension_ui_util.h" |
| 31 #include "chrome/browser/extensions/extension_util.h" | 30 #include "chrome/browser/extensions/extension_util.h" |
| 32 #include "chrome/browser/extensions/install_verifier.h" | 31 #include "chrome/browser/extensions/install_verifier.h" |
| 33 #include "chrome/browser/extensions/path_util.h" | 32 #include "chrome/browser/extensions/path_util.h" |
| 34 #include "chrome/browser/extensions/scripting_permissions_modifier.h" | 33 #include "chrome/browser/extensions/scripting_permissions_modifier.h" |
| 35 #include "chrome/browser/extensions/shared_module_service.h" | 34 #include "chrome/browser/extensions/shared_module_service.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 DeveloperPrivateAPI::DeveloperPrivateAPI(content::BrowserContext* context) | 235 DeveloperPrivateAPI::DeveloperPrivateAPI(content::BrowserContext* context) |
| 237 : profile_(Profile::FromBrowserContext(context)), weak_factory_(this) { | 236 : profile_(Profile::FromBrowserContext(context)), weak_factory_(this) { |
| 238 RegisterNotifications(); | 237 RegisterNotifications(); |
| 239 } | 238 } |
| 240 | 239 |
| 241 DeveloperPrivateEventRouter::DeveloperPrivateEventRouter(Profile* profile) | 240 DeveloperPrivateEventRouter::DeveloperPrivateEventRouter(Profile* profile) |
| 242 : extension_registry_observer_(this), | 241 : extension_registry_observer_(this), |
| 243 error_console_observer_(this), | 242 error_console_observer_(this), |
| 244 process_manager_observer_(this), | 243 process_manager_observer_(this), |
| 245 app_window_registry_observer_(this), | 244 app_window_registry_observer_(this), |
| 246 extension_action_api_observer_(this), | |
| 247 warning_service_observer_(this), | 245 warning_service_observer_(this), |
| 248 extension_prefs_observer_(this), | 246 extension_prefs_observer_(this), |
| 249 extension_management_observer_(this), | 247 extension_management_observer_(this), |
| 250 command_service_observer_(this), | 248 command_service_observer_(this), |
| 251 profile_(profile), | 249 profile_(profile), |
| 252 event_router_(EventRouter::Get(profile_)), | 250 event_router_(EventRouter::Get(profile_)), |
| 253 weak_factory_(this) { | 251 weak_factory_(this) { |
| 254 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | 252 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| 255 error_console_observer_.Add(ErrorConsole::Get(profile)); | 253 error_console_observer_.Add(ErrorConsole::Get(profile)); |
| 256 process_manager_observer_.Add(ProcessManager::Get(profile)); | 254 process_manager_observer_.Add(ProcessManager::Get(profile)); |
| 257 app_window_registry_observer_.Add(AppWindowRegistry::Get(profile)); | 255 app_window_registry_observer_.Add(AppWindowRegistry::Get(profile)); |
| 258 extension_action_api_observer_.Add(ExtensionActionAPI::Get(profile)); | |
| 259 warning_service_observer_.Add(WarningService::Get(profile)); | 256 warning_service_observer_.Add(WarningService::Get(profile)); |
| 260 extension_prefs_observer_.Add(ExtensionPrefs::Get(profile)); | 257 extension_prefs_observer_.Add(ExtensionPrefs::Get(profile)); |
| 261 extension_management_observer_.Add( | 258 extension_management_observer_.Add( |
| 262 ExtensionManagementFactory::GetForBrowserContext(profile)); | 259 ExtensionManagementFactory::GetForBrowserContext(profile)); |
| 263 command_service_observer_.Add(CommandService::Get(profile)); | 260 command_service_observer_.Add(CommandService::Get(profile)); |
| 264 pref_change_registrar_.Init(profile->GetPrefs()); | 261 pref_change_registrar_.Init(profile->GetPrefs()); |
| 265 // The unretained is safe, since the PrefChangeRegistrar unregisters the | 262 // The unretained is safe, since the PrefChangeRegistrar unregisters the |
| 266 // callback on destruction. | 263 // callback on destruction. |
| 267 pref_change_registrar_.Add( | 264 pref_change_registrar_.Add( |
| 268 prefs::kExtensionsUIDeveloperMode, | 265 prefs::kExtensionsUIDeveloperMode, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 extension_id); | 361 extension_id); |
| 365 } | 362 } |
| 366 | 363 |
| 367 void DeveloperPrivateEventRouter::OnExtensionCommandRemoved( | 364 void DeveloperPrivateEventRouter::OnExtensionCommandRemoved( |
| 368 const std::string& extension_id, | 365 const std::string& extension_id, |
| 369 const Command& removed_command) { | 366 const Command& removed_command) { |
| 370 BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, | 367 BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, |
| 371 extension_id); | 368 extension_id); |
| 372 } | 369 } |
| 373 | 370 |
| 374 void DeveloperPrivateEventRouter::OnExtensionActionVisibilityChanged( | |
| 375 const std::string& extension_id, | |
| 376 bool is_now_visible) { | |
| 377 BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, extension_id); | |
| 378 } | |
| 379 | |
| 380 void DeveloperPrivateEventRouter::OnExtensionDisableReasonsChanged( | 371 void DeveloperPrivateEventRouter::OnExtensionDisableReasonsChanged( |
| 381 const std::string& extension_id, int disable_reasons) { | 372 const std::string& extension_id, int disable_reasons) { |
| 382 BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, extension_id); | 373 BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, extension_id); |
| 383 } | 374 } |
| 384 | 375 |
| 385 void DeveloperPrivateEventRouter::OnExtensionManagementSettingsChanged() { | 376 void DeveloperPrivateEventRouter::OnExtensionManagementSettingsChanged() { |
| 386 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 377 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 387 args->Append(CreateProfileInfo(profile_)->ToValue()); | 378 args->Append(CreateProfileInfo(profile_)->ToValue()); |
| 388 std::unique_ptr<Event> event( | 379 std::unique_ptr<Event> event( |
| 389 new Event(events::DEVELOPER_PRIVATE_ON_PROFILE_STATE_CHANGED, | 380 new Event(events::DEVELOPER_PRIVATE_ON_PROFILE_STATE_CHANGED, |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 if (update.run_on_all_urls) { | 705 if (update.run_on_all_urls) { |
| 715 ScriptingPermissionsModifier modifier(browser_context(), extension); | 706 ScriptingPermissionsModifier modifier(browser_context(), extension); |
| 716 if (!modifier.CanAffectExtension( | 707 if (!modifier.CanAffectExtension( |
| 717 extension->permissions_data()->active_permissions()) && | 708 extension->permissions_data()->active_permissions()) && |
| 718 !modifier.HasAffectedExtension()) { | 709 !modifier.HasAffectedExtension()) { |
| 719 return RespondNow( | 710 return RespondNow( |
| 720 Error("Cannot modify all urls of extension: " + extension->id())); | 711 Error("Cannot modify all urls of extension: " + extension->id())); |
| 721 } | 712 } |
| 722 modifier.SetAllowedOnAllUrls(*update.run_on_all_urls); | 713 modifier.SetAllowedOnAllUrls(*update.run_on_all_urls); |
| 723 } | 714 } |
| 724 if (update.show_action_button) { | |
| 725 ExtensionActionAPI::Get(browser_context())->SetBrowserActionVisibility( | |
| 726 extension->id(), | |
| 727 *update.show_action_button); | |
| 728 } | |
| 729 | 715 |
| 730 return RespondNow(NoArguments()); | 716 return RespondNow(NoArguments()); |
| 731 } | 717 } |
| 732 | 718 |
| 733 DeveloperPrivateReloadFunction::~DeveloperPrivateReloadFunction() {} | 719 DeveloperPrivateReloadFunction::~DeveloperPrivateReloadFunction() {} |
| 734 | 720 |
| 735 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() { | 721 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() { |
| 736 std::unique_ptr<Reload::Params> params(Reload::Params::Create(*args_)); | 722 std::unique_ptr<Reload::Params> params(Reload::Params::Create(*args_)); |
| 737 EXTENSION_FUNCTION_VALIDATE(params.get()); | 723 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 738 | 724 |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1576 update.extension_id, update.command_name, *update.keybinding); | 1562 update.extension_id, update.command_name, *update.keybinding); |
| 1577 } | 1563 } |
| 1578 | 1564 |
| 1579 return RespondNow(NoArguments()); | 1565 return RespondNow(NoArguments()); |
| 1580 } | 1566 } |
| 1581 | 1567 |
| 1582 | 1568 |
| 1583 } // namespace api | 1569 } // namespace api |
| 1584 | 1570 |
| 1585 } // namespace extensions | 1571 } // namespace extensions |
| OLD | NEW |