Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / management / management_api.cc
index 489a25e..7fe4b64 100644 (file)
@@ -23,6 +23,7 @@
 #include "chrome/browser/extensions/extension_ui_util.h"
 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
 #include "chrome/browser/extensions/launch_util.h"
+#include "chrome/browser/extensions/window_controller.h"
 #include "chrome/browser/favicon/favicon_service_factory.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/ui/browser_dialogs.h"
 #include "chrome/browser/ui/browser_window.h"
 #include "chrome/browser/ui/extensions/application_launch.h"
 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
+#include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
 #include "chrome/common/chrome_switches.h"
-#include "chrome/common/chrome_utility_messages.h"
 #include "chrome/common/extensions/api/management.h"
+#include "chrome/common/extensions/chrome_utility_extensions_messages.h"
 #include "chrome/common/extensions/extension_constants.h"
 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
 #include "chrome/common/extensions/manifest_url_handler.h"
@@ -43,6 +45,7 @@
 #include "extensions/browser/extension_registry.h"
 #include "extensions/browser/extension_system.h"
 #include "extensions/browser/management_policy.h"
+#include "extensions/browser/uninstall_reason.h"
 #include "extensions/common/constants.h"
 #include "extensions/common/error_utils.h"
 #include "extensions/common/extension.h"
 #include "extensions/common/permissions/permission_set.h"
 #include "extensions/common/permissions/permissions_data.h"
 #include "extensions/common/url_pattern.h"
-#include "ui/gfx/favicon_size.h"
-
-#if !defined(OS_ANDROID)
-#include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
-#endif
 
 using base::IntToString;
 using content::BrowserThread;
@@ -284,14 +282,14 @@ void AddExtensionInfo(const ExtensionSet& extensions,
   }
 }
 
-} // namespace
+}  // namespace
 
 ExtensionService* ManagementFunction::service() {
-  return GetProfile()->GetExtensionService();
+  return ExtensionSystem::Get(GetProfile())->extension_service();
 }
 
 ExtensionService* AsyncManagementFunction::service() {
-  return GetProfile()->GetExtensionService();
+  return ExtensionSystem::Get(GetProfile())->extension_service();
 }
 
 bool ManagementGetAllFunction::RunSync() {
@@ -504,11 +502,9 @@ bool ManagementLaunchAppFunction::RunSync() {
       GetLaunchContainer(ExtensionPrefs::Get(GetProfile()), extension);
   OpenApplication(AppLaunchParams(
       GetProfile(), extension, launch_container, NEW_FOREGROUND_TAB));
-#if !defined(OS_ANDROID)
   CoreAppLauncherHandler::RecordAppLaunchType(
       extension_misc::APP_LAUNCH_EXTENSION_API,
       extension->GetType());
-#endif
 
   return true;
 }
@@ -554,7 +550,7 @@ bool ManagementSetEnabledFunction::RunAsync() {
         error_ = keys::kGestureNeededForEscalationError;
         return false;
       }
-      AddRef(); // Matched in InstallUIProceed/InstallUIAbort
+      AddRef();  // Matched in InstallUIProceed/InstallUIAbort
       install_prompt_.reset(
           new ExtensionInstallPrompt(GetAssociatedWebContents()));
       install_prompt_->ConfirmReEnable(this, extension);
@@ -614,12 +610,15 @@ bool ManagementUninstallFunctionBase::Uninstall(
 
   if (auto_confirm_for_test == DO_NOT_SKIP) {
     if (show_confirm_dialog) {
-      AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled
+      AddRef();  // Balanced in ExtensionUninstallAccepted/Canceled
+      extensions::WindowController* controller = GetExtensionWindowController();
       extension_uninstall_dialog_.reset(ExtensionUninstallDialog::Create(
-          GetProfile(), GetCurrentBrowser(), this));
+          GetProfile(),
+          controller ? controller->window()->GetNativeWindow() : NULL,
+          this));
       if (extension_id() != target_extension_id) {
         extension_uninstall_dialog_->ConfirmProgrammaticUninstall(
-            target_extension, GetExtension());
+            target_extension, extension());
       } else {
         // If this is a self uninstall, show the generic uninstall dialog.
         extension_uninstall_dialog_->ConfirmUninstall(target_extension);
@@ -652,10 +651,11 @@ void ManagementUninstallFunctionBase::Finish(bool should_uninstall) {
                                               extension_id_);
       SendResponse(false);
     } else {
-      bool success =
-          service()->UninstallExtension(extension_id_,
-                                        false, /* external uninstall */
-                                        NULL);
+      bool success = service()->UninstallExtension(
+          extension_id_,
+          extensions::UNINSTALL_REASON_MANAGEMENT_API,
+          base::Bind(&base::DoNothing),
+          NULL);
 
       // TODO set error_ if !success
       SendResponse(success);
@@ -665,7 +665,6 @@ void ManagementUninstallFunctionBase::Finish(bool should_uninstall) {
         keys::kUninstallCanceledError, extension_id_);
     SendResponse(false);
   }
-
 }
 
 void ManagementUninstallFunctionBase::ExtensionUninstallAccepted() {
@@ -921,8 +920,7 @@ bool ManagementGenerateAppForLinkFunction::RunAsync() {
   launch_url_ = launch_url;
 
   favicon_service->GetFaviconImageForPageURL(
-      FaviconService::FaviconForPageURLParams(
-          launch_url, favicon_base::FAVICON, gfx::kFaviconSize),
+      launch_url,
       base::Bind(&ManagementGenerateAppForLinkFunction::OnFaviconForApp, this),
       &cancelable_task_tracker_);
 
@@ -955,13 +953,15 @@ void ManagementEventRouter::OnExtensionUnloaded(
 
 void ManagementEventRouter::OnExtensionInstalled(
     content::BrowserContext* browser_context,
-    const Extension* extension) {
+    const Extension* extension,
+    bool is_update) {
   BroadcastEvent(extension, management::OnInstalled::kEventName);
 }
 
 void ManagementEventRouter::OnExtensionUninstalled(
     content::BrowserContext* browser_context,
-    const Extension* extension) {
+    const Extension* extension,
+    extensions::UninstallReason reason) {
   BroadcastEvent(extension, management::OnUninstalled::kEventName);
 }