summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/guest_view/guest_view_internal_custom_bindings.h
blob: f18e15cd7ab232b00b66be9fe240b88a2397ac6f (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
// Copyright 2014 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 EXTENSIONS_RENDERER_GUEST_VIEW_GUEST_VIEW_INTERNAL_CUSTOM_BINDINGS_H_
#define EXTENSIONS_RENDERER_GUEST_VIEW_GUEST_VIEW_INTERNAL_CUSTOM_BINDINGS_H_

#include <map>

#include "extensions/renderer/object_backed_native_handler.h"

namespace extensions {
class Dispatcher;

// Implements custom bindings for the guestViewInternal API.
class GuestViewInternalCustomBindings : public ObjectBackedNativeHandler {
 public:
  explicit GuestViewInternalCustomBindings(ScriptContext* context);
  ~GuestViewInternalCustomBindings() override;

 private:
  // ResetMapEntry is called as a callback to SetWeak(). It resets the
  // weak view reference held in |view_map_|.
  static void ResetMapEntry(const v8::WeakCallbackInfo<int>& data);

  // AttachGuest attaches a GuestView to a provided container element. Once
  // attached, the GuestView will participate in layout of the container page
  // and become visible on screen.
  // AttachGuest takes four parameters:
  // |element_instance_id| uniquely identifies a container within the content
  // module is able to host GuestViews.
  // |guest_instance_id| uniquely identifies an unattached GuestView.
  // |attach_params| is typically used to convey the current state of the
  // container element at the time of attachment. These parameters are passed
  // down to the GuestView. The GuestView may use these parameters to update the
  // state of the guest hosted in another process.
  // |callback| is an optional callback that is called once attachment is
  // complete. The callback takes in a parameter for the WindowProxy of the
  // guest identified by |guest_instance_id|.
  void AttachGuest(const v8::FunctionCallbackInfo<v8::Value>& args);

  // DetachGuest detaches the container container specified from the associated
  // GuestViewBase. DetachGuest takes two parameters:
  // |element_instance_id| uniquely identifies a container within the content
  // module is able to host GuestViews.
  // |callback| is an optional callback that is called once the container has
  // been detached.
  void DetachGuest(const v8::FunctionCallbackInfo<v8::Value>& args);

  // AttachIframeGuest is --site-per-process variant of AttachGuest().
  //
  // AttachIframeGuest takes a |contentWindow| parameter in addition to the
  // parameters to AttachGuest. That parameter is used to identify the
  // RenderFrame of the <iframe> container element.
  void AttachIframeGuest(const v8::FunctionCallbackInfo<v8::Value>& args);

  // GetContentWindow takes in a RenderView routing ID and returns the
  // Window JavaScript object for that RenderView.
  void GetContentWindow(const v8::FunctionCallbackInfo<v8::Value>& args);

  // Destroys the GuestViewContainer given an element instance ID in |args|.
  void DestroyContainer(const v8::FunctionCallbackInfo<v8::Value>& args);

  // GetViewFromID takes a view ID, and returns the GuestView element associated
  // with that ID, if one exists. Otherwise, null is returned.
  void GetViewFromID(const v8::FunctionCallbackInfo<v8::Value>& args);

  // RegisterDestructionCallback registers a JavaScript callback function to be
  // called when the guestview's container is destroyed.
  // RegisterDestructionCallback takes in a single paramater, |callback|.
  void RegisterDestructionCallback(
      const v8::FunctionCallbackInfo<v8::Value>& args);

  // RegisterElementResizeCallback registers a JavaScript callback function to
  // be called when the element is resized. RegisterElementResizeCallback takes
  // a single parameter, |callback|.
  void RegisterElementResizeCallback(
      const v8::FunctionCallbackInfo<v8::Value>& args);

  // RegisterView takes in a view ID and a GuestView element, and stores the
  // pair as an entry in |view_map_|. The view can then be retrieved using
  // GetViewFromID.
  void RegisterView(const v8::FunctionCallbackInfo<v8::Value>& args);

  // Runs a JavaScript function with user gesture.
  //
  // This is used to request webview element to enter fullscreen (from the
  // embedder).
  // Note that the guest requesting fullscreen means it has already been
  // triggered by a user gesture and we get to this point if embedder allows
  // the fullscreen request to proceed.
  void RunWithGesture(
      const v8::FunctionCallbackInfo<v8::Value>& args);
};

}  // namespace extensions

#endif  // EXTENSIONS_RENDERER_GUEST_VIEW_GUEST_VIEW_INTERNAL_CUSTOM_BINDINGS_H_