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

Side by Side Diff: chrome/browser/ui/login/login_prompt_ui.cc

Issue 8413022: wstring cleanup in browser/ui/login (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better Created 9 years, 1 month 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/login/login_prompt.h" 5 #include "chrome/browser/ui/login/login_prompt.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/string16.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
16 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 17 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
17 #include "chrome/browser/ui/webui/constrained_html_ui.h" 18 #include "chrome/browser/ui/webui/constrained_html_ui.h"
18 #include "chrome/browser/ui/webui/html_dialog_ui.h" 19 #include "chrome/browser/ui/webui/html_dialog_ui.h"
19 #include "chrome/common/jstemplate_builder.h" 20 #include "chrome/common/jstemplate_builder.h"
20 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
21 #include "content/browser/tab_contents/tab_contents.h" 22 #include "content/browser/tab_contents/tab_contents.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 121 }
121 122
122 // WebUIMessageHandler method: 123 // WebUIMessageHandler method:
123 virtual void RegisterMessages() OVERRIDE { 124 virtual void RegisterMessages() OVERRIDE {
124 web_ui_->RegisterMessageCallback( 125 web_ui_->RegisterMessageCallback(
125 "GetAutofill", 126 "GetAutofill",
126 base::Bind(&LoginHandlerHtmlDelegate::GetAutofill, 127 base::Bind(&LoginHandlerHtmlDelegate::GetAutofill,
127 base::Unretained(this))); 128 base::Unretained(this)));
128 } 129 }
129 130
130 void ShowAutofillData(const std::wstring& username, 131 void ShowAutofillData(const string16& username,
131 const std::wstring& password); 132 const string16& password);
132 133
133 private: 134 private:
134 // Send autofill data to HTML once the dialog is ready and the data is 135 // Send autofill data to HTML once the dialog is ready and the data is
135 // available. 136 // available.
136 void SendAutofillData(); 137 void SendAutofillData();
137 138
138 // Handle the request for autofill data from HTML. 139 // Handle the request for autofill data from HTML.
139 void GetAutofill(const ListValue* args) { 140 void GetAutofill(const ListValue* args) {
140 ready_for_autofill_ = true; 141 ready_for_autofill_ = true;
141 SendAutofillData(); 142 SendAutofillData();
142 } 143 }
143 144
144 LoginHandlerHtml* login_handler_; 145 LoginHandlerHtml* login_handler_;
145 std::string explanation_; 146 std::string explanation_;
146 bool closed_; 147 bool closed_;
147 148
148 bool has_autofill_; 149 bool has_autofill_;
149 bool ready_for_autofill_; 150 bool ready_for_autofill_;
150 std::string autofill_username_; 151 string16 autofill_username_;
151 std::string autofill_password_; 152 string16 autofill_password_;
152 153
153 static const int kDialogWidth = 400; 154 static const int kDialogWidth = 400;
154 static const int kDialogHeight = 160; 155 static const int kDialogHeight = 160;
155 156
156 DISALLOW_COPY_AND_ASSIGN(LoginHandlerHtmlDelegate); 157 DISALLOW_COPY_AND_ASSIGN(LoginHandlerHtmlDelegate);
157 }; 158 };
158 159
159 class LoginHandlerHtml : public LoginHandler { 160 class LoginHandlerHtml : public LoginHandler {
160 public: 161 public:
161 LoginHandlerHtml(net::AuthChallengeInfo* auth_info, net::URLRequest* request) 162 LoginHandlerHtml(net::AuthChallengeInfo* auth_info, net::URLRequest* request)
162 : LoginHandler(auth_info, request), 163 : LoginHandler(auth_info, request),
163 delegate_(NULL) { 164 delegate_(NULL) {
164 } 165 }
165 166
166 // LoginModelObserver method: 167 // LoginModelObserver method:
167 virtual void OnAutofillDataAvailable(const std::wstring& username, 168 virtual void OnAutofillDataAvailable(const string16& username,
168 const std::wstring& password) OVERRIDE { 169 const string16& password) OVERRIDE {
169 if (delegate_) 170 if (delegate_)
170 delegate_->ShowAutofillData(username, password); 171 delegate_->ShowAutofillData(username, password);
171 } 172 }
172 173
173 // LoginHandler method: 174 // LoginHandler method:
174 virtual void BuildViewForPasswordManager( 175 virtual void BuildViewForPasswordManager(
175 PasswordManager* manager, const string16& explanation) OVERRIDE; 176 PasswordManager* manager, const string16& explanation) OVERRIDE;
176 177
177 friend class LoginHandlerHtmlDelegate; 178 friend class LoginHandlerHtmlDelegate;
178 179
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 login_handler_->SetAuth(username, password); 212 login_handler_->SetAuth(username, password);
212 } 213 }
213 } 214 }
214 215
215 login_handler_->FreeAndRelease(); 216 login_handler_->FreeAndRelease();
216 217
217 // We don't need to delete |this| here: the WebUI object will delete us since 218 // We don't need to delete |this| here: the WebUI object will delete us since
218 // we've registered ourselves as a WebUIMessageHandler. 219 // we've registered ourselves as a WebUIMessageHandler.
219 } 220 }
220 221
221 void LoginHandlerHtmlDelegate::ShowAutofillData(const std::wstring& username, 222 void LoginHandlerHtmlDelegate::ShowAutofillData(const string16& username,
222 const std::wstring& password) { 223 const string16& password) {
223 autofill_username_ = WideToUTF8(username); 224 autofill_username_ = username;
224 autofill_password_ = WideToUTF8(password); 225 autofill_password_ = password;
225 has_autofill_ = true; 226 has_autofill_ = true;
226 SendAutofillData(); 227 SendAutofillData();
227 } 228 }
228 229
229 void LoginHandlerHtmlDelegate::SendAutofillData() { 230 void LoginHandlerHtmlDelegate::SendAutofillData() {
230 if (!closed_ && web_ui_ && has_autofill_ && ready_for_autofill_) { 231 if (!closed_ && web_ui_ && has_autofill_ && ready_for_autofill_) {
231 StringValue username_v(autofill_username_); 232 StringValue username_v(autofill_username_);
232 StringValue password_v(autofill_password_); 233 StringValue password_v(autofill_password_);
233 web_ui_->CallJavascriptFunction("setAutofillCredentials", 234 web_ui_->CallJavascriptFunction("setAutofillCredentials",
234 username_v, password_v); 235 username_v, password_v);
(...skipping 18 matching lines...) Expand all
253 SetDialog(dialog); 254 SetDialog(dialog);
254 255
255 NotifyAuthNeeded(); 256 NotifyAuthNeeded();
256 } 257 }
257 258
258 // static 259 // static
259 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info, 260 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info,
260 net::URLRequest* request) { 261 net::URLRequest* request) {
261 return new LoginHandlerHtml(auth_info, request); 262 return new LoginHandlerHtml(auth_info, request);
262 } 263 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/login/login_prompt_mac.mm ('k') | chrome/browser/ui/login/login_prompt_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698