OLD | NEW |
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" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
17 #include "chrome/browser/signin/signin_promo.h" | 17 #include "chrome/browser/signin/signin_promo.h" |
18 #include "chrome/browser/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 19 #include "chrome/browser/sync/profile_sync_service_factory.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 21 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
22 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 22 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
26 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 26 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
27 #include "components/signin/core/browser/signin_error_controller.h" | 27 #include "components/signin/core/browser/signin_error_controller.h" |
28 #include "components/signin/core/browser/signin_oauth_helper.h" | 28 #include "components/signin/core/browser/signin_oauth_helper.h" |
29 #include "content/public/browser/storage_partition.h" | 29 #include "content/public/browser/storage_partition.h" |
30 #include "content/public/browser/web_contents.h" | |
31 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
32 #include "google_apis/gaia/gaia_auth_fetcher.h" | 31 #include "google_apis/gaia/gaia_auth_fetcher.h" |
33 #include "google_apis/gaia/gaia_auth_util.h" | 32 #include "google_apis/gaia/gaia_auth_util.h" |
34 #include "google_apis/gaia/gaia_constants.h" | 33 #include "google_apis/gaia/gaia_constants.h" |
35 #include "google_apis/gaia/gaia_urls.h" | 34 #include "google_apis/gaia/gaia_urls.h" |
36 #include "net/base/url_util.h" | 35 #include "net/base/url_util.h" |
37 | 36 |
38 namespace { | 37 namespace { |
39 | 38 |
40 class InlineSigninHelper : public SigninOAuthHelper, | 39 class InlineSigninHelper : public SigninOAuthHelper, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 172 |
174 } // namespace | 173 } // namespace |
175 | 174 |
176 InlineLoginHandlerImpl::InlineLoginHandlerImpl() | 175 InlineLoginHandlerImpl::InlineLoginHandlerImpl() |
177 : weak_factory_(this), | 176 : weak_factory_(this), |
178 choose_what_to_sync_(false) { | 177 choose_what_to_sync_(false) { |
179 } | 178 } |
180 | 179 |
181 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} | 180 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} |
182 | 181 |
183 void InlineLoginHandlerImpl::RegisterMessages() { | |
184 InlineLoginHandler::RegisterMessages(); | |
185 | |
186 web_ui()->RegisterMessageCallback("switchToFullTab", | |
187 base::Bind(&InlineLoginHandlerImpl::HandleSwitchToFullTabMessage, | |
188 base::Unretained(this))); | |
189 } | |
190 | |
191 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { | 182 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { |
192 params.SetInteger("authMode", InlineLoginHandler::kDesktopAuthMode); | 183 params.SetInteger("authMode", InlineLoginHandler::kDesktopAuthMode); |
193 | 184 |
194 const GURL& current_url = web_ui()->GetWebContents()->GetURL(); | 185 const GURL& current_url = web_ui()->GetWebContents()->GetURL(); |
195 signin::Source source = signin::GetSourceForPromoURL(current_url); | 186 signin::Source source = signin::GetSourceForPromoURL(current_url); |
196 DCHECK(source != signin::SOURCE_UNKNOWN); | 187 DCHECK(source != signin::SOURCE_UNKNOWN); |
197 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || | 188 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || |
198 source == signin::SOURCE_AVATAR_BUBBLE_SIGN_IN) { | 189 source == signin::SOURCE_AVATAR_BUBBLE_SIGN_IN) { |
199 // Drop the leading slash in the path. | 190 // Drop the leading slash in the path. |
200 params.SetString("gaiaPath", | 191 params.SetString("gaiaPath", |
(...skipping 28 matching lines...) Expand all Loading... |
229 // TODO(rogerta): this needs to be passed on to gaia somehow. | 220 // TODO(rogerta): this needs to be passed on to gaia somehow. |
230 std::string read_only_email; | 221 std::string read_only_email; |
231 net::GetValueForKeyInQuery(current_url, "readOnlyEmail", &read_only_email); | 222 net::GetValueForKeyInQuery(current_url, "readOnlyEmail", &read_only_email); |
232 if (!read_only_email.empty()) | 223 if (!read_only_email.empty()) |
233 params.SetString("readOnlyEmail", read_only_email); | 224 params.SetString("readOnlyEmail", read_only_email); |
234 | 225 |
235 OneClickSigninHelper::LogHistogramValue( | 226 OneClickSigninHelper::LogHistogramValue( |
236 source, one_click_signin::HISTOGRAM_SHOWN); | 227 source, one_click_signin::HISTOGRAM_SHOWN); |
237 } | 228 } |
238 | 229 |
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(¶ms); | |
253 | |
254 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); | |
255 } | |
256 | |
257 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { | 230 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { |
258 content::WebContents* contents = web_ui()->GetWebContents(); | 231 content::WebContents* contents = web_ui()->GetWebContents(); |
259 const GURL& current_url = contents->GetURL(); | 232 const GURL& current_url = contents->GetURL(); |
260 | 233 |
261 const base::DictionaryValue* dict = NULL; | 234 const base::DictionaryValue* dict = NULL; |
262 args->GetDictionary(0, &dict); | 235 args->GetDictionary(0, &dict); |
263 | 236 |
264 bool skip_for_now = false; | 237 bool skip_for_now = false; |
265 dict->GetBoolean("skipForNow", &skip_for_now); | 238 dict->GetBoolean("skipForNow", &skip_for_now); |
266 if (skip_for_now) { | 239 if (skip_for_now) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 371 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
399 if (tab_strip_model) { | 372 if (tab_strip_model) { |
400 int index = tab_strip_model->GetIndexOfWebContents(tab); | 373 int index = tab_strip_model->GetIndexOfWebContents(tab); |
401 if (index != TabStripModel::kNoTab) { | 374 if (index != TabStripModel::kNoTab) { |
402 tab_strip_model->ExecuteContextMenuCommand( | 375 tab_strip_model->ExecuteContextMenuCommand( |
403 index, TabStripModel::CommandCloseTab); | 376 index, TabStripModel::CommandCloseTab); |
404 } | 377 } |
405 } | 378 } |
406 } | 379 } |
407 } | 380 } |
OLD | NEW |