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/signin_header_helper.h" | 5 #include "chrome/browser/signin/signin_header_helper.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/google/google_util.h" | 9 #include "chrome/browser/google/google_util.h" |
10 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 10 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/android/signin/account_management_screen_helper.h" | 23 #include "chrome/browser/android/signin/account_management_screen_helper.h" |
24 #else | 24 #else |
25 #include "chrome/browser/ui/browser_commands.h" | 25 #include "chrome/browser/ui/browser_commands.h" |
26 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
27 #endif // defined(OS_ANDROID) | 27 #endif // defined(OS_ANDROID) |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 const char kChromeConnectedHeader[] = "X-Chrome-Connected"; | 31 const char kChromeConnectedHeader[] = "X-Chrome-Connected"; |
32 const char kChromeManageAccountsHeader[] = "X-Chrome-Manage-Accounts"; | 32 const char kChromeManageAccountsHeader[] = "X-Chrome-Manage-Accounts"; |
33 const char kGaiaSignoutOptionsIncognito[] = "SIGNOUTOPTIONS_INCOGNITO"; | |
34 const char kGaiaIdAttrName[] = "id"; | 33 const char kGaiaIdAttrName[] = "id"; |
35 const char kProfileModeAttrName[] = "mode"; | 34 const char kProfileModeAttrName[] = "mode"; |
36 const char kEnableAccountConsistencyAttrName[] = "enable_account_consistency"; | 35 const char kEnableAccountConsistencyAttrName[] = "enable_account_consistency"; |
37 | 36 |
| 37 // Determine the service type that has been passed from GAIA in the header. |
| 38 signin::GAIAServiceType GetGAIAServiceTypeFromHeader( |
| 39 const std::string& header_value) { |
| 40 if (header_value == "SIGNOUT") |
| 41 return signin::GAIA_SERVICE_TYPE_SIGNOUT; |
| 42 else if (header_value == "SIGNOUTOPTIONS_INCOGNITO") |
| 43 return signin::GAIA_SERVICE_TYPE_SIGNOUTOPTIONS_INCOGNITO; |
| 44 else if (header_value == "ADDSESSION") |
| 45 return signin::GAIA_SERVICE_TYPE_ADDSESSION; |
| 46 else if (header_value == "REAUTH") |
| 47 return signin::GAIA_SERVICE_TYPE_REAUTH; |
| 48 else if (header_value == "DEFAULT") |
| 49 return signin::GAIA_SERVICE_TYPE_DEFAULT; |
| 50 else |
| 51 return signin::GAIA_SERVICE_TYPE_NONE; |
| 52 } |
| 53 |
38 // Processes the mirror response header on the UI thread. Currently depending | 54 // Processes the mirror response header on the UI thread. Currently depending |
39 // on the value of |header_value|, it either shows the profile avatar menu, or | 55 // on the value of |header_value|, it either shows the profile avatar menu, or |
40 // opens an incognito window/tab. | 56 // opens an incognito window/tab. |
41 void ProcessMirrorHeaderUIThread( | 57 void ProcessMirrorHeaderUIThread( |
42 int child_id, int route_id, const std::string& header_value) { | 58 int child_id, int route_id, const std::string& header_value) { |
43 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 59 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
44 | 60 |
45 content::WebContents* web_contents = | 61 content::WebContents* web_contents = |
46 tab_util::GetWebContentsByID(child_id, route_id); | 62 tab_util::GetWebContentsByID(child_id, route_id); |
47 if (!web_contents) | 63 if (!web_contents) |
48 return; | 64 return; |
49 | 65 |
| 66 signin::GAIAServiceType service_type = |
| 67 GetGAIAServiceTypeFromHeader(header_value); |
| 68 |
50 #if !defined(OS_ANDROID) | 69 #if !defined(OS_ANDROID) |
51 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 70 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
52 if (browser) { | 71 if (browser) { |
53 if (header_value == kGaiaSignoutOptionsIncognito) { | 72 if (service_type == signin::GAIA_SERVICE_TYPE_SIGNOUTOPTIONS_INCOGNITO) { |
54 chrome::NewIncognitoWindow(browser); | 73 chrome::NewIncognitoWindow(browser); |
55 } else { | 74 } else { |
56 browser->window()->ShowAvatarBubbleFromAvatarButton( | 75 browser->window()->ShowAvatarBubbleFromAvatarButton( |
57 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT); | 76 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, |
| 77 service_type); |
58 } | 78 } |
59 } | 79 } |
60 #else // defined(OS_ANDROID) | 80 #else // defined(OS_ANDROID) |
61 if (header_value == kGaiaSignoutOptionsIncognito) { | 81 if (service_type == signin::GAIA_SERVICE_TYPE_SIGNOUTOPTIONS_INCOGNITO) { |
62 web_contents->OpenURL(content::OpenURLParams( | 82 web_contents->OpenURL(content::OpenURLParams( |
63 GURL(chrome::kChromeUINativeNewTabURL), content::Referrer(), | 83 GURL(chrome::kChromeUINativeNewTabURL), content::Referrer(), |
64 OFF_THE_RECORD, content::PAGE_TRANSITION_AUTO_TOPLEVEL, false)); | 84 OFF_THE_RECORD, content::PAGE_TRANSITION_AUTO_TOPLEVEL, false)); |
65 } else { | 85 } else { |
| 86 // TODO(mlerman): pass service_type to android logic for UMA metrics |
| 87 // that will eventually be installed there. |
66 AccountManagementScreenHelper::OpenAccountManagementScreen( | 88 AccountManagementScreenHelper::OpenAccountManagementScreen( |
67 Profile::FromBrowserContext(web_contents->GetBrowserContext())); | 89 Profile::FromBrowserContext(web_contents->GetBrowserContext())); |
68 } | 90 } |
69 #endif // OS_ANDROID | 91 #endif // OS_ANDROID |
70 } | 92 } |
71 | 93 |
72 bool IsDriveOrigin(const GURL& url) { | 94 bool IsDriveOrigin(const GURL& url) { |
73 if (!url.SchemeIsSecure()) | 95 if (!url.SchemeIsSecure()) |
74 return false; | 96 return false; |
75 | 97 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 DCHECK(switches::IsNewProfileManagement() && | 170 DCHECK(switches::IsNewProfileManagement() && |
149 !io_data->IsOffTheRecord()); | 171 !io_data->IsOffTheRecord()); |
150 content::BrowserThread::PostTask( | 172 content::BrowserThread::PostTask( |
151 content::BrowserThread::UI, FROM_HERE, | 173 content::BrowserThread::UI, FROM_HERE, |
152 base::Bind(ProcessMirrorHeaderUIThread, child_id, route_id, | 174 base::Bind(ProcessMirrorHeaderUIThread, child_id, route_id, |
153 header_value)); | 175 header_value)); |
154 } | 176 } |
155 } | 177 } |
156 | 178 |
157 } // namespace signin | 179 } // namespace signin |
OLD | NEW |