OLD | NEW |
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/render_view_impl.h" | 5 #include "content/renderer/render_view_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 static const float kScalingIncrement = 0.1f; | 352 static const float kScalingIncrement = 0.1f; |
353 | 353 |
354 static const float kScalingIncrementForGesture = 0.01f; | 354 static const float kScalingIncrementForGesture = 0.01f; |
355 | 355 |
356 #if defined(OS_ANDROID) | 356 #if defined(OS_ANDROID) |
357 // Delay between tapping in content and launching the associated android intent. | 357 // Delay between tapping in content and launching the associated android intent. |
358 // Used to allow users see what has been recognized as content. | 358 // Used to allow users see what has been recognized as content. |
359 static const size_t kContentIntentDelayMilliseconds = 700; | 359 static const size_t kContentIntentDelayMilliseconds = 700; |
360 #endif | 360 #endif |
361 | 361 |
| 362 static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) = |
| 363 NULL; |
| 364 |
362 static RenderViewImpl* FromRoutingID(int32 routing_id) { | 365 static RenderViewImpl* FromRoutingID(int32 routing_id) { |
363 return static_cast<RenderViewImpl*>( | 366 return static_cast<RenderViewImpl*>( |
364 ChildThread::current()->ResolveRoute(routing_id)); | 367 ChildThread::current()->ResolveRoute(routing_id)); |
365 } | 368 } |
366 | 369 |
367 static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) { | 370 static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) { |
368 for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) { | 371 for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) { |
369 if (frame->identifier() == frame_id) | 372 if (frame->identifier() == frame_id) |
370 return frame; | 373 return frame; |
371 } | 374 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 return -1; | 532 return -1; |
530 | 533 |
531 if (item.httpBody().isNull()) | 534 if (item.httpBody().isNull()) |
532 return -1; | 535 return -1; |
533 | 536 |
534 return item.httpBody().identifier(); | 537 return item.httpBody().identifier(); |
535 } | 538 } |
536 | 539 |
537 } // namespace | 540 } // namespace |
538 | 541 |
539 RenderViewImpl::RenderViewImpl( | 542 RenderViewImplParams::RenderViewImplParams( |
540 int32 opener_id, | 543 int32 opener_id, |
541 const RendererPreferences& renderer_prefs, | 544 const RendererPreferences& renderer_prefs, |
542 const WebPreferences& webkit_prefs, | 545 const WebPreferences& webkit_prefs, |
543 SharedRenderViewCounter* counter, | 546 SharedRenderViewCounter* counter, |
544 int32 routing_id, | 547 int32 routing_id, |
545 int32 surface_id, | 548 int32 surface_id, |
546 int64 session_storage_namespace_id, | 549 int64 session_storage_namespace_id, |
547 const string16& frame_name, | 550 const string16& frame_name, |
548 bool is_renderer_created, | 551 bool is_renderer_created, |
549 bool swapped_out, | 552 bool swapped_out, |
550 int32 next_page_id, | 553 int32 next_page_id, |
551 const WebKit::WebScreenInfo& screen_info, | 554 const WebKit::WebScreenInfo& screen_info, |
552 AccessibilityMode accessibility_mode) | 555 AccessibilityMode accessibility_mode) |
553 : RenderWidget(WebKit::WebPopupTypeNone, screen_info, swapped_out), | 556 : opener_id(opener_id), |
554 webkit_preferences_(webkit_prefs), | 557 renderer_prefs(renderer_prefs), |
| 558 webkit_prefs(webkit_prefs), |
| 559 counter(counter), |
| 560 routing_id(routing_id), |
| 561 surface_id(surface_id), |
| 562 session_storage_namespace_id(session_storage_namespace_id), |
| 563 frame_name(frame_name), |
| 564 is_renderer_created(is_renderer_created), |
| 565 swapped_out(swapped_out), |
| 566 next_page_id(next_page_id), |
| 567 screen_info(screen_info), |
| 568 accessibility_mode(accessibility_mode) { |
| 569 } |
| 570 |
| 571 RenderViewImplParams::~RenderViewImplParams() {} |
| 572 |
| 573 RenderViewImpl::RenderViewImpl(RenderViewImplParams* params) |
| 574 : RenderWidget(WebKit::WebPopupTypeNone, |
| 575 params->screen_info, |
| 576 params->swapped_out), |
| 577 webkit_preferences_(params->webkit_prefs), |
555 send_content_state_immediately_(false), | 578 send_content_state_immediately_(false), |
556 enabled_bindings_(0), | 579 enabled_bindings_(0), |
557 send_preferred_size_changes_(false), | 580 send_preferred_size_changes_(false), |
558 is_loading_(false), | 581 is_loading_(false), |
559 navigation_gesture_(NavigationGestureUnknown), | 582 navigation_gesture_(NavigationGestureUnknown), |
560 opened_by_user_gesture_(true), | 583 opened_by_user_gesture_(true), |
561 opener_suppressed_(false), | 584 opener_suppressed_(false), |
562 page_id_(-1), | 585 page_id_(-1), |
563 last_page_id_sent_to_browser_(-1), | 586 last_page_id_sent_to_browser_(-1), |
564 next_page_id_(next_page_id), | 587 next_page_id_(params->next_page_id), |
565 history_list_offset_(-1), | 588 history_list_offset_(-1), |
566 history_list_length_(0), | 589 history_list_length_(0), |
567 target_url_status_(TARGET_NONE), | 590 target_url_status_(TARGET_NONE), |
568 selection_text_offset_(0), | 591 selection_text_offset_(0), |
569 cached_is_main_frame_pinned_to_left_(false), | 592 cached_is_main_frame_pinned_to_left_(false), |
570 cached_is_main_frame_pinned_to_right_(false), | 593 cached_is_main_frame_pinned_to_right_(false), |
571 cached_has_main_frame_horizontal_scrollbar_(false), | 594 cached_has_main_frame_horizontal_scrollbar_(false), |
572 cached_has_main_frame_vertical_scrollbar_(false), | 595 cached_has_main_frame_vertical_scrollbar_(false), |
573 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), | 596 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
574 geolocation_dispatcher_(NULL), | 597 geolocation_dispatcher_(NULL), |
575 input_tag_speech_dispatcher_(NULL), | 598 input_tag_speech_dispatcher_(NULL), |
576 speech_recognition_dispatcher_(NULL), | 599 speech_recognition_dispatcher_(NULL), |
577 device_orientation_dispatcher_(NULL), | 600 device_orientation_dispatcher_(NULL), |
578 media_stream_dispatcher_(NULL), | 601 media_stream_dispatcher_(NULL), |
579 media_stream_impl_(NULL), | 602 media_stream_impl_(NULL), |
580 devtools_agent_(NULL), | 603 devtools_agent_(NULL), |
581 accessibility_mode_(AccessibilityModeOff), | 604 accessibility_mode_(AccessibilityModeOff), |
582 renderer_accessibility_(NULL), | 605 renderer_accessibility_(NULL), |
583 java_bridge_dispatcher_(NULL), | 606 java_bridge_dispatcher_(NULL), |
584 mouse_lock_dispatcher_(NULL), | 607 mouse_lock_dispatcher_(NULL), |
585 #if defined(OS_ANDROID) | 608 #if defined(OS_ANDROID) |
586 body_background_color_(SK_ColorWHITE), | 609 body_background_color_(SK_ColorWHITE), |
587 update_frame_info_scheduled_(false), | 610 update_frame_info_scheduled_(false), |
588 expected_content_intent_id_(0), | 611 expected_content_intent_id_(0), |
589 media_player_proxy_(NULL), | 612 media_player_proxy_(NULL), |
590 synchronous_find_active_match_ordinal_(-1), | 613 synchronous_find_active_match_ordinal_(-1), |
591 ALLOW_THIS_IN_INITIALIZER_LIST( | 614 ALLOW_THIS_IN_INITIALIZER_LIST( |
592 load_progress_tracker_(new LoadProgressTracker(this))), | 615 load_progress_tracker_(new LoadProgressTracker(this))), |
593 #endif | 616 #endif |
594 session_storage_namespace_id_(session_storage_namespace_id), | 617 session_storage_namespace_id_(params->session_storage_namespace_id), |
595 handling_select_range_(false), | 618 handling_select_range_(false), |
596 #if defined(OS_WIN) | 619 #if defined(OS_WIN) |
597 focused_plugin_id_(-1), | 620 focused_plugin_id_(-1), |
598 #endif | 621 #endif |
599 updating_frame_tree_(false), | 622 updating_frame_tree_(false), |
600 pending_frame_tree_update_(false), | 623 pending_frame_tree_update_(false), |
601 target_process_id_(0), | 624 target_process_id_(0), |
602 target_routing_id_(0), | 625 target_routing_id_(0), |
603 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { | 626 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { |
604 set_throttle_input_events(renderer_prefs.throttle_input_events); | 627 set_throttle_input_events(params->renderer_prefs.throttle_input_events); |
605 routing_id_ = routing_id; | 628 routing_id_ = params->routing_id; |
606 surface_id_ = surface_id; | 629 surface_id_ = params->surface_id; |
607 if (opener_id != MSG_ROUTING_NONE && is_renderer_created) | 630 if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created) |
608 opener_id_ = opener_id; | 631 opener_id_ = params->opener_id; |
609 | 632 |
610 // Ensure we start with a valid next_page_id_ from the browser. | 633 // Ensure we start with a valid next_page_id_ from the browser. |
611 DCHECK_GE(next_page_id_, 0); | 634 DCHECK_GE(next_page_id_, 0); |
612 | 635 |
613 #if defined(ENABLE_NOTIFICATIONS) | 636 #if defined(ENABLE_NOTIFICATIONS) |
614 notification_provider_ = new NotificationProvider(this); | 637 notification_provider_ = new NotificationProvider(this); |
615 #else | 638 #else |
616 notification_provider_ = NULL; | 639 notification_provider_ = NULL; |
617 #endif | 640 #endif |
618 | 641 |
(...skipping 12 matching lines...) Expand all Loading... |
631 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso) | 654 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso) |
632 : device_info->GetNetworkCountryIso(); | 655 : device_info->GetNetworkCountryIso(); |
633 content_detectors_.push_back(linked_ptr<ContentDetector>( | 656 content_detectors_.push_back(linked_ptr<ContentDetector>( |
634 new AddressDetector())); | 657 new AddressDetector())); |
635 content_detectors_.push_back(linked_ptr<ContentDetector>( | 658 content_detectors_.push_back(linked_ptr<ContentDetector>( |
636 new PhoneNumberDetector(region_code))); | 659 new PhoneNumberDetector(region_code))); |
637 content_detectors_.push_back(linked_ptr<ContentDetector>( | 660 content_detectors_.push_back(linked_ptr<ContentDetector>( |
638 new EmailDetector())); | 661 new EmailDetector())); |
639 #endif | 662 #endif |
640 | 663 |
641 if (counter) { | 664 if (params->counter) { |
642 shared_popup_counter_ = counter; | 665 shared_popup_counter_ = params->counter; |
643 // Only count this if it isn't swapped out upon creation. | 666 // Only count this if it isn't swapped out upon creation. |
644 if (!swapped_out) | 667 if (!params->swapped_out) |
645 shared_popup_counter_->data++; | 668 shared_popup_counter_->data++; |
646 decrement_shared_popup_at_destruction_ = true; | 669 decrement_shared_popup_at_destruction_ = true; |
647 } else { | 670 } else { |
648 shared_popup_counter_ = new SharedRenderViewCounter(0); | 671 shared_popup_counter_ = new SharedRenderViewCounter(0); |
649 decrement_shared_popup_at_destruction_ = false; | 672 decrement_shared_popup_at_destruction_ = false; |
650 } | 673 } |
651 | 674 |
652 RenderThread::Get()->AddRoute(routing_id_, this); | 675 RenderThread::Get()->AddRoute(routing_id_, this); |
653 // Take a reference on behalf of the RenderThread. This will be balanced | 676 // Take a reference on behalf of the RenderThread. This will be balanced |
654 // when we receive ViewMsg_ClosePage. | 677 // when we receive ViewMsg_ClosePage. |
655 AddRef(); | 678 AddRef(); |
656 | 679 |
657 // If this is a popup, we must wait for the CreatingNew_ACK message before | 680 // If this is a popup, we must wait for the CreatingNew_ACK message before |
658 // completing initialization. Otherwise, we can finish it now. | 681 // completing initialization. Otherwise, we can finish it now. |
659 if (opener_id_ == MSG_ROUTING_NONE) { | 682 if (opener_id_ == MSG_ROUTING_NONE) { |
660 did_show_ = true; | 683 did_show_ = true; |
661 CompleteInit(); | 684 CompleteInit(); |
662 } | 685 } |
663 | 686 |
664 g_view_map.Get().insert(std::make_pair(webview(), this)); | 687 g_view_map.Get().insert(std::make_pair(webview(), this)); |
665 webview()->setDeviceScaleFactor(device_scale_factor_); | 688 webview()->setDeviceScaleFactor(device_scale_factor_); |
666 webkit_preferences_.Apply(webview()); | 689 webkit_preferences_.Apply(webview()); |
667 webview()->initializeMainFrame(this); | 690 webview()->initializeMainFrame(this); |
668 if (!frame_name.empty()) | 691 if (!params->frame_name.empty()) |
669 webview()->mainFrame()->setName(frame_name); | 692 webview()->mainFrame()->setName(params->frame_name); |
670 webview()->settings()->setMinimumTimerInterval( | 693 webview()->settings()->setMinimumTimerInterval( |
671 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval : | 694 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval : |
672 webkit_glue::kForegroundTabTimerInterval); | 695 webkit_glue::kForegroundTabTimerInterval); |
673 | 696 |
674 OnSetRendererPrefs(renderer_prefs); | 697 OnSetRendererPrefs(params->renderer_prefs); |
675 | 698 |
676 #if defined(ENABLE_WEBRTC) | 699 #if defined(ENABLE_WEBRTC) |
677 if (!media_stream_dispatcher_) | 700 if (!media_stream_dispatcher_) |
678 media_stream_dispatcher_ = new MediaStreamDispatcher(this); | 701 media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
679 #endif | 702 #endif |
680 | 703 |
681 new MHTMLGenerator(this); | 704 new MHTMLGenerator(this); |
682 #if defined(OS_MACOSX) | 705 #if defined(OS_MACOSX) |
683 new TextInputClientObserver(this); | 706 new TextInputClientObserver(this); |
684 #endif // defined(OS_MACOSX) | 707 #endif // defined(OS_MACOSX) |
685 | 708 |
686 #if defined(OS_ANDROID) | 709 #if defined(OS_ANDROID) |
687 media_player_manager_.reset( | 710 media_player_manager_.reset( |
688 new webkit_media::WebMediaPlayerManagerAndroid()); | 711 new webkit_media::WebMediaPlayerManagerAndroid()); |
689 #endif | 712 #endif |
690 | 713 |
691 // The next group of objects all implement RenderViewObserver, so are deleted | 714 // The next group of objects all implement RenderViewObserver, so are deleted |
692 // along with the RenderView automatically. | 715 // along with the RenderView automatically. |
693 devtools_agent_ = new DevToolsAgent(this); | 716 devtools_agent_ = new DevToolsAgent(this); |
694 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this); | 717 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this); |
695 intents_host_ = new WebIntentsHost(this); | 718 intents_host_ = new WebIntentsHost(this); |
696 | 719 |
697 // Create renderer_accessibility_ if needed. | 720 // Create renderer_accessibility_ if needed. |
698 OnSetAccessibilityMode(accessibility_mode); | 721 OnSetAccessibilityMode(params->accessibility_mode); |
699 | 722 |
700 new IdleUserDetector(this); | 723 new IdleUserDetector(this); |
701 | 724 |
702 if (command_line.HasSwitch(switches::kDomAutomationController)) | 725 if (command_line.HasSwitch(switches::kDomAutomationController)) |
703 enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION; | 726 enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION; |
704 | 727 |
705 ProcessViewLayoutFlags(command_line); | 728 ProcessViewLayoutFlags(command_line); |
706 | 729 |
707 GetContentClient()->renderer()->RenderViewCreated(this); | 730 GetContentClient()->renderer()->RenderViewCreated(this); |
708 | 731 |
709 // If we have an opener_id but we weren't created by a renderer, then | 732 // If we have an opener_id but we weren't created by a renderer, then |
710 // it's the browser asking us to set our opener to another RenderView. | 733 // it's the browser asking us to set our opener to another RenderView. |
711 if (opener_id != MSG_ROUTING_NONE && !is_renderer_created) { | 734 if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) { |
712 RenderViewImpl* opener_view = FromRoutingID(opener_id); | 735 RenderViewImpl* opener_view = FromRoutingID(params->opener_id); |
713 if (opener_view) | 736 if (opener_view) |
714 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); | 737 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); |
715 } | 738 } |
716 | 739 |
717 // If we are initially swapped out, navigate to kSwappedOutURL. | 740 // If we are initially swapped out, navigate to kSwappedOutURL. |
718 // This ensures we are in a unique origin that others cannot script. | 741 // This ensures we are in a unique origin that others cannot script. |
719 if (is_swapped_out_) | 742 if (is_swapped_out_) |
720 NavigateToSwappedOutURL(webview()->mainFrame()); | 743 NavigateToSwappedOutURL(webview()->mainFrame()); |
721 } | 744 } |
722 | 745 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 int32 routing_id, | 809 int32 routing_id, |
787 int32 surface_id, | 810 int32 surface_id, |
788 int64 session_storage_namespace_id, | 811 int64 session_storage_namespace_id, |
789 const string16& frame_name, | 812 const string16& frame_name, |
790 bool is_renderer_created, | 813 bool is_renderer_created, |
791 bool swapped_out, | 814 bool swapped_out, |
792 int32 next_page_id, | 815 int32 next_page_id, |
793 const WebKit::WebScreenInfo& screen_info, | 816 const WebKit::WebScreenInfo& screen_info, |
794 AccessibilityMode accessibility_mode) { | 817 AccessibilityMode accessibility_mode) { |
795 DCHECK(routing_id != MSG_ROUTING_NONE); | 818 DCHECK(routing_id != MSG_ROUTING_NONE); |
796 return new RenderViewImpl( | 819 RenderViewImplParams params( |
797 opener_id, | 820 opener_id, |
798 renderer_prefs, | 821 renderer_prefs, |
799 webkit_prefs, | 822 webkit_prefs, |
800 counter, | 823 counter, |
801 routing_id, | 824 routing_id, |
802 surface_id, | 825 surface_id, |
803 session_storage_namespace_id, | 826 session_storage_namespace_id, |
804 frame_name, | 827 frame_name, |
805 is_renderer_created, | 828 is_renderer_created, |
806 swapped_out, | 829 swapped_out, |
807 next_page_id, | 830 next_page_id, |
808 screen_info, | 831 screen_info, |
809 accessibility_mode); | 832 accessibility_mode); |
| 833 if (g_create_render_view_impl) |
| 834 return g_create_render_view_impl(¶ms); |
| 835 return new RenderViewImpl(¶ms); |
| 836 } |
| 837 |
| 838 // static |
| 839 void RenderViewImpl::InstallCreateHook( |
| 840 RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) { |
| 841 CHECK(!g_create_render_view_impl); |
| 842 g_create_render_view_impl = create_render_view_impl; |
810 } | 843 } |
811 | 844 |
812 void RenderViewImpl::AddObserver(RenderViewObserver* observer) { | 845 void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
813 observers_.AddObserver(observer); | 846 observers_.AddObserver(observer); |
814 } | 847 } |
815 | 848 |
816 void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { | 849 void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
817 observer->RenderViewGone(); | 850 observer->RenderViewGone(); |
818 observers_.RemoveObserver(observer); | 851 observers_.RemoveObserver(observer); |
819 } | 852 } |
(...skipping 5541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6361 } | 6394 } |
6362 #endif | 6395 #endif |
6363 | 6396 |
6364 void RenderViewImpl::OnReleaseDisambiguationPopupDIB( | 6397 void RenderViewImpl::OnReleaseDisambiguationPopupDIB( |
6365 TransportDIB::Handle dib_handle) { | 6398 TransportDIB::Handle dib_handle) { |
6366 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); | 6399 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); |
6367 RenderProcess::current()->ReleaseTransportDIB(dib); | 6400 RenderProcess::current()->ReleaseTransportDIB(dib); |
6368 } | 6401 } |
6369 | 6402 |
6370 } // namespace content | 6403 } // namespace content |
OLD | NEW |