| 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*)installMessageForExtensionAction { |
| 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 { |
| 298 CHECK_EQ(extension_installed_bubble::kBrowserAction, type_); |
| 299 extensions::Command browser_action_command; |
| 300 if (extension_->browser_action_command() && |
| 301 command_service->GetBrowserActionCommand( |
| 302 extension_->id(), |
| 303 extensions::CommandService::ACTIVE_ONLY, |
| 304 &browser_action_command, |
| 305 NULL)) { |
| 306 return l10n_util::GetNSStringF( |
| 307 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO_WITH_SHORTCUT, |
| 308 browser_action_command.accelerator().GetShortcutText()); |
| 309 } else { |
| 310 return l10n_util::GetNSString( |
| 311 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO); |
| 312 } |
| 313 } |
| 314 } |
| 315 |
| 277 // Calculate the height of each install message, resizing messages in their | 316 // 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 | 317 // frames to fit window width. Return the new window height, based on the |
| 279 // total of all message heights. | 318 // total of all message heights. |
| 280 - (int)calculateWindowHeight { | 319 - (int)calculateWindowHeight { |
| 281 // Adjust the window height to reflect the sum height of all messages | 320 // Adjust the window height to reflect the sum height of all messages |
| 282 // and vertical padding. | 321 // and vertical padding. |
| 283 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin; | 322 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin; |
| 284 | 323 |
| 285 // First part of extension installed message. | 324 // First part of extension installed message. |
| 286 if (type_ != extension_installed_bubble::kBundle) { | 325 if (type_ != extension_installed_bubble::kBundle) { |
| 287 string16 extension_name = UTF8ToUTF16(extension_->name().c_str()); | 326 string16 extension_name = UTF8ToUTF16(extension_->name().c_str()); |
| 288 base::i18n::AdjustStringForLocaleDirection(&extension_name); | 327 base::i18n::AdjustStringForLocaleDirection(&extension_name); |
| 289 [extensionInstalledMsg_ setStringValue:l10n_util::GetNSStringF( | 328 [extensionInstalledMsg_ setStringValue:l10n_util::GetNSStringF( |
| 290 IDS_EXTENSION_INSTALLED_HEADING, extension_name)]; | 329 IDS_EXTENSION_INSTALLED_HEADING, extension_name)]; |
| 291 [GTMUILocalizerAndLayoutTweaker | 330 [GTMUILocalizerAndLayoutTweaker |
| 292 sizeToFitFixedWidthTextField:extensionInstalledMsg_]; | 331 sizeToFitFixedWidthTextField:extensionInstalledMsg_]; |
| 293 newWindowHeight += [extensionInstalledMsg_ frame].size.height + | 332 newWindowHeight += [extensionInstalledMsg_ frame].size.height + |
| 294 extension_installed_bubble::kInnerVerticalMargin; | 333 extension_installed_bubble::kInnerVerticalMargin; |
| 295 } | 334 } |
| 296 | 335 |
| 297 // If type is page action, include a special message about page actions. | 336 // If type is page action, include a special message about page actions. |
| 298 if (type_ == extension_installed_bubble::kPageAction) { | 337 if (type_ == extension_installed_bubble::kBrowserAction || |
| 338 type_ == extension_installed_bubble::kPageAction) { |
| 339 [extraInfoMsg_ setStringValue:[self installMessageForExtensionAction]]; |
| 299 [extraInfoMsg_ setHidden:NO]; | 340 [extraInfoMsg_ setHidden:NO]; |
| 300 [[extraInfoMsg_ cell] | 341 [[extraInfoMsg_ cell] |
| 301 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 342 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| 302 [GTMUILocalizerAndLayoutTweaker | 343 [GTMUILocalizerAndLayoutTweaker |
| 303 sizeToFitFixedWidthTextField:extraInfoMsg_]; | 344 sizeToFitFixedWidthTextField:extraInfoMsg_]; |
| 304 newWindowHeight += [extraInfoMsg_ frame].size.height + | 345 newWindowHeight += [extraInfoMsg_ frame].size.height + |
| 305 extension_installed_bubble::kInnerVerticalMargin; | 346 extension_installed_bubble::kInnerVerticalMargin; |
| 306 } | 347 } |
| 307 | 348 |
| 308 // If type is omnibox keyword, include a special message about the keyword. | 349 // 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; | 454 return; |
| 414 } | 455 } |
| 415 | 456 |
| 416 NSRect extensionMessageFrame1 = [extensionInstalledMsg_ frame]; | 457 NSRect extensionMessageFrame1 = [extensionInstalledMsg_ frame]; |
| 417 NSRect extensionMessageFrame2 = [extensionInstalledInfoMsg_ frame]; | 458 NSRect extensionMessageFrame2 = [extensionInstalledInfoMsg_ frame]; |
| 418 | 459 |
| 419 extensionMessageFrame1.origin.y = newWindowHeight - ( | 460 extensionMessageFrame1.origin.y = newWindowHeight - ( |
| 420 extensionMessageFrame1.size.height + | 461 extensionMessageFrame1.size.height + |
| 421 extension_installed_bubble::kOuterVerticalMargin); | 462 extension_installed_bubble::kOuterVerticalMargin); |
| 422 [extensionInstalledMsg_ setFrame:extensionMessageFrame1]; | 463 [extensionInstalledMsg_ setFrame:extensionMessageFrame1]; |
| 423 if (type_ == extension_installed_bubble::kPageAction || | 464 if (extension_->is_verbose_install_message()) { |
| 424 type_ == extension_installed_bubble::kOmniboxKeyword) { | |
| 425 // The extra message is only shown when appropriate. | 465 // The extra message is only shown when appropriate. |
| 426 NSRect extraMessageFrame = [extraInfoMsg_ frame]; | 466 NSRect extraMessageFrame = [extraInfoMsg_ frame]; |
| 427 extraMessageFrame.origin.y = extensionMessageFrame1.origin.y - ( | 467 extraMessageFrame.origin.y = extensionMessageFrame1.origin.y - ( |
| 428 extraMessageFrame.size.height + | 468 extraMessageFrame.size.height + |
| 429 extension_installed_bubble::kInnerVerticalMargin); | 469 extension_installed_bubble::kInnerVerticalMargin); |
| 430 [extraInfoMsg_ setFrame:extraMessageFrame]; | 470 [extraInfoMsg_ setFrame:extraMessageFrame]; |
| 431 extensionMessageFrame2.origin.y = extraMessageFrame.origin.y - ( | 471 extensionMessageFrame2.origin.y = extraMessageFrame.origin.y - ( |
| 432 extensionMessageFrame2.size.height + | 472 extensionMessageFrame2.size.height + |
| 433 extension_installed_bubble::kInnerVerticalMargin); | 473 extension_installed_bubble::kInnerVerticalMargin); |
| 434 } else { | 474 } else { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 450 | 490 |
| 451 - (NSRect)getExtensionInstalledInfoMsgFrame { | 491 - (NSRect)getExtensionInstalledInfoMsgFrame { |
| 452 return [extensionInstalledInfoMsg_ frame]; | 492 return [extensionInstalledInfoMsg_ frame]; |
| 453 } | 493 } |
| 454 | 494 |
| 455 - (void)extensionUnloaded:(id)sender { | 495 - (void)extensionUnloaded:(id)sender { |
| 456 extension_ = NULL; | 496 extension_ = NULL; |
| 457 } | 497 } |
| 458 | 498 |
| 459 @end | 499 @end |
| OLD | NEW |