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 | 12 |
13 namespace guest_view { | 13 namespace guest_view { |
14 | 14 |
15 class GuestViewRequest; | 15 class GuestViewRequest; |
16 | 16 |
17 class GuestViewContainer : public content::BrowserPluginDelegate { | 17 class GuestViewContainer : public content::BrowserPluginDelegate { |
18 public: | 18 public: |
19 explicit GuestViewContainer(content::RenderFrame* render_frame); | 19 explicit GuestViewContainer(content::RenderFrame* render_frame); |
20 ~GuestViewContainer() override; | |
21 | 20 |
22 static GuestViewContainer* FromID(int element_instance_id); | 21 static GuestViewContainer* FromID(int element_instance_id); |
23 | 22 |
24 // IssueRequest queues up a |request| until the container is ready and | 23 // IssueRequest queues up a |request| until the container is ready and |
25 // the browser process has responded to the last request if it's still | 24 // the browser process has responded to the last request if it's still |
26 // pending. | 25 // pending. |
27 void IssueRequest(linked_ptr<GuestViewRequest> request); | 26 void IssueRequest(linked_ptr<GuestViewRequest> request); |
28 | 27 |
29 int element_instance_id() const { return element_instance_id_; } | 28 int element_instance_id() const { return element_instance_id_; } |
30 content::RenderFrame* render_frame() const { return render_frame_; } | 29 content::RenderFrame* render_frame() const { return render_frame_; } |
31 | 30 |
32 // Called by GuestViewContainerDispatcher to dispatch message to this | 31 // Called by GuestViewContainerDispatcher to dispatch message to this |
33 // container. | 32 // container. |
34 bool OnMessageReceived(const IPC::Message& message); | 33 bool OnMessageReceived(const IPC::Message& message); |
35 | 34 |
| 35 // Destroys this GuestViewContainer after performing necessary cleanup. |
| 36 void Destroy(); |
| 37 |
36 // Called when the embedding RenderFrame is destroyed. | 38 // Called when the embedding RenderFrame is destroyed. |
37 virtual void OnRenderFrameDestroyed() {} | 39 virtual void OnRenderFrameDestroyed() {} |
38 | 40 |
39 // Called to respond to IPCs from the browser process that have not been | 41 // Called to respond to IPCs from the browser process that have not been |
40 // handled by GuestViewContainer. | 42 // handled by GuestViewContainer. |
41 virtual bool OnMessage(const IPC::Message& message); | 43 virtual bool OnMessage(const IPC::Message& message); |
42 | 44 |
43 // Called to perform actions when a GuestViewContainer gets a geometry. | 45 // Called to perform actions when a GuestViewContainer gets a geometry. |
44 virtual void OnReady() {} | 46 virtual void OnReady() {} |
45 | 47 |
| 48 // Called to perform actions when a GuestViewContainer is about to be |
| 49 // destroyed. |
| 50 // Note that this should be called exactly once. |
| 51 virtual void OnDestroy() {} |
| 52 |
| 53 protected: |
| 54 ~GuestViewContainer() override; |
| 55 |
46 private: | 56 private: |
47 class RenderFrameLifetimeObserver; | 57 class RenderFrameLifetimeObserver; |
48 friend class RenderFrameLifetimeObserver; | 58 friend class RenderFrameLifetimeObserver; |
49 | 59 |
50 void RenderFrameDestroyed(); | 60 void RenderFrameDestroyed(); |
51 | 61 |
52 void EnqueueRequest(linked_ptr<GuestViewRequest> request); | 62 void EnqueueRequest(linked_ptr<GuestViewRequest> request); |
53 void PerformPendingRequest(); | 63 void PerformPendingRequest(); |
54 void HandlePendingResponseCallback(const IPC::Message& message); | 64 void HandlePendingResponseCallback(const IPC::Message& message); |
55 | 65 |
56 void OnHandleCallback(const IPC::Message& message); | 66 void OnHandleCallback(const IPC::Message& message); |
57 | 67 |
58 // BrowserPluginDelegate implementation. | 68 // BrowserPluginDelegate implementation. |
59 void Ready() final; | 69 void Ready() final; |
60 void SetElementInstanceID(int element_instance_id) final; | 70 void SetElementInstanceID(int element_instance_id) final; |
| 71 void DidDestroyElement() final; |
61 | 72 |
62 int element_instance_id_; | 73 int element_instance_id_; |
63 content::RenderFrame* render_frame_; | 74 content::RenderFrame* render_frame_; |
64 scoped_ptr<RenderFrameLifetimeObserver> render_frame_lifetime_observer_; | 75 scoped_ptr<RenderFrameLifetimeObserver> render_frame_lifetime_observer_; |
65 | 76 |
66 bool ready_; | 77 bool ready_; |
| 78 bool in_destruction_; |
67 | 79 |
68 std::deque<linked_ptr<GuestViewRequest> > pending_requests_; | 80 std::deque<linked_ptr<GuestViewRequest> > pending_requests_; |
69 linked_ptr<GuestViewRequest> pending_response_; | 81 linked_ptr<GuestViewRequest> pending_response_; |
70 | 82 |
71 DISALLOW_COPY_AND_ASSIGN(GuestViewContainer); | 83 DISALLOW_COPY_AND_ASSIGN(GuestViewContainer); |
72 }; | 84 }; |
73 | 85 |
74 } // namespace guest_view | 86 } // namespace guest_view |
75 | 87 |
76 #endif // COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_ | 88 #endif // COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_ |
OLD | NEW |