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

Side by Side Diff: chrome/browser/ui/webui/signin/inline_login_handler_impl.cc

Issue 256623002: Implemented inline login dialog for Chrome OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged SetExtraInitParams. Created 6 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/signin/inline_login_handler_impl.h" 5 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
14 #include "base/values.h" 13 #include "base/values.h"
15 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
17 #include "chrome/browser/signin/signin_promo.h"
18 #include "chrome/browser/sync/profile_sync_service.h" 16 #include "chrome/browser/sync/profile_sync_service.h"
19 #include "chrome/browser/sync/profile_sync_service_factory.h" 17 #include "chrome/browser/sync/profile_sync_service_factory.h"
20 #include "chrome/browser/ui/browser_finder.h" 18 #include "chrome/browser/ui/browser_finder.h"
21 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 19 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
22 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" 20 #include "chrome/browser/ui/sync/one_click_signin_histogram.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/common/pref_names.h"
25 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
26 #include "components/signin/core/browser/profile_oauth2_token_service.h" 23 #include "components/signin/core/browser/profile_oauth2_token_service.h"
27 #include "components/signin/core/browser/signin_error_controller.h" 24 #include "components/signin/core/browser/signin_error_controller.h"
28 #include "components/signin/core/browser/signin_oauth_helper.h" 25 #include "components/signin/core/browser/signin_oauth_helper.h"
29 #include "content/public/browser/storage_partition.h" 26 #include "content/public/browser/storage_partition.h"
30 #include "content/public/browser/web_contents.h"
31 #include "content/public/browser/web_ui.h" 27 #include "content/public/browser/web_ui.h"
32 #include "google_apis/gaia/gaia_auth_fetcher.h" 28 #include "google_apis/gaia/gaia_auth_fetcher.h"
33 #include "google_apis/gaia/gaia_auth_util.h" 29 #include "google_apis/gaia/gaia_auth_util.h"
34 #include "google_apis/gaia/gaia_constants.h" 30 #include "google_apis/gaia/gaia_constants.h"
35 #include "google_apis/gaia/gaia_urls.h" 31 #include "google_apis/gaia/gaia_urls.h"
36 #include "net/base/url_util.h" 32 #include "net/base/url_util.h"
37 33
38 namespace { 34 namespace {
39 35
40 class InlineSigninHelper : public SigninOAuthHelper, 36 class InlineSigninHelper : public SigninOAuthHelper,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 169
174 } // namespace 170 } // namespace
175 171
176 InlineLoginHandlerImpl::InlineLoginHandlerImpl() 172 InlineLoginHandlerImpl::InlineLoginHandlerImpl()
177 : weak_factory_(this), 173 : weak_factory_(this),
178 choose_what_to_sync_(false) { 174 choose_what_to_sync_(false) {
179 } 175 }
180 176
181 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} 177 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {}
182 178
183 void InlineLoginHandlerImpl::RegisterMessages() { 179 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) {
184 InlineLoginHandler::RegisterMessages(); 180 params.SetString("service", "chromiumsync");
185 181
186 web_ui()->RegisterMessageCallback("switchToFullTab", 182 signin::Source source = signin::GetSourceForPromoURL(
xiyuan 2014/04/29 16:43:16 nit: you still need signin_promo.h for this.
187 base::Bind(&InlineLoginHandlerImpl::HandleSwitchToFullTabMessage, 183 web_ui()->GetWebContents()->GetURL());
188 base::Unretained(this)));
189 }
190
191 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) {
192 params.SetInteger("authMode", InlineLoginHandler::kDesktopAuthMode);
193
194 const GURL& current_url = web_ui()->GetWebContents()->GetURL();
195 signin::Source source = signin::GetSourceForPromoURL(current_url);
196 DCHECK(source != signin::SOURCE_UNKNOWN);
197 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT ||
198 source == signin::SOURCE_AVATAR_BUBBLE_SIGN_IN) {
199 // Drop the leading slash in the path.
200 params.SetString("gaiaPath",
201 GaiaUrls::GetInstance()->embedded_signin_url().path().substr(1));
202 }
203
204 params.SetString("service", "chromiumsync");
205 params.SetString("continueUrl",
206 signin::GetLandingURL("source", static_cast<int>(source)).spec());
207
208 std::string default_email;
209 if (source != signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT) {
210 default_email = Profile::FromWebUI(web_ui())->GetPrefs()->
211 GetString(prefs::kGoogleServicesLastUsername);
212 } else {
213 if (!net::GetValueForKeyInQuery(current_url, "email", &default_email))
214 default_email.clear();
215 }
216 if (!default_email.empty())
217 params.SetString("email", default_email);
218
219 std::string frame_url;
220 net::GetValueForKeyInQuery(current_url, "frameUrl", &frame_url);
221 if (!frame_url.empty())
222 params.SetString("frameUrl", frame_url);
223
224 std::string is_constrained;
225 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained);
226 if (!is_constrained.empty())
227 params.SetString("constrained", is_constrained);
228
229 // TODO(rogerta): this needs to be passed on to gaia somehow.
230 std::string read_only_email;
231 net::GetValueForKeyInQuery(current_url, "readOnlyEmail", &read_only_email);
232 if (!read_only_email.empty())
233 params.SetString("readOnlyEmail", read_only_email);
234
235 OneClickSigninHelper::LogHistogramValue( 184 OneClickSigninHelper::LogHistogramValue(
236 source, one_click_signin::HISTOGRAM_SHOWN); 185 source, one_click_signin::HISTOGRAM_SHOWN);
237 } 186 }
238 187
239 void InlineLoginHandlerImpl::HandleSwitchToFullTabMessage(
240 const base::ListValue* args) {
241 base::string16 url_str;
242 CHECK(args->GetString(0, &url_str));
243
244 content::WebContents* web_contents = web_ui()->GetWebContents();
245 GURL main_frame_url(web_contents->GetURL());
246 main_frame_url = net::AppendOrReplaceQueryParameter(
247 main_frame_url, "frameUrl", base::UTF16ToASCII(url_str));
248 chrome::NavigateParams params(
249 Profile::FromWebUI(web_ui()),
250 net::AppendOrReplaceQueryParameter(main_frame_url, "constrained", "0"),
251 content::PAGE_TRANSITION_AUTO_TOPLEVEL);
252 chrome::Navigate(&params);
253
254 web_ui()->CallJavascriptFunction("inline.login.closeDialog");
255 }
256
257 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { 188 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) {
258 content::WebContents* contents = web_ui()->GetWebContents(); 189 content::WebContents* contents = web_ui()->GetWebContents();
259 const GURL& current_url = contents->GetURL(); 190 const GURL& current_url = contents->GetURL();
260 191
261 const base::DictionaryValue* dict = NULL; 192 const base::DictionaryValue* dict = NULL;
262 args->GetDictionary(0, &dict); 193 args->GetDictionary(0, &dict);
263 194
264 bool skip_for_now = false; 195 bool skip_for_now = false;
265 dict->GetBoolean("skipForNow", &skip_for_now); 196 dict->GetBoolean("skipForNow", &skip_for_now);
266 if (skip_for_now) { 197 if (skip_for_now) {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 TabStripModel* tab_strip_model = browser->tab_strip_model(); 329 TabStripModel* tab_strip_model = browser->tab_strip_model();
399 if (tab_strip_model) { 330 if (tab_strip_model) {
400 int index = tab_strip_model->GetIndexOfWebContents(tab); 331 int index = tab_strip_model->GetIndexOfWebContents(tab);
401 if (index != TabStripModel::kNoTab) { 332 if (index != TabStripModel::kNoTab) {
402 tab_strip_model->ExecuteContextMenuCommand( 333 tab_strip_model->ExecuteContextMenuCommand(
403 index, TabStripModel::CommandCloseTab); 334 index, TabStripModel::CommandCloseTab);
404 } 335 }
405 } 336 }
406 } 337 }
407 } 338 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698