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