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

Side by Side Diff: chrome/browser/ui/auto_login_prompter.cc

Issue 10800074: Making AutoLoginPrompter::ParseAutoLoginHeader public. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changing method implementation order. Created 8 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
« no previous file with comments | « chrome/browser/ui/auto_login_prompter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/auto_login_prompter.h" 5 #include "chrome/browser/ui/auto_login_prompter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (!ParseAutoLoginHeader(value, &params)) 94 if (!ParseAutoLoginHeader(value, &params))
95 return; 95 return;
96 96
97 BrowserThread::PostTask( 97 BrowserThread::PostTask(
98 BrowserThread::UI, FROM_HERE, 98 BrowserThread::UI, FROM_HERE,
99 base::Bind(&ShowInfoBarUIThread, 99 base::Bind(&ShowInfoBarUIThread,
100 params, request->url(), child_id, route_id)); 100 params, request->url(), child_id, route_id));
101 } 101 }
102 102
103 // static 103 // static
104 bool AutoLoginPrompter::ParseAutoLoginHeader(const std::string& input,
105 Params* output) {
106 // TODO(pliard): Investigate/fix potential internationalization issue. It
107 // seems that "account" from the x-auto-login header might contain non-ASCII
108 // characters.
109 if (input.empty())
110 return false;
111
112 std::vector<std::pair<std::string, std::string> > pairs;
113 if (!base::SplitStringIntoKeyValuePairs(input, '=', '&', &pairs))
114 return false;
115
116 // Parse the information from the |input| string.
117 Params params;
118 for (size_t i = 0; i < pairs.size(); ++i) {
119 const std::pair<std::string, std::string>& pair = pairs[i];
120 std::string unescaped_value(net::UnescapeURLComponent(
121 pair.second, net::UnescapeRule::URL_SPECIAL_CHARS));
122 if (pair.first == "realm") {
123 // Currently we only accept GAIA credentials.
124 if (unescaped_value != "com.google")
125 return false;
126 params.realm = unescaped_value;
127 } else if (pair.first == "account") {
128 params.account = unescaped_value;
129 } else if (pair.first == "args") {
130 params.args = unescaped_value;
131 }
132 }
133 if (params.realm.empty() || params.args.empty())
134 return false;
135
136 *output = params;
137 return true;
138 }
139
140 // static
104 void AutoLoginPrompter::ShowInfoBarUIThread(Params params, 141 void AutoLoginPrompter::ShowInfoBarUIThread(Params params,
105 const GURL& url, 142 const GURL& url,
106 int child_id, 143 int child_id,
107 int route_id) { 144 int route_id) {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 WebContents* web_contents = tab_util::GetWebContentsByID(child_id, route_id); 146 WebContents* web_contents = tab_util::GetWebContentsByID(child_id, route_id);
110 if (!web_contents) 147 if (!web_contents)
111 return; 148 return;
112 149
113 Profile* profile = 150 Profile* profile =
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); 182 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
146 infobar_helper->AddInfoBar( 183 infobar_helper->AddInfoBar(
147 new AutoLoginInfoBarDelegate(infobar_helper, params_)); 184 new AutoLoginInfoBarDelegate(infobar_helper, params_));
148 } 185 }
149 } 186 }
150 // Either we couldn't add the infobar, we added the infobar, or the tab 187 // Either we couldn't add the infobar, we added the infobar, or the tab
151 // contents was destroyed before the navigation completed. In any case 188 // contents was destroyed before the navigation completed. In any case
152 // there's no reason to live further. 189 // there's no reason to live further.
153 delete this; 190 delete this;
154 } 191 }
155
156 // static
157 bool AutoLoginPrompter::ParseAutoLoginHeader(const std::string& input,
158 Params* output) {
159 // TODO(pliard): Investigate/fix potential internationalization issue. It
160 // seems that "account" from the x-auto-login header might contain non-ASCII
161 // characters.
162 if (input.empty())
163 return false;
164
165 std::vector<std::pair<std::string, std::string> > pairs;
166 if (!base::SplitStringIntoKeyValuePairs(input, '=', '&', &pairs))
167 return false;
168
169 // Parse the information from the |input| string.
170 Params params;
171 for (size_t i = 0; i < pairs.size(); ++i) {
172 const std::pair<std::string, std::string>& pair = pairs[i];
173 std::string unescaped_value(net::UnescapeURLComponent(
174 pair.second, net::UnescapeRule::URL_SPECIAL_CHARS));
175 if (pair.first == "realm") {
176 // Currently we only accept GAIA credentials.
177 if (unescaped_value != "com.google")
178 return false;
179 params.realm = unescaped_value;
180 } else if (pair.first == "account") {
181 params.account = unescaped_value;
182 } else if (pair.first == "args") {
183 params.args = unescaped_value;
184 }
185 }
186 if (params.realm.empty() || params.args.empty())
187 return false;
188
189 *output = params;
190 return true;
191 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/auto_login_prompter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698