cloud_print_setup_flow.h revision 513209b27ff55e2841eac0e4120199c23acce758
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_SETUP_FLOW_H_ 6#define CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_SETUP_FLOW_H_ 7 8#include <string> 9#include <vector> 10 11#include "app/l10n_util.h" 12#include "base/time.h" 13#include "chrome/browser/dom_ui/html_dialog_ui.h" 14#include "chrome/common/net/gaia/gaia_auth_consumer.h" 15#include "chrome/common/net/gaia/gaia_authenticator2.h" 16#include "gfx/native_widget_types.h" 17#include "grit/generated_resources.h" 18 19class GaiaAuthenticator2; 20class CloudPrintServiceProcessHelper; 21class CloudPrintSetupMessageHandler; 22class ServiceProcessControl; 23class GoogleServiceAuthError; 24class Browser; 25 26// This class is responsible for showing a cloud print setup dialog 27// and perform operations to fill the content of the dialog and handle 28// user actions in the dialog. 29// 30// It is responsible for: 31// 1. Showing the setup dialog. 32// 2. Providing the URL for the content of the dialog. 33// 3. Providing a data source to provide the content HTML files. 34// 4. Providing a message handler to handle user actions in the DOM UI. 35// 5. Responding to actions received in the message handler. 36// 37// The architecture for DOMUI is designed such that only the message handler 38// can access the DOMUI. This splits the flow control across the message 39// handler and this class. In order to centralize all the flow control and 40// content in the DOMUI, the DOMUI object is given to this object by the 41// message handler through the Attach(DOMUI*) method. 42class CloudPrintSetupFlow : public HtmlDialogUIDelegate, 43 public GaiaAuthConsumer { 44 public: 45 class Delegate { 46 public: 47 virtual ~Delegate() {} 48 // Called when the setup dialog is closed. 49 virtual void OnDialogClosed() = 0; 50 }; 51 virtual ~CloudPrintSetupFlow(); 52 53 // Runs a flow from |start| to |end|, and does the work of actually showing 54 // the HTML dialog. |container| is kept up-to-date with the lifetime of the 55 // flow (e.g it is emptied on dialog close). 56 static CloudPrintSetupFlow* OpenDialog(Profile* service, Delegate* delegate, 57 gfx::NativeWindow parent_window); 58 59 // Focuses the dialog. This is useful in cases where the dialog has been 60 // obscured by a browser window. 61 void Focus(); 62 63 // HtmlDialogUIDelegate implementation. 64 virtual GURL GetDialogContentURL() const; 65 virtual void GetDOMMessageHandlers( 66 std::vector<DOMMessageHandler*>* handlers) const; 67 virtual void GetDialogSize(gfx::Size* size) const; 68 virtual std::string GetDialogArgs() const; 69 virtual void OnDialogClosed(const std::string& json_retval); 70 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog); 71 virtual std::wstring GetDialogTitle() const; 72 virtual bool IsDialogModal() const; 73 virtual bool ShouldShowDialogTitle() const { return true; } 74 75 // GaiaAuthConsumer implementation. 76 virtual void OnClientLoginFailure( 77 const GoogleServiceAuthError& error); 78 virtual void OnClientLoginSuccess( 79 const GaiaAuthConsumer::ClientLoginResult& credentials); 80 81 private: 82 friend class CloudPrintServiceProcessHelper; 83 friend class CloudPrintSetupMessageHandler; 84 85 // Use static Run method to get an instance. 86 CloudPrintSetupFlow(const std::string& args, Profile* profile, 87 Delegate* delegate); 88 89 // Called CloudPrintSetupMessageHandler when a DOM is attached. This method 90 // is called when the HTML page is fully loaded. We then operate on this 91 // DOMUI object directly. 92 void Attach(DOMUI* dom_ui); 93 94 // Called by CloudPrintSetupMessageHandler when user authentication is 95 // registered. 96 void OnUserSubmittedAuth(const std::string& user, 97 const std::string& password, 98 const std::string& captcha); 99 100 // The following methods control which iframe is visible. 101 void ShowGaiaLogin(const DictionaryValue& args); 102 void ShowGaiaSuccessAndSettingUp(); 103 void ShowGaiaFailed(const GoogleServiceAuthError& error); 104 void ShowSetupDone(); 105 void ExecuteJavascriptInIFrame(const std::wstring& iframe_xpath, 106 const std::wstring& js); 107 108 // Pointer to the DOM UI. This is provided by CloudPrintSetupMessageHandler 109 // when attached. 110 DOMUI* dom_ui_; 111 112 // The args to pass to the initial page. 113 std::string dialog_start_args_; 114 Profile* profile_; 115 116 // Fetcher to obtain the Chromoting Directory token. 117 scoped_ptr<GaiaAuthenticator2> authenticator_; 118 std::string login_; 119 std::string lsid_; 120 121 // Handle to the ServiceProcessControl which talks to the service process. 122 ServiceProcessControl* process_control_; 123 Delegate* delegate_; 124 125 DISALLOW_COPY_AND_ASSIGN(CloudPrintSetupFlow); 126}; 127 128#endif // CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_SETUP_FLOW_H_ 129