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
10namespace net {
11class URLRequest;
12}
13class GURL;
14class 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.
21namespace signin {
22
23// Profile mode flags.
24enum 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.
35enum 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_SIGNUP,                   // Create a new account.
42  GAIA_SERVICE_TYPE_DEFAULT,                  // All other cases.
43};
44
45// Struct describing the paramters received in the manage account header.
46struct ManageAccountsParams {
47  // The requested service type such as "ADDSESSION".
48  GAIAServiceType service_type;
49  // The prefilled email.
50  std::string email;
51  // Whether |email| is a saml account.
52  bool is_saml;
53  // The continue URL after the requested service is completed successfully.
54  // Defaults to the current URL if empty.
55  std::string continue_url;
56  // Whether the continue URL should be loaded in the same tab.
57  bool is_same_tab;
58  // The child id associated with the web content of the request.
59  int child_id;
60  // The route id associated with the web content of the request.
61  int route_id;
62
63  ManageAccountsParams();
64};
65
66// Adds X-Chrome-Connected header to all Gaia requests from a connected profile,
67// with the exception of requests from gaia webview. Must be called on IO
68// thread.
69// Returns true if the account management header was added to the request.
70bool AppendMirrorRequestHeaderIfPossible(
71    net::URLRequest* request,
72    const GURL& redirect_url,
73    ProfileIOData* io_data);
74
75// Looks for the X-Chrome-Manage-Accounts response header, and if found,
76// tries to show the avatar bubble in the browser identified by the
77// child/route id. Must be called on IO thread.
78void ProcessMirrorResponseHeaderIfExists(
79    net::URLRequest* request,
80    ProfileIOData* io_data,
81    int child_id,
82    int route_id);
83
84};  // namespace signin
85
86#endif  // CHROME_BROWSER_SIGNIN_SIGNIN_HEADER_HELPER_H_
87