1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.h"
#include "base/i18n/rtl.h"
#include "base/mac/bundle_locations.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/commands/command_service.h"
#include "chrome/browser/extensions/bundle_installer.h"
#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/chrome_style.h"
#include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
#include "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
#include "chrome/browser/ui/cocoa/hover_close_button.h"
#include "chrome/browser/ui/cocoa/info_bubble_view.h"
#include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#include "chrome/browser/ui/cocoa/new_tab_button.h"
#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"
#include "chrome/common/extensions/api/extension_action/action_info.h"
#include "chrome/common/extensions/api/omnibox/omnibox_handler.h"
#include "chrome/common/extensions/sync_helper.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h"
#include "extensions/browser/install/extension_install_ui.h"
#include "extensions/common/extension.h"
#include "extensions/common/feature_switch.h"
#import "skia/ext/skia_utils_mac.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
#import "ui/base/cocoa/controls/hyperlink_text_view.h"
#include "ui/base/l10n/l10n_util.h"
using content::BrowserThread;
using extensions::BundleInstaller;
using extensions::Extension;
using extensions::UnloadedExtensionInfo;
class ExtensionInstalledBubbleBridge
: public ExtensionInstalledBubble::Delegate {
public:
explicit ExtensionInstalledBubbleBridge(
ExtensionInstalledBubbleController* controller);
~ExtensionInstalledBubbleBridge() override;
private:
// ExtensionInstalledBubble::Delegate:
bool MaybeShowNow() override;
// 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 bundle = bundle_;
// Exposed for unit test.
@synthesize pageActionPreviewShowing = pageActionPreviewShowing_;
- (id)initWithParentWindow:(NSWindow*)parentWindow
extension:(const Extension*)extension
bundle:(const BundleInstaller*)bundle
browser:(Browser*)browser
icon:(SkBitmap)icon {
NSString* nibName = bundle ? @"ExtensionInstalledBubbleBundle" :
@"ExtensionInstalledBubble";
if ((self = [super initWithWindowNibPath:nibName
parentWindow:parentWindow
anchoredAt:NSZeroPoint])) {
bundle_ = bundle;
DCHECK(browser);
browser_ = browser;
icon_.reset([gfx::SkBitmapToNSImage(icon) retain]);
pageActionPreviewShowing_ = NO;
if (bundle_) {
type_ = extension_installed_bubble::kBundle;
} else if (extension->is_app()) {
type_ = extension_installed_bubble::kApp;
} else if (!extensions::OmniboxInfo::GetKeyword(extension).empty()) {
type_ = extension_installed_bubble::kOmniboxKeyword;
} else if (extensions::ActionInfo::GetBrowserActionInfo(extension)) {
type_ = extension_installed_bubble::kBrowserAction;
} else if (extensions::ActionInfo::GetPageActionInfo(extension) &&
extensions::ActionInfo::IsVerboseInstallMessage(extension)) {
type_ = extension_installed_bubble::kPageAction;
} else {
type_ = extension_installed_bubble::kGeneric;
}
if (type_ == extension_installed_bubble::kBundle) {
[self showWindow:self];
} else {
// Start showing window only after extension has fully loaded.
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.
// The former doesn't show links in a nice way, but the latter can't be added
// in IB without a containing scroll view, so create the NSTextView
// programmatically.
promo_.reset([[HyperlinkTextView alloc]
initWithFrame:[promoPlaceholder_ frame]]);
[promo_.get() setAutoresizingMask:[promoPlaceholder_ autoresizingMask]];
[[promoPlaceholder_ superview]
replaceSubview:promoPlaceholder_ with:promo_.get()];
promoPlaceholder_ = nil; // Now released.
[promo_.get() setDelegate:self];
}
// Returns YES if the sync promo should be shown in the bubble.
- (BOOL)showSyncPromo {
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];
browser_ = NULL;
[closeButton_ setTrackingEnabled:NO];
[super windowWillClose:notification];
}
// The controller is the delegate of the window, so it receives "did resign
// key" notifications. When key is resigned, close the window.
- (void)windowDidResignKey:(NSNotification*)notification {
// If the browser window is closing, we need to remove the page action
// immediately, otherwise the closing animation may overlap with
// browser destruction.
[self removePageActionPreviewIfNecessary];
[super windowDidResignKey:notification];
}
- (IBAction)closeWindow:(id)sender {
DCHECK([[self window] isVisible]);
[self close];
}
- (BOOL)textView:(NSTextView*)aTextView
clickedOnLink:(id)link
atIndex:(NSUInteger)charIndex {
DCHECK_EQ(promo_.get(), aTextView);
chrome::ShowBrowserSignin(browser_,
signin_metrics::SOURCE_EXTENSION_INSTALL_BUBBLE);
return YES;
}
// Extracted to a function here so that it can be overridden for unit testing.
- (void)removePageActionPreviewIfNecessary {
if (![self extension] || !pageActionPreviewShowing_)
return;
ExtensionAction* page_action =
extensions::ExtensionActionManager::Get(browser_->profile())->
GetPageAction(*[self extension]);
if (!page_action)
return;
pageActionPreviewShowing_ = NO;
BrowserWindowCocoa* window =
static_cast<BrowserWindowCocoa*>(browser_->window());
LocationBarViewMac* locationBarView =
[window->cocoa_controller() locationBarBridge];
locationBarView->SetPreviewEnabledPageAction(page_action,
false); // disables preview.
}
// The extension installed bubble points at the browser action icon or the
// page action icon (shown as a preview), depending on the extension type.
// We need to calculate the location of these icons and the size of the
// message itself (which varies with the title of the extension) in order
// to figure out the origin point for the extension installed bubble.
// TODO(mirandac): add framework to easily test extension UI components!
- (NSPoint)calculateArrowPoint {
BrowserWindowCocoa* window =
static_cast<BrowserWindowCocoa*>(browser_->window());
NSPoint arrowPoint = NSZeroPoint;
if (type_ == extension_installed_bubble::kApp) {
TabStripView* view = [window->cocoa_controller() tabStripView];
NewTabButton* button = [view getNewTabButton];
NSRect bounds = [button bounds];
NSPoint anchor = NSMakePoint(
NSMidX(bounds),
NSMaxY(bounds) - extension_installed_bubble::kAppsBubbleArrowOffset);
arrowPoint = [button convertPoint:anchor toView:nil];
} else if (type_ == extension_installed_bubble::kBrowserAction ||
extensions::FeatureSwitch::extension_action_redesign()->
IsEnabled()) {
// If the toolbar redesign is enabled, all bubbles for extensions point to
// their toolbar action.
BrowserActionsController* controller =
[[window->cocoa_controller() toolbarController]
browserActionsController];
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(*[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. We remove this preview when the extension installed bubble
// closes.
locationBarView->SetPreviewEnabledPageAction(page_action, true);
pageActionPreviewShowing_ = YES;
// Find the center of the bottom of the page action icon.
arrowPoint = locationBarView->GetPageActionBubblePoint(page_action);
} else if (type_ == extension_installed_bubble::kOmniboxKeyword) {
LocationBarViewMac* locationBarView =
[window->cocoa_controller() locationBarBridge];
arrowPoint = locationBarView->GetPageInfoBubblePoint();
} else {
DCHECK(type_ == extension_installed_bubble::kBundle ||
type_ == extension_installed_bubble::kGeneric);
// Point at the bottom of the wrench menu.
NSView* wrenchButton =
[[window->cocoa_controller() toolbarController] wrenchButton];
const NSRect bounds = [wrenchButton bounds];
NSPoint anchor = NSMakePoint(NSMidX(bounds), NSMaxY(bounds));
arrowPoint = [wrenchButton convertPoint:anchor toView:nil];
}
return arrowPoint;
}
// Override -[BaseBubbleController showWindow:] to tweak bubble location and
// set up UI elements.
- (void)showWindow:(id)sender {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Load nib and calculate height based on messages to be shown.
NSWindow* window = [self initializeWindow];
int newWindowHeight = [self calculateWindowHeight];
[self.bubble setFrameSize:NSMakeSize(
NSWidth([[window contentView] bounds]), newWindowHeight)];
NSSize windowDelta = NSMakeSize(
0, newWindowHeight - NSHeight([[window contentView] bounds]));
windowDelta = [[window contentView] convertSize:windowDelta toView:nil];
NSRect newFrame = [window frame];
newFrame.size.height += windowDelta.height;
[window setFrame:newFrame display:NO];
// Now that we have resized the window, adjust y pos of the messages.
[self setMessageFrames:newWindowHeight];
// Find window origin, taking into account bubble size and arrow location.
self.anchorPoint =
[self.parentWindow convertBaseToScreen:[self calculateArrowPoint]];
[super showWindow:sender];
}
// Finish nib loading, set arrow location and load icon into window. This
// function is exposed for unit testing.
- (NSWindow*)initializeWindow {
NSWindow* window = [self window]; // completes nib load
if (type_ == extension_installed_bubble::kOmniboxKeyword) {
[self.bubble setArrowLocation:info_bubble::kTopLeft];
} else {
[self.bubble setArrowLocation:info_bubble::kTopRight];
}
if (type_ == extension_installed_bubble::kBundle)
return window;
// Set appropriate icon, resizing if necessary.
if ([icon_ size].width > extension_installed_bubble::kIconSize) {
[icon_ setSize:NSMakeSize(extension_installed_bubble::kIconSize,
extension_installed_bubble::kIconSize)];
}
[iconImage_ setImage:icon_];
[iconImage_ setNeedsDisplay:YES];
return window;
}
- (bool)hasActivePageAction:(extensions::Command*)command {
extensions::CommandService* command_service =
extensions::CommandService::Get(browser_->profile());
if (type_ == extension_installed_bubble::kPageAction) {
if (extensions::CommandsInfo::GetPageActionCommand([self extension]) &&
command_service->GetPageActionCommand(
[self extension]->id(),
extensions::CommandService::ACTIVE,
command,
NULL)) {
return true;
}
}
return false;
}
- (bool)hasActiveBrowserAction:(extensions::Command*)command {
extensions::CommandService* command_service =
extensions::CommandService::Get(browser_->profile());
if (type_ == extension_installed_bubble::kBrowserAction) {
if (extensions::CommandsInfo::GetBrowserActionCommand([self extension]) &&
command_service->GetBrowserActionCommand(
[self extension]->id(),
extensions::CommandService::ACTIVE,
command,
NULL)) {
return true;
}
}
return false;
}
- (NSString*)installMessageForCurrentExtensionAction {
if (type_ == extension_installed_bubble::kPageAction) {
extensions::Command page_action_command;
if ([self hasActivePageAction:&page_action_command]) {
return l10n_util::GetNSStringF(
IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO_WITH_SHORTCUT,
page_action_command.accelerator().GetShortcutText());
} else {
return l10n_util::GetNSString(
IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO);
}
} else {
CHECK_EQ(extension_installed_bubble::kBrowserAction, type_);
extensions::Command browser_action_command;
if ([self hasActiveBrowserAction:&browser_action_command]) {
return l10n_util::GetNSStringF(
IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO_WITH_SHORTCUT,
browser_action_command.accelerator().GetShortcutText());
} else {
return l10n_util::GetNSString(
IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO);
}
}
}
// Calculate the height of each install message, resizing messages in their
// frames to fit window width. Return the new window height, based on the
// total of all message heights.
- (int)calculateWindowHeight {
// Adjust the window height to reflect the sum height of all messages
// and vertical padding.
int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin;
// If type is bundle, list the extensions that were installed and those that
// failed.
if (type_ == extension_installed_bubble::kBundle) {
NSInteger installedListHeight =
[self addExtensionList:installedHeadingMsg_
itemsMsg:installedItemsMsg_
state:BundleInstaller::Item::STATE_INSTALLED];
NSInteger failedListHeight =
[self addExtensionList:failedHeadingMsg_
itemsMsg:failedItemsMsg_
state:BundleInstaller::Item::STATE_FAILED];
newWindowHeight += installedListHeight + failedListHeight;
// Put some space between the lists if both are present.
if (installedListHeight > 0 && failedListHeight > 0)
newWindowHeight += extension_installed_bubble::kInnerVerticalMargin;
return newWindowHeight;
}
int sync_promo_height = 0;
if ([self showSyncPromo]) {
// First calculate the height of the sign-in promo.
NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
NSString* link(l10n_util::GetNSStringWithFixup(
IDS_EXTENSION_INSTALLED_SIGNIN_PROMO_LINK));
NSString* message(l10n_util::GetNSStringWithFixup(
IDS_EXTENSION_INSTALLED_SIGNIN_PROMO));
message = [link stringByAppendingString:message];
HyperlinkTextView* view = promo_.get();
[view setMessage:message withFont:font messageColor:[NSColor blackColor]];
[view addLinkRange:NSMakeRange(0, [link length])
withName:@""
linkColor:gfx::SkColorToCalibratedNSColor(
chrome_style::GetLinkColor())];
// HACK! The TextView does not report correct height even after you stuff
// it with text (it tells you it is single-line even if it is multiline), so
// here the hidden howToUse_ TextField is temporarily repurposed to
// calculate the correct height for the TextView.
[[howToUse_ cell] setAttributedStringValue:[promo_ attributedString]];
[GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:howToUse_];
sync_promo_height = NSHeight([howToUse_ frame]);
}
// First part of extension installed message, the heading.
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)];
[GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:heading_];
newWindowHeight += NSHeight([heading_ frame]) +
extension_installed_bubble::kInnerVerticalMargin;
// If type is browser/page action, include a special message about them.
if (type_ == extension_installed_bubble::kBrowserAction ||
type_ == extension_installed_bubble::kPageAction) {
[howToUse_ setStringValue:[self
installMessageForCurrentExtensionAction]];
[howToUse_ setHidden:NO];
[[howToUse_ cell]
setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
[GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:howToUse_];
newWindowHeight += NSHeight([howToUse_ frame]) +
extension_installed_bubble::kInnerVerticalMargin;
}
// If type is omnibox keyword, include a special message about the keyword.
if (type_ == extension_installed_bubble::kOmniboxKeyword) {
[howToUse_ setStringValue:l10n_util::GetNSStringF(
IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO,
base::UTF8ToUTF16(extensions::OmniboxInfo::GetKeyword(
[self extension])))];
[howToUse_ setHidden:NO];
[[howToUse_ cell]
setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
[GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:howToUse_];
newWindowHeight += NSHeight([howToUse_ frame]) +
extension_installed_bubble::kInnerVerticalMargin;
}
// If type is app, hide howToManage_, and include a "show me" link in the
// bubble.
if (type_ == extension_installed_bubble::kApp) {
[howToManage_ setHidden:YES];
[appShortcutLink_ setHidden:NO];
newWindowHeight += 2 * extension_installed_bubble::kInnerVerticalMargin;
newWindowHeight += NSHeight([appShortcutLink_ frame]);
} else {
// Second part of extension installed message.
[[howToManage_ cell]
setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
[GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:howToManage_];
newWindowHeight += NSHeight([howToManage_ frame]);
}
// Sync sign-in promo, if any.
if (sync_promo_height > 0) {
NSRect promo_frame = [promo_.get() frame];
promo_frame.size.height = sync_promo_height;
[promo_.get() setFrame:promo_frame];
newWindowHeight += extension_installed_bubble::kInnerVerticalMargin;
newWindowHeight += sync_promo_height;
}
extensions::Command command;
if ([self hasActivePageAction:&command] ||
[self hasActiveBrowserAction:&command]) {
[manageShortcutLink_ setHidden:NO];
[[manageShortcutLink_ cell]
setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
[[manageShortcutLink_ cell]
setTextColor:gfx::SkColorToCalibratedNSColor(
chrome_style::GetLinkColor())];
[GTMUILocalizerAndLayoutTweaker sizeToFitView:manageShortcutLink_];
newWindowHeight += extension_installed_bubble::kInnerVerticalMargin;
newWindowHeight += NSHeight([manageShortcutLink_ frame]);
}
return newWindowHeight;
}
- (NSInteger)addExtensionList:(NSTextField*)headingMsg
itemsMsg:(NSTextField*)itemsMsg
state:(BundleInstaller::Item::State)state {
base::string16 heading = bundle_->GetHeadingTextFor(state);
bool hidden = heading.empty();
[headingMsg setHidden:hidden];
[itemsMsg setHidden:hidden];
if (hidden)
return 0;
[headingMsg setStringValue:base::SysUTF16ToNSString(heading)];
[GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:headingMsg];
NSMutableString* joinedItems = [NSMutableString string];
BundleInstaller::ItemList items = bundle_->GetItemsWithState(state);
for (size_t i = 0; i < items.size(); ++i) {
if (i > 0)
[joinedItems appendString:@"\n"];
[joinedItems appendString:base::SysUTF16ToNSString(
items[i].GetNameForDisplay())];
}
[itemsMsg setStringValue:joinedItems];
[GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:itemsMsg];
return NSHeight([headingMsg frame]) +
extension_installed_bubble::kInnerVerticalMargin +
NSHeight([itemsMsg frame]);
}
// Adjust y-position of messages to sit properly in new window height.
- (void)setMessageFrames:(int)newWindowHeight {
if (type_ == extension_installed_bubble::kBundle) {
// Layout the messages from the bottom up.
NSTextField* msgs[] = { failedItemsMsg_, failedHeadingMsg_,
installedItemsMsg_, installedHeadingMsg_ };
NSInteger offsetFromBottom = 0;
BOOL isFirstVisible = YES;
for (size_t i = 0; i < arraysize(msgs); ++i) {
if ([msgs[i] isHidden])
continue;
NSRect frame = [msgs[i] frame];
NSInteger margin = isFirstVisible ?
extension_installed_bubble::kOuterVerticalMargin :
extension_installed_bubble::kInnerVerticalMargin;
frame.origin.y = offsetFromBottom + margin;
[msgs[i] setFrame:frame];
offsetFromBottom += NSHeight(frame) + margin;
isFirstVisible = NO;
}
// Move the close button a bit to vertically align it with the heading.
NSInteger closeButtonFudge = 1;
NSRect frame = [closeButton_ frame];
frame.origin.y = newWindowHeight - (NSHeight(frame) + closeButtonFudge +
extension_installed_bubble::kOuterVerticalMargin);
[closeButton_ setFrame:frame];
return;
}
NSRect headingFrame = [heading_ frame];
headingFrame.origin.y = newWindowHeight - (
NSHeight(headingFrame) +
extension_installed_bubble::kOuterVerticalMargin);
[heading_ setFrame:headingFrame];
NSRect howToManageFrame = [howToManage_ frame];
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];
howToUseFrame.origin.y = headingFrame.origin.y - (
NSHeight(howToUseFrame) +
extension_installed_bubble::kInnerVerticalMargin);
[howToUse_ setFrame:howToUseFrame];
howToManageFrame.origin.y = howToUseFrame.origin.y - (
NSHeight(howToManageFrame) +
extension_installed_bubble::kInnerVerticalMargin);
} else {
howToManageFrame.origin.y = NSMinY(headingFrame) - (
NSHeight(howToManageFrame) +
extension_installed_bubble::kInnerVerticalMargin);
}
[howToManage_ setFrame:howToManageFrame];
NSRect frame = howToManageFrame;
if ([self showSyncPromo]) {
frame = [promo_.get() frame];
frame.origin.y = NSMinY(howToManageFrame) -
(NSHeight(frame) + extension_installed_bubble::kInnerVerticalMargin);
[promo_.get() setFrame:frame];
}
extensions::Command command;
if (![manageShortcutLink_ isHidden]) {
NSRect manageShortcutFrame = [manageShortcutLink_ frame];
manageShortcutFrame.origin.y = NSMinY(frame) - (
NSHeight(manageShortcutFrame) +
extension_installed_bubble::kInnerVerticalMargin);
// Right-align the link.
manageShortcutFrame.origin.x = NSMaxX(frame) -
NSWidth(manageShortcutFrame);
[manageShortcutLink_ setFrame:manageShortcutFrame];
}
}
// Exposed for unit testing.
- (NSRect)headingFrame {
return [heading_ frame];
}
- (NSRect)frameOfHowToUse {
return [howToUse_ frame];
}
- (NSRect)frameOfHowToManage {
return [howToManage_ frame];
}
- (NSRect)frameOfSigninPromo {
return [promo_ frame];
}
- (NSButton*)appInstalledShortcutLink {
return appShortcutLink_;
}
- (IBAction)onManageShortcutClicked:(id)sender {
[self close];
std::string configure_url = chrome::kChromeUIExtensionsURL;
configure_url += chrome::kExtensionConfigureCommandsSubPage;
chrome::NavigateParams params(chrome::GetSingletonTabNavigateParams(
browser_, GURL(configure_url)));
chrome::Navigate(¶ms);
}
- (IBAction)onAppShortcutClicked:(id)sender {
scoped_ptr<extensions::ExtensionInstallUI> install_ui(
extensions::CreateExtensionInstallUI(browser_->profile()));
install_ui->OpenAppInstalledUI([self extension]->id());
}
- (void)awakeFromNib {
if (bundle_)
return;
[self initializeLabel];
}
@end
|