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 #import "chrome/browser/web_applications/web_app_mac.h" | 5 #import "chrome/browser/web_applications/web_app_mac.h" |
6 | 6 |
7 #import <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 }; | 547 }; |
548 [document_types addObject:type_dictionary]; | 548 [document_types addObject:type_dictionary]; |
549 } | 549 } |
550 | 550 |
551 [plist setObject:document_types | 551 [plist setObject:document_types |
552 forKey:app_mode::kCFBundleDocumentTypesKey]; | 552 forKey:app_mode::kCFBundleDocumentTypesKey]; |
553 } | 553 } |
554 | 554 |
555 } // namespace | 555 } // namespace |
556 | 556 |
557 @interface CrCreateAppShortcutCheckboxObserver : NSObject { | |
558 @private | |
559 NSButton* checkbox_; | |
560 NSButton* continueButton_; | |
561 } | |
562 | |
563 - (id)initWithCheckbox:(NSButton*)checkbox | |
564 withContinueButton:(NSButton*)continueButton; | |
tapted
2014/09/07 23:54:06
nit: withContinueButton -> continueButton
| |
565 - (void)startObserving; | |
566 - (void)stopObserving; | |
567 @end | |
568 | |
569 @implementation CrCreateAppShortcutCheckboxObserver | |
570 | |
571 - (id)initWithCheckbox:(NSButton*)checkbox | |
572 withContinueButton:(NSButton*)continueButton { | |
573 if ((self = [super init])) { | |
574 checkbox_ = checkbox; | |
575 continueButton_ = continueButton; | |
576 } | |
577 return self; | |
578 } | |
579 | |
580 - (void)startObserving { | |
581 [checkbox_ addObserver:self | |
582 forKeyPath:@"cell.state" | |
583 options:0 | |
584 context:nil]; | |
585 } | |
586 | |
587 - (void)stopObserving { | |
588 [checkbox_ removeObserver:self | |
589 forKeyPath:@"cell.state"]; | |
590 } | |
591 | |
592 - (void)observeValueForKeyPath:(NSString*)keyPath | |
593 ofObject:(id)object | |
594 change:(NSDictionary*)change | |
595 context:(void*)context { | |
596 [continueButton_ setEnabled:([checkbox_ state] == NSOnState)]; | |
597 } | |
598 | |
599 @end // @implementation CrCreateAppShortcutCheckboxObserver | |
tapted
2014/09/07 23:54:06
nit: remove comment - it's not typical to add it f
| |
600 | |
557 namespace web_app { | 601 namespace web_app { |
558 | 602 |
559 WebAppShortcutCreator::WebAppShortcutCreator( | 603 WebAppShortcutCreator::WebAppShortcutCreator( |
560 const base::FilePath& app_data_dir, | 604 const base::FilePath& app_data_dir, |
561 const ShortcutInfo& shortcut_info, | 605 const ShortcutInfo& shortcut_info, |
562 const extensions::FileHandlersInfo& file_handlers_info) | 606 const extensions::FileHandlersInfo& file_handlers_info) |
563 : app_data_dir_(app_data_dir), | 607 : app_data_dir_(app_data_dir), |
564 info_(shortcut_info), | 608 info_(shortcut_info), |
565 file_handlers_info_(file_handlers_info) {} | 609 file_handlers_info_(file_handlers_info) {} |
566 | 610 |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
978 [alert setMessageText:l10n_util::GetNSString(IDS_CREATE_SHORTCUTS_LABEL)]; | 1022 [alert setMessageText:l10n_util::GetNSString(IDS_CREATE_SHORTCUTS_LABEL)]; |
979 [alert setAlertStyle:NSInformationalAlertStyle]; | 1023 [alert setAlertStyle:NSInformationalAlertStyle]; |
980 | 1024 |
981 base::scoped_nsobject<NSButton> application_folder_checkbox( | 1025 base::scoped_nsobject<NSButton> application_folder_checkbox( |
982 [[NSButton alloc] initWithFrame:NSZeroRect]); | 1026 [[NSButton alloc] initWithFrame:NSZeroRect]); |
983 [application_folder_checkbox setButtonType:NSSwitchButton]; | 1027 [application_folder_checkbox setButtonType:NSSwitchButton]; |
984 [application_folder_checkbox | 1028 [application_folder_checkbox |
985 setTitle:l10n_util::GetNSString(IDS_CREATE_SHORTCUTS_APP_FOLDER_CHKBOX)]; | 1029 setTitle:l10n_util::GetNSString(IDS_CREATE_SHORTCUTS_APP_FOLDER_CHKBOX)]; |
986 [application_folder_checkbox setState:NSOnState]; | 1030 [application_folder_checkbox setState:NSOnState]; |
987 [application_folder_checkbox sizeToFit]; | 1031 [application_folder_checkbox sizeToFit]; |
1032 | |
1033 base::scoped_nsobject<CrCreateAppShortcutCheckboxObserver> checkbox_observer( | |
1034 [[CrCreateAppShortcutCheckboxObserver alloc] | |
1035 initWithCheckbox:application_folder_checkbox | |
1036 withContinueButton:continue_button]); | |
1037 [checkbox_observer startObserving]; | |
1038 | |
988 [alert setAccessoryView:application_folder_checkbox]; | 1039 [alert setAccessoryView:application_folder_checkbox]; |
989 | 1040 |
990 const int kIconPreviewSizePixels = 128; | 1041 const int kIconPreviewSizePixels = 128; |
991 const int kIconPreviewTargetSize = 64; | 1042 const int kIconPreviewTargetSize = 64; |
992 const gfx::Image* icon = shortcut_info.favicon.GetBest( | 1043 const gfx::Image* icon = shortcut_info.favicon.GetBest( |
993 kIconPreviewSizePixels, kIconPreviewSizePixels); | 1044 kIconPreviewSizePixels, kIconPreviewSizePixels); |
994 | 1045 |
995 if (icon && !icon->IsEmpty()) { | 1046 if (icon && !icon->IsEmpty()) { |
996 NSImage* icon_image = icon->ToNSImage(); | 1047 NSImage* icon_image = icon->ToNSImage(); |
997 [icon_image | 1048 [icon_image |
998 setSize:NSMakeSize(kIconPreviewTargetSize, kIconPreviewTargetSize)]; | 1049 setSize:NSMakeSize(kIconPreviewTargetSize, kIconPreviewTargetSize)]; |
999 [alert setIcon:icon_image]; | 1050 [alert setIcon:icon_image]; |
1000 } | 1051 } |
1001 | 1052 |
1002 bool dialog_accepted = false; | 1053 bool dialog_accepted = false; |
1003 if ([alert runModal] == NSAlertFirstButtonReturn && | 1054 if ([alert runModal] == NSAlertFirstButtonReturn && |
1004 [application_folder_checkbox state] == NSOnState) { | 1055 [application_folder_checkbox state] == NSOnState) { |
1005 dialog_accepted = true; | 1056 dialog_accepted = true; |
1006 CreateShortcuts( | 1057 CreateShortcuts( |
1007 SHORTCUT_CREATION_BY_USER, ShortcutLocations(), profile, app); | 1058 SHORTCUT_CREATION_BY_USER, ShortcutLocations(), profile, app); |
1008 } | 1059 } |
1009 | 1060 |
1061 [checkbox_observer stopObserving]; | |
1062 | |
1010 if (!close_callback.is_null()) | 1063 if (!close_callback.is_null()) |
1011 close_callback.Run(dialog_accepted); | 1064 close_callback.Run(dialog_accepted); |
1012 } | 1065 } |
1013 | 1066 |
1014 void UpdateShortcutsForAllApps(Profile* profile, | 1067 void UpdateShortcutsForAllApps(Profile* profile, |
1015 const base::Closure& callback) { | 1068 const base::Closure& callback) { |
1016 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 1069 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
1017 | 1070 |
1018 extensions::ExtensionRegistry* registry = | 1071 extensions::ExtensionRegistry* registry = |
1019 extensions::ExtensionRegistry::Get(profile); | 1072 extensions::ExtensionRegistry::Get(profile); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1102 web_app::GetShortcutInfoForApp( | 1155 web_app::GetShortcutInfoForApp( |
1103 app, | 1156 app, |
1104 profile, | 1157 profile, |
1105 base::Bind(&web_app::CreateAppShortcutInfoLoaded, | 1158 base::Bind(&web_app::CreateAppShortcutInfoLoaded, |
1106 profile, | 1159 profile, |
1107 app, | 1160 app, |
1108 close_callback)); | 1161 close_callback)); |
1109 } | 1162 } |
1110 | 1163 |
1111 } // namespace chrome | 1164 } // namespace chrome |
OLD | NEW |