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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_cocoa.mm

Issue 777543002: Create hosted app shims on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed further comments and refactored code Created 6 years 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 #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
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}};
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
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"];
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(
533 extensions::pref_names::kBookmarkAppCreationLaunchType) ==
534 extensions::LAUNCH_TYPE_REGULAR];
535 [open_as_tab_checkbox sizeToFit];
536
537 NSTextField* app_title =
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 =
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 =
554 web_app_info.icons[web_app_info.icons.size() - 1];
jackhou1 2014/12/05 01:52:01 web_app_info.icons.back() gives you the last item.
mitchellj 2014/12/05 05:07:48 Done.
555 NSImage* icon_image = gfx::Image::CreateFrom1xBitmap(info.data).ToNSImage();
556 [icon_image
557 setSize:NSMakeSize(kIconPreviewTargetSize, kIconPreviewTargetSize)];
558 [alert setIcon:icon_image];
559 }
560
561 ExtensionService* service =
562 extensions::ExtensionSystem::Get(profile)->extension_service();
563 if ([alert runModal] == NSAlertFirstButtonReturn) {
564 // Save launch type preferences for later when creating another hosted app.
565 extensions::LaunchType launch_type =
566 [open_as_tab_checkbox state] == NSOnState
567 ? extensions::LAUNCH_TYPE_REGULAR
568 : extensions::LAUNCH_TYPE_WINDOW;
569 profile->GetPrefs()->SetInteger(
570 extensions::pref_names::kBookmarkAppCreationLaunchType, launch_type);
571 extensions::SetLaunchType(service, extension_id, launch_type);
572
573 // Update name of app.
574 NSString* new_title = [app_title stringValue];
575 if (![original_title isEqualToString:new_title]) {
576 WebApplicationInfo new_web_app_info(web_app_info);
577 new_web_app_info.title = base::SysNSStringToUTF16(new_title);
578 extensions::CreateOrUpdateBookmarkApp(service, new_web_app_info);
579 }
580
581 extensions::ExtensionRegistry* registry =
582 extensions::ExtensionRegistry::Get(profile);
583 const extensions::Extension* app = registry->GetExtensionById(
584 extension_id, extensions::ExtensionRegistry::ENABLED);
585
586 web_app::RevealAppShimInFinderForApp(profile, app);
587 } else {
588 service->UninstallExtension(extension_id,
589 extensions::UNINSTALL_REASON_INSTALL_CANCELED,
590 base::Bind(&base::DoNothing), NULL);
591 }
501 } 592 }
502 593
503 void BrowserWindowCocoa::ShowTranslateBubble( 594 void BrowserWindowCocoa::ShowTranslateBubble(
504 content::WebContents* contents, 595 content::WebContents* contents,
505 translate::TranslateStep step, 596 translate::TranslateStep step,
506 translate::TranslateErrors::Type error_type, 597 translate::TranslateErrors::Type error_type,
507 bool is_user_gesture) { 598 bool is_user_gesture) {
508 ChromeTranslateClient* chrome_translate_client = 599 ChromeTranslateClient* chrome_translate_client =
509 ChromeTranslateClient::FromWebContents(contents); 600 ChromeTranslateClient::FromWebContents(contents);
510 translate::LanguageState& language_state = 601 translate::LanguageState& language_state =
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) 797 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED)
707 return 0; 798 return 0;
708 return 40; 799 return 40;
709 } 800 }
710 801
711 void BrowserWindowCocoa::ExecuteExtensionCommand( 802 void BrowserWindowCocoa::ExecuteExtensionCommand(
712 const extensions::Extension* extension, 803 const extensions::Extension* extension,
713 const extensions::Command& command) { 804 const extensions::Command& command) {
714 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; 805 [cocoa_controller() executeExtensionCommand:extension->id() command:command];
715 } 806 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698