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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin.cc

Issue 444813002: Remove BrowserPlugin's -internal-attach method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move AttachToBrowserPlugin to RenderFrame Created 6 years, 4 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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "content/renderer/browser_plugin/browser_plugin.h" 5 #include "content/renderer/browser_plugin/browser_plugin.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 content_window_routing_id_(MSG_ROUTING_NONE), 57 content_window_routing_id_(MSG_ROUTING_NONE),
58 plugin_focused_(false), 58 plugin_focused_(false),
59 visible_(true), 59 visible_(true),
60 auto_navigate_(auto_navigate), 60 auto_navigate_(auto_navigate),
61 mouse_locked_(false), 61 mouse_locked_(false),
62 browser_plugin_manager_(render_view->GetBrowserPluginManager()), 62 browser_plugin_manager_(render_view->GetBrowserPluginManager()),
63 weak_ptr_factory_(this) { 63 weak_ptr_factory_(this) {
64 } 64 }
65 65
66 BrowserPlugin::~BrowserPlugin() { 66 BrowserPlugin::~BrowserPlugin() {
67 browser_plugin_manager()->RemoveBrowserPluginInternal(
68 browser_plugin_instance_id_);
67 // If the BrowserPlugin has never navigated then the browser process and 69 // If the BrowserPlugin has never navigated then the browser process and
68 // BrowserPluginManager don't know about it and so there is nothing to do 70 // BrowserPluginManager don't know about it and so there is nothing to do
69 // here. 71 // here.
70 if (!HasGuestInstanceID()) 72 if (!HasGuestInstanceID())
71 return; 73 return;
72 browser_plugin_manager()->RemoveBrowserPlugin(guest_instance_id_); 74 browser_plugin_manager()->RemoveBrowserPlugin(guest_instance_id_);
73 browser_plugin_manager()->Send( 75 browser_plugin_manager()->Send(
74 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, 76 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_,
75 guest_instance_id_)); 77 guest_instance_id_));
76 } 78 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 153
152 if (compositing_helper_) 154 if (compositing_helper_)
153 compositing_helper_->SetContentsOpaque(opaque); 155 compositing_helper_->SetContentsOpaque(opaque);
154 156
155 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque( 157 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque(
156 render_view_routing_id_, 158 render_view_routing_id_,
157 guest_instance_id_, 159 guest_instance_id_,
158 opaque)); 160 opaque));
159 } 161 }
160 162
161 void BrowserPlugin::Attach(int guest_instance_id, 163 void BrowserPlugin::Attach(int guest_instance_id) {
162 scoped_ptr<base::DictionaryValue> extra_params) { 164 CHECK_NE(browser_plugin::kInstanceIDNone, guest_instance_id);
163 CHECK(guest_instance_id != browser_plugin::kInstanceIDNone);
164
165 // If this BrowserPlugin is already attached to a guest, then kill the guest. 165 // If this BrowserPlugin is already attached to a guest, then kill the guest.
166 if (HasGuestInstanceID()) { 166 if (HasGuestInstanceID()) {
167 if (guest_instance_id == guest_instance_id_) 167 if (guest_instance_id == guest_instance_id_)
168 return; 168 return;
169 guest_crashed_ = false; 169 guest_crashed_ = false;
170 EnableCompositing(false); 170 EnableCompositing(false);
171 if (compositing_helper_) { 171 if (compositing_helper_) {
172 compositing_helper_->OnContainerDestroy(); 172 compositing_helper_->OnContainerDestroy();
173 compositing_helper_ = NULL; 173 compositing_helper_ = NULL;
174 } 174 }
175 browser_plugin_manager()->RemoveBrowserPlugin(guest_instance_id_); 175 browser_plugin_manager()->RemoveBrowserPlugin(guest_instance_id_);
176 browser_plugin_manager()->Send(new BrowserPluginHostMsg_PluginDestroyed( 176 browser_plugin_manager()->Send(new BrowserPluginHostMsg_PluginDestroyed(
177 render_view_routing_id_, guest_instance_id_)); 177 render_view_routing_id_, guest_instance_id_));
178 } 178 }
179 179
180 // This API may be called directly without setting the src attribute.
181 // In that case, we need to make sure we don't allocate another instance ID.
182 guest_instance_id_ = guest_instance_id; 180 guest_instance_id_ = guest_instance_id;
183 browser_plugin_manager()->AddBrowserPlugin(guest_instance_id, this); 181 browser_plugin_manager()->AddBrowserPlugin(guest_instance_id, this);
184 182
185 BrowserPluginHostMsg_Attach_Params attach_params; 183 BrowserPluginHostMsg_Attach_Params attach_params;
186 attach_params.focused = ShouldGuestBeFocused(); 184 attach_params.focused = ShouldGuestBeFocused();
187 attach_params.visible = visible_; 185 attach_params.visible = visible_;
188 attach_params.opaque = !GetAllowTransparencyAttribute(); 186 attach_params.opaque = !GetAllowTransparencyAttribute();
189 attach_params.origin = plugin_rect().origin(); 187 attach_params.origin = plugin_rect().origin();
190 GetSizeParams(&attach_params.resize_guest_params, false); 188 GetSizeParams(&attach_params.resize_guest_params, false);
191 189
192 browser_plugin_manager()->Send( 190 browser_plugin_manager()->Send(new BrowserPluginHostMsg_Attach(
193 new BrowserPluginHostMsg_Attach(render_view_routing_id_, 191 render_view_routing_id_,
194 guest_instance_id_, attach_params, 192 browser_plugin_instance_id_,
195 *extra_params)); 193 attach_params));
196 } 194 }
197 195
198 void BrowserPlugin::DidCommitCompositorFrame() { 196 void BrowserPlugin::DidCommitCompositorFrame() {
199 if (compositing_helper_.get()) 197 if (compositing_helper_.get())
200 compositing_helper_->DidCommitCompositorFrame(); 198 compositing_helper_->DidCommitCompositorFrame();
201 } 199 }
202 200
203 void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) { 201 void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) {
204 DCHECK(render_view_.get()); 202 DCHECK(render_view_.get());
205 render_view_->GetWebView()->advanceFocus(reverse); 203 render_view_->GetWebView()->advanceFocus(reverse);
206 } 204 }
207 205
208 void BrowserPlugin::OnAttachACK(int guest_instance_id) { 206 void BrowserPlugin::OnAttachACK(int guest_instance_id) {
207 DCHECK(!attached());
209 attached_ = true; 208 attached_ = true;
210 } 209 }
211 210
212 void BrowserPlugin::OnBuffersSwapped( 211 void BrowserPlugin::OnBuffersSwapped(
213 int instance_id, 212 int instance_id,
214 const FrameMsg_BuffersSwapped_Params& params) { 213 const FrameMsg_BuffersSwapped_Params& params) {
215 EnableCompositing(true); 214 EnableCompositing(true);
216 215
217 compositing_helper_->OnBuffersSwapped(params.size, 216 compositing_helper_->OnBuffersSwapped(params.size,
218 params.mailbox, 217 params.mailbox,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 OnLockMouseACK(false); 291 OnLockMouseACK(false);
293 return; 292 return;
294 } 293 }
295 render_view_->mouse_lock_dispatcher()->UnlockMouse(this); 294 render_view_->mouse_lock_dispatcher()->UnlockMouse(this);
296 } 295 }
297 } 296 }
298 297
299 void BrowserPlugin::OnShouldAcceptTouchEvents(int guest_instance_id, 298 void BrowserPlugin::OnShouldAcceptTouchEvents(int guest_instance_id,
300 bool accept) { 299 bool accept) {
301 if (container()) { 300 if (container()) {
302 container()->requestTouchEventType(accept ? 301 container()->requestTouchEventType(
303 blink::WebPluginContainer::TouchEventRequestTypeRaw : 302 accept ? WebPluginContainer::TouchEventRequestTypeRaw
304 blink::WebPluginContainer::TouchEventRequestTypeNone); 303 : WebPluginContainer::TouchEventRequestTypeNone);
305 } 304 }
306 } 305 }
307 306
308 void BrowserPlugin::OnUpdateRect( 307 void BrowserPlugin::OnUpdateRect(
309 int guest_instance_id, 308 int guest_instance_id,
310 const BrowserPluginMsg_UpdateRect_Params& params) { 309 const BrowserPluginMsg_UpdateRect_Params& params) {
311 // Note that there is no need to send ACK for this message. 310 // Note that there is no need to send ACK for this message.
312 // If the guest has updated pixels then it is no longer crashed. 311 // If the guest has updated pixels then it is no longer crashed.
313 guest_crashed_ = false; 312 guest_crashed_ = false;
314 313
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 should_be_focused)); 381 should_be_focused));
383 } 382 }
384 383
385 bool BrowserPlugin::ShouldGuestBeFocused() const { 384 bool BrowserPlugin::ShouldGuestBeFocused() const {
386 bool embedder_focused = false; 385 bool embedder_focused = false;
387 if (render_view_.get()) 386 if (render_view_.get())
388 embedder_focused = render_view_->has_focus(); 387 embedder_focused = render_view_->has_focus();
389 return plugin_focused_ && embedder_focused; 388 return plugin_focused_ && embedder_focused;
390 } 389 }
391 390
392 blink::WebPluginContainer* BrowserPlugin::container() const { 391 WebPluginContainer* BrowserPlugin::container() const {
393 return container_; 392 return container_;
394 } 393 }
395 394
396 bool BrowserPlugin::initialize(WebPluginContainer* container) { 395 bool BrowserPlugin::initialize(WebPluginContainer* container) {
397 if (!container) 396 if (!container)
398 return false; 397 return false;
399 398
400 // Tell |container| to allow this plugin to use script objects. 399 // Tell |container| to allow this plugin to use script objects.
401 npp_.reset(new NPP_t); 400 npp_.reset(new NPP_t);
402 container->allowScriptObjects(); 401 container->allowScriptObjects();
403 402
404 bindings_.reset(new BrowserPluginBindings(this)); 403 bindings_.reset(new BrowserPluginBindings(this));
405 container_ = container; 404 container_ = container;
406 container_->setWantsWheelEvents(true); 405 container_->setWantsWheelEvents(true);
407 // This is a way to notify observers of our attributes that we have the 406
408 // bindings ready. This also means that this plugin is available in render 407 // This is a way to notify observers of our attributes that this plugin is
409 // tree. 408 // available in render tree.
410 UpdateDOMAttribute("internalbindings", "true"); 409 browser_plugin_instance_id_ = browser_plugin_manager()->GetNextInstanceID();
410 UpdateDOMAttribute("internalinstanceid",
411 base::StringPrintf("%d", browser_plugin_instance_id_));
412
413 browser_plugin_manager()->AddBrowserPluginInternal(
414 browser_plugin_instance_id_, this);
411 return true; 415 return true;
412 } 416 }
413 417
414 void BrowserPlugin::EnableCompositing(bool enable) { 418 void BrowserPlugin::EnableCompositing(bool enable) {
415 bool enabled = !!compositing_helper_; 419 bool enabled = !!compositing_helper_;
416 if (enabled == enable) 420 if (enabled == enable)
417 return; 421 return;
418 422
419 if (enable) { 423 if (enable) {
420 DCHECK(!compositing_helper_.get()); 424 DCHECK(!compositing_helper_.get());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 SkPaint paint; 508 SkPaint paint;
505 paint.setStyle(SkPaint::kFill_Style); 509 paint.setStyle(SkPaint::kFill_Style);
506 paint.setColor(guest_crashed_ ? SK_ColorBLACK : SK_ColorWHITE); 510 paint.setColor(guest_crashed_ ? SK_ColorBLACK : SK_ColorWHITE);
507 canvas->drawRect(image_data_rect, paint); 511 canvas->drawRect(image_data_rect, paint);
508 } 512 }
509 513
510 // static 514 // static
511 bool BrowserPlugin::ShouldForwardToBrowserPlugin( 515 bool BrowserPlugin::ShouldForwardToBrowserPlugin(
512 const IPC::Message& message) { 516 const IPC::Message& message) {
513 switch (message.type()) { 517 switch (message.type()) {
518 case BrowserPluginMsg_Attach_ACK::ID:
Xi Han 2014/08/12 18:17:55 Please sort it alphabetically, i.e., move to after
Fady Samuel 2014/08/13 22:24:39 Done.
514 case BrowserPluginMsg_AdvanceFocus::ID: 519 case BrowserPluginMsg_AdvanceFocus::ID:
515 case BrowserPluginMsg_Attach_ACK::ID:
516 case BrowserPluginMsg_BuffersSwapped::ID: 520 case BrowserPluginMsg_BuffersSwapped::ID:
517 case BrowserPluginMsg_CompositorFrameSwapped::ID: 521 case BrowserPluginMsg_CompositorFrameSwapped::ID:
518 case BrowserPluginMsg_CopyFromCompositingSurface::ID: 522 case BrowserPluginMsg_CopyFromCompositingSurface::ID:
519 case BrowserPluginMsg_GuestContentWindowReady::ID: 523 case BrowserPluginMsg_GuestContentWindowReady::ID:
520 case BrowserPluginMsg_GuestGone::ID: 524 case BrowserPluginMsg_GuestGone::ID:
521 case BrowserPluginMsg_SetCursor::ID: 525 case BrowserPluginMsg_SetCursor::ID:
522 case BrowserPluginMsg_SetMouseLock::ID: 526 case BrowserPluginMsg_SetMouseLock::ID:
523 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: 527 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID:
524 case BrowserPluginMsg_UpdateRect::ID: 528 case BrowserPluginMsg_UpdateRect::ID:
525 return true; 529 return true;
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 const blink::WebMouseEvent& event) { 820 const blink::WebMouseEvent& event) {
817 browser_plugin_manager()->Send( 821 browser_plugin_manager()->Send(
818 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, 822 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_,
819 guest_instance_id_, 823 guest_instance_id_,
820 plugin_rect_, 824 plugin_rect_,
821 &event)); 825 &event));
822 return true; 826 return true;
823 } 827 }
824 828
825 } // namespace content 829 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698