| 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/signin/chrome_signin_helper.h" | 5 #include "chrome/browser/signin/chrome_signin_helper.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 8 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 9 #include "chrome/browser/profiles/profile_io_data.h" | 9 #include "chrome/browser/profiles/profile_io_data.h" |
| 10 #include "chrome/browser/signin/account_reconcilor_factory.h" | 10 #include "chrome/browser/signin/account_reconcilor_factory.h" |
| 11 #include "chrome/browser/signin/chrome_signin_client.h" | 11 #include "chrome/browser/signin/chrome_signin_client.h" |
| 12 #include "chrome/browser/tab_contents/tab_util.h" | 12 #include "chrome/browser/tab_contents/tab_util.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/common/features.h" |
| 14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 15 #include "components/signin/core/browser/account_reconcilor.h" | 16 #include "components/signin/core/browser/account_reconcilor.h" |
| 16 #include "components/signin/core/browser/signin_header_helper.h" | 17 #include "components/signin/core/browser/signin_header_helper.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/resource_request_info.h" | 19 #include "content/public/browser/resource_request_info.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "google_apis/gaia/gaia_auth_util.h" | 21 #include "google_apis/gaia/gaia_auth_util.h" |
| 21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 22 | 23 |
| 23 #if defined(OS_ANDROID) | 24 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 24 #include "chrome/browser/android/signin/account_management_screen_helper.h" | 25 #include "chrome/browser/android/signin/account_management_screen_helper.h" |
| 25 #else | 26 #else |
| 26 #include "chrome/browser/ui/browser_commands.h" | 27 #include "chrome/browser/ui/browser_commands.h" |
| 27 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
| 28 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | 29 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
| 29 #endif // defined(OS_ANDROID) | 30 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 30 | 31 |
| 31 namespace signin { | 32 namespace signin { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 // Processes the mirror response header on the UI thread. Currently depending | 36 // Processes the mirror response header on the UI thread. Currently depending |
| 36 // on the value of |header_value|, it either shows the profile avatar menu, or | 37 // on the value of |header_value|, it either shows the profile avatar menu, or |
| 37 // opens an incognito window/tab. | 38 // opens an incognito window/tab. |
| 38 void ProcessMirrorHeaderUIThread(int child_id, | 39 void ProcessMirrorHeaderUIThread(int child_id, |
| 39 int route_id, | 40 int route_id, |
| 40 ManageAccountsParams manage_accounts_params) { | 41 ManageAccountsParams manage_accounts_params) { |
| 41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 42 | 43 |
| 43 GAIAServiceType service_type = manage_accounts_params.service_type; | 44 GAIAServiceType service_type = manage_accounts_params.service_type; |
| 44 DCHECK_NE(GAIA_SERVICE_TYPE_NONE, service_type); | 45 DCHECK_NE(GAIA_SERVICE_TYPE_NONE, service_type); |
| 45 | 46 |
| 46 content::WebContents* web_contents = | 47 content::WebContents* web_contents = |
| 47 tab_util::GetWebContentsByID(child_id, route_id); | 48 tab_util::GetWebContentsByID(child_id, route_id); |
| 48 if (!web_contents) | 49 if (!web_contents) |
| 49 return; | 50 return; |
| 50 | 51 |
| 51 Profile* profile = | 52 Profile* profile = |
| 52 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 53 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 53 AccountReconcilor* account_reconcilor = | 54 AccountReconcilor* account_reconcilor = |
| 54 AccountReconcilorFactory::GetForProfile(profile); | 55 AccountReconcilorFactory::GetForProfile(profile); |
| 55 account_reconcilor->OnReceivedManageAccountsResponse( | 56 account_reconcilor->OnReceivedManageAccountsResponse( |
| 56 manage_accounts_params.service_type); | 57 manage_accounts_params.service_type); |
| 57 #if !defined(OS_ANDROID) | 58 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 58 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 59 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 59 if (browser) { | 60 if (browser) { |
| 60 BrowserWindow::AvatarBubbleMode bubble_mode; | 61 BrowserWindow::AvatarBubbleMode bubble_mode; |
| 61 switch (service_type) { | 62 switch (service_type) { |
| 62 case GAIA_SERVICE_TYPE_INCOGNITO: | 63 case GAIA_SERVICE_TYPE_INCOGNITO: |
| 63 chrome::NewIncognitoWindow(browser); | 64 chrome::NewIncognitoWindow(browser); |
| 64 return; | 65 return; |
| 65 case GAIA_SERVICE_TYPE_ADDSESSION: | 66 case GAIA_SERVICE_TYPE_ADDSESSION: |
| 66 bubble_mode = BrowserWindow::AVATAR_BUBBLE_MODE_ADD_ACCOUNT; | 67 bubble_mode = BrowserWindow::AVATAR_BUBBLE_MODE_ADD_ACCOUNT; |
| 67 break; | 68 break; |
| 68 case GAIA_SERVICE_TYPE_REAUTH: | 69 case GAIA_SERVICE_TYPE_REAUTH: |
| 69 bubble_mode = BrowserWindow::AVATAR_BUBBLE_MODE_REAUTH; | 70 bubble_mode = BrowserWindow::AVATAR_BUBBLE_MODE_REAUTH; |
| 70 break; | 71 break; |
| 71 default: | 72 default: |
| 72 bubble_mode = BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT; | 73 bubble_mode = BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT; |
| 73 } | 74 } |
| 74 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( | 75 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( |
| 75 account_reconcilor->GetState()); | 76 account_reconcilor->GetState()); |
| 76 browser->window()->ShowAvatarBubbleFromAvatarButton(bubble_mode, | 77 browser->window()->ShowAvatarBubbleFromAvatarButton(bubble_mode, |
| 77 manage_accounts_params); | 78 manage_accounts_params); |
| 78 } | 79 } |
| 79 #else // defined(OS_ANDROID) | 80 #else // BUILDFLAG(ANDROID_JAVA_UI) |
| 80 if (service_type == signin::GAIA_SERVICE_TYPE_INCOGNITO) { | 81 if (service_type == signin::GAIA_SERVICE_TYPE_INCOGNITO) { |
| 81 GURL url(manage_accounts_params.continue_url.empty() | 82 GURL url(manage_accounts_params.continue_url.empty() |
| 82 ? chrome::kChromeUINativeNewTabURL | 83 ? chrome::kChromeUINativeNewTabURL |
| 83 : manage_accounts_params.continue_url); | 84 : manage_accounts_params.continue_url); |
| 84 web_contents->OpenURL( | 85 web_contents->OpenURL( |
| 85 content::OpenURLParams(url, content::Referrer(), OFF_THE_RECORD, | 86 content::OpenURLParams(url, content::Referrer(), OFF_THE_RECORD, |
| 86 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false)); | 87 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false)); |
| 87 } else { | 88 } else { |
| 88 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( | 89 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( |
| 89 account_reconcilor->GetState()); | 90 account_reconcilor->GetState()); |
| 90 AccountManagementScreenHelper::OpenAccountManagementScreen(profile, | 91 AccountManagementScreenHelper::OpenAccountManagementScreen(profile, |
| 91 service_type); | 92 service_type); |
| 92 } | 93 } |
| 93 #endif // !defined(OS_ANDROID) | 94 #endif // !BUILDFLAG(ANDROID_JAVA_UI) |
| 94 } | 95 } |
| 95 | 96 |
| 96 // Returns the parameters contained in the X-Chrome-Manage-Accounts response | 97 // Returns the parameters contained in the X-Chrome-Manage-Accounts response |
| 97 // header. | 98 // header. |
| 98 // If the request does not have a response header or if the header contains | 99 // If the request does not have a response header or if the header contains |
| 99 // garbage, then |service_type| is set to |GAIA_SERVICE_TYPE_NONE|. | 100 // garbage, then |service_type| is set to |GAIA_SERVICE_TYPE_NONE|. |
| 100 // Must be called on IO thread. | 101 // Must be called on IO thread. |
| 101 ManageAccountsParams BuildManageAccountsParamsHelper(net::URLRequest* request, | 102 ManageAccountsParams BuildManageAccountsParamsHelper(net::URLRequest* request, |
| 102 ProfileIOData* io_data) { | 103 ProfileIOData* io_data) { |
| 103 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 104 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 return; | 161 return; |
| 161 | 162 |
| 162 params.child_id = child_id; | 163 params.child_id = child_id; |
| 163 params.route_id = route_id; | 164 params.route_id = route_id; |
| 164 content::BrowserThread::PostTask( | 165 content::BrowserThread::PostTask( |
| 165 content::BrowserThread::UI, FROM_HERE, | 166 content::BrowserThread::UI, FROM_HERE, |
| 166 base::Bind(ProcessMirrorHeaderUIThread, child_id, route_id, params)); | 167 base::Bind(ProcessMirrorHeaderUIThread, child_id, route_id, params)); |
| 167 } | 168 } |
| 168 | 169 |
| 169 } // namespace signin | 170 } // namespace signin |
| OLD | NEW |