Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / guest_view / renderer / guest_view_request.h
blob222c7ddbeb718949fb4a6c61cccd7644c6a9d13e
1 // Copyright 2015 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.
5 #ifndef COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_REQUEST_H_
6 #define COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_REQUEST_H_
8 #include "ipc/ipc_message.h"
9 #include "v8/include/v8.h"
11 namespace guest_view {
13 class GuestViewContainer;
15 // A GuestViewRequest is the base class for an asynchronous operation performed
16 // on a GuestView or GuestViewContainer from JavaScript. This operation may be
17 // queued until the container is ready to be operated upon (it has geometry).
18 // A GuestViewRequest may or may not have a callback back into JavaScript.
19 // Typically, performing a request involves sending an IPC to the browser
20 // process in PerformRequest. Handling a response involves receiving a related
21 // IPC from the browser process in HandleResponse.
22 class GuestViewRequest {
23 public:
24 GuestViewRequest(GuestViewContainer* container,
25 v8::Local<v8::Function> callback,
26 v8::Isolate* isolate);
27 virtual ~GuestViewRequest();
29 // Performs the associated request.
30 virtual void PerformRequest() = 0;
32 // Called by GuestViewContainer when the browser process has responded to the
33 // request initiated by PerformRequest.
34 virtual void HandleResponse(const IPC::Message& message) = 0;
36 // Called to call the callback associated with this request if one is
37 // available.
38 // Note: the callback may be called even if a response has not been heard from
39 // the browser process if the GuestViewContainer is being torn down.
40 void ExecuteCallbackIfAvailable(int argc,
41 scoped_ptr<v8::Local<v8::Value>[]> argv);
43 GuestViewContainer* container() const { return container_; }
45 v8::Isolate* isolate() const { return isolate_; }
47 private:
48 GuestViewContainer* const container_;
49 v8::Global<v8::Function> callback_;
50 v8::Isolate* const isolate_;
52 DISALLOW_COPY_AND_ASSIGN(GuestViewRequest);
55 // This class represents an AttachGuest request from Javascript. It includes
56 // the input parameters and the callback function. The Attach operation may
57 // not execute immediately, if the container is not ready or if there are
58 // other GuestViewRequests in flight.
59 class GuestViewAttachRequest : public GuestViewRequest {
60 public:
61 GuestViewAttachRequest(GuestViewContainer* container,
62 int guest_instance_id,
63 scoped_ptr<base::DictionaryValue> params,
64 v8::Local<v8::Function> callback,
65 v8::Isolate* isolate);
66 ~GuestViewAttachRequest() override;
68 void PerformRequest() override;
69 void HandleResponse(const IPC::Message& message) override;
71 private:
72 const int guest_instance_id_;
73 scoped_ptr<base::DictionaryValue> params_;
75 DISALLOW_COPY_AND_ASSIGN(GuestViewAttachRequest);
78 // This class represents a DetachGuest request from Javascript. The Detach
79 // operation may not execute immediately, if the container is not ready or if
80 // there are other GuestViewRequests in flight.
81 class GuestViewDetachRequest : public GuestViewRequest {
82 public:
83 GuestViewDetachRequest(GuestViewContainer* container,
84 v8::Local<v8::Function> callback,
85 v8::Isolate* isolate);
86 ~GuestViewDetachRequest() override;
88 void PerformRequest() override;
89 void HandleResponse(const IPC::Message& message) override;
91 private:
92 DISALLOW_COPY_AND_ASSIGN(GuestViewDetachRequest);
95 } // namespace guest_view
97 #endif // COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_