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

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

Issue 11416074: Browser Plugin: Simplified BrowserPluginManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 #include "content/browser/browser_plugin/browser_plugin_guest.h" 5 #include "content/browser/browser_plugin/browser_plugin_guest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "content/browser/browser_plugin/browser_plugin_embedder.h" 10 #include "content/browser/browser_plugin/browser_plugin_embedder.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 break; 105 break;
106 } 106 }
107 default: 107 default:
108 NOTREACHED() << "Unexpected notification sent."; 108 NOTREACHED() << "Unexpected notification sent.";
109 break; 109 break;
110 } 110 }
111 } 111 }
112 112
113 bool BrowserPluginGuest::ViewTakeFocus(bool reverse) { 113 bool BrowserPluginGuest::ViewTakeFocus(bool reverse) {
114 SendMessageToEmbedder( 114 SendMessageToEmbedder(
115 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); 115 new BrowserPluginMsg_AdvanceFocus(embedder_routing_id(),
116 instance_id(),
117 reverse));
116 return true; 118 return true;
117 } 119 }
118 120
119 void BrowserPluginGuest::Go(int relative_index) { 121 void BrowserPluginGuest::Go(int relative_index) {
120 web_contents()->GetController().GoToOffset(relative_index); 122 web_contents()->GetController().GoToOffset(relative_index);
121 } 123 }
122 124
123 bool BrowserPluginGuest::CanDownload(RenderViewHost* render_view_host, 125 bool BrowserPluginGuest::CanDownload(RenderViewHost* render_view_host,
124 int request_id, 126 int request_id,
125 const std::string& request_method) { 127 const std::string& request_method) {
(...skipping 25 matching lines...) Expand all
151 } 153 }
152 154
153 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { 155 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() {
154 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will 156 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will
155 // manage the focus ourselves. 157 // manage the focus ourselves.
156 return false; 158 return false;
157 } 159 }
158 160
159 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) { 161 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) {
160 SendMessageToEmbedder( 162 SendMessageToEmbedder(
161 new BrowserPluginMsg_ShouldAcceptTouchEvents(instance_id(), accept)); 163 new BrowserPluginMsg_ShouldAcceptTouchEvents(embedder_routing_id(),
164 instance_id(),
165 accept));
162 } 166 }
163 167
164 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) { 168 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) {
165 visible_ = visible; 169 visible_ = visible;
166 if (embedder_visible && visible) 170 if (embedder_visible && visible)
167 web_contents()->WasShown(); 171 web_contents()->WasShown();
168 else 172 else
169 web_contents()->WasHidden(); 173 web_contents()->WasHidden();
170 } 174 }
171 175
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // between the embedder and browser processes. 298 // between the embedder and browser processes.
295 DCHECK(*static_cast<unsigned int*>(damage_buffer->memory()) == 0xdeadbeef); 299 DCHECK(*static_cast<unsigned int*>(damage_buffer->memory()) == 0xdeadbeef);
296 damage_buffer_.reset(damage_buffer); 300 damage_buffer_.reset(damage_buffer);
297 #if defined(OS_WIN) 301 #if defined(OS_WIN)
298 damage_buffer_size_ = damage_buffer_size; 302 damage_buffer_size_ = damage_buffer_size;
299 #endif 303 #endif
300 damage_view_size_ = damage_view_size; 304 damage_view_size_ = damage_view_size;
301 damage_buffer_scale_factor_ = scale_factor; 305 damage_buffer_scale_factor_ = scale_factor;
302 } 306 }
303 307
308 int BrowserPluginGuest::embedder_routing_id() const {
309 return embedder_web_contents_->GetRoutingID();
310 }
311
304 bool BrowserPluginGuest::InAutoSizeBounds(const gfx::Size& size) const { 312 bool BrowserPluginGuest::InAutoSizeBounds(const gfx::Size& size) const {
305 return size.width() <= max_auto_size_.width() && 313 return size.width() <= max_auto_size_.width() &&
306 size.height() <= max_auto_size_.height(); 314 size.height() <= max_auto_size_.height();
307 } 315 }
308 316
309 void BrowserPluginGuest::UpdateRect( 317 void BrowserPluginGuest::UpdateRect(
310 RenderViewHost* render_view_host, 318 RenderViewHost* render_view_host,
311 const ViewHostMsg_UpdateRect_Params& params) { 319 const ViewHostMsg_UpdateRect_Params& params) {
312 RenderWidgetHostImpl* render_widget_host = 320 RenderWidgetHostImpl* render_widget_host =
313 RenderWidgetHostImpl::From(render_view_host); 321 RenderWidgetHostImpl::From(render_view_host);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 params.flags); 365 params.flags);
358 366
359 // We need to send the ACK to the same render_view_host that issued 367 // We need to send the ACK to the same render_view_host that issued
360 // the UpdateRect. We keep track of this correspondence via a message_id. 368 // the UpdateRect. We keep track of this correspondence via a message_id.
361 int message_id = pending_update_counter_++; 369 int message_id = pending_update_counter_++;
362 pending_updates_.AddWithID(render_view_host, message_id); 370 pending_updates_.AddWithID(render_view_host, message_id);
363 371
364 gfx::Size param_size = gfx::Size(params.view_size.width(), 372 gfx::Size param_size = gfx::Size(params.view_size.width(),
365 params.view_size.height()); 373 params.view_size.height());
366 374
367 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(instance_id(), 375 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(),
376 instance_id(),
368 message_id, 377 message_id,
369 relay_params)); 378 relay_params));
370 } 379 }
371 380
372 void BrowserPluginGuest::UpdateRectACK(int message_id, const gfx::Size& size) { 381 void BrowserPluginGuest::UpdateRectACK(int message_id, const gfx::Size& size) {
373 RenderViewHost* render_view_host = pending_updates_.Lookup(message_id); 382 RenderViewHost* render_view_host = pending_updates_.Lookup(message_id);
374 // If the guest has crashed since it sent the initial ViewHostMsg_UpdateRect 383 // If the guest has crashed since it sent the initial ViewHostMsg_UpdateRect
375 // then the pending_updates_ map will have been cleared. 384 // then the pending_updates_ map will have been cleared.
376 if (!render_view_host) 385 if (!render_view_host)
377 return; 386 return;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 void BrowserPluginGuest::ShowWidget(RenderViewHost* render_view_host, 471 void BrowserPluginGuest::ShowWidget(RenderViewHost* render_view_host,
463 int route_id, 472 int route_id,
464 const gfx::Rect& initial_pos) { 473 const gfx::Rect& initial_pos) {
465 gfx::Rect screen_pos(initial_pos); 474 gfx::Rect screen_pos(initial_pos);
466 screen_pos.Offset(guest_rect_.OffsetFromOrigin()); 475 screen_pos.Offset(guest_rect_.OffsetFromOrigin());
467 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id, 476 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id,
468 screen_pos); 477 screen_pos);
469 } 478 }
470 479
471 void BrowserPluginGuest::SetCursor(const WebCursor& cursor) { 480 void BrowserPluginGuest::SetCursor(const WebCursor& cursor) {
472 SendMessageToEmbedder(new BrowserPluginMsg_SetCursor(instance_id(), cursor)); 481 SendMessageToEmbedder(new BrowserPluginMsg_SetCursor(embedder_routing_id(),
482 instance_id(),
483 cursor));
473 } 484 }
474 485
475 void BrowserPluginGuest::DidStartProvisionalLoadForFrame( 486 void BrowserPluginGuest::DidStartProvisionalLoadForFrame(
476 int64 frame_id, 487 int64 frame_id,
477 int64 parent_frame_id, 488 int64 parent_frame_id,
478 bool is_main_frame, 489 bool is_main_frame,
479 const GURL& validated_url, 490 const GURL& validated_url,
480 bool is_error_page, 491 bool is_error_page,
481 RenderViewHost* render_view_host) { 492 RenderViewHost* render_view_host) {
482 // Inform the embedder of the loadStart. 493 // Inform the embedder of the loadStart.
483 SendMessageToEmbedder( 494 SendMessageToEmbedder(
484 new BrowserPluginMsg_LoadStart(instance_id(), 495 new BrowserPluginMsg_LoadStart(embedder_routing_id(),
496 instance_id(),
485 validated_url, 497 validated_url,
486 is_main_frame)); 498 is_main_frame));
487 } 499 }
488 500
489 void BrowserPluginGuest::DidFailProvisionalLoad( 501 void BrowserPluginGuest::DidFailProvisionalLoad(
490 int64 frame_id, 502 int64 frame_id,
491 bool is_main_frame, 503 bool is_main_frame,
492 const GURL& validated_url, 504 const GURL& validated_url,
493 int error_code, 505 int error_code,
494 const string16& error_description, 506 const string16& error_description,
495 RenderViewHost* render_view_host) { 507 RenderViewHost* render_view_host) {
496 // Translate the |error_code| into an error string. 508 // Translate the |error_code| into an error string.
497 std::string error_type; 509 std::string error_type;
498 RemoveChars(net::ErrorToString(error_code), "net::", &error_type); 510 RemoveChars(net::ErrorToString(error_code), "net::", &error_type);
499 // Inform the embedder of the loadAbort. 511 // Inform the embedder of the loadAbort.
500 SendMessageToEmbedder( 512 SendMessageToEmbedder(
501 new BrowserPluginMsg_LoadAbort(instance_id(), 513 new BrowserPluginMsg_LoadAbort(embedder_routing_id(),
514 instance_id(),
502 validated_url, 515 validated_url,
503 is_main_frame, 516 is_main_frame,
504 error_type)); 517 error_type));
505 } 518 }
506 519
507 void BrowserPluginGuest::LoadRedirect( 520 void BrowserPluginGuest::LoadRedirect(
508 const GURL& old_url, 521 const GURL& old_url,
509 const GURL& new_url, 522 const GURL& new_url,
510 bool is_top_level) { 523 bool is_top_level) {
511 SendMessageToEmbedder( 524 SendMessageToEmbedder(
512 new BrowserPluginMsg_LoadRedirect( 525 new BrowserPluginMsg_LoadRedirect(embedder_routing_id(),
513 instance_id(), old_url, new_url, is_top_level)); 526 instance_id(),
527 old_url,
528 new_url,
529 is_top_level));
514 } 530 }
515 531
516 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( 532 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame(
517 int64 frame_id, 533 int64 frame_id,
518 bool is_main_frame, 534 bool is_main_frame,
519 const GURL& url, 535 const GURL& url,
520 PageTransition transition_type, 536 PageTransition transition_type,
521 RenderViewHost* render_view_host) { 537 RenderViewHost* render_view_host) {
522 // Inform its embedder of the updated URL. 538 // Inform its embedder of the updated URL.
523 BrowserPluginMsg_LoadCommit_Params params; 539 BrowserPluginMsg_LoadCommit_Params params;
524 params.url = url; 540 params.url = url;
525 params.is_top_level = is_main_frame; 541 params.is_top_level = is_main_frame;
526 params.process_id = render_view_host->GetProcess()->GetID(); 542 params.process_id = render_view_host->GetProcess()->GetID();
527 params.current_entry_index = 543 params.current_entry_index =
528 web_contents()->GetController().GetCurrentEntryIndex(); 544 web_contents()->GetController().GetCurrentEntryIndex();
529 params.entry_count = 545 params.entry_count =
530 web_contents()->GetController().GetEntryCount(); 546 web_contents()->GetController().GetEntryCount();
531 SendMessageToEmbedder( 547 SendMessageToEmbedder(
532 new BrowserPluginMsg_LoadCommit(instance_id(), params)); 548 new BrowserPluginMsg_LoadCommit(embedder_routing_id(),
549 instance_id(),
550 params));
533 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); 551 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate"));
534 } 552 }
535 553
536 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { 554 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) {
537 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(instance_id())); 555 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(embedder_routing_id(),
556 instance_id()));
538 } 557 }
539 558
540 void BrowserPluginGuest::RenderViewReady() { 559 void BrowserPluginGuest::RenderViewReady() {
541 // TODO(fsamuel): Investigate whether it's possible to update state earlier 560 // TODO(fsamuel): Investigate whether it's possible to update state earlier
542 // here (see http://www.crbug.com/158151). 561 // here (see http://www.crbug.com/158151).
543 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); 562 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost();
544 render_view_host->Send( 563 render_view_host->Send(
545 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused_)); 564 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused_));
546 bool embedder_visible = 565 bool embedder_visible =
547 embedder_web_contents_->GetBrowserPluginEmbedder()->visible(); 566 embedder_web_contents_->GetBrowserPluginEmbedder()->visible();
548 SetVisibility(embedder_visible, visible()); 567 SetVisibility(embedder_visible, visible());
549 if (auto_size_) { 568 if (auto_size_) {
550 web_contents()->GetRenderViewHost()->EnableAutoResize( 569 web_contents()->GetRenderViewHost()->EnableAutoResize(
551 min_auto_size_, max_auto_size_); 570 min_auto_size_, max_auto_size_);
552 } else { 571 } else {
553 web_contents()->GetRenderViewHost()->DisableAutoResize(damage_view_size_); 572 web_contents()->GetRenderViewHost()->DisableAutoResize(damage_view_size_);
554 } 573 }
555 } 574 }
556 575
557 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { 576 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) {
558 if (pending_input_event_reply_.get()) { 577 if (pending_input_event_reply_.get()) {
559 IPC::Message* reply_message = pending_input_event_reply_.release(); 578 IPC::Message* reply_message = pending_input_event_reply_.release();
560 BrowserPluginHostMsg_HandleInputEvent::WriteReplyParams(reply_message, 579 BrowserPluginHostMsg_HandleInputEvent::WriteReplyParams(reply_message,
561 false); 580 false);
562 SendMessageToEmbedder(reply_message); 581 SendMessageToEmbedder(reply_message);
563 } 582 }
564 int process_id = web_contents()->GetRenderProcessHost()->GetID(); 583 int process_id = web_contents()->GetRenderProcessHost()->GetID();
565 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(instance_id(), 584 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(embedder_routing_id(),
585 instance_id(),
566 process_id, 586 process_id,
567 status)); 587 status));
568 IDMap<RenderViewHost>::const_iterator iter(&pending_updates_); 588 IDMap<RenderViewHost>::const_iterator iter(&pending_updates_);
569 while (!iter.IsAtEnd()) { 589 while (!iter.IsAtEnd()) {
570 pending_updates_.Remove(iter.GetCurrentKey()); 590 pending_updates_.Remove(iter.GetCurrentKey());
571 iter.Advance(); 591 iter.Advance();
572 } 592 }
573 593
574 switch (status) { 594 switch (status) {
575 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: 595 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
576 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Killed")); 596 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Killed"));
577 break; 597 break;
578 case base::TERMINATION_STATUS_PROCESS_CRASHED: 598 case base::TERMINATION_STATUS_PROCESS_CRASHED:
579 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Crashed")); 599 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Crashed"));
580 break; 600 break;
581 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: 601 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
582 RecordAction(UserMetricsAction("BrowserPlugin.Guest.AbnormalDeath")); 602 RecordAction(UserMetricsAction("BrowserPlugin.Guest.AbnormalDeath"));
583 break; 603 break;
584 default: 604 default:
585 break; 605 break;
586 } 606 }
587 } 607 }
588 608
589 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { 609 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
590 embedder_web_contents_->GetRenderProcessHost()->Send(msg); 610 embedder_web_contents_->GetRenderProcessHost()->Send(msg);
591 } 611 }
592 612
593 } // namespace content 613 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.h ('k') | content/common/browser_plugin_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698