| 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 "base/atomic_sequence_num.h" |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 8 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/signin/signin_global_error.h" | 14 #include "chrome/browser/signin/signin_global_error.h" |
| 14 #include "chrome/browser/signin/signin_oauth_helper.h" | 15 #include "chrome/browser/signin/signin_oauth_helper.h" |
| 15 #include "chrome/browser/signin/signin_promo.h" | 16 #include "chrome/browser/signin/signin_promo.h" |
| 16 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
| 17 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
| 19 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 20 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/common/url_constants.h" | |
| 23 #include "content/public/browser/storage_partition.h" | 23 #include "content/public/browser/storage_partition.h" |
| 24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_ui.h" | 25 #include "content/public/browser/web_ui.h" |
| 26 #include "google_apis/gaia/gaia_auth_fetcher.h" | 26 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 27 #include "google_apis/gaia/gaia_constants.h" | 27 #include "google_apis/gaia/gaia_constants.h" |
| 28 #include "google_apis/gaia/gaia_urls.h" | 28 #include "google_apis/gaia/gaia_urls.h" |
| 29 #include "net/base/url_util.h" | 29 #include "net/base/url_util.h" |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Global SequenceNumber used for generating unique webview partition IDs. |
| 34 base::StaticAtomicSequenceNumber next_partition_id; |
| 35 |
| 33 } // empty namespace | 36 } // empty namespace |
| 34 | 37 |
| 35 InlineLoginHandlerImpl::InlineLoginHandlerImpl() | 38 InlineLoginHandlerImpl::InlineLoginHandlerImpl() |
| 36 : weak_factory_(this), choose_what_to_sync_(false) { | 39 : weak_factory_(this), choose_what_to_sync_(false), partition_id_("") { |
| 37 } | 40 } |
| 38 | 41 |
| 39 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} | 42 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} |
| 40 | 43 |
| 41 void InlineLoginHandlerImpl::RegisterMessages() { | 44 void InlineLoginHandlerImpl::RegisterMessages() { |
| 42 InlineLoginHandler::RegisterMessages(); | 45 InlineLoginHandler::RegisterMessages(); |
| 43 | 46 |
| 44 web_ui()->RegisterMessageCallback("switchToFullTab", | 47 web_ui()->RegisterMessageCallback("switchToFullTab", |
| 45 base::Bind(&InlineLoginHandlerImpl::HandleSwitchToFullTabMessage, | 48 base::Bind(&InlineLoginHandlerImpl::HandleSwitchToFullTabMessage, |
| 46 base::Unretained(this))); | 49 base::Unretained(this))); |
| 47 } | 50 } |
| 48 | 51 |
| 49 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { | 52 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { |
| 50 params.SetInteger("authMode", InlineLoginHandler::kDesktopAuthMode); | 53 params.SetInteger("authMode", InlineLoginHandler::kInlineAuthMode); |
| 51 | 54 |
| 52 const GURL& current_url = web_ui()->GetWebContents()->GetURL(); | 55 const GURL& current_url = web_ui()->GetWebContents()->GetURL(); |
| 53 signin::Source source = signin::GetSourceForPromoURL(current_url); | 56 signin::Source source = signin::GetSourceForPromoURL(current_url); |
| 54 DCHECK(source != signin::SOURCE_UNKNOWN); | 57 DCHECK(source != signin::SOURCE_UNKNOWN); |
| 55 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || | 58 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || |
| 56 source == signin::SOURCE_AVATAR_BUBBLE_SIGN_IN) { | 59 source == signin::SOURCE_AVATAR_BUBBLE_SIGN_IN) { |
| 57 // Drop the leading slash in the path. | 60 // Drop the leading slash in the path. |
| 58 params.SetString("gaiaPath", | 61 params.SetString("gaiaPath", |
| 59 GaiaUrls::GetInstance()->embedded_signin_url().path().substr(1)); | 62 GaiaUrls::GetInstance()->embedded_signin_url().path().substr(1)); |
| 60 } | 63 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 82 std::string is_constrained; | 85 std::string is_constrained; |
| 83 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); | 86 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); |
| 84 if (!is_constrained.empty()) | 87 if (!is_constrained.empty()) |
| 85 params.SetString("constrained", is_constrained); | 88 params.SetString("constrained", is_constrained); |
| 86 | 89 |
| 87 // TODO(rogerta): this needs to be passed on to gaia somehow. | 90 // TODO(rogerta): this needs to be passed on to gaia somehow. |
| 88 std::string read_only_email; | 91 std::string read_only_email; |
| 89 net::GetValueForKeyInQuery(current_url, "readOnlyEmail", &read_only_email); | 92 net::GetValueForKeyInQuery(current_url, "readOnlyEmail", &read_only_email); |
| 90 if (!read_only_email.empty()) | 93 if (!read_only_email.empty()) |
| 91 params.SetString("readOnlyEmail", read_only_email); | 94 params.SetString("readOnlyEmail", read_only_email); |
| 95 |
| 96 net::GetValueForKeyInQuery(current_url, "partitionId", &partition_id_); |
| 97 if (partition_id_.empty()) { |
| 98 partition_id_ = |
| 99 "gaia-webview-" + base::IntToString(next_partition_id.GetNext()); |
| 100 } |
| 101 params.SetString("partitionId", partition_id_); |
| 92 } | 102 } |
| 93 | 103 |
| 94 | 104 |
| 95 void InlineLoginHandlerImpl::HandleSwitchToFullTabMessage( | 105 void InlineLoginHandlerImpl::HandleSwitchToFullTabMessage( |
| 96 const base::ListValue* args) { | 106 const base::ListValue* args) { |
| 97 base::string16 url_str; | 107 base::string16 url_str; |
| 98 CHECK(args->GetString(0, &url_str)); | 108 CHECK(args->GetString(0, &url_str)); |
| 99 | 109 |
| 100 content::WebContents* web_contents = web_ui()->GetWebContents(); | 110 content::WebContents* web_contents = web_ui()->GetWebContents(); |
| 101 GURL main_frame_url(web_contents->GetURL()); | 111 GURL main_frame_url(web_contents->GetURL()); |
| 102 main_frame_url = net::AppendOrReplaceQueryParameter( | 112 main_frame_url = net::AppendOrReplaceQueryParameter( |
| 103 main_frame_url, "frameUrl", UTF16ToASCII(url_str)); | 113 main_frame_url, "frameUrl", UTF16ToASCII(url_str)); |
| 114 main_frame_url = net::AppendOrReplaceQueryParameter( |
| 115 main_frame_url, "partitionId", partition_id_); |
| 104 chrome::NavigateParams params( | 116 chrome::NavigateParams params( |
| 105 Profile::FromWebUI(web_ui()), | 117 Profile::FromWebUI(web_ui()), |
| 106 net::AppendOrReplaceQueryParameter(main_frame_url, "constrained", "0"), | 118 net::AppendOrReplaceQueryParameter(main_frame_url, "constrained", "0"), |
| 107 content::PAGE_TRANSITION_AUTO_TOPLEVEL); | 119 content::PAGE_TRANSITION_AUTO_TOPLEVEL); |
| 108 chrome::Navigate(¶ms); | 120 chrome::Navigate(¶ms); |
| 109 | 121 |
| 110 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); | 122 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); |
| 111 } | 123 } |
| 112 | 124 |
| 113 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { | 125 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { |
| 114 DCHECK(email_.empty() && password_.empty() && session_index_.empty()); | 126 DCHECK(email_.empty() && password_.empty()); |
| 115 | 127 |
| 116 content::WebContents* contents = web_ui()->GetWebContents(); | 128 content::WebContents* contents = web_ui()->GetWebContents(); |
| 117 const GURL& current_url = contents->GetURL(); | 129 const GURL& current_url = contents->GetURL(); |
| 118 | 130 |
| 119 const base::DictionaryValue* dict = NULL; | 131 const base::DictionaryValue* dict = NULL; |
| 120 base::string16 email; | 132 base::string16 email; |
| 121 if (!args->GetDictionary(0, &dict) || !dict || | 133 if (!args->GetDictionary(0, &dict) || !dict || |
| 122 !dict->GetString("email", &email)) { | 134 !dict->GetString("email", &email)) { |
| 123 // User cancelled the signin by clicking 'skip for now'. | 135 // User cancelled the signin by clicking 'skip for now'. |
| 124 bool skip_for_now = false; | 136 bool skip_for_now = false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 143 if (net::GetValueForKeyInQuery(current_url, "email", &default_email) && | 155 if (net::GetValueForKeyInQuery(current_url, "email", &default_email) && |
| 144 net::GetValueForKeyInQuery(current_url, "validateEmail", | 156 net::GetValueForKeyInQuery(current_url, "validateEmail", |
| 145 &validate_email) && | 157 &validate_email) && |
| 146 validate_email == "1") { | 158 validate_email == "1") { |
| 147 if (email_ != default_email) { | 159 if (email_ != default_email) { |
| 148 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); | 160 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); |
| 149 return; | 161 return; |
| 150 } | 162 } |
| 151 } | 163 } |
| 152 | 164 |
| 153 base::string16 session_index; | |
| 154 dict->GetString("sessionIndex", &session_index); | |
| 155 session_index_ = UTF16ToASCII(session_index); | |
| 156 DCHECK(!session_index_.empty()); | |
| 157 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync_); | 165 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync_); |
| 158 | 166 |
| 159 signin::Source source = signin::GetSourceForPromoURL(current_url); | 167 signin::Source source = signin::GetSourceForPromoURL(current_url); |
| 160 OneClickSigninHelper::CanOfferFor can_offer = | 168 OneClickSigninHelper::CanOfferFor can_offer = |
| 161 source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT ? | 169 source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT ? |
| 162 OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT : | 170 OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT : |
| 163 OneClickSigninHelper::CAN_OFFER_FOR_ALL; | 171 OneClickSigninHelper::CAN_OFFER_FOR_ALL; |
| 164 std::string error_msg; | 172 std::string error_msg; |
| 165 OneClickSigninHelper::CanOffer( | 173 OneClickSigninHelper::CanOffer( |
| 166 contents, can_offer, email_, &error_msg); | 174 contents, can_offer, email_, &error_msg); |
| 167 if (!error_msg.empty()) { | 175 if (!error_msg.empty()) { |
| 168 HandleLoginError(error_msg); | 176 HandleLoginError(error_msg); |
| 169 return; | 177 return; |
| 170 } | 178 } |
| 171 | 179 |
| 172 content::StoragePartition* partition = | 180 content::StoragePartition* partition = |
| 173 content::BrowserContext::GetStoragePartitionForSite( | 181 content::BrowserContext::GetStoragePartitionForSite( |
| 174 contents->GetBrowserContext(), | 182 contents->GetBrowserContext(), |
| 175 GURL(chrome::kChromeUIChromeSigninURL)); | 183 GURL("chrome-guest://mfffpogegjflfpflabcdkioaeobkgjik/?" + |
| 184 partition_id_)); |
| 176 | 185 |
| 177 auth_fetcher_.reset(new GaiaAuthFetcher(this, | 186 auth_fetcher_.reset(new GaiaAuthFetcher(this, |
| 178 GaiaConstants::kChromeSource, | 187 GaiaConstants::kChromeSource, |
| 179 partition->GetURLRequestContext())); | 188 partition->GetURLRequestContext())); |
| 180 auth_fetcher_->StartCookieForOAuthCodeExchange(session_index_); | 189 auth_fetcher_->StartCookieForOAuthCodeExchange("0"); |
| 181 } | 190 } |
| 182 | 191 |
| 183 void InlineLoginHandlerImpl::OnClientOAuthCodeSuccess( | 192 void InlineLoginHandlerImpl::OnClientOAuthCodeSuccess( |
| 184 const std::string& oauth_code) { | 193 const std::string& oauth_code) { |
| 185 DCHECK(!oauth_code.empty()); | 194 DCHECK(!oauth_code.empty()); |
| 186 | 195 |
| 187 content::WebContents* contents = web_ui()->GetWebContents(); | 196 content::WebContents* contents = web_ui()->GetWebContents(); |
| 188 Profile* profile = Profile::FromWebUI(web_ui()); | 197 Profile* profile = Profile::FromWebUI(web_ui()); |
| 189 ProfileSyncService* sync_service = | 198 ProfileSyncService* sync_service = |
| 190 ProfileSyncServiceFactory::GetForProfile(profile); | 199 ProfileSyncServiceFactory::GetForProfile(profile); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 email_, password_, oauth_code, | 246 email_, password_, oauth_code, |
| 238 start_mode, | 247 start_mode, |
| 239 contents, | 248 contents, |
| 240 confirmation_required, | 249 confirmation_required, |
| 241 sync_callback); | 250 sync_callback); |
| 242 } | 251 } |
| 243 } | 252 } |
| 244 | 253 |
| 245 email_.clear(); | 254 email_.clear(); |
| 246 password_.clear(); | 255 password_.clear(); |
| 247 session_index_.clear(); | |
| 248 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); | 256 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); |
| 249 } | 257 } |
| 250 | 258 |
| 251 void InlineLoginHandlerImpl::OnClientOAuthCodeFailure( | 259 void InlineLoginHandlerImpl::OnClientOAuthCodeFailure( |
| 252 const GoogleServiceAuthError& error) { | 260 const GoogleServiceAuthError& error) { |
| 253 LOG(ERROR) << "InlineLoginUI::OnClientOAuthCodeFailure"; | 261 LOG(ERROR) << "InlineLoginUI::OnClientOAuthCodeFailure"; |
| 254 HandleLoginError(error.ToString()); | 262 HandleLoginError(error.ToString()); |
| 255 } | 263 } |
| 256 | 264 |
| 257 void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg) { | 265 void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg) { |
| 258 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); | 266 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); |
| 259 | 267 |
| 260 Browser* browser = chrome::FindBrowserWithWebContents( | 268 Browser* browser = chrome::FindBrowserWithWebContents( |
| 261 web_ui()->GetWebContents()); | 269 web_ui()->GetWebContents()); |
| 262 if (!browser) { | 270 if (!browser) { |
| 263 browser = chrome::FindLastActiveWithProfile( | 271 browser = chrome::FindLastActiveWithProfile( |
| 264 Profile::FromWebUI(web_ui()), chrome::GetActiveDesktop()); | 272 Profile::FromWebUI(web_ui()), chrome::GetActiveDesktop()); |
| 265 } | 273 } |
| 266 if (browser) | 274 if (browser) |
| 267 OneClickSigninHelper::ShowSigninErrorBubble(browser, error_msg); | 275 OneClickSigninHelper::ShowSigninErrorBubble(browser, error_msg); |
| 268 | 276 |
| 269 email_.clear(); | 277 email_.clear(); |
| 270 password_.clear(); | 278 password_.clear(); |
| 271 session_index_.clear(); | |
| 272 } | 279 } |
| 273 | 280 |
| 274 void InlineLoginHandlerImpl::SyncStarterCallback( | 281 void InlineLoginHandlerImpl::SyncStarterCallback( |
| 275 OneClickSigninSyncStarter::SyncSetupResult result) { | 282 OneClickSigninSyncStarter::SyncSetupResult result) { |
| 276 content::WebContents* contents = web_ui()->GetWebContents(); | 283 content::WebContents* contents = web_ui()->GetWebContents(); |
| 277 const GURL& current_url = contents->GetURL(); | 284 const GURL& current_url = contents->GetURL(); |
| 278 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url); | 285 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url); |
| 279 if (auto_close) { | 286 if (auto_close) { |
| 280 base::MessageLoop::current()->PostTask( | 287 base::MessageLoop::current()->PostTask( |
| 281 FROM_HERE, | 288 FROM_HERE, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 295 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 302 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
| 296 if (tab_strip_model) { | 303 if (tab_strip_model) { |
| 297 int index = tab_strip_model->GetIndexOfWebContents(tab); | 304 int index = tab_strip_model->GetIndexOfWebContents(tab); |
| 298 if (index != TabStripModel::kNoTab) { | 305 if (index != TabStripModel::kNoTab) { |
| 299 tab_strip_model->ExecuteContextMenuCommand( | 306 tab_strip_model->ExecuteContextMenuCommand( |
| 300 index, TabStripModel::CommandCloseTab); | 307 index, TabStripModel::CommandCloseTab); |
| 301 } | 308 } |
| 302 } | 309 } |
| 303 } | 310 } |
| 304 } | 311 } |
| OLD | NEW |