Chromium Code Reviews| Index: chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.mm b/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.mm |
| index aeb3fac0cc02b6c819b345a72b8e8f2160b4e9a5..9ffef41d34fe6ff787821734425e87004cdb3692 100644 |
| --- a/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.mm |
| +++ b/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.mm |
| @@ -30,6 +30,7 @@ |
| #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| #include "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" |
| +#include "chrome/browser/ui/extensions/extension_installed_bubble.h" |
| #include "chrome/browser/ui/singleton_tabs.h" |
| #include "chrome/browser/ui/sync/sync_promo_ui.h" |
| #include "chrome/common/extensions/api/commands/commands_handler.h" |
| @@ -54,56 +55,36 @@ using extensions::BundleInstaller; |
| using extensions::Extension; |
| using extensions::UnloadedExtensionInfo; |
| -// C++ class that receives EXTENSION_LOADED notifications and proxies them back |
| -// to |controller|. |
| -class ExtensionLoadedNotificationObserver |
| - : public content::NotificationObserver { |
| +class ExtensionInstalledBubbleBridge |
| + : public ExtensionInstalledBubble::Delegate { |
| public: |
| - ExtensionLoadedNotificationObserver( |
| - ExtensionInstalledBubbleController* controller, Profile* profile) |
| - : controller_(controller) { |
| - registrar_.Add(this, |
| - extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| - content::Source<Profile>(profile)); |
| - registrar_.Add(this, |
| - extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
| - content::Source<Profile>(profile)); |
| - } |
| + ExtensionInstalledBubbleBridge( |
|
Robert Sesek
2015/02/12 23:47:35
explicit
Devlin
2015/02/13 01:11:50
I forget how dependent I am on presubmit checks so
|
| + ExtensionInstalledBubbleController* controller); |
| + ~ExtensionInstalledBubbleBridge() override; |
| private: |
| - // NotificationObserver implementation. Tells the controller to start showing |
| - // its window on the main thread when the extension has finished loading. |
| - void Observe(int type, |
| - const content::NotificationSource& source, |
| - const content::NotificationDetails& details) override { |
| - if (type == extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED) { |
| - const Extension* extension = |
| - content::Details<const Extension>(details).ptr(); |
| - if (extension == [controller_ extension]) { |
| - [controller_ performSelectorOnMainThread:@selector(showWindow:) |
| - withObject:controller_ |
| - waitUntilDone:NO]; |
| - } |
| - } else if (type == extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { |
| - const Extension* extension = |
| - content::Details<const UnloadedExtensionInfo>(details)->extension; |
| - if (extension == [controller_ extension]) { |
| - [controller_ performSelectorOnMainThread:@selector(extensionUnloaded:) |
| - withObject:controller_ |
| - waitUntilDone:NO]; |
| - } |
| - } else { |
| - NOTREACHED() << "Received unexpected notification."; |
| - } |
| - } |
| + // ExtensionInstalledBubble::Delegate: |
| + bool MaybeShowNow() override; |
| - content::NotificationRegistrar registrar_; |
| - ExtensionInstalledBubbleController* controller_; // weak, owns us |
| + // The (owning) installed bubble controller. |
| + ExtensionInstalledBubbleController* controller_; |
| }; |
|
Robert Sesek
2015/02/12 23:47:35
DISALLOW_COPY_AND_ASSIGN
Devlin
2015/02/13 01:11:50
Done.
|
| +ExtensionInstalledBubbleBridge::ExtensionInstalledBubbleBridge( |
| + ExtensionInstalledBubbleController* controller) |
| + : controller_(controller) { |
| +} |
| + |
| +ExtensionInstalledBubbleBridge::~ExtensionInstalledBubbleBridge() { |
| +} |
| + |
| +bool ExtensionInstalledBubbleBridge::MaybeShowNow() { |
| + [controller_ showWindow:controller_]; |
| + return true; |
| +} |
| + |
| @implementation ExtensionInstalledBubbleController |
| -@synthesize extension = extension_; |
| @synthesize bundle = bundle_; |
| // Exposed for unit test. |
| @synthesize pageActionPreviewShowing = pageActionPreviewShowing_; |
| @@ -118,7 +99,6 @@ class ExtensionLoadedNotificationObserver |
| if ((self = [super initWithWindowNibPath:nibName |
| parentWindow:parentWindow |
| anchoredAt:NSZeroPoint])) { |
| - extension_ = extension; |
| bundle_ = bundle; |
| DCHECK(browser); |
| browser_ = browser; |
| @@ -144,13 +124,22 @@ class ExtensionLoadedNotificationObserver |
| [self showWindow:self]; |
| } else { |
| // Start showing window only after extension has fully loaded. |
| - extensionObserver_.reset(new ExtensionLoadedNotificationObserver( |
| - self, browser->profile())); |
| + installedBubbleBridge_.reset(new ExtensionInstalledBubbleBridge(self)); |
| + installedBubble_.reset(new ExtensionInstalledBubble( |
| + installedBubbleBridge_.get(), |
| + extension, |
| + browser, |
| + icon)); |
| + installedBubble_->IgnoreBrowserClosing(); |
| } |
| } |
| return self; |
| } |
| +- (const Extension*)extension { |
| + return installedBubble_->extension(); |
| +} |
| + |
| // Sets |promo_| based on |promoPlaceholder_|, sets |promoPlaceholder_| to nil. |
| - (void)initializeLabel { |
| // Replace the promo placeholder NSTextField with the real label NSTextView. |
| @@ -168,15 +157,14 @@ class ExtensionLoadedNotificationObserver |
| // Returns YES if the sync promo should be shown in the bubble. |
| - (BOOL)showSyncPromo { |
| - return extensions::sync_helper::IsSyncableExtension(extension_) && |
| - SyncPromoUI::ShouldShowSyncPromo(browser_->profile()); |
| + return extensions::sync_helper::IsSyncableExtension([self extension]) && |
| + SyncPromoUI::ShouldShowSyncPromo(browser_->profile()); |
| } |
| - (void)windowWillClose:(NSNotification*)notification { |
| // Turn off page action icon preview when the window closes, unless we |
| // already removed it when the window resigned key status. |
| [self removePageActionPreviewIfNecessary]; |
| - extension_ = NULL; |
| browser_ = NULL; |
| [closeButton_ setTrackingEnabled:NO]; |
| [super windowWillClose:notification]; |
| @@ -208,11 +196,11 @@ class ExtensionLoadedNotificationObserver |
| // Extracted to a function here so that it can be overridden for unit testing. |
| - (void)removePageActionPreviewIfNecessary { |
| - if (!extension_ || !pageActionPreviewShowing_) |
| + if (![self extension] || !pageActionPreviewShowing_) |
| return; |
| ExtensionAction* page_action = |
| extensions::ExtensionActionManager::Get(browser_->profile())-> |
| - GetPageAction(*extension_); |
| + GetPageAction(*[self extension]); |
| if (!page_action) |
| return; |
| pageActionPreviewShowing_ = NO; |
| @@ -257,7 +245,7 @@ class ExtensionLoadedNotificationObserver |
| BrowserActionsController* controller = |
| [[window->cocoa_controller() toolbarController] |
| browserActionsController]; |
| - arrowPoint = [controller popupPointForId:extension_->id()]; |
| + arrowPoint = [controller popupPointForId:[self extension]->id()]; |
| break; |
| } |
| case extension_installed_bubble::kPageAction: { |
| @@ -266,7 +254,7 @@ class ExtensionLoadedNotificationObserver |
| ExtensionAction* page_action = |
| extensions::ExtensionActionManager::Get(browser_->profile())-> |
| - GetPageAction(*extension_); |
| + GetPageAction(*[self extension]); |
| // Tell the location bar to show a preview of the page action icon, which |
| // would ordinarily only be displayed on a page of the appropriate type. |
| @@ -350,9 +338,9 @@ class ExtensionLoadedNotificationObserver |
| extensions::CommandService* command_service = |
| extensions::CommandService::Get(browser_->profile()); |
| if (type_ == extension_installed_bubble::kPageAction) { |
| - if (extensions::CommandsInfo::GetPageActionCommand(extension_) && |
| + if (extensions::CommandsInfo::GetPageActionCommand([self extension]) && |
| command_service->GetPageActionCommand( |
| - extension_->id(), |
| + [self extension]->id(), |
| extensions::CommandService::ACTIVE, |
| command, |
| NULL)) { |
| @@ -367,9 +355,9 @@ class ExtensionLoadedNotificationObserver |
| extensions::CommandService* command_service = |
| extensions::CommandService::Get(browser_->profile()); |
| if (type_ == extension_installed_bubble::kBrowserAction) { |
| - if (extensions::CommandsInfo::GetBrowserActionCommand(extension_) && |
| + if (extensions::CommandsInfo::GetBrowserActionCommand([self extension]) && |
| command_service->GetBrowserActionCommand( |
| - extension_->id(), |
| + [self extension]->id(), |
| extensions::CommandService::ACTIVE, |
| command, |
| NULL)) { |
| @@ -464,7 +452,8 @@ class ExtensionLoadedNotificationObserver |
| } |
| // First part of extension installed message, the heading. |
| - base::string16 extension_name = base::UTF8ToUTF16(extension_->name().c_str()); |
| + base::string16 extension_name = |
| + base::UTF8ToUTF16([self extension]->name().c_str()); |
| base::i18n::AdjustStringForLocaleDirection(&extension_name); |
| [heading_ setStringValue:l10n_util::GetNSStringF( |
| IDS_EXTENSION_INSTALLED_HEADING, extension_name)]; |
| @@ -491,7 +480,8 @@ class ExtensionLoadedNotificationObserver |
| if (type_ == extension_installed_bubble::kOmniboxKeyword) { |
| [howToUse_ setStringValue:l10n_util::GetNSStringF( |
| IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO, |
| - base::UTF8ToUTF16(extensions::OmniboxInfo::GetKeyword(extension_)))]; |
| + base::UTF8ToUTF16(extensions::OmniboxInfo::GetKeyword( |
| + [self extension])))]; |
| [howToUse_ setHidden:NO]; |
| [[howToUse_ cell] |
| setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| @@ -614,9 +604,9 @@ class ExtensionLoadedNotificationObserver |
| [heading_ setFrame:headingFrame]; |
| NSRect howToManageFrame = [howToManage_ frame]; |
| - if (!extensions::OmniboxInfo::GetKeyword(extension_).empty() || |
| - extensions::ActionInfo::GetBrowserActionInfo(extension_) || |
| - extensions::ActionInfo::IsVerboseInstallMessage(extension_)) { |
| + if (!extensions::OmniboxInfo::GetKeyword([self extension]).empty() || |
| + extensions::ActionInfo::GetBrowserActionInfo([self extension]) || |
| + extensions::ActionInfo::IsVerboseInstallMessage([self extension])) { |
| // For browser actions, page actions and omnibox keyword show the |
| // 'how to use' message before the 'how to manage' message. |
| NSRect howToUseFrame = [howToUse_ frame]; |
| @@ -677,10 +667,6 @@ class ExtensionLoadedNotificationObserver |
| return appShortcutLink_; |
| } |
| -- (void)extensionUnloaded:(id)sender { |
| - extension_ = NULL; |
| -} |
| - |
| - (IBAction)onManageShortcutClicked:(id)sender { |
| [self close]; |
| std::string configure_url = chrome::kChromeUIExtensionsURL; |
| @@ -693,7 +679,7 @@ class ExtensionLoadedNotificationObserver |
| - (IBAction)onAppShortcutClicked:(id)sender { |
| scoped_ptr<extensions::ExtensionInstallUI> install_ui( |
| extensions::CreateExtensionInstallUI(browser_->profile())); |
| - install_ui->OpenAppInstalledUI(extension_->id()); |
| + install_ui->OpenAppInstalledUI([self extension]->id()); |
| } |
| - (void)awakeFromNib { |