• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_HEADER_HELPER_H_
6 #define CHROME_BROWSER_SIGNIN_SIGNIN_HEADER_HELPER_H_
7 
8 #include <string>
9 
10 namespace net {
11 class URLRequest;
12 }
13 class GURL;
14 class ProfileIOData;
15 
16 // Utility functions for handling Chrome/Gaia headers during signin process.
17 // In the Mirror world, Chrome identity should always stay in sync with Gaia
18 // identity. Therefore Chrome needs to send Gaia special header for requests
19 // from a connected profile, so that Gaia can modify its response accordingly
20 // and let Chrome handles signin with native UI.
21 namespace signin {
22 
23 // Profile mode flags.
24 enum ProfileMode {
25   PROFILE_MODE_DEFAULT = 0,
26   // Incognito mode disabled by enterprise policy or by parental controls.
27   PROFILE_MODE_INCOGNITO_DISABLED = 1 << 0,
28   // Adding account disabled in the Android-for-EDU mode.
29   PROFILE_MODE_ADD_ACCOUNT_DISABLED = 1 << 1
30 };
31 
32 // The ServiceType specified by GAIA in the response header accompanying the 204
33 // response. This indicates the action Chrome is supposed to lead the user to
34 // perform.
35 enum GAIAServiceType {
36   GAIA_SERVICE_TYPE_NONE = 0,                 // No GAIA response header.
37   GAIA_SERVICE_TYPE_SIGNOUT,                  // Logout all existing sessions.
38   GAIA_SERVICE_TYPE_INCOGNITO,                // Open an incognito tab.
39   GAIA_SERVICE_TYPE_ADDSESSION,               // Add a secondary account.
40   GAIA_SERVICE_TYPE_REAUTH,                   // Re-authenticate an account.
41   GAIA_SERVICE_TYPE_DEFAULT,                  // All other cases.
42 };
43 
44 // Struct describing the paramters received in the manage account header.
45 struct ManageAccountsParams {
46   // The requested service type such as "ADDSESSION".
47   GAIAServiceType service_type;
48   // The prefilled email.
49   std::string email;
50   // Whether |email| is a saml account.
51   bool is_saml;
52   // The continue URL after the requested service is completed successfully.
53   // Defaults to the current URL if empty.
54   std::string continue_url;
55   // Whether the continue URL should be loaded in the same tab.
56   bool is_same_tab;
57   // The child id associated with the web content of the request.
58   int child_id;
59   // The route id associated with the web content of the request.
60   int route_id;
61 
62   ManageAccountsParams();
63 };
64 
65 // Adds X-Chrome-Connected header to all Gaia requests from a connected profile,
66 // with the exception of requests from gaia webview. Must be called on IO
67 // thread.
68 // Returns true if the account management header was added to the request.
69 bool AppendMirrorRequestHeaderIfPossible(
70     net::URLRequest* request,
71     const GURL& redirect_url,
72     ProfileIOData* io_data,
73     int child_id,
74     int route_id);
75 
76 // Looks for the X-Chrome-Manage-Accounts response header, and if found,
77 // tries to show the avatar bubble in the browser identified by the
78 // child/route id. Must be called on IO thread.
79 void ProcessMirrorResponseHeaderIfExists(
80     net::URLRequest* request,
81     ProfileIOData* io_data,
82     int child_id,
83     int route_id);
84 
85 };  // namespace signin
86 
87 #endif  // CHROME_BROWSER_SIGNIN_SIGNIN_HEADER_HELPER_H_
88