| 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/inline_login_ui.h" | 5 #include "chrome/browser/ui/webui/inline_login_ui.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | |
| 10 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.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/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 14 #include "base/values.h" | 13 #include "base/values.h" |
| 15 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/extensions/tab_helper.h" | 15 #include "chrome/browser/extensions/tab_helper.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 20 #include "chrome/browser/signin/signin_global_error.h" | 19 #include "chrome/browser/signin/signin_global_error.h" |
| 21 #include "chrome/browser/signin/signin_names_io_thread.h" | 20 #include "chrome/browser/signin/signin_names_io_thread.h" |
| 22 #include "chrome/browser/signin/signin_oauth_helper.h" | 21 #include "chrome/browser/signin/signin_oauth_helper.h" |
| 23 #include "chrome/browser/signin/signin_promo.h" | 22 #include "chrome/browser/signin/signin_promo.h" |
| 24 #include "chrome/browser/sync/profile_sync_service.h" | 23 #include "chrome/browser/sync/profile_sync_service.h" |
| 25 #include "chrome/browser/sync/profile_sync_service_factory.h" | 24 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 26 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
| 27 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 26 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
| 28 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 27 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
| 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 30 #include "chrome/common/profile_management_switches.h" | |
| 31 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 32 #include "content/public/browser/storage_partition.h" | 30 #include "content/public/browser/storage_partition.h" |
| 33 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 34 #include "content/public/browser/web_ui.h" | 32 #include "content/public/browser/web_ui.h" |
| 35 #include "content/public/browser/web_ui_data_source.h" | 33 #include "content/public/browser/web_ui_data_source.h" |
| 36 #include "content/public/browser/web_ui_message_handler.h" | 34 #include "content/public/browser/web_ui_message_handler.h" |
| 37 #include "google_apis/gaia/gaia_auth_consumer.h" | 35 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 38 #include "google_apis/gaia/gaia_auth_fetcher.h" | 36 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 39 #include "google_apis/gaia/gaia_constants.h" | 37 #include "google_apis/gaia/gaia_constants.h" |
| 40 #include "google_apis/gaia/gaia_switches.h" | 38 #include "google_apis/gaia/gaia_switches.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 128 |
| 131 void LoadAuthExtension() { | 129 void LoadAuthExtension() { |
| 132 base::DictionaryValue params; | 130 base::DictionaryValue params; |
| 133 | 131 |
| 134 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 132 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 135 params.SetString("hl", app_locale); | 133 params.SetString("hl", app_locale); |
| 136 | 134 |
| 137 GaiaUrls* gaiaUrls = GaiaUrls::GetInstance(); | 135 GaiaUrls* gaiaUrls = GaiaUrls::GetInstance(); |
| 138 params.SetString("gaiaUrl", gaiaUrls->gaia_url().spec()); | 136 params.SetString("gaiaUrl", gaiaUrls->gaia_url().spec()); |
| 139 | 137 |
| 140 bool enable_inline = switches::IsEnableInlineSignin(); | |
| 141 params.SetInteger("authMode", | |
| 142 enable_inline ? kInlineAuthMode : kDefaultAuthMode); | |
| 143 | 138 |
| 144 // Set parameters specific for inline signin flow. | 139 #if defined(OS_CHROMEOS) |
| 145 #if !defined(OS_CHROMEOS) | 140 params.SetInteger("authMode", kDefaultAuthMode); |
| 146 if (enable_inline) { | 141 #else |
| 142 params.SetInteger("authMode", kInlineAuthMode); |
| 147 | 143 |
| 148 const GURL& current_url = web_ui()->GetWebContents()->GetURL(); | 144 const GURL& current_url = web_ui()->GetWebContents()->GetURL(); |
| 149 signin::Source source = signin::GetSourceForPromoURL(current_url); | 145 signin::Source source = signin::GetSourceForPromoURL(current_url); |
| 150 DCHECK(source != signin::SOURCE_UNKNOWN); | 146 DCHECK(source != signin::SOURCE_UNKNOWN); |
| 151 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || | 147 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || |
| 152 source == signin::SOURCE_AVATAR_BUBBLE_SIGN_IN) { | 148 source == signin::SOURCE_AVATAR_BUBBLE_SIGN_IN) { |
| 153 // Drop the leading slash in the path. | 149 // Drop the leading slash in the path. |
| 154 params.SetString("gaiaPath", | 150 params.SetString("gaiaPath", |
| 155 gaiaUrls->embedded_signin_url().path().substr(1)); | 151 gaiaUrls->embedded_signin_url().path().substr(1)); |
| 156 } | 152 } |
| 157 | 153 |
| 158 params.SetString("service", "chromiumsync"); | 154 params.SetString("service", "chromiumsync"); |
| 159 params.SetString("continueUrl", | 155 params.SetString("continueUrl", |
| 160 signin::GetLandingURL("source", static_cast<int>(source)).spec()); | 156 signin::GetLandingURL("source", static_cast<int>(source)).spec()); |
| 161 | 157 |
| 162 std::string email; | 158 std::string email; |
| 163 net::GetValueForKeyInQuery(current_url, "Email", &email); | 159 net::GetValueForKeyInQuery(current_url, "Email", &email); |
| 164 if (!email.empty()) | 160 if (!email.empty()) |
| 165 params.SetString("email", email); | 161 params.SetString("email", email); |
| 166 | 162 |
| 167 std::string frame_url; | 163 std::string frame_url; |
| 168 net::GetValueForKeyInQuery(current_url, "frameUrl", &frame_url); | 164 net::GetValueForKeyInQuery(current_url, "frameUrl", &frame_url); |
| 169 if (!frame_url.empty()) | 165 if (!frame_url.empty()) |
| 170 params.SetString("frameUrl", frame_url); | 166 params.SetString("frameUrl", frame_url); |
| 171 | 167 |
| 172 std::string is_constrained; | 168 std::string is_constrained; |
| 173 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); | 169 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); |
| 174 if (!is_constrained.empty()) | 170 if (!is_constrained.empty()) |
| 175 params.SetString("constrained", is_constrained); | 171 params.SetString("constrained", is_constrained); |
| 176 | 172 |
| 177 net::GetValueForKeyInQuery(current_url, "partitionId", &partition_id_); | 173 net::GetValueForKeyInQuery(current_url, "partitionId", &partition_id_); |
| 178 if (partition_id_.empty()) { | 174 if (partition_id_.empty()) { |
| 179 partition_id_ = | 175 partition_id_ = |
| 180 "gaia-webview-" + base::IntToString(next_partition_id.GetNext()); | 176 "gaia-webview-" + base::IntToString(next_partition_id.GetNext()); |
| 181 } | |
| 182 params.SetString("partitionId", partition_id_); | |
| 183 } | 177 } |
| 178 params.SetString("partitionId", partition_id_); |
| 184 #endif // OS_CHROMEOS | 179 #endif // OS_CHROMEOS |
| 185 | 180 |
| 186 web_ui()->CallJavascriptFunction("inline.login.loadAuthExtension", params); | 181 web_ui()->CallJavascriptFunction("inline.login.loadAuthExtension", params); |
| 187 } | 182 } |
| 188 | 183 |
| 189 // JS callback: | 184 // JS callback: |
| 190 void HandleInitialize(const base::ListValue* args) { | 185 void HandleInitialize(const base::ListValue* args) { |
| 191 LoadAuthExtension(); | 186 LoadAuthExtension(); |
| 192 } | 187 } |
| 193 | 188 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 content::WebUIDataSource::Add(profile, CreateWebUIDataSource()); | 408 content::WebUIDataSource::Add(profile, CreateWebUIDataSource()); |
| 414 | 409 |
| 415 web_ui->AddMessageHandler(new InlineLoginUIHandler(profile)); | 410 web_ui->AddMessageHandler(new InlineLoginUIHandler(profile)); |
| 416 // Required for intercepting extension function calls when the page is loaded | 411 // Required for intercepting extension function calls when the page is loaded |
| 417 // in a bubble (not a full tab, thus tab helpers are not registered | 412 // in a bubble (not a full tab, thus tab helpers are not registered |
| 418 // automatically). | 413 // automatically). |
| 419 extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents()); | 414 extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents()); |
| 420 } | 415 } |
| 421 | 416 |
| 422 InlineLoginUI::~InlineLoginUI() {} | 417 InlineLoginUI::~InlineLoginUI() {} |
| OLD | NEW |