15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/printing/print_dialog_cloud.h"
6c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/base64.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind_helpers.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/files/file_util.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/json/json_reader.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h"
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/values.h"
17f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "chrome/browser/browser_process.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/devtools/devtools_window.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/lifetime/application_lifetime.h"
20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/printing/print_dialog_cloud_internal.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile.h"
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_dialogs.h"
24116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chrome/browser/ui/browser_window.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/print_messages.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/url_constants.h"
290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "components/cloud_devices/common/cloud_devices_urls.h"
306d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "components/google/core/browser/google_util.h"
31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/pref_registry/pref_registry_syncable.h"
32116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/signin/core/common/profile_management_switches.h"
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/browser_thread.h"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_controller.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_entry.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_registrar.h"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_source.h"
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_types.h"
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/render_view_host.h"
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h"
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/web_contents_observer.h"
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_ui.h"
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/common/frame_navigate_params.h"
44116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/public/common/web_preferences.h"
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(USE_AURA)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window.h"
4823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "ui/aura/window_tree_host.h"
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/win/foreground_helper.h"
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This module implements the UI support in Chrome for cloud printing.
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This means hosting a dialog containing HTML/JavaScript and using
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the published cloud print user interface integration APIs to get
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// page setup settings from the dialog contents and provide the
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// generated print data to the dialog contents for uploading to the
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// cloud print service.
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Currently, the flow between these classes is as follows:
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// PrintDialogCloud::CreatePrintDialogForFile is called from
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// resource_message_filter_gtk.cc once the renderer has informed the
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// renderer host that print data generation into the renderer host provided
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// temp file has been completed.  That call is on the FILE thread.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// That, in turn, hops over to the UI thread to create an instance of
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// PrintDialogCloud.
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The constructor for PrintDialogCloud creates a
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// CloudPrintWebDialogDelegate and asks the current active browser to
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// show an HTML dialog using that class as the delegate. That class
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// hands in the kChromeUICloudPrintResourcesURL as the URL to visit.  That is
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// recognized by the GetWebUIFactoryFunction as a signal to create an
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ExternalWebDialogUI.
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// CloudPrintWebDialogDelegate also temporarily owns a
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// CloudPrintFlowHandler, a class which is responsible for the actual
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interactions with the dialog contents, including handing in the
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// print data and getting any page setup parameters that the dialog
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// contents provides.  As part of bringing up the dialog,
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebDialogUI::RenderViewCreated is called (an override of
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebUI::RenderViewCreated).  That routine, in turn, calls the
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// delegate's GetWebUIMessageHandlers routine, at which point the
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ownership of the CloudPrintFlowHandler is handed over.  A pointer
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to the flow handler is kept to facilitate communication back and
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// forth between the two classes.
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The WebUI continues dialog bring-up, calling
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// CloudPrintFlowHandler::RegisterMessages.  This is where the
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// additional object model capabilities are registered for the dialog
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// contents to use.  It is also at this time that capabilities for the
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// dialog contents are adjusted to allow the dialog contents to close
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the window.  In addition, the pending URL is redirected to the
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// actual cloud print service URL.  The flow controller also registers
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// for notification of when the dialog contents finish loading, which
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is currently used to send the data to the dialog contents.
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// In order to send the data to the dialog contents, the flow
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// handler uses a CloudPrintDataSender.  It creates one, letting it
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// know the name of the temporary file containing the data, and
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// posts the task of reading the file
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (CloudPrintDataSender::ReadPrintDataFile) to the file thread.  That
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// routine reads in the file, and then hops over to the IO thread to
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// send that data to the dialog contents.
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// When the dialog contents are finished (by either being cancelled or
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// hitting the print button), the delegate is notified, and responds
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that the dialog should be closed, at which point things are torn
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// down and released.
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::BrowserThread;
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::NavigationController;
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::NavigationEntry;
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::RenderViewHost;
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::WebContents;
118116680a4aac90f2aa7413d9095a592090648e557Ben Murdochusing content::WebPreferences;
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::WebUIMessageHandler;
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using ui::WebDialogDelegate;
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace {
1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kDefaultWidth = 912;
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kDefaultHeight = 633;
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool IsSimilarUrl(const GURL& url, const GURL& cloud_print_url) {
1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return url.host() == cloud_print_url.host() &&
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)         StartsWithASCII(url.path(), cloud_print_url.path(), false) &&
1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)         url.scheme() == cloud_print_url.scheme();
1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class SignInObserver : public content::WebContentsObserver {
1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SignInObserver(content::WebContents* web_contents,
1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 GURL cloud_print_url,
1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 const base::Closure& callback)
1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : WebContentsObserver(web_contents),
1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        cloud_print_url_(cloud_print_url),
1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        callback_(callback),
1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        weak_ptr_factory_(this) {
1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Overridden from content::WebContentsObserver:
1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void DidNavigateMainFrame(
1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const content::LoadCommittedDetails& details,
1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const content::FrameNavigateParams& params) OVERRIDE {
1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (IsSimilarUrl(params.url, cloud_print_url_)) {
1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::MessageLoop::current()->PostTask(
1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          FROM_HERE,
1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          base::Bind(&SignInObserver::OnSignIn,
1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     weak_ptr_factory_.GetWeakPtr()));
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
157010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void WebContentsDestroyed() OVERRIDE {
1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    delete this;
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void OnSignIn() {
1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    callback_.Run();
1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (web_contents())
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      web_contents()->Close();
1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GURL cloud_print_url_;
1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::Closure callback_;
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::WeakPtrFactory<SignInObserver> weak_ptr_factory_;
1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SignInObserver);
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace internal_cloud_print_helpers {
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// From the JSON parsed value, get the entries for the page setup
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// parameters.
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool GetPageSetupParameters(const std::string& json,
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            PrintMsg_Print_Params& parameters) {
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<base::Value> parsed_value(base::JSONReader::Read(json));
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DLOG_IF(ERROR, (!parsed_value.get() ||
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  !parsed_value->IsType(base::Value::TYPE_DICTIONARY)))
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << "PageSetup call didn't have expected contents";
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!parsed_value.get() ||
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      !parsed_value->IsType(base::Value::TYPE_DICTIONARY)) {
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool result = true;
1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::DictionaryValue* params =
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      static_cast<base::DictionaryValue*>(parsed_value.get());
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  result &= params->GetDouble("dpi", &parameters.dpi);
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  result &= params->GetDouble("min_shrink", &parameters.min_shrink);
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  result &= params->GetDouble("max_shrink", &parameters.max_shrink);
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  result &= params->GetBoolean("selection_only", &parameters.selection_only);
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return result;
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
201f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)base::string16 GetSwitchValueString16(const CommandLine& command_line,
202f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                      const char* switchName) {
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
204f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return command_line.GetSwitchValueNative(switchName);
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(OS_POSIX)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // POSIX Command line string types are different.
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CommandLine::StringType native_switch_val;
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  native_switch_val = command_line.GetSwitchValueASCII(switchName);
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Convert the ASCII string to UTF16 to prepare to pass.
210f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return base::ASCIIToUTF16(native_switch_val);
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintDataSenderHelper::CallJavascriptFunction(
2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& function_name,
2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const base::Value& arg1,
2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const base::Value& arg2) {
218f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  web_ui_->CallJavascriptFunction(function_name, arg1, arg2);
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Clears out the pointer we're using to communicate.  Either routine is
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// potentially expensive enough that stopping whatever is in progress
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is worth it.
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintDataSender::CancelPrintDataFile() {
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::AutoLock lock(lock_);
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We don't own helper, it was passed in to us, so no need to
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // delete, just let it go.
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  helper_ = NULL;
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
231a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)CloudPrintDataSender::CloudPrintDataSender(
232a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    CloudPrintDataSenderHelper* helper,
233a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16& print_job_title,
234a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16& print_ticket,
235a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const std::string& file_type,
236a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::RefCountedMemory* data)
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : helper_(helper),
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      print_job_title_(print_job_title),
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      print_ticket_(print_ticket),
2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      file_type_(file_type),
2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      data_(data) {
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)CloudPrintDataSender::~CloudPrintDataSender() {}
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// We have the data in hand that needs to be pushed into the dialog
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// contents; do so from the IO thread.
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(scottbyer): If the print data ends up being larger than the
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// upload limit (currently 10MB), what we need to do is upload that
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// large data to google docs and set the URL in the printing
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// JavaScript to that location, and make sure it gets deleted when not
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// needed. - 4/1/2010
2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void CloudPrintDataSender::SendPrintData() {
2550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DCHECK_CURRENTLY_ON(BrowserThread::IO);
256868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if (!data_.get() || !data_->size())
2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return;
2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string base64_data;
2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::Base64Encode(
2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::StringPiece(data_->front_as<char>(), data_->size()),
2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      &base64_data);
2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string header("data:");
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  header.append(file_type_);
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  header.append(";base64,");
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base64_data.insert(0, header);
2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::AutoLock lock(lock_);
2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (helper_) {
270f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    base::StringValue title(print_job_title_);
271f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    base::StringValue ticket(print_ticket_);
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // TODO(abodenha): Change Javascript call to pass in print ticket
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // after server side support is added. Add test for it.
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Send the print data to the dialog contents.  The JavaScript
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // function is a preliminary API for prototyping purposes and is
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // subject to change.
278f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    helper_->CallJavascriptFunction(
279f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        "printApp._printDataUrl", base::StringValue(base64_data), title);
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
284a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)CloudPrintFlowHandler::CloudPrintFlowHandler(
285a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::RefCountedMemory* data,
286a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16& print_job_title,
287a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16& print_ticket,
2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& file_type)
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : dialog_delegate_(NULL),
2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      data_(data),
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      print_job_title_(print_job_title),
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      print_ticket_(print_ticket),
2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      file_type_(file_type) {
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)CloudPrintFlowHandler::~CloudPrintFlowHandler() {
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This will also cancel any task in flight.
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CancelAnyRunningTask();
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintFlowHandler::SetDialogDelegate(
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CloudPrintWebDialogDelegate* delegate) {
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Even if setting a new WebUI, it means any previous task needs
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to be canceled, its now invalid.
3060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DCHECK_CURRENTLY_ON(BrowserThread::UI);
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CancelAnyRunningTask();
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  dialog_delegate_ = delegate;
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Cancels any print data sender we have in flight and removes our
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// reference to it, so when the task that is calling it finishes and
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// removes its reference, it goes away.
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintFlowHandler::CancelAnyRunningTask() {
3150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DCHECK_CURRENTLY_ON(BrowserThread::UI);
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (print_data_sender_.get()) {
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    print_data_sender_->CancelPrintDataFile();
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    print_data_sender_ = NULL;
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintFlowHandler::RegisterMessages() {
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(scottbyer) - This is where we will register messages for the
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // UI JS to use.  Needed: Call to update page setup parameters.
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_ui()->RegisterMessageCallback("ShowDebugger",
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::Bind(&CloudPrintFlowHandler::HandleShowDebugger,
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 base::Unretained(this)));
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_ui()->RegisterMessageCallback("SendPrintData",
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::Bind(&CloudPrintFlowHandler::HandleSendPrintData,
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 base::Unretained(this)));
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_ui()->RegisterMessageCallback("SetPageParameters",
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::Bind(&CloudPrintFlowHandler::HandleSetPageParameters,
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 base::Unretained(this)));
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Register for appropriate notifications, and re-direct the URL
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to the real server URL, now that we've gotten an HTML dialog
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // going.
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NavigationController* controller =
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      &web_ui()->GetWebContents()->GetController();
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NavigationEntry* pending_entry = controller->GetPendingEntry();
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (pending_entry) {
3420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    pending_entry->SetURL(google_util::AppendGoogleLocaleParam(
343f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        cloud_devices::GetCloudPrintRelativeURL("client/dialog.html"),
344f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        g_browser_process->GetApplicationLocale()));
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 content::Source<NavigationController>(controller));
3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
3492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                 content::Source<NavigationController>(controller));
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintFlowHandler::Observe(
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int type,
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const content::NotificationSource& source,
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const content::NotificationDetails& details) {
3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  switch (type) {
3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case content::NOTIFICATION_LOAD_STOP: {
3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      GURL url = web_ui()->GetWebContents()->GetURL();
359b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      if (IsCloudPrintDialogUrl(url)) {
360b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        // Take the opportunity to set some (minimal) additional
361b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        // script permissions required for the web UI.
3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost();
3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        if (rvh) {
3646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)          // TODO(chrishtr): this is wrong. allow_scripts_to_close_windows will
3656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)          // be reset the next time a preference changes.
366c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          WebPreferences webkit_prefs = rvh->GetWebkitPreferences();
3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          webkit_prefs.allow_scripts_to_close_windows = true;
3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          rvh->UpdateWebkitPreferences(webkit_prefs);
3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        } else {
3702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          NOTREACHED();
3712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        }
372b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        // Choose one or the other.  If you need to debug, bring up the
373b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        // debugger.  You can then use the various chrome.send()
374b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        // registrations above to kick of the various function calls,
375b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        // including chrome.send("SendPrintData") in the javaScript
376b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        // console and watch things happen with:
377b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        // HandleShowDebugger(NULL);
378b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        HandleSendPrintData(NULL);
3792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      }
3802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
3812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void CloudPrintFlowHandler::HandleShowDebugger(const base::ListValue* args) {
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ShowDebugger();
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintFlowHandler::ShowDebugger() {
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (web_ui()) {
3916e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    WebContents* web_contents = web_ui()->GetWebContents();
3926e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    if (web_contents)
3936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      DevToolsWindow::OpenDevToolsWindow(web_contents);
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_refptr<CloudPrintDataSender>
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)CloudPrintFlowHandler::CreateCloudPrintDataSender() {
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(web_ui());
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  print_data_helper_.reset(new CloudPrintDataSenderHelper(web_ui()));
4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_refptr<CloudPrintDataSender> sender(
402868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      new CloudPrintDataSender(print_data_helper_.get(),
403868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                               print_job_title_,
404868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                               print_ticket_,
405868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                               file_type_,
406868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                               data_.get()));
4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return sender;
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void CloudPrintFlowHandler::HandleSendPrintData(const base::ListValue* args) {
4110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DCHECK_CURRENTLY_ON(BrowserThread::UI);
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This will cancel any ReadPrintDataFile() or SendPrintDataFile()
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // requests in flight (this is anticipation of when setting page
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // setup parameters becomes asynchronous and may be set while some
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // data is in flight).  Then we can clear out the print data.
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CancelAnyRunningTask();
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (web_ui()) {
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    print_data_sender_ = CreateCloudPrintDataSender();
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    BrowserThread::PostTask(
4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        BrowserThread::IO, FROM_HERE,
4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        base::Bind(&CloudPrintDataSender::SendPrintData, print_data_sender_));
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void CloudPrintFlowHandler::HandleSetPageParameters(
4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const base::ListValue* args) {
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string json;
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ret = args->GetString(0, &json);
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!ret || json.empty()) {
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NOTREACHED() << "Empty json string";
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // These are backstop default values - 72 dpi to match the screen,
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 8.5x11 inch paper with margins subtracted (1/4 inch top, left,
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // right and 0.56 bottom), and the min page shrink and max page
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // shrink values appear all over the place with no explanation.
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(scottbyer): Get a Linux/ChromeOS edge for PrintSettings
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // working so that we can get the default values from there.  Fix up
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // PrintWebViewHelper to do the same.
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const int kDPI = 72;
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const int kWidth = static_cast<int>((8.5-0.25-0.25)*kDPI);
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const int kHeight = static_cast<int>((11-0.25-0.56)*kDPI);
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const double kMinPageShrink = 1.25;
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const double kMaxPageShrink = 2.0;
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PrintMsg_Print_Params default_settings;
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_settings.content_size = gfx::Size(kWidth, kHeight);
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_settings.printable_area = gfx::Rect(0, 0, kWidth, kHeight);
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_settings.dpi = kDPI;
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_settings.min_shrink = kMinPageShrink;
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_settings.max_shrink = kMaxPageShrink;
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_settings.desired_dpi = kDPI;
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_settings.document_cookie = 0;
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_settings.selection_only = false;
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_settings.preview_request_id = 0;
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_settings.is_first_request = true;
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_settings.print_to_pdf = false;
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!GetPageSetupParameters(json, default_settings)) {
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NOTREACHED();
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(scottbyer) - Here is where we would kick the originating
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // renderer thread with these new parameters in order to get it to
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // re-generate the PDF data and hand it back to us.  window.print() is
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // currently synchronous, so there's a lot of work to do to get to
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that point.
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintFlowHandler::StoreDialogClientSize() const {
474010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  if (web_ui() && web_ui()->GetWebContents()) {
475010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    gfx::Size size = web_ui()->GetWebContents()->GetContainerBounds().size();
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Profile* profile = Profile::FromWebUI(web_ui());
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogWidth,
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    size.width());
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    profile->GetPrefs()->SetInteger(prefs::kCloudPrintDialogHeight,
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    size.height());
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
484b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)bool CloudPrintFlowHandler::IsCloudPrintDialogUrl(const GURL& url) {
4850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  GURL cloud_print_url = cloud_devices::GetCloudPrintURL();
4865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return IsSimilarUrl(url, cloud_print_url);
487b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
488b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate(
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content::BrowserContext* browser_context,
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gfx::NativeWindow modal_parent,
4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const base::RefCountedMemory* data,
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::string& json_arguments,
494a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16& print_job_title,
495a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16& print_ticket,
4965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& file_type)
4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : flow_handler_(
4982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          new CloudPrintFlowHandler(data, print_job_title, print_ticket,
4995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                    file_type)),
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      modal_parent_(modal_parent),
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      owns_flow_handler_(true),
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      keep_alive_when_non_modal_(true) {
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Init(browser_context, json_arguments);
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// For unit testing.
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)CloudPrintWebDialogDelegate::CloudPrintWebDialogDelegate(
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CloudPrintFlowHandler* flow_handler,
5092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const std::string& json_arguments)
5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : flow_handler_(flow_handler),
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      modal_parent_(NULL),
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      owns_flow_handler_(true),
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      keep_alive_when_non_modal_(false) {
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Init(NULL, json_arguments);
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the persisted width/height for the print dialog.
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void GetDialogWidthAndHeightFromPrefs(content::BrowserContext* browser_context,
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      int* width,
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      int* height) {
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!browser_context) {
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    *width = kDefaultWidth;
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    *height = kDefaultHeight;
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  PrefService* prefs = Profile::FromBrowserContext(browser_context)->GetPrefs();
5282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  *width = prefs->GetInteger(prefs::kCloudPrintDialogWidth);
5292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  *height = prefs->GetInteger(prefs::kCloudPrintDialogHeight);
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintWebDialogDelegate::Init(content::BrowserContext* browser_context,
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       const std::string& json_arguments) {
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This information is needed to show the dialog HTML content.
5350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DCHECK_CURRENTLY_ON(BrowserThread::UI);
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  params_.url = GURL(chrome::kChromeUICloudPrintResourcesURL);
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetDialogWidthAndHeightFromPrefs(browser_context,
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   &params_.width,
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   &params_.height);
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  params_.json_input = json_arguments;
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  flow_handler_->SetDialogDelegate(this);
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If we're not modal we can show the dialog with no browser.
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We need this to keep Chrome alive while our dialog is up.
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!modal_parent_ && keep_alive_when_non_modal_)
547a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    chrome::IncrementKeepAliveCount();
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)CloudPrintWebDialogDelegate::~CloudPrintWebDialogDelegate() {
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If the flow_handler_ is about to outlive us because we don't own
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // it anymore, we need to have it remove its reference to us.
5530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DCHECK_CURRENTLY_ON(BrowserThread::UI);
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  flow_handler_->SetDialogDelegate(NULL);
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (owns_flow_handler_) {
5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delete flow_handler_;
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ui::ModalType CloudPrintWebDialogDelegate::GetDialogModalType() const {
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return modal_parent_ ? ui::MODAL_TYPE_WINDOW : ui::MODAL_TYPE_NONE;
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::string16 CloudPrintWebDialogDelegate::GetDialogTitle() const {
565a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return base::string16();
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GURL CloudPrintWebDialogDelegate::GetDialogContentURL() const {
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return params_.url;
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintWebDialogDelegate::GetWebUIMessageHandlers(
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    std::vector<WebUIMessageHandler*>* handlers) const {
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  handlers->push_back(flow_handler_);
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We don't own flow_handler_ anymore, but it sticks around until at
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // least right after OnDialogClosed() is called (and this object is
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // destroyed).
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  owns_flow_handler_ = false;
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintWebDialogDelegate::GetDialogSize(gfx::Size* size) const {
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  size->set_width(params_.width);
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  size->set_height(params_.height);
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)std::string CloudPrintWebDialogDelegate::GetDialogArgs() const {
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return params_.json_input;
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintWebDialogDelegate::OnDialogClosed(
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::string& json_retval) {
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the final dialog size and store it.
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  flow_handler_->StoreDialogClientSize();
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If we're modal we can show the dialog with no browser.
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // End the keep-alive so that Chrome can exit.
597f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (!modal_parent_ && keep_alive_when_non_modal_) {
598f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // Post to prevent recursive call tho this function.
599a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    base::MessageLoop::current()->PostTask(
600a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        FROM_HERE, base::Bind(&chrome::DecrementKeepAliveCount));
601f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  delete this;
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CloudPrintWebDialogDelegate::OnCloseContents(WebContents* source,
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                  bool* out_close_dialog) {
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (out_close_dialog)
6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    *out_close_dialog = true;
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool CloudPrintWebDialogDelegate::ShouldShowDialogTitle() const {
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return false;
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool CloudPrintWebDialogDelegate::HandleContextMenu(
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const content::ContextMenuParams& params) {
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Called from the UI thread, starts up the dialog.
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CreateDialogImpl(content::BrowserContext* browser_context,
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                      gfx::NativeWindow modal_parent,
6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                      const base::RefCountedMemory* data,
624a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                      const base::string16& print_job_title,
625a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                      const base::string16& print_ticket,
6265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                      const std::string& file_type) {
6270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DCHECK_CURRENTLY_ON(BrowserThread::UI);
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebDialogDelegate* dialog_delegate =
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      new internal_cloud_print_helpers::CloudPrintWebDialogDelegate(
6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          browser_context, modal_parent, data, std::string(), print_job_title,
6315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          print_ticket, file_type);
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::NativeWindow window =
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::ShowWebDialog(modal_parent,
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            Profile::FromBrowserContext(browser_context),
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            dialog_delegate);
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (window) {
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    HWND dialog_handle;
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(USE_AURA)
642a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    dialog_handle = window->GetHost()->GetAcceleratedWidget();
6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    dialog_handle = window;
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (::GetForegroundWindow() != dialog_handle) {
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ui::ForegroundHelper::SetForeground(dialog_handle);
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void CreateDialogForFileImpl(content::BrowserContext* browser_context,
6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             gfx::NativeWindow modal_parent,
6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             const base::FilePath& path_to_file,
656a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                             const base::string16& print_job_title,
657a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                             const base::string16& print_ticket,
658a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                             const std::string& file_type) {
6590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DCHECK_CURRENTLY_ON(BrowserThread::FILE);
6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_refptr<base::RefCountedMemory> data;
6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int64 file_size = 0;
662a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (base::GetFileSize(path_to_file, &file_size) && file_size != 0) {
6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    std::string file_data;
6642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (file_size < kuint32max) {
6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      file_data.reserve(static_cast<unsigned int>(file_size));
6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    } else {
6672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      DLOG(WARNING) << " print data file too large to reserve space";
6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
66958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    if (base::ReadFileToString(path_to_file, &file_data)) {
6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      data = base::RefCountedString::TakeString(&file_data);
6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Proceed even for empty data to simplify testing.
6742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  BrowserThread::PostTask(
6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      BrowserThread::UI, FROM_HERE,
6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::Bind(&print_dialog_cloud::CreatePrintDialogForBytes,
6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                 browser_context, modal_parent, data, print_job_title,
6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                 print_ticket, file_type));
679a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  base::DeleteFile(path_to_file, false);
6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace internal_cloud_print_helpers
6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace print_dialog_cloud {
6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  registry->RegisterIntegerPref(
6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      prefs::kCloudPrintDialogWidth,
6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      kDefaultWidth,
690c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  registry->RegisterIntegerPref(
6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      prefs::kCloudPrintDialogHeight,
6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      kDefaultHeight,
694c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Called on the FILE or UI thread.  This is the main entry point into creating
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the dialog.
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CreatePrintDialogForFile(content::BrowserContext* browser_context,
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              gfx::NativeWindow modal_parent,
7022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                              const base::FilePath& path_to_file,
703a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                              const base::string16& print_job_title,
704a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                              const base::string16& print_ticket,
705a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                              const std::string& file_type) {
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE) ||
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         BrowserThread::CurrentlyOn(BrowserThread::UI));
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BrowserThread::PostTask(
7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      BrowserThread::FILE, FROM_HERE,
7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::Bind(&internal_cloud_print_helpers::CreateDialogForFileImpl,
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 browser_context, modal_parent, path_to_file, print_job_title,
712a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                 print_ticket, file_type));
7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void CreateCloudPrintSigninTab(Browser* browser,
716e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch                               bool add_account,
7175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                               const base::Closure& callback) {
7180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DCHECK_CURRENTLY_ON(BrowserThread::UI);
719116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (switches::IsEnableAccountConsistency() &&
720116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      !browser->profile()->IsOffTheRecord()) {
721116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    browser->window()->ShowAvatarBubbleFromAvatarButton(
722116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        add_account ? BrowserWindow::AVATAR_BUBBLE_MODE_ADD_ACCOUNT
723116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                    : BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN,
724116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        signin::ManageAccountsParams());
725116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  } else {
726116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    GURL url = add_account ? cloud_devices::GetCloudPrintAddAccountURL()
727116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                           : cloud_devices::GetCloudPrintSigninURL();
728116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    content::WebContents* web_contents =
729116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        browser->OpenURL(content::OpenURLParams(
730116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch            google_util::AppendGoogleLocaleParam(
731116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                url, g_browser_process->GetApplicationLocale()),
732116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch            content::Referrer(),
733116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch            NEW_FOREGROUND_TAB,
7341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            ui::PAGE_TRANSITION_AUTO_BOOKMARK,
735116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch            false));
736116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    new SignInObserver(web_contents, cloud_devices::GetCloudPrintURL(),
737116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        callback);
738116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CreatePrintDialogForBytes(content::BrowserContext* browser_context,
7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               gfx::NativeWindow modal_parent,
7432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                               const base::RefCountedMemory* data,
744a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                               const base::string16& print_job_title,
745a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                               const base::string16& print_ticket,
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               const std::string& file_type) {
7472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  internal_cloud_print_helpers::CreateDialogImpl(browser_context, modal_parent,
7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                 data, print_job_title,
7495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                                 print_ticket, file_type);
7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool CreatePrintDialogFromCommandLine(Profile* profile,
7535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                      const CommandLine& command_line) {
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(command_line.HasSwitch(switches::kCloudPrintFile));
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!command_line.GetSwitchValuePath(switches::kCloudPrintFile).empty()) {
7562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    base::FilePath cloud_print_file;
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cloud_print_file =
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        command_line.GetSwitchValuePath(switches::kCloudPrintFile);
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!cloud_print_file.empty()) {
760a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      base::string16 print_job_title;
761a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      base::string16 print_job_print_ticket;
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (command_line.HasSwitch(switches::kCloudPrintJobTitle)) {
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        print_job_title =
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          internal_cloud_print_helpers::GetSwitchValueString16(
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              command_line, switches::kCloudPrintJobTitle);
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (command_line.HasSwitch(switches::kCloudPrintPrintTicket)) {
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        print_job_print_ticket =
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          internal_cloud_print_helpers::GetSwitchValueString16(
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              command_line, switches::kCloudPrintPrintTicket);
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      std::string file_type = "application/pdf";
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (command_line.HasSwitch(switches::kCloudPrintFileType)) {
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        file_type = command_line.GetSwitchValueASCII(
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            switches::kCloudPrintFileType);
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
778a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      print_dialog_cloud::CreatePrintDialogForFile(profile, NULL,
779a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)          cloud_print_file, print_job_title, print_job_print_ticket, file_type);
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return true;
7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return false;
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
786f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace print_dialog_cloud
787