| 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 |
| 21 // the input parameters and the callback function. The Attach operation may |
| 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: |
| 26 AttachRequest(int element_instance_id, |
| 27 int guest_instance_id, |
| 28 scoped_ptr<base::DictionaryValue> params, |
| 29 v8::Handle<v8::Function> callback, |
| 30 v8::Isolate* isolate); |
| 31 ~AttachRequest(); |
| 20 | 32 |
| 21 class Request { | 33 int element_instance_id() const { return element_instance_id_; } |
| 22 public: | |
| 23 Request(GuestViewContainer* container, | |
| 24 v8::Handle<v8::Function> callback, | |
| 25 v8::Isolate* isolate); | |
| 26 virtual ~Request(); | |
| 27 | 34 |
| 28 virtual void PerformRequest() = 0; | 35 int guest_instance_id() const { return guest_instance_id_; } |
| 29 virtual void HandleResponse(const IPC::Message& message) = 0; | |
| 30 | 36 |
| 31 GuestViewContainer* container() const { return container_; } | 37 base::DictionaryValue* attach_params() const { |
| 38 return params_.get(); |
| 39 } |
| 32 | 40 |
| 33 bool HasCallback() const; | 41 bool HasCallback() const; |
| 34 | 42 |
| 35 v8::Handle<v8::Function> GetCallback() const; | 43 v8::Handle<v8::Function> GetCallback() const; |
| 36 | 44 |
| 37 v8::Isolate* isolate() const { return isolate_; } | 45 v8::Isolate* isolate() const { return isolate_; } |
| 38 | 46 |
| 39 private: | 47 private: |
| 40 GuestViewContainer* container_; | 48 const int element_instance_id_; |
| 49 const int guest_instance_id_; |
| 50 scoped_ptr<base::DictionaryValue> params_; |
| 41 ScopedPersistent<v8::Function> callback_; | 51 ScopedPersistent<v8::Function> callback_; |
| 42 v8::Isolate* const isolate_; | 52 v8::Isolate* const isolate_; |
| 43 }; | 53 }; |
| 44 | 54 |
| 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: | |
| 62 const int guest_instance_id_; | |
| 63 scoped_ptr<base::DictionaryValue> params_; | |
| 64 }; | |
| 65 | |
| 66 explicit ExtensionsGuestViewContainer(content::RenderFrame* render_frame); | 55 explicit ExtensionsGuestViewContainer(content::RenderFrame* render_frame); |
| 67 ~ExtensionsGuestViewContainer() override; | 56 ~ExtensionsGuestViewContainer() override; |
| 68 | 57 |
| 69 static ExtensionsGuestViewContainer* FromID(int element_instance_id); | 58 static ExtensionsGuestViewContainer* FromID(int render_view_routing_id, |
| 59 int element_instance_id); |
| 70 | 60 |
| 71 void IssueRequest(linked_ptr<Request> request); | 61 void AttachGuest(linked_ptr<AttachRequest> request); |
| 72 | 62 |
| 73 // BrowserPluginDelegate implementation. | 63 // BrowserPluginDelegate implementation. |
| 74 void SetElementInstanceID(int element_instance_id) override; | 64 void SetElementInstanceID(int element_instance_id) override; |
| 75 void Ready() override; | 65 void Ready() override; |
| 76 | 66 |
| 77 // GuestViewContainer override. | 67 // GuestViewContainer override. |
| 78 bool HandlesMessage(const IPC::Message& message) override; | 68 bool HandlesMessage(const IPC::Message& message) override; |
| 79 bool OnMessage(const IPC::Message& message) override; | 69 bool OnMessage(const IPC::Message& message) override; |
| 80 | 70 |
| 81 private: | 71 private: |
| 82 void OnHandleCallback(const IPC::Message& message); | 72 void OnGuestAttached(int element_instance_id, |
| 73 int guest_proxy_routing_id); |
| 83 | 74 |
| 84 void EnqueueRequest(linked_ptr<Request> request); | 75 void AttachGuestInternal(linked_ptr<AttachRequest> request); |
| 85 void PerformPendingRequest(); | 76 void EnqueueAttachRequest(linked_ptr<AttachRequest> request); |
| 86 void HandlePendingResponseCallback(const IPC::Message& message); | 77 void PerformPendingAttachRequest(); |
| 78 void HandlePendingResponseCallback(int guest_proxy_routing_id); |
| 87 | 79 |
| 88 bool ready_; | 80 bool ready_; |
| 89 | 81 |
| 90 std::deque<linked_ptr<Request> > pending_requests_; | 82 std::deque<linked_ptr<AttachRequest> > pending_requests_; |
| 91 linked_ptr<Request> pending_response_; | 83 linked_ptr<AttachRequest> pending_response_; |
| 92 | 84 |
| 93 DISALLOW_COPY_AND_ASSIGN(ExtensionsGuestViewContainer); | 85 DISALLOW_COPY_AND_ASSIGN(ExtensionsGuestViewContainer); |
| 94 }; | 86 }; |
| 95 | 87 |
| 96 } // namespace extensions | 88 } // namespace extensions |
| 97 | 89 |
| 98 #endif // EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_ | 90 #endif // EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_ |
| OLD | NEW |