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" |
(...skipping 12 matching lines...) Expand all Loading... | |
40 #include "chrome/browser/ui/cocoa/restart_browser.h" | 43 #include "chrome/browser/ui/cocoa/restart_browser.h" |
41 #include "chrome/browser/ui/cocoa/status_bubble_mac.h" | 44 #include "chrome/browser/ui/cocoa/status_bubble_mac.h" |
42 #include "chrome/browser/ui/cocoa/task_manager_mac.h" | 45 #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
43 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 46 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
44 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" | 47 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" |
45 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro ller.h" | 48 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro ller.h" |
46 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 49 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
47 #include "chrome/browser/ui/search/search_model.h" | 50 #include "chrome/browser/ui/search/search_model.h" |
48 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 51 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
49 #include "chrome/browser/web_applications/web_app.h" | 52 #include "chrome/browser/web_applications/web_app.h" |
53 #include "chrome/browser/web_applications/web_app_mac.h" | |
50 #include "chrome/common/chrome_switches.h" | 54 #include "chrome/common/chrome_switches.h" |
51 #include "chrome/common/pref_names.h" | 55 #include "chrome/common/pref_names.h" |
56 #include "chrome/grit/generated_resources.h" | |
52 #include "components/translate/core/browser/language_state.h" | 57 #include "components/translate/core/browser/language_state.h" |
53 #include "content/public/browser/native_web_keyboard_event.h" | 58 #include "content/public/browser/native_web_keyboard_event.h" |
54 #include "content/public/browser/notification_details.h" | 59 #include "content/public/browser/notification_details.h" |
55 #include "content/public/browser/notification_source.h" | 60 #include "content/public/browser/notification_source.h" |
56 #include "content/public/browser/web_contents.h" | 61 #include "content/public/browser/web_contents.h" |
62 #include "extensions/common/constants.h" | |
63 #include "extensions/browser/extension_system.h" | |
64 #include "extensions/browser/extension_registry.h" | |
65 #include "extensions/browser/pref_names.h" | |
57 #include "ui/base/l10n/l10n_util_mac.h" | 66 #include "ui/base/l10n/l10n_util_mac.h" |
58 #include "ui/gfx/rect.h" | 67 #include "ui/gfx/rect.h" |
59 | 68 |
60 #if defined(ENABLE_ONE_CLICK_SIGNIN) | 69 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
61 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" | 70 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" |
62 #import "chrome/browser/ui/cocoa/one_click_signin_dialog_controller.h" | 71 #import "chrome/browser/ui/cocoa/one_click_signin_dialog_controller.h" |
63 #endif | 72 #endif |
64 | 73 |
65 using content::NativeWebKeyboardEvent; | 74 using content::NativeWebKeyboardEvent; |
66 using content::SSLStatus; | 75 using content::SSLStatus; |
67 using content::WebContents; | 76 using content::WebContents; |
68 | 77 |
69 namespace { | 78 namespace { |
70 | 79 |
80 const NSRect kAppTitleTextFieldSize = {{0, 24}, {200, 22}}; | |
Robert Sesek
2014/12/05 18:30:37
Where do these constants come from? And can you no
mitchellj
2014/12/09 01:39:52
These are just UI constants. I've extracted the co
| |
81 const NSRect kBookmarkAppBubbleAccessoryViewSize = {{0, 0}, {200, 46}}; | |
82 const int kIconPreviewTargetSize = 64; | |
83 | |
71 NSPoint GetPointForBubble(content::WebContents* web_contents, | 84 NSPoint GetPointForBubble(content::WebContents* web_contents, |
72 int x_offset, | 85 int x_offset, |
73 int y_offset) { | 86 int y_offset) { |
74 NSView* view = web_contents->GetNativeView(); | 87 NSView* view = web_contents->GetNativeView(); |
75 NSRect bounds = [view bounds]; | 88 NSRect bounds = [view bounds]; |
76 NSPoint point; | 89 NSPoint point; |
77 point.x = NSMinX(bounds) + x_offset; | 90 point.x = NSMinX(bounds) + x_offset; |
78 // The view's origin is at the bottom but |rect|'s origin is at the top. | 91 // The view's origin is at the bottom but |rect|'s origin is at the top. |
79 point.y = NSMaxY(bounds) - y_offset; | 92 point.y = NSMaxY(bounds) - y_offset; |
80 point = [view convertPoint:point toView:nil]; | 93 point = [view convertPoint:point toView:nil]; |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 | 503 |
491 void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url, | 504 void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url, |
492 bool already_bookmarked) { | 505 bool already_bookmarked) { |
493 [controller_ showBookmarkBubbleForURL:url | 506 [controller_ showBookmarkBubbleForURL:url |
494 alreadyBookmarked:(already_bookmarked ? YES : NO)]; | 507 alreadyBookmarked:(already_bookmarked ? YES : NO)]; |
495 } | 508 } |
496 | 509 |
497 void BrowserWindowCocoa::ShowBookmarkAppBubble( | 510 void BrowserWindowCocoa::ShowBookmarkAppBubble( |
498 const WebApplicationInfo& web_app_info, | 511 const WebApplicationInfo& web_app_info, |
499 const std::string& extension_id) { | 512 const std::string& extension_id) { |
500 NOTIMPLEMENTED(); | 513 Profile* profile = browser_->profile(); |
514 | |
515 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); | |
516 [alert setMessageText:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_TITLE)]; | |
517 [alert setAlertStyle:NSInformationalAlertStyle]; | |
518 | |
519 NSButton* continue_button = | |
520 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_OK)]; | |
521 [continue_button setKeyEquivalent:@"\r"]; | |
Robert Sesek
2014/12/05 18:30:37
Use constants defined in chrome/browser/ui/cocoa/k
mitchellj
2014/12/09 01:39:52
Done.
| |
522 NSButton* cancel_button = | |
523 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_CANCEL)]; | |
524 [cancel_button setKeyEquivalent:@"\033"]; | |
525 | |
526 base::scoped_nsobject<NSButton> open_as_tab_checkbox( | |
527 [[NSButton alloc] initWithFrame:NSZeroRect]); | |
528 [open_as_tab_checkbox setButtonType:NSSwitchButton]; | |
529 [open_as_tab_checkbox | |
530 setTitle:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_TAB)]; | |
531 [open_as_tab_checkbox | |
532 setState:profile->GetPrefs()->GetInteger( | |
Robert Sesek
2014/12/05 18:30:37
Move setState: back on the previous line and then
mitchellj
2014/12/09 01:39:52
Done.
| |
533 extensions::pref_names::kBookmarkAppCreationLaunchType) == | |
534 extensions::LAUNCH_TYPE_REGULAR]; | |
535 [open_as_tab_checkbox sizeToFit]; | |
536 | |
537 NSTextField* app_title = | |
Robert Sesek
2014/12/05 18:30:37
This is leaked.
mitchellj
2014/12/09 01:39:52
Done.
| |
538 [[NSTextField alloc] initWithFrame:kAppTitleTextFieldSize]; | |
539 NSString* original_title = SysUTF16ToNSString(web_app_info.title); | |
540 [app_title.cell setWraps:NO]; | |
541 [app_title.cell setScrollable:YES]; | |
542 [app_title setStringValue:original_title]; | |
543 | |
544 NSView* view = | |
Robert Sesek
2014/12/05 18:30:37
This is leaked.
mitchellj
2014/12/09 01:39:52
Done.
| |
545 [[NSView alloc] initWithFrame:kBookmarkAppBubbleAccessoryViewSize]; | |
546 [view addSubview:open_as_tab_checkbox]; | |
547 [view addSubview:app_title]; | |
548 [alert setAccessoryView:view]; | |
549 | |
550 // Find the image with target size. | |
551 // Assumes that the icons are sorted in ascending order of size. | |
552 if (!web_app_info.icons.empty()) { | |
553 WebApplicationInfo::IconInfo& info = web_app_info.icons.back(); | |
554 NSImage* icon_image = gfx::Image::CreateFrom1xBitmap(info.data).ToNSImage(); | |
Robert Sesek
2014/12/05 18:30:37
icon_image is technically being used-after-free. g
mitchellj
2014/12/09 01:39:52
Done.
| |
555 [icon_image | |
556 setSize:NSMakeSize(kIconPreviewTargetSize, kIconPreviewTargetSize)]; | |
557 [alert setIcon:icon_image]; | |
558 } | |
559 | |
560 ExtensionService* service = | |
561 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
562 if ([alert runModal] == NSAlertFirstButtonReturn) { | |
563 // Save launch type preferences for later when creating another hosted app. | |
564 extensions::LaunchType launch_type = | |
565 [open_as_tab_checkbox state] == NSOnState | |
566 ? extensions::LAUNCH_TYPE_REGULAR | |
567 : extensions::LAUNCH_TYPE_WINDOW; | |
568 profile->GetPrefs()->SetInteger( | |
569 extensions::pref_names::kBookmarkAppCreationLaunchType, launch_type); | |
570 extensions::SetLaunchType(service, extension_id, launch_type); | |
571 | |
572 // Update name of app. | |
573 NSString* new_title = [app_title stringValue]; | |
574 if (![original_title isEqualToString: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 | |
580 extensions::ExtensionRegistry* registry = | |
581 extensions::ExtensionRegistry::Get(profile); | |
582 const extensions::Extension* app = registry->GetExtensionById( | |
583 extension_id, extensions::ExtensionRegistry::ENABLED); | |
584 | |
585 web_app::RevealAppShimInFinderForApp(profile, app); | |
586 } else { | |
587 service->UninstallExtension(extension_id, | |
588 extensions::UNINSTALL_REASON_INSTALL_CANCELED, | |
589 base::Bind(&base::DoNothing), NULL); | |
590 } | |
501 } | 591 } |
502 | 592 |
503 void BrowserWindowCocoa::ShowTranslateBubble( | 593 void BrowserWindowCocoa::ShowTranslateBubble( |
504 content::WebContents* contents, | 594 content::WebContents* contents, |
505 translate::TranslateStep step, | 595 translate::TranslateStep step, |
506 translate::TranslateErrors::Type error_type, | 596 translate::TranslateErrors::Type error_type, |
507 bool is_user_gesture) { | 597 bool is_user_gesture) { |
508 ChromeTranslateClient* chrome_translate_client = | 598 ChromeTranslateClient* chrome_translate_client = |
509 ChromeTranslateClient::FromWebContents(contents); | 599 ChromeTranslateClient::FromWebContents(contents); |
510 translate::LanguageState& language_state = | 600 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) | 796 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) |
707 return 0; | 797 return 0; |
708 return 40; | 798 return 40; |
709 } | 799 } |
710 | 800 |
711 void BrowserWindowCocoa::ExecuteExtensionCommand( | 801 void BrowserWindowCocoa::ExecuteExtensionCommand( |
712 const extensions::Extension* extension, | 802 const extensions::Extension* extension, |
713 const extensions::Command& command) { | 803 const extensions::Command& command) { |
714 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; | 804 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; |
715 } | 805 } |
OLD | NEW |