Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Side by Side Diff: chrome/browser/ui/webui/cloud_print_signin_dialog.cc

Issue 7518002: Add sign in dialog for GCP->print preview integration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 #include "chrome/browser/ui/webui/cloud_print_signin_dialog.h"
6 #include "chrome/browser/prefs/pref_service.h"
7 #include "chrome/browser/printing/cloud_print/cloud_print_url.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_list.h"
11 #include "chrome/browser/ui/webui/html_dialog_ui.h"
12 #include "chrome/common/pref_names.h"
13 #include "chrome/common/url_constants.h"
14 #include "content/browser/renderer_host/render_view_host.h"
15 #include "content/browser/tab_contents/navigation_controller.h"
16 #include "content/browser/tab_contents/tab_contents.h"
17 #include "content/browser/tab_contents/tab_contents_view.h"
18 #include "content/common/content_notification_types.h"
19 #include "content/common/notification_registrar.h"
20 #include "content/common/notification_source.h"
21 #include "content/common/view_messages.h"
22
23 // This module implements a sign in dialog for cloud print.
24 // it is based heavily off "chrome/browser/printing/print_dialog_cloud.cc".
25 // See the comments in that file for a discussion about how this works.
26
27 namespace cloud_print_signin_dialog {
28
29 // The flow handler sends our dialog to the correct URL, saves size info,
30 // and closes the dialog when sign in is complete.
31 class CloudPrintSigninFlowHandler : public WebUIMessageHandler,
32 public NotificationObserver {
33 // WebUIMessageHandler implementation.
34 virtual void RegisterMessages() OVERRIDE;
35
36 // NotificationObserver implementation.
37 virtual void Observe(int type,
38 const NotificationSource& source,
39 const NotificationDetails& details) OVERRIDE;
40 private:
41 // Records the final size of the dialog in prefs.
42 void StoreDialogSize();
43 NotificationRegistrar registrar_;
44 };
45
46 void CloudPrintSigninFlowHandler::RegisterMessages() {
47 if (web_ui_ && web_ui_->tab_contents()) {
48 NavigationController* controller = &web_ui_->tab_contents()->controller();
49 NavigationEntry* pending_entry = controller->pending_entry();
50 if (pending_entry)
51 pending_entry->set_url(CloudPrintURL(
52 Profile::FromWebUI(web_ui_)).GetCloudPrintSigninURL());
53 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
54 Source<NavigationController>(controller));
55 }
56 }
57
58 void CloudPrintSigninFlowHandler::Observe(int type,
59 const NotificationSource& source,
Scott Byer 2011/08/23 23:57:33 nit: indent
Albert Bodenhamer 2011/08/24 01:00:07 Done.
60 const NotificationDetails& details) {
61 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
62 GURL url = web_ui_->tab_contents()->GetURL();
63 GURL dialog_url = CloudPrintURL(
64 Profile::FromWebUI(web_ui_)).GetCloudPrintServiceURL();
65 if (url.host() == dialog_url.host() &&
66 url.path() == dialog_url.path() &&
67 url.scheme() == dialog_url.scheme()) {
68 StoreDialogSize();
69 web_ui_->tab_contents()->render_view_host()->ClosePage();
70 }
71 }
72 }
73
74 void CloudPrintSigninFlowHandler::StoreDialogSize() {
75 if (web_ui_ && web_ui_->tab_contents() && web_ui_->tab_contents()->view()) {
76 gfx::Size size = web_ui_->tab_contents()->view()->GetContainerSize();
77 Profile* profile = Profile::FromWebUI(web_ui_);
78 profile->GetPrefs()->SetInteger(prefs::kCloudPrintSigninDialogWidth,
79 size.width());
80 profile->GetPrefs()->SetInteger(
81 prefs::kCloudPrintSigninDialogHeight, size.height());
82 }
83 }
84
85 // The delegate provides most of the basic setup for the dialog.
86 class CloudPrintSigninDelegate : public HtmlDialogUIDelegate {
87 public:
88 explicit CloudPrintSigninDelegate(TabContents* parent_tab);
89 virtual bool IsDialogModal() const OVERRIDE;
90 virtual string16 GetDialogTitle() const OVERRIDE;
91 virtual GURL GetDialogContentURL() const OVERRIDE;
92 virtual void GetWebUIMessageHandlers(
93 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE;
94 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
95 virtual std::string GetDialogArgs() const OVERRIDE;
96 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE;
97 virtual void OnCloseContents(
98 TabContents* source, bool* out_close_dialog) OVERRIDE;
99 virtual bool ShouldShowDialogTitle() const OVERRIDE;
100 private:
101 TabContents* parent_tab_;
102 };
103
104 CloudPrintSigninDelegate::CloudPrintSigninDelegate(TabContents* parent_tab)
105 : parent_tab_(parent_tab) {
106 }
107
108
Scott Byer 2011/08/23 23:57:33 nit: extra blank line
Albert Bodenhamer 2011/08/24 01:00:07 Done.
109 bool CloudPrintSigninDelegate::IsDialogModal() const {
110 // TODO(abodenha@chromium.org) We want this to be modal, but calling
111 // ClosePage from the flow handler on a modal dialog results in the
112 // browser window never responding to input again. Figure out why.
Scott Byer 2011/08/23 23:57:33 Add a bug to track this with and put the URL here.
Albert Bodenhamer 2011/08/24 01:00:07 Done.
113 return false;
114 }
115
116 string16 CloudPrintSigninDelegate::GetDialogTitle() const {
117 return string16();
118 }
119
120 GURL CloudPrintSigninDelegate::GetDialogContentURL() const {
121 return GURL(chrome::kChromeUICloudPrintResourcesURL);
122 }
123
124 void CloudPrintSigninDelegate::GetWebUIMessageHandlers(
125 std::vector<WebUIMessageHandler*>* handlers) const {
126 handlers->push_back(new CloudPrintSigninFlowHandler());
127 }
128
129 void CloudPrintSigninDelegate::GetDialogSize(gfx::Size* size) const {
130 PrefService* pref_service =
131 BrowserList::GetLastActive()->GetProfile()->GetPrefs();
132 if (!pref_service->FindPreference(prefs::kCloudPrintSigninDialogWidth)) {
133 pref_service->RegisterIntegerPref(prefs::kCloudPrintSigninDialogWidth,
134 800,
135 PrefService::UNSYNCABLE_PREF);
136 }
137 if (!pref_service->FindPreference(prefs::kCloudPrintSigninDialogHeight)) {
138 pref_service->RegisterIntegerPref(prefs::kCloudPrintSigninDialogHeight,
139 600,
140 PrefService::UNSYNCABLE_PREF);
141 }
142
143 size->set_width(
144 pref_service->GetInteger(prefs::kCloudPrintSigninDialogWidth));
145 size->set_height(
146 pref_service->GetInteger(prefs::kCloudPrintSigninDialogHeight));
147 }
148
149 std::string CloudPrintSigninDelegate::GetDialogArgs() const {
150 return std::string();
151 }
152
153 void CloudPrintSigninDelegate::OnDialogClosed(const std::string& json_retval) {
154 parent_tab_->controller().Reload(false);
155 }
156
157 void CloudPrintSigninDelegate::OnCloseContents(TabContents* source,
158 bool* out_close_dialog) {
159 if (out_close_dialog)
160 *out_close_dialog = true;
161 }
162
163 bool CloudPrintSigninDelegate::ShouldShowDialogTitle() const {
164 return false;
165 }
166
167 void CreateCloudPrintSigninDialogImpl(TabContents* parent_tab) {
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
169 HtmlDialogUIDelegate* dialog_delegate =
170 new CloudPrintSigninDelegate(parent_tab);
171 BrowserList::GetLastActive()->BrowserShowHtmlDialog(dialog_delegate, NULL);
172 }
173
174 void CreateCloudPrintSigninDialog(TabContents* parent_tab) {
175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
176
177 BrowserThread::PostTask(
178 BrowserThread::UI, FROM_HERE,
179 NewRunnableFunction(CreateCloudPrintSigninDialogImpl,
180 parent_tab));
181 }
182 }
Scott Byer 2011/08/23 23:57:33 Missing // namespace comment.
Albert Bodenhamer 2011/08/24 01:00:07 Done.
183
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698