| 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 COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_ | 5 #ifndef COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_ |
| 6 #define COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_ | 6 #define COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_ |
| 7 | 7 |
| 8 #include "base/memory/linked_ptr.h" | 8 #include "base/memory/linked_ptr.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/public/renderer/browser_plugin_delegate.h" | 10 #include "content/public/renderer/browser_plugin_delegate.h" |
| 11 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
| 12 #include "v8/include/v8.h" |
| 12 | 13 |
| 13 namespace guest_view { | 14 namespace guest_view { |
| 14 | 15 |
| 15 class GuestViewRequest; | 16 class GuestViewRequest; |
| 16 | 17 |
| 17 class GuestViewContainer : public content::BrowserPluginDelegate { | 18 class GuestViewContainer : public content::BrowserPluginDelegate { |
| 18 public: | 19 public: |
| 19 explicit GuestViewContainer(content::RenderFrame* render_frame); | 20 explicit GuestViewContainer(content::RenderFrame* render_frame); |
| 20 | 21 |
| 21 static GuestViewContainer* FromID(int element_instance_id); | 22 static GuestViewContainer* FromID(int element_instance_id); |
| 22 | 23 |
| 23 // IssueRequest queues up a |request| until the container is ready and | 24 // IssueRequest queues up a |request| until the container is ready and |
| 24 // the browser process has responded to the last request if it's still | 25 // the browser process has responded to the last request if it's still |
| 25 // pending. | 26 // pending. |
| 26 void IssueRequest(linked_ptr<GuestViewRequest> request); | 27 void IssueRequest(linked_ptr<GuestViewRequest> request); |
| 27 | 28 |
| 28 int element_instance_id() const { return element_instance_id_; } | 29 int element_instance_id() const { return element_instance_id_; } |
| 29 content::RenderFrame* render_frame() const { return render_frame_; } | 30 content::RenderFrame* render_frame() const { return render_frame_; } |
| 30 | 31 |
| 31 // Called by GuestViewContainerDispatcher to dispatch message to this | 32 // Called by GuestViewContainerDispatcher to dispatch message to this |
| 32 // container. | 33 // container. |
| 33 bool OnMessageReceived(const IPC::Message& message); | 34 bool OnMessageReceived(const IPC::Message& message); |
| 34 | 35 |
| 35 // Destroys this GuestViewContainer after performing necessary cleanup. | 36 // Destroys this GuestViewContainer after performing necessary cleanup. |
| 36 // |embedder_frame_destroyed| is true if this destruction is due to the | 37 // |embedder_frame_destroyed| is true if this destruction is due to the |
| 37 // embedding frame of the container being destroyed. | 38 // embedding frame of the container being destroyed. |
| 38 void Destroy(bool embedder_frame_destroyed); | 39 void Destroy(bool embedder_frame_destroyed); |
| 39 | 40 |
| 41 void RegisterDestructionCallback(v8::Local<v8::Function> callback, |
| 42 v8::Isolate* isolate); |
| 43 |
| 40 // Called when the embedding RenderFrame is destroyed. | 44 // Called when the embedding RenderFrame is destroyed. |
| 41 virtual void OnRenderFrameDestroyed() {} | 45 virtual void OnRenderFrameDestroyed() {} |
| 42 | 46 |
| 43 // Called to respond to IPCs from the browser process that have not been | 47 // Called to respond to IPCs from the browser process that have not been |
| 44 // handled by GuestViewContainer. | 48 // handled by GuestViewContainer. |
| 45 virtual bool OnMessage(const IPC::Message& message); | 49 virtual bool OnMessage(const IPC::Message& message); |
| 46 | 50 |
| 47 // Called to perform actions when a GuestViewContainer gets a geometry. | 51 // Called to perform actions when a GuestViewContainer gets a geometry. |
| 48 virtual void OnReady() {} | 52 virtual void OnReady() {} |
| 49 | 53 |
| 50 // Called to perform actions when a GuestViewContainer is about to be | 54 // Called to perform actions when a GuestViewContainer is about to be |
| 51 // destroyed. | 55 // destroyed. |
| 52 // Note that this should be called exactly once. | 56 // Note that this should be called exactly once. |
| 53 virtual void OnDestroy(bool embedder_frame_destroyed) {} | 57 virtual void OnDestroy(bool embedder_frame_destroyed) {} |
| 54 | 58 |
| 59 // BrowserPluginGuestDelegate public implementation. |
| 60 void SetElementInstanceID(int element_instance_id) final; |
| 61 |
| 55 protected: | 62 protected: |
| 56 ~GuestViewContainer() override; | 63 ~GuestViewContainer() override; |
| 57 | 64 |
| 65 bool ready_; |
| 66 |
| 67 void OnHandleCallback(const IPC::Message& message); |
| 68 |
| 58 private: | 69 private: |
| 59 class RenderFrameLifetimeObserver; | 70 class RenderFrameLifetimeObserver; |
| 60 friend class RenderFrameLifetimeObserver; | 71 friend class RenderFrameLifetimeObserver; |
| 61 | 72 |
| 62 void RenderFrameDestroyed(); | 73 void RenderFrameDestroyed(); |
| 63 | 74 |
| 64 void EnqueueRequest(linked_ptr<GuestViewRequest> request); | 75 void EnqueueRequest(linked_ptr<GuestViewRequest> request); |
| 65 void PerformPendingRequest(); | 76 void PerformPendingRequest(); |
| 66 void HandlePendingResponseCallback(const IPC::Message& message); | 77 void HandlePendingResponseCallback(const IPC::Message& message); |
| 67 | 78 void RunDestructionCallback(bool embedder_frame_destroyed); |
| 68 void OnHandleCallback(const IPC::Message& message); | |
| 69 | 79 |
| 70 // BrowserPluginDelegate implementation. | 80 // BrowserPluginDelegate implementation. |
| 71 void Ready() final; | 81 void Ready() final; |
| 72 void SetElementInstanceID(int element_instance_id) final; | |
| 73 void DidDestroyElement() final; | 82 void DidDestroyElement() final; |
| 74 base::WeakPtr<BrowserPluginDelegate> GetWeakPtr() final; | 83 base::WeakPtr<BrowserPluginDelegate> GetWeakPtr() final; |
| 75 | 84 |
| 76 int element_instance_id_; | 85 int element_instance_id_; |
| 77 content::RenderFrame* render_frame_; | 86 content::RenderFrame* render_frame_; |
| 78 scoped_ptr<RenderFrameLifetimeObserver> render_frame_lifetime_observer_; | 87 scoped_ptr<RenderFrameLifetimeObserver> render_frame_lifetime_observer_; |
| 79 | 88 |
| 80 bool ready_; | |
| 81 bool in_destruction_; | 89 bool in_destruction_; |
| 82 | 90 |
| 83 std::deque<linked_ptr<GuestViewRequest> > pending_requests_; | 91 std::deque<linked_ptr<GuestViewRequest> > pending_requests_; |
| 84 linked_ptr<GuestViewRequest> pending_response_; | 92 linked_ptr<GuestViewRequest> pending_response_; |
| 85 | 93 |
| 94 v8::Global<v8::Function> destruction_callback_; |
| 95 v8::Isolate* destruction_isolate_; |
| 96 |
| 86 base::WeakPtrFactory<GuestViewContainer> weak_ptr_factory_; | 97 base::WeakPtrFactory<GuestViewContainer> weak_ptr_factory_; |
| 87 | 98 |
| 88 DISALLOW_COPY_AND_ASSIGN(GuestViewContainer); | 99 DISALLOW_COPY_AND_ASSIGN(GuestViewContainer); |
| 89 }; | 100 }; |
| 90 | 101 |
| 91 } // namespace guest_view | 102 } // namespace guest_view |
| 92 | 103 |
| 93 #endif // COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_ | 104 #endif // COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_ |
| OLD | NEW |