summaryrefslogtreecommitdiff
path: root/chromium/components/autofill_assistant/browser/actions/show_generic_ui_action.h
blob: bca744ddf8d13559c138d94a2d4912f57b4c9be2 (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
// Copyright 2020 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_ACTIONS_SHOW_GENERIC_UI_ACTION_H_
#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_ACTIONS_SHOW_GENERIC_UI_ACTION_H_

#include "base/callback.h"
#include "base/containers/flat_map.h"
#include "base/memory/weak_ptr.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/personal_data_manager_observer.h"
#include "components/autofill_assistant/browser/actions/action.h"
#include "components/autofill_assistant/browser/element_precondition.h"
#include "components/autofill_assistant/browser/wait_for_dom_observer.h"
#include "components/autofill_assistant/browser/web/element.h"
#include "components/autofill_assistant/browser/website_login_manager.h"

namespace autofill_assistant {

// Action to show generic UI in the sheet.
class ShowGenericUiAction : public Action,
                            public WaitForDomObserver,
                            public autofill::PersonalDataManagerObserver {
 public:
  explicit ShowGenericUiAction(ActionDelegate* delegate,
                               const ActionProto& proto);
  ~ShowGenericUiAction() override;

  ShowGenericUiAction(const ShowGenericUiAction&) = delete;
  ShowGenericUiAction& operator=(const ShowGenericUiAction&) = delete;

  // Overrides Action:
  bool ShouldInterruptOnPause() const override;

  // Overrides WaitForDomObserver:
  void OnInterruptStarted() override;
  void OnInterruptFinished() override;

 private:
  // Overrides Action:
  void InternalProcessAction(ProcessActionCallback callback) override;

  void RegisterChecks(
      BatchElementChecker* checker,
      base::OnceCallback<void(const ClientStatus&)> wait_for_dom_callback);
  void OnPreconditionResult(
      size_t choice_index,
      const ClientStatus& status,
      const std::vector<std::string>& ignored_payloads,
      const base::flat_map<std::string, DomObjectFrameStack>& ignored_elements);
  void OnElementChecksDone(
      base::OnceCallback<void(const ClientStatus&)> wait_for_dom_callback);
  void OnDoneWaitForDom(const ClientStatus& status);
  // If there is an active WaitForDom this method ends it before calling
  // EndAction, otherwise it just calls EndAction.
  void OnEndActionInteraction(const ClientStatus& status);
  void EndAction(const ClientStatus& status);

  void OnViewInflationFinished(bool first_inflation,
                               const ClientStatus& status);
  void OnNavigationEnded();

  // From autofill::PersonalDataManagerObserver.
  void OnPersonalDataChanged() override;

  base::TimeTicks wait_time_start_;
  bool has_pending_wait_for_dom_ = false;
  bool should_end_action_ = false;
  std::vector<std::unique_ptr<ElementPrecondition>> preconditions_;
  ProcessActionCallback callback_;
  base::WeakPtrFactory<ShowGenericUiAction> weak_ptr_factory_{this};
};

}  // namespace autofill_assistant
#endif  // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_ACTIONS_SHOW_GENERIC_UI_ACTION_H_