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 #include "content/browser/browser_plugin/browser_plugin_host_embedder_delegate.h " | |
6 | |
7 #include "base/time.h" | |
8 #include "content/browser/browser_plugin/browser_plugin_host_guest_delegate.h" | |
9 #include "content/browser/browser_plugin/browser_plugin_host_guest_role.h" | |
10 #include "content/browser/renderer_host/render_view_host_impl.h" | |
11 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
12 #include "content/browser/web_contents/web_contents_impl.h" | |
13 #include "content/common/browser_plugin_messages.h" | |
14 #include "content/common/view_messages.h" | |
15 #include "content/public/browser/render_process_host.h" | |
16 #include "content/public/browser/render_view_host.h" | |
17 #include "content/public/browser/render_widget_host_view.h" | |
18 #include "content/public/browser/web_contents_observer.h" | |
19 #include "content/public/browser/web_contents_view.h" | |
20 #include "content/public/common/url_constants.h" | |
21 #include "ui/gfx/size.h" | |
22 | |
23 namespace content { | |
24 | |
25 BrowserPluginHostEmbedderDelegate::BrowserPluginHostEmbedderDelegate( | |
26 WebContentsImpl* web_contents) : WebContentsObserver(web_contents) { | |
27 } | |
28 | |
29 BrowserPluginHostEmbedderDelegate::~BrowserPluginHostEmbedderDelegate() { | |
30 } | |
31 | |
32 BrowserPluginHostGuestDelegate* BrowserPluginHostEmbedderDelegate:: | |
33 GetGuestByInstanceID(int instance_id) const { | |
34 ContainerInstanceMap::const_iterator it = | |
35 guests_by_instance_id_.find(instance_id); | |
36 if (it != guests_by_instance_id_.end()) | |
37 return it->second; | |
38 return NULL; | |
39 } | |
40 | |
41 void BrowserPluginHostEmbedderDelegate::AddGuest(int instance_id, | |
42 BrowserPluginHostGuestDelegate* guest, | |
43 int64 frame_id) { | |
44 DCHECK(guests_by_instance_id_.find(instance_id) == | |
45 guests_by_instance_id_.end()); | |
46 guests_by_instance_id_[instance_id] = guest; | |
47 guests_[guest->web_contents()] = frame_id; | |
48 } | |
49 | |
50 void BrowserPluginHostEmbedderDelegate::NavigateGuest( | |
51 RenderViewHost* render_view_host, | |
52 int instance_id, | |
53 int64 frame_id, | |
54 const std::string& src, | |
55 const gfx::Size& size) { | |
56 BrowserPluginHostGuestDelegate* guest = GetGuestByInstanceID(instance_id); | |
57 WebContentsImpl* guest_web_contents = NULL; | |
58 GURL url(src); | |
59 if (!guest) { | |
60 // The SiteInstance of a given guest is based on the fact that it's a guest | |
61 // in addition to which platform application the guest belongs to, rather | |
62 // than the URL that the guest is being navigated to. | |
63 std::string host = render_view_host->GetSiteInstance()->GetSite().host(); | |
64 GURL guest_site( | |
65 base::StringPrintf("%s://%s", chrome::kGuestScheme, host.c_str())); | |
66 SiteInstance* guest_site_instance = | |
67 SiteInstance::CreateForURL(web_contents()->GetBrowserContext(), | |
68 guest_site); | |
69 guest_web_contents = | |
70 static_cast<WebContentsImpl*>( | |
71 WebContents::Create(web_contents()->GetBrowserContext(), | |
72 guest_site_instance, | |
73 MSG_ROUTING_NONE, | |
74 NULL, // base WebContents | |
75 NULL // session storage namespace | |
76 )); | |
77 | |
78 BrowserPluginHostGuestRole* guest_role = guest_web_contents->AddGuestRole( | |
79 instance_id, | |
80 render_view_host->GetProcess()); | |
81 guest = guest_role->GetDelegate(); | |
82 guest->set_embedder_render_process_host( | |
83 render_view_host->GetProcess()); | |
84 | |
85 guest_web_contents->GetMutableRendererPrefs()-> | |
86 throttle_input_events = false; | |
87 AddGuest(instance_id, guest, frame_id); | |
88 } else { | |
89 guest_web_contents = static_cast<WebContentsImpl*>(guest->web_contents()); | |
90 } | |
91 guest->web_contents()->SetDelegate(guest); | |
92 guest->web_contents()->GetController().LoadURL(url, | |
93 Referrer(), | |
94 PAGE_TRANSITION_AUTO_SUBFRAME, | |
95 std::string()); | |
96 if (!size.IsEmpty()) | |
97 guest_web_contents->GetView()->SizeContents(size); | |
98 } | |
99 | |
100 void BrowserPluginHostEmbedderDelegate::UpdateRectACK(int instance_id, | |
101 int message_id, | |
rjkroege
2012/08/22 21:57:38
one space off. shove over.
lazyboy
2012/08/23 00:45:22
Done.
| |
102 const gfx::Size& size) { | |
103 BrowserPluginHostGuestDelegate* guest = GetGuestByInstanceID(instance_id); | |
104 if (guest) { | |
105 guest->UpdateRectACK(message_id, size); | |
106 } | |
107 } | |
108 | |
109 void BrowserPluginHostEmbedderDelegate::ResizeGuest(int instance_id, | |
110 TransportDIB* damage_buffer, | |
111 int width, | |
112 int height, | |
113 bool resize_pending, | |
114 float scale_factor) { | |
115 BrowserPluginHostGuestDelegate* guest = GetGuestByInstanceID(instance_id); | |
116 if (!guest) | |
117 return; | |
118 WebContentsImpl* guest_web_contents = | |
119 static_cast<WebContentsImpl*>(guest->web_contents()); | |
120 guest->SetDamageBuffer(damage_buffer, gfx::Size(width, height), scale_factor); | |
121 if (!resize_pending) | |
122 guest_web_contents->GetView()->SizeContents(gfx::Size(width, height)); | |
123 } | |
124 | |
125 void BrowserPluginHostEmbedderDelegate::SetFocus(int instance_id, | |
126 bool focused) { | |
127 BrowserPluginHostGuestDelegate* guest = GetGuestByInstanceID(instance_id); | |
128 if (guest) { | |
129 guest->SetFocus(focused); | |
130 } | |
131 } | |
132 | |
133 void BrowserPluginHostEmbedderDelegate::DestroyGuests() { | |
134 for (GuestMap::const_iterator it = guests_.begin(); | |
135 it != guests_.end(); ++it) { | |
136 WebContents* web_contents = it->first; | |
137 delete web_contents; | |
138 } | |
139 guests_.clear(); | |
140 guests_by_instance_id_.clear(); | |
141 } | |
142 | |
143 void BrowserPluginHostEmbedderDelegate::HandleInputEvent( | |
144 int instance_id, | |
145 RenderViewHost* render_view_host, | |
146 const gfx::Rect& guest_rect, | |
147 const WebKit::WebInputEvent& event, | |
148 IPC::Message* reply_message) { | |
149 BrowserPluginHostGuestDelegate* guest = GetGuestByInstanceID(instance_id); | |
150 if (guest) { | |
151 guest->HandleInputEvent(render_view_host, guest_rect, event, reply_message); | |
152 } | |
153 } | |
154 | |
155 void BrowserPluginHostEmbedderDelegate::DestroyGuestByInstanceID( | |
156 int instance_id) { | |
157 BrowserPluginHostGuestDelegate* guest = GetGuestByInstanceID(instance_id); | |
158 if (guest) { | |
159 WebContents* guest_web_contents = guest->web_contents(); | |
160 | |
161 GuestMap::iterator guest_it = guests_.find(guest_web_contents); | |
162 DCHECK(guest_it != guests_.end()); | |
163 | |
164 guests_.erase(guest_it); | |
165 guests_by_instance_id_.erase(instance_id); | |
166 | |
167 guest->Destroy(); | |
168 } | |
169 } | |
170 | |
171 void BrowserPluginHostEmbedderDelegate::DidCommitProvisionalLoadForFrame( | |
172 int64 frame_id, | |
173 bool is_main_frame, | |
174 const GURL& url, | |
175 PageTransition transition_type, | |
176 RenderViewHost* render_view_host) { | |
177 // Clean-up guests that lie in the frame that we're navigating. | |
178 typedef std::set<WebContents*> GuestSet; | |
179 GuestSet guests_to_delete; | |
180 for (GuestMap::const_iterator it = guests_.begin(); | |
181 it != guests_.end(); ++it) { | |
182 WebContents* web_contents = it->first; | |
183 if (it->second == frame_id) { | |
184 // TODO(lazyboy): If we allow browser tags to be nested, we need to take | |
185 // care of subframes inside this frame as well. | |
186 guests_to_delete.insert(web_contents); | |
187 } | |
188 } | |
189 for (GuestSet::const_iterator it = guests_to_delete.begin(); | |
190 it != guests_to_delete.end(); ++it) { | |
191 int instance_id = static_cast<WebContentsImpl*>(*it)->GetGuestRole()-> | |
192 GetDelegate()->instance_id(); | |
193 DestroyGuestByInstanceID(instance_id); | |
194 } | |
195 } | |
196 | |
197 void BrowserPluginHostEmbedderDelegate::RenderViewDeleted( | |
198 RenderViewHost* render_view_host) { | |
199 DestroyGuests(); | |
200 } | |
201 | |
202 void BrowserPluginHostEmbedderDelegate::RenderViewGone( | |
203 base::TerminationStatus status) { | |
204 DestroyGuests(); | |
205 } | |
206 | |
207 void BrowserPluginHostEmbedderDelegate::WebContentsVisiblitlyChanged( | |
208 bool visible) { | |
209 // If the embedder is hidden we need to hide the guests as well. | |
210 for (GuestMap::const_iterator it = guests_.begin(); | |
211 it != guests_.end(); ++it) { | |
212 WebContents* web_contents = it->first; | |
213 if (visible) | |
214 web_contents->WasShown(); | |
215 else | |
216 web_contents->WasHidden(); | |
217 } | |
218 } | |
219 | |
220 void BrowserPluginHostEmbedderDelegate::PluginDestroyed( | |
221 int instance_id) { | |
222 DestroyGuestByInstanceID(instance_id); | |
223 } | |
224 | |
225 } // namespace content | |
OLD | NEW |