OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_H__ | 5 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_H__ |
6 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_H__ | 6 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_H__ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
12 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
13 #include "content/public/browser/web_contents_delegate.h" | 13 #include "content/public/browser/web_contents_delegate.h" |
14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
15 #include "ppapi/c/pp_instance.h" | 15 #include "ppapi/c/pp_instance.h" |
16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
17 | 17 |
18 class WebContentsImpl; | 18 class WebContentsImpl; |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 class RenderProcessHost; | 22 class RenderProcessHost; |
23 | 23 |
24 // A BrowserPluginHost object is used by both embedders and guests. | 24 // A BrowserPluginHost object is used by both embedders and guests. |
25 // The primary purpose of BrowserPluginHost is to allow an embedder | 25 // The primary purpose of BrowserPluginHost is to allow an embedder |
26 // to manage the lifetime of its guests. It cleans up its guests | 26 // to manage the lifetime of its guests. It cleans up its guests |
27 // on navigation, crashes, and "hides" guests when it hides. | 27 // on navigation, crashes, and "hides" guests when it hides. |
28 // For the guest, BrowserPluginHost keeps track of its embedder, | 28 // For the guest, BrowserPluginHost keeps track of its embedder, |
29 // its BrowserPlugin instance ID, and some initialization state | 29 // and its BrowserPlugin instance ID. |
30 // such as initial size. | |
31 class BrowserPluginHost : public WebContentsObserver, | 30 class BrowserPluginHost : public WebContentsObserver, |
32 public NotificationObserver, | 31 public NotificationObserver, |
33 public WebContentsDelegate { | 32 public WebContentsDelegate { |
34 public: | 33 public: |
35 // BrowserPluginHost is owned by a WebContentsImpl. Here it takes in its | 34 // BrowserPluginHost is owned by a WebContentsImpl. Here it takes in its |
36 // owner. The owner can be either a guest or embedder WebContents. | 35 // owner. The owner can be either a guest or embedder WebContents. |
37 explicit BrowserPluginHost(WebContentsImpl* web_contents); | 36 explicit BrowserPluginHost(WebContentsImpl* web_contents); |
38 | 37 |
39 virtual ~BrowserPluginHost(); | 38 virtual ~BrowserPluginHost(); |
40 | 39 |
41 // TODO(fsamuel): Remove this once BrowserPluginHost_MapInstance | |
42 // is removed. | |
43 void OnPendingNavigation(RenderViewHost* dest_rvh); | |
44 | |
45 void ConnectEmbedderToChannel(RenderViewHost* render_view_host, | 40 void ConnectEmbedderToChannel(RenderViewHost* render_view_host, |
46 const IPC::ChannelHandle& handle); | 41 const IPC::ChannelHandle& handle); |
47 | 42 |
48 // This is called on the first navigation of the browser plugin. It creates | 43 // This is called on the first navigation of the browser plugin. It creates |
49 // a new WebContentsImpl for the guest, associates it with its embedder, sets | 44 // a new WebContentsImpl for the guest, associates it with its embedder, sets |
50 // its size and navigates it to the src URL. | 45 // its size and navigates it to the src URL. |
51 void NavigateGuestFromEmbedder(RenderViewHost* render_view_host, | 46 void NavigateGuestFromEmbedder(RenderViewHost* render_view_host, |
52 int container_instance_id, | 47 int container_instance_id, |
53 long long frame_id, | 48 long long frame_id, |
54 const std::string& src, | 49 const std::string& src); |
55 const gfx::Size& size); | |
56 | 50 |
57 RenderProcessHost* embedder_render_process_host() const { | 51 RenderProcessHost* embedder_render_process_host() const { |
58 return embedder_render_process_host_; | 52 return embedder_render_process_host_; |
59 } | 53 } |
| 54 int instance_id() const { return instance_id_; } |
60 | 55 |
61 private: | 56 private: |
62 typedef std::map<WebContentsImpl*, int64> GuestMap; | 57 typedef std::map<WebContentsImpl*, int64> GuestMap; |
63 typedef std::map<int, BrowserPluginHost*> ContainerInstanceMap; | 58 typedef std::map<int, BrowserPluginHost*> ContainerInstanceMap; |
64 | 59 |
65 // Get a guest BrowserPluginHost by its container ID specified | 60 // Get a guest BrowserPluginHost by its container ID specified |
66 // in BrowserPlugin. | 61 // in BrowserPlugin. |
67 BrowserPluginHost* GetGuestByContainerID(int container_id); | 62 BrowserPluginHost* GetGuestByContainerID(int container_id); |
68 | 63 |
69 // Associate a guest with its container instance ID. | 64 // Associate a guest with its container instance ID. |
70 void RegisterContainerInstance( | 65 void RegisterContainerInstance( |
71 int container_id, | 66 int container_id, |
72 BrowserPluginHost* observer); | 67 BrowserPluginHost* observer); |
73 | 68 |
74 // An embedder BrowserPluginHost keeps track of | 69 // An embedder BrowserPluginHost keeps track of |
75 // its guests so that if it navigates away, its associated RenderView | 70 // its guests so that if it navigates away, its associated RenderView |
76 // crashes or it is hidden, it takes appropriate action on the guest. | 71 // crashes or it is hidden, it takes appropriate action on the guest. |
77 void AddGuest(WebContentsImpl* guest, int64 frame_id); | 72 void AddGuest(WebContentsImpl* guest, int64 frame_id); |
78 | 73 |
79 // This removes a guest from an embedder's guest list. | 74 // This removes a guest from an embedder's guest list. |
80 // TODO(fsamuel): Use this when deleting guest after they crash. | 75 // TODO(fsamuel): Use this when deleting guest after they crash. |
81 // ToT plugin crash handling seems to be broken in this case and so I can't | 76 // ToT plugin crash handling seems to be broken in this case and so I can't |
82 // test this scenario at the moment. Delete this comment once fixed. | 77 // test this scenario at the moment. Delete this comment once fixed. |
83 void RemoveGuest(WebContentsImpl* guest); | 78 void RemoveGuest(WebContentsImpl* guest); |
84 | 79 |
85 void set_embedder_render_process_host( | 80 void set_embedder_render_process_host( |
86 RenderProcessHost* embedder_render_process_host) { | 81 RenderProcessHost* embedder_render_process_host) { |
87 embedder_render_process_host_ = embedder_render_process_host; | 82 embedder_render_process_host_ = embedder_render_process_host; |
88 } | 83 } |
89 int instance_id() const { return instance_id_; } | |
90 void set_instance_id(int instance_id) { instance_id_ = instance_id; } | 84 void set_instance_id(int instance_id) { instance_id_ = instance_id; } |
91 const gfx::Size& initial_size() const { return initial_size_; } | |
92 void set_initial_size(const gfx::Size& size) { initial_size_ = size; } | |
93 RenderViewHost* pending_render_view_host() const { | |
94 return pending_render_view_host_; | |
95 } | |
96 | 85 |
97 void OnNavigateFromGuest(PP_Instance instance, | 86 void OnNavigateFromGuest(PP_Instance instance, |
98 const std::string& src); | 87 const std::string& src); |
99 | 88 |
100 void DestroyGuests(); | 89 void DestroyGuests(); |
101 | 90 |
102 // TODO(fsamuel): Replace BrowserPluginHost_MapInstance with a message | |
103 // over the GuestToEmbedderChannel that tells the guest to size itself | |
104 // and begin compositing. Currently we use the guest's routing ID to look | |
105 // up the appropriate guest in | |
106 // BrowserPluginChannelManager::OnCompleteNavigation. In order to bypass the | |
107 // need to grab a routing ID from the browser process, we can instead pass the | |
108 // container instance ID to the guest on ViewMsg_New. The container instance | |
109 // ID and the embedder channel name can then be used together to uniquely | |
110 // identify a guest RenderViewImpl within a render process. | |
111 void OnMapInstance(int container_instance_id, PP_Instance instance); | |
112 | |
113 // WebContentObserver implementation. | 91 // WebContentObserver implementation. |
114 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 92 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
115 // Used to monitor frame navigation to cleanup guests when a frame navigates | 93 // Used to monitor frame navigation to cleanup guests when a frame navigates |
116 // away from the browser plugin it's hosting. | 94 // away from the browser plugin it's hosting. |
117 virtual void DidCommitProvisionalLoadForFrame( | 95 virtual void DidCommitProvisionalLoadForFrame( |
118 int64 frame_id, | 96 int64 frame_id, |
119 bool is_main_frame, | 97 bool is_main_frame, |
120 const GURL& url, | 98 const GURL& url, |
121 PageTransition transition_type, | 99 PageTransition transition_type, |
122 RenderViewHost* render_view_host) OVERRIDE; | 100 RenderViewHost* render_view_host) OVERRIDE; |
123 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE; | 101 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE; |
124 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | 102 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
125 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE; | 103 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE; |
126 | 104 |
127 // NotificationObserver method override. | 105 // NotificationObserver method override. |
128 virtual void Observe(int type, | 106 virtual void Observe(int type, |
129 const NotificationSource& source, | 107 const NotificationSource& source, |
130 const NotificationDetails& details) OVERRIDE; | 108 const NotificationDetails& details) OVERRIDE; |
131 | 109 |
132 // A scoped container for notification registries. | 110 // A scoped container for notification registries. |
133 NotificationRegistrar registrar_; | 111 NotificationRegistrar registrar_; |
134 RenderProcessHost* embedder_render_process_host_; | 112 RenderProcessHost* embedder_render_process_host_; |
135 // An identifier that uniquely identifies a browser plugin container | 113 // An identifier that uniquely identifies a browser plugin container |
136 // within an embedder. | 114 // within an embedder. |
137 int instance_id_; | 115 int instance_id_; |
138 gfx::Size initial_size_; | 116 gfx::Size initial_size_; |
139 GuestMap guests_; | 117 GuestMap guests_; |
140 ContainerInstanceMap guests_by_container_id_; | 118 ContainerInstanceMap guests_by_container_id_; |
141 // TODO(fsamuel): This should not be exposed outside of WebContentsImpl | |
142 // because this can change at any time. Remove this, along with | |
143 // OnPendingNavigation once BrowserPluginHost_MapInstance is modified | |
144 // to be sent over the GuestToEmbedderChannel directly instead of through | |
145 // the browser process. | |
146 RenderViewHost* pending_render_view_host_; | |
147 }; | 119 }; |
148 | 120 |
149 } // namespace content | 121 } // namespace content |
150 | 122 |
151 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_H_ | 123 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_H_ |
OLD | NEW |