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

Side by Side Diff: chrome/browser/web_applications/web_app_mac.mm

Issue 1972843002: MacViews GN: Get chrome compiling with mac_views_browser = true (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase (patch failure due to r393625) Created 4 years, 7 months 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 #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 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "base/strings/sys_string_conversions.h" 31 #include "base/strings/sys_string_conversions.h"
32 #include "base/strings/utf_string_conversions.h" 32 #include "base/strings/utf_string_conversions.h"
33 #include "base/version.h" 33 #include "base/version.h"
34 #include "chrome/browser/browser_process.h" 34 #include "chrome/browser/browser_process.h"
35 #include "chrome/browser/extensions/extension_ui_util.h" 35 #include "chrome/browser/extensions/extension_ui_util.h"
36 #import "chrome/browser/mac/dock.h" 36 #import "chrome/browser/mac/dock.h"
37 #include "chrome/browser/profiles/profile.h" 37 #include "chrome/browser/profiles/profile.h"
38 #include "chrome/browser/profiles/profile_manager.h" 38 #include "chrome/browser/profiles/profile_manager.h"
39 #include "chrome/browser/shell_integration.h" 39 #include "chrome/browser/shell_integration.h"
40 #include "chrome/browser/ui/app_list/app_list_service.h" 40 #include "chrome/browser/ui/app_list/app_list_service.h"
41 #include "chrome/browser/ui/cocoa/key_equivalent_constants.h"
42 #include "chrome/common/channel_info.h" 41 #include "chrome/common/channel_info.h"
43 #include "chrome/common/chrome_constants.h" 42 #include "chrome/common/chrome_constants.h"
44 #include "chrome/common/chrome_paths.h" 43 #include "chrome/common/chrome_paths.h"
45 #include "chrome/common/chrome_switches.h" 44 #include "chrome/common/chrome_switches.h"
46 #import "chrome/common/mac/app_mode_common.h" 45 #import "chrome/common/mac/app_mode_common.h"
47 #include "chrome/grit/generated_resources.h" 46 #include "chrome/grit/generated_resources.h"
48 #include "components/crx_file/id_util.h" 47 #include "components/crx_file/id_util.h"
49 #include "components/version_info/version_info.h" 48 #include "components/version_info/version_info.h"
50 #include "content/public/browser/browser_thread.h" 49 #include "content/public/browser/browser_thread.h"
51 #include "content/public/common/content_switches.h" 50 #include "content/public/common/content_switches.h"
52 #include "extensions/browser/extension_registry.h" 51 #include "extensions/browser/extension_registry.h"
53 #include "extensions/common/extension.h" 52 #include "extensions/common/extension.h"
54 #include "grit/chrome_unscaled_resources.h" 53 #include "grit/chrome_unscaled_resources.h"
55 #include "grit/components_strings.h"
56 #import "skia/ext/skia_utils_mac.h" 54 #import "skia/ext/skia_utils_mac.h"
57 #include "third_party/skia/include/core/SkBitmap.h" 55 #include "third_party/skia/include/core/SkBitmap.h"
58 #include "third_party/skia/include/core/SkColor.h" 56 #include "third_party/skia/include/core/SkColor.h"
59 #include "ui/base/l10n/l10n_util.h" 57 #include "ui/base/l10n/l10n_util.h"
60 #import "ui/base/l10n/l10n_util_mac.h"
61 #include "ui/base/resource/resource_bundle.h" 58 #include "ui/base/resource/resource_bundle.h"
62 #include "ui/gfx/image/image_family.h" 59 #include "ui/gfx/image/image_family.h"
63 60
64 bool g_app_shims_allow_update_and_launch_in_tests = false; 61 bool g_app_shims_allow_update_and_launch_in_tests = false;
65 62
66 namespace { 63 namespace {
67 64
68 // Launch Services Key to run as an agent app, which doesn't launch in the dock. 65 // Launch Services Key to run as an agent app, which doesn't launch in the dock.
69 NSString* const kLSUIElement = @"LSUIElement"; 66 NSString* const kLSUIElement = @"LSUIElement";
70 67
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 if (extension->location() == extensions::Manifest::COMPONENT || 625 if (extension->location() == extensions::Manifest::COMPONENT ||
629 !extensions::ui_util::CanDisplayInAppLauncher(extension, profile)) { 626 !extensions::ui_util::CanDisplayInAppLauncher(extension, profile)) {
630 return false; 627 return false;
631 } 628 }
632 629
633 return extension->is_app(); 630 return extension->is_app();
634 } 631 }
635 632
636 } // namespace 633 } // namespace
637 634
638 @interface CrCreateAppShortcutCheckboxObserver : NSObject {
639 @private
640 NSButton* checkbox_;
641 NSButton* continueButton_;
642 }
643
644 - (id)initWithCheckbox:(NSButton*)checkbox
645 continueButton:(NSButton*)continueButton;
646 - (void)startObserving;
647 - (void)stopObserving;
648 @end
649
650 @implementation CrCreateAppShortcutCheckboxObserver
651
652 - (id)initWithCheckbox:(NSButton*)checkbox
653 continueButton:(NSButton*)continueButton {
654 if ((self = [super init])) {
655 checkbox_ = checkbox;
656 continueButton_ = continueButton;
657 }
658 return self;
659 }
660
661 - (void)startObserving {
662 [checkbox_ addObserver:self
663 forKeyPath:@"cell.state"
664 options:0
665 context:nil];
666 }
667
668 - (void)stopObserving {
669 [checkbox_ removeObserver:self
670 forKeyPath:@"cell.state"];
671 }
672
673 - (void)observeValueForKeyPath:(NSString*)keyPath
674 ofObject:(id)object
675 change:(NSDictionary*)change
676 context:(void*)context {
677 [continueButton_ setEnabled:([checkbox_ state] == NSOnState)];
678 }
679
680 @end
681
682 namespace web_app { 635 namespace web_app {
683 636
684 WebAppShortcutCreator::WebAppShortcutCreator( 637 WebAppShortcutCreator::WebAppShortcutCreator(
685 const base::FilePath& app_data_dir, 638 const base::FilePath& app_data_dir,
686 const ShortcutInfo* shortcut_info, 639 const ShortcutInfo* shortcut_info,
687 const extensions::FileHandlersInfo& file_handlers_info) 640 const extensions::FileHandlersInfo& file_handlers_info)
688 : app_data_dir_(app_data_dir), 641 : app_data_dir_(app_data_dir),
689 info_(shortcut_info), 642 info_(shortcut_info),
690 file_handlers_info_(file_handlers_info) { 643 file_handlers_info_(file_handlers_info) {
691 DCHECK(shortcut_info); 644 DCHECK(shortcut_info);
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 1091
1139 base::PostTaskAndReplyWithResult( 1092 base::PostTaskAndReplyWithResult(
1140 content::BrowserThread::GetBlockingPool(), 1093 content::BrowserThread::GetBlockingPool(),
1141 FROM_HERE, 1094 FROM_HERE,
1142 base::Bind(&RecordAppShimErrorAndBuildShortcutInfo, 1095 base::Bind(&RecordAppShimErrorAndBuildShortcutInfo,
1143 command_line.GetSwitchValuePath(app_mode::kAppShimError)), 1096 command_line.GetSwitchValuePath(app_mode::kAppShimError)),
1144 base::Bind(&RebuildAppAndLaunch)); 1097 base::Bind(&RebuildAppAndLaunch));
1145 return true; 1098 return true;
1146 } 1099 }
1147 1100
1148 // Called when the app's ShortcutInfo (with icon) is loaded when creating app
1149 // shortcuts.
1150 void CreateAppShortcutInfoLoaded(
1151 Profile* profile,
1152 const extensions::Extension* app,
1153 const base::Callback<void(bool)>& close_callback,
1154 std::unique_ptr<ShortcutInfo> shortcut_info) {
1155 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]);
1156
1157 NSButton* continue_button = [alert
1158 addButtonWithTitle:l10n_util::GetNSString(IDS_CREATE_SHORTCUTS_COMMIT)];
1159 [continue_button setKeyEquivalent:kKeyEquivalentReturn];
1160
1161 NSButton* cancel_button =
1162 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_CANCEL)];
1163 [cancel_button setKeyEquivalent:kKeyEquivalentEscape];
1164
1165 [alert setMessageText:l10n_util::GetNSString(IDS_CREATE_SHORTCUTS_LABEL)];
1166 [alert setAlertStyle:NSInformationalAlertStyle];
1167
1168 base::scoped_nsobject<NSButton> application_folder_checkbox(
1169 [[NSButton alloc] initWithFrame:NSZeroRect]);
1170 [application_folder_checkbox setButtonType:NSSwitchButton];
1171 [application_folder_checkbox
1172 setTitle:l10n_util::GetNSString(IDS_CREATE_SHORTCUTS_APP_FOLDER_CHKBOX)];
1173 [application_folder_checkbox setState:NSOnState];
1174 [application_folder_checkbox sizeToFit];
1175
1176 base::scoped_nsobject<CrCreateAppShortcutCheckboxObserver> checkbox_observer(
1177 [[CrCreateAppShortcutCheckboxObserver alloc]
1178 initWithCheckbox:application_folder_checkbox
1179 continueButton:continue_button]);
1180 [checkbox_observer startObserving];
1181
1182 [alert setAccessoryView:application_folder_checkbox];
1183
1184 const int kIconPreviewSizePixels = 128;
1185 const int kIconPreviewTargetSize = 64;
1186 const gfx::Image* icon = shortcut_info->favicon.GetBest(
1187 kIconPreviewSizePixels, kIconPreviewSizePixels);
1188
1189 if (icon && !icon->IsEmpty()) {
1190 NSImage* icon_image = icon->ToNSImage();
1191 [icon_image
1192 setSize:NSMakeSize(kIconPreviewTargetSize, kIconPreviewTargetSize)];
1193 [alert setIcon:icon_image];
1194 }
1195
1196 bool dialog_accepted = false;
1197 if ([alert runModal] == NSAlertFirstButtonReturn &&
1198 [application_folder_checkbox state] == NSOnState) {
1199 dialog_accepted = true;
1200 CreateShortcuts(
1201 SHORTCUT_CREATION_BY_USER, ShortcutLocations(), profile, app);
1202 }
1203
1204 [checkbox_observer stopObserving];
1205
1206 if (!close_callback.is_null())
1207 close_callback.Run(dialog_accepted);
1208 }
1209
1210 void UpdateShortcutsForAllApps(Profile* profile, 1101 void UpdateShortcutsForAllApps(Profile* profile,
1211 const base::Closure& callback) { 1102 const base::Closure& callback) {
1212 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 1103 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1213 1104
1214 extensions::ExtensionRegistry* registry = 1105 extensions::ExtensionRegistry* registry =
1215 extensions::ExtensionRegistry::Get(profile); 1106 extensions::ExtensionRegistry::Get(profile);
1216 if (!registry) 1107 if (!registry)
1217 return; 1108 return;
1218 1109
1219 scoped_refptr<Latch> latch = new Latch(callback); 1110 scoped_refptr<Latch> latch = new Latch(callback);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 BuildShortcutInfoFromBundle(*it); 1176 BuildShortcutInfoFromBundle(*it);
1286 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info.get(), 1177 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info.get(),
1287 extensions::FileHandlersInfo()); 1178 extensions::FileHandlersInfo());
1288 shortcut_creator.DeleteShortcuts(); 1179 shortcut_creator.DeleteShortcuts();
1289 } 1180 }
1290 } 1181 }
1291 1182
1292 } // namespace internals 1183 } // namespace internals
1293 1184
1294 } // namespace web_app 1185 } // namespace web_app
1295
1296 namespace chrome {
1297
1298 void ShowCreateChromeAppShortcutsDialog(
1299 gfx::NativeWindow /*parent_window*/,
1300 Profile* profile,
1301 const extensions::Extension* app,
1302 const base::Callback<void(bool)>& close_callback) {
1303 web_app::GetShortcutInfoForApp(
1304 app,
1305 profile,
1306 base::Bind(&web_app::CreateAppShortcutInfoLoaded,
1307 profile,
1308 app,
1309 close_callback));
1310 }
1311
1312 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/immersive_mode_controller_factory_mac.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698