blob: 6d92817a77383155be327ab1cfa17a8e14607b04 [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]4c2eb402014-06-13 02:18:5617#include "chrome/browser/browser_process.h"
[email protected]70019152012-12-19 11:44:1918#include "chrome/browser/devtools/devtools_window.h"
[email protected]2e6389f2012-05-18 19:41:2519#include "chrome/browser/lifetime/application_lifetime.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]6c465292014-01-14 15:38:3122#include "chrome/browser/ui/browser.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]09cff78782014-04-20 22:04:4828#include "components/cloud_devices/common/cloud_devices_urls.h"
[email protected]8e44a5b02014-06-19 19:03:2429#include "components/google/core/browser/google_util.h"
[email protected]f0c8c4992014-05-15 17:37:2630#include "components/pref_registry/pref_registry_syncable.h"
[email protected]c38831a12011-10-28 12:44:4931#include "content/public/browser/browser_thread.h"
[email protected]cdcb1dee2012-01-04 00:46:2032#include "content/public/browser/navigation_controller.h"
[email protected]022af742011-12-28 18:37:2533#include "content/public/browser/navigation_entry.h"
[email protected]6c2381d2011-10-19 02:52:5334#include "content/public/browser/notification_registrar.h"
35#include "content/public/browser/notification_source.h"
[email protected]0d6e9bd2011-10-18 04:29:1636#include "content/public/browser/notification_types.h"
[email protected]9c1662b2012-03-06 15:44:3337#include "content/public/browser/render_view_host.h"
[email protected]0ec4898e2011-12-30 21:09:2438#include "content/public/browser/web_contents.h"
[email protected]6c465292014-01-14 15:38:3139#include "content/public/browser/web_contents_observer.h"
[email protected]01ec4ec2012-01-18 04:13:4740#include "content/public/browser/web_ui.h"
[email protected]6c465292014-01-14 15:38:3141#include "content/public/common/frame_navigate_params.h"
[email protected]fab55e72013-05-31 07:06:1842#include "webkit/common/webpreferences.h"
[email protected]520c2022012-03-15 00:13:1543
[email protected]88bfd25b2012-06-22 06:28:3344#if defined(USE_AURA)
[email protected]88bfd25b2012-06-22 06:28:3345#include "ui/aura/window.h"
[email protected]7a60cd3a2014-03-20 20:54:5746#include "ui/aura/window_tree_host.h"
[email protected]88bfd25b2012-06-22 06:28:3347#endif
48
[email protected]520c2022012-03-15 00:13:1549#if defined(OS_WIN)
50#include "ui/base/win/foreground_helper.h"
51#endif
52
[email protected]73852b8f2010-05-14 00:38:1253// This module implements the UI support in Chrome for cloud printing.
54// This means hosting a dialog containing HTML/JavaScript and using
55// the published cloud print user interface integration APIs to get
56// page setup settings from the dialog contents and provide the
[email protected]a984bdf2011-03-15 20:17:1657// generated print data to the dialog contents for uploading to the
[email protected]73852b8f2010-05-14 00:38:1258// cloud print service.
59
60// Currently, the flow between these classes is as follows:
61
[email protected]a984bdf2011-03-15 20:17:1662// PrintDialogCloud::CreatePrintDialogForFile is called from
[email protected]73852b8f2010-05-14 00:38:1263// resource_message_filter_gtk.cc once the renderer has informed the
[email protected]a984bdf2011-03-15 20:17:1664// renderer host that print data generation into the renderer host provided
[email protected]032682b2011-01-12 22:05:0265// temp file has been completed. That call is on the FILE thread.
[email protected]73852b8f2010-05-14 00:38:1266// That, in turn, hops over to the UI thread to create an instance of
67// PrintDialogCloud.
68
69// The constructor for PrintDialogCloud creates a
[email protected]5835871a2012-04-25 21:56:5570// CloudPrintWebDialogDelegate and asks the current active browser to
[email protected]73852b8f2010-05-14 00:38:1271// show an HTML dialog using that class as the delegate. That class
[email protected]89f550b2011-06-08 18:34:0372// hands in the kChromeUICloudPrintResourcesURL as the URL to visit. That is
[email protected]80a8fad2011-01-29 04:02:3873// recognized by the GetWebUIFactoryFunction as a signal to create an
[email protected]02b5ccc2012-04-30 23:58:3174// ExternalWebDialogUI.
[email protected]73852b8f2010-05-14 00:38:1275
[email protected]5835871a2012-04-25 21:56:5576// CloudPrintWebDialogDelegate also temporarily owns a
[email protected]73852b8f2010-05-14 00:38:1277// CloudPrintFlowHandler, a class which is responsible for the actual
[email protected]a984bdf2011-03-15 20:17:1678// interactions with the dialog contents, including handing in the
[email protected]73852b8f2010-05-14 00:38:1279// print data and getting any page setup parameters that the dialog
80// contents provides. As part of bringing up the dialog,
[email protected]02b5ccc2012-04-30 23:58:3181// WebDialogUI::RenderViewCreated is called (an override of
[email protected]c39f9bf2011-02-12 00:43:5582// WebUI::RenderViewCreated). That routine, in turn, calls the
[email protected]36e12172011-02-08 23:46:0283// delegate's GetWebUIMessageHandlers routine, at which point the
[email protected]73852b8f2010-05-14 00:38:1284// ownership of the CloudPrintFlowHandler is handed over. A pointer
85// to the flow handler is kept to facilitate communication back and
86// forth between the two classes.
87
[email protected]c39f9bf2011-02-12 00:43:5588// The WebUI continues dialog bring-up, calling
[email protected]73852b8f2010-05-14 00:38:1289// CloudPrintFlowHandler::RegisterMessages. This is where the
90// additional object model capabilities are registered for the dialog
91// contents to use. It is also at this time that capabilities for the
92// dialog contents are adjusted to allow the dialog contents to close
93// the window. In addition, the pending URL is redirected to the
94// actual cloud print service URL. The flow controller also registers
95// for notification of when the dialog contents finish loading, which
[email protected]a984bdf2011-03-15 20:17:1696// is currently used to send the data to the dialog contents.
[email protected]73852b8f2010-05-14 00:38:1297
[email protected]a984bdf2011-03-15 20:17:1698// In order to send the data to the dialog contents, the flow
[email protected]73852b8f2010-05-14 00:38:1299// handler uses a CloudPrintDataSender. It creates one, letting it
[email protected]a984bdf2011-03-15 20:17:16100// know the name of the temporary file containing the data, and
[email protected]73852b8f2010-05-14 00:38:12101// posts the task of reading the file
102// (CloudPrintDataSender::ReadPrintDataFile) to the file thread. That
103// routine reads in the file, and then hops over to the IO thread to
104// send that data to the dialog contents.
105
106// When the dialog contents are finished (by either being cancelled or
107// hitting the print button), the delegate is notified, and responds
108// that the dialog should be closed, at which point things are torn
109// down and released.
110
[email protected]631bb742011-11-02 11:29:39111using content::BrowserThread;
[email protected]c5eed492012-01-04 17:07:50112using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23113using content::NavigationEntry;
[email protected]eaabba22012-03-07 15:02:11114using content::RenderViewHost;
[email protected]a81343d232011-12-27 07:39:20115using content::WebContents;
[email protected]26e2632a2011-12-31 04:02:55116using content::WebUIMessageHandler;
[email protected]20c07f8e2012-05-31 08:43:14117using ui::WebDialogDelegate;
[email protected]631bb742011-11-02 11:29:39118
[email protected]6c465292014-01-14 15:38:31119namespace {
120
[email protected]681958c2013-02-21 13:48:14121const int kDefaultWidth = 912;
122const int kDefaultHeight = 633;
123
[email protected]6c465292014-01-14 15:38:31124bool IsSimilarUrl(const GURL& url, const GURL& cloud_print_url) {
125 return url.host() == cloud_print_url.host() &&
126 StartsWithASCII(url.path(), cloud_print_url.path(), false) &&
127 url.scheme() == cloud_print_url.scheme();
128}
129
130class SignInObserver : public content::WebContentsObserver {
131 public:
132 SignInObserver(content::WebContents* web_contents,
133 GURL cloud_print_url,
134 const base::Closure& callback)
135 : WebContentsObserver(web_contents),
136 cloud_print_url_(cloud_print_url),
137 callback_(callback),
138 weak_ptr_factory_(this) {
139 }
140
141 private:
142 // Overridden from content::WebContentsObserver:
143 virtual void DidNavigateMainFrame(
144 const content::LoadCommittedDetails& details,
145 const content::FrameNavigateParams& params) OVERRIDE {
146 if (IsSimilarUrl(params.url, cloud_print_url_)) {
147 base::MessageLoop::current()->PostTask(
148 FROM_HERE,
149 base::Bind(&SignInObserver::OnSignIn,
150 weak_ptr_factory_.GetWeakPtr()));
151 }
152 }
153
[email protected]12a46832014-05-09 13:35:58154 virtual void WebContentsDestroyed() OVERRIDE {
[email protected]6c465292014-01-14 15:38:31155 delete this;
156 }
157
158 void OnSignIn() {
159 callback_.Run();
160 if (web_contents())
161 web_contents()->Close();
162 }
163
164 GURL cloud_print_url_;
165 base::Closure callback_;
166 base::WeakPtrFactory<SignInObserver> weak_ptr_factory_;
167
168 DISALLOW_COPY_AND_ASSIGN(SignInObserver);
169};
170
171} // namespace
172
[email protected]73852b8f2010-05-14 00:38:12173namespace internal_cloud_print_helpers {
174
[email protected]73852b8f2010-05-14 00:38:12175// From the JSON parsed value, get the entries for the page setup
176// parameters.
177bool GetPageSetupParameters(const std::string& json,
[email protected]1375e3ab2011-03-24 17:07:22178 PrintMsg_Print_Params& parameters) {
[email protected]dbb9aa42013-12-23 20:08:21179 scoped_ptr<base::Value> parsed_value(base::JSONReader::Read(json));
[email protected]73852b8f2010-05-14 00:38:12180 DLOG_IF(ERROR, (!parsed_value.get() ||
[email protected]dbb9aa42013-12-23 20:08:21181 !parsed_value->IsType(base::Value::TYPE_DICTIONARY)))
[email protected]73852b8f2010-05-14 00:38:12182 << "PageSetup call didn't have expected contents";
[email protected]dbb9aa42013-12-23 20:08:21183 if (!parsed_value.get() ||
184 !parsed_value->IsType(base::Value::TYPE_DICTIONARY)) {
[email protected]73852b8f2010-05-14 00:38:12185 return false;
[email protected]dbb9aa42013-12-23 20:08:21186 }
[email protected]73852b8f2010-05-14 00:38:12187
188 bool result = true;
[email protected]dbb9aa42013-12-23 20:08:21189 base::DictionaryValue* params =
190 static_cast<base::DictionaryValue*>(parsed_value.get());
[email protected]05c7da62011-05-05 17:23:56191 result &= params->GetDouble("dpi", &parameters.dpi);
192 result &= params->GetDouble("min_shrink", &parameters.min_shrink);
193 result &= params->GetDouble("max_shrink", &parameters.max_shrink);
[email protected]a65175d2010-08-17 04:00:57194 result &= params->GetBoolean("selection_only", &parameters.selection_only);
[email protected]73852b8f2010-05-14 00:38:12195 return result;
196}
197
[email protected]536f86a2013-11-23 01:24:56198base::string16 GetSwitchValueString16(const CommandLine& command_line,
199 const char* switchName) {
[email protected]31662202013-03-23 19:10:54200#if defined(OS_WIN)
[email protected]536f86a2013-11-23 01:24:56201 return command_line.GetSwitchValueNative(switchName);
[email protected]e8368e92011-08-20 04:05:56202#elif defined(OS_POSIX)
203 // POSIX Command line string types are different.
204 CommandLine::StringType native_switch_val;
205 native_switch_val = command_line.GetSwitchValueASCII(switchName);
206 // Convert the ASCII string to UTF16 to prepare to pass.
[email protected]536f86a2013-11-23 01:24:56207 return base::ASCIIToUTF16(native_switch_val);
[email protected]e8368e92011-08-20 04:05:56208#endif
209}
210
[email protected]73852b8f2010-05-14 00:38:12211void CloudPrintDataSenderHelper::CallJavascriptFunction(
[email protected]dbb9aa42013-12-23 20:08:21212 const std::string& function_name,
213 const base::Value& arg1,
214 const base::Value& arg2) {
[email protected]536f86a2013-11-23 01:24:56215 web_ui_->CallJavascriptFunction(function_name, arg1, arg2);
[email protected]e8368e92011-08-20 04:05:56216}
217
[email protected]73852b8f2010-05-14 00:38:12218// Clears out the pointer we're using to communicate. Either routine is
219// potentially expensive enough that stopping whatever is in progress
220// is worth it.
221void CloudPrintDataSender::CancelPrintDataFile() {
[email protected]20305ec2011-01-21 04:55:52222 base::AutoLock lock(lock_);
[email protected]73852b8f2010-05-14 00:38:12223 // We don't own helper, it was passed in to us, so no need to
224 // delete, just let it go.
225 helper_ = NULL;
226}
227
[email protected]0085863a2013-12-06 21:19:03228CloudPrintDataSender::CloudPrintDataSender(
229 CloudPrintDataSenderHelper* helper,
230 const base::string16& print_job_title,
231 const base::string16& print_ticket,
232 const std::string& file_type,
233 const base::RefCountedMemory* data)
[email protected]38e08982010-10-22 17:28:43234 : helper_(helper),
[email protected]a984bdf2011-03-15 20:17:16235 print_job_title_(print_job_title),
[email protected]e8368e92011-08-20 04:05:56236 print_ticket_(print_ticket),
[email protected]a9723e12013-03-05 04:02:45237 file_type_(file_type),
238 data_(data) {
[email protected]38e08982010-10-22 17:28:43239}
240
241CloudPrintDataSender::~CloudPrintDataSender() {}
242
[email protected]73852b8f2010-05-14 00:38:12243// We have the data in hand that needs to be pushed into the dialog
244// contents; do so from the IO thread.
245
246// TODO(scottbyer): If the print data ends up being larger than the
247// upload limit (currently 10MB), what we need to do is upload that
248// large data to google docs and set the URL in the printing
249// JavaScript to that location, and make sure it gets deleted when not
250// needed. - 4/1/2010
[email protected]a9723e12013-03-05 04:02:45251void CloudPrintDataSender::SendPrintData() {
[email protected]dee01572014-04-18 22:33:44252 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]5173de8b2013-06-02 21:16:02253 if (!data_.get() || !data_->size())
[email protected]a9723e12013-03-05 04:02:45254 return;
255
256 std::string base64_data;
257 base::Base64Encode(
[email protected]8df08cf2014-02-12 22:34:08258 base::StringPiece(data_->front_as<char>(), data_->size()),
[email protected]a9723e12013-03-05 04:02:45259 &base64_data);
[email protected]a9723e12013-03-05 04:02:45260 std::string header("data:");
261 header.append(file_type_);
262 header.append(";base64,");
263 base64_data.insert(0, header);
264
[email protected]20305ec2011-01-21 04:55:52265 base::AutoLock lock(lock_);
[email protected]a9723e12013-03-05 04:02:45266 if (helper_) {
[email protected]536f86a2013-11-23 01:24:56267 base::StringValue title(print_job_title_);
268 base::StringValue ticket(print_ticket_);
[email protected]e8368e92011-08-20 04:05:56269 // TODO(abodenha): Change Javascript call to pass in print ticket
270 // after server side support is added. Add test for it.
[email protected]73852b8f2010-05-14 00:38:12271
272 // Send the print data to the dialog contents. The JavaScript
273 // function is a preliminary API for prototyping purposes and is
274 // subject to change.
[email protected]536f86a2013-11-23 01:24:56275 helper_->CallJavascriptFunction(
276 "printApp._printDataUrl", base::StringValue(base64_data), title);
[email protected]73852b8f2010-05-14 00:38:12277 }
278}
279
280
[email protected]0085863a2013-12-06 21:19:03281CloudPrintFlowHandler::CloudPrintFlowHandler(
282 const base::RefCountedMemory* data,
283 const base::string16& print_job_title,
284 const base::string16& print_ticket,
[email protected]6c465292014-01-14 15:38:31285 const std::string& file_type)
[email protected]c7bf7452011-09-12 21:31:50286 : dialog_delegate_(NULL),
[email protected]a9723e12013-03-05 04:02:45287 data_(data),
[email protected]a984bdf2011-03-15 20:17:16288 print_job_title_(print_job_title),
[email protected]e8368e92011-08-20 04:05:56289 print_ticket_(print_ticket),
[email protected]6c465292014-01-14 15:38:31290 file_type_(file_type) {
[email protected]38e08982010-10-22 17:28:43291}
292
293CloudPrintFlowHandler::~CloudPrintFlowHandler() {
294 // This will also cancel any task in flight.
295 CancelAnyRunningTask();
296}
297
298
[email protected]73852b8f2010-05-14 00:38:12299void CloudPrintFlowHandler::SetDialogDelegate(
[email protected]5835871a2012-04-25 21:56:55300 CloudPrintWebDialogDelegate* delegate) {
[email protected]7b748982011-02-14 19:28:23301 // Even if setting a new WebUI, it means any previous task needs
[email protected]a2c92a1c2012-04-03 12:32:14302 // to be canceled, its now invalid.
[email protected]dee01572014-04-18 22:33:44303 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]73852b8f2010-05-14 00:38:12304 CancelAnyRunningTask();
305 dialog_delegate_ = delegate;
306}
307
308// Cancels any print data sender we have in flight and removes our
309// reference to it, so when the task that is calling it finishes and
[email protected]a2c92a1c2012-04-03 12:32:14310// removes its reference, it goes away.
[email protected]73852b8f2010-05-14 00:38:12311void CloudPrintFlowHandler::CancelAnyRunningTask() {
[email protected]dee01572014-04-18 22:33:44312 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]73852b8f2010-05-14 00:38:12313 if (print_data_sender_.get()) {
314 print_data_sender_->CancelPrintDataFile();
315 print_data_sender_ = NULL;
316 }
317}
318
[email protected]73852b8f2010-05-14 00:38:12319void CloudPrintFlowHandler::RegisterMessages() {
[email protected]73852b8f2010-05-14 00:38:12320 // TODO(scottbyer) - This is where we will register messages for the
321 // UI JS to use. Needed: Call to update page setup parameters.
[email protected]46adf7ff2011-12-30 00:53:09322 web_ui()->RegisterMessageCallback("ShowDebugger",
[email protected]ba4fc242011-10-04 18:56:56323 base::Bind(&CloudPrintFlowHandler::HandleShowDebugger,
324 base::Unretained(this)));
[email protected]46adf7ff2011-12-30 00:53:09325 web_ui()->RegisterMessageCallback("SendPrintData",
[email protected]ba4fc242011-10-04 18:56:56326 base::Bind(&CloudPrintFlowHandler::HandleSendPrintData,
327 base::Unretained(this)));
[email protected]46adf7ff2011-12-30 00:53:09328 web_ui()->RegisterMessageCallback("SetPageParameters",
[email protected]ba4fc242011-10-04 18:56:56329 base::Bind(&CloudPrintFlowHandler::HandleSetPageParameters,
330 base::Unretained(this)));
[email protected]73852b8f2010-05-14 00:38:12331
[email protected]0eb25c42011-08-11 14:50:14332 // Register for appropriate notifications, and re-direct the URL
333 // to the real server URL, now that we've gotten an HTML dialog
334 // going.
[email protected]c5eed492012-01-04 17:07:50335 NavigationController* controller =
[email protected]01ec4ec2012-01-18 04:13:47336 &web_ui()->GetWebContents()->GetController();
[email protected]10f417c52011-12-28 21:04:23337 NavigationEntry* pending_entry = controller->GetPendingEntry();
[email protected]0eb25c42011-08-11 14:50:14338 if (pending_entry) {
[email protected]09cff78782014-04-20 22:04:48339 pending_entry->SetURL(google_util::AppendGoogleLocaleParam(
[email protected]4c2eb402014-06-13 02:18:56340 cloud_devices::GetCloudPrintRelativeURL("client/dialog.html"),
341 g_browser_process->GetApplicationLocale()));
[email protected]73852b8f2010-05-14 00:38:12342 }
[email protected]0eb25c42011-08-11 14:50:14343 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50344 content::Source<NavigationController>(controller));
[email protected]57c8cf22013-03-02 16:50:00345 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
346 content::Source<NavigationController>(controller));
[email protected]73852b8f2010-05-14 00:38:12347}
348
[email protected]6c2381d2011-10-19 02:52:53349void CloudPrintFlowHandler::Observe(
350 int type,
351 const content::NotificationSource& source,
352 const content::NotificationDetails& details) {
[email protected]57c8cf22013-03-02 16:50:00353 switch (type) {
[email protected]57c8cf22013-03-02 16:50:00354 case content::NOTIFICATION_LOAD_STOP: {
[email protected]57c8cf22013-03-02 16:50:00355 GURL url = web_ui()->GetWebContents()->GetURL();
[email protected]6e536cdf2013-05-09 04:49:52356 if (IsCloudPrintDialogUrl(url)) {
357 // Take the opportunity to set some (minimal) additional
358 // script permissions required for the web UI.
[email protected]57c8cf22013-03-02 16:50:00359 RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost();
360 if (rvh) {
[email protected]3184f90b2013-05-01 18:17:53361 WebPreferences webkit_prefs = rvh->GetWebkitPreferences();
[email protected]57c8cf22013-03-02 16:50:00362 webkit_prefs.allow_scripts_to_close_windows = true;
363 rvh->UpdateWebkitPreferences(webkit_prefs);
364 } else {
365 NOTREACHED();
366 }
[email protected]6e536cdf2013-05-09 04:49:52367 // Choose one or the other. If you need to debug, bring up the
368 // debugger. You can then use the various chrome.send()
369 // registrations above to kick of the various function calls,
370 // including chrome.send("SendPrintData") in the javaScript
371 // console and watch things happen with:
372 // HandleShowDebugger(NULL);
373 HandleSendPrintData(NULL);
[email protected]57c8cf22013-03-02 16:50:00374 }
[email protected]57c8cf22013-03-02 16:50:00375 break;
376 }
[email protected]73852b8f2010-05-14 00:38:12377 }
378}
379
[email protected]dbb9aa42013-12-23 20:08:21380void CloudPrintFlowHandler::HandleShowDebugger(const base::ListValue* args) {
[email protected]73852b8f2010-05-14 00:38:12381 ShowDebugger();
382}
383
384void CloudPrintFlowHandler::ShowDebugger() {
[email protected]46adf7ff2011-12-30 00:53:09385 if (web_ui()) {
[email protected]01ec4ec2012-01-18 04:13:47386 RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost();
[email protected]73852b8f2010-05-14 00:38:12387 if (rvh)
[email protected]aebdd072011-07-07 12:36:59388 DevToolsWindow::OpenDevToolsWindow(rvh);
[email protected]73852b8f2010-05-14 00:38:12389 }
390}
391
392scoped_refptr<CloudPrintDataSender>
393CloudPrintFlowHandler::CreateCloudPrintDataSender() {
[email protected]46adf7ff2011-12-30 00:53:09394 DCHECK(web_ui());
395 print_data_helper_.reset(new CloudPrintDataSenderHelper(web_ui()));
[email protected]a9723e12013-03-05 04:02:45396 scoped_refptr<CloudPrintDataSender> sender(
[email protected]5173de8b2013-06-02 21:16:02397 new CloudPrintDataSender(print_data_helper_.get(),
398 print_job_title_,
399 print_ticket_,
400 file_type_,
401 data_.get()));
[email protected]a9723e12013-03-05 04:02:45402 return sender;
[email protected]73852b8f2010-05-14 00:38:12403}
404
[email protected]dbb9aa42013-12-23 20:08:21405void CloudPrintFlowHandler::HandleSendPrintData(const base::ListValue* args) {
[email protected]dee01572014-04-18 22:33:44406 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]73852b8f2010-05-14 00:38:12407 // This will cancel any ReadPrintDataFile() or SendPrintDataFile()
408 // requests in flight (this is anticipation of when setting page
409 // setup parameters becomes asynchronous and may be set while some
410 // data is in flight). Then we can clear out the print data.
411 CancelAnyRunningTask();
[email protected]46adf7ff2011-12-30 00:53:09412 if (web_ui()) {
[email protected]73852b8f2010-05-14 00:38:12413 print_data_sender_ = CreateCloudPrintDataSender();
[email protected]3e2dd4fa2011-11-10 06:06:40414 BrowserThread::PostTask(
[email protected]a9723e12013-03-05 04:02:45415 BrowserThread::IO, FROM_HERE,
416 base::Bind(&CloudPrintDataSender::SendPrintData, print_data_sender_));
[email protected]73852b8f2010-05-14 00:38:12417 }
418}
419
[email protected]dbb9aa42013-12-23 20:08:21420void CloudPrintFlowHandler::HandleSetPageParameters(
421 const base::ListValue* args) {
[email protected]036056a32011-03-03 21:05:01422 std::string json;
[email protected]e675f7b2011-06-22 17:32:12423 bool ret = args->GetString(0, &json);
424 if (!ret || json.empty()) {
[email protected]036056a32011-03-03 21:05:01425 NOTREACHED() << "Empty json string";
[email protected]73852b8f2010-05-14 00:38:12426 return;
[email protected]036056a32011-03-03 21:05:01427 }
[email protected]73852b8f2010-05-14 00:38:12428
429 // These are backstop default values - 72 dpi to match the screen,
430 // 8.5x11 inch paper with margins subtracted (1/4 inch top, left,
431 // right and 0.56 bottom), and the min page shrink and max page
432 // shrink values appear all over the place with no explanation.
433
434 // TODO(scottbyer): Get a Linux/ChromeOS edge for PrintSettings
435 // working so that we can get the default values from there. Fix up
436 // PrintWebViewHelper to do the same.
437 const int kDPI = 72;
438 const int kWidth = static_cast<int>((8.5-0.25-0.25)*kDPI);
439 const int kHeight = static_cast<int>((11-0.25-0.56)*kDPI);
440 const double kMinPageShrink = 1.25;
441 const double kMaxPageShrink = 2.0;
442
[email protected]1375e3ab2011-03-24 17:07:22443 PrintMsg_Print_Params default_settings;
[email protected]10980442011-12-04 22:33:05444 default_settings.content_size = gfx::Size(kWidth, kHeight);
[email protected]732b8132012-01-10 23:17:32445 default_settings.printable_area = gfx::Rect(0, 0, kWidth, kHeight);
[email protected]73852b8f2010-05-14 00:38:12446 default_settings.dpi = kDPI;
447 default_settings.min_shrink = kMinPageShrink;
448 default_settings.max_shrink = kMaxPageShrink;
449 default_settings.desired_dpi = kDPI;
450 default_settings.document_cookie = 0;
451 default_settings.selection_only = false;
[email protected]718af822011-08-12 22:11:33452 default_settings.preview_request_id = 0;
453 default_settings.is_first_request = true;
[email protected]732b8132012-01-10 23:17:32454 default_settings.print_to_pdf = false;
[email protected]73852b8f2010-05-14 00:38:12455
456 if (!GetPageSetupParameters(json, default_settings)) {
457 NOTREACHED();
458 return;
459 }
460
461 // TODO(scottbyer) - Here is where we would kick the originating
462 // renderer thread with these new parameters in order to get it to
[email protected]a984bdf2011-03-15 20:17:16463 // re-generate the PDF data and hand it back to us. window.print() is
[email protected]73852b8f2010-05-14 00:38:12464 // currently synchronous, so there's a lot of work to do to get to
465 // that point.
466}
467
[email protected]ea161da2010-11-02 21:57:35468void CloudPrintFlowHandler::StoreDialogClientSize() const {
[email protected]fc2b46b2014-05-03 16:33:45469 if (web_ui() && web_ui()->GetWebContents()) {
470 gfx::Size size = web_ui()->GetWebContents()->GetContainerBounds().size();
[email protected]46adf7ff2011-12-30 00:53:09471 Profile* profile = Profile::FromWebUI(web_ui());
[email protected]0eb25c42011-08-11 14:50:14472 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogWidth,
473 size.width());
474 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogHeight,
475 size.height());
[email protected]ea161da2010-11-02 21:57:35476 }
477}
478
[email protected]6e536cdf2013-05-09 04:49:52479bool CloudPrintFlowHandler::IsCloudPrintDialogUrl(const GURL& url) {
[email protected]09cff78782014-04-20 22:04:48480 GURL cloud_print_url = cloud_devices::GetCloudPrintURL();
[email protected]6c465292014-01-14 15:38:31481 return IsSimilarUrl(url, cloud_print_url);
[email protected]6e536cdf2013-05-09 04:49:52482}
483
[email protected]5835871a2012-04-25 21:56:55484CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate(
[email protected]b5b79d72012-05-24 19:42:28485 content::BrowserContext* browser_context,
486 gfx::NativeWindow modal_parent,
[email protected]a9723e12013-03-05 04:02:45487 const base::RefCountedMemory* data,
[email protected]9848c7e2010-06-03 16:06:56488 const std::string& json_arguments,
[email protected]0085863a2013-12-06 21:19:03489 const base::string16& print_job_title,
490 const base::string16& print_ticket,
[email protected]6c465292014-01-14 15:38:31491 const std::string& file_type)
[email protected]a9723e12013-03-05 04:02:45492 : flow_handler_(
493 new CloudPrintFlowHandler(data, print_job_title, print_ticket,
[email protected]6c465292014-01-14 15:38:31494 file_type)),
[email protected]b5b79d72012-05-24 19:42:28495 modal_parent_(modal_parent),
[email protected]6ddda232011-04-22 15:41:47496 owns_flow_handler_(true),
[email protected]b5b79d72012-05-24 19:42:28497 keep_alive_when_non_modal_(true) {
498 Init(browser_context, json_arguments);
[email protected]73852b8f2010-05-14 00:38:12499}
500
[email protected]05acb55472011-02-03 00:11:07501// For unit testing.
[email protected]5835871a2012-04-25 21:56:55502CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate(
[email protected]73852b8f2010-05-14 00:38:12503 CloudPrintFlowHandler* flow_handler,
[email protected]a9723e12013-03-05 04:02:45504 const std::string& json_arguments)
505 : flow_handler_(flow_handler),
[email protected]b5b79d72012-05-24 19:42:28506 modal_parent_(NULL),
507 owns_flow_handler_(true),
508 keep_alive_when_non_modal_(false) {
509 Init(NULL, json_arguments);
[email protected]73852b8f2010-05-14 00:38:12510}
511
[email protected]b5b79d72012-05-24 19:42:28512// Returns the persisted width/height for the print dialog.
513void GetDialogWidthAndHeightFromPrefs(content::BrowserContext* browser_context,
514 int* width,
515 int* height) {
[email protected]b5b79d72012-05-24 19:42:28516 if (!browser_context) {
517 *width = kDefaultWidth;
518 *height = kDefaultHeight;
519 return;
520 }
521
[email protected]c753f142013-02-10 13:14:04522 PrefService* prefs = Profile::FromBrowserContext(browser_context)->GetPrefs();
[email protected]c753f142013-02-10 13:14:04523 *width = prefs->GetInteger(prefs::kCloudPrintDialogWidth);
524 *height = prefs->GetInteger(prefs::kCloudPrintDialogHeight);
[email protected]b5b79d72012-05-24 19:42:28525}
526
527void CloudPrintWebDialogDelegate::Init(content::BrowserContext* browser_context,
[email protected]5835871a2012-04-25 21:56:55528 const std::string& json_arguments) {
[email protected]73852b8f2010-05-14 00:38:12529 // This information is needed to show the dialog HTML content.
[email protected]dee01572014-04-18 22:33:44530 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]b5b79d72012-05-24 19:42:28531
[email protected]89f550b2011-06-08 18:34:03532 params_.url = GURL(chrome::kChromeUICloudPrintResourcesURL);
[email protected]b5b79d72012-05-24 19:42:28533 GetDialogWidthAndHeightFromPrefs(browser_context,
534 &params_.width,
535 &params_.height);
[email protected]73852b8f2010-05-14 00:38:12536 params_.json_input = json_arguments;
537
538 flow_handler_->SetDialogDelegate(this);
[email protected]e39027a2011-01-24 21:41:54539 // If we're not modal we can show the dialog with no browser.
540 // We need this to keep Chrome alive while our dialog is up.
[email protected]b5b79d72012-05-24 19:42:28541 if (!modal_parent_ && keep_alive_when_non_modal_)
[email protected]9a718b22014-02-25 15:17:27542 chrome::IncrementKeepAliveCount();
[email protected]73852b8f2010-05-14 00:38:12543}
544
[email protected]5835871a2012-04-25 21:56:55545CloudPrintWebDialogDelegate::~CloudPrintWebDialogDelegate() {
[email protected]73852b8f2010-05-14 00:38:12546 // If the flow_handler_ is about to outlive us because we don't own
[email protected]a2c92a1c2012-04-03 12:32:14547 // it anymore, we need to have it remove its reference to us.
[email protected]dee01572014-04-18 22:33:44548 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]73852b8f2010-05-14 00:38:12549 flow_handler_->SetDialogDelegate(NULL);
550 if (owns_flow_handler_) {
551 delete flow_handler_;
552 }
553}
554
[email protected]5835871a2012-04-25 21:56:55555ui::ModalType CloudPrintWebDialogDelegate::GetDialogModalType() const {
[email protected]b5b79d72012-05-24 19:42:28556 return modal_parent_ ? ui::MODAL_TYPE_WINDOW : ui::MODAL_TYPE_NONE;
[email protected]73852b8f2010-05-14 00:38:12557}
558
[email protected]6a72a632013-12-12 22:22:00559base::string16 CloudPrintWebDialogDelegate::GetDialogTitle() const {
[email protected]0085863a2013-12-06 21:19:03560 return base::string16();
[email protected]73852b8f2010-05-14 00:38:12561}
562
[email protected]5835871a2012-04-25 21:56:55563GURL CloudPrintWebDialogDelegate::GetDialogContentURL() const {
[email protected]73852b8f2010-05-14 00:38:12564 return params_.url;
565}
566
[email protected]5835871a2012-04-25 21:56:55567void CloudPrintWebDialogDelegate::GetWebUIMessageHandlers(
[email protected]36e12172011-02-08 23:46:02568 std::vector<WebUIMessageHandler*>* handlers) const {
[email protected]73852b8f2010-05-14 00:38:12569 handlers->push_back(flow_handler_);
570 // We don't own flow_handler_ anymore, but it sticks around until at
571 // least right after OnDialogClosed() is called (and this object is
572 // destroyed).
573 owns_flow_handler_ = false;
574}
575
[email protected]5835871a2012-04-25 21:56:55576void CloudPrintWebDialogDelegate::GetDialogSize(gfx::Size* size) const {
[email protected]73852b8f2010-05-14 00:38:12577 size->set_width(params_.width);
578 size->set_height(params_.height);
579}
580
[email protected]5835871a2012-04-25 21:56:55581std::string CloudPrintWebDialogDelegate::GetDialogArgs() const {
[email protected]73852b8f2010-05-14 00:38:12582 return params_.json_input;
583}
584
[email protected]5835871a2012-04-25 21:56:55585void CloudPrintWebDialogDelegate::OnDialogClosed(
[email protected]73852b8f2010-05-14 00:38:12586 const std::string& json_retval) {
[email protected]ea161da2010-11-02 21:57:35587 // Get the final dialog size and store it.
588 flow_handler_->StoreDialogClientSize();
[email protected]6ddda232011-04-22 15:41:47589
[email protected]e39027a2011-01-24 21:41:54590 // If we're modal we can show the dialog with no browser.
591 // End the keep-alive so that Chrome can exit.
[email protected]129bedf2013-11-20 07:34:03592 if (!modal_parent_ && keep_alive_when_non_modal_) {
593 // Post to prevent recursive call tho this function.
[email protected]9a718b22014-02-25 15:17:27594 base::MessageLoop::current()->PostTask(
595 FROM_HERE, base::Bind(&chrome::DecrementKeepAliveCount));
[email protected]129bedf2013-11-20 07:34:03596 }
[email protected]73852b8f2010-05-14 00:38:12597 delete this;
598}
599
[email protected]5835871a2012-04-25 21:56:55600void CloudPrintWebDialogDelegate::OnCloseContents(WebContents* source,
601 bool* out_close_dialog) {
[email protected]18137e02010-05-25 21:10:35602 if (out_close_dialog)
603 *out_close_dialog = true;
604}
605
[email protected]5835871a2012-04-25 21:56:55606bool CloudPrintWebDialogDelegate::ShouldShowDialogTitle() const {
[email protected]ea161da2010-11-02 21:57:35607 return false;
608}
609
[email protected]5835871a2012-04-25 21:56:55610bool CloudPrintWebDialogDelegate::HandleContextMenu(
[email protected]35be7ec2012-02-12 20:42:51611 const content::ContextMenuParams& params) {
[email protected]34478212011-04-19 01:35:46612 return true;
613}
614
[email protected]6085c70d2011-03-22 22:51:07615// Called from the UI thread, starts up the dialog.
[email protected]b5b79d72012-05-24 19:42:28616void CreateDialogImpl(content::BrowserContext* browser_context,
617 gfx::NativeWindow modal_parent,
[email protected]a9723e12013-03-05 04:02:45618 const base::RefCountedMemory* data,
[email protected]0085863a2013-12-06 21:19:03619 const base::string16& print_job_title,
620 const base::string16& print_ticket,
[email protected]6c465292014-01-14 15:38:31621 const std::string& file_type) {
[email protected]dee01572014-04-18 22:33:44622 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]5835871a2012-04-25 21:56:55623 WebDialogDelegate* dialog_delegate =
624 new internal_cloud_print_helpers::CloudPrintWebDialogDelegate(
[email protected]a9723e12013-03-05 04:02:45625 browser_context, modal_parent, data, std::string(), print_job_title,
[email protected]6c465292014-01-14 15:38:31626 print_ticket, file_type);
[email protected]88bfd25b2012-06-22 06:28:33627#if defined(OS_WIN)
628 gfx::NativeWindow window =
629#endif
[email protected]87586fb72012-07-02 13:15:02630 chrome::ShowWebDialog(modal_parent,
631 Profile::FromBrowserContext(browser_context),
632 dialog_delegate);
[email protected]88bfd25b2012-06-22 06:28:33633#if defined(OS_WIN)
[email protected]a9723e12013-03-05 04:02:45634 if (window) {
[email protected]88bfd25b2012-06-22 06:28:33635 HWND dialog_handle;
636#if defined(USE_AURA)
[email protected]2374d1812014-03-04 03:42:27637 dialog_handle = window->GetHost()->GetAcceleratedWidget();
[email protected]88bfd25b2012-06-22 06:28:33638#else
639 dialog_handle = window;
640#endif
641 if (::GetForegroundWindow() != dialog_handle) {
642 ui::ForegroundHelper::SetForeground(dialog_handle);
643 }
644 }
645#endif
[email protected]73852b8f2010-05-14 00:38:12646}
[email protected]6085c70d2011-03-22 22:51:07647
[email protected]a9723e12013-03-05 04:02:45648void CreateDialogForFileImpl(content::BrowserContext* browser_context,
649 gfx::NativeWindow modal_parent,
650 const base::FilePath& path_to_file,
[email protected]0085863a2013-12-06 21:19:03651 const base::string16& print_job_title,
652 const base::string16& print_ticket,
[email protected]c9060842014-03-13 01:26:19653 const std::string& file_type) {
[email protected]dee01572014-04-18 22:33:44654 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
[email protected]a9723e12013-03-05 04:02:45655 scoped_refptr<base::RefCountedMemory> data;
656 int64 file_size = 0;
[email protected]56285702013-12-04 18:22:49657 if (base::GetFileSize(path_to_file, &file_size) && file_size != 0) {
[email protected]a9723e12013-03-05 04:02:45658 std::string file_data;
659 if (file_size < kuint32max) {
660 file_data.reserve(static_cast<unsigned int>(file_size));
661 } else {
662 DLOG(WARNING) << " print data file too large to reserve space";
663 }
[email protected]82f84b92013-08-30 18:23:50664 if (base::ReadFileToString(path_to_file, &file_data)) {
[email protected]a9723e12013-03-05 04:02:45665 data = base::RefCountedString::TakeString(&file_data);
666 }
667 }
668 // Proceed even for empty data to simplify testing.
669 BrowserThread::PostTask(
670 BrowserThread::UI, FROM_HERE,
671 base::Bind(&print_dialog_cloud::CreatePrintDialogForBytes,
672 browser_context, modal_parent, data, print_job_title,
673 print_ticket, file_type));
[email protected]c9060842014-03-13 01:26:19674 base::DeleteFile(path_to_file, false);
[email protected]6ddda232011-04-22 15:41:47675}
676
[email protected]6085c70d2011-03-22 22:51:07677} // namespace internal_cloud_print_helpers
678
679namespace print_dialog_cloud {
680
[email protected]37ca3fe02013-07-05 15:32:44681void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
[email protected]681958c2013-02-21 13:48:14682 registry->RegisterIntegerPref(
683 prefs::kCloudPrintDialogWidth,
684 kDefaultWidth,
[email protected]443e9312013-05-06 06:17:34685 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]681958c2013-02-21 13:48:14686 registry->RegisterIntegerPref(
687 prefs::kCloudPrintDialogHeight,
688 kDefaultHeight,
[email protected]443e9312013-05-06 06:17:34689 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]681958c2013-02-21 13:48:14690}
691
[email protected]6085c70d2011-03-22 22:51:07692// Called on the FILE or UI thread. This is the main entry point into creating
693// the dialog.
694
[email protected]b5b79d72012-05-24 19:42:28695void CreatePrintDialogForFile(content::BrowserContext* browser_context,
696 gfx::NativeWindow modal_parent,
[email protected]650b2d52013-02-10 03:41:45697 const base::FilePath& path_to_file,
[email protected]0085863a2013-12-06 21:19:03698 const base::string16& print_job_title,
699 const base::string16& print_ticket,
[email protected]c9060842014-03-13 01:26:19700 const std::string& file_type) {
[email protected]6085c70d2011-03-22 22:51:07701 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE) ||
702 BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]6085c70d2011-03-22 22:51:07703 BrowserThread::PostTask(
[email protected]a9723e12013-03-05 04:02:45704 BrowserThread::FILE, FROM_HERE,
705 base::Bind(&internal_cloud_print_helpers::CreateDialogForFileImpl,
[email protected]b5b79d72012-05-24 19:42:28706 browser_context, modal_parent, path_to_file, print_job_title,
[email protected]c9060842014-03-13 01:26:19707 print_ticket, file_type));
[email protected]d955fc92011-09-19 20:49:03708}
709
[email protected]6c465292014-01-14 15:38:31710void CreateCloudPrintSigninTab(Browser* browser,
[email protected]7b92eea9e2014-04-01 09:17:11711 bool add_account,
[email protected]6c465292014-01-14 15:38:31712 const base::Closure& callback) {
[email protected]dee01572014-04-18 22:33:44713 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]09cff78782014-04-20 22:04:48714 GURL url = add_account ? cloud_devices::GetCloudPrintAddAccountURL()
715 : cloud_devices::GetCloudPrintSigninURL();
[email protected]4c2eb402014-06-13 02:18:56716 content::WebContents* web_contents = browser->OpenURL(content::OpenURLParams(
717 google_util::AppendGoogleLocaleParam(
718 url, g_browser_process->GetApplicationLocale()),
719 content::Referrer(),
720 NEW_FOREGROUND_TAB,
721 content::PAGE_TRANSITION_AUTO_BOOKMARK,
722 false));
[email protected]09cff78782014-04-20 22:04:48723 new SignInObserver(web_contents, cloud_devices::GetCloudPrintURL(), callback);
[email protected]4cd49022012-01-19 20:37:37724}
725
[email protected]b5b79d72012-05-24 19:42:28726void CreatePrintDialogForBytes(content::BrowserContext* browser_context,
727 gfx::NativeWindow modal_parent,
[email protected]a9723e12013-03-05 04:02:45728 const base::RefCountedMemory* data,
[email protected]0085863a2013-12-06 21:19:03729 const base::string16& print_job_title,
730 const base::string16& print_ticket,
[email protected]b5b79d72012-05-24 19:42:28731 const std::string& file_type) {
[email protected]a9723e12013-03-05 04:02:45732 internal_cloud_print_helpers::CreateDialogImpl(browser_context, modal_parent,
733 data, print_job_title,
[email protected]6c465292014-01-14 15:38:31734 print_ticket, file_type);
[email protected]6085c70d2011-03-22 22:51:07735}
736
[email protected]39c61872013-12-13 11:48:02737bool CreatePrintDialogFromCommandLine(Profile* profile,
738 const CommandLine& command_line) {
[email protected]87ab41e72012-01-04 18:45:11739 DCHECK(command_line.HasSwitch(switches::kCloudPrintFile));
[email protected]65c9d89a2011-04-13 21:02:39740 if (!command_line.GetSwitchValuePath(switches::kCloudPrintFile).empty()) {
[email protected]650b2d52013-02-10 03:41:45741 base::FilePath cloud_print_file;
[email protected]65c9d89a2011-04-13 21:02:39742 cloud_print_file =
743 command_line.GetSwitchValuePath(switches::kCloudPrintFile);
744 if (!cloud_print_file.empty()) {
[email protected]0085863a2013-12-06 21:19:03745 base::string16 print_job_title;
746 base::string16 print_job_print_ticket;
[email protected]65c9d89a2011-04-13 21:02:39747 if (command_line.HasSwitch(switches::kCloudPrintJobTitle)) {
[email protected]e8368e92011-08-20 04:05:56748 print_job_title =
749 internal_cloud_print_helpers::GetSwitchValueString16(
750 command_line, switches::kCloudPrintJobTitle);
751 }
752 if (command_line.HasSwitch(switches::kCloudPrintPrintTicket)) {
753 print_job_print_ticket =
754 internal_cloud_print_helpers::GetSwitchValueString16(
755 command_line, switches::kCloudPrintPrintTicket);
[email protected]65c9d89a2011-04-13 21:02:39756 }
757 std::string file_type = "application/pdf";
758 if (command_line.HasSwitch(switches::kCloudPrintFileType)) {
759 file_type = command_line.GetSwitchValueASCII(
760 switches::kCloudPrintFileType);
761 }
[email protected]e8368e92011-08-20 04:05:56762
[email protected]c9060842014-03-13 01:26:19763 print_dialog_cloud::CreatePrintDialogForFile(profile, NULL,
764 cloud_print_file, print_job_title, print_job_print_ticket, file_type);
[email protected]65c9d89a2011-04-13 21:02:39765 return true;
766 }
767 }
768 return false;
769}
770
[email protected]228f0f02013-11-15 05:58:36771} // namespace print_dialog_cloud