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 #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 const int kAppTextFieldVerticalSpacing = 2; | |
| 82 const NSSize kAppTextFieldSize = NSMakeSize(200, 22); | |
| 83 const NSSize kViewSize = NSMakeSize(200, 46); | |
|
Robert Sesek
2014/12/09 02:20:52
naming: this needs to mention "app" somewhere, and
mitchellj
2014/12/09 04:23:39
Done.
| |
| 84 const NSRect kAppTitleTextFieldSize = { | |
| 85 NSMakePoint(0, kAppTextFieldSize.height + kAppTextFieldVerticalSpacing), | |
| 86 kAppTextFieldSize}; | |
| 87 const NSRect kBookmarkAppBubbleAccessoryViewSize = {NSMakePoint(0, 0), | |
| 88 kViewSize}; | |
| 89 const int kIconPreviewTargetSize = 64; | |
| 90 | |
| 71 NSPoint GetPointForBubble(content::WebContents* web_contents, | 91 NSPoint GetPointForBubble(content::WebContents* web_contents, |
| 72 int x_offset, | 92 int x_offset, |
| 73 int y_offset) { | 93 int y_offset) { |
| 74 NSView* view = web_contents->GetNativeView(); | 94 NSView* view = web_contents->GetNativeView(); |
| 75 NSRect bounds = [view bounds]; | 95 NSRect bounds = [view bounds]; |
| 76 NSPoint point; | 96 NSPoint point; |
| 77 point.x = NSMinX(bounds) + x_offset; | 97 point.x = NSMinX(bounds) + x_offset; |
| 78 // The view's origin is at the bottom but |rect|'s origin is at the top. | 98 // The view's origin is at the bottom but |rect|'s origin is at the top. |
| 79 point.y = NSMaxY(bounds) - y_offset; | 99 point.y = NSMaxY(bounds) - y_offset; |
| 80 point = [view convertPoint:point toView:nil]; | 100 point = [view convertPoint:point toView:nil]; |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 | 510 |
| 491 void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url, | 511 void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url, |
| 492 bool already_bookmarked) { | 512 bool already_bookmarked) { |
| 493 [controller_ showBookmarkBubbleForURL:url | 513 [controller_ showBookmarkBubbleForURL:url |
| 494 alreadyBookmarked:(already_bookmarked ? YES : NO)]; | 514 alreadyBookmarked:(already_bookmarked ? YES : NO)]; |
| 495 } | 515 } |
| 496 | 516 |
| 497 void BrowserWindowCocoa::ShowBookmarkAppBubble( | 517 void BrowserWindowCocoa::ShowBookmarkAppBubble( |
| 498 const WebApplicationInfo& web_app_info, | 518 const WebApplicationInfo& web_app_info, |
| 499 const std::string& extension_id) { | 519 const std::string& extension_id) { |
| 500 NOTIMPLEMENTED(); | 520 Profile* profile = browser_->profile(); |
| 521 | |
| 522 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); | |
| 523 [alert setMessageText:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_TITLE)]; | |
| 524 [alert setAlertStyle:NSInformationalAlertStyle]; | |
| 525 | |
| 526 NSButton* continue_button = | |
| 527 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_OK)]; | |
| 528 [continue_button setKeyEquivalent:kKeyEquivalentReturn]; | |
| 529 NSButton* cancel_button = | |
| 530 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_CANCEL)]; | |
| 531 [cancel_button setKeyEquivalent:kKeyEquivalentEscape]; | |
| 532 | |
| 533 base::scoped_nsobject<NSButton> open_as_tab_checkbox( | |
| 534 [[NSButton alloc] initWithFrame:NSZeroRect]); | |
| 535 [open_as_tab_checkbox setButtonType:NSSwitchButton]; | |
| 536 [open_as_tab_checkbox | |
| 537 setTitle:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_TAB)]; | |
| 538 [open_as_tab_checkbox setState: | |
| 539 profile->GetPrefs()->GetInteger( | |
| 540 extensions::pref_names::kBookmarkAppCreationLaunchType) == | |
| 541 extensions::LAUNCH_TYPE_REGULAR]; | |
| 542 [open_as_tab_checkbox sizeToFit]; | |
| 543 | |
| 544 base::scoped_nsobject<NSTextField> app_title( | |
| 545 [[NSTextField alloc] initWithFrame:kAppTitleTextFieldSize]); | |
| 546 NSString* original_title = SysUTF16ToNSString(web_app_info.title); | |
| 547 [[app_title cell] setWraps:NO]; | |
| 548 [[app_title cell] setScrollable:YES]; | |
| 549 [app_title setStringValue:original_title]; | |
| 550 | |
| 551 base::scoped_nsobject<NSView> view( | |
| 552 [[NSView alloc] initWithFrame:kBookmarkAppBubbleAccessoryViewSize]); | |
| 553 [view addSubview:open_as_tab_checkbox]; | |
| 554 [view addSubview:app_title]; | |
| 555 [alert setAccessoryView:view]; | |
| 556 | |
| 557 // Find the image with target size. | |
| 558 // Assumes that the icons are sorted in ascending order of size. | |
| 559 if (!web_app_info.icons.empty()) { | |
| 560 const WebApplicationInfo::IconInfo& info = web_app_info.icons.back(); | |
| 561 gfx::Image icon_image = gfx::Image::CreateFrom1xBitmap(info.data); | |
| 562 [icon_image.ToNSImage() | |
| 563 setSize:NSMakeSize(kIconPreviewTargetSize, kIconPreviewTargetSize)]; | |
| 564 [alert setIcon:icon_image.ToNSImage()]; | |
| 565 } | |
| 566 | |
| 567 ExtensionService* service = | |
| 568 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
| 569 if ([alert runModal] == NSAlertFirstButtonReturn) { | |
| 570 // Save launch type preferences for later when creating another hosted app. | |
| 571 extensions::LaunchType launch_type = | |
| 572 [open_as_tab_checkbox state] == NSOnState | |
| 573 ? extensions::LAUNCH_TYPE_REGULAR | |
| 574 : extensions::LAUNCH_TYPE_WINDOW; | |
| 575 profile->GetPrefs()->SetInteger( | |
| 576 extensions::pref_names::kBookmarkAppCreationLaunchType, launch_type); | |
| 577 extensions::SetLaunchType(service, extension_id, launch_type); | |
| 578 | |
| 579 // Update name of app. | |
| 580 NSString* new_title = [app_title stringValue]; | |
| 581 if (![original_title isEqualToString:new_title]) { | |
| 582 WebApplicationInfo new_web_app_info(web_app_info); | |
| 583 new_web_app_info.title = base::SysNSStringToUTF16(new_title); | |
| 584 extensions::CreateOrUpdateBookmarkApp(service, new_web_app_info); | |
| 585 } | |
| 586 | |
| 587 extensions::ExtensionRegistry* registry = | |
| 588 extensions::ExtensionRegistry::Get(profile); | |
| 589 const extensions::Extension* app = registry->GetExtensionById( | |
| 590 extension_id, extensions::ExtensionRegistry::ENABLED); | |
| 591 | |
| 592 web_app::RevealAppShimInFinderForApp(profile, app); | |
| 593 } else { | |
| 594 service->UninstallExtension(extension_id, | |
| 595 extensions::UNINSTALL_REASON_INSTALL_CANCELED, | |
| 596 base::Bind(&base::DoNothing), NULL); | |
| 597 } | |
| 501 } | 598 } |
| 502 | 599 |
| 503 void BrowserWindowCocoa::ShowTranslateBubble( | 600 void BrowserWindowCocoa::ShowTranslateBubble( |
| 504 content::WebContents* contents, | 601 content::WebContents* contents, |
| 505 translate::TranslateStep step, | 602 translate::TranslateStep step, |
| 506 translate::TranslateErrors::Type error_type, | 603 translate::TranslateErrors::Type error_type, |
| 507 bool is_user_gesture) { | 604 bool is_user_gesture) { |
| 508 ChromeTranslateClient* chrome_translate_client = | 605 ChromeTranslateClient* chrome_translate_client = |
| 509 ChromeTranslateClient::FromWebContents(contents); | 606 ChromeTranslateClient::FromWebContents(contents); |
| 510 translate::LanguageState& language_state = | 607 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) | 803 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) |
| 707 return 0; | 804 return 0; |
| 708 return 40; | 805 return 40; |
| 709 } | 806 } |
| 710 | 807 |
| 711 void BrowserWindowCocoa::ExecuteExtensionCommand( | 808 void BrowserWindowCocoa::ExecuteExtensionCommand( |
| 712 const extensions::Extension* extension, | 809 const extensions::Extension* extension, |
| 713 const extensions::Command& command) { | 810 const extensions::Command& command) { |
| 714 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; | 811 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; |
| 715 } | 812 } |
| OLD | NEW |