Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / extensions / extension_enable_flow.cc
index b89155f..8e305e7 100644 (file)
@@ -7,11 +7,10 @@
 #include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/extensions/extension_service.h"
 #include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/browser.h"
 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
-#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
 #include "content/public/browser/notification_details.h"
 #include "content/public/browser/notification_source.h"
+#include "extensions/browser/extension_prefs.h"
 #include "extensions/browser/extension_registry.h"
 #include "extensions/browser/extension_system.h"
 
@@ -24,7 +23,8 @@ ExtensionEnableFlow::ExtensionEnableFlow(Profile* profile,
       extension_id_(extension_id),
       delegate_(delegate),
       parent_contents_(NULL),
-      parent_window_(NULL) {
+      parent_window_(NULL),
+      extension_registry_observer_(this) {
 }
 
 ExtensionEnableFlow::~ExtensionEnableFlow() {
@@ -106,53 +106,46 @@ void ExtensionEnableFlow::CreatePrompt() {
     parent_window_ = window_getter_.Run();
   prompt_.reset(parent_contents_ ?
       new ExtensionInstallPrompt(parent_contents_) :
-      new ExtensionInstallPrompt(profile_, parent_window_, this));
+      new ExtensionInstallPrompt(profile_, parent_window_));
 }
 
 void ExtensionEnableFlow::StartObserving() {
-  registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
-                 content::Source<Profile>(profile_));
-  registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
-                 content::Source<Profile>(profile_));
-  registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
+  extension_registry_observer_.Add(
+      extensions::ExtensionRegistry::Get(profile_));
+  registrar_.Add(this,
+                 extensions::NOTIFICATION_EXTENSION_LOAD_ERROR,
                  content::Source<Profile>(profile_));
 }
 
 void ExtensionEnableFlow::StopObserving() {
   registrar_.RemoveAll();
+  extension_registry_observer_.RemoveAll();
 }
 
 void ExtensionEnableFlow::Observe(int type,
                                   const content::NotificationSource& source,
                                   const content::NotificationDetails& details) {
-  switch (type) {
-    case chrome::NOTIFICATION_EXTENSION_LOADED: {
-      const Extension* extension =
-          content::Details<const Extension>(details).ptr();
-      if (extension->id() == extension_id_) {
-        StopObserving();
-        CheckPermissionAndMaybePromptUser();
-      }
-
-      break;
-    }
-    case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: {
-      StopObserving();
-      delegate_->ExtensionEnableFlowAborted(false);
-      break;
-    }
-    case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
-      const Extension* extension =
-          content::Details<const Extension>(details).ptr();
-      if (extension->id() == extension_id_) {
-        StopObserving();
-        delegate_->ExtensionEnableFlowAborted(false);
-      }
-
-      break;
-    }
-    default:
-      NOTREACHED();
+  DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_LOAD_ERROR, type);
+  StopObserving();
+  delegate_->ExtensionEnableFlowAborted(false);
+}
+
+void ExtensionEnableFlow::OnExtensionLoaded(
+    content::BrowserContext* browser_context,
+    const Extension* extension) {
+  if (extension->id() == extension_id_) {
+    StopObserving();
+    CheckPermissionAndMaybePromptUser();
+  }
+}
+
+void ExtensionEnableFlow::OnExtensionUninstalled(
+    content::BrowserContext* browser_context,
+    const Extension* extension,
+    extensions::UninstallReason reason) {
+  if (extension->id() == extension_id_) {
+    StopObserving();
+    delegate_->ExtensionEnableFlowAborted(false);
   }
 }
 
@@ -176,10 +169,3 @@ void ExtensionEnableFlow::InstallUIAbort(bool user_initiated) {
   delegate_->ExtensionEnableFlowAborted(user_initiated);
   // |delegate_| may delete us.
 }
-
-content::WebContents* ExtensionEnableFlow::OpenURL(
-    const content::OpenURLParams& params) {
-  chrome::ScopedTabbedBrowserDisplayer displayer(
-      profile_, chrome::GetActiveDesktop());
-  return displayer.browser()->OpenURL(params);
-}