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

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: comments 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));
Avi (use Gerrit) 2013/02/05 05:15:49 Yikes. This leaked...
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));
Avi (use Gerrit) 2013/02/05 05:15:49 Did this leak? What does LSApplicationParameters r
jeremya 2013/02/05 05:42:15 I think so. I can't find any documentation saying
38 FSRef ref; 39 FSRef ref;
39 CFURLRef* kDontWantURL = NULL; 40 CFURLRef* kDontWantURL = NULL;
40 // Get Chrome's bundle ID. 41 // Get Chrome's bundle ID.
41 std::string bundleID = base::mac::BaseBundleID(); 42 std::string bundleID = base::mac::BaseBundleID();
42 CFStringRef bundleIDCF = 43 base::mac::ScopedCFTypeRef<CFStringRef> bundleIDCF(
43 CFStringCreateWithCString(NULL, bundleID.c_str(), kCFStringEncodingUTF8); 44 base::SysUTF8ToCFStringRef(bundleID));
Avi (use Gerrit) 2013/02/05 05:15:49 .. and this clearly leaked.
44 // Use Launch Services to locate Chrome using its bundleID. 45 // Use Launch Services to locate Chrome using its bundleID.
45 OSStatus status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF, 46 OSStatus status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF,
46 NULL, &ref, kDontWantURL); 47 NULL, &ref, kDontWantURL);
Avi (use Gerrit) 2013/02/05 05:15:49 Put a null in this last parameter rather than this
jeremya 2013/02/05 05:42:15 Done.
47 48
48 if (status != noErr) { 49 if (status != noErr) {
49 OSSTATUS_LOG(ERROR, status) << "Failed to make path ref"; 50 OSSTATUS_LOG(ERROR, status) << "Failed to make path ref";
50 return; 51 return;
51 } 52 }
52 // Actually create the Apple Event. 53 // Actually create the Apple Event.
53 NSAppleEventDescriptor* sendEvent = 54 NSAppleEventDescriptor* sendEvent =
54 [NSAppleEventDescriptor 55 [NSAppleEventDescriptor
55 appleEventWithEventClass:cloud_print::kAECloudPrintClass 56 appleEventWithEventClass:cloud_print::kAECloudPrintClass
56 eventID:cloud_print::kAECloudPrintClass 57 eventID:cloud_print::kAECloudPrintClass
57 targetDescriptor:nil 58 targetDescriptor:nil
58 returnID:kAutoGenerateReturnID 59 returnID:kAutoGenerateReturnID
59 transactionID:kAnyTransactionID]; 60 transactionID:kAnyTransactionID];
60 // Pull the parameters out of AppleEvent sent to us and attach them 61 // Pull the parameters out of AppleEvent sent to us and attach them
61 // to our Apple Event. 62 // to our Apple Event.
62 NSAppleEventDescriptor* parameters = 63 NSAppleEventDescriptor* parameters =
63 [event paramDescriptorForKeyword:cloud_print::kAECloudPrintClass]; 64 [event paramDescriptorForKeyword:cloud_print::kAECloudPrintClass];
64 [sendEvent setParamDescriptor:parameters 65 [sendEvent setParamDescriptor:parameters
65 forKeyword:cloud_print::kAECloudPrintClass]; 66 forKeyword:cloud_print::kAECloudPrintClass];
66 LSApplicationParameters params = { 0, 67 LSApplicationParameters params = { 0,
67 kLSLaunchDefaults, 68 kLSLaunchDefaults,
68 &ref, 69 &ref,
69 NULL, 70 NULL,
70 NULL, 71 NULL,
71 passArgv, 72 passArgv,
72 NULL }; 73 NULL };
73 AEDesc* initialEvent = const_cast<AEDesc*> ([sendEvent aeDesc]); 74 AEDesc* initialEvent = const_cast<AEDesc*>([sendEvent aeDesc]);
74 params.initialEvent = static_cast<AppleEvent*> (initialEvent); 75 params.initialEvent = static_cast<AppleEvent*>(initialEvent);
75 // Send the Apple Event Using launch services, launching Chrome if necessary. 76 // Send the Apple Event Using launch services, launching Chrome if necessary.
76 status = LSOpenApplication(&params, NULL); 77 status = LSOpenApplication(&params, NULL);
77 if (status != noErr) { 78 if (status != noErr) {
78 OSSTATUS_LOG(ERROR, status) << "Unable to launch"; 79 OSSTATUS_LOG(ERROR, status) << "Unable to launch";
79 } 80 }
80 } 81 }
81 82
82 83
83 @end 84 @end
84 85
85 86
86 namespace chrome_service_application_mac { 87 namespace chrome_service_application_mac {
87 88
88 void RegisterServiceApp() { 89 void RegisterServiceApp() {
89 ServiceApplication* var = 90 ServiceApplication* var =
90 base::mac::ObjCCastStrict<ServiceApplication>( 91 base::mac::ObjCCastStrict<ServiceApplication>(
91 [ServiceApplication sharedApplication]); 92 [ServiceApplication sharedApplication]);
92 [var setCloudPrintHandler]; 93 [var setCloudPrintHandler];
93 } 94 }
94 95
95 } // namespace chrome_service_application_mac 96 } // 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