Reland the ULONG -> SIZE_T change from 317177
[chromium-blink-merge.git] / extensions / renderer / guest_view / extensions_guest_view_container.h
blobdf257f18171a99d9d9aab21d599c6c3135699608
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 "extensions/renderer/scoped_persistent.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 GuestViewContainer* container() const { return container_; }
37 bool HasCallback() const;
39 v8::Handle<v8::Function> GetCallback() const;
41 v8::Isolate* isolate() const { return isolate_; }
43 private:
44 GuestViewContainer* container_;
45 ScopedPersistent<v8::Function> callback_;
46 v8::Isolate* const isolate_;
49 // This class represents an AttachGuest request from Javascript. It includes
50 // the input parameters and the callback function. The Attach operation may
51 // not execute immediately, if the container is not ready or if there are
52 // other attach operations in flight.
53 class AttachRequest : public Request {
54 public:
55 AttachRequest(GuestViewContainer* container,
56 int guest_instance_id,
57 scoped_ptr<base::DictionaryValue> params,
58 v8::Handle<v8::Function> callback,
59 v8::Isolate* isolate);
60 ~AttachRequest() override;
62 void PerformRequest() override;
63 void HandleResponse(const IPC::Message& message) override;
65 private:
66 const int guest_instance_id_;
67 scoped_ptr<base::DictionaryValue> params_;
70 class DetachRequest : public Request {
71 public:
72 DetachRequest(GuestViewContainer* container,
73 v8::Handle<v8::Function> callback,
74 v8::Isolate* isolate);
75 ~DetachRequest() override;
77 void PerformRequest() override;
78 void HandleResponse(const IPC::Message& message) override;
81 explicit ExtensionsGuestViewContainer(content::RenderFrame* render_frame);
82 ~ExtensionsGuestViewContainer() override;
84 static ExtensionsGuestViewContainer* FromID(int element_instance_id);
86 void IssueRequest(linked_ptr<Request> request);
87 void RegisterDestructionCallback(v8::Handle<v8::Function> callback,
88 v8::Isolate* isolate);
89 void RegisterElementResizeCallback(v8::Handle<v8::Function> callback,
90 v8::Isolate* isolate);
92 // BrowserPluginDelegate implementation.
93 bool OnMessageReceived(const IPC::Message& message) override;
94 void SetElementInstanceID(int element_instance_id) override;
95 void Ready() override;
96 void DidResizeElement(const gfx::Size& old_size,
97 const gfx::Size& new_size) override;
99 private:
100 void OnHandleCallback(const IPC::Message& message);
102 void CallElementResizeCallback(const gfx::Size& old_size,
103 const gfx::Size& new_size);
104 void EnqueueRequest(linked_ptr<Request> request);
105 void PerformPendingRequest();
106 void HandlePendingResponseCallback(const IPC::Message& message);
108 bool ready_;
110 std::deque<linked_ptr<Request> > pending_requests_;
111 linked_ptr<Request> pending_response_;
113 ScopedPersistent<v8::Function> destruction_callback_;
114 v8::Isolate* destruction_isolate_;
116 ScopedPersistent<v8::Function> element_resize_callback_;
117 v8::Isolate* element_resize_isolate_;
119 // Weak pointer factory used for calling the element resize callback.
120 base::WeakPtrFactory<ExtensionsGuestViewContainer> weak_ptr_factory_;
122 DISALLOW_COPY_AND_ASSIGN(ExtensionsGuestViewContainer);
125 } // namespace extensions
127 #endif // EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_