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/management/management_api.h" | 5 #include "chrome/browser/extensions/api/management/management_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/extensions/extension_ui_util.h" | 23 #include "chrome/browser/extensions/extension_ui_util.h" |
24 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 24 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
25 #include "chrome/browser/extensions/launch_util.h" | 25 #include "chrome/browser/extensions/launch_util.h" |
26 #include "chrome/browser/favicon/favicon_service_factory.h" | 26 #include "chrome/browser/favicon/favicon_service_factory.h" |
27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/ui/browser_dialogs.h" | 28 #include "chrome/browser/ui/browser_dialogs.h" |
29 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
30 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
31 #include "chrome/browser/ui/extensions/application_launch.h" | 31 #include "chrome/browser/ui/extensions/application_launch.h" |
32 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 32 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 33 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" |
33 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
34 #include "chrome/common/chrome_utility_messages.h" | 35 #include "chrome/common/chrome_utility_messages.h" |
35 #include "chrome/common/extensions/api/management.h" | 36 #include "chrome/common/extensions/api/management.h" |
36 #include "chrome/common/extensions/extension_constants.h" | 37 #include "chrome/common/extensions/extension_constants.h" |
37 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 38 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
38 #include "chrome/common/extensions/manifest_url_handler.h" | 39 #include "chrome/common/extensions/manifest_url_handler.h" |
39 #include "content/public/browser/utility_process_host.h" | 40 #include "content/public/browser/utility_process_host.h" |
40 #include "content/public/browser/utility_process_host_client.h" | 41 #include "content/public/browser/utility_process_host_client.h" |
41 #include "extensions/browser/event_router.h" | 42 #include "extensions/browser/event_router.h" |
42 #include "extensions/browser/extension_prefs.h" | 43 #include "extensions/browser/extension_prefs.h" |
43 #include "extensions/browser/extension_registry.h" | 44 #include "extensions/browser/extension_registry.h" |
44 #include "extensions/browser/extension_system.h" | 45 #include "extensions/browser/extension_system.h" |
45 #include "extensions/browser/management_policy.h" | 46 #include "extensions/browser/management_policy.h" |
46 #include "extensions/common/constants.h" | 47 #include "extensions/common/constants.h" |
47 #include "extensions/common/error_utils.h" | 48 #include "extensions/common/error_utils.h" |
48 #include "extensions/common/extension.h" | 49 #include "extensions/common/extension.h" |
49 #include "extensions/common/extension_icon_set.h" | 50 #include "extensions/common/extension_icon_set.h" |
50 #include "extensions/common/manifest_handlers/icons_handler.h" | 51 #include "extensions/common/manifest_handlers/icons_handler.h" |
51 #include "extensions/common/manifest_handlers/offline_enabled_info.h" | 52 #include "extensions/common/manifest_handlers/offline_enabled_info.h" |
52 #include "extensions/common/permissions/permission_set.h" | 53 #include "extensions/common/permissions/permission_set.h" |
53 #include "extensions/common/permissions/permissions_data.h" | 54 #include "extensions/common/permissions/permissions_data.h" |
54 #include "extensions/common/url_pattern.h" | 55 #include "extensions/common/url_pattern.h" |
55 #include "ui/gfx/favicon_size.h" | 56 #include "ui/gfx/favicon_size.h" |
56 | 57 |
57 #if !defined(OS_ANDROID) | |
58 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" | |
59 #endif | |
60 | |
61 using base::IntToString; | 58 using base::IntToString; |
62 using content::BrowserThread; | 59 using content::BrowserThread; |
63 using content::UtilityProcessHost; | 60 using content::UtilityProcessHost; |
64 using content::UtilityProcessHostClient; | 61 using content::UtilityProcessHostClient; |
65 | 62 |
66 namespace keys = extension_management_api_constants; | 63 namespace keys = extension_management_api_constants; |
67 | 64 |
68 namespace extensions { | 65 namespace extensions { |
69 | 66 |
70 namespace management = api::management; | 67 namespace management = api::management; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 const Extension& extension = *iter->get(); | 274 const Extension& extension = *iter->get(); |
278 | 275 |
279 if (ui_util::ShouldNotBeVisible(&extension, context)) | 276 if (ui_util::ShouldNotBeVisible(&extension, context)) |
280 continue; // Skip built-in extensions/apps. | 277 continue; // Skip built-in extensions/apps. |
281 | 278 |
282 extension_list->push_back(make_linked_ptr<management::ExtensionInfo>( | 279 extension_list->push_back(make_linked_ptr<management::ExtensionInfo>( |
283 CreateExtensionInfo(extension, system).release())); | 280 CreateExtensionInfo(extension, system).release())); |
284 } | 281 } |
285 } | 282 } |
286 | 283 |
287 } // namespace | 284 } // namespace |
288 | 285 |
289 ExtensionService* ManagementFunction::service() { | 286 ExtensionService* ManagementFunction::service() { |
290 return extensions::ExtensionSystem::Get(GetProfile())->extension_service(); | 287 return ExtensionSystem::Get(GetProfile())->extension_service(); |
291 } | 288 } |
292 | 289 |
293 ExtensionService* AsyncManagementFunction::service() { | 290 ExtensionService* AsyncManagementFunction::service() { |
294 return extensions::ExtensionSystem::Get(GetProfile())->extension_service(); | 291 return ExtensionSystem::Get(GetProfile())->extension_service(); |
295 } | 292 } |
296 | 293 |
297 bool ManagementGetAllFunction::RunSync() { | 294 bool ManagementGetAllFunction::RunSync() { |
298 ExtensionInfoList extensions; | 295 ExtensionInfoList extensions; |
299 ExtensionRegistry* registry = ExtensionRegistry::Get(GetProfile()); | 296 ExtensionRegistry* registry = ExtensionRegistry::Get(GetProfile()); |
300 ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); | 297 ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); |
301 | 298 |
302 AddExtensionInfo(registry->enabled_extensions(), | 299 AddExtensionInfo(registry->enabled_extensions(), |
303 system, &extensions, browser_context()); | 300 system, &extensions, browser_context()); |
304 AddExtensionInfo(registry->disabled_extensions(), | 301 AddExtensionInfo(registry->disabled_extensions(), |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 return false; | 494 return false; |
498 } | 495 } |
499 | 496 |
500 // Look at prefs to find the right launch container. | 497 // Look at prefs to find the right launch container. |
501 // If the user has not set a preference, the default launch value will be | 498 // If the user has not set a preference, the default launch value will be |
502 // returned. | 499 // returned. |
503 LaunchContainer launch_container = | 500 LaunchContainer launch_container = |
504 GetLaunchContainer(ExtensionPrefs::Get(GetProfile()), extension); | 501 GetLaunchContainer(ExtensionPrefs::Get(GetProfile()), extension); |
505 OpenApplication(AppLaunchParams( | 502 OpenApplication(AppLaunchParams( |
506 GetProfile(), extension, launch_container, NEW_FOREGROUND_TAB)); | 503 GetProfile(), extension, launch_container, NEW_FOREGROUND_TAB)); |
507 #if !defined(OS_ANDROID) | |
508 CoreAppLauncherHandler::RecordAppLaunchType( | 504 CoreAppLauncherHandler::RecordAppLaunchType( |
509 extension_misc::APP_LAUNCH_EXTENSION_API, | 505 extension_misc::APP_LAUNCH_EXTENSION_API, |
510 extension->GetType()); | 506 extension->GetType()); |
511 #endif | |
512 | 507 |
513 return true; | 508 return true; |
514 } | 509 } |
515 | 510 |
516 ManagementSetEnabledFunction::ManagementSetEnabledFunction() { | 511 ManagementSetEnabledFunction::ManagementSetEnabledFunction() { |
517 } | 512 } |
518 | 513 |
519 ManagementSetEnabledFunction::~ManagementSetEnabledFunction() { | 514 ManagementSetEnabledFunction::~ManagementSetEnabledFunction() { |
520 } | 515 } |
521 | 516 |
(...skipping 25 matching lines...) Expand all Loading... |
547 | 542 |
548 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); | 543 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); |
549 | 544 |
550 if (!currently_enabled && params->enabled) { | 545 if (!currently_enabled && params->enabled) { |
551 ExtensionPrefs* prefs = ExtensionPrefs::Get(GetProfile()); | 546 ExtensionPrefs* prefs = ExtensionPrefs::Get(GetProfile()); |
552 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { | 547 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { |
553 if (!user_gesture()) { | 548 if (!user_gesture()) { |
554 error_ = keys::kGestureNeededForEscalationError; | 549 error_ = keys::kGestureNeededForEscalationError; |
555 return false; | 550 return false; |
556 } | 551 } |
557 AddRef(); // Matched in InstallUIProceed/InstallUIAbort | 552 AddRef(); // Matched in InstallUIProceed/InstallUIAbort |
558 install_prompt_.reset( | 553 install_prompt_.reset( |
559 new ExtensionInstallPrompt(GetAssociatedWebContents())); | 554 new ExtensionInstallPrompt(GetAssociatedWebContents())); |
560 install_prompt_->ConfirmReEnable(this, extension); | 555 install_prompt_->ConfirmReEnable(this, extension); |
561 return true; | 556 return true; |
562 } | 557 } |
563 service()->EnableExtension(extension_id_); | 558 service()->EnableExtension(extension_id_); |
564 } else if (currently_enabled && !params->enabled) { | 559 } else if (currently_enabled && !params->enabled) { |
565 service()->DisableExtension(extension_id_, Extension::DISABLE_USER_ACTION); | 560 service()->DisableExtension(extension_id_, Extension::DISABLE_USER_ACTION); |
566 } | 561 } |
567 | 562 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 if (!ExtensionSystem::Get(GetProfile()) | 602 if (!ExtensionSystem::Get(GetProfile()) |
608 ->management_policy() | 603 ->management_policy() |
609 ->UserMayModifySettings(target_extension, NULL)) { | 604 ->UserMayModifySettings(target_extension, NULL)) { |
610 error_ = ErrorUtils::FormatErrorMessage( | 605 error_ = ErrorUtils::FormatErrorMessage( |
611 keys::kUserCantModifyError, extension_id_); | 606 keys::kUserCantModifyError, extension_id_); |
612 return false; | 607 return false; |
613 } | 608 } |
614 | 609 |
615 if (auto_confirm_for_test == DO_NOT_SKIP) { | 610 if (auto_confirm_for_test == DO_NOT_SKIP) { |
616 if (show_confirm_dialog) { | 611 if (show_confirm_dialog) { |
617 AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled | 612 AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled |
618 extension_uninstall_dialog_.reset(ExtensionUninstallDialog::Create( | 613 extension_uninstall_dialog_.reset(ExtensionUninstallDialog::Create( |
619 GetProfile(), GetCurrentBrowser(), this)); | 614 GetProfile(), GetCurrentBrowser(), this)); |
620 if (extension_id() != target_extension_id) { | 615 if (extension_id() != target_extension_id) { |
621 extension_uninstall_dialog_->ConfirmProgrammaticUninstall( | 616 extension_uninstall_dialog_->ConfirmProgrammaticUninstall( |
622 target_extension, GetExtension()); | 617 target_extension, GetExtension()); |
623 } else { | 618 } else { |
624 // If this is a self uninstall, show the generic uninstall dialog. | 619 // If this is a self uninstall, show the generic uninstall dialog. |
625 extension_uninstall_dialog_->ConfirmUninstall(target_extension); | 620 extension_uninstall_dialog_->ConfirmUninstall(target_extension); |
626 } | 621 } |
627 } else { | 622 } else { |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 ManagementAPI::GetFactoryInstance() { | 1000 ManagementAPI::GetFactoryInstance() { |
1006 return g_factory.Pointer(); | 1001 return g_factory.Pointer(); |
1007 } | 1002 } |
1008 | 1003 |
1009 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) { | 1004 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) { |
1010 management_event_router_.reset(new ManagementEventRouter(browser_context_)); | 1005 management_event_router_.reset(new ManagementEventRouter(browser_context_)); |
1011 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 1006 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
1012 } | 1007 } |
1013 | 1008 |
1014 } // namespace extensions | 1009 } // namespace extensions |
OLD | NEW |