| OLD | NEW |
| 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/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 13 #include "chrome/browser/extensions/api/commands/command_service_factory.h" |
| 12 #include "chrome/browser/extensions/bundle_installer.h" | 14 #include "chrome/browser/extensions/bundle_installer.h" |
| 13 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 17 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 16 #include "chrome/browser/ui/cocoa/browser_window_controller.h" | 18 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 17 #include "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" | 19 #include "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
| 18 #include "chrome/browser/ui/cocoa/hover_close_button.h" | 20 #include "chrome/browser/ui/cocoa/hover_close_button.h" |
| 19 #include "chrome/browser/ui/cocoa/info_bubble_view.h" | 21 #include "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 20 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 22 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 21 #include "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 23 #include "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 if ((self = [super initWithWindowNibPath:nibName | 98 if ((self = [super initWithWindowNibPath:nibName |
| 97 parentWindow:parentWindow | 99 parentWindow:parentWindow |
| 98 anchoredAt:NSZeroPoint])) { | 100 anchoredAt:NSZeroPoint])) { |
| 99 extension_ = extension; | 101 extension_ = extension; |
| 100 bundle_ = bundle; | 102 bundle_ = bundle; |
| 101 DCHECK(browser); | 103 DCHECK(browser); |
| 102 browser_ = browser; | 104 browser_ = browser; |
| 103 icon_.reset([gfx::SkBitmapToNSImage(icon) retain]); | 105 icon_.reset([gfx::SkBitmapToNSImage(icon) retain]); |
| 104 pageActionRemoved_ = NO; | 106 pageActionRemoved_ = NO; |
| 105 | 107 |
| 106 if (bundle_) { | 108 if (bundle_) |
| 107 type_ = extension_installed_bubble::kBundle; | 109 type_ = extension_installed_bubble::kBundle; |
| 108 } else if (!extension->omnibox_keyword().empty()) { | 110 else if (!extension->omnibox_keyword().empty()) |
| 109 type_ = extension_installed_bubble::kOmniboxKeyword; | 111 type_ = extension_installed_bubble::kOmniboxKeyword; |
| 110 } else if (extension->browser_action()) { | 112 else if (extension->browser_action()) |
| 111 type_ = extension_installed_bubble::kBrowserAction; | 113 type_ = extension_installed_bubble::kBrowserAction; |
| 112 } else if (extension->page_action() && | 114 else if (extension->page_action() && extension->verbose_install_message()) |
| 113 !extension->page_action()->default_icon_path().empty()) { | |
| 114 type_ = extension_installed_bubble::kPageAction; | 115 type_ = extension_installed_bubble::kPageAction; |
| 115 } else { | 116 else |
| 116 NOTREACHED(); // kGeneric installs handled in extension_install_prompt. | 117 NOTREACHED(); // kGeneric installs handled in extension_install_prompt. |
| 117 } | |
| 118 | 118 |
| 119 if (type_ == extension_installed_bubble::kBundle) { | 119 if (type_ == extension_installed_bubble::kBundle) { |
| 120 [self showWindow:self]; | 120 [self showWindow:self]; |
| 121 } else { | 121 } else { |
| 122 // Start showing window only after extension has fully loaded. | 122 // Start showing window only after extension has fully loaded. |
| 123 extensionObserver_.reset(new ExtensionLoadedNotificationObserver( | 123 extensionObserver_.reset(new ExtensionLoadedNotificationObserver( |
| 124 self, browser->profile())); | 124 self, browser->profile())); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 return self; | 127 return self; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // Set appropriate icon, resizing if necessary. | 267 // Set appropriate icon, resizing if necessary. |
| 268 if ([icon_ size].width > extension_installed_bubble::kIconSize) { | 268 if ([icon_ size].width > extension_installed_bubble::kIconSize) { |
| 269 [icon_ setSize:NSMakeSize(extension_installed_bubble::kIconSize, | 269 [icon_ setSize:NSMakeSize(extension_installed_bubble::kIconSize, |
| 270 extension_installed_bubble::kIconSize)]; | 270 extension_installed_bubble::kIconSize)]; |
| 271 } | 271 } |
| 272 [iconImage_ setImage:icon_]; | 272 [iconImage_ setImage:icon_]; |
| 273 [iconImage_ setNeedsDisplay:YES]; | 273 [iconImage_ setNeedsDisplay:YES]; |
| 274 return window; | 274 return window; |
| 275 } | 275 } |
| 276 | 276 |
| 277 - (NSString*)getResourceIdForExtensionAction { |
| 278 extensions::CommandService* command_service = |
| 279 extensions::CommandServiceFactory::GetForProfile(browser_->profile()); |
| 280 if (type_ == extension_installed_bubble::kPageAction) { |
| 281 extensions::Command page_action_command; |
| 282 if (extension_->page_action_command() && |
| 283 command_service->GetPageActionCommand( |
| 284 extension_->id(), |
| 285 extensions::CommandService::ACTIVE_ONLY, |
| 286 &page_action_command, |
| 287 NULL)) { |
| 288 return l10n_util::GetNSStringF( |
| 289 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO_WITH_SHORTCUT, |
| 290 page_action_command.accelerator().GetShortcutText()); |
| 291 } else { |
| 292 return l10n_util::GetNSString( |
| 293 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO); |
| 294 } |
| 295 } else { |
| 296 extensions::Command browser_action_command; |
| 297 if (extension_->browser_action_command() && |
| 298 command_service->GetBrowserActionCommand( |
| 299 extension_->id(), |
| 300 extensions::CommandService::ACTIVE_ONLY, |
| 301 &browser_action_command, |
| 302 NULL)) { |
| 303 return l10n_util::GetNSStringF( |
| 304 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO_WITH_SHORTCUT, |
| 305 browser_action_command.accelerator().GetShortcutText()); |
| 306 } else { |
| 307 return l10n_util::GetNSString( |
| 308 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO); |
| 309 } |
| 310 } |
| 311 } |
| 312 |
| 277 // Calculate the height of each install message, resizing messages in their | 313 // Calculate the height of each install message, resizing messages in their |
| 278 // frames to fit window width. Return the new window height, based on the | 314 // frames to fit window width. Return the new window height, based on the |
| 279 // total of all message heights. | 315 // total of all message heights. |
| 280 - (int)calculateWindowHeight { | 316 - (int)calculateWindowHeight { |
| 281 // Adjust the window height to reflect the sum height of all messages | 317 // Adjust the window height to reflect the sum height of all messages |
| 282 // and vertical padding. | 318 // and vertical padding. |
| 283 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin; | 319 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin; |
| 284 | 320 |
| 285 // First part of extension installed message. | 321 // First part of extension installed message. |
| 286 if (type_ != extension_installed_bubble::kBundle) { | 322 if (type_ != extension_installed_bubble::kBundle) { |
| 287 string16 extension_name = UTF8ToUTF16(extension_->name().c_str()); | 323 string16 extension_name = UTF8ToUTF16(extension_->name().c_str()); |
| 288 base::i18n::AdjustStringForLocaleDirection(&extension_name); | 324 base::i18n::AdjustStringForLocaleDirection(&extension_name); |
| 289 [extensionInstalledMsg_ setStringValue:l10n_util::GetNSStringF( | 325 [extensionInstalledMsg_ setStringValue:l10n_util::GetNSStringF( |
| 290 IDS_EXTENSION_INSTALLED_HEADING, extension_name)]; | 326 IDS_EXTENSION_INSTALLED_HEADING, extension_name)]; |
| 291 [GTMUILocalizerAndLayoutTweaker | 327 [GTMUILocalizerAndLayoutTweaker |
| 292 sizeToFitFixedWidthTextField:extensionInstalledMsg_]; | 328 sizeToFitFixedWidthTextField:extensionInstalledMsg_]; |
| 293 newWindowHeight += [extensionInstalledMsg_ frame].size.height + | 329 newWindowHeight += [extensionInstalledMsg_ frame].size.height + |
| 294 extension_installed_bubble::kInnerVerticalMargin; | 330 extension_installed_bubble::kInnerVerticalMargin; |
| 295 } | 331 } |
| 296 | 332 |
| 297 // If type is page action, include a special message about page actions. | 333 // If type is page action, include a special message about page actions. |
| 298 if (type_ == extension_installed_bubble::kPageAction) { | 334 if (type_ == extension_installed_bubble::kBrowserAction || |
| 335 type_ == extension_installed_bubble::kPageAction) { |
| 336 [extraInfoMsg_ setStringValue:[self getResourceIdForExtensionAction]]; |
| 299 [extraInfoMsg_ setHidden:NO]; | 337 [extraInfoMsg_ setHidden:NO]; |
| 300 [[extraInfoMsg_ cell] | 338 [[extraInfoMsg_ cell] |
| 301 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 339 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| 302 [GTMUILocalizerAndLayoutTweaker | 340 [GTMUILocalizerAndLayoutTweaker |
| 303 sizeToFitFixedWidthTextField:extraInfoMsg_]; | 341 sizeToFitFixedWidthTextField:extraInfoMsg_]; |
| 304 newWindowHeight += [extraInfoMsg_ frame].size.height + | 342 newWindowHeight += [extraInfoMsg_ frame].size.height + |
| 305 extension_installed_bubble::kInnerVerticalMargin; | 343 extension_installed_bubble::kInnerVerticalMargin; |
| 306 } | 344 } |
| 307 | 345 |
| 308 // If type is omnibox keyword, include a special message about the keyword. | 346 // If type is omnibox keyword, include a special message about the keyword. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 return; | 451 return; |
| 414 } | 452 } |
| 415 | 453 |
| 416 NSRect extensionMessageFrame1 = [extensionInstalledMsg_ frame]; | 454 NSRect extensionMessageFrame1 = [extensionInstalledMsg_ frame]; |
| 417 NSRect extensionMessageFrame2 = [extensionInstalledInfoMsg_ frame]; | 455 NSRect extensionMessageFrame2 = [extensionInstalledInfoMsg_ frame]; |
| 418 | 456 |
| 419 extensionMessageFrame1.origin.y = newWindowHeight - ( | 457 extensionMessageFrame1.origin.y = newWindowHeight - ( |
| 420 extensionMessageFrame1.size.height + | 458 extensionMessageFrame1.size.height + |
| 421 extension_installed_bubble::kOuterVerticalMargin); | 459 extension_installed_bubble::kOuterVerticalMargin); |
| 422 [extensionInstalledMsg_ setFrame:extensionMessageFrame1]; | 460 [extensionInstalledMsg_ setFrame:extensionMessageFrame1]; |
| 423 if (type_ == extension_installed_bubble::kPageAction || | 461 if (extension_->verbose_install_message()) { |
| 424 type_ == extension_installed_bubble::kOmniboxKeyword) { | |
| 425 // The extra message is only shown when appropriate. | 462 // The extra message is only shown when appropriate. |
| 426 NSRect extraMessageFrame = [extraInfoMsg_ frame]; | 463 NSRect extraMessageFrame = [extraInfoMsg_ frame]; |
| 427 extraMessageFrame.origin.y = extensionMessageFrame1.origin.y - ( | 464 extraMessageFrame.origin.y = extensionMessageFrame1.origin.y - ( |
| 428 extraMessageFrame.size.height + | 465 extraMessageFrame.size.height + |
| 429 extension_installed_bubble::kInnerVerticalMargin); | 466 extension_installed_bubble::kInnerVerticalMargin); |
| 430 [extraInfoMsg_ setFrame:extraMessageFrame]; | 467 [extraInfoMsg_ setFrame:extraMessageFrame]; |
| 431 extensionMessageFrame2.origin.y = extraMessageFrame.origin.y - ( | 468 extensionMessageFrame2.origin.y = extraMessageFrame.origin.y - ( |
| 432 extensionMessageFrame2.size.height + | 469 extensionMessageFrame2.size.height + |
| 433 extension_installed_bubble::kInnerVerticalMargin); | 470 extension_installed_bubble::kInnerVerticalMargin); |
| 434 } else { | 471 } else { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 450 | 487 |
| 451 - (NSRect)getExtensionInstalledInfoMsgFrame { | 488 - (NSRect)getExtensionInstalledInfoMsgFrame { |
| 452 return [extensionInstalledInfoMsg_ frame]; | 489 return [extensionInstalledInfoMsg_ frame]; |
| 453 } | 490 } |
| 454 | 491 |
| 455 - (void)extensionUnloaded:(id)sender { | 492 - (void)extensionUnloaded:(id)sender { |
| 456 extension_ = NULL; | 493 extension_ = NULL; |
| 457 } | 494 } |
| 458 | 495 |
| 459 @end | 496 @end |
| OLD | NEW |