File: guest_view_request.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (72 lines) | stat: -rw-r--r-- 2,581 bytes parent folder | download | duplicates (7)
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
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_REQUEST_H_
#define COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_REQUEST_H_

#include <memory>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "components/guest_view/common/guest_view.mojom.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "v8/include/v8-forward.h"
#include "v8/include/v8-persistent-handle.h"

namespace content {
class RenderFrame;
}

namespace guest_view {

class GuestViewContainer;

// This class represents an attach request from Javascript.
// A GuestViewAttachRequest is an asynchronous operation performed on a
// GuestView or GuestViewContainer from JavaScript. This operation may be queued
// until the container is ready to be operated upon (it has geometry). A
// GuestViewAttachRequest may or may not have a callback back into JavaScript.
// Performing a request involves sending an IPC to the browser process in
// PerformRequest which the browser will acknowledge.
class GuestViewAttachRequest {
 public:
  GuestViewAttachRequest(GuestViewContainer* container,
                         content::RenderFrame* render_frame,
                         int guest_instance_id,
                         base::Value::Dict params,
                         v8::Local<v8::Function> callback,
                         v8::Isolate* isolate);

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

  ~GuestViewAttachRequest();

  // Performs the associated request.
  void PerformRequest();

  // Called to call the callback associated with this request if one is
  // available.
  // Note: the callback may be called even if a response has not been heard from
  // the browser process if the GuestViewContainer is being torn down.
  void ExecuteCallbackIfAvailable(int argc,
                                  std::unique_ptr<v8::Local<v8::Value>[]> argv);

 private:
  void OnAcknowledged();

  const raw_ptr<GuestViewContainer> container_;
  v8::Global<v8::Function> callback_;
  const raw_ptr<v8::Isolate> isolate_;
  const int guest_instance_id_;
  const base::Value::Dict params_;
  mojo::AssociatedRemote<mojom::GuestViewHost> remote_;

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

}  // namespace guest_view

#endif  // COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_REQUEST_H_