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