1 // Copyright 2019 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 COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_ 6 #define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_ 7 8 #include <ostream> 9 #include "components/autofill_assistant/browser/service.pb.h" 10 11 namespace autofill_assistant { 12 13 // High-level states the Autofill Assistant can be in. 14 // 15 // A typical run, when started from CCT, autostarts a script, then displays a 16 // prompt and continues until a script sends the Stop action: 17 // 18 // INACTIVE -> STARTING -> RUNNING -> PROMPT -> RUNNING -> .. -> STOPPED 19 // 20 // A typical run, when started from a direct action, goes into tracking mode, 21 // execute a script, the goes back to tracking mode: 22 // 23 // INACTIVE -> TRACKING -> RUNNING -> TRACKING -> ... -> STOPPED 24 // 25 // See the individual state for possible state transitions. 26 enum class AutofillAssistantState { 27 // Autofill assistant is not doing or showing anything. 28 // 29 // Initial state. 30 // Next states: STARTING, TRACKING, STOPPED 31 INACTIVE = 0, 32 33 // Autofill assistant is keeping track of script availability. 34 // 35 // In this mode, no UI is shown and scripts are not autostarted. User 36 // actions might be available. 37 // 38 // Note that it is possible to go from TRACKING to STARTING to trigger 39 // whatever autostartable scripts is defined for a page. 40 // 41 // Next states: STARTING, RUNNING, STOPPED 42 TRACKING, 43 44 // Autofill assistant is waiting for an autostart script. 45 // 46 // Status message, progress and details are initialized to useful values. 47 // 48 // Next states: RUNNING, AUTOSTART_FALLBACK_PROMPT, STOPPED 49 STARTING, 50 51 // Autofill assistant is manipulating the website. 52 // 53 // Status message, progress and details kept up-to-date by the running 54 // script. 55 // 56 // Next states: PROMPT, MODAL_DIALOG, TRACKING, STARTING, STOPPED 57 RUNNING, 58 59 // Autofill assistant is waiting for the user to make a choice. 60 // 61 // Status message is initialized to a useful value. Chips are set and might be 62 // empty. A touchable area must be configured. The user might be filling in 63 // the data for a payment request. 64 // 65 // Next states: RUNNING, TRACKING, STOPPED 66 PROMPT, 67 68 // Autofill assistant is waiting for the user to make the first choice. 69 // 70 // When autostartable scripts are expected, this is only triggered as a 71 // fallback if there are non-autostartable scripts to choose from instead. 72 // 73 // Next states: RUNNING, STOPPED 74 AUTOSTART_FALLBACK_PROMPT, 75 76 // Autofill assistant is expecting a modal dialog, such as the one asking for 77 // CVC. 78 // 79 // Next states: RUNNING 80 MODAL_DIALOG, 81 82 // Autofill assistant is stopped, but the controller is still available. 83 // 84 // This is a final state for the UI, which, when entering this state, detaches 85 // itself from the controller and lets the user read the message. 86 // 87 // In that scenario, the status message at the time of transition to STOPPED 88 // is supposed to contain the final message. 89 // 90 // Next states: TRACKING, RUNNING 91 STOPPED, 92 93 // Autofill assistant is waiting for the user to browse the website until one 94 // of a set of specified preconditions match. 95 // 96 // Prompt-like state where a user is expected to browse a website with a 97 // minimal autofill assistant UI. Preconditions are still evaluated and 98 // buttons displayed if they match. There is no touchable 99 // area set for this state. 100 // 101 // In praticular, navigation to subdomains and user gestures like 'go back' 102 // are not a reason to shutdown autofill assistant. Navigating away from the 103 // original domain will however shut down autofill assistant. 104 // 105 // Next states: RUNNING, TRACKING, STOPPED 106 BROWSE, 107 }; 108 109 inline std::ostream& operator<<(std::ostream& out, 110 const AutofillAssistantState& state) { 111 #ifdef NDEBUG 112 // Non-debugging builds write the enum number. 113 out << static_cast<int>(state); 114 return out; 115 #else 116 // Debugging builds write a string representation of |state|. 117 switch (state) { 118 case AutofillAssistantState::INACTIVE: 119 out << "INACTIVE"; 120 break; 121 case AutofillAssistantState::TRACKING: 122 out << "TRACKING"; 123 break; 124 case AutofillAssistantState::STARTING: 125 out << "STARTING"; 126 break; 127 case AutofillAssistantState::RUNNING: 128 out << "RUNNING"; 129 break; 130 case AutofillAssistantState::PROMPT: 131 out << "PROMPT"; 132 break; 133 case AutofillAssistantState::AUTOSTART_FALLBACK_PROMPT: 134 out << "AUTOSTART_FALLBACK_PROMPT"; 135 break; 136 case AutofillAssistantState::MODAL_DIALOG: 137 out << "MODAL_DIALOG"; 138 break; 139 case AutofillAssistantState::STOPPED: 140 out << "STOPPED"; 141 break; 142 case AutofillAssistantState::BROWSE: 143 out << "BROWSE"; 144 break; 145 // Intentionally no default case to make compilation fail if a new value 146 // was added to the enum but not to this list. 147 } 148 return out; 149 #endif // NDEBUG 150 } 151 152 } // namespace autofill_assistant 153 154 #endif // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_STATE_H_ 155