summaryrefslogtreecommitdiffstats
path: root/chrome/service
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/service')
-rw-r--r--chrome/service/chrome_service_application_mac.h27
-rw-r--r--chrome/service/chrome_service_application_mac.mm101
-rw-r--r--chrome/service/service_ipc_server.cc13
-rw-r--r--chrome/service/service_ipc_server.h2
-rw-r--r--chrome/service/service_main.cc4
-rw-r--r--chrome/service/service_process.cc24
-rw-r--r--chrome/service/service_process.h5
7 files changed, 174 insertions, 2 deletions
diff --git a/chrome/service/chrome_service_application_mac.h b/chrome/service/chrome_service_application_mac.h
new file mode 100644
index 0000000..554a19f
--- /dev/null
+++ b/chrome/service/chrome_service_application_mac.h
@@ -0,0 +1,27 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_SERVICE_CHROME_SERVICE_APPLICATION_MAC_H_
+#define CHROME_SERVICE_CHROME_SERVICE_APPLICATION_MAC_H_
+#pragma once
+
+#ifdef __OBJC__
+
+#import "content/common/chrome_application_mac.h"
+
+// Top level Mac Application for the service process.
+@interface ServiceCrApplication : CrApplication
+
+@end
+
+#endif // __OBJC__
+
+namespace chrome_service_application_mac {
+
+// To be used to instantiate ServiceCrApplication from C++ code.
+void RegisterServiceCrApp();
+} // namespace chrome_service_application_mac
+
+#endif // CHROME_SERVICE_CHROME_SERVICE_APPLICATION_MAC_H_
+
diff --git a/chrome/service/chrome_service_application_mac.mm b/chrome/service/chrome_service_application_mac.mm
new file mode 100644
index 0000000..e7815e9
--- /dev/null
+++ b/chrome/service/chrome_service_application_mac.mm
@@ -0,0 +1,101 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/service/chrome_service_application_mac.h"
+
+#include "base/logging.h"
+#include "base/mac/foundation_util.h"
+#import "content/common/cloud_print_class_mac.h"
+#include "chrome/common/chrome_switches.h"
+
+@interface ServiceCrApplication ()
+- (void)setCloudPrintHandler;
+- (void)submitPrint:(NSAppleEventDescriptor*)event;
+@end
+
+@implementation ServiceCrApplication
+
+-(void)setCloudPrintHandler {
+ NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
+ [em setEventHandler:self
+ andSelector:@selector(submitPrint:)
+ forEventClass:content::kAECloudPrintClass
+ andEventID:content::kAECloudPrintClass];
+}
+
+// Event handler for Cloud Print Event. Forwards print job received to Chrome,
+// launching Chrome if necessary. Used to beat CUPS sandboxing.
+- (void)submitPrint:(NSAppleEventDescriptor*)event {
+ std::string silent = std::string("--") + switches::kNoStartupWindow;
+ // Set up flag so that it can be passed along with the Apple Event.
+ CFStringRef silentLaunchFlag =
+ CFStringCreateWithCString(NULL, silent.c_str(), kCFStringEncodingUTF8);
+ CFStringRef flags[] = { silentLaunchFlag };
+ // Argv array that will be passed.
+ CFArrayRef passArgv =
+ CFArrayCreate(NULL, (const void**) flags, 1, &kCFTypeArrayCallBacks);
+ FSRef ref;
+ OSStatus status = noErr;
+ CFURLRef* kDontWantURL = NULL;
+ // Get Chrome's bundle ID.
+ std::string bundleID = base::mac::BaseBundleID();
+ CFStringRef bundleIDCF =
+ CFStringCreateWithCString(NULL, bundleID.c_str(), kCFStringEncodingUTF8);
+ // Use Launch Services to locate Chrome using its bundleID.
+ status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF,
+ NULL, &ref, kDontWantURL);
+
+ if (status != noErr) {
+ LOG(ERROR) << "Failed to make path ref";
+ LOG(ERROR) << GetMacOSStatusErrorString(status);
+ LOG(ERROR) << GetMacOSStatusCommentString(status);
+ return;
+ }
+ // Actually create the Apple Event.
+ NSAppleEventDescriptor* sendEvent =
+ [NSAppleEventDescriptor
+ appleEventWithEventClass:content::kAECloudPrintClass
+ eventID:content::kAECloudPrintClass
+ targetDescriptor:nil
+ returnID:kAutoGenerateReturnID
+ transactionID:kAnyTransactionID];
+ // Pull the parameters out of AppleEvent sent to us and attach them
+ // to our Apple Event.
+ NSAppleEventDescriptor* parameters =
+ [event paramDescriptorForKeyword:content::kAECloudPrintClass];
+ [sendEvent setParamDescriptor:parameters
+ forKeyword:content::kAECloudPrintClass];
+ LSApplicationParameters params = { 0,
+ kLSLaunchDefaults,
+ &ref,
+ NULL,
+ NULL,
+ passArgv,
+ NULL };
+ AEDesc* initialEvent = const_cast<AEDesc*> ([sendEvent aeDesc]);
+ params.initialEvent = static_cast<AppleEvent*> (initialEvent);
+ // Send the Apple Event Using launch services, launching Chrome if necessary.
+ status = LSOpenApplication(&params, NULL);
+ if (status != noErr) {
+ LOG(ERROR) << "Unable to launch";
+ LOG(ERROR) << GetMacOSStatusErrorString(status);
+ LOG(ERROR) << GetMacOSStatusCommentString(status);
+ }
+}
+
+
+@end
+
+
+namespace chrome_service_application_mac {
+
+void RegisterServiceCrApp() {
+ ServiceCrApplication* var =
+ static_cast<ServiceCrApplication*>
+ ([ServiceCrApplication sharedApplication]);
+ [var setCloudPrintHandler];
+}
+
+} // namespace chrome_service_application_mac
+
diff --git a/chrome/service/service_ipc_server.cc b/chrome/service/service_ipc_server.cc
index b3582a2..01b5deb 100644
--- a/chrome/service/service_ipc_server.cc
+++ b/chrome/service/service_ipc_server.cc
@@ -109,6 +109,10 @@ bool ServiceIPCServer::OnMessageReceived(const IPC::Message& msg) {
OnGetCloudPrintProxyInfo)
IPC_MESSAGE_HANDLER(ServiceMsg_Shutdown, OnShutdown);
IPC_MESSAGE_HANDLER(ServiceMsg_UpdateAvailable, OnUpdateAvailable);
+ IPC_MESSAGE_HANDLER(ServiceMsg_EnableVirtualDriver,
+ OnEnableVirtualDriver);
+ IPC_MESSAGE_HANDLER(ServiceMsg_DisableVirtualDriver,
+ OnDisableVirtualDriver);
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -145,3 +149,12 @@ void ServiceIPCServer::OnShutdown() {
void ServiceIPCServer::OnUpdateAvailable() {
g_service_process->SetUpdateAvailable();
}
+
+void ServiceIPCServer::OnEnableVirtualDriver() {
+ g_service_process->EnableVirtualPrintDriver();
+}
+
+void ServiceIPCServer::OnDisableVirtualDriver() {
+ g_service_process->DisableVirtualPrintDriver();
+}
+
diff --git a/chrome/service/service_ipc_server.h b/chrome/service/service_ipc_server.h
index eeb1f74..ed1613f 100644
--- a/chrome/service/service_ipc_server.h
+++ b/chrome/service/service_ipc_server.h
@@ -48,6 +48,8 @@ class ServiceIPCServer : public IPC::Channel::Listener,
const std::string& user_email);
void OnGetCloudPrintProxyInfo();
void OnDisableCloudPrintProxy();
+ void OnEnableVirtualDriver();
+ void OnDisableVirtualDriver();
void OnShutdown();
void OnUpdateAvailable();
diff --git a/chrome/service/service_main.cc b/chrome/service/service_main.cc
index 9242c17..bd5e66f 100644
--- a/chrome/service/service_main.cc
+++ b/chrome/service/service_main.cc
@@ -12,7 +12,7 @@
#if defined(OS_WIN)
#include "content/common/sandbox_policy.h"
#elif defined(OS_MACOSX)
-#include "content/common/chrome_application_mac.h"
+#include "chrome/service/chrome_service_application_mac.h"
#endif // defined(OS_WIN)
// Mainline routine for running as the service process.
@@ -27,7 +27,7 @@ int ServiceProcessMain(const MainFunctionParams& parameters) {
<< parameters.command_line_.GetCommandLineString();
#if defined(OS_MACOSX)
- chrome_application_mac::RegisterCrApp();
+ chrome_service_application_mac::RegisterServiceCrApp();
#endif
base::PlatformThread::SetName("CrServiceMain");
diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc
index e5e0494..8fc8e95 100644
--- a/chrome/service/service_process.cc
+++ b/chrome/service/service_process.cc
@@ -192,6 +192,16 @@ bool ServiceProcess::Initialize(MessageLoopForUI* message_loop,
if (cloud_print_proxy_enabled) {
GetCloudPrintProxy()->EnableForUser(lsid);
}
+ // Enable Virtual Printer Driver if needed.
+ bool virtual_printer_driver_enabled = false;
+ service_prefs_->GetBoolean(prefs::kVirtualPrinterDriverEnabled,
+ &virtual_printer_driver_enabled);
+
+ if (virtual_printer_driver_enabled) {
+ // Register the fact that there is at least one
+ // service needing the process.
+ OnServiceEnabled();
+ }
VLOG(1) << "Starting Service Process IPC Server";
ipc_server_.reset(new ServiceIPCServer(
@@ -272,6 +282,20 @@ void ServiceProcess::OnCloudPrintProxyDisabled(bool persist_state) {
OnServiceDisabled();
}
+void ServiceProcess::EnableVirtualPrintDriver() {
+ OnServiceEnabled();
+ // Save the preference that we have enabled the virtual driver.
+ service_prefs_->SetBoolean(prefs::kVirtualPrinterDriverEnabled, true);
+ service_prefs_->WritePrefs();
+}
+
+void ServiceProcess::DisableVirtualPrintDriver() {
+ OnServiceDisabled();
+ // Save the preference that we have disabled the virtual driver.
+ service_prefs_->SetBoolean(prefs::kVirtualPrinterDriverEnabled, false);
+ service_prefs_->WritePrefs();
+}
+
ServiceURLRequestContextGetter*
ServiceProcess::GetServiceURLRequestContextGetter() {
DCHECK(request_context_getter_.get());
diff --git a/chrome/service/service_process.h b/chrome/service/service_process.h
index ce1fc5a..8379fb8 100644
--- a/chrome/service/service_process.h
+++ b/chrome/service/service_process.h
@@ -39,6 +39,11 @@ class ServiceProcess : public CloudPrintProxy::Client {
bool Initialize(MessageLoopForUI* message_loop,
const CommandLine& command_line,
ServiceProcessState* state);
+
+ // Functions for Cloud Print virtual driver on Mac.
+ void EnableVirtualPrintDriver();
+ void DisableVirtualPrintDriver();
+
bool Teardown();
// TODO(sanjeevr): Change various parts of the code such as
// net::ProxyService::CreateSystemProxyConfigService to take in