OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_ | 5 #ifndef EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_ |
6 #define EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_ | 6 #define EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "extensions/renderer/guest_view/guest_view_container.h" | 13 #include "extensions/renderer/guest_view/guest_view_container.h" |
14 #include "extensions/renderer/scoped_persistent.h" | 14 #include "extensions/renderer/scoped_persistent.h" |
15 | 15 |
16 namespace extensions { | 16 namespace extensions { |
17 | 17 |
18 class ExtensionsGuestViewContainer : public GuestViewContainer { | 18 class ExtensionsGuestViewContainer : public GuestViewContainer { |
19 public: | 19 public: |
20 // This class represents an AttachGuest request from Javascript. It includes | 20 |
21 // the input parameters and the callback function. The Attach operation may | 21 class Request { |
22 // not execute immediately, if the container is not ready or if there are | |
23 // other attach operations in flight. | |
24 class AttachRequest { | |
25 public: | 22 public: |
26 AttachRequest(int element_instance_id, | 23 Request(GuestViewContainer* container, |
27 int guest_instance_id, | 24 v8::Handle<v8::Function> callback, |
28 scoped_ptr<base::DictionaryValue> params, | 25 v8::Isolate* isolate); |
29 v8::Handle<v8::Function> callback, | 26 virtual ~Request(); |
30 v8::Isolate* isolate); | |
31 ~AttachRequest(); | |
32 | 27 |
33 int element_instance_id() const { return element_instance_id_; } | 28 virtual void PerformRequest() = 0; |
| 29 virtual void HandleResponse(const IPC::Message& message) = 0; |
34 | 30 |
35 int guest_instance_id() const { return guest_instance_id_; } | 31 GuestViewContainer* container() const { return container_; } |
36 | |
37 base::DictionaryValue* attach_params() const { | |
38 return params_.get(); | |
39 } | |
40 | 32 |
41 bool HasCallback() const; | 33 bool HasCallback() const; |
42 | 34 |
43 v8::Handle<v8::Function> GetCallback() const; | 35 v8::Handle<v8::Function> GetCallback() const; |
44 | 36 |
45 v8::Isolate* isolate() const { return isolate_; } | 37 v8::Isolate* isolate() const { return isolate_; } |
46 | 38 |
47 private: | 39 private: |
48 const int element_instance_id_; | 40 GuestViewContainer* container_; |
| 41 ScopedPersistent<v8::Function> callback_; |
| 42 v8::Isolate* const isolate_; |
| 43 }; |
| 44 |
| 45 // This class represents an AttachGuest request from Javascript. It includes |
| 46 // the input parameters and the callback function. The Attach operation may |
| 47 // not execute immediately, if the container is not ready or if there are |
| 48 // other attach operations in flight. |
| 49 class AttachRequest : public Request { |
| 50 public: |
| 51 AttachRequest(GuestViewContainer* container, |
| 52 int guest_instance_id, |
| 53 scoped_ptr<base::DictionaryValue> params, |
| 54 v8::Handle<v8::Function> callback, |
| 55 v8::Isolate* isolate); |
| 56 ~AttachRequest() override; |
| 57 |
| 58 void PerformRequest() override; |
| 59 void HandleResponse(const IPC::Message& message) override; |
| 60 |
| 61 private: |
49 const int guest_instance_id_; | 62 const int guest_instance_id_; |
50 scoped_ptr<base::DictionaryValue> params_; | 63 scoped_ptr<base::DictionaryValue> params_; |
51 ScopedPersistent<v8::Function> callback_; | |
52 v8::Isolate* const isolate_; | |
53 }; | 64 }; |
54 | 65 |
55 explicit ExtensionsGuestViewContainer(content::RenderFrame* render_frame); | 66 explicit ExtensionsGuestViewContainer(content::RenderFrame* render_frame); |
56 ~ExtensionsGuestViewContainer() override; | 67 ~ExtensionsGuestViewContainer() override; |
57 | 68 |
58 static ExtensionsGuestViewContainer* FromID(int render_view_routing_id, | 69 static ExtensionsGuestViewContainer* FromID(int element_instance_id); |
59 int element_instance_id); | |
60 | 70 |
61 void AttachGuest(linked_ptr<AttachRequest> request); | 71 void IssueRequest(linked_ptr<Request> request); |
62 | 72 |
63 // BrowserPluginDelegate implementation. | 73 // BrowserPluginDelegate implementation. |
64 void SetElementInstanceID(int element_instance_id) override; | 74 void SetElementInstanceID(int element_instance_id) override; |
65 void Ready() override; | 75 void Ready() override; |
66 | 76 |
67 // GuestViewContainer override. | 77 // GuestViewContainer override. |
68 bool HandlesMessage(const IPC::Message& message) override; | 78 bool HandlesMessage(const IPC::Message& message) override; |
69 bool OnMessage(const IPC::Message& message) override; | 79 bool OnMessage(const IPC::Message& message) override; |
70 | 80 |
71 private: | 81 private: |
72 void OnGuestAttached(int element_instance_id, | 82 void OnHandleCallback(const IPC::Message& message); |
73 int guest_proxy_routing_id); | |
74 | 83 |
75 void AttachGuestInternal(linked_ptr<AttachRequest> request); | 84 void EnqueueRequest(linked_ptr<Request> request); |
76 void EnqueueAttachRequest(linked_ptr<AttachRequest> request); | 85 void PerformPendingRequest(); |
77 void PerformPendingAttachRequest(); | 86 void HandlePendingResponseCallback(const IPC::Message& message); |
78 void HandlePendingResponseCallback(int guest_proxy_routing_id); | |
79 | 87 |
80 bool ready_; | 88 bool ready_; |
81 | 89 |
82 std::deque<linked_ptr<AttachRequest> > pending_requests_; | 90 std::deque<linked_ptr<Request> > pending_requests_; |
83 linked_ptr<AttachRequest> pending_response_; | 91 linked_ptr<Request> pending_response_; |
84 | 92 |
85 DISALLOW_COPY_AND_ASSIGN(ExtensionsGuestViewContainer); | 93 DISALLOW_COPY_AND_ASSIGN(ExtensionsGuestViewContainer); |
86 }; | 94 }; |
87 | 95 |
88 } // namespace extensions | 96 } // namespace extensions |
89 | 97 |
90 #endif // EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_ | 98 #endif // EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_ |
OLD | NEW |