| 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 0b06ff95ede0f79cacfbc1e2a88dd856bfbb71bf..465614e528b6d7f32453b0c1bd0f304a55be41c0 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"
|
| @@ -55,56 +56,38 @@ 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));
|
| - }
|
| + explicit ExtensionInstalledBubbleBridge(
|
| + 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_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubbleBridge);
|
| };
|
|
|
| +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_;
|
| @@ -119,7 +102,6 @@ class ExtensionLoadedNotificationObserver
|
| if ((self = [super initWithWindowNibPath:nibName
|
| parentWindow:parentWindow
|
| anchoredAt:NSZeroPoint])) {
|
| - extension_ = extension;
|
| bundle_ = bundle;
|
| DCHECK(browser);
|
| browser_ = browser;
|
| @@ -145,13 +127,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.
|
| @@ -169,15 +160,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];
|
| @@ -209,11 +199,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;
|
| @@ -253,14 +243,14 @@ class ExtensionLoadedNotificationObserver
|
| BrowserActionsController* controller =
|
| [[window->cocoa_controller() toolbarController]
|
| browserActionsController];
|
| - arrowPoint = [controller popupPointForId:extension_->id()];
|
| + arrowPoint = [controller popupPointForId:[self extension]->id()];
|
| } else if (type_ == extension_installed_bubble::kPageAction) {
|
| LocationBarViewMac* locationBarView =
|
| [window->cocoa_controller() locationBarBridge];
|
|
|
| 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
|
| @@ -342,9 +332,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)) {
|
| @@ -359,9 +349,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)) {
|
| @@ -456,7 +446,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)];
|
| @@ -483,7 +474,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]]];
|
| @@ -606,9 +598,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];
|
| @@ -669,10 +661,6 @@ class ExtensionLoadedNotificationObserver
|
| return appShortcutLink_;
|
| }
|
|
|
| -- (void)extensionUnloaded:(id)sender {
|
| - extension_ = NULL;
|
| -}
|
| -
|
| - (IBAction)onManageShortcutClicked:(id)sender {
|
| [self close];
|
| std::string configure_url = chrome::kChromeUIExtensionsURL;
|
| @@ -685,7 +673,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 {
|
|
|