summaryrefslogtreecommitdiff
path: root/chromium/components/autofill_assistant/browser/actions/execute_js_action.h
blob: a2f462e3ec3789f56925571bd86da3291fe6907b (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
// Copyright 2022 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_EXECUTE_JS_ACTION_H_
#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_ACTIONS_EXECUTE_JS_ACTION_H_

#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
#include "components/autofill_assistant/browser/actions/action.h"
#include "components/autofill_assistant/browser/actions/action_delegate.h"
#include "components/autofill_assistant/browser/dom_action.pb.h"
#include "components/autofill_assistant/browser/web/element_finder.h"

namespace autofill_assistant {

// An action that runs the JS snippet on a single previously stored element.
// No additional parameters are provided when running the snippet.
class ExecuteJsAction : public Action {
 public:
  ExecuteJsAction(ActionDelegate* delegate, const ActionProto& proto);
  ~ExecuteJsAction() override;

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

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

  void EndAction(const ClientStatus& status);

  ElementFinder::Result element_;
  ProcessActionCallback callback_;
  base::OneShotTimer timer_;

  base::WeakPtrFactory<ExecuteJsAction> weak_ptr_factory_{this};
};

}  // namespace autofill_assistant
#endif  // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_ACTIONS_EXECUTE_JS_ACTION_H_