#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"
extension_id_(extension_id),
delegate_(delegate),
parent_contents_(NULL),
- parent_window_(NULL) {
+ parent_window_(NULL),
+ extension_registry_observer_(this) {
}
ExtensionEnableFlow::~ExtensionEnableFlow() {
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);
}
}
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);
-}