Chromium Code Reviews| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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() && |
| 113 !extension->page_action()->default_icon_path().empty()) { | 115 extension->is_verbose_install_message()) { |
| 114 type_ = extension_installed_bubble::kPageAction; | 116 type_ = extension_installed_bubble::kPageAction; |
| 115 } else { | 117 } else { |
| 116 NOTREACHED(); // kGeneric installs handled in extension_install_prompt. | 118 NOTREACHED(); // kGeneric installs handled in extension_install_prompt. |
| 117 } | 119 } |
| 118 | 120 |
| 119 if (type_ == extension_installed_bubble::kBundle) { | 121 if (type_ == extension_installed_bubble::kBundle) { |
| 120 [self showWindow:self]; | 122 [self showWindow:self]; |
| 121 } else { | 123 } else { |
| 122 // Start showing window only after extension has fully loaded. | 124 // Start showing window only after extension has fully loaded. |
| 123 extensionObserver_.reset(new ExtensionLoadedNotificationObserver( | 125 extensionObserver_.reset(new ExtensionLoadedNotificationObserver( |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 // Set appropriate icon, resizing if necessary. | 269 // Set appropriate icon, resizing if necessary. |
| 268 if ([icon_ size].width > extension_installed_bubble::kIconSize) { | 270 if ([icon_ size].width > extension_installed_bubble::kIconSize) { |
| 269 [icon_ setSize:NSMakeSize(extension_installed_bubble::kIconSize, | 271 [icon_ setSize:NSMakeSize(extension_installed_bubble::kIconSize, |
| 270 extension_installed_bubble::kIconSize)]; | 272 extension_installed_bubble::kIconSize)]; |
| 271 } | 273 } |
| 272 [iconImage_ setImage:icon_]; | 274 [iconImage_ setImage:icon_]; |
| 273 [iconImage_ setNeedsDisplay:YES]; | 275 [iconImage_ setNeedsDisplay:YES]; |
| 274 return window; | 276 return window; |
| 275 } | 277 } |
| 276 | 278 |
| 279 - (NSString*)getResourceIdForExtensionAction { | |
| 280 extensions::CommandService* command_service = | |
| 281 extensions::CommandServiceFactory::GetForProfile(browser_->profile()); | |
| 282 if (type_ == extension_installed_bubble::kPageAction) { | |
| 283 extensions::Command page_action_command; | |
| 284 if (extension_->page_action_command() && | |
| 285 command_service->GetPageActionCommand( | |
| 286 extension_->id(), | |
| 287 extensions::CommandService::ACTIVE_ONLY, | |
| 288 &page_action_command, | |
| 289 NULL)) { | |
| 290 return l10n_util::GetNSStringF( | |
| 291 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO_WITH_SHORTCUT, | |
| 292 page_action_command.accelerator().GetShortcutText()); | |
| 293 } else { | |
| 294 return l10n_util::GetNSString( | |
| 295 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO); | |
| 296 } | |
| 297 } else { | |
|
Nico
2012/08/27 19:08:41
CHECK_EQ(extension_installed_bubble::kBrowserActio
| |
| 298 extensions::Command browser_action_command; | |
| 299 if (extension_->browser_action_command() && | |
| 300 command_service->GetBrowserActionCommand( | |
| 301 extension_->id(), | |
| 302 extensions::CommandService::ACTIVE_ONLY, | |
| 303 &browser_action_command, | |
| 304 NULL)) { | |
| 305 return l10n_util::GetNSStringF( | |
| 306 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO_WITH_SHORTCUT, | |
| 307 browser_action_command.accelerator().GetShortcutText()); | |
| 308 } else { | |
| 309 return l10n_util::GetNSString( | |
| 310 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO); | |
| 311 } | |
| 312 } | |
| 313 } | |
| 314 | |
| 277 // Calculate the height of each install message, resizing messages in their | 315 // 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 | 316 // frames to fit window width. Return the new window height, based on the |
| 279 // total of all message heights. | 317 // total of all message heights. |
| 280 - (int)calculateWindowHeight { | 318 - (int)calculateWindowHeight { |
| 281 // Adjust the window height to reflect the sum height of all messages | 319 // Adjust the window height to reflect the sum height of all messages |
| 282 // and vertical padding. | 320 // and vertical padding. |
| 283 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin; | 321 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin; |
| 284 | 322 |
| 285 // First part of extension installed message. | 323 // First part of extension installed message. |
| 286 if (type_ != extension_installed_bubble::kBundle) { | 324 if (type_ != extension_installed_bubble::kBundle) { |
| 287 string16 extension_name = UTF8ToUTF16(extension_->name().c_str()); | 325 string16 extension_name = UTF8ToUTF16(extension_->name().c_str()); |
| 288 base::i18n::AdjustStringForLocaleDirection(&extension_name); | 326 base::i18n::AdjustStringForLocaleDirection(&extension_name); |
| 289 [extensionInstalledMsg_ setStringValue:l10n_util::GetNSStringF( | 327 [extensionInstalledMsg_ setStringValue:l10n_util::GetNSStringF( |
| 290 IDS_EXTENSION_INSTALLED_HEADING, extension_name)]; | 328 IDS_EXTENSION_INSTALLED_HEADING, extension_name)]; |
| 291 [GTMUILocalizerAndLayoutTweaker | 329 [GTMUILocalizerAndLayoutTweaker |
| 292 sizeToFitFixedWidthTextField:extensionInstalledMsg_]; | 330 sizeToFitFixedWidthTextField:extensionInstalledMsg_]; |
| 293 newWindowHeight += [extensionInstalledMsg_ frame].size.height + | 331 newWindowHeight += [extensionInstalledMsg_ frame].size.height + |
| 294 extension_installed_bubble::kInnerVerticalMargin; | 332 extension_installed_bubble::kInnerVerticalMargin; |
| 295 } | 333 } |
| 296 | 334 |
| 297 // If type is page action, include a special message about page actions. | 335 // If type is page action, include a special message about page actions. |
| 298 if (type_ == extension_installed_bubble::kPageAction) { | 336 if (type_ == extension_installed_bubble::kBrowserAction || |
| 337 type_ == extension_installed_bubble::kPageAction) { | |
| 338 [extraInfoMsg_ setStringValue:[self getResourceIdForExtensionAction]]; | |
| 299 [extraInfoMsg_ setHidden:NO]; | 339 [extraInfoMsg_ setHidden:NO]; |
| 300 [[extraInfoMsg_ cell] | 340 [[extraInfoMsg_ cell] |
| 301 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 341 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| 302 [GTMUILocalizerAndLayoutTweaker | 342 [GTMUILocalizerAndLayoutTweaker |
| 303 sizeToFitFixedWidthTextField:extraInfoMsg_]; | 343 sizeToFitFixedWidthTextField:extraInfoMsg_]; |
| 304 newWindowHeight += [extraInfoMsg_ frame].size.height + | 344 newWindowHeight += [extraInfoMsg_ frame].size.height + |
| 305 extension_installed_bubble::kInnerVerticalMargin; | 345 extension_installed_bubble::kInnerVerticalMargin; |
| 306 } | 346 } |
| 307 | 347 |
| 308 // If type is omnibox keyword, include a special message about the keyword. | 348 // 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; | 453 return; |
| 414 } | 454 } |
| 415 | 455 |
| 416 NSRect extensionMessageFrame1 = [extensionInstalledMsg_ frame]; | 456 NSRect extensionMessageFrame1 = [extensionInstalledMsg_ frame]; |
| 417 NSRect extensionMessageFrame2 = [extensionInstalledInfoMsg_ frame]; | 457 NSRect extensionMessageFrame2 = [extensionInstalledInfoMsg_ frame]; |
| 418 | 458 |
| 419 extensionMessageFrame1.origin.y = newWindowHeight - ( | 459 extensionMessageFrame1.origin.y = newWindowHeight - ( |
| 420 extensionMessageFrame1.size.height + | 460 extensionMessageFrame1.size.height + |
| 421 extension_installed_bubble::kOuterVerticalMargin); | 461 extension_installed_bubble::kOuterVerticalMargin); |
| 422 [extensionInstalledMsg_ setFrame:extensionMessageFrame1]; | 462 [extensionInstalledMsg_ setFrame:extensionMessageFrame1]; |
| 423 if (type_ == extension_installed_bubble::kPageAction || | 463 if (extension_->is_verbose_install_message()) { |
| 424 type_ == extension_installed_bubble::kOmniboxKeyword) { | |
| 425 // The extra message is only shown when appropriate. | 464 // The extra message is only shown when appropriate. |
| 426 NSRect extraMessageFrame = [extraInfoMsg_ frame]; | 465 NSRect extraMessageFrame = [extraInfoMsg_ frame]; |
| 427 extraMessageFrame.origin.y = extensionMessageFrame1.origin.y - ( | 466 extraMessageFrame.origin.y = extensionMessageFrame1.origin.y - ( |
| 428 extraMessageFrame.size.height + | 467 extraMessageFrame.size.height + |
| 429 extension_installed_bubble::kInnerVerticalMargin); | 468 extension_installed_bubble::kInnerVerticalMargin); |
| 430 [extraInfoMsg_ setFrame:extraMessageFrame]; | 469 [extraInfoMsg_ setFrame:extraMessageFrame]; |
| 431 extensionMessageFrame2.origin.y = extraMessageFrame.origin.y - ( | 470 extensionMessageFrame2.origin.y = extraMessageFrame.origin.y - ( |
| 432 extensionMessageFrame2.size.height + | 471 extensionMessageFrame2.size.height + |
| 433 extension_installed_bubble::kInnerVerticalMargin); | 472 extension_installed_bubble::kInnerVerticalMargin); |
| 434 } else { | 473 } else { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 450 | 489 |
| 451 - (NSRect)getExtensionInstalledInfoMsgFrame { | 490 - (NSRect)getExtensionInstalledInfoMsgFrame { |
| 452 return [extensionInstalledInfoMsg_ frame]; | 491 return [extensionInstalledInfoMsg_ frame]; |
| 453 } | 492 } |
| 454 | 493 |
| 455 - (void)extensionUnloaded:(id)sender { | 494 - (void)extensionUnloaded:(id)sender { |
| 456 extension_ = NULL; | 495 extension_ = NULL; |
| 457 } | 496 } |
| 458 | 497 |
| 459 @end | 498 @end |
| OLD | NEW |