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

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

Issue 9003014: Replace WebUI::tab_contents() with web_contents() and switch all users to use web_contents.h inst... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/cloud_print_signin_dialog.h" 5 #include "chrome/browser/ui/webui/cloud_print_signin_dialog.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" 12 #include "chrome/browser/printing/cloud_print/cloud_print_url.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_list.h" 15 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/dialog_style.h" 16 #include "chrome/browser/ui/dialog_style.h"
17 #include "chrome/browser/ui/webui/html_dialog_ui.h" 17 #include "chrome/browser/ui/webui/html_dialog_ui.h"
18 #include "chrome/browser/ui/webui/print_preview_ui.h" 18 #include "chrome/browser/ui/webui/print_preview_ui.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
21 #include "content/browser/renderer_host/render_view_host.h" 21 #include "content/browser/renderer_host/render_view_host.h"
22 #include "content/browser/tab_contents/navigation_controller.h" 22 #include "content/browser/tab_contents/navigation_controller.h"
23 #include "content/browser/tab_contents/tab_contents.h"
24 #include "content/browser/tab_contents/tab_contents_view.h" 23 #include "content/browser/tab_contents/tab_contents_view.h"
25 #include "content/public/browser/navigation_entry.h" 24 #include "content/public/browser/navigation_entry.h"
26 #include "content/public/browser/notification_registrar.h" 25 #include "content/public/browser/notification_registrar.h"
27 #include "content/public/browser/notification_source.h" 26 #include "content/public/browser/notification_source.h"
28 #include "content/public/browser/notification_types.h" 27 #include "content/public/browser/notification_types.h"
28 #include "content/public/browser/web_contents.h"
29 29
30 using content::BrowserThread; 30 using content::BrowserThread;
31 using content::NavigationEntry; 31 using content::NavigationEntry;
32 using content::WebContents; 32 using content::WebContents;
33 33
34 // This module implements a sign in dialog for cloud print. 34 // This module implements a sign in dialog for cloud print.
35 // it is based heavily off "chrome/browser/printing/print_dialog_cloud.cc". 35 // it is based heavily off "chrome/browser/printing/print_dialog_cloud.cc".
36 // See the comments in that file for a discussion about how this works. 36 // See the comments in that file for a discussion about how this works.
37 37
38 namespace cloud_print_signin_dialog { 38 namespace cloud_print_signin_dialog {
39 39
40 // The flow handler sends our dialog to the correct URL, saves size info, 40 // The flow handler sends our dialog to the correct URL, saves size info,
41 // and closes the dialog when sign in is complete. 41 // and closes the dialog when sign in is complete.
42 class CloudPrintSigninFlowHandler : public WebUIMessageHandler, 42 class CloudPrintSigninFlowHandler : public WebUIMessageHandler,
43 public content::NotificationObserver { 43 public content::NotificationObserver {
44 public: 44 public:
45 explicit CloudPrintSigninFlowHandler(TabContents* parent_tab); 45 explicit CloudPrintSigninFlowHandler(WebContents* parent_tab);
46 // WebUIMessageHandler implementation. 46 // WebUIMessageHandler implementation.
47 virtual void RegisterMessages() OVERRIDE; 47 virtual void RegisterMessages() OVERRIDE;
48 48
49 // content::NotificationObserver implementation. 49 // content::NotificationObserver implementation.
50 virtual void Observe(int type, 50 virtual void Observe(int type,
51 const content::NotificationSource& source, 51 const content::NotificationSource& source,
52 const content::NotificationDetails& details) OVERRIDE; 52 const content::NotificationDetails& details) OVERRIDE;
53 private: 53 private:
54 // Records the final size of the dialog in prefs. 54 // Records the final size of the dialog in prefs.
55 void StoreDialogSize(); 55 void StoreDialogSize();
56 content::NotificationRegistrar registrar_; 56 content::NotificationRegistrar registrar_;
57 TabContents* parent_tab_; 57 WebContents* parent_tab_;
58 }; 58 };
59 59
60 CloudPrintSigninFlowHandler::CloudPrintSigninFlowHandler( 60 CloudPrintSigninFlowHandler::CloudPrintSigninFlowHandler(
61 TabContents* parent_tab) : parent_tab_(parent_tab) { 61 WebContents* parent_tab) : parent_tab_(parent_tab) {
62 } 62 }
63 63
64 void CloudPrintSigninFlowHandler::RegisterMessages() { 64 void CloudPrintSigninFlowHandler::RegisterMessages() {
65 if (web_ui() && web_ui()->tab_contents()) { 65 if (web_ui() && web_ui()->web_contents()) {
66 NavigationController* controller = 66 NavigationController* controller =
67 &web_ui()->tab_contents()->GetController(); 67 &web_ui()->web_contents()->GetController();
68 NavigationEntry* pending_entry = controller->GetPendingEntry(); 68 NavigationEntry* pending_entry = controller->GetPendingEntry();
69 if (pending_entry) 69 if (pending_entry)
70 pending_entry->SetURL(CloudPrintURL( 70 pending_entry->SetURL(CloudPrintURL(
71 Profile::FromWebUI(web_ui())).GetCloudPrintSigninURL()); 71 Profile::FromWebUI(web_ui())).GetCloudPrintSigninURL());
72 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 72 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
73 content::Source<NavigationController>(controller)); 73 content::Source<NavigationController>(controller));
74 } 74 }
75 } 75 }
76 76
77 void CloudPrintSigninFlowHandler::Observe( 77 void CloudPrintSigninFlowHandler::Observe(
78 int type, 78 int type,
79 const content::NotificationSource& source, 79 const content::NotificationSource& source,
80 const content::NotificationDetails& details) { 80 const content::NotificationDetails& details) {
81 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { 81 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
82 GURL url = web_ui()->tab_contents()->GetURL(); 82 GURL url = web_ui()->web_contents()->GetURL();
83 GURL dialog_url = CloudPrintURL( 83 GURL dialog_url = CloudPrintURL(
84 Profile::FromWebUI(web_ui())).GetCloudPrintServiceURL(); 84 Profile::FromWebUI(web_ui())).GetCloudPrintServiceURL();
85 if (url.host() == dialog_url.host() && 85 if (url.host() == dialog_url.host() &&
86 url.path() == dialog_url.path() && 86 url.path() == dialog_url.path() &&
87 url.scheme() == dialog_url.scheme()) { 87 url.scheme() == dialog_url.scheme()) {
88 StoreDialogSize(); 88 StoreDialogSize();
89 web_ui()->tab_contents()->GetRenderViewHost()->ClosePage(); 89 web_ui()->web_contents()->GetRenderViewHost()->ClosePage();
90 static_cast<PrintPreviewUI*>( 90 static_cast<PrintPreviewUI*>(
91 parent_tab_->GetWebUI())->OnReloadPrintersList(); 91 parent_tab_->GetWebUI())->OnReloadPrintersList();
92 } 92 }
93 } 93 }
94 } 94 }
95 95
96 void CloudPrintSigninFlowHandler::StoreDialogSize() { 96 void CloudPrintSigninFlowHandler::StoreDialogSize() {
97 if (web_ui() && 97 if (web_ui() &&
98 web_ui()->tab_contents() && 98 web_ui()->web_contents() &&
99 web_ui()->tab_contents()->GetView()) { 99 web_ui()->web_contents()->GetView()) {
100 gfx::Size size = web_ui()->tab_contents()->GetView()->GetContainerSize(); 100 gfx::Size size = web_ui()->web_contents()->GetView()->GetContainerSize();
101 Profile* profile = Profile::FromWebUI(web_ui()); 101 Profile* profile = Profile::FromWebUI(web_ui());
102 profile->GetPrefs()->SetInteger(prefs::kCloudPrintSigninDialogWidth, 102 profile->GetPrefs()->SetInteger(prefs::kCloudPrintSigninDialogWidth,
103 size.width()); 103 size.width());
104 profile->GetPrefs()->SetInteger( 104 profile->GetPrefs()->SetInteger(
105 prefs::kCloudPrintSigninDialogHeight, size.height()); 105 prefs::kCloudPrintSigninDialogHeight, size.height());
106 } 106 }
107 } 107 }
108 108
109 // The delegate provides most of the basic setup for the dialog. 109 // The delegate provides most of the basic setup for the dialog.
110 class CloudPrintSigninDelegate : public HtmlDialogUIDelegate { 110 class CloudPrintSigninDelegate : public HtmlDialogUIDelegate {
111 public: 111 public:
112 explicit CloudPrintSigninDelegate(TabContents* parent_tab); 112 explicit CloudPrintSigninDelegate(WebContents* parent_tab);
113 virtual bool IsDialogModal() const OVERRIDE; 113 virtual bool IsDialogModal() const OVERRIDE;
114 virtual string16 GetDialogTitle() const OVERRIDE; 114 virtual string16 GetDialogTitle() const OVERRIDE;
115 virtual GURL GetDialogContentURL() const OVERRIDE; 115 virtual GURL GetDialogContentURL() const OVERRIDE;
116 virtual void GetWebUIMessageHandlers( 116 virtual void GetWebUIMessageHandlers(
117 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; 117 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE;
118 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; 118 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
119 virtual std::string GetDialogArgs() const OVERRIDE; 119 virtual std::string GetDialogArgs() const OVERRIDE;
120 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; 120 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE;
121 virtual void OnCloseContents( 121 virtual void OnCloseContents(
122 WebContents* source, bool* out_close_dialog) OVERRIDE; 122 WebContents* source, bool* out_close_dialog) OVERRIDE;
123 virtual bool ShouldShowDialogTitle() const OVERRIDE; 123 virtual bool ShouldShowDialogTitle() const OVERRIDE;
124 private: 124 private:
125 TabContents* parent_tab_; 125 WebContents* parent_tab_;
126 }; 126 };
127 127
128 CloudPrintSigninDelegate::CloudPrintSigninDelegate(TabContents* parent_tab) 128 CloudPrintSigninDelegate::CloudPrintSigninDelegate(WebContents* parent_tab)
129 : parent_tab_(parent_tab) { 129 : parent_tab_(parent_tab) {
130 } 130 }
131 131
132 bool CloudPrintSigninDelegate::IsDialogModal() const { 132 bool CloudPrintSigninDelegate::IsDialogModal() const {
133 return true; 133 return true;
134 } 134 }
135 135
136 string16 CloudPrintSigninDelegate::GetDialogTitle() const { 136 string16 CloudPrintSigninDelegate::GetDialogTitle() const {
137 return string16(); 137 return string16();
138 } 138 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 void CloudPrintSigninDelegate::OnCloseContents(WebContents* source, 176 void CloudPrintSigninDelegate::OnCloseContents(WebContents* source,
177 bool* out_close_dialog) { 177 bool* out_close_dialog) {
178 if (out_close_dialog) 178 if (out_close_dialog)
179 *out_close_dialog = true; 179 *out_close_dialog = true;
180 } 180 }
181 181
182 bool CloudPrintSigninDelegate::ShouldShowDialogTitle() const { 182 bool CloudPrintSigninDelegate::ShouldShowDialogTitle() const {
183 return false; 183 return false;
184 } 184 }
185 185
186 void CreateCloudPrintSigninDialogImpl(TabContents* parent_tab) { 186 void CreateCloudPrintSigninDialogImpl(WebContents* parent_tab) {
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
188 HtmlDialogUIDelegate* dialog_delegate = 188 HtmlDialogUIDelegate* dialog_delegate =
189 new CloudPrintSigninDelegate(parent_tab); 189 new CloudPrintSigninDelegate(parent_tab);
190 BrowserList::GetLastActive()->BrowserShowHtmlDialog(dialog_delegate, 190 BrowserList::GetLastActive()->BrowserShowHtmlDialog(dialog_delegate,
191 NULL, 191 NULL,
192 STYLE_GENERIC); 192 STYLE_GENERIC);
193 } 193 }
194 194
195 void CreateCloudPrintSigninDialog(TabContents* parent_tab) { 195 void CreateCloudPrintSigninDialog(WebContents* parent_tab) {
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
197 197
198 BrowserThread::PostTask( 198 BrowserThread::PostTask(
199 BrowserThread::UI, FROM_HERE, 199 BrowserThread::UI, FROM_HERE,
200 base::Bind(&CreateCloudPrintSigninDialogImpl, parent_tab)); 200 base::Bind(&CreateCloudPrintSigninDialogImpl, parent_tab));
201 } 201 }
202 } // namespace cloud_print_signin_dialog 202 } // namespace cloud_print_signin_dialog
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/cloud_print_signin_dialog.h ('k') | chrome/browser/ui/webui/conflicts_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698