1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.h"
7 #include "base/i18n/rtl.h"
8 #include "base/mac/bundle_locations.h"
9 #include "base/mac/mac_util.h"
10 #include "base/strings/sys_string_conversions.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/extensions/api/commands/command_service.h"
14 #include "chrome/browser/extensions/bundle_installer.h"
15 #include "chrome/browser/extensions/extension_action.h"
16 #include "chrome/browser/extensions/extension_action_manager.h"
17 #include "chrome/browser/extensions/extension_install_ui.h"
18 #include "chrome/browser/signin/signin_promo.h"
19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_navigator.h"
21 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/browser/ui/chrome_style.h"
23 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
24 #include "chrome/browser/ui/cocoa/browser_window_controller.h"
25 #include "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
26 #include "chrome/browser/ui/cocoa/hover_close_button.h"
27 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h"
28 #include "chrome/browser/ui/cocoa/info_bubble_view.h"
29 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
30 #include "chrome/browser/ui/cocoa/new_tab_button.h"
31 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
32 #include "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
33 #include "chrome/browser/ui/singleton_tabs.h"
34 #include "chrome/browser/ui/sync/sync_promo_ui.h"
35 #include "chrome/common/extensions/api/commands/commands_handler.h"
36 #include "chrome/common/extensions/api/extension_action/action_info.h"
37 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h"
38 #include "chrome/common/extensions/sync_helper.h"
39 #include "chrome/common/url_constants.h"
40 #include "content/public/browser/notification_details.h"
41 #include "content/public/browser/notification_registrar.h"
42 #include "content/public/browser/notification_source.h"
43 #include "extensions/common/extension.h"
44 #include "grit/chromium_strings.h"
45 #include "grit/generated_resources.h"
46 #import "skia/ext/skia_utils_mac.h"
47 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
48 #include "ui/base/l10n/l10n_util.h"
50 using content::BrowserThread;
51 using extensions::BundleInstaller;
52 using extensions::Extension;
53 using extensions::UnloadedExtensionInfo;
55 // C++ class that receives EXTENSION_LOADED notifications and proxies them back
57 class ExtensionLoadedNotificationObserver
58 : public content::NotificationObserver {
60 ExtensionLoadedNotificationObserver(
61 ExtensionInstalledBubbleController* controller, Profile* profile)
62 : controller_(controller) {
63 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
64 content::Source<Profile>(profile));
65 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
66 content::Source<Profile>(profile));
70 // NotificationObserver implementation. Tells the controller to start showing
71 // its window on the main thread when the extension has finished loading.
74 const content::NotificationSource& source,
75 const content::NotificationDetails& details) OVERRIDE {
76 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) {
77 const Extension* extension =
78 content::Details<const Extension>(details).ptr();
79 if (extension == [controller_ extension]) {
80 [controller_ performSelectorOnMainThread:@selector(showWindow:)
81 withObject:controller_
84 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
85 const Extension* extension =
86 content::Details<const UnloadedExtensionInfo>(details)->extension;
87 if (extension == [controller_ extension]) {
88 [controller_ performSelectorOnMainThread:@selector(extensionUnloaded:)
89 withObject:controller_
93 NOTREACHED() << "Received unexpected notification.";
97 content::NotificationRegistrar registrar_;
98 ExtensionInstalledBubbleController* controller_; // weak, owns us
101 @implementation ExtensionInstalledBubbleController
103 @synthesize extension = extension_;
104 @synthesize bundle = bundle_;
105 // Exposed for unit test.
106 @synthesize pageActionPreviewShowing = pageActionPreviewShowing_;
108 - (id)initWithParentWindow:(NSWindow*)parentWindow
109 extension:(const Extension*)extension
110 bundle:(const BundleInstaller*)bundle
111 browser:(Browser*)browser
112 icon:(SkBitmap)icon {
113 NSString* nibName = bundle ? @"ExtensionInstalledBubbleBundle" :
114 @"ExtensionInstalledBubble";
115 if ((self = [super initWithWindowNibPath:nibName
116 parentWindow:parentWindow
117 anchoredAt:NSZeroPoint])) {
118 extension_ = extension;
122 icon_.reset([gfx::SkBitmapToNSImage(icon) retain]);
123 pageActionPreviewShowing_ = NO;
126 type_ = extension_installed_bubble::kBundle;
127 } else if (extension->is_app()) {
128 type_ = extension_installed_bubble::kApp;
129 } else if (!extensions::OmniboxInfo::GetKeyword(extension).empty()) {
130 type_ = extension_installed_bubble::kOmniboxKeyword;
131 } else if (extensions::ActionInfo::GetBrowserActionInfo(extension)) {
132 type_ = extension_installed_bubble::kBrowserAction;
133 } else if (extensions::ActionInfo::GetPageActionInfo(extension) &&
134 extensions::ActionInfo::IsVerboseInstallMessage(extension)) {
135 type_ = extension_installed_bubble::kPageAction;
137 type_ = extension_installed_bubble::kGeneric;
140 if (type_ == extension_installed_bubble::kBundle) {
141 [self showWindow:self];
143 // Start showing window only after extension has fully loaded.
144 extensionObserver_.reset(new ExtensionLoadedNotificationObserver(
145 self, browser->profile()));
151 // Sets |promo_| based on |promoPlaceholder_|, sets |promoPlaceholder_| to nil.
152 - (void)initializeLabel {
153 // Replace the promo placeholder NSTextField with the real label NSTextView.
154 // The former doesn't show links in a nice way, but the latter can't be added
155 // in IB without a containing scroll view, so create the NSTextView
157 promo_.reset([[HyperlinkTextView alloc]
158 initWithFrame:[promoPlaceholder_ frame]]);
159 [promo_.get() setAutoresizingMask:[promoPlaceholder_ autoresizingMask]];
160 [[promoPlaceholder_ superview]
161 replaceSubview:promoPlaceholder_ with:promo_.get()];
162 promoPlaceholder_ = nil; // Now released.
163 [promo_.get() setDelegate:self];
166 // Returns YES if the sync promo should be shown in the bubble.
167 - (BOOL)showSyncPromo {
168 return extensions::sync_helper::IsSyncableExtension(extension_) &&
169 SyncPromoUI::ShouldShowSyncPromo(browser_->profile());
172 - (void)windowWillClose:(NSNotification*)notification {
173 // Turn off page action icon preview when the window closes, unless we
174 // already removed it when the window resigned key status.
175 [self removePageActionPreviewIfNecessary];
179 [super windowWillClose:notification];
182 // The controller is the delegate of the window, so it receives "did resign
183 // key" notifications. When key is resigned, close the window.
184 - (void)windowDidResignKey:(NSNotification*)notification {
185 // If the browser window is closing, we need to remove the page action
186 // immediately, otherwise the closing animation may overlap with
187 // browser destruction.
188 [self removePageActionPreviewIfNecessary];
189 [super windowDidResignKey:notification];
192 - (IBAction)closeWindow:(id)sender {
193 DCHECK([[self window] isVisible]);
197 - (BOOL)textView:(NSTextView*)aTextView
198 clickedOnLink:(id)link
199 atIndex:(NSUInteger)charIndex {
200 DCHECK_EQ(promo_.get(), aTextView);
202 signin::GetPromoURL(signin::SOURCE_EXTENSION_INSTALL_BUBBLE, false);
203 chrome::NavigateParams params(
204 chrome::GetSingletonTabNavigateParams(browser_, promo_url));
205 chrome::Navigate(¶ms);
209 // Extracted to a function here so that it can be overridden for unit testing.
210 - (void)removePageActionPreviewIfNecessary {
211 if (!extension_ || !pageActionPreviewShowing_)
213 ExtensionAction* page_action =
214 extensions::ExtensionActionManager::Get(browser_->profile())->
215 GetPageAction(*extension_);
218 pageActionPreviewShowing_ = NO;
220 BrowserWindowCocoa* window =
221 static_cast<BrowserWindowCocoa*>(browser_->window());
222 LocationBarViewMac* locationBarView =
223 [window->cocoa_controller() locationBarBridge];
224 locationBarView->SetPreviewEnabledPageAction(page_action,
225 false); // disables preview.
228 // The extension installed bubble points at the browser action icon or the
229 // page action icon (shown as a preview), depending on the extension type.
230 // We need to calculate the location of these icons and the size of the
231 // message itself (which varies with the title of the extension) in order
232 // to figure out the origin point for the extension installed bubble.
233 // TODO(mirandac): add framework to easily test extension UI components!
234 - (NSPoint)calculateArrowPoint {
235 BrowserWindowCocoa* window =
236 static_cast<BrowserWindowCocoa*>(browser_->window());
237 NSPoint arrowPoint = NSZeroPoint;
240 case extension_installed_bubble::kApp: {
241 TabStripView* view = [window->cocoa_controller() tabStripView];
242 NewTabButton* button = [view getNewTabButton];
243 NSRect bounds = [button bounds];
244 NSPoint anchor = NSMakePoint(
246 NSMaxY(bounds) - extension_installed_bubble::kAppsBubbleArrowOffset);
247 arrowPoint = [button convertPoint:anchor toView:nil];
250 case extension_installed_bubble::kOmniboxKeyword: {
251 LocationBarViewMac* locationBarView =
252 [window->cocoa_controller() locationBarBridge];
253 arrowPoint = locationBarView->GetPageInfoBubblePoint();
256 case extension_installed_bubble::kBrowserAction: {
257 BrowserActionsController* controller =
258 [[window->cocoa_controller() toolbarController]
259 browserActionsController];
260 arrowPoint = [controller popupPointForBrowserAction:extension_];
263 case extension_installed_bubble::kPageAction: {
264 LocationBarViewMac* locationBarView =
265 [window->cocoa_controller() locationBarBridge];
267 ExtensionAction* page_action =
268 extensions::ExtensionActionManager::Get(browser_->profile())->
269 GetPageAction(*extension_);
271 // Tell the location bar to show a preview of the page action icon, which
272 // would ordinarily only be displayed on a page of the appropriate type.
273 // We remove this preview when the extension installed bubble closes.
274 locationBarView->SetPreviewEnabledPageAction(page_action, true);
275 pageActionPreviewShowing_ = YES;
277 // Find the center of the bottom of the page action icon.
279 locationBarView->GetPageActionBubblePoint(page_action);
282 case extension_installed_bubble::kBundle:
283 case extension_installed_bubble::kGeneric: {
284 // Point at the bottom of the wrench menu.
285 NSView* wrenchButton =
286 [[window->cocoa_controller() toolbarController] wrenchButton];
287 const NSRect bounds = [wrenchButton bounds];
288 NSPoint anchor = NSMakePoint(NSMidX(bounds), NSMaxY(bounds));
289 arrowPoint = [wrenchButton convertPoint:anchor toView:nil];
299 // Override -[BaseBubbleController showWindow:] to tweak bubble location and
300 // set up UI elements.
301 - (void)showWindow:(id)sender {
302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
304 // Load nib and calculate height based on messages to be shown.
305 NSWindow* window = [self initializeWindow];
306 int newWindowHeight = [self calculateWindowHeight];
307 [self.bubble setFrameSize:NSMakeSize(
308 NSWidth([[window contentView] bounds]), newWindowHeight)];
309 NSSize windowDelta = NSMakeSize(
310 0, newWindowHeight - NSHeight([[window contentView] bounds]));
311 windowDelta = [[window contentView] convertSize:windowDelta toView:nil];
312 NSRect newFrame = [window frame];
313 newFrame.size.height += windowDelta.height;
314 [window setFrame:newFrame display:NO];
316 // Now that we have resized the window, adjust y pos of the messages.
317 [self setMessageFrames:newWindowHeight];
319 // Find window origin, taking into account bubble size and arrow location.
321 [self.parentWindow convertBaseToScreen:[self calculateArrowPoint]];
322 [super showWindow:sender];
325 // Finish nib loading, set arrow location and load icon into window. This
326 // function is exposed for unit testing.
327 - (NSWindow*)initializeWindow {
328 NSWindow* window = [self window]; // completes nib load
330 if (type_ == extension_installed_bubble::kOmniboxKeyword) {
331 [self.bubble setArrowLocation:info_bubble::kTopLeft];
333 [self.bubble setArrowLocation:info_bubble::kTopRight];
336 if (type_ == extension_installed_bubble::kBundle)
339 // Set appropriate icon, resizing if necessary.
340 if ([icon_ size].width > extension_installed_bubble::kIconSize) {
341 [icon_ setSize:NSMakeSize(extension_installed_bubble::kIconSize,
342 extension_installed_bubble::kIconSize)];
344 [iconImage_ setImage:icon_];
345 [iconImage_ setNeedsDisplay:YES];
349 - (bool)hasActivePageAction:(extensions::Command*)command {
350 extensions::CommandService* command_service =
351 extensions::CommandService::Get(browser_->profile());
352 if (type_ == extension_installed_bubble::kPageAction) {
353 if (extensions::CommandsInfo::GetPageActionCommand(extension_) &&
354 command_service->GetPageActionCommand(
356 extensions::CommandService::ACTIVE_ONLY,
366 - (bool)hasActiveBrowserAction:(extensions::Command*)command {
367 extensions::CommandService* command_service =
368 extensions::CommandService::Get(browser_->profile());
369 if (type_ == extension_installed_bubble::kBrowserAction) {
370 if (extensions::CommandsInfo::GetBrowserActionCommand(extension_) &&
371 command_service->GetBrowserActionCommand(
373 extensions::CommandService::ACTIVE_ONLY,
383 - (NSString*)installMessageForCurrentExtensionAction {
384 if (type_ == extension_installed_bubble::kPageAction) {
385 extensions::Command page_action_command;
386 if ([self hasActivePageAction:&page_action_command]) {
387 return l10n_util::GetNSStringF(
388 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO_WITH_SHORTCUT,
389 page_action_command.accelerator().GetShortcutText());
391 return l10n_util::GetNSString(
392 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO);
395 CHECK_EQ(extension_installed_bubble::kBrowserAction, type_);
396 extensions::Command browser_action_command;
397 if ([self hasActiveBrowserAction:&browser_action_command]) {
398 return l10n_util::GetNSStringF(
399 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO_WITH_SHORTCUT,
400 browser_action_command.accelerator().GetShortcutText());
402 return l10n_util::GetNSString(
403 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO);
408 // Calculate the height of each install message, resizing messages in their
409 // frames to fit window width. Return the new window height, based on the
410 // total of all message heights.
411 - (int)calculateWindowHeight {
412 // Adjust the window height to reflect the sum height of all messages
413 // and vertical padding.
414 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin;
416 // If type is bundle, list the extensions that were installed and those that
418 if (type_ == extension_installed_bubble::kBundle) {
419 NSInteger installedListHeight =
420 [self addExtensionList:installedHeadingMsg_
421 itemsMsg:installedItemsMsg_
422 state:BundleInstaller::Item::STATE_INSTALLED];
424 NSInteger failedListHeight =
425 [self addExtensionList:failedHeadingMsg_
426 itemsMsg:failedItemsMsg_
427 state:BundleInstaller::Item::STATE_FAILED];
429 newWindowHeight += installedListHeight + failedListHeight;
431 // Put some space between the lists if both are present.
432 if (installedListHeight > 0 && failedListHeight > 0)
433 newWindowHeight += extension_installed_bubble::kInnerVerticalMargin;
435 return newWindowHeight;
438 int sync_promo_height = 0;
439 if ([self showSyncPromo]) {
440 // First calculate the height of the sign-in promo.
441 NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
443 NSString* link(l10n_util::GetNSStringFWithFixup(
444 IDS_EXTENSION_INSTALLED_SIGNIN_PROMO_LINK,
445 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)));
446 NSString* message(l10n_util::GetNSStringWithFixup(
447 IDS_EXTENSION_INSTALLED_SIGNIN_PROMO));
449 HyperlinkTextView* view = promo_.get();
450 [view setMessageAndLink:message
454 messageColor:[NSColor blackColor]
455 linkColor:gfx::SkColorToCalibratedNSColor(
456 chrome_style::GetLinkColor())];
458 // HACK! The TextView does not report correct height even after you stuff
459 // it with text (it tells you it is single-line even if it is multiline), so
460 // here the hidden howToUse_ TextField is temporarily repurposed to
461 // calculate the correct height for the TextView.
462 [[howToUse_ cell] setAttributedStringValue:[promo_ attributedString]];
463 [GTMUILocalizerAndLayoutTweaker
464 sizeToFitFixedWidthTextField:howToUse_];
465 sync_promo_height = NSHeight([howToUse_ frame]);
468 // First part of extension installed message, the heading.
469 base::string16 extension_name = base::UTF8ToUTF16(extension_->name().c_str());
470 base::i18n::AdjustStringForLocaleDirection(&extension_name);
471 [heading_ setStringValue:l10n_util::GetNSStringF(
472 IDS_EXTENSION_INSTALLED_HEADING, extension_name)];
473 [GTMUILocalizerAndLayoutTweaker
474 sizeToFitFixedWidthTextField:heading_];
475 newWindowHeight += NSHeight([heading_ frame]) +
476 extension_installed_bubble::kInnerVerticalMargin;
478 // If type is browser/page action, include a special message about them.
479 if (type_ == extension_installed_bubble::kBrowserAction ||
480 type_ == extension_installed_bubble::kPageAction) {
481 [howToUse_ setStringValue:[self
482 installMessageForCurrentExtensionAction]];
483 [howToUse_ setHidden:NO];
485 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
486 [GTMUILocalizerAndLayoutTweaker
487 sizeToFitFixedWidthTextField:howToUse_];
488 newWindowHeight += NSHeight([howToUse_ frame]) +
489 extension_installed_bubble::kInnerVerticalMargin;
492 // If type is omnibox keyword, include a special message about the keyword.
493 if (type_ == extension_installed_bubble::kOmniboxKeyword) {
494 [howToUse_ setStringValue:l10n_util::GetNSStringF(
495 IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO,
496 base::UTF8ToUTF16(extensions::OmniboxInfo::GetKeyword(extension_)))];
497 [howToUse_ setHidden:NO];
499 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
500 [GTMUILocalizerAndLayoutTweaker
501 sizeToFitFixedWidthTextField:howToUse_];
502 newWindowHeight += NSHeight([howToUse_ frame]) +
503 extension_installed_bubble::kInnerVerticalMargin;
506 // If type is app, hide howToManage_, and include a "show me" link in the
508 if (type_ == extension_installed_bubble::kApp) {
509 [howToManage_ setHidden:YES];
510 [appShortcutLink_ setHidden:NO];
511 newWindowHeight += 2 * extension_installed_bubble::kInnerVerticalMargin;
512 newWindowHeight += NSHeight([appShortcutLink_ frame]);
514 // Second part of extension installed message.
516 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
517 [GTMUILocalizerAndLayoutTweaker
518 sizeToFitFixedWidthTextField:howToManage_];
519 newWindowHeight += NSHeight([howToManage_ frame]);
522 // Sync sign-in promo, if any.
523 if (sync_promo_height > 0) {
524 NSRect promo_frame = [promo_.get() frame];
525 promo_frame.size.height = sync_promo_height;
526 [promo_.get() setFrame:promo_frame];
527 newWindowHeight += extension_installed_bubble::kInnerVerticalMargin;
528 newWindowHeight += sync_promo_height;
531 extensions::Command command;
532 if ([self hasActivePageAction:&command] ||
533 [self hasActiveBrowserAction:&command]) {
534 [manageShortcutLink_ setHidden:NO];
535 [[manageShortcutLink_ cell]
536 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
537 [[manageShortcutLink_ cell]
538 setTextColor:gfx::SkColorToCalibratedNSColor(
539 chrome_style::GetLinkColor())];
540 [GTMUILocalizerAndLayoutTweaker sizeToFitView:manageShortcutLink_];
541 newWindowHeight += extension_installed_bubble::kInnerVerticalMargin;
542 newWindowHeight += NSHeight([manageShortcutLink_ frame]);
545 return newWindowHeight;
548 - (NSInteger)addExtensionList:(NSTextField*)headingMsg
549 itemsMsg:(NSTextField*)itemsMsg
550 state:(BundleInstaller::Item::State)state {
551 base::string16 heading = bundle_->GetHeadingTextFor(state);
552 bool hidden = heading.empty();
553 [headingMsg setHidden:hidden];
554 [itemsMsg setHidden:hidden];
558 [headingMsg setStringValue:base::SysUTF16ToNSString(heading)];
559 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:headingMsg];
561 NSMutableString* joinedItems = [NSMutableString string];
562 BundleInstaller::ItemList items = bundle_->GetItemsWithState(state);
563 for (size_t i = 0; i < items.size(); ++i) {
565 [joinedItems appendString:@"\n"];
566 [joinedItems appendString:base::SysUTF16ToNSString(
567 items[i].GetNameForDisplay())];
570 [itemsMsg setStringValue:joinedItems];
571 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:itemsMsg];
573 return NSHeight([headingMsg frame]) +
574 extension_installed_bubble::kInnerVerticalMargin +
575 NSHeight([itemsMsg frame]);
578 // Adjust y-position of messages to sit properly in new window height.
579 - (void)setMessageFrames:(int)newWindowHeight {
580 if (type_ == extension_installed_bubble::kBundle) {
581 // Layout the messages from the bottom up.
582 NSTextField* msgs[] = { failedItemsMsg_, failedHeadingMsg_,
583 installedItemsMsg_, installedHeadingMsg_ };
584 NSInteger offsetFromBottom = 0;
585 BOOL isFirstVisible = YES;
586 for (size_t i = 0; i < arraysize(msgs); ++i) {
587 if ([msgs[i] isHidden])
590 NSRect frame = [msgs[i] frame];
591 NSInteger margin = isFirstVisible ?
592 extension_installed_bubble::kOuterVerticalMargin :
593 extension_installed_bubble::kInnerVerticalMargin;
595 frame.origin.y = offsetFromBottom + margin;
596 [msgs[i] setFrame:frame];
597 offsetFromBottom += NSHeight(frame) + margin;
602 // Move the close button a bit to vertically align it with the heading.
603 NSInteger closeButtonFudge = 1;
604 NSRect frame = [closeButton_ frame];
605 frame.origin.y = newWindowHeight - (NSHeight(frame) + closeButtonFudge +
606 extension_installed_bubble::kOuterVerticalMargin);
607 [closeButton_ setFrame:frame];
612 NSRect headingFrame = [heading_ frame];
613 headingFrame.origin.y = newWindowHeight - (
614 NSHeight(headingFrame) +
615 extension_installed_bubble::kOuterVerticalMargin);
616 [heading_ setFrame:headingFrame];
618 NSRect howToManageFrame = [howToManage_ frame];
619 if (!extensions::OmniboxInfo::GetKeyword(extension_).empty() ||
620 extensions::ActionInfo::GetBrowserActionInfo(extension_) ||
621 extensions::ActionInfo::IsVerboseInstallMessage(extension_)) {
622 // For browser actions, page actions and omnibox keyword show the
623 // 'how to use' message before the 'how to manage' message.
624 NSRect howToUseFrame = [howToUse_ frame];
625 howToUseFrame.origin.y = headingFrame.origin.y - (
626 NSHeight(howToUseFrame) +
627 extension_installed_bubble::kInnerVerticalMargin);
628 [howToUse_ setFrame:howToUseFrame];
630 howToManageFrame.origin.y = howToUseFrame.origin.y - (
631 NSHeight(howToManageFrame) +
632 extension_installed_bubble::kInnerVerticalMargin);
634 howToManageFrame.origin.y = NSMinY(headingFrame) - (
635 NSHeight(howToManageFrame) +
636 extension_installed_bubble::kInnerVerticalMargin);
638 [howToManage_ setFrame:howToManageFrame];
640 NSRect frame = howToManageFrame;
641 if ([self showSyncPromo]) {
642 frame = [promo_.get() frame];
643 frame.origin.y = NSMinY(howToManageFrame) -
644 (NSHeight(frame) + extension_installed_bubble::kInnerVerticalMargin);
645 [promo_.get() setFrame:frame];
648 extensions::Command command;
649 if (![manageShortcutLink_ isHidden]) {
650 NSRect manageShortcutFrame = [manageShortcutLink_ frame];
651 manageShortcutFrame.origin.y = NSMinY(frame) - (
652 NSHeight(manageShortcutFrame) +
653 extension_installed_bubble::kInnerVerticalMargin);
654 // Right-align the link.
655 manageShortcutFrame.origin.x = NSMaxX(frame) -
656 NSWidth(manageShortcutFrame);
657 [manageShortcutLink_ setFrame:manageShortcutFrame];
661 // Exposed for unit testing.
662 - (NSRect)headingFrame {
663 return [heading_ frame];
666 - (NSRect)frameOfHowToUse {
667 return [howToUse_ frame];
670 - (NSRect)frameOfHowToManage {
671 return [howToManage_ frame];
674 - (NSRect)frameOfSigninPromo {
675 return [promo_ frame];
678 - (NSButton*)appInstalledShortcutLink {
679 return appShortcutLink_;
682 - (void)extensionUnloaded:(id)sender {
686 - (IBAction)onManageShortcutClicked:(id)sender {
688 std::string configure_url = chrome::kChromeUIExtensionsURL;
689 configure_url += chrome::kExtensionConfigureCommandsSubPage;
690 chrome::NavigateParams params(chrome::GetSingletonTabNavigateParams(
691 browser_, GURL(configure_url)));
692 chrome::Navigate(¶ms);
695 - (IBAction)onAppShortcutClicked:(id)sender {
696 ExtensionInstallUI::OpenAppInstalledUI(browser_->profile(), extension_->id());
699 - (void)awakeFromNib {
702 [self initializeLabel];