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

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: 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
74 using content::BrowserThread;
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
71 NSPoint GetPointForBubble(content::WebContents* web_contents, 81 NSPoint GetPointForBubble(content::WebContents* web_contents,
72 int x_offset, 82 int x_offset,
73 int y_offset) { 83 int y_offset) {
74 NSView* view = web_contents->GetNativeView(); 84 NSView* view = web_contents->GetNativeView();
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 500
491 void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url, 501 void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url,
492 bool already_bookmarked) { 502 bool already_bookmarked) {
493 [controller_ showBookmarkBubbleForURL:url 503 [controller_ showBookmarkBubbleForURL:url
494 alreadyBookmarked:(already_bookmarked ? YES : NO)]; 504 alreadyBookmarked:(already_bookmarked ? YES : NO)];
495 } 505 }
496 506
497 void BrowserWindowCocoa::ShowBookmarkAppBubble( 507 void BrowserWindowCocoa::ShowBookmarkAppBubble(
498 const WebApplicationInfo& web_app_info, 508 const WebApplicationInfo& web_app_info,
499 const std::string& extension_id) { 509 const std::string& extension_id) {
500 NOTIMPLEMENTED(); 510 Profile* profile = browser_->profile();
511
512 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]);
513 [alert setMessageText:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_TITLE)];
514 [alert setAlertStyle:NSInformationalAlertStyle];
515
516 NSButton* continue_button = [alert
517 addButtonWithTitle:l10n_util::GetNSString(IDS_OK)];
518 [continue_button setKeyEquivalent:@"\r"];
519 NSButton* cancel_button = [alert
520 addButtonWithTitle:l10n_util::GetNSString(IDS_CANCEL)];
521 [cancel_button setKeyEquivalent:@"\033"];
522
523 base::scoped_nsobject<NSButton> open_as_tab_checkbox(
524 [[NSButton alloc] initWithFrame:NSZeroRect]);
525 [open_as_tab_checkbox setButtonType:NSSwitchButton];
526 [open_as_tab_checkbox
527 setTitle:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_TAB)];
528 [open_as_tab_checkbox setState:profile->GetPrefs()->GetInteger(
529 extensions::pref_names::kBookmarkAppCreationLaunchType)
530 == extensions::LAUNCH_TYPE_REGULAR];
531 [open_as_tab_checkbox sizeToFit];
532
533 NSTextField* app_title = [[NSTextField alloc]
534 initWithFrame:NSMakeRect(0,24,200,22)];
jackhou1 2014/12/03 05:12:05 Constants need to be declared at the top of the fi
mitchellj 2014/12/04 04:53:53 Done.
535 NSString* original_title = SysUTF16ToNSString(web_app_info.title);
536 [app_title.cell setWraps:NO];
jackhou1 2014/12/03 05:12:05 It should probably be a single line field.
mitchellj 2014/12/04 04:53:53 The parameter setWraps:NO makes sure that no wrapp
537 [app_title.cell setScrollable:YES];
538 [app_title setStringValue:original_title];
539
540 NSView* view = [[NSView alloc] initWithFrame:NSMakeRect(0,0,200,46)];
541 [view addSubview:open_as_tab_checkbox];
542 [view addSubview:app_title];
543 [alert setAccessoryView:view];
544
545 const int kIconPreviewTargetSize = 64;
546
547 // Find the image with target size.
548 // Assumes that the icons are sorted in ascending order of size.
549 WebApplicationInfo::IconInfo info =
550 web_app_info.icons[web_app_info.icons.size()-1];
551 if (info.width >= kIconPreviewTargetSize &&
552 info.height >= kIconPreviewTargetSize) {
553 NSImage* icon_image =
554 gfx::Image::CreateFrom1xBitmap(info.data).ToNSImage();
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
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 : 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 =
583 registry->GetExtensionById(extension_id,
584 extensions::ExtensionRegistry::ENABLED);
585
586 BrowserThread::PostTask(
587 BrowserThread::FILE,
588 FROM_HERE,
589 base::Bind(&web_app::internals::RevealAppShimInFinderForApp,
590 profile, app->path()));
591 } else {
592 service->UninstallExtension(extension_id,
593 extensions::UNINSTALL_REASON_INSTALL_CANCELED,
594 base::Bind(&base::DoNothing), NULL);
595 }
501 } 596 }
502 597
503 void BrowserWindowCocoa::ShowTranslateBubble( 598 void BrowserWindowCocoa::ShowTranslateBubble(
504 content::WebContents* contents, 599 content::WebContents* contents,
505 translate::TranslateStep step, 600 translate::TranslateStep step,
506 translate::TranslateErrors::Type error_type, 601 translate::TranslateErrors::Type error_type,
507 bool is_user_gesture) { 602 bool is_user_gesture) {
508 ChromeTranslateClient* chrome_translate_client = 603 ChromeTranslateClient* chrome_translate_client =
509 ChromeTranslateClient::FromWebContents(contents); 604 ChromeTranslateClient::FromWebContents(contents);
510 translate::LanguageState& language_state = 605 translate::LanguageState& language_state =
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) 801 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED)
707 return 0; 802 return 0;
708 return 40; 803 return 40;
709 } 804 }
710 805
711 void BrowserWindowCocoa::ExecuteExtensionCommand( 806 void BrowserWindowCocoa::ExecuteExtensionCommand(
712 const extensions::Extension* extension, 807 const extensions::Extension* extension,
713 const extensions::Command& command) { 808 const extensions::Command& command) {
714 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; 809 [cocoa_controller() executeExtensionCommand:extension->id() command:command];
715 } 810 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698