diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-28 18:14:23 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-28 18:14:23 +0000 |
commit | a9125703559d60a1aaeab24bc7d1a17b53682c41 (patch) | |
tree | da03b30dda2e0600cabf51b781586fffa6f649cb /chrome | |
parent | 6f2d84c8437f25886f4e6822004b397ce50b26c4 (diff) | |
download | chromium_src-a9125703559d60a1aaeab24bc7d1a17b53682c41.zip chromium_src-a9125703559d60a1aaeab24bc7d1a17b53682c41.tar.gz chromium_src-a9125703559d60a1aaeab24bc7d1a17b53682c41.tar.bz2 |
Changed the CloudPrintSetupFlow to not create a Browser object. Made the setup flow dialog modeless. Added a delegate to CloudPrintSetupFlow. Hooked up the expired token notifications handler to the CloudPrintSetupFlow dialog.
BUG=None
TEST=Test Cloud print proxy UI.
Review URL: http://codereview.chromium.org/3433027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60814 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
7 files changed, 80 insertions, 35 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 9d6e3c5..783ff7e 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1928,10 +1928,6 @@ void Browser::OpenLanguageOptionsDialog() { } #endif -void Browser::OpenCloudPrintProxySetupDialog() { - CloudPrintSetupFlow::OpenDialog(profile_); -} - /////////////////////////////////////////////////////////////////////////////// // static diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 478bd8b..27e8db0 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -547,7 +547,6 @@ class Browser : public TabStripModelDelegate, void OpenLanguageOptionsDialog(); void OpenSystemOptionsDialog(); #endif - void OpenCloudPrintProxySetupDialog(); virtual void UpdateDownloadShelfVisibility(bool visible); diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc index d1fc6a5..1067923 100644 --- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc +++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc @@ -14,7 +14,9 @@ #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_ui_manager.h" +#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profile.h" +#include "chrome/common/pref_names.h" #include "grit/generated_resources.h" // TODO(sanjeevr): Localize the product name? @@ -93,25 +95,34 @@ bool CloudPrintProxyService::ShowTokenExpiredNotification() { } void CloudPrintProxyService::OnTokenExpiredNotificationError() { - TokenExpiredNotificationDone(); + TokenExpiredNotificationDone(false); } void CloudPrintProxyService::OnTokenExpiredNotificationClosed(bool by_user) { - TokenExpiredNotificationDone(); + TokenExpiredNotificationDone(false); } void CloudPrintProxyService::OnTokenExpiredNotificationClick() { - TokenExpiredNotificationDone(); - // TODO(sanjeevr): Launch the cloud print setup flow. + TokenExpiredNotificationDone(true); + // Clear the cached cloud print email pref so that the cloud print setup + // flow happens. + profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); + CloudPrintSetupFlow::OpenDialog(profile_, this, NULL); } -void CloudPrintProxyService::TokenExpiredNotificationDone() { +void CloudPrintProxyService::TokenExpiredNotificationDone(bool keep_alive) { if (token_expired_delegate_.get()) { g_browser_process->notification_ui_manager()->Cancel( Notification(GURL(), GURL(), string16(), string16(), token_expired_delegate_.get())); token_expired_delegate_ = NULL; - BrowserList::EndKeepAlive(); + if (!keep_alive) + BrowserList::EndKeepAlive(); } } +void CloudPrintProxyService::OnDialogClosed() { + MessageLoop::current()->PostTask( + FROM_HERE, NewRunnableFunction(&BrowserList::EndKeepAlive)); +} + diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h index db2240f..538da2c 100644 --- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h +++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h @@ -11,12 +11,13 @@ #include "base/basictypes.h" #include "base/observer_list.h" #include "base/ref_counted.h" +#include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" class Profile; // Layer between the browser user interface and the cloud print proxy code // running in the service process. -class CloudPrintProxyService { +class CloudPrintProxyService : public CloudPrintSetupFlow::Delegate { public: explicit CloudPrintProxyService(Profile* profile); virtual ~CloudPrintProxyService(); @@ -31,6 +32,9 @@ class CloudPrintProxyService { bool ShowTokenExpiredNotification(); + // CloudPrintSetupFlow::Delegate implementation. + virtual void OnDialogClosed(); + private: // NotificationDelegate implementation for the token expired notification. class TokenExpiredNotificationDelegate; @@ -43,7 +47,7 @@ class CloudPrintProxyService { void OnTokenExpiredNotificationError(); void OnTokenExpiredNotificationClosed(bool by_user); void OnTokenExpiredNotificationClick(); - void TokenExpiredNotificationDone(); + void TokenExpiredNotificationDone(bool keep_alive); DISALLOW_COPY_AND_ASSIGN(CloudPrintProxyService); diff --git a/chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc b/chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc index 566fed4..54fcab6 100644 --- a/chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc +++ b/chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc @@ -14,6 +14,9 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" #include "chrome/browser/dom_ui/dom_ui_util.h" +#if defined(TOOLKIT_GTK) +#include "chrome/browser/gtk/html_dialog_gtk.h" +#endif // defined(TOOLKIT_GTK) #include "chrome/browser/platform_util.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/printing/cloud_print/cloud_print_setup_message_handler.h" @@ -23,6 +26,9 @@ #include "chrome/browser/service/service_process_control.h" #include "chrome/browser/service/service_process_control_manager.h" #include "chrome/browser/tab_contents/tab_contents.h" +#if defined(TOOLKIT_VIEWS) +#include "chrome/browser/views/browser_dialogs.h" +#endif // defined(TOOLKIT_GTK) #include "chrome/common/net/gaia/gaia_authenticator2.h" #include "chrome/common/net/gaia/gaia_constants.h" #include "chrome/common/net/gaia/google_service_auth_error.h" @@ -176,7 +182,8 @@ class CloudPrintServiceRefreshTask // CloudPrintSetupFlow implementation. // static -CloudPrintSetupFlow* CloudPrintSetupFlow::OpenDialog(Profile* profile) { +CloudPrintSetupFlow* CloudPrintSetupFlow::OpenDialog( + Profile* profile, Delegate* delegate, gfx::NativeWindow parent_window) { // Set the arguments for showing the gaia login page. DictionaryValue args; args.SetString("iframeToShow", "login"); @@ -192,13 +199,25 @@ CloudPrintSetupFlow* CloudPrintSetupFlow::OpenDialog(Profile* profile) { std::string json_args; base::JSONWriter::Write(&args, false, &json_args); - // Create a browser to run the dialog. The new CloudPrintSetupFlow - // class takes ownership. - Browser* browser = Browser::CreateForPopup(profile); - DCHECK(browser); - - CloudPrintSetupFlow* flow = new CloudPrintSetupFlow(json_args, browser); - browser->BrowserShowHtmlDialog(flow, NULL); + CloudPrintSetupFlow* flow = new CloudPrintSetupFlow(json_args, profile, + delegate); + // We may not always have a browser. This can happen when we are being + // invoked in the context of a "token expired" notfication. If we don't have + // a brower, use the underlying dialog system to show the dialog without + // using a browser. + Browser* browser = BrowserList::GetLastActive(); + if (browser) { + browser->BrowserShowHtmlDialog(flow, parent_window); + } else { +#if defined(TOOLKIT_VIEWS) + browser::ShowHtmlDialogView(parent_window, profile, flow); +#elif defined(TOOLKIT_GTK) + HtmlDialogGtk* html_dialog = + new HtmlDialogGtk(profile, flow, parent_window); + html_dialog->InitDialog(); +#endif // defined(TOOLKIT_VIEWS) + // TODO(sanjeevr): Implement the "no browser" scenario for the Mac. + } return flow; } @@ -225,12 +244,14 @@ void CloudPrintSetupFlow::RefreshPreferencesFromService( } CloudPrintSetupFlow::CloudPrintSetupFlow(const std::string& args, - Browser* browser) + Profile* profile, + Delegate* delegate) : dom_ui_(NULL), dialog_start_args_(args), - process_control_(NULL) { + process_control_(NULL), + delegate_(delegate) { // TODO(hclam): The data source should be added once. - browser_.reset(browser); + profile_ = profile; ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, NewRunnableMethod(Singleton<ChromeURLDataManager>::get(), @@ -262,7 +283,7 @@ void CloudPrintSetupFlow::GetDOMMessageHandlers( } void CloudPrintSetupFlow::GetDialogSize(gfx::Size* size) const { - PrefService* prefs = browser_->profile()->GetPrefs(); + PrefService* prefs = profile_->GetPrefs(); gfx::Font approximate_web_font( UTF8ToWide(prefs->GetString(prefs::kWebKitSansSerifFontFamily)), prefs->GetInteger(prefs::kWebKitDefaultFontSize)); @@ -286,6 +307,9 @@ void CloudPrintSetupFlow::OnDialogClosed(const std::string& json_retval) { // the service process helper to call us when the process is launched. if (service_process_helper_.get()) service_process_helper_->Detach(); + if (delegate_) { + delegate_->OnDialogClosed(); + } delete this; } @@ -302,7 +326,8 @@ std::wstring CloudPrintSetupFlow::GetDialogTitle() const { } bool CloudPrintSetupFlow::IsDialogModal() const { - return true; + // We are always modeless. + return false; } /////////////////////////////////////////////////////////////////////////////// @@ -327,7 +352,7 @@ void CloudPrintSetupFlow::OnClientLoginSuccess( // to it to register the host. process_control_ = ServiceProcessControlManager::instance()->GetProcessControl( - browser_->profile(), + profile_, kServiceProcessCloudPrint); #if defined(OS_WIN) @@ -361,7 +386,7 @@ void CloudPrintSetupFlow::OnUserSubmittedAuth(const std::string& user, // Start the authenticator. authenticator_.reset( new GaiaAuthenticator2(this, GaiaConstants::kChromeSource, - browser_->profile()->GetRequestContext())); + profile_->GetRequestContext())); authenticator_->StartClientLogin(user, password, GaiaConstants::kCloudPrintService, "", captcha); @@ -378,7 +403,7 @@ void CloudPrintSetupFlow::OnProcessLaunched() { // Save the preference that we have completed the setup of cloud // print. - browser_->profile()->GetPrefs()->SetString(prefs::kCloudPrintEmail, login_); + profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, login_); ShowSetupDone(); } diff --git a/chrome/browser/printing/cloud_print/cloud_print_setup_flow.h b/chrome/browser/printing/cloud_print/cloud_print_setup_flow.h index 551e163..453c1e3 100644 --- a/chrome/browser/printing/cloud_print/cloud_print_setup_flow.h +++ b/chrome/browser/printing/cloud_print/cloud_print_setup_flow.h @@ -42,12 +42,19 @@ class Browser; class CloudPrintSetupFlow : public HtmlDialogUIDelegate, public GaiaAuthConsumer { public: + class Delegate { + public: + virtual ~Delegate() {} + // Called when the setup dialog is closed. + virtual void OnDialogClosed() = 0; + }; virtual ~CloudPrintSetupFlow(); // Runs a flow from |start| to |end|, and does the work of actually showing // the HTML dialog. |container| is kept up-to-date with the lifetime of the // flow (e.g it is emptied on dialog close). - static CloudPrintSetupFlow* OpenDialog(Profile* service); + static CloudPrintSetupFlow* OpenDialog(Profile* service, Delegate* delegate, + gfx::NativeWindow parent_window); // Disables the cloud print proxy if it's enabled and running. static void DisableCloudPrintProxy(Profile* profile); @@ -83,9 +90,9 @@ class CloudPrintSetupFlow : public HtmlDialogUIDelegate, friend class CloudPrintServiceProcessHelper; friend class CloudPrintSetupMessageHandler; - // Use static Run method to get an instance. This class takes - // ownership of browser and is responsible for it's destruction. - CloudPrintSetupFlow(const std::string& args, Browser* browser); + // Use static Run method to get an instance. + CloudPrintSetupFlow(const std::string& args, Profile* profile, + Delegate* delegate); // Called CloudPrintSetupMessageHandler when a DOM is attached. This method // is called when the HTML page is fully loaded. We then operate on this @@ -115,7 +122,7 @@ class CloudPrintSetupFlow : public HtmlDialogUIDelegate, // The args to pass to the initial page. std::string dialog_start_args_; - scoped_ptr<Browser> browser_; + Profile* profile_; // Fetcher to obtain the Chromoting Directory token. scoped_ptr<GaiaAuthenticator2> authenticator_; @@ -126,6 +133,8 @@ class CloudPrintSetupFlow : public HtmlDialogUIDelegate, ServiceProcessControl* process_control_; scoped_refptr<CloudPrintServiceProcessHelper> service_process_helper_; + Delegate* delegate_; + DISALLOW_COPY_AND_ASSIGN(CloudPrintSetupFlow); }; diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc index 3200494..db25463 100644 --- a/chrome/browser/views/options/advanced_contents_view.cc +++ b/chrome/browser/views/options/advanced_contents_view.cc @@ -1425,7 +1425,8 @@ void CloudPrintProxySection::ButtonPressed(views::Button* sender, UserMetricsAction("Options_EnableCloudPrintProxy"), NULL); // We open a new browser window so the Options dialog doesn't // get lost behind other windows. - CloudPrintSetupFlow::OpenDialog(profile()); + CloudPrintSetupFlow::OpenDialog(profile(), NULL, + GetWindow()->GetNativeWindow()); } } else if (sender == manage_printer_button_) { // Open a new browser window for the management tab. The browser |