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 "chrome/browser/google/google_util.h" | 9 #include "chrome/browser/google/google_util.h" |
9 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 10 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
10 #include "chrome/browser/profiles/profile_io_data.h" | 11 #include "chrome/browser/profiles/profile_io_data.h" |
11 #include "chrome/browser/tab_contents/tab_util.h" | 12 #include "chrome/browser/tab_contents/tab_util.h" |
12 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
14 #include "components/signin/core/common/profile_management_switches.h" | 15 #include "components/signin/core/common/profile_management_switches.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "google_apis/gaia/gaia_auth_util.h" | 18 #include "google_apis/gaia/gaia_auth_util.h" |
18 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
19 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
20 | 21 |
21 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
22 #include "chrome/browser/android/signin/account_management_screen_helper.h" | 23 #include "chrome/browser/android/signin/account_management_screen_helper.h" |
23 #else | 24 #else |
24 #include "chrome/browser/ui/browser_commands.h" | 25 #include "chrome/browser/ui/browser_commands.h" |
25 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
26 #endif // defined(OS_ANDROID) | 27 #endif // defined(OS_ANDROID) |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 const char kChromeConnectedHeader[] = "X-Chrome-Connected"; | 31 const char kChromeConnectedHeader[] = "X-Chrome-Connected"; |
31 const char kChromeManageAccountsHeader[] = "X-Chrome-Manage-Accounts"; | 32 const char kChromeManageAccountsHeader[] = "X-Chrome-Manage-Accounts"; |
32 const char kGaiaSignoutOptionsIncognito[] = "SIGNOUTOPTIONS_INCOGNITO"; | 33 const char kGaiaSignoutOptionsIncognito[] = "SIGNOUTOPTIONS_INCOGNITO"; |
| 34 const char kGaiaIdAttrName[] = "id"; |
| 35 const char kProfileModeAttrName[] = "mode"; |
| 36 const char kEnableAccountConsistencyAttrName[] = "enable_account_consistency"; |
33 | 37 |
34 // Processes the mirror response header on the UI thread. Currently depending | 38 // 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 | 39 // on the value of |header_value|, it either shows the profile avatar menu, or |
36 // opens an incognito window/tab. | 40 // opens an incognito window/tab. |
37 void ProcessMirrorHeaderUIThread( | 41 void ProcessMirrorHeaderUIThread( |
38 int child_id, int route_id, const std::string& header_value) { | 42 int child_id, int route_id, const std::string& header_value) { |
39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 43 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
40 | 44 |
41 content::WebContents* web_contents = | 45 content::WebContents* web_contents = |
42 tab_util::GetWebContentsByID(child_id, route_id); | 46 tab_util::GetWebContentsByID(child_id, route_id); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 97 |
94 // Only set the header for Drive always, and other Google properties if | 98 // Only set the header for Drive always, and other Google properties if |
95 // new-profile-management is enabled. | 99 // new-profile-management is enabled. |
96 // Vasquette, which is integrated with most Google properties, needs the | 100 // Vasquette, which is integrated with most Google properties, needs the |
97 // header to redirect certain user actions to Chrome native UI. Drive needs | 101 // header to redirect certain user actions to Chrome native UI. Drive needs |
98 // the header to tell if the current user is connected. The drive path is a | 102 // the header to tell if the current user is connected. The drive path is a |
99 // temporary workaround until the more generic chrome.principals API is | 103 // temporary workaround until the more generic chrome.principals API is |
100 // available. | 104 // available. |
101 const GURL& url = redirect_url.is_empty() ? request->url() : redirect_url; | 105 const GURL& url = redirect_url.is_empty() ? request->url() : redirect_url; |
102 GURL origin(url.GetOrigin()); | 106 GURL origin(url.GetOrigin()); |
| 107 bool is_new_profile_management = switches::IsNewProfileManagement(); |
103 bool is_google_url = | 108 bool is_google_url = |
104 !switches::IsEnableWebBasedSignin() && | 109 !switches::IsEnableWebBasedSignin() && |
105 switches::IsNewProfileManagement() && | 110 is_new_profile_management && |
106 google_util::IsGoogleDomainUrl( | 111 google_util::IsGoogleDomainUrl( |
107 url, | 112 url, |
108 google_util::ALLOW_SUBDOMAIN, | 113 google_util::ALLOW_SUBDOMAIN, |
109 google_util::DISALLOW_NON_STANDARD_PORTS); | 114 google_util::DISALLOW_NON_STANDARD_PORTS); |
110 if (!is_google_url && !IsDriveOrigin(origin)) | 115 if (!is_google_url && !IsDriveOrigin(origin)) |
111 return; | 116 return; |
112 | 117 |
113 std::string account_id(io_data->google_services_account_id()->GetValue()); | 118 std::string account_id(io_data->google_services_account_id()->GetValue()); |
114 | 119 |
115 int profile_mode_mask = PROFILE_MODE_DEFAULT; | 120 int profile_mode_mask = PROFILE_MODE_DEFAULT; |
116 // TODO(guohui): Needs to check for parent control as well. | 121 // TODO(guohui): Needs to check for parent control as well. |
117 if (io_data->incognito_availibility()->GetValue() == | 122 if (io_data->incognito_availibility()->GetValue() == |
118 IncognitoModePrefs::DISABLED) { | 123 IncognitoModePrefs::DISABLED) { |
119 profile_mode_mask |= PROFILE_MODE_INCOGNITO_DISABLED; | 124 profile_mode_mask |= PROFILE_MODE_INCOGNITO_DISABLED; |
120 } | 125 } |
121 | 126 |
122 std::string header_value = | 127 // TODO(guohui): needs to make a new flag for enabling account consistency. |
123 account_id + ":" + base::IntToString(profile_mode_mask); | 128 std::string header_value(base::StringPrintf("%s=%s,%s=%s,%s=%s", |
| 129 kGaiaIdAttrName, account_id.c_str(), |
| 130 kProfileModeAttrName, base::IntToString(profile_mode_mask).c_str(), |
| 131 kEnableAccountConsistencyAttrName, |
| 132 is_new_profile_management ? "true" : "false")); |
124 request->SetExtraRequestHeaderByName( | 133 request->SetExtraRequestHeaderByName( |
125 kChromeConnectedHeader, header_value, false); | 134 kChromeConnectedHeader, header_value, false); |
126 } | 135 } |
127 | 136 |
128 void ProcessMirrorResponseHeaderIfExists( | 137 void ProcessMirrorResponseHeaderIfExists( |
129 net::URLRequest* request, | 138 net::URLRequest* request, |
130 ProfileIOData* io_data, | 139 ProfileIOData* io_data, |
131 int child_id, | 140 int child_id, |
132 int route_id) { | 141 int route_id) { |
133 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 142 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
134 | 143 |
135 std::string header_value; | 144 std::string header_value; |
136 if (gaia::IsGaiaSignonRealm(request->url().GetOrigin()) && | 145 if (gaia::IsGaiaSignonRealm(request->url().GetOrigin()) && |
137 request->response_headers()->GetNormalizedHeader( | 146 request->response_headers()->GetNormalizedHeader( |
138 kChromeManageAccountsHeader, &header_value)) { | 147 kChromeManageAccountsHeader, &header_value)) { |
139 DCHECK(switches::IsNewProfileManagement() && | 148 DCHECK(switches::IsNewProfileManagement() && |
140 !io_data->IsOffTheRecord()); | 149 !io_data->IsOffTheRecord()); |
141 content::BrowserThread::PostTask( | 150 content::BrowserThread::PostTask( |
142 content::BrowserThread::UI, FROM_HERE, | 151 content::BrowserThread::UI, FROM_HERE, |
143 base::Bind(ProcessMirrorHeaderUIThread, child_id, route_id, | 152 base::Bind(ProcessMirrorHeaderUIThread, child_id, route_id, |
144 header_value)); | 153 header_value)); |
145 } | 154 } |
146 } | 155 } |
147 | 156 |
148 } // namespace signin | 157 } // namespace signin |
OLD | NEW |