Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(956)

Side by Side Diff: chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.mm

Issue 917863003: [Extensions UI Mac] Wire up Mac to use the ExtensionInstalledBubble (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Robert's Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controlle r.h" 5 #import "chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controlle r.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/mac/bundle_locations.h" 8 #include "base/mac/bundle_locations.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" 23 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
24 #include "chrome/browser/ui/cocoa/browser_window_controller.h" 24 #include "chrome/browser/ui/cocoa/browser_window_controller.h"
25 #include "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" 25 #include "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
26 #include "chrome/browser/ui/cocoa/hover_close_button.h" 26 #include "chrome/browser/ui/cocoa/hover_close_button.h"
27 #include "chrome/browser/ui/cocoa/info_bubble_view.h" 27 #include "chrome/browser/ui/cocoa/info_bubble_view.h"
28 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 28 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
29 #include "chrome/browser/ui/cocoa/new_tab_button.h" 29 #include "chrome/browser/ui/cocoa/new_tab_button.h"
30 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 30 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
31 #include "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 31 #include "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
32 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" 32 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h"
33 #include "chrome/browser/ui/extensions/extension_installed_bubble.h"
33 #include "chrome/browser/ui/singleton_tabs.h" 34 #include "chrome/browser/ui/singleton_tabs.h"
34 #include "chrome/browser/ui/sync/sync_promo_ui.h" 35 #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/commands/commands_handler.h"
36 #include "chrome/common/extensions/api/extension_action/action_info.h" 37 #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/api/omnibox/omnibox_handler.h"
38 #include "chrome/common/extensions/sync_helper.h" 39 #include "chrome/common/extensions/sync_helper.h"
39 #include "chrome/common/url_constants.h" 40 #include "chrome/common/url_constants.h"
40 #include "chrome/grit/chromium_strings.h" 41 #include "chrome/grit/chromium_strings.h"
41 #include "chrome/grit/generated_resources.h" 42 #include "chrome/grit/generated_resources.h"
42 #include "content/public/browser/notification_details.h" 43 #include "content/public/browser/notification_details.h"
43 #include "content/public/browser/notification_registrar.h" 44 #include "content/public/browser/notification_registrar.h"
44 #include "content/public/browser/notification_source.h" 45 #include "content/public/browser/notification_source.h"
45 #include "extensions/browser/install/extension_install_ui.h" 46 #include "extensions/browser/install/extension_install_ui.h"
46 #include "extensions/common/extension.h" 47 #include "extensions/common/extension.h"
47 #include "extensions/common/feature_switch.h" 48 #include "extensions/common/feature_switch.h"
48 #import "skia/ext/skia_utils_mac.h" 49 #import "skia/ext/skia_utils_mac.h"
49 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" 50 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h"
50 #import "ui/base/cocoa/controls/hyperlink_text_view.h" 51 #import "ui/base/cocoa/controls/hyperlink_text_view.h"
51 #include "ui/base/l10n/l10n_util.h" 52 #include "ui/base/l10n/l10n_util.h"
52 53
53 using content::BrowserThread; 54 using content::BrowserThread;
54 using extensions::BundleInstaller; 55 using extensions::BundleInstaller;
55 using extensions::Extension; 56 using extensions::Extension;
56 using extensions::UnloadedExtensionInfo; 57 using extensions::UnloadedExtensionInfo;
57 58
58 // C++ class that receives EXTENSION_LOADED notifications and proxies them back 59 class ExtensionInstalledBubbleBridge
59 // to |controller|. 60 : public ExtensionInstalledBubble::Delegate {
60 class ExtensionLoadedNotificationObserver
61 : public content::NotificationObserver {
62 public: 61 public:
63 ExtensionLoadedNotificationObserver( 62 explicit ExtensionInstalledBubbleBridge(
64 ExtensionInstalledBubbleController* controller, Profile* profile) 63 ExtensionInstalledBubbleController* controller);
65 : controller_(controller) { 64 ~ExtensionInstalledBubbleBridge() override;
66 registrar_.Add(this,
67 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
68 content::Source<Profile>(profile));
69 registrar_.Add(this,
70 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
71 content::Source<Profile>(profile));
72 }
73 65
74 private: 66 private:
75 // NotificationObserver implementation. Tells the controller to start showing 67 // ExtensionInstalledBubble::Delegate:
76 // its window on the main thread when the extension has finished loading. 68 bool MaybeShowNow() override;
77 void Observe(int type,
78 const content::NotificationSource& source,
79 const content::NotificationDetails& details) override {
80 if (type == extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED) {
81 const Extension* extension =
82 content::Details<const Extension>(details).ptr();
83 if (extension == [controller_ extension]) {
84 [controller_ performSelectorOnMainThread:@selector(showWindow:)
85 withObject:controller_
86 waitUntilDone:NO];
87 }
88 } else if (type == extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) {
89 const Extension* extension =
90 content::Details<const UnloadedExtensionInfo>(details)->extension;
91 if (extension == [controller_ extension]) {
92 [controller_ performSelectorOnMainThread:@selector(extensionUnloaded:)
93 withObject:controller_
94 waitUntilDone:NO];
95 }
96 } else {
97 NOTREACHED() << "Received unexpected notification.";
98 }
99 }
100 69
101 content::NotificationRegistrar registrar_; 70 // The (owning) installed bubble controller.
102 ExtensionInstalledBubbleController* controller_; // weak, owns us 71 ExtensionInstalledBubbleController* controller_;
72
73 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubbleBridge);
103 }; 74 };
104 75
76 ExtensionInstalledBubbleBridge::ExtensionInstalledBubbleBridge(
77 ExtensionInstalledBubbleController* controller)
78 : controller_(controller) {
79 }
80
81 ExtensionInstalledBubbleBridge::~ExtensionInstalledBubbleBridge() {
82 }
83
84 bool ExtensionInstalledBubbleBridge::MaybeShowNow() {
85 [controller_ showWindow:controller_];
86 return true;
87 }
88
105 @implementation ExtensionInstalledBubbleController 89 @implementation ExtensionInstalledBubbleController
106 90
107 @synthesize extension = extension_;
108 @synthesize bundle = bundle_; 91 @synthesize bundle = bundle_;
109 // Exposed for unit test. 92 // Exposed for unit test.
110 @synthesize pageActionPreviewShowing = pageActionPreviewShowing_; 93 @synthesize pageActionPreviewShowing = pageActionPreviewShowing_;
111 94
112 - (id)initWithParentWindow:(NSWindow*)parentWindow 95 - (id)initWithParentWindow:(NSWindow*)parentWindow
113 extension:(const Extension*)extension 96 extension:(const Extension*)extension
114 bundle:(const BundleInstaller*)bundle 97 bundle:(const BundleInstaller*)bundle
115 browser:(Browser*)browser 98 browser:(Browser*)browser
116 icon:(SkBitmap)icon { 99 icon:(SkBitmap)icon {
117 NSString* nibName = bundle ? @"ExtensionInstalledBubbleBundle" : 100 NSString* nibName = bundle ? @"ExtensionInstalledBubbleBundle" :
118 @"ExtensionInstalledBubble"; 101 @"ExtensionInstalledBubble";
119 if ((self = [super initWithWindowNibPath:nibName 102 if ((self = [super initWithWindowNibPath:nibName
120 parentWindow:parentWindow 103 parentWindow:parentWindow
121 anchoredAt:NSZeroPoint])) { 104 anchoredAt:NSZeroPoint])) {
122 extension_ = extension;
123 bundle_ = bundle; 105 bundle_ = bundle;
124 DCHECK(browser); 106 DCHECK(browser);
125 browser_ = browser; 107 browser_ = browser;
126 icon_.reset([gfx::SkBitmapToNSImage(icon) retain]); 108 icon_.reset([gfx::SkBitmapToNSImage(icon) retain]);
127 pageActionPreviewShowing_ = NO; 109 pageActionPreviewShowing_ = NO;
128 110
129 if (bundle_) { 111 if (bundle_) {
130 type_ = extension_installed_bubble::kBundle; 112 type_ = extension_installed_bubble::kBundle;
131 } else if (extension->is_app()) { 113 } else if (extension->is_app()) {
132 type_ = extension_installed_bubble::kApp; 114 type_ = extension_installed_bubble::kApp;
133 } else if (!extensions::OmniboxInfo::GetKeyword(extension).empty()) { 115 } else if (!extensions::OmniboxInfo::GetKeyword(extension).empty()) {
134 type_ = extension_installed_bubble::kOmniboxKeyword; 116 type_ = extension_installed_bubble::kOmniboxKeyword;
135 } else if (extensions::ActionInfo::GetBrowserActionInfo(extension)) { 117 } else if (extensions::ActionInfo::GetBrowserActionInfo(extension)) {
136 type_ = extension_installed_bubble::kBrowserAction; 118 type_ = extension_installed_bubble::kBrowserAction;
137 } else if (extensions::ActionInfo::GetPageActionInfo(extension) && 119 } else if (extensions::ActionInfo::GetPageActionInfo(extension) &&
138 extensions::ActionInfo::IsVerboseInstallMessage(extension)) { 120 extensions::ActionInfo::IsVerboseInstallMessage(extension)) {
139 type_ = extension_installed_bubble::kPageAction; 121 type_ = extension_installed_bubble::kPageAction;
140 } else { 122 } else {
141 type_ = extension_installed_bubble::kGeneric; 123 type_ = extension_installed_bubble::kGeneric;
142 } 124 }
143 125
144 if (type_ == extension_installed_bubble::kBundle) { 126 if (type_ == extension_installed_bubble::kBundle) {
145 [self showWindow:self]; 127 [self showWindow:self];
146 } else { 128 } else {
147 // Start showing window only after extension has fully loaded. 129 // Start showing window only after extension has fully loaded.
148 extensionObserver_.reset(new ExtensionLoadedNotificationObserver( 130 installedBubbleBridge_.reset(new ExtensionInstalledBubbleBridge(self));
149 self, browser->profile())); 131 installedBubble_.reset(new ExtensionInstalledBubble(
132 installedBubbleBridge_.get(),
133 extension,
134 browser,
135 icon));
136 installedBubble_->IgnoreBrowserClosing();
150 } 137 }
151 } 138 }
152 return self; 139 return self;
153 } 140 }
154 141
142 - (const Extension*)extension {
143 return installedBubble_->extension();
144 }
145
155 // Sets |promo_| based on |promoPlaceholder_|, sets |promoPlaceholder_| to nil. 146 // Sets |promo_| based on |promoPlaceholder_|, sets |promoPlaceholder_| to nil.
156 - (void)initializeLabel { 147 - (void)initializeLabel {
157 // Replace the promo placeholder NSTextField with the real label NSTextView. 148 // Replace the promo placeholder NSTextField with the real label NSTextView.
158 // The former doesn't show links in a nice way, but the latter can't be added 149 // The former doesn't show links in a nice way, but the latter can't be added
159 // in IB without a containing scroll view, so create the NSTextView 150 // in IB without a containing scroll view, so create the NSTextView
160 // programmatically. 151 // programmatically.
161 promo_.reset([[HyperlinkTextView alloc] 152 promo_.reset([[HyperlinkTextView alloc]
162 initWithFrame:[promoPlaceholder_ frame]]); 153 initWithFrame:[promoPlaceholder_ frame]]);
163 [promo_.get() setAutoresizingMask:[promoPlaceholder_ autoresizingMask]]; 154 [promo_.get() setAutoresizingMask:[promoPlaceholder_ autoresizingMask]];
164 [[promoPlaceholder_ superview] 155 [[promoPlaceholder_ superview]
165 replaceSubview:promoPlaceholder_ with:promo_.get()]; 156 replaceSubview:promoPlaceholder_ with:promo_.get()];
166 promoPlaceholder_ = nil; // Now released. 157 promoPlaceholder_ = nil; // Now released.
167 [promo_.get() setDelegate:self]; 158 [promo_.get() setDelegate:self];
168 } 159 }
169 160
170 // Returns YES if the sync promo should be shown in the bubble. 161 // Returns YES if the sync promo should be shown in the bubble.
171 - (BOOL)showSyncPromo { 162 - (BOOL)showSyncPromo {
172 return extensions::sync_helper::IsSyncableExtension(extension_) && 163 return extensions::sync_helper::IsSyncableExtension([self extension]) &&
173 SyncPromoUI::ShouldShowSyncPromo(browser_->profile()); 164 SyncPromoUI::ShouldShowSyncPromo(browser_->profile());
174 } 165 }
175 166
176 - (void)windowWillClose:(NSNotification*)notification { 167 - (void)windowWillClose:(NSNotification*)notification {
177 // Turn off page action icon preview when the window closes, unless we 168 // Turn off page action icon preview when the window closes, unless we
178 // already removed it when the window resigned key status. 169 // already removed it when the window resigned key status.
179 [self removePageActionPreviewIfNecessary]; 170 [self removePageActionPreviewIfNecessary];
180 extension_ = NULL;
181 browser_ = NULL; 171 browser_ = NULL;
182 [closeButton_ setTrackingEnabled:NO]; 172 [closeButton_ setTrackingEnabled:NO];
183 [super windowWillClose:notification]; 173 [super windowWillClose:notification];
184 } 174 }
185 175
186 // The controller is the delegate of the window, so it receives "did resign 176 // The controller is the delegate of the window, so it receives "did resign
187 // key" notifications. When key is resigned, close the window. 177 // key" notifications. When key is resigned, close the window.
188 - (void)windowDidResignKey:(NSNotification*)notification { 178 - (void)windowDidResignKey:(NSNotification*)notification {
189 // If the browser window is closing, we need to remove the page action 179 // If the browser window is closing, we need to remove the page action
190 // immediately, otherwise the closing animation may overlap with 180 // immediately, otherwise the closing animation may overlap with
(...skipping 11 matching lines...) Expand all
202 clickedOnLink:(id)link 192 clickedOnLink:(id)link
203 atIndex:(NSUInteger)charIndex { 193 atIndex:(NSUInteger)charIndex {
204 DCHECK_EQ(promo_.get(), aTextView); 194 DCHECK_EQ(promo_.get(), aTextView);
205 chrome::ShowBrowserSignin(browser_, 195 chrome::ShowBrowserSignin(browser_,
206 signin_metrics::SOURCE_EXTENSION_INSTALL_BUBBLE); 196 signin_metrics::SOURCE_EXTENSION_INSTALL_BUBBLE);
207 return YES; 197 return YES;
208 } 198 }
209 199
210 // Extracted to a function here so that it can be overridden for unit testing. 200 // Extracted to a function here so that it can be overridden for unit testing.
211 - (void)removePageActionPreviewIfNecessary { 201 - (void)removePageActionPreviewIfNecessary {
212 if (!extension_ || !pageActionPreviewShowing_) 202 if (![self extension] || !pageActionPreviewShowing_)
213 return; 203 return;
214 ExtensionAction* page_action = 204 ExtensionAction* page_action =
215 extensions::ExtensionActionManager::Get(browser_->profile())-> 205 extensions::ExtensionActionManager::Get(browser_->profile())->
216 GetPageAction(*extension_); 206 GetPageAction(*[self extension]);
217 if (!page_action) 207 if (!page_action)
218 return; 208 return;
219 pageActionPreviewShowing_ = NO; 209 pageActionPreviewShowing_ = NO;
220 210
221 BrowserWindowCocoa* window = 211 BrowserWindowCocoa* window =
222 static_cast<BrowserWindowCocoa*>(browser_->window()); 212 static_cast<BrowserWindowCocoa*>(browser_->window());
223 LocationBarViewMac* locationBarView = 213 LocationBarViewMac* locationBarView =
224 [window->cocoa_controller() locationBarBridge]; 214 [window->cocoa_controller() locationBarBridge];
225 locationBarView->SetPreviewEnabledPageAction(page_action, 215 locationBarView->SetPreviewEnabledPageAction(page_action,
226 false); // disables preview. 216 false); // disables preview.
(...skipping 19 matching lines...) Expand all
246 NSMaxY(bounds) - extension_installed_bubble::kAppsBubbleArrowOffset); 236 NSMaxY(bounds) - extension_installed_bubble::kAppsBubbleArrowOffset);
247 arrowPoint = [button convertPoint:anchor toView:nil]; 237 arrowPoint = [button convertPoint:anchor toView:nil];
248 } else if (type_ == extension_installed_bubble::kBrowserAction || 238 } else if (type_ == extension_installed_bubble::kBrowserAction ||
249 extensions::FeatureSwitch::extension_action_redesign()-> 239 extensions::FeatureSwitch::extension_action_redesign()->
250 IsEnabled()) { 240 IsEnabled()) {
251 // If the toolbar redesign is enabled, all bubbles for extensions point to 241 // If the toolbar redesign is enabled, all bubbles for extensions point to
252 // their toolbar action. 242 // their toolbar action.
253 BrowserActionsController* controller = 243 BrowserActionsController* controller =
254 [[window->cocoa_controller() toolbarController] 244 [[window->cocoa_controller() toolbarController]
255 browserActionsController]; 245 browserActionsController];
256 arrowPoint = [controller popupPointForId:extension_->id()]; 246 arrowPoint = [controller popupPointForId:[self extension]->id()];
257 } else if (type_ == extension_installed_bubble::kPageAction) { 247 } else if (type_ == extension_installed_bubble::kPageAction) {
258 LocationBarViewMac* locationBarView = 248 LocationBarViewMac* locationBarView =
259 [window->cocoa_controller() locationBarBridge]; 249 [window->cocoa_controller() locationBarBridge];
260 250
261 ExtensionAction* page_action = 251 ExtensionAction* page_action =
262 extensions::ExtensionActionManager::Get(browser_->profile())-> 252 extensions::ExtensionActionManager::Get(browser_->profile())->
263 GetPageAction(*extension_); 253 GetPageAction(*[self extension]);
264 254
265 // Tell the location bar to show a preview of the page action icon, 255 // Tell the location bar to show a preview of the page action icon,
266 // which would ordinarily only be displayed on a page of the appropriate 256 // which would ordinarily only be displayed on a page of the appropriate
267 // type. We remove this preview when the extension installed bubble 257 // type. We remove this preview when the extension installed bubble
268 // closes. 258 // closes.
269 locationBarView->SetPreviewEnabledPageAction(page_action, true); 259 locationBarView->SetPreviewEnabledPageAction(page_action, true);
270 pageActionPreviewShowing_ = YES; 260 pageActionPreviewShowing_ = YES;
271 261
272 // Find the center of the bottom of the page action icon. 262 // Find the center of the bottom of the page action icon.
273 arrowPoint = locationBarView->GetPageActionBubblePoint(page_action); 263 arrowPoint = locationBarView->GetPageActionBubblePoint(page_action);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 } 325 }
336 [iconImage_ setImage:icon_]; 326 [iconImage_ setImage:icon_];
337 [iconImage_ setNeedsDisplay:YES]; 327 [iconImage_ setNeedsDisplay:YES];
338 return window; 328 return window;
339 } 329 }
340 330
341 - (bool)hasActivePageAction:(extensions::Command*)command { 331 - (bool)hasActivePageAction:(extensions::Command*)command {
342 extensions::CommandService* command_service = 332 extensions::CommandService* command_service =
343 extensions::CommandService::Get(browser_->profile()); 333 extensions::CommandService::Get(browser_->profile());
344 if (type_ == extension_installed_bubble::kPageAction) { 334 if (type_ == extension_installed_bubble::kPageAction) {
345 if (extensions::CommandsInfo::GetPageActionCommand(extension_) && 335 if (extensions::CommandsInfo::GetPageActionCommand([self extension]) &&
346 command_service->GetPageActionCommand( 336 command_service->GetPageActionCommand(
347 extension_->id(), 337 [self extension]->id(),
348 extensions::CommandService::ACTIVE, 338 extensions::CommandService::ACTIVE,
349 command, 339 command,
350 NULL)) { 340 NULL)) {
351 return true; 341 return true;
352 } 342 }
353 } 343 }
354 344
355 return false; 345 return false;
356 } 346 }
357 347
358 - (bool)hasActiveBrowserAction:(extensions::Command*)command { 348 - (bool)hasActiveBrowserAction:(extensions::Command*)command {
359 extensions::CommandService* command_service = 349 extensions::CommandService* command_service =
360 extensions::CommandService::Get(browser_->profile()); 350 extensions::CommandService::Get(browser_->profile());
361 if (type_ == extension_installed_bubble::kBrowserAction) { 351 if (type_ == extension_installed_bubble::kBrowserAction) {
362 if (extensions::CommandsInfo::GetBrowserActionCommand(extension_) && 352 if (extensions::CommandsInfo::GetBrowserActionCommand([self extension]) &&
363 command_service->GetBrowserActionCommand( 353 command_service->GetBrowserActionCommand(
364 extension_->id(), 354 [self extension]->id(),
365 extensions::CommandService::ACTIVE, 355 extensions::CommandService::ACTIVE,
366 command, 356 command,
367 NULL)) { 357 NULL)) {
368 return true; 358 return true;
369 } 359 }
370 } 360 }
371 361
372 return false; 362 return false;
373 } 363 }
374 364
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 // it with text (it tells you it is single-line even if it is multiline), so 439 // it with text (it tells you it is single-line even if it is multiline), so
450 // here the hidden howToUse_ TextField is temporarily repurposed to 440 // here the hidden howToUse_ TextField is temporarily repurposed to
451 // calculate the correct height for the TextView. 441 // calculate the correct height for the TextView.
452 [[howToUse_ cell] setAttributedStringValue:[promo_ attributedString]]; 442 [[howToUse_ cell] setAttributedStringValue:[promo_ attributedString]];
453 [GTMUILocalizerAndLayoutTweaker 443 [GTMUILocalizerAndLayoutTweaker
454 sizeToFitFixedWidthTextField:howToUse_]; 444 sizeToFitFixedWidthTextField:howToUse_];
455 sync_promo_height = NSHeight([howToUse_ frame]); 445 sync_promo_height = NSHeight([howToUse_ frame]);
456 } 446 }
457 447
458 // First part of extension installed message, the heading. 448 // First part of extension installed message, the heading.
459 base::string16 extension_name = base::UTF8ToUTF16(extension_->name().c_str()); 449 base::string16 extension_name =
450 base::UTF8ToUTF16([self extension]->name().c_str());
460 base::i18n::AdjustStringForLocaleDirection(&extension_name); 451 base::i18n::AdjustStringForLocaleDirection(&extension_name);
461 [heading_ setStringValue:l10n_util::GetNSStringF( 452 [heading_ setStringValue:l10n_util::GetNSStringF(
462 IDS_EXTENSION_INSTALLED_HEADING, extension_name)]; 453 IDS_EXTENSION_INSTALLED_HEADING, extension_name)];
463 [GTMUILocalizerAndLayoutTweaker 454 [GTMUILocalizerAndLayoutTweaker
464 sizeToFitFixedWidthTextField:heading_]; 455 sizeToFitFixedWidthTextField:heading_];
465 newWindowHeight += NSHeight([heading_ frame]) + 456 newWindowHeight += NSHeight([heading_ frame]) +
466 extension_installed_bubble::kInnerVerticalMargin; 457 extension_installed_bubble::kInnerVerticalMargin;
467 458
468 // If type is browser/page action, include a special message about them. 459 // If type is browser/page action, include a special message about them.
469 if (type_ == extension_installed_bubble::kBrowserAction || 460 if (type_ == extension_installed_bubble::kBrowserAction ||
470 type_ == extension_installed_bubble::kPageAction) { 461 type_ == extension_installed_bubble::kPageAction) {
471 [howToUse_ setStringValue:[self 462 [howToUse_ setStringValue:[self
472 installMessageForCurrentExtensionAction]]; 463 installMessageForCurrentExtensionAction]];
473 [howToUse_ setHidden:NO]; 464 [howToUse_ setHidden:NO];
474 [[howToUse_ cell] 465 [[howToUse_ cell]
475 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; 466 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
476 [GTMUILocalizerAndLayoutTweaker 467 [GTMUILocalizerAndLayoutTweaker
477 sizeToFitFixedWidthTextField:howToUse_]; 468 sizeToFitFixedWidthTextField:howToUse_];
478 newWindowHeight += NSHeight([howToUse_ frame]) + 469 newWindowHeight += NSHeight([howToUse_ frame]) +
479 extension_installed_bubble::kInnerVerticalMargin; 470 extension_installed_bubble::kInnerVerticalMargin;
480 } 471 }
481 472
482 // If type is omnibox keyword, include a special message about the keyword. 473 // If type is omnibox keyword, include a special message about the keyword.
483 if (type_ == extension_installed_bubble::kOmniboxKeyword) { 474 if (type_ == extension_installed_bubble::kOmniboxKeyword) {
484 [howToUse_ setStringValue:l10n_util::GetNSStringF( 475 [howToUse_ setStringValue:l10n_util::GetNSStringF(
485 IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO, 476 IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO,
486 base::UTF8ToUTF16(extensions::OmniboxInfo::GetKeyword(extension_)))]; 477 base::UTF8ToUTF16(extensions::OmniboxInfo::GetKeyword(
478 [self extension])))];
487 [howToUse_ setHidden:NO]; 479 [howToUse_ setHidden:NO];
488 [[howToUse_ cell] 480 [[howToUse_ cell]
489 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; 481 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
490 [GTMUILocalizerAndLayoutTweaker 482 [GTMUILocalizerAndLayoutTweaker
491 sizeToFitFixedWidthTextField:howToUse_]; 483 sizeToFitFixedWidthTextField:howToUse_];
492 newWindowHeight += NSHeight([howToUse_ frame]) + 484 newWindowHeight += NSHeight([howToUse_ frame]) +
493 extension_installed_bubble::kInnerVerticalMargin; 485 extension_installed_bubble::kInnerVerticalMargin;
494 } 486 }
495 487
496 // If type is app, hide howToManage_, and include a "show me" link in the 488 // If type is app, hide howToManage_, and include a "show me" link in the
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 return; 591 return;
600 } 592 }
601 593
602 NSRect headingFrame = [heading_ frame]; 594 NSRect headingFrame = [heading_ frame];
603 headingFrame.origin.y = newWindowHeight - ( 595 headingFrame.origin.y = newWindowHeight - (
604 NSHeight(headingFrame) + 596 NSHeight(headingFrame) +
605 extension_installed_bubble::kOuterVerticalMargin); 597 extension_installed_bubble::kOuterVerticalMargin);
606 [heading_ setFrame:headingFrame]; 598 [heading_ setFrame:headingFrame];
607 599
608 NSRect howToManageFrame = [howToManage_ frame]; 600 NSRect howToManageFrame = [howToManage_ frame];
609 if (!extensions::OmniboxInfo::GetKeyword(extension_).empty() || 601 if (!extensions::OmniboxInfo::GetKeyword([self extension]).empty() ||
610 extensions::ActionInfo::GetBrowserActionInfo(extension_) || 602 extensions::ActionInfo::GetBrowserActionInfo([self extension]) ||
611 extensions::ActionInfo::IsVerboseInstallMessage(extension_)) { 603 extensions::ActionInfo::IsVerboseInstallMessage([self extension])) {
612 // For browser actions, page actions and omnibox keyword show the 604 // For browser actions, page actions and omnibox keyword show the
613 // 'how to use' message before the 'how to manage' message. 605 // 'how to use' message before the 'how to manage' message.
614 NSRect howToUseFrame = [howToUse_ frame]; 606 NSRect howToUseFrame = [howToUse_ frame];
615 howToUseFrame.origin.y = headingFrame.origin.y - ( 607 howToUseFrame.origin.y = headingFrame.origin.y - (
616 NSHeight(howToUseFrame) + 608 NSHeight(howToUseFrame) +
617 extension_installed_bubble::kInnerVerticalMargin); 609 extension_installed_bubble::kInnerVerticalMargin);
618 [howToUse_ setFrame:howToUseFrame]; 610 [howToUse_ setFrame:howToUseFrame];
619 611
620 howToManageFrame.origin.y = howToUseFrame.origin.y - ( 612 howToManageFrame.origin.y = howToUseFrame.origin.y - (
621 NSHeight(howToManageFrame) + 613 NSHeight(howToManageFrame) +
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 } 654 }
663 655
664 - (NSRect)frameOfSigninPromo { 656 - (NSRect)frameOfSigninPromo {
665 return [promo_ frame]; 657 return [promo_ frame];
666 } 658 }
667 659
668 - (NSButton*)appInstalledShortcutLink { 660 - (NSButton*)appInstalledShortcutLink {
669 return appShortcutLink_; 661 return appShortcutLink_;
670 } 662 }
671 663
672 - (void)extensionUnloaded:(id)sender {
673 extension_ = NULL;
674 }
675
676 - (IBAction)onManageShortcutClicked:(id)sender { 664 - (IBAction)onManageShortcutClicked:(id)sender {
677 [self close]; 665 [self close];
678 std::string configure_url = chrome::kChromeUIExtensionsURL; 666 std::string configure_url = chrome::kChromeUIExtensionsURL;
679 configure_url += chrome::kExtensionConfigureCommandsSubPage; 667 configure_url += chrome::kExtensionConfigureCommandsSubPage;
680 chrome::NavigateParams params(chrome::GetSingletonTabNavigateParams( 668 chrome::NavigateParams params(chrome::GetSingletonTabNavigateParams(
681 browser_, GURL(configure_url))); 669 browser_, GURL(configure_url)));
682 chrome::Navigate(&params); 670 chrome::Navigate(&params);
683 } 671 }
684 672
685 - (IBAction)onAppShortcutClicked:(id)sender { 673 - (IBAction)onAppShortcutClicked:(id)sender {
686 scoped_ptr<extensions::ExtensionInstallUI> install_ui( 674 scoped_ptr<extensions::ExtensionInstallUI> install_ui(
687 extensions::CreateExtensionInstallUI(browser_->profile())); 675 extensions::CreateExtensionInstallUI(browser_->profile()));
688 install_ui->OpenAppInstalledUI(extension_->id()); 676 install_ui->OpenAppInstalledUI([self extension]->id());
689 } 677 }
690 678
691 - (void)awakeFromNib { 679 - (void)awakeFromNib {
692 if (bundle_) 680 if (bundle_)
693 return; 681 return;
694 [self initializeLabel]; 682 [self initializeLabel];
695 } 683 }
696 684
697 @end 685 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698