summaryrefslogtreecommitdiff
path: root/chromium/components/autofill_assistant/browser/state.h
blob: 5106b3ee5ebb5c9077cefe48048db478c892425c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_
#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_

#include <ostream>

namespace autofill_assistant {

// High-level states the Autofill Assistant can be in.
//
// A typical run, when started from CCT, autostarts a script, then displays a
// prompt and continues until a script sends the Stop action:
//
// INACTIVE -> STARTING -> RUNNING -> PROMPT -> RUNNING -> .. -> STOPPED
//
// A typical run, when started from a direct action, goes into tracking mode,
// execute a script, the goes back to tracking mode:
//
// INACTIVE -> TRACKING -> RUNNING -> TRACKING -> ... -> STOPPED
//
// See the individual state for possible state transitions.
enum class AutofillAssistantState {
  // Autofill assistant is not doing or showing anything.
  //
  // Initial state.
  // Next states: STARTING, TRACKING, STOPPED
  INACTIVE = 0,

  // Autofill assistant is keeping track of script availability.
  //
  // In this mode, no UI is shown and scripts are not autostarted. User
  // actions might be available.
  //
  // Note that it is possible to go from TRACKING to STARTING to trigger
  // whatever autostartable scripts is defined for a page.
  //
  // Next states: STARTING, RUNNING, STOPPED
  TRACKING,

  // Autofill assistant is waiting for an autostart script.
  //
  // Status message, progress and details are initialized to useful values.
  //
  // Next states: RUNNING, AUTOSTART_FALLBACK_PROMPT, STOPPED
  STARTING,

  // Autofill assistant is manipulating the website.
  //
  // Status message, progress and details kept up-to-date by the running
  // script.
  //
  // Next states: PROMPT, MODAL_DIALOG, TRACKING, STARTING, STOPPED
  RUNNING,

  // Autofill assistant is waiting for the user to make a choice.
  //
  // Status message is initialized to a useful value. Chips are set and might be
  // empty. A touchable area must be configured. The user might be filling in
  // the data for a payment request.
  //
  // Next states: RUNNING, TRACKING, STOPPED
  PROMPT,

  // Autofill assistant is waiting for the user to make the first choice.
  //
  // When autostartable scripts are expected, this is only triggered as a
  // fallback if there are non-autostartable scripts to choose from instead.
  //
  // Next states: RUNNING, STOPPED
  AUTOSTART_FALLBACK_PROMPT,

  // Autofill assistant is expecting a modal dialog, such as the one asking for
  // CVC.
  //
  // Next states: RUNNING
  MODAL_DIALOG,

  // Autofill assistant is stopped, but the controller is still available.
  //
  // This is a final state for the UI, which, when entering this state, detaches
  // itself from the controller and lets the user read  the message.
  //
  // In that scenario, the status message at the time of transition to STOPPED
  // is supposed to contain the final message.
  //
  // Next states: TRACKING
  STOPPED,

  // Autofill assistant is waiting for the user to browse the website until one
  // of a set of specified preconditions match.
  //
  // Prompt-like state where a user is expected to browse a website with a
  // minimal autofill assistant UI. Preconditions are still evaluated and
  // buttons displayed if they match. There is no touchable
  // area set for this state.
  //
  // In praticular, navigation to subdomains and user gestures like 'go back'
  // are not a reason to shutdown autofill assistant. Navigating away from the
  // original domain will however shut down autofill assistant.
  //
  // Next states: RUNNING, TRACKING, STOPPED
  BROWSE,
};

inline std::ostream& operator<<(std::ostream& out,
                                const AutofillAssistantState& state) {
#ifdef NDEBUG
  // Non-debugging builds write the enum number.
  out << static_cast<int>(state);
  return out;
#else
  // Debugging builds write a string representation of |state|.
  switch (state) {
    case AutofillAssistantState::INACTIVE:
      out << "INACTIVE";
      break;
    case AutofillAssistantState::TRACKING:
      out << "TRACKING";
      break;
    case AutofillAssistantState::STARTING:
      out << "STARTING";
      break;
    case AutofillAssistantState::RUNNING:
      out << "RUNNING";
      break;
    case AutofillAssistantState::PROMPT:
      out << "PROMPT";
      break;
    case AutofillAssistantState::AUTOSTART_FALLBACK_PROMPT:
      out << "AUTOSTART_FALLBACK_PROMPT";
      break;
    case AutofillAssistantState::MODAL_DIALOG:
      out << "MODAL_DIALOG";
      break;
    case AutofillAssistantState::STOPPED:
      out << "STOPPED";
      break;
    case AutofillAssistantState::BROWSE:
      out << "BROWSE";
      break;
      // Intentionally no default case to make compilation fail if a new value
      // was added to the enum but not to this list.
  }
  return out;
#endif  // NDEBUG
}

}  // namespace autofill_assistant

#endif  // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_