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

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

Issue 11565024: Browser Plugin: Reduce code repetition in BrowserPluginManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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/renderer/browser_plugin/browser_plugin.h" 5 #include "content/renderer/browser_plugin/browser_plugin.h"
6 6
7 #include "base/json/json_string_value_serializer.h" 7 #include "base/json/json_string_value_serializer.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 instance_id_)); 145 instance_id_));
146 } 146 }
147 147
148 void BrowserPlugin::Cleanup() { 148 void BrowserPlugin::Cleanup() {
149 if (current_damage_buffer_) 149 if (current_damage_buffer_)
150 FreeDamageBuffer(&current_damage_buffer_); 150 FreeDamageBuffer(&current_damage_buffer_);
151 if (pending_damage_buffer_) 151 if (pending_damage_buffer_)
152 FreeDamageBuffer(&pending_damage_buffer_); 152 FreeDamageBuffer(&pending_damage_buffer_);
153 } 153 }
154 154
155 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) {
156 bool handled = true;
157 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message)
158 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus)
159 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady,
160 OnGuestContentWindowReady)
161 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone)
162 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive)
163 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive)
164 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort)
165 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit)
166 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect)
167 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart)
168 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStop, OnLoadStop)
169 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents,
170 OnShouldAcceptTouchEvents)
171 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor)
172 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect)
173 IPC_MESSAGE_UNHANDLED(handled = false)
174 IPC_END_MESSAGE_MAP()
175 return handled;
176 }
177
178 void BrowserPlugin::UpdateDOMAttribute(
179 const std::string& attribute_name,
180 const std::string& attribute_value) {
181 if (!container())
182 return;
183
184 WebKit::WebElement element = container()->element();
185 WebKit::WebString web_attribute_name =
186 WebKit::WebString::fromUTF8(attribute_name);
187 std::string current_value(element.getAttribute(web_attribute_name).utf8());
188 if (current_value == attribute_value)
189 return;
190
191 if (attribute_value.empty()) {
192 element.removeAttribute(web_attribute_name);
193 } else {
194 element.setAttribute(web_attribute_name,
195 WebKit::WebString::fromUTF8(attribute_value));
196 }
197 }
198
199
155 bool BrowserPlugin::SetSrcAttribute(const std::string& src, 200 bool BrowserPlugin::SetSrcAttribute(const std::string& src,
156 std::string* error_message) { 201 std::string* error_message) {
157 if (!valid_partition_id_) { 202 if (!valid_partition_id_) {
158 *error_message = kErrorInvalidPartition; 203 *error_message = kErrorInvalidPartition;
159 return false; 204 return false;
160 } 205 }
161 206
162 if (src.empty() || (src == src_ && !guest_crashed_)) 207 if (src.empty() || (src == src_ && !guest_crashed_))
163 return true; 208 return true;
164 209
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 #else 300 #else
256 bool BrowserPlugin::DamageBufferMatches( 301 bool BrowserPlugin::DamageBufferMatches(
257 const TransportDIB* damage_buffer, 302 const TransportDIB* damage_buffer,
258 const TransportDIB::Handle& other_damage_buffer_handle) { 303 const TransportDIB::Handle& other_damage_buffer_handle) {
259 if (!damage_buffer) 304 if (!damage_buffer)
260 return false; 305 return false;
261 return damage_buffer->handle() == other_damage_buffer_handle; 306 return damage_buffer->handle() == other_damage_buffer_handle;
262 } 307 }
263 #endif 308 #endif
264 309
265 void BrowserPlugin::UpdateDOMAttribute( 310 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) {
266 const std::string& attribute_name, 311 DCHECK(render_view_);
267 const std::string& attribute_value) { 312 render_view_->GetWebView()->advanceFocus(reverse);
268 if (!container()) 313 }
314
315 void BrowserPlugin::OnGuestContentWindowReady(int instance_id,
316 int content_window_routing_id) {
317 DCHECK(content_window_routing_id != MSG_ROUTING_NONE);
318 content_window_routing_id_ = content_window_routing_id;
319 }
320
321 void BrowserPlugin::OnGuestGone(int instance_id, int process_id, int status) {
322 // We fire the event listeners before painting the sad graphic to give the
323 // developer an opportunity to display an alternative overlay image on crash.
324 std::string termination_status = TerminationStatusToString(
325 static_cast<base::TerminationStatus>(status));
326 std::map<std::string, base::Value*> props;
327 props[kProcessId] = base::Value::CreateIntegerValue(process_id);
328 props[kReason] = base::Value::CreateStringValue(termination_status);
329
330 // Event listeners may remove the BrowserPlugin from the document. If that
331 // happens, the BrowserPlugin will be scheduled for later deletion (see
332 // BrowserPlugin::destroy()). That will clear the container_ reference,
333 // but leave other member variables valid below.
334 TriggerEvent(kEventExit, &props);
335
336 guest_crashed_ = true;
337 // We won't paint the contents of the current backing store again so we might
338 // as well toss it out and save memory.
339 backing_store_.reset();
340 // If the BrowserPlugin is scheduled to be deleted, then container_ will be
341 // NULL so we shouldn't attempt to access it.
342 if (container_)
343 container_->invalidate();
344 }
345
346 void BrowserPlugin::OnGuestResponsive(int instance_id, int process_id) {
347 std::map<std::string, base::Value*> props;
348 props[kProcessId] = base::Value::CreateIntegerValue(process_id);
349 TriggerEvent(kEventResponsive, &props);
350 }
351
352 void BrowserPlugin::OnGuestUnresponsive(int instance_id, int process_id) {
353 std::map<std::string, base::Value*> props;
354 props[kProcessId] = base::Value::CreateIntegerValue(process_id);
355 TriggerEvent(kEventUnresponsive, &props);
356 }
357
358 void BrowserPlugin::OnLoadAbort(int instance_id,
359 const GURL& url,
360 bool is_top_level,
361 const std::string& type) {
362 std::map<std::string, base::Value*> props;
363 props[kURL] = base::Value::CreateStringValue(url.spec());
364 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level);
365 props[kReason] = base::Value::CreateStringValue(type);
366 TriggerEvent(kEventLoadAbort, &props);
367 }
368
369 void BrowserPlugin::OnLoadCommit(
370 int instance_id,
371 const BrowserPluginMsg_LoadCommit_Params& params) {
372 // If the guest has just committed a new navigation then it is no longer
373 // crashed.
374 guest_crashed_ = false;
375 if (params.is_top_level) {
376 src_ = params.url.spec();
377 UpdateDOMAttribute(kSrc, src_.c_str());
378 }
379 process_id_ = params.process_id;
380 current_nav_entry_index_ = params.current_entry_index;
381 nav_entry_count_ = params.entry_count;
382
383 std::map<std::string, base::Value*> props;
384 props[kURL] = base::Value::CreateStringValue(params.url.spec());
385 props[kIsTopLevel] = base::Value::CreateBooleanValue(params.is_top_level);
386 TriggerEvent(kEventLoadCommit, &props);
387 }
388
389 void BrowserPlugin::OnLoadRedirect(int instance_id,
390 const GURL& old_url,
391 const GURL& new_url,
392 bool is_top_level) {
393 std::map<std::string, base::Value*> props;
394 props[kOldURL] = base::Value::CreateStringValue(old_url.spec());
395 props[kNewURL] = base::Value::CreateStringValue(new_url.spec());
396 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level);
397 TriggerEvent(kEventLoadRedirect, &props);
398 }
399
400 void BrowserPlugin::OnLoadStart(int instance_id,
401 const GURL& url,
402 bool is_top_level) {
403 std::map<std::string, base::Value*> props;
404 props[kURL] = base::Value::CreateStringValue(url.spec());
405 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level);
406
407 TriggerEvent(kEventLoadStart, &props);
408 }
409
410 void BrowserPlugin::OnLoadStop(int instance_id) {
411 // Construct the loadStop event object.
sadrul 2012/12/14 16:08:39 This comment doesn't seem relevant anymore.
Fady Samuel 2012/12/14 17:05:54 Done.
412 TriggerEvent(kEventLoadStop, NULL);
413 }
414
415 void BrowserPlugin::OnSetCursor(int instance_id, const WebCursor& cursor) {
416 cursor_ = cursor;
417 }
418
419 void BrowserPlugin::OnShouldAcceptTouchEvents(int instance_id, bool accept) {
420 if (container()) {
421 container()->requestTouchEventType(accept ?
422 WebKit::WebPluginContainer::TouchEventRequestTypeRaw :
423 WebKit::WebPluginContainer::TouchEventRequestTypeNone);
424 }
425 }
426
427 void BrowserPlugin::OnUpdateRect(
428 int instance_id,
429 int message_id,
430 const BrowserPluginMsg_UpdateRect_Params& params) {
431 bool use_new_damage_buffer = !backing_store_;
432 BrowserPluginHostMsg_AutoSize_Params auto_size_params;
433 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params;
434 // If we have a pending damage buffer, and the guest has begun to use the
435 // damage buffer then we know the guest will no longer use the current
436 // damage buffer. At this point, we drop the current damage buffer, and
437 // mark the pending damage buffer as the current damage buffer.
438 if (DamageBufferMatches(pending_damage_buffer_,
439 params.damage_buffer_identifier)) {
440 SwapDamageBuffers();
441 use_new_damage_buffer = true;
442 }
443 if ((!auto_size_ &&
444 (width() != params.view_size.width() ||
445 height() != params.view_size.height())) ||
446 (auto_size_ && (!InAutoSizeBounds(params.view_size)))) {
447 if (pending_damage_buffer_) {
448 // The guest has not yet responded to the last resize request, and
449 // so we don't want to do anything at this point other than ACK the guest.
450 PopulateAutoSizeParameters(&auto_size_params);
451 } else {
452 // If we have no pending damage buffer, then the guest has not caught up
453 // with the BrowserPlugin container. We now tell the guest about the new
454 // container size.
455 pending_damage_buffer_ =
456 GetDamageBufferWithSizeParams(&auto_size_params,
457 &resize_guest_params);
458 }
459 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK(
460 render_view_routing_id_,
461 instance_id_,
462 message_id,
463 auto_size_params,
464 resize_guest_params));
269 return; 465 return;
270 466 }
271 WebKit::WebElement element = container()->element(); 467
272 WebKit::WebString web_attribute_name = 468 if (auto_size_ && (params.view_size != last_view_size_)) {
273 WebKit::WebString::fromUTF8(attribute_name); 469 if (backing_store_)
274 std::string current_value(element.getAttribute(web_attribute_name).utf8()); 470 backing_store_->Clear(SK_ColorWHITE);
275 if (current_value == attribute_value) 471 gfx::Size old_view_size = last_view_size_;
276 return; 472 last_view_size_ = params.view_size;
277 473 // Schedule a SizeChanged instead of calling it directly to ensure that
278 if (attribute_value.empty()) { 474 // the backing store has been updated before the developer attempts to
279 element.removeAttribute(web_attribute_name); 475 // resize to avoid flicker. |size_changed_in_flight_| acts as a form of
280 } else { 476 // flow control for SizeChanged events. If the guest's view size is changing
281 element.setAttribute(web_attribute_name, 477 // rapidly before a SizeChanged event fires, then we avoid scheduling
282 WebKit::WebString::fromUTF8(attribute_value)); 478 // another SizeChanged event. SizeChanged reads the new size from
283 } 479 // |last_view_size_| so we can be sure that it always fires an event
480 // with the last seen view size.
481 if (container_ && !size_changed_in_flight_) {
482 size_changed_in_flight_ = true;
483 MessageLoop::current()->PostTask(
484 FROM_HERE,
485 base::Bind(&BrowserPlugin::SizeChangedDueToAutoSize,
486 base::Unretained(this),
487 old_view_size));
488 }
489 }
490
491 // If we are now using a new damage buffer, then that means that the guest
492 // has updated its size state in response to a resize request. We change
493 // the backing store's size to accomodate the new damage buffer size.
494 if (use_new_damage_buffer) {
495 int backing_store_width = auto_size_ ? max_width_ : width();
496 int backing_store_height = auto_size_ ? max_height_: height();
497 backing_store_.reset(
498 new BrowserPluginBackingStore(
499 gfx::Size(backing_store_width, backing_store_height),
500 params.scale_factor));
501 }
502
503 // Update the backing store.
504 if (!params.scroll_rect.IsEmpty()) {
505 backing_store_->ScrollBackingStore(params.scroll_delta,
506 params.scroll_rect,
507 params.view_size);
508 }
509 for (unsigned i = 0; i < params.copy_rects.size(); i++) {
510 backing_store_->PaintToBackingStore(params.bitmap_rect,
511 params.copy_rects,
512 current_damage_buffer_);
513 }
514 // Invalidate the container.
515 // If the BrowserPlugin is scheduled to be deleted, then container_ will be
516 // NULL so we shouldn't attempt to access it.
517 if (container_)
518 container_->invalidate();
519 PopulateAutoSizeParameters(&auto_size_params);
520 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK(
521 render_view_routing_id_,
522 instance_id_,
523 message_id,
524 auto_size_params,
525 resize_guest_params));
284 } 526 }
285 527
286 void BrowserPlugin::SetMaxHeightAttribute(int max_height) { 528 void BrowserPlugin::SetMaxHeightAttribute(int max_height) {
287 if (max_height_ == max_height) 529 if (max_height_ == max_height)
288 return; 530 return;
289 max_height_ = max_height; 531 max_height_ = max_height;
290 if (!auto_size_) 532 if (!auto_size_)
291 return; 533 return;
292 UpdateGuestAutoSizeState(); 534 UpdateGuestAutoSizeState();
293 } 535 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 } 731 }
490 732
491 void BrowserPlugin::Reload() { 733 void BrowserPlugin::Reload() {
492 if (!navigate_src_sent_) 734 if (!navigate_src_sent_)
493 return; 735 return;
494 browser_plugin_manager()->Send( 736 browser_plugin_manager()->Send(
495 new BrowserPluginHostMsg_Reload(render_view_routing_id_, 737 new BrowserPluginHostMsg_Reload(render_view_routing_id_,
496 instance_id_)); 738 instance_id_));
497 } 739 }
498 740
499 void BrowserPlugin::SetCursor(const WebCursor& cursor) {
500 cursor_ = cursor;
501 }
502
503 void BrowserPlugin::UpdateRect(
504 int message_id,
505 const BrowserPluginMsg_UpdateRect_Params& params) {
506 bool use_new_damage_buffer = !backing_store_;
507 BrowserPluginHostMsg_AutoSize_Params auto_size_params;
508 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params;
509 // If we have a pending damage buffer, and the guest has begun to use the
510 // damage buffer then we know the guest will no longer use the current
511 // damage buffer. At this point, we drop the current damage buffer, and
512 // mark the pending damage buffer as the current damage buffer.
513 if (DamageBufferMatches(pending_damage_buffer_,
514 params.damage_buffer_identifier)) {
515 SwapDamageBuffers();
516 use_new_damage_buffer = true;
517 }
518 if ((!auto_size_ &&
519 (width() != params.view_size.width() ||
520 height() != params.view_size.height())) ||
521 (auto_size_ && (!InAutoSizeBounds(params.view_size)))) {
522 if (pending_damage_buffer_) {
523 // The guest has not yet responded to the last resize request, and
524 // so we don't want to do anything at this point other than ACK the guest.
525 PopulateAutoSizeParameters(&auto_size_params);
526 } else {
527 // If we have no pending damage buffer, then the guest has not caught up
528 // with the BrowserPlugin container. We now tell the guest about the new
529 // container size.
530 pending_damage_buffer_ =
531 GetDamageBufferWithSizeParams(&auto_size_params,
532 &resize_guest_params);
533 }
534 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK(
535 render_view_routing_id_,
536 instance_id_,
537 message_id,
538 auto_size_params,
539 resize_guest_params));
540 return;
541 }
542
543 if (auto_size_ && (params.view_size != last_view_size_)) {
544 if (backing_store_)
545 backing_store_->Clear(SK_ColorWHITE);
546 gfx::Size old_view_size = last_view_size_;
547 last_view_size_ = params.view_size;
548 // Schedule a SizeChanged instead of calling it directly to ensure that
549 // the backing store has been updated before the developer attempts to
550 // resize to avoid flicker. |size_changed_in_flight_| acts as a form of
551 // flow control for SizeChanged events. If the guest's view size is changing
552 // rapidly before a SizeChanged event fires, then we avoid scheduling
553 // another SizeChanged event. SizeChanged reads the new size from
554 // |last_view_size_| so we can be sure that it always fires an event
555 // with the last seen view size.
556 if (container_ && !size_changed_in_flight_) {
557 size_changed_in_flight_ = true;
558 MessageLoop::current()->PostTask(
559 FROM_HERE,
560 base::Bind(&BrowserPlugin::SizeChangedDueToAutoSize,
561 base::Unretained(this),
562 old_view_size));
563 }
564 }
565
566 // If we are now using a new damage buffer, then that means that the guest
567 // has updated its size state in response to a resize request. We change
568 // the backing store's size to accomodate the new damage buffer size.
569 if (use_new_damage_buffer) {
570 int backing_store_width = auto_size_ ? max_width_ : width();
571 int backing_store_height = auto_size_ ? max_height_: height();
572 backing_store_.reset(
573 new BrowserPluginBackingStore(
574 gfx::Size(backing_store_width, backing_store_height),
575 params.scale_factor));
576 }
577
578 // Update the backing store.
579 if (!params.scroll_rect.IsEmpty()) {
580 backing_store_->ScrollBackingStore(params.scroll_delta,
581 params.scroll_rect,
582 params.view_size);
583 }
584 for (unsigned i = 0; i < params.copy_rects.size(); i++) {
585 backing_store_->PaintToBackingStore(params.bitmap_rect,
586 params.copy_rects,
587 current_damage_buffer_);
588 }
589 // Invalidate the container.
590 // If the BrowserPlugin is scheduled to be deleted, then container_ will be
591 // NULL so we shouldn't attempt to access it.
592 if (container_)
593 container_->invalidate();
594 PopulateAutoSizeParameters(&auto_size_params);
595 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK(
596 render_view_routing_id_,
597 instance_id_,
598 message_id,
599 auto_size_params,
600 resize_guest_params));
601 }
602
603 void BrowserPlugin::GuestGone(int process_id, base::TerminationStatus status) {
604 // We fire the event listeners before painting the sad graphic to give the
605 // developer an opportunity to display an alternative overlay image on crash.
606 std::string termination_status = TerminationStatusToString(status);
607 std::map<std::string, base::Value*> props;
608 props[kProcessId] = base::Value::CreateIntegerValue(process_id);
609 props[kReason] = base::Value::CreateStringValue(termination_status);
610
611 // Event listeners may remove the BrowserPlugin from the document. If that
612 // happens, the BrowserPlugin will be scheduled for later deletion (see
613 // BrowserPlugin::destroy()). That will clear the container_ reference,
614 // but leave other member variables valid below.
615 TriggerEvent(kEventExit, &props);
616
617 guest_crashed_ = true;
618 // We won't paint the contents of the current backing store again so we might
619 // as well toss it out and save memory.
620 backing_store_.reset();
621 // If the BrowserPlugin is scheduled to be deleted, then container_ will be
622 // NULL so we shouldn't attempt to access it.
623 if (container_)
624 container_->invalidate();
625 }
626
627 void BrowserPlugin::GuestUnresponsive(int process_id) {
628 std::map<std::string, base::Value*> props;
629 props[kProcessId] = base::Value::CreateIntegerValue(process_id);
630 TriggerEvent(kEventUnresponsive, &props);
631 }
632
633 void BrowserPlugin::GuestResponsive(int process_id) {
634 std::map<std::string, base::Value*> props;
635 props[kProcessId] = base::Value::CreateIntegerValue(process_id);
636 TriggerEvent(kEventResponsive, &props);
637 }
638
639 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) {
640 std::map<std::string, base::Value*> props;
641 props[kURL] = base::Value::CreateStringValue(url.spec());
642 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level);
643
644 TriggerEvent(kEventLoadStart, &props);
645 }
646
647 void BrowserPlugin::LoadCommit(
648 const BrowserPluginMsg_LoadCommit_Params& params) {
649 // If the guest has just committed a new navigation then it is no longer
650 // crashed.
651 guest_crashed_ = false;
652 if (params.is_top_level) {
653 src_ = params.url.spec();
654 UpdateDOMAttribute(kSrc, src_.c_str());
655 }
656 process_id_ = params.process_id;
657 current_nav_entry_index_ = params.current_entry_index;
658 nav_entry_count_ = params.entry_count;
659
660 std::map<std::string, base::Value*> props;
661 props[kURL] = base::Value::CreateStringValue(params.url.spec());
662 props[kIsTopLevel] = base::Value::CreateBooleanValue(params.is_top_level);
663 TriggerEvent(kEventLoadCommit, &props);
664 }
665
666 void BrowserPlugin::LoadStop() {
667 // Construct the loadStop event object.
668 TriggerEvent(kEventLoadStop, NULL);
669 }
670
671 void BrowserPlugin::LoadAbort(const GURL& url,
672 bool is_top_level,
673 const std::string& type) {
674 std::map<std::string, base::Value*> props;
675 props[kURL] = base::Value::CreateStringValue(url.spec());
676 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level);
677 props[kReason] = base::Value::CreateStringValue(type);
678 TriggerEvent(kEventLoadAbort, &props);
679 }
680
681 void BrowserPlugin::LoadRedirect(const GURL& old_url,
682 const GURL& new_url,
683 bool is_top_level) {
684 std::map<std::string, base::Value*> props;
685 props[kOldURL] = base::Value::CreateStringValue(old_url.spec());
686 props[kNewURL] = base::Value::CreateStringValue(new_url.spec());
687 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level);
688 TriggerEvent(kEventLoadRedirect, &props);
689 }
690
691 void BrowserPlugin::AdvanceFocus(bool reverse) {
692 DCHECK(render_view_);
693 render_view_->GetWebView()->advanceFocus(reverse);
694 }
695
696 void BrowserPlugin::SetEmbedderFocus(bool focused) { 741 void BrowserPlugin::SetEmbedderFocus(bool focused) {
697 if (embedder_focused_ == focused) 742 if (embedder_focused_ == focused)
698 return; 743 return;
699 744
700 bool old_guest_focus_state = ShouldGuestBeFocused(); 745 bool old_guest_focus_state = ShouldGuestBeFocused();
701 embedder_focused_ = focused; 746 embedder_focused_ = focused;
702 747
703 if (ShouldGuestBeFocused() != old_guest_focus_state) 748 if (ShouldGuestBeFocused() != old_guest_focus_state)
704 UpdateGuestFocusState(); 749 UpdateGuestFocusState();
705 } 750 }
706 751
707 void BrowserPlugin::UpdateGuestFocusState() { 752 void BrowserPlugin::UpdateGuestFocusState() {
708 if (!navigate_src_sent_) 753 if (!navigate_src_sent_)
709 return; 754 return;
710 bool should_be_focused = ShouldGuestBeFocused(); 755 bool should_be_focused = ShouldGuestBeFocused();
711 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( 756 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus(
712 render_view_routing_id_, 757 render_view_routing_id_,
713 instance_id_, 758 instance_id_,
714 should_be_focused)); 759 should_be_focused));
715 } 760 }
716 761
717 bool BrowserPlugin::ShouldGuestBeFocused() const { 762 bool BrowserPlugin::ShouldGuestBeFocused() const {
718 return plugin_focused_ && embedder_focused_; 763 return plugin_focused_ && embedder_focused_;
719 } 764 }
720 765
721 void BrowserPlugin::GuestContentWindowReady(int content_window_routing_id) {
722 DCHECK(content_window_routing_id != MSG_ROUTING_NONE);
723 content_window_routing_id_ = content_window_routing_id;
724 }
725
726 void BrowserPlugin::SetAcceptTouchEvents(bool accept) {
727 if (container()) {
728 container()->requestTouchEventType(accept ?
729 WebKit::WebPluginContainer::TouchEventRequestTypeRaw :
730 WebKit::WebPluginContainer::TouchEventRequestTypeNone);
731 }
732 }
733
734 WebKit::WebPluginContainer* BrowserPlugin::container() const { 766 WebKit::WebPluginContainer* BrowserPlugin::container() const {
735 return container_; 767 return container_;
736 } 768 }
737 769
738 bool BrowserPlugin::initialize(WebPluginContainer* container) { 770 bool BrowserPlugin::initialize(WebPluginContainer* container) {
739 container_ = container; 771 container_ = container;
740 container_->setWantsWheelEvents(true); 772 container_->setWantsWheelEvents(true);
741 return true; 773 return true;
742 } 774 }
743 775
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 void* notify_data) { 1048 void* notify_data) {
1017 } 1049 }
1018 1050
1019 void BrowserPlugin::didFailLoadingFrameRequest( 1051 void BrowserPlugin::didFailLoadingFrameRequest(
1020 const WebKit::WebURL& url, 1052 const WebKit::WebURL& url,
1021 void* notify_data, 1053 void* notify_data,
1022 const WebKit::WebURLError& error) { 1054 const WebKit::WebURLError& error) {
1023 } 1055 }
1024 1056
1025 } // namespace content 1057 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698