blob: f030633765d8b258fd99219c4b9709a2377db982 [file] [log] [blame]
[email protected]87ab41e72012-01-04 18:45:111// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]73852b8f2010-05-14 00:38:122// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/printing/print_dialog_cloud.h"
[email protected]443e9312013-05-06 06:17:346
[email protected]73852b8f2010-05-14 00:38:127
[email protected]73852b8f2010-05-14 00:38:128#include "base/base64.h"
[email protected]ba4fc242011-10-04 18:56:569#include "base/bind.h"
10#include "base/bind_helpers.h"
[email protected]65c9d89a2011-04-13 21:02:3911#include "base/command_line.h"
[email protected]73852b8f2010-05-14 00:38:1212#include "base/file_util.h"
13#include "base/json/json_reader.h"
[email protected]3853a4c2013-02-11 17:15:5714#include "base/prefs/pref_service.h"
[email protected]e309f312013-06-07 21:50:0815#include "base/strings/utf_string_conversions.h"
[email protected]73852b8f2010-05-14 00:38:1216#include "base/values.h"
[email protected]70019152012-12-19 11:44:1917#include "chrome/browser/devtools/devtools_window.h"
[email protected]2e6389f2012-05-18 19:41:2518#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]2283eead2010-09-29 23:17:3019#include "chrome/browser/printing/cloud_print/cloud_print_url.h"
[email protected]443e9312013-05-06 06:17:3420#include "chrome/browser/printing/print_dialog_cloud_internal.h"
[email protected]8ecad5e2010-12-02 21:18:3321#include "chrome/browser/profiles/profile.h"
[email protected]e39027a2011-01-24 21:41:5422#include "chrome/browser/profiles/profile_manager.h"
[email protected]508326df2012-05-23 16:01:1923#include "chrome/browser/ui/browser_dialogs.h"
[email protected]65c9d89a2011-04-13 21:02:3924#include "chrome/common/chrome_switches.h"
[email protected]ea161da2010-11-02 21:57:3525#include "chrome/common/pref_names.h"
[email protected]1375e3ab2011-03-24 17:07:2226#include "chrome/common/print_messages.h"
[email protected]73852b8f2010-05-14 00:38:1227#include "chrome/common/url_constants.h"
[email protected]75fee372013-03-06 00:42:4428#include "components/user_prefs/pref_registry_syncable.h"
[email protected]c38831a12011-10-28 12:44:4929#include "content/public/browser/browser_thread.h"
[email protected]cdcb1dee2012-01-04 00:46:2030#include "content/public/browser/navigation_controller.h"
[email protected]022af742011-12-28 18:37:2531#include "content/public/browser/navigation_entry.h"
[email protected]6c2381d2011-10-19 02:52:5332#include "content/public/browser/notification_registrar.h"
33#include "content/public/browser/notification_source.h"
[email protected]0d6e9bd2011-10-18 04:29:1634#include "content/public/browser/notification_types.h"
[email protected]9c1662b2012-03-06 15:44:3335#include "content/public/browser/render_view_host.h"
[email protected]0ec4898e2011-12-30 21:09:2436#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1037#include "content/public/browser/web_contents_view.h"
[email protected]01ec4ec2012-01-18 04:13:4738#include "content/public/browser/web_ui.h"
[email protected]fca6b9b2012-05-22 17:11:0539#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1740#include "ui/base/l10n/l10n_util.h"
[email protected]fab55e72013-05-31 07:06:1841#include "webkit/common/webpreferences.h"
[email protected]520c2022012-03-15 00:13:1542
[email protected]88bfd25b2012-06-22 06:28:3343#if defined(USE_AURA)
44#include "ui/aura/root_window.h"
45#include "ui/aura/window.h"
46#endif
47
[email protected]520c2022012-03-15 00:13:1548#if defined(OS_WIN)
49#include "ui/base/win/foreground_helper.h"
50#endif
51
[email protected]73852b8f2010-05-14 00:38:1252// This module implements the UI support in Chrome for cloud printing.
53// This means hosting a dialog containing HTML/JavaScript and using
54// the published cloud print user interface integration APIs to get
55// page setup settings from the dialog contents and provide the
[email protected]a984bdf2011-03-15 20:17:1656// generated print data to the dialog contents for uploading to the
[email protected]73852b8f2010-05-14 00:38:1257// cloud print service.
58
59// Currently, the flow between these classes is as follows:
60
[email protected]a984bdf2011-03-15 20:17:1661// PrintDialogCloud::CreatePrintDialogForFile is called from
[email protected]73852b8f2010-05-14 00:38:1262// resource_message_filter_gtk.cc once the renderer has informed the
[email protected]a984bdf2011-03-15 20:17:1663// renderer host that print data generation into the renderer host provided
[email protected]032682b2011-01-12 22:05:0264// temp file has been completed. That call is on the FILE thread.
[email protected]73852b8f2010-05-14 00:38:1265// That, in turn, hops over to the UI thread to create an instance of
66// PrintDialogCloud.
67
68// The constructor for PrintDialogCloud creates a
[email protected]5835871a2012-04-25 21:56:5569// CloudPrintWebDialogDelegate and asks the current active browser to
[email protected]73852b8f2010-05-14 00:38:1270// show an HTML dialog using that class as the delegate. That class
[email protected]89f550b2011-06-08 18:34:0371// hands in the kChromeUICloudPrintResourcesURL as the URL to visit. That is
[email protected]80a8fad2011-01-29 04:02:3872// recognized by the GetWebUIFactoryFunction as a signal to create an
[email protected]02b5ccc2012-04-30 23:58:3173// ExternalWebDialogUI.
[email protected]73852b8f2010-05-14 00:38:1274
[email protected]5835871a2012-04-25 21:56:5575// CloudPrintWebDialogDelegate also temporarily owns a
[email protected]73852b8f2010-05-14 00:38:1276// CloudPrintFlowHandler, a class which is responsible for the actual
[email protected]a984bdf2011-03-15 20:17:1677// interactions with the dialog contents, including handing in the
[email protected]73852b8f2010-05-14 00:38:1278// print data and getting any page setup parameters that the dialog
79// contents provides. As part of bringing up the dialog,
[email protected]02b5ccc2012-04-30 23:58:3180// WebDialogUI::RenderViewCreated is called (an override of
[email protected]c39f9bf2011-02-12 00:43:5581// WebUI::RenderViewCreated). That routine, in turn, calls the
[email protected]36e12172011-02-08 23:46:0282// delegate's GetWebUIMessageHandlers routine, at which point the
[email protected]73852b8f2010-05-14 00:38:1283// ownership of the CloudPrintFlowHandler is handed over. A pointer
84// to the flow handler is kept to facilitate communication back and
85// forth between the two classes.
86
[email protected]c39f9bf2011-02-12 00:43:5587// The WebUI continues dialog bring-up, calling
[email protected]73852b8f2010-05-14 00:38:1288// CloudPrintFlowHandler::RegisterMessages. This is where the
89// additional object model capabilities are registered for the dialog
90// contents to use. It is also at this time that capabilities for the
91// dialog contents are adjusted to allow the dialog contents to close
92// the window. In addition, the pending URL is redirected to the
93// actual cloud print service URL. The flow controller also registers
94// for notification of when the dialog contents finish loading, which
[email protected]a984bdf2011-03-15 20:17:1695// is currently used to send the data to the dialog contents.
[email protected]73852b8f2010-05-14 00:38:1296
[email protected]a984bdf2011-03-15 20:17:1697// In order to send the data to the dialog contents, the flow
[email protected]73852b8f2010-05-14 00:38:1298// handler uses a CloudPrintDataSender. It creates one, letting it
[email protected]a984bdf2011-03-15 20:17:1699// know the name of the temporary file containing the data, and
[email protected]73852b8f2010-05-14 00:38:12100// posts the task of reading the file
101// (CloudPrintDataSender::ReadPrintDataFile) to the file thread. That
102// routine reads in the file, and then hops over to the IO thread to
103// send that data to the dialog contents.
104
105// When the dialog contents are finished (by either being cancelled or
106// hitting the print button), the delegate is notified, and responds
107// that the dialog should be closed, at which point things are torn
108// down and released.
109
[email protected]631bb742011-11-02 11:29:39110using content::BrowserThread;
[email protected]c5eed492012-01-04 17:07:50111using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23112using content::NavigationEntry;
[email protected]eaabba22012-03-07 15:02:11113using content::RenderViewHost;
[email protected]a81343d232011-12-27 07:39:20114using content::WebContents;
[email protected]26e2632a2011-12-31 04:02:55115using content::WebUIMessageHandler;
[email protected]20c07f8e2012-05-31 08:43:14116using ui::WebDialogDelegate;
[email protected]631bb742011-11-02 11:29:39117
[email protected]681958c2013-02-21 13:48:14118const int kDefaultWidth = 912;
119const int kDefaultHeight = 633;
120
[email protected]73852b8f2010-05-14 00:38:12121namespace internal_cloud_print_helpers {
122
[email protected]73852b8f2010-05-14 00:38:12123// From the JSON parsed value, get the entries for the page setup
124// parameters.
125bool GetPageSetupParameters(const std::string& json,
[email protected]1375e3ab2011-03-24 17:07:22126 PrintMsg_Print_Params& parameters) {
[email protected]cd5785752012-04-11 00:15:41127 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json));
[email protected]73852b8f2010-05-14 00:38:12128 DLOG_IF(ERROR, (!parsed_value.get() ||
129 !parsed_value->IsType(Value::TYPE_DICTIONARY)))
130 << "PageSetup call didn't have expected contents";
131 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY))
132 return false;
133
134 bool result = true;
135 DictionaryValue* params = static_cast<DictionaryValue*>(parsed_value.get());
[email protected]05c7da62011-05-05 17:23:56136 result &= params->GetDouble("dpi", &parameters.dpi);
137 result &= params->GetDouble("min_shrink", &parameters.min_shrink);
138 result &= params->GetDouble("max_shrink", &parameters.max_shrink);
[email protected]a65175d2010-08-17 04:00:57139 result &= params->GetBoolean("selection_only", &parameters.selection_only);
[email protected]73852b8f2010-05-14 00:38:12140 return result;
141}
142
[email protected]e8368e92011-08-20 04:05:56143string16 GetSwitchValueString16(const CommandLine& command_line,
144 const char* switchName) {
[email protected]31662202013-03-23 19:10:54145#if defined(OS_WIN)
[email protected]e8368e92011-08-20 04:05:56146 CommandLine::StringType native_switch_val;
147 native_switch_val = command_line.GetSwitchValueNative(switchName);
148 return string16(native_switch_val);
149#elif defined(OS_POSIX)
150 // POSIX Command line string types are different.
151 CommandLine::StringType native_switch_val;
152 native_switch_val = command_line.GetSwitchValueASCII(switchName);
153 // Convert the ASCII string to UTF16 to prepare to pass.
154 return string16(ASCIIToUTF16(native_switch_val));
155#endif
156}
157
[email protected]73852b8f2010-05-14 00:38:12158void CloudPrintDataSenderHelper::CallJavascriptFunction(
159 const std::wstring& function_name) {
[email protected]47e870b2013-02-24 21:14:53160 web_ui_->CallJavascriptFunction(WideToASCII(function_name));
[email protected]73852b8f2010-05-14 00:38:12161}
162
163void CloudPrintDataSenderHelper::CallJavascriptFunction(
164 const std::wstring& function_name, const Value& arg) {
[email protected]47e870b2013-02-24 21:14:53165 web_ui_->CallJavascriptFunction(WideToASCII(function_name), arg);
[email protected]73852b8f2010-05-14 00:38:12166}
167
168void CloudPrintDataSenderHelper::CallJavascriptFunction(
169 const std::wstring& function_name, const Value& arg1, const Value& arg2) {
[email protected]47e870b2013-02-24 21:14:53170 web_ui_->CallJavascriptFunction(WideToASCII(function_name), arg1, arg2);
[email protected]73852b8f2010-05-14 00:38:12171}
172
[email protected]e8368e92011-08-20 04:05:56173void CloudPrintDataSenderHelper::CallJavascriptFunction(
174 const std::wstring& function_name,
175 const Value& arg1,
176 const Value& arg2,
177 const Value& arg3) {
[email protected]46adf7ff2011-12-30 00:53:09178 web_ui_->CallJavascriptFunction(
[email protected]47e870b2013-02-24 21:14:53179 WideToASCII(function_name), arg1, arg2, arg3);
[email protected]e8368e92011-08-20 04:05:56180}
181
[email protected]73852b8f2010-05-14 00:38:12182// Clears out the pointer we're using to communicate. Either routine is
183// potentially expensive enough that stopping whatever is in progress
184// is worth it.
185void CloudPrintDataSender::CancelPrintDataFile() {
[email protected]20305ec2011-01-21 04:55:52186 base::AutoLock lock(lock_);
[email protected]73852b8f2010-05-14 00:38:12187 // We don't own helper, it was passed in to us, so no need to
188 // delete, just let it go.
189 helper_ = NULL;
190}
191
[email protected]38e08982010-10-22 17:28:43192CloudPrintDataSender::CloudPrintDataSender(CloudPrintDataSenderHelper* helper,
[email protected]a984bdf2011-03-15 20:17:16193 const string16& print_job_title,
[email protected]e8368e92011-08-20 04:05:56194 const string16& print_ticket,
[email protected]a9723e12013-03-05 04:02:45195 const std::string& file_type,
196 const base::RefCountedMemory* data)
[email protected]38e08982010-10-22 17:28:43197 : helper_(helper),
[email protected]a984bdf2011-03-15 20:17:16198 print_job_title_(print_job_title),
[email protected]e8368e92011-08-20 04:05:56199 print_ticket_(print_ticket),
[email protected]a9723e12013-03-05 04:02:45200 file_type_(file_type),
201 data_(data) {
[email protected]38e08982010-10-22 17:28:43202}
203
204CloudPrintDataSender::~CloudPrintDataSender() {}
205
[email protected]73852b8f2010-05-14 00:38:12206// We have the data in hand that needs to be pushed into the dialog
207// contents; do so from the IO thread.
208
209// TODO(scottbyer): If the print data ends up being larger than the
210// upload limit (currently 10MB), what we need to do is upload that
211// large data to google docs and set the URL in the printing
212// JavaScript to that location, and make sure it gets deleted when not
213// needed. - 4/1/2010
[email protected]a9723e12013-03-05 04:02:45214void CloudPrintDataSender::SendPrintData() {
[email protected]ba4f1132010-10-09 02:02:35215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5173de8b2013-06-02 21:16:02216 if (!data_.get() || !data_->size())
[email protected]a9723e12013-03-05 04:02:45217 return;
218
219 std::string base64_data;
220 base::Base64Encode(
221 base::StringPiece(reinterpret_cast<const char*>(data_->front()),
222 data_->size()),
223 &base64_data);
[email protected]a9723e12013-03-05 04:02:45224 std::string header("data:");
225 header.append(file_type_);
226 header.append(";base64,");
227 base64_data.insert(0, header);
228
[email protected]20305ec2011-01-21 04:55:52229 base::AutoLock lock(lock_);
[email protected]a9723e12013-03-05 04:02:45230 if (helper_) {
[email protected]9848c7e2010-06-03 16:06:56231 StringValue title(print_job_title_);
[email protected]e8368e92011-08-20 04:05:56232 StringValue ticket(print_ticket_);
233 // TODO(abodenha): Change Javascript call to pass in print ticket
234 // after server side support is added. Add test for it.
[email protected]73852b8f2010-05-14 00:38:12235
236 // Send the print data to the dialog contents. The JavaScript
237 // function is a preliminary API for prototyping purposes and is
238 // subject to change.
239 const_cast<CloudPrintDataSenderHelper*>(helper_)->CallJavascriptFunction(
[email protected]a9723e12013-03-05 04:02:45240 L"printApp._printDataUrl", StringValue(base64_data), title);
[email protected]73852b8f2010-05-14 00:38:12241 }
242}
243
244
[email protected]a9723e12013-03-05 04:02:45245CloudPrintFlowHandler::CloudPrintFlowHandler(const base::RefCountedMemory* data,
[email protected]a984bdf2011-03-15 20:17:16246 const string16& print_job_title,
[email protected]e8368e92011-08-20 04:05:56247 const string16& print_ticket,
[email protected]4cd49022012-01-19 20:37:37248 const std::string& file_type,
249 bool close_after_signin,
250 const base::Closure& callback)
[email protected]c7bf7452011-09-12 21:31:50251 : dialog_delegate_(NULL),
[email protected]a9723e12013-03-05 04:02:45252 data_(data),
[email protected]a984bdf2011-03-15 20:17:16253 print_job_title_(print_job_title),
[email protected]e8368e92011-08-20 04:05:56254 print_ticket_(print_ticket),
[email protected]4cd49022012-01-19 20:37:37255 file_type_(file_type),
256 close_after_signin_(close_after_signin),
257 callback_(callback) {
[email protected]38e08982010-10-22 17:28:43258}
259
260CloudPrintFlowHandler::~CloudPrintFlowHandler() {
261 // This will also cancel any task in flight.
262 CancelAnyRunningTask();
263}
264
265
[email protected]73852b8f2010-05-14 00:38:12266void CloudPrintFlowHandler::SetDialogDelegate(
[email protected]5835871a2012-04-25 21:56:55267 CloudPrintWebDialogDelegate* delegate) {
[email protected]7b748982011-02-14 19:28:23268 // Even if setting a new WebUI, it means any previous task needs
[email protected]a2c92a1c2012-04-03 12:32:14269 // to be canceled, its now invalid.
[email protected]ba4f1132010-10-09 02:02:35270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]73852b8f2010-05-14 00:38:12271 CancelAnyRunningTask();
272 dialog_delegate_ = delegate;
273}
274
275// Cancels any print data sender we have in flight and removes our
276// reference to it, so when the task that is calling it finishes and
[email protected]a2c92a1c2012-04-03 12:32:14277// removes its reference, it goes away.
[email protected]73852b8f2010-05-14 00:38:12278void CloudPrintFlowHandler::CancelAnyRunningTask() {
[email protected]ba4f1132010-10-09 02:02:35279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]73852b8f2010-05-14 00:38:12280 if (print_data_sender_.get()) {
281 print_data_sender_->CancelPrintDataFile();
282 print_data_sender_ = NULL;
283 }
284}
285
[email protected]73852b8f2010-05-14 00:38:12286void CloudPrintFlowHandler::RegisterMessages() {
[email protected]73852b8f2010-05-14 00:38:12287 // TODO(scottbyer) - This is where we will register messages for the
288 // UI JS to use. Needed: Call to update page setup parameters.
[email protected]46adf7ff2011-12-30 00:53:09289 web_ui()->RegisterMessageCallback("ShowDebugger",
[email protected]ba4fc242011-10-04 18:56:56290 base::Bind(&CloudPrintFlowHandler::HandleShowDebugger,
291 base::Unretained(this)));
[email protected]46adf7ff2011-12-30 00:53:09292 web_ui()->RegisterMessageCallback("SendPrintData",
[email protected]ba4fc242011-10-04 18:56:56293 base::Bind(&CloudPrintFlowHandler::HandleSendPrintData,
294 base::Unretained(this)));
[email protected]46adf7ff2011-12-30 00:53:09295 web_ui()->RegisterMessageCallback("SetPageParameters",
[email protected]ba4fc242011-10-04 18:56:56296 base::Bind(&CloudPrintFlowHandler::HandleSetPageParameters,
297 base::Unretained(this)));
[email protected]73852b8f2010-05-14 00:38:12298
[email protected]0eb25c42011-08-11 14:50:14299 // Register for appropriate notifications, and re-direct the URL
300 // to the real server URL, now that we've gotten an HTML dialog
301 // going.
[email protected]c5eed492012-01-04 17:07:50302 NavigationController* controller =
[email protected]01ec4ec2012-01-18 04:13:47303 &web_ui()->GetWebContents()->GetController();
[email protected]10f417c52011-12-28 21:04:23304 NavigationEntry* pending_entry = controller->GetPendingEntry();
[email protected]0eb25c42011-08-11 14:50:14305 if (pending_entry) {
[email protected]46adf7ff2011-12-30 00:53:09306 Profile* profile = Profile::FromWebUI(web_ui());
[email protected]4cd49022012-01-19 20:37:37307 if (close_after_signin_) {
308 pending_entry->SetURL(
309 CloudPrintURL(profile).GetCloudPrintSigninURL());
310 } else {
311 pending_entry->SetURL(
312 CloudPrintURL(profile).GetCloudPrintServiceDialogURL());
313 }
[email protected]73852b8f2010-05-14 00:38:12314 }
[email protected]0eb25c42011-08-11 14:50:14315 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50316 content::Source<NavigationController>(controller));
[email protected]57c8cf22013-03-02 16:50:00317 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
318 content::Source<NavigationController>(controller));
[email protected]73852b8f2010-05-14 00:38:12319}
320
[email protected]6c2381d2011-10-19 02:52:53321void CloudPrintFlowHandler::Observe(
322 int type,
323 const content::NotificationSource& source,
324 const content::NotificationDetails& details) {
[email protected]57c8cf22013-03-02 16:50:00325 switch (type) {
326 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
327 NavigationEntry* entry =
328 web_ui()->GetWebContents()->GetController().GetActiveEntry();
329 if (entry)
330 NavigationToURLDidCloseDialog(entry->GetURL());
331 break;
[email protected]20c52d22011-06-20 22:42:42332 }
[email protected]57c8cf22013-03-02 16:50:00333 case content::NOTIFICATION_LOAD_STOP: {
[email protected]57c8cf22013-03-02 16:50:00334 GURL url = web_ui()->GetWebContents()->GetURL();
[email protected]6e536cdf2013-05-09 04:49:52335 if (IsCloudPrintDialogUrl(url)) {
336 // Take the opportunity to set some (minimal) additional
337 // script permissions required for the web UI.
[email protected]57c8cf22013-03-02 16:50:00338 RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost();
339 if (rvh) {
[email protected]3184f90b2013-05-01 18:17:53340 WebPreferences webkit_prefs = rvh->GetWebkitPreferences();
[email protected]57c8cf22013-03-02 16:50:00341 webkit_prefs.allow_scripts_to_close_windows = true;
342 rvh->UpdateWebkitPreferences(webkit_prefs);
343 } else {
344 NOTREACHED();
345 }
[email protected]6e536cdf2013-05-09 04:49:52346 // Choose one or the other. If you need to debug, bring up the
347 // debugger. You can then use the various chrome.send()
348 // registrations above to kick of the various function calls,
349 // including chrome.send("SendPrintData") in the javaScript
350 // console and watch things happen with:
351 // HandleShowDebugger(NULL);
352 HandleSendPrintData(NULL);
[email protected]57c8cf22013-03-02 16:50:00353 }
[email protected]57c8cf22013-03-02 16:50:00354 break;
355 }
[email protected]73852b8f2010-05-14 00:38:12356 }
357}
358
[email protected]88942a22010-08-19 20:34:43359void CloudPrintFlowHandler::HandleShowDebugger(const ListValue* args) {
[email protected]73852b8f2010-05-14 00:38:12360 ShowDebugger();
361}
362
363void CloudPrintFlowHandler::ShowDebugger() {
[email protected]46adf7ff2011-12-30 00:53:09364 if (web_ui()) {
[email protected]01ec4ec2012-01-18 04:13:47365 RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost();
[email protected]73852b8f2010-05-14 00:38:12366 if (rvh)
[email protected]aebdd072011-07-07 12:36:59367 DevToolsWindow::OpenDevToolsWindow(rvh);
[email protected]73852b8f2010-05-14 00:38:12368 }
369}
370
371scoped_refptr<CloudPrintDataSender>
372CloudPrintFlowHandler::CreateCloudPrintDataSender() {
[email protected]46adf7ff2011-12-30 00:53:09373 DCHECK(web_ui());
374 print_data_helper_.reset(new CloudPrintDataSenderHelper(web_ui()));
[email protected]a9723e12013-03-05 04:02:45375 scoped_refptr<CloudPrintDataSender> sender(
[email protected]5173de8b2013-06-02 21:16:02376 new CloudPrintDataSender(print_data_helper_.get(),
377 print_job_title_,
378 print_ticket_,
379 file_type_,
380 data_.get()));
[email protected]a9723e12013-03-05 04:02:45381 return sender;
[email protected]73852b8f2010-05-14 00:38:12382}
383
[email protected]88942a22010-08-19 20:34:43384void CloudPrintFlowHandler::HandleSendPrintData(const ListValue* args) {
[email protected]ba4f1132010-10-09 02:02:35385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]73852b8f2010-05-14 00:38:12386 // This will cancel any ReadPrintDataFile() or SendPrintDataFile()
387 // requests in flight (this is anticipation of when setting page
388 // setup parameters becomes asynchronous and may be set while some
389 // data is in flight). Then we can clear out the print data.
390 CancelAnyRunningTask();
[email protected]46adf7ff2011-12-30 00:53:09391 if (web_ui()) {
[email protected]73852b8f2010-05-14 00:38:12392 print_data_sender_ = CreateCloudPrintDataSender();
[email protected]3e2dd4fa2011-11-10 06:06:40393 BrowserThread::PostTask(
[email protected]a9723e12013-03-05 04:02:45394 BrowserThread::IO, FROM_HERE,
395 base::Bind(&CloudPrintDataSender::SendPrintData, print_data_sender_));
[email protected]73852b8f2010-05-14 00:38:12396 }
397}
398
[email protected]88942a22010-08-19 20:34:43399void CloudPrintFlowHandler::HandleSetPageParameters(const ListValue* args) {
[email protected]036056a32011-03-03 21:05:01400 std::string json;
[email protected]e675f7b2011-06-22 17:32:12401 bool ret = args->GetString(0, &json);
402 if (!ret || json.empty()) {
[email protected]036056a32011-03-03 21:05:01403 NOTREACHED() << "Empty json string";
[email protected]73852b8f2010-05-14 00:38:12404 return;
[email protected]036056a32011-03-03 21:05:01405 }
[email protected]73852b8f2010-05-14 00:38:12406
407 // These are backstop default values - 72 dpi to match the screen,
408 // 8.5x11 inch paper with margins subtracted (1/4 inch top, left,
409 // right and 0.56 bottom), and the min page shrink and max page
410 // shrink values appear all over the place with no explanation.
411
412 // TODO(scottbyer): Get a Linux/ChromeOS edge for PrintSettings
413 // working so that we can get the default values from there. Fix up
414 // PrintWebViewHelper to do the same.
415 const int kDPI = 72;
416 const int kWidth = static_cast<int>((8.5-0.25-0.25)*kDPI);
417 const int kHeight = static_cast<int>((11-0.25-0.56)*kDPI);
418 const double kMinPageShrink = 1.25;
419 const double kMaxPageShrink = 2.0;
420
[email protected]1375e3ab2011-03-24 17:07:22421 PrintMsg_Print_Params default_settings;
[email protected]10980442011-12-04 22:33:05422 default_settings.content_size = gfx::Size(kWidth, kHeight);
[email protected]732b8132012-01-10 23:17:32423 default_settings.printable_area = gfx::Rect(0, 0, kWidth, kHeight);
[email protected]73852b8f2010-05-14 00:38:12424 default_settings.dpi = kDPI;
425 default_settings.min_shrink = kMinPageShrink;
426 default_settings.max_shrink = kMaxPageShrink;
427 default_settings.desired_dpi = kDPI;
428 default_settings.document_cookie = 0;
429 default_settings.selection_only = false;
[email protected]718af822011-08-12 22:11:33430 default_settings.preview_request_id = 0;
431 default_settings.is_first_request = true;
[email protected]732b8132012-01-10 23:17:32432 default_settings.print_to_pdf = false;
[email protected]73852b8f2010-05-14 00:38:12433
434 if (!GetPageSetupParameters(json, default_settings)) {
435 NOTREACHED();
436 return;
437 }
438
439 // TODO(scottbyer) - Here is where we would kick the originating
440 // renderer thread with these new parameters in order to get it to
[email protected]a984bdf2011-03-15 20:17:16441 // re-generate the PDF data and hand it back to us. window.print() is
[email protected]73852b8f2010-05-14 00:38:12442 // currently synchronous, so there's a lot of work to do to get to
443 // that point.
444}
445
[email protected]ea161da2010-11-02 21:57:35446void CloudPrintFlowHandler::StoreDialogClientSize() const {
[email protected]01ec4ec2012-01-18 04:13:47447 if (web_ui() && web_ui()->GetWebContents() &&
448 web_ui()->GetWebContents()->GetView()) {
449 gfx::Size size = web_ui()->GetWebContents()->GetView()->GetContainerSize();
[email protected]46adf7ff2011-12-30 00:53:09450 Profile* profile = Profile::FromWebUI(web_ui());
[email protected]0eb25c42011-08-11 14:50:14451 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogWidth,
452 size.width());
453 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogHeight,
454 size.height());
[email protected]ea161da2010-11-02 21:57:35455 }
456}
457
[email protected]a911c4e2012-10-12 00:37:57458bool CloudPrintFlowHandler::NavigationToURLDidCloseDialog(const GURL& url) {
459 if (close_after_signin_) {
[email protected]6e536cdf2013-05-09 04:49:52460 if (IsCloudPrintDialogUrl(url)) {
[email protected]a911c4e2012-10-12 00:37:57461 StoreDialogClientSize();
462 web_ui()->GetWebContents()->GetRenderViewHost()->ClosePage();
463 callback_.Run();
464 return true;
465 }
466 }
467 return false;
468}
469
[email protected]6e536cdf2013-05-09 04:49:52470bool CloudPrintFlowHandler::IsCloudPrintDialogUrl(const GURL& url) {
471 GURL cloud_print_url =
472 CloudPrintURL(Profile::FromWebUI(web_ui())).GetCloudPrintServiceURL();
473 return url.host() == cloud_print_url.host() &&
474 StartsWithASCII(url.path(), cloud_print_url.path(), false) &&
475 url.scheme() == cloud_print_url.scheme();
476}
477
[email protected]5835871a2012-04-25 21:56:55478CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate(
[email protected]b5b79d72012-05-24 19:42:28479 content::BrowserContext* browser_context,
480 gfx::NativeWindow modal_parent,
[email protected]a9723e12013-03-05 04:02:45481 const base::RefCountedMemory* data,
[email protected]9848c7e2010-06-03 16:06:56482 const std::string& json_arguments,
[email protected]e39027a2011-01-24 21:41:54483 const string16& print_job_title,
[email protected]e8368e92011-08-20 04:05:56484 const string16& print_ticket,
[email protected]a984bdf2011-03-15 20:17:16485 const std::string& file_type,
[email protected]4cd49022012-01-19 20:37:37486 bool close_after_signin,
487 const base::Closure& callback)
[email protected]a9723e12013-03-05 04:02:45488 : flow_handler_(
489 new CloudPrintFlowHandler(data, print_job_title, print_ticket,
490 file_type, close_after_signin, callback)),
[email protected]b5b79d72012-05-24 19:42:28491 modal_parent_(modal_parent),
[email protected]6ddda232011-04-22 15:41:47492 owns_flow_handler_(true),
[email protected]b5b79d72012-05-24 19:42:28493 keep_alive_when_non_modal_(true) {
494 Init(browser_context, json_arguments);
[email protected]73852b8f2010-05-14 00:38:12495}
496
[email protected]05acb55472011-02-03 00:11:07497// For unit testing.
[email protected]5835871a2012-04-25 21:56:55498CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate(
[email protected]73852b8f2010-05-14 00:38:12499 CloudPrintFlowHandler* flow_handler,
[email protected]a9723e12013-03-05 04:02:45500 const std::string& json_arguments)
501 : flow_handler_(flow_handler),
[email protected]b5b79d72012-05-24 19:42:28502 modal_parent_(NULL),
503 owns_flow_handler_(true),
504 keep_alive_when_non_modal_(false) {
505 Init(NULL, json_arguments);
[email protected]73852b8f2010-05-14 00:38:12506}
507
[email protected]b5b79d72012-05-24 19:42:28508// Returns the persisted width/height for the print dialog.
509void GetDialogWidthAndHeightFromPrefs(content::BrowserContext* browser_context,
510 int* width,
511 int* height) {
[email protected]b5b79d72012-05-24 19:42:28512 if (!browser_context) {
513 *width = kDefaultWidth;
514 *height = kDefaultHeight;
515 return;
516 }
517
[email protected]c753f142013-02-10 13:14:04518 PrefService* prefs = Profile::FromBrowserContext(browser_context)->GetPrefs();
[email protected]c753f142013-02-10 13:14:04519 *width = prefs->GetInteger(prefs::kCloudPrintDialogWidth);
520 *height = prefs->GetInteger(prefs::kCloudPrintDialogHeight);
[email protected]b5b79d72012-05-24 19:42:28521}
522
523void CloudPrintWebDialogDelegate::Init(content::BrowserContext* browser_context,
[email protected]5835871a2012-04-25 21:56:55524 const std::string& json_arguments) {
[email protected]73852b8f2010-05-14 00:38:12525 // This information is needed to show the dialog HTML content.
[email protected]ba4f1132010-10-09 02:02:35526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]b5b79d72012-05-24 19:42:28527
[email protected]89f550b2011-06-08 18:34:03528 params_.url = GURL(chrome::kChromeUICloudPrintResourcesURL);
[email protected]b5b79d72012-05-24 19:42:28529 GetDialogWidthAndHeightFromPrefs(browser_context,
530 &params_.width,
531 &params_.height);
[email protected]73852b8f2010-05-14 00:38:12532 params_.json_input = json_arguments;
533
534 flow_handler_->SetDialogDelegate(this);
[email protected]e39027a2011-01-24 21:41:54535 // If we're not modal we can show the dialog with no browser.
536 // We need this to keep Chrome alive while our dialog is up.
[email protected]b5b79d72012-05-24 19:42:28537 if (!modal_parent_ && keep_alive_when_non_modal_)
[email protected]313fce12013-01-30 17:09:04538 chrome::StartKeepAlive();
[email protected]73852b8f2010-05-14 00:38:12539}
540
[email protected]5835871a2012-04-25 21:56:55541CloudPrintWebDialogDelegate::~CloudPrintWebDialogDelegate() {
[email protected]73852b8f2010-05-14 00:38:12542 // If the flow_handler_ is about to outlive us because we don't own
[email protected]a2c92a1c2012-04-03 12:32:14543 // it anymore, we need to have it remove its reference to us.
[email protected]ba4f1132010-10-09 02:02:35544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]73852b8f2010-05-14 00:38:12545 flow_handler_->SetDialogDelegate(NULL);
546 if (owns_flow_handler_) {
547 delete flow_handler_;
548 }
549}
550
[email protected]5835871a2012-04-25 21:56:55551ui::ModalType CloudPrintWebDialogDelegate::GetDialogModalType() const {
[email protected]b5b79d72012-05-24 19:42:28552 return modal_parent_ ? ui::MODAL_TYPE_WINDOW : ui::MODAL_TYPE_NONE;
[email protected]73852b8f2010-05-14 00:38:12553}
554
[email protected]5835871a2012-04-25 21:56:55555string16 CloudPrintWebDialogDelegate::GetDialogTitle() const {
[email protected]bdae5c12011-08-05 21:49:06556 return string16();
[email protected]73852b8f2010-05-14 00:38:12557}
558
[email protected]5835871a2012-04-25 21:56:55559GURL CloudPrintWebDialogDelegate::GetDialogContentURL() const {
[email protected]73852b8f2010-05-14 00:38:12560 return params_.url;
561}
562
[email protected]5835871a2012-04-25 21:56:55563void CloudPrintWebDialogDelegate::GetWebUIMessageHandlers(
[email protected]36e12172011-02-08 23:46:02564 std::vector<WebUIMessageHandler*>* handlers) const {
[email protected]73852b8f2010-05-14 00:38:12565 handlers->push_back(flow_handler_);
566 // We don't own flow_handler_ anymore, but it sticks around until at
567 // least right after OnDialogClosed() is called (and this object is
568 // destroyed).
569 owns_flow_handler_ = false;
570}
571
[email protected]5835871a2012-04-25 21:56:55572void CloudPrintWebDialogDelegate::GetDialogSize(gfx::Size* size) const {
[email protected]73852b8f2010-05-14 00:38:12573 size->set_width(params_.width);
574 size->set_height(params_.height);
575}
576
[email protected]5835871a2012-04-25 21:56:55577std::string CloudPrintWebDialogDelegate::GetDialogArgs() const {
[email protected]73852b8f2010-05-14 00:38:12578 return params_.json_input;
579}
580
[email protected]5835871a2012-04-25 21:56:55581void CloudPrintWebDialogDelegate::OnDialogClosed(
[email protected]73852b8f2010-05-14 00:38:12582 const std::string& json_retval) {
[email protected]ea161da2010-11-02 21:57:35583 // Get the final dialog size and store it.
584 flow_handler_->StoreDialogClientSize();
[email protected]6ddda232011-04-22 15:41:47585
[email protected]e39027a2011-01-24 21:41:54586 // If we're modal we can show the dialog with no browser.
587 // End the keep-alive so that Chrome can exit.
[email protected]129bedf2013-11-20 07:34:03588 if (!modal_parent_ && keep_alive_when_non_modal_) {
589 // Post to prevent recursive call tho this function.
590 base::MessageLoop::current()->PostTask(FROM_HERE,
591 base::Bind(&chrome::EndKeepAlive));
592 }
[email protected]73852b8f2010-05-14 00:38:12593 delete this;
594}
595
[email protected]5835871a2012-04-25 21:56:55596void CloudPrintWebDialogDelegate::OnCloseContents(WebContents* source,
597 bool* out_close_dialog) {
[email protected]18137e02010-05-25 21:10:35598 if (out_close_dialog)
599 *out_close_dialog = true;
600}
601
[email protected]5835871a2012-04-25 21:56:55602bool CloudPrintWebDialogDelegate::ShouldShowDialogTitle() const {
[email protected]ea161da2010-11-02 21:57:35603 return false;
604}
605
[email protected]5835871a2012-04-25 21:56:55606bool CloudPrintWebDialogDelegate::HandleContextMenu(
[email protected]35be7ec2012-02-12 20:42:51607 const content::ContextMenuParams& params) {
[email protected]34478212011-04-19 01:35:46608 return true;
609}
610
[email protected]a911c4e2012-10-12 00:37:57611bool CloudPrintWebDialogDelegate::HandleOpenURLFromTab(
612 content::WebContents* source,
613 const content::OpenURLParams& params,
614 content::WebContents** out_new_contents) {
615 return flow_handler_->NavigationToURLDidCloseDialog(params.url);
616}
617
[email protected]6085c70d2011-03-22 22:51:07618// Called from the UI thread, starts up the dialog.
[email protected]b5b79d72012-05-24 19:42:28619void CreateDialogImpl(content::BrowserContext* browser_context,
620 gfx::NativeWindow modal_parent,
[email protected]a9723e12013-03-05 04:02:45621 const base::RefCountedMemory* data,
[email protected]6085c70d2011-03-22 22:51:07622 const string16& print_job_title,
[email protected]e8368e92011-08-20 04:05:56623 const string16& print_ticket,
[email protected]6085c70d2011-03-22 22:51:07624 const std::string& file_type,
[email protected]4cd49022012-01-19 20:37:37625 bool close_after_signin,
626 const base::Closure& callback) {
[email protected]ba4f1132010-10-09 02:02:35627 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]5835871a2012-04-25 21:56:55628 WebDialogDelegate* dialog_delegate =
629 new internal_cloud_print_helpers::CloudPrintWebDialogDelegate(
[email protected]a9723e12013-03-05 04:02:45630 browser_context, modal_parent, data, std::string(), print_job_title,
631 print_ticket, file_type, close_after_signin, callback);
[email protected]88bfd25b2012-06-22 06:28:33632#if defined(OS_WIN)
633 gfx::NativeWindow window =
634#endif
[email protected]87586fb72012-07-02 13:15:02635 chrome::ShowWebDialog(modal_parent,
636 Profile::FromBrowserContext(browser_context),
637 dialog_delegate);
[email protected]88bfd25b2012-06-22 06:28:33638#if defined(OS_WIN)
[email protected]a9723e12013-03-05 04:02:45639 if (window) {
[email protected]88bfd25b2012-06-22 06:28:33640 HWND dialog_handle;
641#if defined(USE_AURA)
[email protected]228f0f02013-11-15 05:58:36642 dialog_handle = window->GetDispatcher()->host()->GetAcceleratedWidget();
[email protected]88bfd25b2012-06-22 06:28:33643#else
644 dialog_handle = window;
645#endif
646 if (::GetForegroundWindow() != dialog_handle) {
647 ui::ForegroundHelper::SetForeground(dialog_handle);
648 }
649 }
650#endif
[email protected]73852b8f2010-05-14 00:38:12651}
[email protected]6085c70d2011-03-22 22:51:07652
[email protected]b5b79d72012-05-24 19:42:28653void CreateDialogSigninImpl(content::BrowserContext* browser_context,
654 gfx::NativeWindow modal_parent,
655 const base::Closure& callback) {
[email protected]a9723e12013-03-05 04:02:45656 CreateDialogImpl(browser_context, modal_parent, NULL, string16(),
657 string16(), std::string(), true, callback);
[email protected]4cd49022012-01-19 20:37:37658}
659
[email protected]a9723e12013-03-05 04:02:45660void CreateDialogForFileImpl(content::BrowserContext* browser_context,
661 gfx::NativeWindow modal_parent,
662 const base::FilePath& path_to_file,
663 const string16& print_job_title,
664 const string16& print_ticket,
665 const std::string& file_type,
666 bool delete_on_close) {
667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
668 scoped_refptr<base::RefCountedMemory> data;
669 int64 file_size = 0;
670 if (file_util::GetFileSize(path_to_file, &file_size) && file_size != 0) {
671 std::string file_data;
672 if (file_size < kuint32max) {
673 file_data.reserve(static_cast<unsigned int>(file_size));
674 } else {
675 DLOG(WARNING) << " print data file too large to reserve space";
676 }
[email protected]82f84b92013-08-30 18:23:50677 if (base::ReadFileToString(path_to_file, &file_data)) {
[email protected]a9723e12013-03-05 04:02:45678 data = base::RefCountedString::TakeString(&file_data);
679 }
680 }
681 // Proceed even for empty data to simplify testing.
682 BrowserThread::PostTask(
683 BrowserThread::UI, FROM_HERE,
684 base::Bind(&print_dialog_cloud::CreatePrintDialogForBytes,
685 browser_context, modal_parent, data, print_job_title,
686 print_ticket, file_type));
687 if (delete_on_close)
[email protected]dd3aa792013-07-16 19:10:23688 base::DeleteFile(path_to_file, false);
[email protected]6ddda232011-04-22 15:41:47689}
690
[email protected]6085c70d2011-03-22 22:51:07691} // namespace internal_cloud_print_helpers
692
693namespace print_dialog_cloud {
694
[email protected]37ca3fe02013-07-05 15:32:44695void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
[email protected]681958c2013-02-21 13:48:14696 registry->RegisterIntegerPref(
697 prefs::kCloudPrintDialogWidth,
698 kDefaultWidth,
[email protected]443e9312013-05-06 06:17:34699 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]681958c2013-02-21 13:48:14700 registry->RegisterIntegerPref(
701 prefs::kCloudPrintDialogHeight,
702 kDefaultHeight,
[email protected]443e9312013-05-06 06:17:34703 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]681958c2013-02-21 13:48:14704}
705
[email protected]6085c70d2011-03-22 22:51:07706// Called on the FILE or UI thread. This is the main entry point into creating
707// the dialog.
708
[email protected]b5b79d72012-05-24 19:42:28709void CreatePrintDialogForFile(content::BrowserContext* browser_context,
710 gfx::NativeWindow modal_parent,
[email protected]650b2d52013-02-10 03:41:45711 const base::FilePath& path_to_file,
[email protected]6085c70d2011-03-22 22:51:07712 const string16& print_job_title,
[email protected]e8368e92011-08-20 04:05:56713 const string16& print_ticket,
[email protected]6085c70d2011-03-22 22:51:07714 const std::string& file_type,
[email protected]d955fc92011-09-19 20:49:03715 bool delete_on_close) {
[email protected]6085c70d2011-03-22 22:51:07716 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE) ||
717 BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]6085c70d2011-03-22 22:51:07718 BrowserThread::PostTask(
[email protected]a9723e12013-03-05 04:02:45719 BrowserThread::FILE, FROM_HERE,
720 base::Bind(&internal_cloud_print_helpers::CreateDialogForFileImpl,
[email protected]b5b79d72012-05-24 19:42:28721 browser_context, modal_parent, path_to_file, print_job_title,
722 print_ticket, file_type, delete_on_close));
[email protected]d955fc92011-09-19 20:49:03723}
724
[email protected]b5b79d72012-05-24 19:42:28725void CreateCloudPrintSigninDialog(content::BrowserContext* browser_context,
726 gfx::NativeWindow modal_parent,
727 const base::Closure& callback) {
[email protected]4cd49022012-01-19 20:37:37728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
729
730 BrowserThread::PostTask(
731 BrowserThread::UI, FROM_HERE,
732 base::Bind(&internal_cloud_print_helpers::CreateDialogSigninImpl,
[email protected]a9723e12013-03-05 04:02:45733 browser_context, modal_parent, callback));
[email protected]4cd49022012-01-19 20:37:37734}
735
[email protected]b5b79d72012-05-24 19:42:28736void CreatePrintDialogForBytes(content::BrowserContext* browser_context,
737 gfx::NativeWindow modal_parent,
[email protected]a9723e12013-03-05 04:02:45738 const base::RefCountedMemory* data,
[email protected]d955fc92011-09-19 20:49:03739 const string16& print_job_title,
740 const string16& print_ticket,
[email protected]b5b79d72012-05-24 19:42:28741 const std::string& file_type) {
[email protected]a9723e12013-03-05 04:02:45742 internal_cloud_print_helpers::CreateDialogImpl(browser_context, modal_parent,
743 data, print_job_title,
744 print_ticket, file_type, false,
745 base::Closure());
[email protected]6085c70d2011-03-22 22:51:07746}
747
[email protected]65c9d89a2011-04-13 21:02:39748bool CreatePrintDialogFromCommandLine(const CommandLine& command_line) {
[email protected]87ab41e72012-01-04 18:45:11749 DCHECK(command_line.HasSwitch(switches::kCloudPrintFile));
[email protected]65c9d89a2011-04-13 21:02:39750 if (!command_line.GetSwitchValuePath(switches::kCloudPrintFile).empty()) {
[email protected]650b2d52013-02-10 03:41:45751 base::FilePath cloud_print_file;
[email protected]65c9d89a2011-04-13 21:02:39752 cloud_print_file =
753 command_line.GetSwitchValuePath(switches::kCloudPrintFile);
754 if (!cloud_print_file.empty()) {
755 string16 print_job_title;
[email protected]e8368e92011-08-20 04:05:56756 string16 print_job_print_ticket;
[email protected]65c9d89a2011-04-13 21:02:39757 if (command_line.HasSwitch(switches::kCloudPrintJobTitle)) {
[email protected]e8368e92011-08-20 04:05:56758 print_job_title =
759 internal_cloud_print_helpers::GetSwitchValueString16(
760 command_line, switches::kCloudPrintJobTitle);
761 }
762 if (command_line.HasSwitch(switches::kCloudPrintPrintTicket)) {
763 print_job_print_ticket =
764 internal_cloud_print_helpers::GetSwitchValueString16(
765 command_line, switches::kCloudPrintPrintTicket);
[email protected]65c9d89a2011-04-13 21:02:39766 }
767 std::string file_type = "application/pdf";
768 if (command_line.HasSwitch(switches::kCloudPrintFileType)) {
769 file_type = command_line.GetSwitchValueASCII(
770 switches::kCloudPrintFileType);
771 }
[email protected]e8368e92011-08-20 04:05:56772
[email protected]d955fc92011-09-19 20:49:03773 bool delete_on_close = CommandLine::ForCurrentProcess()->HasSwitch(
774 switches::kCloudPrintDeleteFile);
775
[email protected]b5b79d72012-05-24 19:42:28776 print_dialog_cloud::CreatePrintDialogForFile(
777 ProfileManager::GetDefaultProfile(),
778 NULL,
779 cloud_print_file,
780 print_job_title,
781 print_job_print_ticket,
782 file_type,
783 delete_on_close);
[email protected]65c9d89a2011-04-13 21:02:39784 return true;
785 }
786 }
787 return false;
788}
789
[email protected]228f0f02013-11-15 05:58:36790} // namespace print_dialog_cloud