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