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

Side by Side Diff: chrome/service/chrome_service_application_mac.mm

Issue 12178030: [mac] Delete app shortcuts on app uninstall. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix rebase Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/web_applications/web_app_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/service/chrome_service_application_mac.h" 5 #import "chrome/service/chrome_service_application_mac.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/mac/mac_logging.h" 8 #include "base/mac/mac_logging.h"
9 #include "base/sys_string_conversions.h"
9 #import "chrome/common/cloud_print/cloud_print_class_mac.h" 10 #import "chrome/common/cloud_print/cloud_print_class_mac.h"
10 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
11 12
12 @interface ServiceApplication () 13 @interface ServiceApplication ()
13 - (void)setCloudPrintHandler; 14 - (void)setCloudPrintHandler;
14 - (void)submitPrint:(NSAppleEventDescriptor*)event; 15 - (void)submitPrint:(NSAppleEventDescriptor*)event;
15 @end 16 @end
16 17
17 @implementation ServiceApplication 18 @implementation ServiceApplication
18 19
19 - (void)setCloudPrintHandler { 20 - (void)setCloudPrintHandler {
20 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; 21 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
21 [em setEventHandler:self 22 [em setEventHandler:self
22 andSelector:@selector(submitPrint:) 23 andSelector:@selector(submitPrint:)
23 forEventClass:cloud_print::kAECloudPrintClass 24 forEventClass:cloud_print::kAECloudPrintClass
24 andEventID:cloud_print::kAECloudPrintClass]; 25 andEventID:cloud_print::kAECloudPrintClass];
25 } 26 }
26 27
27 // Event handler for Cloud Print Event. Forwards print job received to Chrome, 28 // Event handler for Cloud Print Event. Forwards print job received to Chrome,
28 // launching Chrome if necessary. Used to beat CUPS sandboxing. 29 // launching Chrome if necessary. Used to beat CUPS sandboxing.
29 - (void)submitPrint:(NSAppleEventDescriptor*)event { 30 - (void)submitPrint:(NSAppleEventDescriptor*)event {
30 std::string silent = std::string("--") + switches::kNoStartupWindow; 31 std::string silent = std::string("--") + switches::kNoStartupWindow;
31 // Set up flag so that it can be passed along with the Apple Event. 32 // Set up flag so that it can be passed along with the Apple Event.
32 CFStringRef silentLaunchFlag = 33 base::mac::ScopedCFTypeRef<CFStringRef> silentLaunchFlag(
33 CFStringCreateWithCString(NULL, silent.c_str(), kCFStringEncodingUTF8); 34 base::SysUTF8ToCFStringRef(silent));
34 CFStringRef flags[] = { silentLaunchFlag }; 35 CFStringRef flags[] = { silentLaunchFlag };
35 // Argv array that will be passed. 36 // Argv array that will be passed.
36 CFArrayRef passArgv = 37 base::mac::ScopedCFTypeRef<CFArrayRef> passArgv(
37 CFArrayCreate(NULL, (const void**) flags, 1, &kCFTypeArrayCallBacks); 38 CFArrayCreate(NULL, (const void**) flags, 1, &kCFTypeArrayCallBacks));
38 FSRef ref; 39 FSRef ref;
39 CFURLRef* kDontWantURL = NULL;
40 // Get Chrome's bundle ID. 40 // Get Chrome's bundle ID.
41 std::string bundleID = base::mac::BaseBundleID(); 41 std::string bundleID = base::mac::BaseBundleID();
42 CFStringRef bundleIDCF = 42 base::mac::ScopedCFTypeRef<CFStringRef> bundleIDCF(
43 CFStringCreateWithCString(NULL, bundleID.c_str(), kCFStringEncodingUTF8); 43 base::SysUTF8ToCFStringRef(bundleID));
44 // Use Launch Services to locate Chrome using its bundleID. 44 // Use Launch Services to locate Chrome using its bundleID.
45 OSStatus status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF, 45 OSStatus status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF,
46 NULL, &ref, kDontWantURL); 46 NULL, &ref, NULL);
47 47
48 if (status != noErr) { 48 if (status != noErr) {
49 OSSTATUS_LOG(ERROR, status) << "Failed to make path ref"; 49 OSSTATUS_LOG(ERROR, status) << "Failed to make path ref";
50 return; 50 return;
51 } 51 }
52 // Actually create the Apple Event. 52 // Actually create the Apple Event.
53 NSAppleEventDescriptor* sendEvent = 53 NSAppleEventDescriptor* sendEvent =
54 [NSAppleEventDescriptor 54 [NSAppleEventDescriptor
55 appleEventWithEventClass:cloud_print::kAECloudPrintClass 55 appleEventWithEventClass:cloud_print::kAECloudPrintClass
56 eventID:cloud_print::kAECloudPrintClass 56 eventID:cloud_print::kAECloudPrintClass
57 targetDescriptor:nil 57 targetDescriptor:nil
58 returnID:kAutoGenerateReturnID 58 returnID:kAutoGenerateReturnID
59 transactionID:kAnyTransactionID]; 59 transactionID:kAnyTransactionID];
60 // Pull the parameters out of AppleEvent sent to us and attach them 60 // Pull the parameters out of AppleEvent sent to us and attach them
61 // to our Apple Event. 61 // to our Apple Event.
62 NSAppleEventDescriptor* parameters = 62 NSAppleEventDescriptor* parameters =
63 [event paramDescriptorForKeyword:cloud_print::kAECloudPrintClass]; 63 [event paramDescriptorForKeyword:cloud_print::kAECloudPrintClass];
64 [sendEvent setParamDescriptor:parameters 64 [sendEvent setParamDescriptor:parameters
65 forKeyword:cloud_print::kAECloudPrintClass]; 65 forKeyword:cloud_print::kAECloudPrintClass];
66 LSApplicationParameters params = { 0, 66 LSApplicationParameters params = { 0,
67 kLSLaunchDefaults, 67 kLSLaunchDefaults,
68 &ref, 68 &ref,
69 NULL, 69 NULL,
70 NULL, 70 NULL,
71 passArgv, 71 passArgv,
72 NULL }; 72 NULL };
73 AEDesc* initialEvent = const_cast<AEDesc*> ([sendEvent aeDesc]); 73 AEDesc* initialEvent = const_cast<AEDesc*>([sendEvent aeDesc]);
74 params.initialEvent = static_cast<AppleEvent*> (initialEvent); 74 params.initialEvent = static_cast<AppleEvent*>(initialEvent);
75 // Send the Apple Event Using launch services, launching Chrome if necessary. 75 // Send the Apple Event Using launch services, launching Chrome if necessary.
76 status = LSOpenApplication(&params, NULL); 76 status = LSOpenApplication(&params, NULL);
77 if (status != noErr) { 77 if (status != noErr) {
78 OSSTATUS_LOG(ERROR, status) << "Unable to launch"; 78 OSSTATUS_LOG(ERROR, status) << "Unable to launch";
79 } 79 }
80 } 80 }
81 81
82 82
83 @end 83 @end
84 84
85 85
86 namespace chrome_service_application_mac { 86 namespace chrome_service_application_mac {
87 87
88 void RegisterServiceApp() { 88 void RegisterServiceApp() {
89 ServiceApplication* var = 89 ServiceApplication* var =
90 base::mac::ObjCCastStrict<ServiceApplication>( 90 base::mac::ObjCCastStrict<ServiceApplication>(
91 [ServiceApplication sharedApplication]); 91 [ServiceApplication sharedApplication]);
92 [var setCloudPrintHandler]; 92 [var setCloudPrintHandler];
93 } 93 }
94 94
95 } // namespace chrome_service_application_mac 95 } // namespace chrome_service_application_mac
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698