blob: b5d49f07ae9c2014d2280b3034343525c9de5e87 [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"
thestig18dfb7a52014-08-26 10:44:0412#include "base/files/file_util.h"
[email protected]73852b8f2010-05-14 00:38:1213#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]8c885f662014-07-04 16:37:3424#include "chrome/browser/ui/browser_window.h"
[email protected]65c9d89a2011-04-13 21:02:3925#include "chrome/common/chrome_switches.h"
[email protected]ea161da2010-11-02 21:57:3526#include "chrome/common/pref_names.h"
[email protected]1375e3ab2011-03-24 17:07:2227#include "chrome/common/print_messages.h"
[email protected]73852b8f2010-05-14 00:38:1228#include "chrome/common/url_constants.h"
[email protected]09cff78782014-04-20 22:04:4829#include "components/cloud_devices/common/cloud_devices_urls.h"
[email protected]8e44a5b02014-06-19 19:03:2430#include "components/google/core/browser/google_util.h"
[email protected]f0c8c4992014-05-15 17:37:2631#include "components/pref_registry/pref_registry_syncable.h"
[email protected]8c885f662014-07-04 16:37:3432#include "components/signin/core/common/profile_management_switches.h"
[email protected]c38831a12011-10-28 12:44:4933#include "content/public/browser/browser_thread.h"
[email protected]cdcb1dee2012-01-04 00:46:2034#include "content/public/browser/navigation_controller.h"
[email protected]022af742011-12-28 18:37:2535#include "content/public/browser/navigation_entry.h"
[email protected]6c2381d2011-10-19 02:52:5336#include "content/public/browser/notification_registrar.h"
37#include "content/public/browser/notification_source.h"
[email protected]0d6e9bd2011-10-18 04:29:1638#include "content/public/browser/notification_types.h"
[email protected]9c1662b2012-03-06 15:44:3339#include "content/public/browser/render_view_host.h"
[email protected]0ec4898e2011-12-30 21:09:2440#include "content/public/browser/web_contents.h"
[email protected]6c465292014-01-14 15:38:3141#include "content/public/browser/web_contents_observer.h"
[email protected]01ec4ec2012-01-18 04:13:4742#include "content/public/browser/web_ui.h"
[email protected]6c465292014-01-14 15:38:3143#include "content/public/common/frame_navigate_params.h"
[email protected]b3a97b52014-07-09 06:25:0544#include "content/public/common/web_preferences.h"
[email protected]520c2022012-03-15 00:13:1545
[email protected]88bfd25b2012-06-22 06:28:3346#if defined(USE_AURA)
[email protected]88bfd25b2012-06-22 06:28:3347#include "ui/aura/window.h"
[email protected]7a60cd3a2014-03-20 20:54:5748#include "ui/aura/window_tree_host.h"
[email protected]88bfd25b2012-06-22 06:28:3349#endif
50
[email protected]520c2022012-03-15 00:13:1551#if defined(OS_WIN)
52#include "ui/base/win/foreground_helper.h"
53#endif
54
[email protected]73852b8f2010-05-14 00:38:1255// This module implements the UI support in Chrome for cloud printing.
56// This means hosting a dialog containing HTML/JavaScript and using
57// the published cloud print user interface integration APIs to get
58// page setup settings from the dialog contents and provide the
[email protected]a984bdf2011-03-15 20:17:1659// generated print data to the dialog contents for uploading to the
[email protected]73852b8f2010-05-14 00:38:1260// cloud print service.
61
62// Currently, the flow between these classes is as follows:
63
[email protected]a984bdf2011-03-15 20:17:1664// PrintDialogCloud::CreatePrintDialogForFile is called from
[email protected]73852b8f2010-05-14 00:38:1265// resource_message_filter_gtk.cc once the renderer has informed the
[email protected]a984bdf2011-03-15 20:17:1666// renderer host that print data generation into the renderer host provided
[email protected]032682b2011-01-12 22:05:0267// temp file has been completed. That call is on the FILE thread.
[email protected]73852b8f2010-05-14 00:38:1268// That, in turn, hops over to the UI thread to create an instance of
69// PrintDialogCloud.
70
71// The constructor for PrintDialogCloud creates a
[email protected]5835871a2012-04-25 21:56:5572// CloudPrintWebDialogDelegate and asks the current active browser to
[email protected]73852b8f2010-05-14 00:38:1273// show an HTML dialog using that class as the delegate. That class
[email protected]89f550b2011-06-08 18:34:0374// hands in the kChromeUICloudPrintResourcesURL as the URL to visit. That is
[email protected]80a8fad2011-01-29 04:02:3875// recognized by the GetWebUIFactoryFunction as a signal to create an
[email protected]02b5ccc2012-04-30 23:58:3176// ExternalWebDialogUI.
[email protected]73852b8f2010-05-14 00:38:1277
[email protected]5835871a2012-04-25 21:56:5578// CloudPrintWebDialogDelegate also temporarily owns a
[email protected]73852b8f2010-05-14 00:38:1279// CloudPrintFlowHandler, a class which is responsible for the actual
[email protected]a984bdf2011-03-15 20:17:1680// interactions with the dialog contents, including handing in the
[email protected]73852b8f2010-05-14 00:38:1281// print data and getting any page setup parameters that the dialog
82// contents provides. As part of bringing up the dialog,
[email protected]02b5ccc2012-04-30 23:58:3183// WebDialogUI::RenderViewCreated is called (an override of
[email protected]c39f9bf2011-02-12 00:43:5584// WebUI::RenderViewCreated). That routine, in turn, calls the
[email protected]36e12172011-02-08 23:46:0285// delegate's GetWebUIMessageHandlers routine, at which point the
[email protected]73852b8f2010-05-14 00:38:1286// ownership of the CloudPrintFlowHandler is handed over. A pointer
87// to the flow handler is kept to facilitate communication back and
88// forth between the two classes.
89
[email protected]c39f9bf2011-02-12 00:43:5590// The WebUI continues dialog bring-up, calling
[email protected]73852b8f2010-05-14 00:38:1291// CloudPrintFlowHandler::RegisterMessages. This is where the
92// additional object model capabilities are registered for the dialog
93// contents to use. It is also at this time that capabilities for the
94// dialog contents are adjusted to allow the dialog contents to close
95// the window. In addition, the pending URL is redirected to the
96// actual cloud print service URL. The flow controller also registers
97// for notification of when the dialog contents finish loading, which
[email protected]a984bdf2011-03-15 20:17:1698// is currently used to send the data to the dialog contents.
[email protected]73852b8f2010-05-14 00:38:1299
[email protected]a984bdf2011-03-15 20:17:16100// In order to send the data to the dialog contents, the flow
[email protected]73852b8f2010-05-14 00:38:12101// handler uses a CloudPrintDataSender. It creates one, letting it
[email protected]a984bdf2011-03-15 20:17:16102// know the name of the temporary file containing the data, and
[email protected]73852b8f2010-05-14 00:38:12103// posts the task of reading the file
104// (CloudPrintDataSender::ReadPrintDataFile) to the file thread. That
105// routine reads in the file, and then hops over to the IO thread to
106// send that data to the dialog contents.
107
108// When the dialog contents are finished (by either being cancelled or
109// hitting the print button), the delegate is notified, and responds
110// that the dialog should be closed, at which point things are torn
111// down and released.
112
[email protected]631bb742011-11-02 11:29:39113using content::BrowserThread;
[email protected]c5eed492012-01-04 17:07:50114using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23115using content::NavigationEntry;
[email protected]eaabba22012-03-07 15:02:11116using content::RenderViewHost;
[email protected]a81343d232011-12-27 07:39:20117using content::WebContents;
[email protected]b3a97b52014-07-09 06:25:05118using content::WebPreferences;
[email protected]26e2632a2011-12-31 04:02:55119using content::WebUIMessageHandler;
[email protected]20c07f8e2012-05-31 08:43:14120using ui::WebDialogDelegate;
[email protected]631bb742011-11-02 11:29:39121
[email protected]6c465292014-01-14 15:38:31122namespace {
123
[email protected]681958c2013-02-21 13:48:14124const int kDefaultWidth = 912;
125const int kDefaultHeight = 633;
126
[email protected]6c465292014-01-14 15:38:31127bool IsSimilarUrl(const GURL& url, const GURL& cloud_print_url) {
128 return url.host() == cloud_print_url.host() &&
129 StartsWithASCII(url.path(), cloud_print_url.path(), false) &&
130 url.scheme() == cloud_print_url.scheme();
131}
132
133class SignInObserver : public content::WebContentsObserver {
134 public:
135 SignInObserver(content::WebContents* web_contents,
136 GURL cloud_print_url,
137 const base::Closure& callback)
138 : WebContentsObserver(web_contents),
139 cloud_print_url_(cloud_print_url),
140 callback_(callback),
141 weak_ptr_factory_(this) {
142 }
143
144 private:
145 // Overridden from content::WebContentsObserver:
dchengdf7e44a72014-10-21 23:50:19146 void DidNavigateMainFrame(
[email protected]6c465292014-01-14 15:38:31147 const content::LoadCommittedDetails& details,
mostynb2b52d1db2014-10-07 02:47:17148 const content::FrameNavigateParams& params) override {
[email protected]6c465292014-01-14 15:38:31149 if (IsSimilarUrl(params.url, cloud_print_url_)) {
150 base::MessageLoop::current()->PostTask(
151 FROM_HERE,
152 base::Bind(&SignInObserver::OnSignIn,
153 weak_ptr_factory_.GetWeakPtr()));
154 }
155 }
156
dchengdf7e44a72014-10-21 23:50:19157 void WebContentsDestroyed() override { delete this; }
[email protected]6c465292014-01-14 15:38:31158
159 void OnSignIn() {
160 callback_.Run();
161 if (web_contents())
162 web_contents()->Close();
163 }
164
165 GURL cloud_print_url_;
166 base::Closure callback_;
167 base::WeakPtrFactory<SignInObserver> weak_ptr_factory_;
168
169 DISALLOW_COPY_AND_ASSIGN(SignInObserver);
170};
171
172} // namespace
173
[email protected]73852b8f2010-05-14 00:38:12174namespace internal_cloud_print_helpers {
175
[email protected]73852b8f2010-05-14 00:38:12176// From the JSON parsed value, get the entries for the page setup
177// parameters.
178bool GetPageSetupParameters(const std::string& json,
[email protected]1375e3ab2011-03-24 17:07:22179 PrintMsg_Print_Params& parameters) {
[email protected]dbb9aa42013-12-23 20:08:21180 scoped_ptr<base::Value> parsed_value(base::JSONReader::Read(json));
[email protected]73852b8f2010-05-14 00:38:12181 DLOG_IF(ERROR, (!parsed_value.get() ||
[email protected]dbb9aa42013-12-23 20:08:21182 !parsed_value->IsType(base::Value::TYPE_DICTIONARY)))
[email protected]73852b8f2010-05-14 00:38:12183 << "PageSetup call didn't have expected contents";
[email protected]dbb9aa42013-12-23 20:08:21184 if (!parsed_value.get() ||
185 !parsed_value->IsType(base::Value::TYPE_DICTIONARY)) {
[email protected]73852b8f2010-05-14 00:38:12186 return false;
[email protected]dbb9aa42013-12-23 20:08:21187 }
[email protected]73852b8f2010-05-14 00:38:12188
189 bool result = true;
[email protected]dbb9aa42013-12-23 20:08:21190 base::DictionaryValue* params =
191 static_cast<base::DictionaryValue*>(parsed_value.get());
[email protected]05c7da62011-05-05 17:23:56192 result &= params->GetDouble("dpi", &parameters.dpi);
193 result &= params->GetDouble("min_shrink", &parameters.min_shrink);
194 result &= params->GetDouble("max_shrink", &parameters.max_shrink);
[email protected]a65175d2010-08-17 04:00:57195 result &= params->GetBoolean("selection_only", &parameters.selection_only);
[email protected]73852b8f2010-05-14 00:38:12196 return result;
197}
198
[email protected]536f86a2013-11-23 01:24:56199base::string16 GetSwitchValueString16(const CommandLine& command_line,
200 const char* switchName) {
[email protected]31662202013-03-23 19:10:54201#if defined(OS_WIN)
[email protected]536f86a2013-11-23 01:24:56202 return command_line.GetSwitchValueNative(switchName);
[email protected]e8368e92011-08-20 04:05:56203#elif defined(OS_POSIX)
204 // POSIX Command line string types are different.
205 CommandLine::StringType native_switch_val;
206 native_switch_val = command_line.GetSwitchValueASCII(switchName);
207 // Convert the ASCII string to UTF16 to prepare to pass.
[email protected]536f86a2013-11-23 01:24:56208 return base::ASCIIToUTF16(native_switch_val);
[email protected]e8368e92011-08-20 04:05:56209#endif
210}
211
[email protected]73852b8f2010-05-14 00:38:12212void CloudPrintDataSenderHelper::CallJavascriptFunction(
[email protected]dbb9aa42013-12-23 20:08:21213 const std::string& function_name,
214 const base::Value& arg1,
215 const base::Value& arg2) {
[email protected]536f86a2013-11-23 01:24:56216 web_ui_->CallJavascriptFunction(function_name, arg1, arg2);
[email protected]e8368e92011-08-20 04:05:56217}
218
[email protected]73852b8f2010-05-14 00:38:12219// Clears out the pointer we're using to communicate. Either routine is
220// potentially expensive enough that stopping whatever is in progress
221// is worth it.
222void CloudPrintDataSender::CancelPrintDataFile() {
[email protected]20305ec2011-01-21 04:55:52223 base::AutoLock lock(lock_);
[email protected]73852b8f2010-05-14 00:38:12224 // We don't own helper, it was passed in to us, so no need to
225 // delete, just let it go.
226 helper_ = NULL;
227}
228
[email protected]0085863a2013-12-06 21:19:03229CloudPrintDataSender::CloudPrintDataSender(
230 CloudPrintDataSenderHelper* helper,
231 const base::string16& print_job_title,
232 const base::string16& print_ticket,
233 const std::string& file_type,
234 const base::RefCountedMemory* data)
[email protected]38e08982010-10-22 17:28:43235 : helper_(helper),
[email protected]a984bdf2011-03-15 20:17:16236 print_job_title_(print_job_title),
[email protected]e8368e92011-08-20 04:05:56237 print_ticket_(print_ticket),
[email protected]a9723e12013-03-05 04:02:45238 file_type_(file_type),
239 data_(data) {
[email protected]38e08982010-10-22 17:28:43240}
241
242CloudPrintDataSender::~CloudPrintDataSender() {}
243
[email protected]73852b8f2010-05-14 00:38:12244// We have the data in hand that needs to be pushed into the dialog
245// contents; do so from the IO thread.
246
247// TODO(scottbyer): If the print data ends up being larger than the
248// upload limit (currently 10MB), what we need to do is upload that
249// large data to google docs and set the URL in the printing
250// JavaScript to that location, and make sure it gets deleted when not
251// needed. - 4/1/2010
[email protected]a9723e12013-03-05 04:02:45252void CloudPrintDataSender::SendPrintData() {
[email protected]dee01572014-04-18 22:33:44253 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]5173de8b2013-06-02 21:16:02254 if (!data_.get() || !data_->size())
[email protected]a9723e12013-03-05 04:02:45255 return;
256
257 std::string base64_data;
258 base::Base64Encode(
[email protected]8df08cf2014-02-12 22:34:08259 base::StringPiece(data_->front_as<char>(), data_->size()),
[email protected]a9723e12013-03-05 04:02:45260 &base64_data);
[email protected]a9723e12013-03-05 04:02:45261 std::string header("data:");
262 header.append(file_type_);
263 header.append(";base64,");
264 base64_data.insert(0, header);
265
[email protected]20305ec2011-01-21 04:55:52266 base::AutoLock lock(lock_);
[email protected]a9723e12013-03-05 04:02:45267 if (helper_) {
[email protected]536f86a2013-11-23 01:24:56268 base::StringValue title(print_job_title_);
269 base::StringValue ticket(print_ticket_);
[email protected]e8368e92011-08-20 04:05:56270 // TODO(abodenha): Change Javascript call to pass in print ticket
271 // after server side support is added. Add test for it.
[email protected]73852b8f2010-05-14 00:38:12272
273 // Send the print data to the dialog contents. The JavaScript
274 // function is a preliminary API for prototyping purposes and is
275 // subject to change.
[email protected]536f86a2013-11-23 01:24:56276 helper_->CallJavascriptFunction(
277 "printApp._printDataUrl", base::StringValue(base64_data), title);
[email protected]73852b8f2010-05-14 00:38:12278 }
279}
280
281
[email protected]0085863a2013-12-06 21:19:03282CloudPrintFlowHandler::CloudPrintFlowHandler(
283 const base::RefCountedMemory* data,
284 const base::string16& print_job_title,
285 const base::string16& print_ticket,
[email protected]6c465292014-01-14 15:38:31286 const std::string& file_type)
[email protected]c7bf7452011-09-12 21:31:50287 : dialog_delegate_(NULL),
[email protected]a9723e12013-03-05 04:02:45288 data_(data),
[email protected]a984bdf2011-03-15 20:17:16289 print_job_title_(print_job_title),
[email protected]e8368e92011-08-20 04:05:56290 print_ticket_(print_ticket),
[email protected]6c465292014-01-14 15:38:31291 file_type_(file_type) {
[email protected]38e08982010-10-22 17:28:43292}
293
294CloudPrintFlowHandler::~CloudPrintFlowHandler() {
295 // This will also cancel any task in flight.
296 CancelAnyRunningTask();
297}
298
299
[email protected]73852b8f2010-05-14 00:38:12300void CloudPrintFlowHandler::SetDialogDelegate(
[email protected]5835871a2012-04-25 21:56:55301 CloudPrintWebDialogDelegate* delegate) {
[email protected]7b748982011-02-14 19:28:23302 // Even if setting a new WebUI, it means any previous task needs
[email protected]a2c92a1c2012-04-03 12:32:14303 // to be canceled, its now invalid.
[email protected]dee01572014-04-18 22:33:44304 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]73852b8f2010-05-14 00:38:12305 CancelAnyRunningTask();
306 dialog_delegate_ = delegate;
307}
308
309// Cancels any print data sender we have in flight and removes our
310// reference to it, so when the task that is calling it finishes and
[email protected]a2c92a1c2012-04-03 12:32:14311// removes its reference, it goes away.
[email protected]73852b8f2010-05-14 00:38:12312void CloudPrintFlowHandler::CancelAnyRunningTask() {
[email protected]dee01572014-04-18 22:33:44313 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]73852b8f2010-05-14 00:38:12314 if (print_data_sender_.get()) {
315 print_data_sender_->CancelPrintDataFile();
316 print_data_sender_ = NULL;
317 }
318}
319
[email protected]73852b8f2010-05-14 00:38:12320void CloudPrintFlowHandler::RegisterMessages() {
[email protected]73852b8f2010-05-14 00:38:12321 // TODO(scottbyer) - This is where we will register messages for the
322 // UI JS to use. Needed: Call to update page setup parameters.
[email protected]46adf7ff2011-12-30 00:53:09323 web_ui()->RegisterMessageCallback("ShowDebugger",
[email protected]ba4fc242011-10-04 18:56:56324 base::Bind(&CloudPrintFlowHandler::HandleShowDebugger,
325 base::Unretained(this)));
[email protected]46adf7ff2011-12-30 00:53:09326 web_ui()->RegisterMessageCallback("SendPrintData",
[email protected]ba4fc242011-10-04 18:56:56327 base::Bind(&CloudPrintFlowHandler::HandleSendPrintData,
328 base::Unretained(this)));
[email protected]46adf7ff2011-12-30 00:53:09329 web_ui()->RegisterMessageCallback("SetPageParameters",
[email protected]ba4fc242011-10-04 18:56:56330 base::Bind(&CloudPrintFlowHandler::HandleSetPageParameters,
331 base::Unretained(this)));
[email protected]73852b8f2010-05-14 00:38:12332
[email protected]0eb25c42011-08-11 14:50:14333 // Register for appropriate notifications, and re-direct the URL
334 // to the real server URL, now that we've gotten an HTML dialog
335 // going.
[email protected]c5eed492012-01-04 17:07:50336 NavigationController* controller =
[email protected]01ec4ec2012-01-18 04:13:47337 &web_ui()->GetWebContents()->GetController();
[email protected]10f417c52011-12-28 21:04:23338 NavigationEntry* pending_entry = controller->GetPendingEntry();
[email protected]0eb25c42011-08-11 14:50:14339 if (pending_entry) {
[email protected]09cff78782014-04-20 22:04:48340 pending_entry->SetURL(google_util::AppendGoogleLocaleParam(
[email protected]4c2eb402014-06-13 02:18:56341 cloud_devices::GetCloudPrintRelativeURL("client/dialog.html"),
342 g_browser_process->GetApplicationLocale()));
[email protected]73852b8f2010-05-14 00:38:12343 }
[email protected]0eb25c42011-08-11 14:50:14344 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50345 content::Source<NavigationController>(controller));
[email protected]57c8cf22013-03-02 16:50:00346 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
347 content::Source<NavigationController>(controller));
[email protected]73852b8f2010-05-14 00:38:12348}
349
[email protected]6c2381d2011-10-19 02:52:53350void CloudPrintFlowHandler::Observe(
351 int type,
352 const content::NotificationSource& source,
353 const content::NotificationDetails& details) {
[email protected]57c8cf22013-03-02 16:50:00354 switch (type) {
[email protected]57c8cf22013-03-02 16:50:00355 case content::NOTIFICATION_LOAD_STOP: {
[email protected]57c8cf22013-03-02 16:50:00356 GURL url = web_ui()->GetWebContents()->GetURL();
[email protected]6e536cdf2013-05-09 04:49:52357 if (IsCloudPrintDialogUrl(url)) {
358 // Take the opportunity to set some (minimal) additional
359 // script permissions required for the web UI.
[email protected]57c8cf22013-03-02 16:50:00360 RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost();
361 if (rvh) {
[email protected]9e797d22014-08-08 21:31:30362 // TODO(chrishtr): this is wrong. allow_scripts_to_close_windows will
363 // be reset the next time a preference changes.
[email protected]3184f90b2013-05-01 18:17:53364 WebPreferences webkit_prefs = rvh->GetWebkitPreferences();
[email protected]57c8cf22013-03-02 16:50:00365 webkit_prefs.allow_scripts_to_close_windows = true;
366 rvh->UpdateWebkitPreferences(webkit_prefs);
367 } else {
368 NOTREACHED();
369 }
[email protected]6e536cdf2013-05-09 04:49:52370 // Choose one or the other. If you need to debug, bring up the
371 // debugger. You can then use the various chrome.send()
372 // registrations above to kick of the various function calls,
373 // including chrome.send("SendPrintData") in the javaScript
374 // console and watch things happen with:
375 // HandleShowDebugger(NULL);
376 HandleSendPrintData(NULL);
[email protected]57c8cf22013-03-02 16:50:00377 }
[email protected]57c8cf22013-03-02 16:50:00378 break;
379 }
[email protected]73852b8f2010-05-14 00:38:12380 }
381}
382
[email protected]dbb9aa42013-12-23 20:08:21383void CloudPrintFlowHandler::HandleShowDebugger(const base::ListValue* args) {
[email protected]73852b8f2010-05-14 00:38:12384 ShowDebugger();
385}
386
387void CloudPrintFlowHandler::ShowDebugger() {
[email protected]46adf7ff2011-12-30 00:53:09388 if (web_ui()) {
[email protected]b3f957e62014-08-08 10:09:02389 WebContents* web_contents = web_ui()->GetWebContents();
390 if (web_contents)
391 DevToolsWindow::OpenDevToolsWindow(web_contents);
[email protected]73852b8f2010-05-14 00:38:12392 }
393}
394
395scoped_refptr<CloudPrintDataSender>
396CloudPrintFlowHandler::CreateCloudPrintDataSender() {
[email protected]46adf7ff2011-12-30 00:53:09397 DCHECK(web_ui());
398 print_data_helper_.reset(new CloudPrintDataSenderHelper(web_ui()));
[email protected]a9723e12013-03-05 04:02:45399 scoped_refptr<CloudPrintDataSender> sender(
[email protected]5173de8b2013-06-02 21:16:02400 new CloudPrintDataSender(print_data_helper_.get(),
401 print_job_title_,
402 print_ticket_,
403 file_type_,
404 data_.get()));
[email protected]a9723e12013-03-05 04:02:45405 return sender;
[email protected]73852b8f2010-05-14 00:38:12406}
407
[email protected]dbb9aa42013-12-23 20:08:21408void CloudPrintFlowHandler::HandleSendPrintData(const base::ListValue* args) {
[email protected]dee01572014-04-18 22:33:44409 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]73852b8f2010-05-14 00:38:12410 // This will cancel any ReadPrintDataFile() or SendPrintDataFile()
411 // requests in flight (this is anticipation of when setting page
412 // setup parameters becomes asynchronous and may be set while some
413 // data is in flight). Then we can clear out the print data.
414 CancelAnyRunningTask();
[email protected]46adf7ff2011-12-30 00:53:09415 if (web_ui()) {
[email protected]73852b8f2010-05-14 00:38:12416 print_data_sender_ = CreateCloudPrintDataSender();
[email protected]3e2dd4fa2011-11-10 06:06:40417 BrowserThread::PostTask(
[email protected]a9723e12013-03-05 04:02:45418 BrowserThread::IO, FROM_HERE,
419 base::Bind(&CloudPrintDataSender::SendPrintData, print_data_sender_));
[email protected]73852b8f2010-05-14 00:38:12420 }
421}
422
[email protected]dbb9aa42013-12-23 20:08:21423void CloudPrintFlowHandler::HandleSetPageParameters(
424 const base::ListValue* args) {
[email protected]036056a32011-03-03 21:05:01425 std::string json;
[email protected]e675f7b2011-06-22 17:32:12426 bool ret = args->GetString(0, &json);
427 if (!ret || json.empty()) {
[email protected]036056a32011-03-03 21:05:01428 NOTREACHED() << "Empty json string";
[email protected]73852b8f2010-05-14 00:38:12429 return;
[email protected]036056a32011-03-03 21:05:01430 }
[email protected]73852b8f2010-05-14 00:38:12431
432 // These are backstop default values - 72 dpi to match the screen,
433 // 8.5x11 inch paper with margins subtracted (1/4 inch top, left,
434 // right and 0.56 bottom), and the min page shrink and max page
435 // shrink values appear all over the place with no explanation.
436
437 // TODO(scottbyer): Get a Linux/ChromeOS edge for PrintSettings
438 // working so that we can get the default values from there. Fix up
439 // PrintWebViewHelper to do the same.
440 const int kDPI = 72;
441 const int kWidth = static_cast<int>((8.5-0.25-0.25)*kDPI);
442 const int kHeight = static_cast<int>((11-0.25-0.56)*kDPI);
443 const double kMinPageShrink = 1.25;
444 const double kMaxPageShrink = 2.0;
445
[email protected]1375e3ab2011-03-24 17:07:22446 PrintMsg_Print_Params default_settings;
[email protected]10980442011-12-04 22:33:05447 default_settings.content_size = gfx::Size(kWidth, kHeight);
[email protected]732b8132012-01-10 23:17:32448 default_settings.printable_area = gfx::Rect(0, 0, kWidth, kHeight);
[email protected]73852b8f2010-05-14 00:38:12449 default_settings.dpi = kDPI;
450 default_settings.min_shrink = kMinPageShrink;
451 default_settings.max_shrink = kMaxPageShrink;
452 default_settings.desired_dpi = kDPI;
453 default_settings.document_cookie = 0;
454 default_settings.selection_only = false;
[email protected]718af822011-08-12 22:11:33455 default_settings.preview_request_id = 0;
456 default_settings.is_first_request = true;
[email protected]732b8132012-01-10 23:17:32457 default_settings.print_to_pdf = false;
[email protected]73852b8f2010-05-14 00:38:12458
459 if (!GetPageSetupParameters(json, default_settings)) {
460 NOTREACHED();
461 return;
462 }
463
464 // TODO(scottbyer) - Here is where we would kick the originating
465 // renderer thread with these new parameters in order to get it to
[email protected]a984bdf2011-03-15 20:17:16466 // re-generate the PDF data and hand it back to us. window.print() is
[email protected]73852b8f2010-05-14 00:38:12467 // currently synchronous, so there's a lot of work to do to get to
468 // that point.
469}
470
[email protected]ea161da2010-11-02 21:57:35471void CloudPrintFlowHandler::StoreDialogClientSize() const {
[email protected]fc2b46b2014-05-03 16:33:45472 if (web_ui() && web_ui()->GetWebContents()) {
473 gfx::Size size = web_ui()->GetWebContents()->GetContainerBounds().size();
[email protected]46adf7ff2011-12-30 00:53:09474 Profile* profile = Profile::FromWebUI(web_ui());
[email protected]0eb25c42011-08-11 14:50:14475 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogWidth,
476 size.width());
477 profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogHeight,
478 size.height());
[email protected]ea161da2010-11-02 21:57:35479 }
480}
481
[email protected]6e536cdf2013-05-09 04:49:52482bool CloudPrintFlowHandler::IsCloudPrintDialogUrl(const GURL& url) {
[email protected]09cff78782014-04-20 22:04:48483 GURL cloud_print_url = cloud_devices::GetCloudPrintURL();
[email protected]6c465292014-01-14 15:38:31484 return IsSimilarUrl(url, cloud_print_url);
[email protected]6e536cdf2013-05-09 04:49:52485}
486
[email protected]5835871a2012-04-25 21:56:55487CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate(
[email protected]b5b79d72012-05-24 19:42:28488 content::BrowserContext* browser_context,
489 gfx::NativeWindow modal_parent,
[email protected]a9723e12013-03-05 04:02:45490 const base::RefCountedMemory* data,
[email protected]9848c7e2010-06-03 16:06:56491 const std::string& json_arguments,
[email protected]0085863a2013-12-06 21:19:03492 const base::string16& print_job_title,
493 const base::string16& print_ticket,
[email protected]6c465292014-01-14 15:38:31494 const std::string& file_type)
[email protected]a9723e12013-03-05 04:02:45495 : flow_handler_(
496 new CloudPrintFlowHandler(data, print_job_title, print_ticket,
[email protected]6c465292014-01-14 15:38:31497 file_type)),
[email protected]b5b79d72012-05-24 19:42:28498 modal_parent_(modal_parent),
[email protected]6ddda232011-04-22 15:41:47499 owns_flow_handler_(true),
[email protected]b5b79d72012-05-24 19:42:28500 keep_alive_when_non_modal_(true) {
501 Init(browser_context, json_arguments);
[email protected]73852b8f2010-05-14 00:38:12502}
503
[email protected]05acb55472011-02-03 00:11:07504// For unit testing.
[email protected]5835871a2012-04-25 21:56:55505CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate(
[email protected]73852b8f2010-05-14 00:38:12506 CloudPrintFlowHandler* flow_handler,
[email protected]a9723e12013-03-05 04:02:45507 const std::string& json_arguments)
508 : flow_handler_(flow_handler),
[email protected]b5b79d72012-05-24 19:42:28509 modal_parent_(NULL),
510 owns_flow_handler_(true),
511 keep_alive_when_non_modal_(false) {
512 Init(NULL, json_arguments);
[email protected]73852b8f2010-05-14 00:38:12513}
514
[email protected]b5b79d72012-05-24 19:42:28515// Returns the persisted width/height for the print dialog.
516void GetDialogWidthAndHeightFromPrefs(content::BrowserContext* browser_context,
517 int* width,
518 int* height) {
[email protected]b5b79d72012-05-24 19:42:28519 if (!browser_context) {
520 *width = kDefaultWidth;
521 *height = kDefaultHeight;
522 return;
523 }
524
[email protected]c753f142013-02-10 13:14:04525 PrefService* prefs = Profile::FromBrowserContext(browser_context)->GetPrefs();
[email protected]c753f142013-02-10 13:14:04526 *width = prefs->GetInteger(prefs::kCloudPrintDialogWidth);
527 *height = prefs->GetInteger(prefs::kCloudPrintDialogHeight);
[email protected]b5b79d72012-05-24 19:42:28528}
529
530void CloudPrintWebDialogDelegate::Init(content::BrowserContext* browser_context,
[email protected]5835871a2012-04-25 21:56:55531 const std::string& json_arguments) {
[email protected]73852b8f2010-05-14 00:38:12532 // This information is needed to show the dialog HTML content.
[email protected]dee01572014-04-18 22:33:44533 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]b5b79d72012-05-24 19:42:28534
[email protected]89f550b2011-06-08 18:34:03535 params_.url = GURL(chrome::kChromeUICloudPrintResourcesURL);
[email protected]b5b79d72012-05-24 19:42:28536 GetDialogWidthAndHeightFromPrefs(browser_context,
537 &params_.width,
538 &params_.height);
[email protected]73852b8f2010-05-14 00:38:12539 params_.json_input = json_arguments;
540
541 flow_handler_->SetDialogDelegate(this);
[email protected]e39027a2011-01-24 21:41:54542 // If we're not modal we can show the dialog with no browser.
543 // We need this to keep Chrome alive while our dialog is up.
[email protected]b5b79d72012-05-24 19:42:28544 if (!modal_parent_ && keep_alive_when_non_modal_)
[email protected]9a718b22014-02-25 15:17:27545 chrome::IncrementKeepAliveCount();
[email protected]73852b8f2010-05-14 00:38:12546}
547
[email protected]5835871a2012-04-25 21:56:55548CloudPrintWebDialogDelegate::~CloudPrintWebDialogDelegate() {
[email protected]73852b8f2010-05-14 00:38:12549 // If the flow_handler_ is about to outlive us because we don't own
[email protected]a2c92a1c2012-04-03 12:32:14550 // it anymore, we need to have it remove its reference to us.
[email protected]dee01572014-04-18 22:33:44551 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]73852b8f2010-05-14 00:38:12552 flow_handler_->SetDialogDelegate(NULL);
553 if (owns_flow_handler_) {
554 delete flow_handler_;
555 }
556}
557
[email protected]5835871a2012-04-25 21:56:55558ui::ModalType CloudPrintWebDialogDelegate::GetDialogModalType() const {
[email protected]b5b79d72012-05-24 19:42:28559 return modal_parent_ ? ui::MODAL_TYPE_WINDOW : ui::MODAL_TYPE_NONE;
[email protected]73852b8f2010-05-14 00:38:12560}
561
[email protected]6a72a632013-12-12 22:22:00562base::string16 CloudPrintWebDialogDelegate::GetDialogTitle() const {
[email protected]0085863a2013-12-06 21:19:03563 return base::string16();
[email protected]73852b8f2010-05-14 00:38:12564}
565
[email protected]5835871a2012-04-25 21:56:55566GURL CloudPrintWebDialogDelegate::GetDialogContentURL() const {
[email protected]73852b8f2010-05-14 00:38:12567 return params_.url;
568}
569
[email protected]5835871a2012-04-25 21:56:55570void CloudPrintWebDialogDelegate::GetWebUIMessageHandlers(
[email protected]36e12172011-02-08 23:46:02571 std::vector<WebUIMessageHandler*>* handlers) const {
[email protected]73852b8f2010-05-14 00:38:12572 handlers->push_back(flow_handler_);
573 // We don't own flow_handler_ anymore, but it sticks around until at
574 // least right after OnDialogClosed() is called (and this object is
575 // destroyed).
576 owns_flow_handler_ = false;
577}
578
[email protected]5835871a2012-04-25 21:56:55579void CloudPrintWebDialogDelegate::GetDialogSize(gfx::Size* size) const {
[email protected]73852b8f2010-05-14 00:38:12580 size->set_width(params_.width);
581 size->set_height(params_.height);
582}
583
[email protected]5835871a2012-04-25 21:56:55584std::string CloudPrintWebDialogDelegate::GetDialogArgs() const {
[email protected]73852b8f2010-05-14 00:38:12585 return params_.json_input;
586}
587
[email protected]5835871a2012-04-25 21:56:55588void CloudPrintWebDialogDelegate::OnDialogClosed(
[email protected]73852b8f2010-05-14 00:38:12589 const std::string& json_retval) {
[email protected]ea161da2010-11-02 21:57:35590 // Get the final dialog size and store it.
591 flow_handler_->StoreDialogClientSize();
[email protected]6ddda232011-04-22 15:41:47592
[email protected]e39027a2011-01-24 21:41:54593 // If we're modal we can show the dialog with no browser.
594 // End the keep-alive so that Chrome can exit.
[email protected]129bedf2013-11-20 07:34:03595 if (!modal_parent_ && keep_alive_when_non_modal_) {
596 // Post to prevent recursive call tho this function.
[email protected]9a718b22014-02-25 15:17:27597 base::MessageLoop::current()->PostTask(
598 FROM_HERE, base::Bind(&chrome::DecrementKeepAliveCount));
[email protected]129bedf2013-11-20 07:34:03599 }
[email protected]73852b8f2010-05-14 00:38:12600 delete this;
601}
602
[email protected]5835871a2012-04-25 21:56:55603void CloudPrintWebDialogDelegate::OnCloseContents(WebContents* source,
604 bool* out_close_dialog) {
[email protected]18137e02010-05-25 21:10:35605 if (out_close_dialog)
606 *out_close_dialog = true;
607}
608
[email protected]5835871a2012-04-25 21:56:55609bool CloudPrintWebDialogDelegate::ShouldShowDialogTitle() const {
[email protected]ea161da2010-11-02 21:57:35610 return false;
611}
612
[email protected]5835871a2012-04-25 21:56:55613bool CloudPrintWebDialogDelegate::HandleContextMenu(
[email protected]35be7ec2012-02-12 20:42:51614 const content::ContextMenuParams& params) {
[email protected]34478212011-04-19 01:35:46615 return true;
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]0085863a2013-12-06 21:19:03622 const base::string16& print_job_title,
623 const base::string16& print_ticket,
[email protected]6c465292014-01-14 15:38:31624 const std::string& file_type) {
[email protected]dee01572014-04-18 22:33:44625 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]5835871a2012-04-25 21:56:55626 WebDialogDelegate* dialog_delegate =
627 new internal_cloud_print_helpers::CloudPrintWebDialogDelegate(
[email protected]a9723e12013-03-05 04:02:45628 browser_context, modal_parent, data, std::string(), print_job_title,
[email protected]6c465292014-01-14 15:38:31629 print_ticket, file_type);
[email protected]88bfd25b2012-06-22 06:28:33630#if defined(OS_WIN)
631 gfx::NativeWindow window =
632#endif
[email protected]87586fb72012-07-02 13:15:02633 chrome::ShowWebDialog(modal_parent,
634 Profile::FromBrowserContext(browser_context),
635 dialog_delegate);
[email protected]88bfd25b2012-06-22 06:28:33636#if defined(OS_WIN)
[email protected]a9723e12013-03-05 04:02:45637 if (window) {
[email protected]88bfd25b2012-06-22 06:28:33638 HWND dialog_handle;
639#if defined(USE_AURA)
[email protected]2374d1812014-03-04 03:42:27640 dialog_handle = window->GetHost()->GetAcceleratedWidget();
[email protected]88bfd25b2012-06-22 06:28:33641#else
642 dialog_handle = window;
643#endif
644 if (::GetForegroundWindow() != dialog_handle) {
645 ui::ForegroundHelper::SetForeground(dialog_handle);
646 }
647 }
648#endif
[email protected]73852b8f2010-05-14 00:38:12649}
[email protected]6085c70d2011-03-22 22:51:07650
[email protected]a9723e12013-03-05 04:02:45651void CreateDialogForFileImpl(content::BrowserContext* browser_context,
652 gfx::NativeWindow modal_parent,
653 const base::FilePath& path_to_file,
[email protected]0085863a2013-12-06 21:19:03654 const base::string16& print_job_title,
655 const base::string16& print_ticket,
[email protected]c9060842014-03-13 01:26:19656 const std::string& file_type) {
[email protected]dee01572014-04-18 22:33:44657 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
[email protected]a9723e12013-03-05 04:02:45658 scoped_refptr<base::RefCountedMemory> data;
659 int64 file_size = 0;
[email protected]56285702013-12-04 18:22:49660 if (base::GetFileSize(path_to_file, &file_size) && file_size != 0) {
[email protected]a9723e12013-03-05 04:02:45661 std::string file_data;
662 if (file_size < kuint32max) {
663 file_data.reserve(static_cast<unsigned int>(file_size));
664 } else {
665 DLOG(WARNING) << " print data file too large to reserve space";
666 }
[email protected]82f84b92013-08-30 18:23:50667 if (base::ReadFileToString(path_to_file, &file_data)) {
[email protected]a9723e12013-03-05 04:02:45668 data = base::RefCountedString::TakeString(&file_data);
669 }
670 }
671 // Proceed even for empty data to simplify testing.
672 BrowserThread::PostTask(
673 BrowserThread::UI, FROM_HERE,
674 base::Bind(&print_dialog_cloud::CreatePrintDialogForBytes,
675 browser_context, modal_parent, data, print_job_title,
676 print_ticket, file_type));
[email protected]c9060842014-03-13 01:26:19677 base::DeleteFile(path_to_file, false);
[email protected]6ddda232011-04-22 15:41:47678}
679
[email protected]6085c70d2011-03-22 22:51:07680} // namespace internal_cloud_print_helpers
681
682namespace print_dialog_cloud {
683
[email protected]37ca3fe02013-07-05 15:32:44684void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
[email protected]681958c2013-02-21 13:48:14685 registry->RegisterIntegerPref(
686 prefs::kCloudPrintDialogWidth,
687 kDefaultWidth,
[email protected]443e9312013-05-06 06:17:34688 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]681958c2013-02-21 13:48:14689 registry->RegisterIntegerPref(
690 prefs::kCloudPrintDialogHeight,
691 kDefaultHeight,
[email protected]443e9312013-05-06 06:17:34692 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]681958c2013-02-21 13:48:14693}
694
[email protected]6085c70d2011-03-22 22:51:07695// Called on the FILE or UI thread. This is the main entry point into creating
696// the dialog.
697
[email protected]b5b79d72012-05-24 19:42:28698void CreatePrintDialogForFile(content::BrowserContext* browser_context,
699 gfx::NativeWindow modal_parent,
[email protected]650b2d52013-02-10 03:41:45700 const base::FilePath& path_to_file,
[email protected]0085863a2013-12-06 21:19:03701 const base::string16& print_job_title,
702 const base::string16& print_ticket,
[email protected]c9060842014-03-13 01:26:19703 const std::string& file_type) {
[email protected]6085c70d2011-03-22 22:51:07704 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE) ||
705 BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]6085c70d2011-03-22 22:51:07706 BrowserThread::PostTask(
[email protected]a9723e12013-03-05 04:02:45707 BrowserThread::FILE, FROM_HERE,
708 base::Bind(&internal_cloud_print_helpers::CreateDialogForFileImpl,
[email protected]b5b79d72012-05-24 19:42:28709 browser_context, modal_parent, path_to_file, print_job_title,
[email protected]c9060842014-03-13 01:26:19710 print_ticket, file_type));
[email protected]d955fc92011-09-19 20:49:03711}
712
[email protected]6c465292014-01-14 15:38:31713void CreateCloudPrintSigninTab(Browser* browser,
[email protected]7b92eea9e2014-04-01 09:17:11714 bool add_account,
[email protected]6c465292014-01-14 15:38:31715 const base::Closure& callback) {
[email protected]dee01572014-04-18 22:33:44716 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]8c885f662014-07-04 16:37:34717 if (switches::IsEnableAccountConsistency() &&
718 !browser->profile()->IsOffTheRecord()) {
719 browser->window()->ShowAvatarBubbleFromAvatarButton(
720 add_account ? BrowserWindow::AVATAR_BUBBLE_MODE_ADD_ACCOUNT
721 : BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN,
722 signin::ManageAccountsParams());
723 } else {
724 GURL url = add_account ? cloud_devices::GetCloudPrintAddAccountURL()
725 : cloud_devices::GetCloudPrintSigninURL();
726 content::WebContents* web_contents =
727 browser->OpenURL(content::OpenURLParams(
728 google_util::AppendGoogleLocaleParam(
729 url, g_browser_process->GetApplicationLocale()),
730 content::Referrer(),
731 NEW_FOREGROUND_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35732 ui::PAGE_TRANSITION_AUTO_BOOKMARK,
[email protected]8c885f662014-07-04 16:37:34733 false));
734 new SignInObserver(web_contents, cloud_devices::GetCloudPrintURL(),
735 callback);
736 }
[email protected]4cd49022012-01-19 20:37:37737}
738
[email protected]b5b79d72012-05-24 19:42:28739void CreatePrintDialogForBytes(content::BrowserContext* browser_context,
740 gfx::NativeWindow modal_parent,
[email protected]a9723e12013-03-05 04:02:45741 const base::RefCountedMemory* data,
[email protected]0085863a2013-12-06 21:19:03742 const base::string16& print_job_title,
743 const base::string16& print_ticket,
[email protected]b5b79d72012-05-24 19:42:28744 const std::string& file_type) {
[email protected]a9723e12013-03-05 04:02:45745 internal_cloud_print_helpers::CreateDialogImpl(browser_context, modal_parent,
746 data, print_job_title,
[email protected]6c465292014-01-14 15:38:31747 print_ticket, file_type);
[email protected]6085c70d2011-03-22 22:51:07748}
749
[email protected]39c61872013-12-13 11:48:02750bool CreatePrintDialogFromCommandLine(Profile* profile,
751 const CommandLine& command_line) {
[email protected]87ab41e72012-01-04 18:45:11752 DCHECK(command_line.HasSwitch(switches::kCloudPrintFile));
[email protected]65c9d89a2011-04-13 21:02:39753 if (!command_line.GetSwitchValuePath(switches::kCloudPrintFile).empty()) {
[email protected]650b2d52013-02-10 03:41:45754 base::FilePath cloud_print_file;
[email protected]65c9d89a2011-04-13 21:02:39755 cloud_print_file =
756 command_line.GetSwitchValuePath(switches::kCloudPrintFile);
757 if (!cloud_print_file.empty()) {
[email protected]0085863a2013-12-06 21:19:03758 base::string16 print_job_title;
759 base::string16 print_job_print_ticket;
[email protected]65c9d89a2011-04-13 21:02:39760 if (command_line.HasSwitch(switches::kCloudPrintJobTitle)) {
[email protected]e8368e92011-08-20 04:05:56761 print_job_title =
762 internal_cloud_print_helpers::GetSwitchValueString16(
763 command_line, switches::kCloudPrintJobTitle);
764 }
765 if (command_line.HasSwitch(switches::kCloudPrintPrintTicket)) {
766 print_job_print_ticket =
767 internal_cloud_print_helpers::GetSwitchValueString16(
768 command_line, switches::kCloudPrintPrintTicket);
[email protected]65c9d89a2011-04-13 21:02:39769 }
770 std::string file_type = "application/pdf";
771 if (command_line.HasSwitch(switches::kCloudPrintFileType)) {
772 file_type = command_line.GetSwitchValueASCII(
773 switches::kCloudPrintFileType);
774 }
[email protected]e8368e92011-08-20 04:05:56775
[email protected]c9060842014-03-13 01:26:19776 print_dialog_cloud::CreatePrintDialogForFile(profile, NULL,
777 cloud_print_file, print_job_title, print_job_print_ticket, file_type);
[email protected]65c9d89a2011-04-13 21:02:39778 return true;
779 }
780 }
781 return false;
782}
783
[email protected]228f0f02013-11-15 05:58:36784} // namespace print_dialog_cloud