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 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
11 #import "base/mac/sdk_forward_declarations.h" | 11 #import "base/mac/sdk_forward_declarations.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/download/download_shelf.h" | 17 #include "chrome/browser/download/download_shelf.h" |
18 #include "chrome/browser/extensions/bookmark_app_helper.h" | |
19 #include "chrome/browser/extensions/extension_service.h" | |
20 #include "chrome/browser/extensions/launch_util.h" | |
18 #include "chrome/browser/extensions/tab_helper.h" | 21 #include "chrome/browser/extensions/tab_helper.h" |
19 #include "chrome/browser/fullscreen.h" | 22 #include "chrome/browser/fullscreen.h" |
20 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/shell_integration.h" | 24 #include "chrome/browser/shell_integration.h" |
22 #include "chrome/browser/signin/signin_header_helper.h" | 25 #include "chrome/browser/signin/signin_header_helper.h" |
23 #include "chrome/browser/translate/chrome_translate_client.h" | 26 #include "chrome/browser/translate/chrome_translate_client.h" |
24 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_command_controller.h" | 28 #include "chrome/browser/ui/browser_command_controller.h" |
26 #include "chrome/browser/ui/browser_commands_mac.h" | 29 #include "chrome/browser/ui/browser_commands_mac.h" |
27 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
28 #include "chrome/browser/ui/browser_window_state.h" | 31 #include "chrome/browser/ui/browser_window_state.h" |
32 #include "chrome/browser/ui/cocoa/key_equivalent_constants.h" | |
29 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" | 33 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" |
30 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 34 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
31 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 35 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
32 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 36 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
33 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" | 37 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" |
34 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 38 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
35 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 39 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
36 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 40 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
37 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" | 41 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" |
38 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" | 42 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" |
39 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h" | 43 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h" |
40 #include "chrome/browser/ui/cocoa/restart_browser.h" | 44 #include "chrome/browser/ui/cocoa/restart_browser.h" |
41 #include "chrome/browser/ui/cocoa/status_bubble_mac.h" | 45 #include "chrome/browser/ui/cocoa/status_bubble_mac.h" |
42 #include "chrome/browser/ui/cocoa/task_manager_mac.h" | 46 #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
43 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 47 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
44 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" | 48 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" |
45 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro ller.h" | 49 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro ller.h" |
46 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 50 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
47 #include "chrome/browser/ui/search/search_model.h" | 51 #include "chrome/browser/ui/search/search_model.h" |
48 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 52 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
49 #include "chrome/browser/web_applications/web_app.h" | 53 #include "chrome/browser/web_applications/web_app.h" |
54 #include "chrome/browser/web_applications/web_app_mac.h" | |
50 #include "chrome/common/chrome_switches.h" | 55 #include "chrome/common/chrome_switches.h" |
51 #include "chrome/common/pref_names.h" | 56 #include "chrome/common/pref_names.h" |
57 #include "chrome/grit/generated_resources.h" | |
52 #include "components/translate/core/browser/language_state.h" | 58 #include "components/translate/core/browser/language_state.h" |
53 #include "content/public/browser/native_web_keyboard_event.h" | 59 #include "content/public/browser/native_web_keyboard_event.h" |
54 #include "content/public/browser/notification_details.h" | 60 #include "content/public/browser/notification_details.h" |
55 #include "content/public/browser/notification_source.h" | 61 #include "content/public/browser/notification_source.h" |
56 #include "content/public/browser/web_contents.h" | 62 #include "content/public/browser/web_contents.h" |
63 #include "extensions/common/constants.h" | |
64 #include "extensions/browser/extension_system.h" | |
65 #include "extensions/browser/extension_registry.h" | |
66 #include "extensions/browser/pref_names.h" | |
57 #include "ui/base/l10n/l10n_util_mac.h" | 67 #include "ui/base/l10n/l10n_util_mac.h" |
58 #include "ui/gfx/rect.h" | 68 #include "ui/gfx/rect.h" |
59 | 69 |
60 #if defined(ENABLE_ONE_CLICK_SIGNIN) | 70 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
61 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" | 71 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" |
62 #import "chrome/browser/ui/cocoa/one_click_signin_dialog_controller.h" | 72 #import "chrome/browser/ui/cocoa/one_click_signin_dialog_controller.h" |
63 #endif | 73 #endif |
64 | 74 |
65 using content::NativeWebKeyboardEvent; | 75 using content::NativeWebKeyboardEvent; |
66 using content::SSLStatus; | 76 using content::SSLStatus; |
67 using content::WebContents; | 77 using content::WebContents; |
68 | 78 |
69 namespace { | 79 namespace { |
70 | 80 |
81 // These UI constants are used in BrowserWindowCocoa::ShowBookmarkAppBubble. | |
82 // Used for defining the layout of the NSAlert and NSTextField within the | |
83 // accessory view. | |
84 const int kAppTextFieldVerticalSpacing = 2; | |
85 const int kAppTextFieldWidth = 200; | |
86 const int kAppTextFieldHeight = 22; | |
87 const int kBookmarkAppBubbleViewWidth = 200; | |
88 const int kBookmarkAppBubbleViewHeight = 46; | |
mitchellj
2014/12/10 02:48:45
Robert, tapted@ warned that by calling NSMakeRect
| |
89 | |
90 const int kIconPreviewTargetSize = 64; | |
91 | |
71 NSPoint GetPointForBubble(content::WebContents* web_contents, | 92 NSPoint GetPointForBubble(content::WebContents* web_contents, |
72 int x_offset, | 93 int x_offset, |
73 int y_offset) { | 94 int y_offset) { |
74 NSView* view = web_contents->GetNativeView(); | 95 NSView* view = web_contents->GetNativeView(); |
75 NSRect bounds = [view bounds]; | 96 NSRect bounds = [view bounds]; |
76 NSPoint point; | 97 NSPoint point; |
77 point.x = NSMinX(bounds) + x_offset; | 98 point.x = NSMinX(bounds) + x_offset; |
78 // The view's origin is at the bottom but |rect|'s origin is at the top. | 99 // The view's origin is at the bottom but |rect|'s origin is at the top. |
79 point.y = NSMaxY(bounds) - y_offset; | 100 point.y = NSMaxY(bounds) - y_offset; |
80 point = [view convertPoint:point toView:nil]; | 101 point = [view convertPoint:point toView:nil]; |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 | 511 |
491 void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url, | 512 void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url, |
492 bool already_bookmarked) { | 513 bool already_bookmarked) { |
493 [controller_ showBookmarkBubbleForURL:url | 514 [controller_ showBookmarkBubbleForURL:url |
494 alreadyBookmarked:(already_bookmarked ? YES : NO)]; | 515 alreadyBookmarked:(already_bookmarked ? YES : NO)]; |
495 } | 516 } |
496 | 517 |
497 void BrowserWindowCocoa::ShowBookmarkAppBubble( | 518 void BrowserWindowCocoa::ShowBookmarkAppBubble( |
498 const WebApplicationInfo& web_app_info, | 519 const WebApplicationInfo& web_app_info, |
499 const std::string& extension_id) { | 520 const std::string& extension_id) { |
500 NOTIMPLEMENTED(); | 521 Profile* profile = browser_->profile(); |
522 | |
523 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); | |
524 [alert setMessageText:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_TITLE)]; | |
525 [alert setAlertStyle:NSInformationalAlertStyle]; | |
526 | |
527 NSButton* continue_button = | |
528 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_OK)]; | |
529 [continue_button setKeyEquivalent:kKeyEquivalentReturn]; | |
530 NSButton* cancel_button = | |
531 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_CANCEL)]; | |
532 [cancel_button setKeyEquivalent:kKeyEquivalentEscape]; | |
533 | |
534 base::scoped_nsobject<NSButton> open_as_tab_checkbox( | |
535 [[NSButton alloc] initWithFrame:NSZeroRect]); | |
536 [open_as_tab_checkbox setButtonType:NSSwitchButton]; | |
537 [open_as_tab_checkbox | |
538 setTitle:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_TAB)]; | |
539 [open_as_tab_checkbox setState: | |
540 profile->GetPrefs()->GetInteger( | |
541 extensions::pref_names::kBookmarkAppCreationLaunchType) == | |
542 extensions::LAUNCH_TYPE_REGULAR]; | |
543 [open_as_tab_checkbox sizeToFit]; | |
544 | |
545 base::scoped_nsobject<NSTextField> app_title([[NSTextField alloc] | |
546 initWithFrame:NSMakeRect(0, kAppTextFieldHeight + | |
547 kAppTextFieldVerticalSpacing, | |
548 kAppTextFieldWidth, kAppTextFieldHeight)]); | |
549 NSString* original_title = SysUTF16ToNSString(web_app_info.title); | |
550 [[app_title cell] setWraps:NO]; | |
551 [[app_title cell] setScrollable:YES]; | |
552 [app_title setStringValue:original_title]; | |
553 | |
554 base::scoped_nsobject<NSView> view([[NSView alloc] | |
555 initWithFrame:NSMakeRect(0, 0, kBookmarkAppBubbleViewWidth, | |
556 kBookmarkAppBubbleViewHeight)]); | |
557 [view addSubview:open_as_tab_checkbox]; | |
558 [view addSubview:app_title]; | |
559 [alert setAccessoryView:view]; | |
560 | |
561 // Find the image with target size. | |
562 // Assumes that the icons are sorted in ascending order of size. | |
563 if (!web_app_info.icons.empty()) { | |
564 const WebApplicationInfo::IconInfo& info = web_app_info.icons.back(); | |
565 gfx::Image icon_image = gfx::Image::CreateFrom1xBitmap(info.data); | |
566 [icon_image.ToNSImage() | |
567 setSize:NSMakeSize(kIconPreviewTargetSize, kIconPreviewTargetSize)]; | |
568 [alert setIcon:icon_image.ToNSImage()]; | |
569 } | |
570 | |
571 ExtensionService* service = | |
572 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
573 if ([alert runModal] == NSAlertFirstButtonReturn) { | |
574 // Save launch type preferences for later when creating another hosted app. | |
575 extensions::LaunchType launch_type = | |
576 [open_as_tab_checkbox state] == NSOnState | |
577 ? extensions::LAUNCH_TYPE_REGULAR | |
578 : extensions::LAUNCH_TYPE_WINDOW; | |
579 profile->GetPrefs()->SetInteger( | |
580 extensions::pref_names::kBookmarkAppCreationLaunchType, launch_type); | |
581 extensions::SetLaunchType(service, extension_id, launch_type); | |
582 | |
583 // Update name of app. | |
584 NSString* new_title = [app_title stringValue]; | |
585 if (![original_title isEqualToString:new_title]) { | |
586 WebApplicationInfo new_web_app_info(web_app_info); | |
587 new_web_app_info.title = base::SysNSStringToUTF16(new_title); | |
588 extensions::CreateOrUpdateBookmarkApp(service, new_web_app_info); | |
589 } | |
590 | |
591 extensions::ExtensionRegistry* registry = | |
592 extensions::ExtensionRegistry::Get(profile); | |
593 const extensions::Extension* app = registry->GetExtensionById( | |
594 extension_id, extensions::ExtensionRegistry::ENABLED); | |
595 | |
596 web_app::RevealAppShimInFinderForApp(profile, app); | |
597 } else { | |
598 service->UninstallExtension(extension_id, | |
599 extensions::UNINSTALL_REASON_INSTALL_CANCELED, | |
600 base::Bind(&base::DoNothing), NULL); | |
601 } | |
501 } | 602 } |
502 | 603 |
503 void BrowserWindowCocoa::ShowTranslateBubble( | 604 void BrowserWindowCocoa::ShowTranslateBubble( |
504 content::WebContents* contents, | 605 content::WebContents* contents, |
505 translate::TranslateStep step, | 606 translate::TranslateStep step, |
506 translate::TranslateErrors::Type error_type, | 607 translate::TranslateErrors::Type error_type, |
507 bool is_user_gesture) { | 608 bool is_user_gesture) { |
508 ChromeTranslateClient* chrome_translate_client = | 609 ChromeTranslateClient* chrome_translate_client = |
509 ChromeTranslateClient::FromWebContents(contents); | 610 ChromeTranslateClient::FromWebContents(contents); |
510 translate::LanguageState& language_state = | 611 translate::LanguageState& language_state = |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) | 807 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) |
707 return 0; | 808 return 0; |
708 return 40; | 809 return 40; |
709 } | 810 } |
710 | 811 |
711 void BrowserWindowCocoa::ExecuteExtensionCommand( | 812 void BrowserWindowCocoa::ExecuteExtensionCommand( |
712 const extensions::Extension* extension, | 813 const extensions::Extension* extension, |
713 const extensions::Command& command) { | 814 const extensions::Command& command) { |
714 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; | 815 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; |
715 } | 816 } |
OLD | NEW |