Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: content/browser/browser_plugin/browser_plugin_embedder.cc

Issue 10868012: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-trial-obrowser
Patch Set: Rename class as we agreed upon, keep correct type of instances (guest/embedder, not helpers) inside… Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_embedder.h"
6
7 #include "base/time.h"
8 #include "content/browser/browser_plugin/browser_plugin_embedder_helper.h"
9 #include "content/browser/browser_plugin/browser_plugin_guest.h"
10 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h"
11 #include "content/browser/renderer_host/render_view_host_impl.h"
12 #include "content/browser/renderer_host/render_widget_host_impl.h"
13 #include "content/browser/web_contents/web_contents_impl.h"
14 #include "content/common/browser_plugin_messages.h"
15 #include "content/common/view_messages.h"
16 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/render_widget_host_view.h"
19 #include "content/public/browser/web_contents_observer.h"
20 #include "content/public/browser/web_contents_view.h"
21 #include "content/public/common/url_constants.h"
22 #include "ui/gfx/size.h"
23
24 namespace content {
25
26 BrowserPluginEmbedder::BrowserPluginEmbedder(
27 WebContentsImpl* web_contents,
28 RenderViewHost* render_view_host)
29 : WebContentsObserver(web_contents) {
30 new BrowserPluginEmbedderHelper(this, web_contents, render_view_host);
Fady Samuel 2012/08/25 05:28:32 The helpers are not being created in the correct s
31 }
32
33 BrowserPluginEmbedder::~BrowserPluginEmbedder() {
34 }
35
36 BrowserPluginGuest* BrowserPluginEmbedder:: GetGuestByInstanceID(
37 int instance_id) const {
38 ContainerInstanceMap::const_iterator it =
39 guests_by_instance_id_.find(instance_id);
40 if (it != guests_by_instance_id_.end())
41 return it->second;
42 return NULL;
43 }
44
45 void BrowserPluginEmbedder::AddGuest(int instance_id,
46 BrowserPluginGuest* guest,
47 int64 frame_id) {
48 DCHECK(guests_by_instance_id_.find(instance_id) ==
Charlie Reis 2012/08/27 20:23:59 nit: DCHECK_EQ Should we make this a CHECK_EQ?
lazyboy 2012/08/28 19:07:14 Isn't CHECK more aggressive for this case? Also, _
49 guests_by_instance_id_.end());
50 guests_by_instance_id_[instance_id] = guest;
51 guests_[guest->web_contents()] = frame_id;
52 }
53
54 void BrowserPluginEmbedder::NavigateGuest(RenderViewHost* render_view_host,
55 int instance_id,
56 int64 frame_id,
57 const std::string& src,
58 const gfx::Size& size) {
59 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
60 WebContentsImpl* guest_web_contents = NULL;
61 GURL url(src);
62 if (!guest) {
63 // The SiteInstance of a given guest is based on the fact that it's a guest
64 // in addition to which platform application the guest belongs to, rather
65 // than the URL that the guest is being navigated to.
66 std::string host = render_view_host->GetSiteInstance()->GetSite().host();
67 GURL guest_site(
68 base::StringPrintf("%s://%s", chrome::kGuestScheme, host.c_str()));
69 SiteInstance* guest_site_instance =
70 SiteInstance::CreateForURL(web_contents()->GetBrowserContext(),
71 guest_site);
72 guest_web_contents =
73 static_cast<WebContentsImpl*>(
74 WebContents::Create(web_contents()->GetBrowserContext(),
75 guest_site_instance,
76 MSG_ROUTING_NONE,
77 NULL, // base WebContents
78 NULL // session storage namespace
79 ));
80
81 guest = guest_web_contents->AddBrowserPluginGuest(instance_id);
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);
Charlie Reis 2012/08/27 20:23:59 Do we need to set this again if the guest already
lazyboy 2012/08/28 19:07:14 Moved. Also this is a bit weird this part has gues
Fady Samuel 2012/08/29 08:16:20 Yea, it doesn't look like the local variable guest
lazyboy 2012/08/31 00:38:04 Done.
92 guest->web_contents()->GetController().LoadURL(url,
93 Referrer(),
94 PAGE_TRANSITION_AUTO_SUBFRAME,
Charlie Reis 2012/08/27 20:23:59 I like that we're classifying this as a subframe l
lazyboy 2012/08/28 19:07:14 I'm not aware of the differences. Only related dif
95 std::string());
96 if (!size.IsEmpty())
97 guest_web_contents->GetView()->SizeContents(size);
98 }
99
100 void BrowserPluginEmbedder::UpdateRectACK(int instance_id,
101 int message_id,
102 const gfx::Size& size) {
103 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
104 if (guest)
105 guest->UpdateRectACK(message_id, size);
106 }
107
108 void BrowserPluginEmbedder::ResizeGuest(int instance_id,
109 TransportDIB* damage_buffer,
110 int width,
111 int height,
112 bool resize_pending,
113 float scale_factor) {
114 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
115 if (!guest)
116 return;
117 WebContentsImpl* guest_web_contents =
118 static_cast<WebContentsImpl*>(guest->web_contents());
119 guest->SetDamageBuffer(damage_buffer, gfx::Size(width, height), scale_factor);
120 if (!resize_pending)
121 guest_web_contents->GetView()->SizeContents(gfx::Size(width, height));
122 }
123
124 void BrowserPluginEmbedder::SetFocus(int instance_id,
125 bool focused) {
126 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
127 if (guest)
128 guest->SetFocus(focused);
129 }
130
131 void BrowserPluginEmbedder::DestroyGuests() {
132 for (GuestMap::const_iterator it = guests_.begin();
133 it != guests_.end(); ++it) {
134 WebContents* web_contents = it->first;
135 delete web_contents;
136 }
137 guests_.clear();
138 guests_by_instance_id_.clear();
139 }
140
141 void BrowserPluginEmbedder::HandleInputEvent(int instance_id,
142 RenderViewHost* render_view_host,
143 const gfx::Rect& guest_rect,
144 const WebKit::WebInputEvent& event,
145 IPC::Message* reply_message) {
146 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
147 if (guest)
148 guest->HandleInputEvent(render_view_host, guest_rect, event, reply_message);
149 }
150
151 void BrowserPluginEmbedder::DestroyGuestByInstanceID(int instance_id) {
152 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
153 if (guest) {
154 WebContents* guest_web_contents = guest->web_contents();
155
156 GuestMap::iterator guest_it = guests_.find(guest_web_contents);
157 DCHECK(guest_it != guests_.end());
158
159 guests_.erase(guest_it);
160 guests_by_instance_id_.erase(instance_id);
161
162 guest->Destroy();
163 }
164 }
165
166 void BrowserPluginEmbedder::DidCommitProvisionalLoadForFrame(
167 int64 frame_id,
168 bool is_main_frame,
169 const GURL& url,
170 PageTransition transition_type,
171 RenderViewHost* render_view_host) {
172 // Clean-up guests that lie in the frame that we're navigating.
Charlie Reis 2012/08/27 20:23:59 nit: Clean up
lazyboy 2012/08/28 19:07:14 Done.
173 typedef std::set<WebContents*> GuestSet;
174 GuestSet guests_to_delete;
175 for (GuestMap::const_iterator it = guests_.begin();
176 it != guests_.end(); ++it) {
Charlie Reis 2012/08/27 20:23:59 nit: Wrong indent. Same below.
lazyboy 2012/08/28 19:07:14 I somehow broke this thinking for statements are n
177 WebContents* web_contents = it->first;
178 if (it->second == frame_id) {
179 // TODO(lazyboy): If we allow browser tags to be nested, we need to take
180 // care of subframes inside this frame as well.
Charlie Reis 2012/08/27 20:23:59 This is not sufficient. If the embedder has a tre
lazyboy 2012/08/28 19:07:14 Wouldn't that iframe's embedder take care of that?
181 guests_to_delete.insert(web_contents);
182 }
183 }
184 for (GuestSet::const_iterator it = guests_to_delete.begin();
185 it != guests_to_delete.end(); ++it) {
186 int instance_id = static_cast<WebContentsImpl*>(*it)->
187 GetBrowserPluginGuest()->instance_id();
188 DestroyGuestByInstanceID(instance_id);
189 }
190 }
191
192 void BrowserPluginEmbedder::RenderViewDeleted(
193 RenderViewHost* render_view_host) {
194 DestroyGuests();
195 }
196
197 void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) {
198 DestroyGuests();
199 }
200
201 void BrowserPluginEmbedder::WebContentsVisiblitlyChanged(bool visible) {
202 // If the embedder is hidden we need to hide the guests as well.
203 for (GuestMap::const_iterator it = guests_.begin();
204 it != guests_.end(); ++it) {
Charlie Reis 2012/08/27 20:23:59 nit: Wrong indent.
lazyboy 2012/08/28 19:07:14 Done.
205 WebContents* web_contents = it->first;
206 if (visible)
207 web_contents->WasShown();
208 else
209 web_contents->WasHidden();
210 }
211 }
212
213 void BrowserPluginEmbedder::PluginDestroyed(int instance_id) {
214 DestroyGuestByInstanceID(instance_id);
215 }
216
217 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698