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 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/download/download_shelf.h" | 16 #include "chrome/browser/download/download_shelf.h" |
17 #include "chrome/browser/extensions/bookmark_app_helper.h" | |
18 #include "chrome/browser/extensions/extension_service.h" | |
19 #include "chrome/browser/extensions/launch_util.h" | |
20 #include "chrome/browser/extensions/tab_helper.h" | 17 #include "chrome/browser/extensions/tab_helper.h" |
21 #include "chrome/browser/fullscreen.h" | 18 #include "chrome/browser/fullscreen.h" |
22 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/shell_integration.h" | 20 #include "chrome/browser/shell_integration.h" |
24 #include "chrome/browser/signin/signin_header_helper.h" | 21 #include "chrome/browser/signin/signin_header_helper.h" |
25 #include "chrome/browser/translate/chrome_translate_client.h" | 22 #include "chrome/browser/translate/chrome_translate_client.h" |
26 #include "chrome/browser/ui/app_list/app_list_util.h" | |
27 #include "chrome/browser/ui/app_list/app_list_service.h" | |
28 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
29 #include "chrome/browser/ui/browser_command_controller.h" | 24 #include "chrome/browser/ui/browser_command_controller.h" |
30 #include "chrome/browser/ui/browser_commands_mac.h" | 25 #include "chrome/browser/ui/browser_commands_mac.h" |
31 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
32 #include "chrome/browser/ui/browser_window_state.h" | 27 #include "chrome/browser/ui/browser_window_state.h" |
33 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" | 28 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" |
34 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 29 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
35 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 30 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
36 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 31 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
37 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" | 32 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" |
38 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 33 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
39 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 34 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
40 #include "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 35 #include "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
41 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 36 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
42 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" | 37 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" |
43 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" | 38 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" |
44 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h" | 39 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h" |
45 #include "chrome/browser/ui/cocoa/restart_browser.h" | 40 #include "chrome/browser/ui/cocoa/restart_browser.h" |
46 #include "chrome/browser/ui/cocoa/status_bubble_mac.h" | 41 #include "chrome/browser/ui/cocoa/status_bubble_mac.h" |
47 #include "chrome/browser/ui/cocoa/task_manager_mac.h" | 42 #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 43 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
49 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" | 44 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" |
50 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro
ller.h" | 45 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro
ller.h" |
51 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 46 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
52 #include "chrome/browser/ui/search/search_model.h" | 47 #include "chrome/browser/ui/search/search_model.h" |
53 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 48 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
54 #include "chrome/browser/web_applications/web_app.h" | 49 #include "chrome/browser/web_applications/web_app.h" |
55 #include "chrome/browser/web_applications/web_app_mac.h" | |
56 #include "chrome/common/chrome_switches.h" | 50 #include "chrome/common/chrome_switches.h" |
57 #include "chrome/common/pref_names.h" | 51 #include "chrome/common/pref_names.h" |
58 #include "chrome/grit/generated_resources.h" | 52 #include "chrome/grit/generated_resources.h" |
59 #include "components/translate/core/browser/language_state.h" | 53 #include "components/translate/core/browser/language_state.h" |
60 #include "content/public/browser/native_web_keyboard_event.h" | 54 #include "content/public/browser/native_web_keyboard_event.h" |
61 #include "content/public/browser/notification_details.h" | 55 #include "content/public/browser/notification_details.h" |
62 #include "content/public/browser/notification_source.h" | 56 #include "content/public/browser/notification_source.h" |
63 #include "content/public/browser/notification_service.h" | 57 #include "content/public/browser/notification_service.h" |
64 #include "content/public/browser/web_contents.h" | 58 #include "content/public/browser/web_contents.h" |
65 #include "extensions/browser/extension_registry.h" | 59 #include "extensions/browser/extension_registry.h" |
66 #include "extensions/browser/extension_system.h" | 60 #include "extensions/browser/extension_system.h" |
67 #include "extensions/browser/pref_names.h" | |
68 #include "extensions/common/constants.h" | 61 #include "extensions/common/constants.h" |
69 #include "ui/base/l10n/l10n_util_mac.h" | 62 #include "ui/base/l10n/l10n_util_mac.h" |
70 #include "ui/gfx/geometry/rect.h" | 63 #include "ui/gfx/geometry/rect.h" |
71 | 64 |
72 #if defined(ENABLE_ONE_CLICK_SIGNIN) | 65 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
73 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" | 66 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" |
74 #import "chrome/browser/ui/cocoa/one_click_signin_dialog_controller.h" | 67 #import "chrome/browser/ui/cocoa/one_click_signin_dialog_controller.h" |
75 #endif | 68 #endif |
76 | 69 |
77 using content::NativeWebKeyboardEvent; | 70 using content::NativeWebKeyboardEvent; |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 } | 489 } |
497 | 490 |
498 void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url, | 491 void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url, |
499 bool already_bookmarked) { | 492 bool already_bookmarked) { |
500 [controller_ showBookmarkBubbleForURL:url | 493 [controller_ showBookmarkBubbleForURL:url |
501 alreadyBookmarked:(already_bookmarked ? YES : NO)]; | 494 alreadyBookmarked:(already_bookmarked ? YES : NO)]; |
502 } | 495 } |
503 | 496 |
504 void BrowserWindowCocoa::ShowBookmarkAppBubble( | 497 void BrowserWindowCocoa::ShowBookmarkAppBubble( |
505 const WebApplicationInfo& web_app_info, | 498 const WebApplicationInfo& web_app_info, |
506 const std::string& extension_id) { | 499 const ShowBookmarkAppBubbleCallback& callback) { |
507 Profile* profile = browser_->profile(); | |
508 | |
509 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); | 500 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); |
510 [alert setMessageText:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_TITLE)]; | 501 [alert setMessageText:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_TITLE)]; |
511 [alert setAlertStyle:NSInformationalAlertStyle]; | 502 [alert setAlertStyle:NSInformationalAlertStyle]; |
512 | 503 |
513 NSButton* continue_button = | 504 NSButton* continue_button = |
514 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_OK)]; | 505 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_OK)]; |
515 [continue_button setKeyEquivalent:kKeyEquivalentReturn]; | 506 [continue_button setKeyEquivalent:kKeyEquivalentReturn]; |
516 NSButton* cancel_button = | 507 NSButton* cancel_button = |
517 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_CANCEL)]; | 508 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_CANCEL)]; |
518 [cancel_button setKeyEquivalent:kKeyEquivalentEscape]; | 509 [cancel_button setKeyEquivalent:kKeyEquivalentEscape]; |
519 | 510 |
520 base::scoped_nsobject<NSButton> open_as_window_checkbox( | 511 base::scoped_nsobject<NSButton> open_as_window_checkbox( |
521 [[NSButton alloc] initWithFrame:NSZeroRect]); | 512 [[NSButton alloc] initWithFrame:NSZeroRect]); |
522 [open_as_window_checkbox setButtonType:NSSwitchButton]; | 513 [open_as_window_checkbox setButtonType:NSSwitchButton]; |
523 [open_as_window_checkbox | 514 [open_as_window_checkbox |
524 setTitle:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_WINDOW)]; | 515 setTitle:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_WINDOW)]; |
525 [open_as_window_checkbox setState: | 516 [open_as_window_checkbox setState:web_app_info.open_as_window]; |
526 profile->GetPrefs()->GetInteger( | |
527 extensions::pref_names::kBookmarkAppCreationLaunchType) == | |
528 extensions::LAUNCH_TYPE_WINDOW]; | |
529 [open_as_window_checkbox sizeToFit]; | 517 [open_as_window_checkbox sizeToFit]; |
530 | 518 |
531 base::scoped_nsobject<NSTextField> app_title([[NSTextField alloc] | 519 base::scoped_nsobject<NSTextField> app_title([[NSTextField alloc] |
532 initWithFrame:NSMakeRect(0, kAppTextFieldHeight + | 520 initWithFrame:NSMakeRect(0, kAppTextFieldHeight + |
533 kAppTextFieldVerticalSpacing, | 521 kAppTextFieldVerticalSpacing, |
534 kAppTextFieldWidth, kAppTextFieldHeight)]); | 522 kAppTextFieldWidth, kAppTextFieldHeight)]); |
535 NSString* original_title = SysUTF16ToNSString(web_app_info.title); | 523 NSString* original_title = SysUTF16ToNSString(web_app_info.title); |
536 [[app_title cell] setWraps:NO]; | 524 [[app_title cell] setWraps:NO]; |
537 [[app_title cell] setScrollable:YES]; | 525 [[app_title cell] setScrollable:YES]; |
538 [app_title setStringValue:original_title]; | 526 [app_title setStringValue:original_title]; |
(...skipping 11 matching lines...) Expand all Loading... |
550 for (const WebApplicationInfo::IconInfo& info : web_app_info.icons) { | 538 for (const WebApplicationInfo::IconInfo& info : web_app_info.icons) { |
551 if (info.width == kIconPreviewTargetSize && | 539 if (info.width == kIconPreviewTargetSize && |
552 info.height == kIconPreviewTargetSize) { | 540 info.height == kIconPreviewTargetSize) { |
553 gfx::Image icon_image = gfx::Image::CreateFrom1xBitmap(info.data); | 541 gfx::Image icon_image = gfx::Image::CreateFrom1xBitmap(info.data); |
554 [alert setIcon:icon_image.ToNSImage()]; | 542 [alert setIcon:icon_image.ToNSImage()]; |
555 break; | 543 break; |
556 } | 544 } |
557 } | 545 } |
558 } | 546 } |
559 | 547 |
560 ExtensionService* service = | |
561 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
562 if ([alert runModal] == NSAlertFirstButtonReturn) { | 548 if ([alert runModal] == NSAlertFirstButtonReturn) { |
563 // Save launch type preferences for later when creating another hosted app. | 549 WebApplicationInfo updated_info = web_app_info; |
564 extensions::LaunchType launch_type = | 550 updated_info.open_as_window = [open_as_window_checkbox state] == NSOnState; |
565 [open_as_window_checkbox state] == NSOnState | |
566 ? extensions::LAUNCH_TYPE_WINDOW | |
567 : extensions::LAUNCH_TYPE_REGULAR; | |
568 profile->GetPrefs()->SetInteger( | |
569 extensions::pref_names::kBookmarkAppCreationLaunchType, launch_type); | |
570 extensions::SetLaunchType(profile, extension_id, launch_type); | |
571 | 551 |
572 // Update name of app. | |
573 NSString* new_title = [app_title stringValue]; | 552 NSString* new_title = [app_title stringValue]; |
574 if (![original_title isEqualToString:new_title]) { | 553 updated_info.title = base::SysNSStringToUTF16(new_title); |
575 WebApplicationInfo new_web_app_info(web_app_info); | |
576 new_web_app_info.title = base::SysNSStringToUTF16(new_title); | |
577 extensions::CreateOrUpdateBookmarkApp(service, &new_web_app_info); | |
578 } | |
579 | 554 |
580 // If we're not creating app shims, no need to reveal it in Finder. | 555 callback.Run(true, updated_info); |
581 // Otherwise reveal the app in the app launcher. If not installed, | 556 return; |
582 // then open the chrome://apps page. | 557 } |
583 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
584 switches::kEnableHostedAppShimCreation)) { | |
585 extensions::ExtensionRegistry* registry = | |
586 extensions::ExtensionRegistry::Get(profile); | |
587 const extensions::Extension* app = registry->GetExtensionById( | |
588 extension_id, extensions::ExtensionRegistry::ENABLED); | |
589 | 558 |
590 web_app::RevealAppShimInFinderForApp(profile, app); | 559 callback.Run(false, web_app_info); |
591 } else { | |
592 if (IsAppLauncherEnabled()) { | |
593 AppListService::Get(chrome::GetHostDesktopTypeForNativeWindow( | |
594 browser_->window()->GetNativeWindow())) | |
595 ->ShowForAppInstall(profile, extension_id, false); | |
596 } else { | |
597 chrome::NavigateParams params(profile, GURL(chrome::kChromeUIAppsURL), | |
598 ui::PAGE_TRANSITION_LINK); | |
599 params.disposition = SINGLETON_TAB; | |
600 chrome::Navigate(¶ms); | |
601 | |
602 content::NotificationService::current()->Notify( | |
603 chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, | |
604 content::Source<content::WebContents>(params.target_contents), | |
605 content::Details<const std::string>(&extension_id)); | |
606 } | |
607 } | |
608 } else { | |
609 service->UninstallExtension(extension_id, | |
610 extensions::UNINSTALL_REASON_INSTALL_CANCELED, | |
611 base::Bind(&base::DoNothing), NULL); | |
612 } | |
613 } | 560 } |
614 | 561 |
615 void BrowserWindowCocoa::ShowTranslateBubble( | 562 void BrowserWindowCocoa::ShowTranslateBubble( |
616 content::WebContents* contents, | 563 content::WebContents* contents, |
617 translate::TranslateStep step, | 564 translate::TranslateStep step, |
618 translate::TranslateErrors::Type error_type, | 565 translate::TranslateErrors::Type error_type, |
619 bool is_user_gesture) { | 566 bool is_user_gesture) { |
620 ChromeTranslateClient* chrome_translate_client = | 567 ChromeTranslateClient* chrome_translate_client = |
621 ChromeTranslateClient::FromWebContents(contents); | 568 ChromeTranslateClient::FromWebContents(contents); |
622 translate::LanguageState& language_state = | 569 translate::LanguageState& language_state = |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) | 767 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) |
821 return 0; | 768 return 0; |
822 return 40; | 769 return 40; |
823 } | 770 } |
824 | 771 |
825 void BrowserWindowCocoa::ExecuteExtensionCommand( | 772 void BrowserWindowCocoa::ExecuteExtensionCommand( |
826 const extensions::Extension* extension, | 773 const extensions::Extension* extension, |
827 const extensions::Command& command) { | 774 const extensions::Command& command) { |
828 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; | 775 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; |
829 } | 776 } |
OLD | NEW |