Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / extensions / renderer / guest_view / extensions_guest_view_container.h
blob75e21698d9d35c9847b71182a6efd4631f9b53af
1 // Copyright 2014 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 EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_
6 #define EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_
8 #include <queue>
10 #include "base/memory/linked_ptr.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h"
13 #include "extensions/renderer/guest_view/guest_view_container.h"
14 #include "v8/include/v8.h"
16 namespace gfx {
17 class Size;
20 namespace extensions {
22 class ExtensionsGuestViewContainer : public GuestViewContainer {
23 public:
25 class Request {
26 public:
27 Request(GuestViewContainer* container,
28 v8::Handle<v8::Function> callback,
29 v8::Isolate* isolate);
30 virtual ~Request();
32 virtual void PerformRequest() = 0;
33 virtual void HandleResponse(const IPC::Message& message) = 0;
35 void ExecuteCallbackIfAvailable(int argc,
36 scoped_ptr<v8::Handle<v8::Value>[]> argv);
38 GuestViewContainer* container() const { return container_; }
40 bool HasCallback() const;
42 v8::Handle<v8::Function> GetCallback() const;
44 v8::Isolate* isolate() const { return isolate_; }
46 private:
47 GuestViewContainer* container_;
48 v8::Global<v8::Function> callback_;
49 v8::Isolate* const isolate_;
52 // This class represents an AttachGuest request from Javascript. It includes
53 // the input parameters and the callback function. The Attach operation may
54 // not execute immediately, if the container is not ready or if there are
55 // other attach operations in flight.
56 class AttachRequest : public Request {
57 public:
58 AttachRequest(GuestViewContainer* container,
59 int guest_instance_id,
60 scoped_ptr<base::DictionaryValue> params,
61 v8::Handle<v8::Function> callback,
62 v8::Isolate* isolate);
63 ~AttachRequest() override;
65 void PerformRequest() override;
66 void HandleResponse(const IPC::Message& message) override;
68 private:
69 const int guest_instance_id_;
70 scoped_ptr<base::DictionaryValue> params_;
73 class DetachRequest : public Request {
74 public:
75 DetachRequest(GuestViewContainer* container,
76 v8::Handle<v8::Function> callback,
77 v8::Isolate* isolate);
78 ~DetachRequest() override;
80 void PerformRequest() override;
81 void HandleResponse(const IPC::Message& message) override;
84 explicit ExtensionsGuestViewContainer(content::RenderFrame* render_frame);
85 ~ExtensionsGuestViewContainer() override;
87 static ExtensionsGuestViewContainer* FromID(int element_instance_id);
89 void IssueRequest(linked_ptr<Request> request);
90 void RegisterDestructionCallback(v8::Handle<v8::Function> callback,
91 v8::Isolate* isolate);
92 void RegisterElementResizeCallback(v8::Handle<v8::Function> callback,
93 v8::Isolate* isolate);
95 // BrowserPluginDelegate implementation.
96 bool OnMessageReceived(const IPC::Message& message) override;
97 void SetElementInstanceID(int element_instance_id) override;
98 void Ready() override;
99 void DidResizeElement(const gfx::Size& old_size,
100 const gfx::Size& new_size) override;
102 private:
103 void OnHandleCallback(const IPC::Message& message);
105 void CallElementResizeCallback(const gfx::Size& old_size,
106 const gfx::Size& new_size);
107 void EnqueueRequest(linked_ptr<Request> request);
108 void PerformPendingRequest();
109 void HandlePendingResponseCallback(const IPC::Message& message);
111 bool ready_;
113 std::deque<linked_ptr<Request> > pending_requests_;
114 linked_ptr<Request> pending_response_;
116 v8::Global<v8::Function> destruction_callback_;
117 v8::Isolate* destruction_isolate_;
119 v8::Global<v8::Function> element_resize_callback_;
120 v8::Isolate* element_resize_isolate_;
122 // Weak pointer factory used for calling the element resize callback.
123 base::WeakPtrFactory<ExtensionsGuestViewContainer> weak_ptr_factory_;
125 DISALLOW_COPY_AND_ASSIGN(ExtensionsGuestViewContainer);
128 } // namespace extensions
130 #endif // EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_