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

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

Issue 922523005: [Extensions UI] Share more code in ExtensionInstalledBubble (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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"
9 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
11 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/extensions/api/commands/command_service.h"
14 #include "chrome/browser/extensions/bundle_installer.h" 11 #include "chrome/browser/extensions/bundle_installer.h"
15 #include "chrome/browser/extensions/extension_action.h" 12 #include "chrome/browser/extensions/extension_action.h"
16 #include "chrome/browser/extensions/extension_action_manager.h" 13 #include "chrome/browser/extensions/extension_action_manager.h"
17 #include "chrome/browser/signin/signin_promo.h"
18 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_navigator.h" 15 #include "chrome/browser/ui/browser_navigator.h"
20 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/chrome_pages.h" 17 #include "chrome/browser/ui/chrome_pages.h"
22 #include "chrome/browser/ui/chrome_style.h" 18 #include "chrome/browser/ui/chrome_style.h"
23 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" 19 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
24 #include "chrome/browser/ui/cocoa/browser_window_controller.h" 20 #include "chrome/browser/ui/cocoa/browser_window_controller.h"
25 #include "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" 21 #include "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
26 #include "chrome/browser/ui/cocoa/hover_close_button.h" 22 #include "chrome/browser/ui/cocoa/hover_close_button.h"
27 #include "chrome/browser/ui/cocoa/info_bubble_view.h" 23 #include "chrome/browser/ui/cocoa/info_bubble_view.h"
28 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 24 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
29 #include "chrome/browser/ui/cocoa/new_tab_button.h" 25 #include "chrome/browser/ui/cocoa/new_tab_button.h"
30 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 26 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
31 #include "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 27 #include "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
32 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" 28 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h"
33 #include "chrome/browser/ui/extensions/extension_installed_bubble.h" 29 #include "chrome/browser/ui/extensions/extension_installed_bubble.h"
34 #include "chrome/browser/ui/singleton_tabs.h" 30 #include "chrome/browser/ui/singleton_tabs.h"
35 #include "chrome/browser/ui/sync/sync_promo_ui.h" 31 #include "chrome/browser/ui/sync/sync_promo_ui.h"
36 #include "chrome/common/extensions/api/commands/commands_handler.h"
37 #include "chrome/common/extensions/api/extension_action/action_info.h" 32 #include "chrome/common/extensions/api/extension_action/action_info.h"
38 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h" 33 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h"
39 #include "chrome/common/extensions/sync_helper.h" 34 #include "chrome/common/extensions/sync_helper.h"
40 #include "chrome/common/url_constants.h" 35 #include "chrome/common/url_constants.h"
41 #include "chrome/grit/chromium_strings.h" 36 #include "chrome/grit/chromium_strings.h"
42 #include "chrome/grit/generated_resources.h" 37 #include "chrome/grit/generated_resources.h"
43 #include "content/public/browser/notification_details.h" 38 #include "components/signin/core/browser/signin_metrics.h"
44 #include "content/public/browser/notification_registrar.h"
45 #include "content/public/browser/notification_source.h"
46 #include "extensions/browser/install/extension_install_ui.h" 39 #include "extensions/browser/install/extension_install_ui.h"
47 #include "extensions/common/extension.h" 40 #include "extensions/common/extension.h"
48 #include "extensions/common/feature_switch.h" 41 #include "extensions/common/feature_switch.h"
49 #import "skia/ext/skia_utils_mac.h" 42 #import "skia/ext/skia_utils_mac.h"
50 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" 43 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h"
51 #import "ui/base/cocoa/controls/hyperlink_text_view.h" 44 #import "ui/base/cocoa/controls/hyperlink_text_view.h"
52 #include "ui/base/l10n/l10n_util.h" 45 #include "ui/base/l10n/l10n_util.h"
53 46
54 using content::BrowserThread; 47 using content::BrowserThread;
55 using extensions::BundleInstaller; 48 using extensions::BundleInstaller;
56 using extensions::Extension; 49 using extensions::Extension;
57 using extensions::UnloadedExtensionInfo;
58 50
59 class ExtensionInstalledBubbleBridge 51 class ExtensionInstalledBubbleBridge
60 : public ExtensionInstalledBubble::Delegate { 52 : public ExtensionInstalledBubble::Delegate {
61 public: 53 public:
62 explicit ExtensionInstalledBubbleBridge( 54 explicit ExtensionInstalledBubbleBridge(
63 ExtensionInstalledBubbleController* controller); 55 ExtensionInstalledBubbleController* controller);
64 ~ExtensionInstalledBubbleBridge() override; 56 ~ExtensionInstalledBubbleBridge() override;
65 57
66 private: 58 private:
67 // ExtensionInstalledBubble::Delegate: 59 // ExtensionInstalledBubble::Delegate:
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // Set appropriate icon, resizing if necessary. 313 // Set appropriate icon, resizing if necessary.
322 if ([icon_ size].width > extension_installed_bubble::kIconSize) { 314 if ([icon_ size].width > extension_installed_bubble::kIconSize) {
323 [icon_ setSize:NSMakeSize(extension_installed_bubble::kIconSize, 315 [icon_ setSize:NSMakeSize(extension_installed_bubble::kIconSize,
324 extension_installed_bubble::kIconSize)]; 316 extension_installed_bubble::kIconSize)];
325 } 317 }
326 [iconImage_ setImage:icon_]; 318 [iconImage_ setImage:icon_];
327 [iconImage_ setNeedsDisplay:YES]; 319 [iconImage_ setNeedsDisplay:YES];
328 return window; 320 return window;
329 } 321 }
330 322
331 - (bool)hasActivePageAction:(extensions::Command*)command {
332 extensions::CommandService* command_service =
333 extensions::CommandService::Get(browser_->profile());
334 if (type_ == extension_installed_bubble::kPageAction) {
335 if (extensions::CommandsInfo::GetPageActionCommand([self extension]) &&
336 command_service->GetPageActionCommand(
337 [self extension]->id(),
338 extensions::CommandService::ACTIVE,
339 command,
340 NULL)) {
341 return true;
342 }
343 }
344
345 return false;
346 }
347
348 - (bool)hasActiveBrowserAction:(extensions::Command*)command {
349 extensions::CommandService* command_service =
350 extensions::CommandService::Get(browser_->profile());
351 if (type_ == extension_installed_bubble::kBrowserAction) {
352 if (extensions::CommandsInfo::GetBrowserActionCommand([self extension]) &&
353 command_service->GetBrowserActionCommand(
354 [self extension]->id(),
355 extensions::CommandService::ACTIVE,
356 command,
357 NULL)) {
358 return true;
359 }
360 }
361
362 return false;
363 }
364
365 - (NSString*)installMessageForCurrentExtensionAction {
366 if (type_ == extension_installed_bubble::kPageAction) {
367 extensions::Command page_action_command;
368 if ([self hasActivePageAction:&page_action_command]) {
369 return l10n_util::GetNSStringF(
370 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO_WITH_SHORTCUT,
371 page_action_command.accelerator().GetShortcutText());
372 } else {
373 return l10n_util::GetNSString(
374 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO);
375 }
376 } else {
377 CHECK_EQ(extension_installed_bubble::kBrowserAction, type_);
378 extensions::Command browser_action_command;
379 if ([self hasActiveBrowserAction:&browser_action_command]) {
380 return l10n_util::GetNSStringF(
381 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO_WITH_SHORTCUT,
382 browser_action_command.accelerator().GetShortcutText());
383 } else {
384 return l10n_util::GetNSString(
385 IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO);
386 }
387 }
388 }
389
390 // Calculate the height of each install message, resizing messages in their 323 // Calculate the height of each install message, resizing messages in their
391 // frames to fit window width. Return the new window height, based on the 324 // frames to fit window width. Return the new window height, based on the
392 // total of all message heights. 325 // total of all message heights.
393 - (int)calculateWindowHeight { 326 - (int)calculateWindowHeight {
394 // Adjust the window height to reflect the sum height of all messages 327 // Adjust the window height to reflect the sum height of all messages
395 // and vertical padding. 328 // and vertical padding.
396 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin; 329 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin;
397 330
398 // If type is bundle, list the extensions that were installed and those that 331 // If type is bundle, list the extensions that were installed and those that
399 // failed. 332 // failed.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 [heading_ setStringValue:l10n_util::GetNSStringF( 385 [heading_ setStringValue:l10n_util::GetNSStringF(
453 IDS_EXTENSION_INSTALLED_HEADING, extension_name)]; 386 IDS_EXTENSION_INSTALLED_HEADING, extension_name)];
454 [GTMUILocalizerAndLayoutTweaker 387 [GTMUILocalizerAndLayoutTweaker
455 sizeToFitFixedWidthTextField:heading_]; 388 sizeToFitFixedWidthTextField:heading_];
456 newWindowHeight += NSHeight([heading_ frame]) + 389 newWindowHeight += NSHeight([heading_ frame]) +
457 extension_installed_bubble::kInnerVerticalMargin; 390 extension_installed_bubble::kInnerVerticalMargin;
458 391
459 // If type is browser/page action, include a special message about them. 392 // If type is browser/page action, include a special message about them.
460 if (type_ == extension_installed_bubble::kBrowserAction || 393 if (type_ == extension_installed_bubble::kBrowserAction ||
461 type_ == extension_installed_bubble::kPageAction) { 394 type_ == extension_installed_bubble::kPageAction) {
462 [howToUse_ setStringValue:[self 395 [howToUse_ setStringValue:base::SysUTF16ToNSString(
463 installMessageForCurrentExtensionAction]]; 396 installedBubble_->GetHowToUseDescription())];
464 [howToUse_ setHidden:NO]; 397 [howToUse_ setHidden:NO];
465 [[howToUse_ cell] 398 [[howToUse_ cell]
466 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; 399 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
467 [GTMUILocalizerAndLayoutTweaker 400 [GTMUILocalizerAndLayoutTweaker
468 sizeToFitFixedWidthTextField:howToUse_]; 401 sizeToFitFixedWidthTextField:howToUse_];
469 newWindowHeight += NSHeight([howToUse_ frame]) + 402 newWindowHeight += NSHeight([howToUse_ frame]) +
470 extension_installed_bubble::kInnerVerticalMargin; 403 extension_installed_bubble::kInnerVerticalMargin;
471 } 404 }
472 405
473 // If type is omnibox keyword, include a special message about the keyword. 406 // If type is omnibox keyword, include a special message about the keyword.
474 if (type_ == extension_installed_bubble::kOmniboxKeyword) { 407 if (type_ == extension_installed_bubble::kOmniboxKeyword) {
475 [howToUse_ setStringValue:l10n_util::GetNSStringF( 408 [howToUse_ setStringValue:base::SysUTF16ToNSString(
476 IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO, 409 installedBubble_->GetHowToUseDescription())];
477 base::UTF8ToUTF16(extensions::OmniboxInfo::GetKeyword(
478 [self extension])))];
479 [howToUse_ setHidden:NO]; 410 [howToUse_ setHidden:NO];
480 [[howToUse_ cell] 411 [[howToUse_ cell]
481 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; 412 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
482 [GTMUILocalizerAndLayoutTweaker 413 [GTMUILocalizerAndLayoutTweaker
483 sizeToFitFixedWidthTextField:howToUse_]; 414 sizeToFitFixedWidthTextField:howToUse_];
484 newWindowHeight += NSHeight([howToUse_ frame]) + 415 newWindowHeight += NSHeight([howToUse_ frame]) +
485 extension_installed_bubble::kInnerVerticalMargin; 416 extension_installed_bubble::kInnerVerticalMargin;
486 } 417 }
487 418
488 // If type is app, hide howToManage_, and include a "show me" link in the 419 // If type is app, hide howToManage_, and include a "show me" link in the
(...skipping 14 matching lines...) Expand all
503 434
504 // Sync sign-in promo, if any. 435 // Sync sign-in promo, if any.
505 if (sync_promo_height > 0) { 436 if (sync_promo_height > 0) {
506 NSRect promo_frame = [promo_.get() frame]; 437 NSRect promo_frame = [promo_.get() frame];
507 promo_frame.size.height = sync_promo_height; 438 promo_frame.size.height = sync_promo_height;
508 [promo_.get() setFrame:promo_frame]; 439 [promo_.get() setFrame:promo_frame];
509 newWindowHeight += extension_installed_bubble::kInnerVerticalMargin; 440 newWindowHeight += extension_installed_bubble::kInnerVerticalMargin;
510 newWindowHeight += sync_promo_height; 441 newWindowHeight += sync_promo_height;
511 } 442 }
512 443
513 extensions::Command command; 444 if (installedBubble_->has_command_keybinding()) {
514 if ([self hasActivePageAction:&command] ||
515 [self hasActiveBrowserAction:&command]) {
516 [manageShortcutLink_ setHidden:NO]; 445 [manageShortcutLink_ setHidden:NO];
517 [[manageShortcutLink_ cell] 446 [[manageShortcutLink_ cell]
518 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; 447 setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
519 [[manageShortcutLink_ cell] 448 [[manageShortcutLink_ cell]
520 setTextColor:gfx::SkColorToCalibratedNSColor( 449 setTextColor:gfx::SkColorToCalibratedNSColor(
521 chrome_style::GetLinkColor())]; 450 chrome_style::GetLinkColor())];
522 [GTMUILocalizerAndLayoutTweaker sizeToFitView:manageShortcutLink_]; 451 [GTMUILocalizerAndLayoutTweaker sizeToFitView:manageShortcutLink_];
523 newWindowHeight += extension_installed_bubble::kInnerVerticalMargin; 452 newWindowHeight += extension_installed_bubble::kInnerVerticalMargin;
524 newWindowHeight += NSHeight([manageShortcutLink_ frame]); 453 newWindowHeight += NSHeight([manageShortcutLink_ frame]);
525 } 454 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 [howToManage_ setFrame:howToManageFrame]; 549 [howToManage_ setFrame:howToManageFrame];
621 550
622 NSRect frame = howToManageFrame; 551 NSRect frame = howToManageFrame;
623 if ([self showSyncPromo]) { 552 if ([self showSyncPromo]) {
624 frame = [promo_.get() frame]; 553 frame = [promo_.get() frame];
625 frame.origin.y = NSMinY(howToManageFrame) - 554 frame.origin.y = NSMinY(howToManageFrame) -
626 (NSHeight(frame) + extension_installed_bubble::kInnerVerticalMargin); 555 (NSHeight(frame) + extension_installed_bubble::kInnerVerticalMargin);
627 [promo_.get() setFrame:frame]; 556 [promo_.get() setFrame:frame];
628 } 557 }
629 558
630 extensions::Command command;
631 if (![manageShortcutLink_ isHidden]) { 559 if (![manageShortcutLink_ isHidden]) {
632 NSRect manageShortcutFrame = [manageShortcutLink_ frame]; 560 NSRect manageShortcutFrame = [manageShortcutLink_ frame];
633 manageShortcutFrame.origin.y = NSMinY(frame) - ( 561 manageShortcutFrame.origin.y = NSMinY(frame) - (
634 NSHeight(manageShortcutFrame) + 562 NSHeight(manageShortcutFrame) +
635 extension_installed_bubble::kInnerVerticalMargin); 563 extension_installed_bubble::kInnerVerticalMargin);
636 // Right-align the link. 564 // Right-align the link.
637 manageShortcutFrame.origin.x = NSMaxX(frame) - 565 manageShortcutFrame.origin.x = NSMaxX(frame) -
638 NSWidth(manageShortcutFrame); 566 NSWidth(manageShortcutFrame);
639 [manageShortcutLink_ setFrame:manageShortcutFrame]; 567 [manageShortcutLink_ setFrame:manageShortcutFrame];
640 } 568 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 install_ui->OpenAppInstalledUI([self extension]->id()); 604 install_ui->OpenAppInstalledUI([self extension]->id());
677 } 605 }
678 606
679 - (void)awakeFromNib { 607 - (void)awakeFromNib {
680 if (bundle_) 608 if (bundle_)
681 return; 609 return;
682 [self initializeLabel]; 610 [self initializeLabel];
683 } 611 }
684 612
685 @end 613 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698