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 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 blink::WebPopupTypeNone, | 663 blink::WebPopupTypeNone, |
664 params.initial_size.screen_info, | 664 params.initial_size.screen_info, |
665 params.swapped_out, | 665 params.swapped_out, |
666 params.hidden, | 666 params.hidden, |
667 params.never_visible), | 667 params.never_visible), |
668 webkit_preferences_(params.web_preferences), | 668 webkit_preferences_(params.web_preferences), |
669 send_content_state_immediately_(false), | 669 send_content_state_immediately_(false), |
670 enabled_bindings_(0), | 670 enabled_bindings_(0), |
671 send_preferred_size_changes_(false), | 671 send_preferred_size_changes_(false), |
672 navigation_gesture_(NavigationGestureUnknown), | 672 navigation_gesture_(NavigationGestureUnknown), |
673 opened_by_user_gesture_(true), | |
674 history_list_offset_(-1), | 673 history_list_offset_(-1), |
675 history_list_length_(0), | 674 history_list_length_(0), |
676 frames_in_progress_(0), | 675 frames_in_progress_(0), |
677 target_url_status_(TARGET_NONE), | 676 target_url_status_(TARGET_NONE), |
678 uses_temporary_zoom_level_(false), | 677 uses_temporary_zoom_level_(false), |
679 #if defined(OS_ANDROID) | 678 #if defined(OS_ANDROID) |
680 top_controls_constraints_(BROWSER_CONTROLS_STATE_BOTH), | 679 top_controls_constraints_(BROWSER_CONTROLS_STATE_BOTH), |
681 #endif | 680 #endif |
682 browser_controls_shrink_blink_size_(false), | 681 browser_controls_shrink_blink_size_(false), |
683 top_controls_height_(0.f), | 682 top_controls_height_(0.f), |
684 webview_(nullptr), | 683 webview_(nullptr), |
685 has_scrolled_focused_editable_node_into_rect_(false), | 684 has_scrolled_focused_editable_node_into_rect_(false), |
686 page_zoom_level_(params.page_zoom_level), | 685 page_zoom_level_(params.page_zoom_level), |
687 main_render_frame_(nullptr), | 686 main_render_frame_(nullptr), |
688 frame_widget_(nullptr), | 687 frame_widget_(nullptr), |
689 speech_recognition_dispatcher_(NULL), | 688 speech_recognition_dispatcher_(NULL), |
690 #if defined(OS_ANDROID) | 689 #if defined(OS_ANDROID) |
691 expected_content_intent_id_(0), | 690 expected_content_intent_id_(0), |
| 691 was_created_by_renderer_(false), |
692 #endif | 692 #endif |
693 enumeration_completion_id_(0), | 693 enumeration_completion_id_(0), |
694 session_storage_namespace_id_(params.session_storage_namespace_id), | 694 session_storage_namespace_id_(params.session_storage_namespace_id), |
695 has_added_input_handler_(false) { | 695 has_added_input_handler_(false) { |
696 GetWidget()->set_owner_delegate(this); | 696 GetWidget()->set_owner_delegate(this); |
697 } | 697 } |
698 | 698 |
699 void RenderViewImpl::Initialize(const mojom::CreateViewParams& params, | 699 void RenderViewImpl::Initialize( |
700 bool was_created_by_renderer) { | 700 const mojom::CreateViewParams& params, |
701 int opener_view_routing_id = MSG_ROUTING_NONE; | 701 const RenderWidget::ShowCallback& show_callback) { |
702 WebFrame* opener_frame = RenderFrameImpl::ResolveOpener( | 702 bool was_created_by_renderer = !show_callback.is_null(); |
703 params.opener_frame_route_id, &opener_view_routing_id); | 703 #if defined(OS_ANDROID) |
704 if (!was_created_by_renderer) | 704 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated |
705 opener_view_routing_id = MSG_ROUTING_NONE; | 705 // HandleNavigation codepath. |
| 706 was_created_by_renderer_ = was_created_by_renderer; |
| 707 #endif |
| 708 WebFrame* opener_frame = |
| 709 RenderFrameImpl::ResolveOpener(params.opener_frame_route_id, nullptr); |
706 | 710 |
707 display_mode_ = params.initial_size.display_mode; | 711 display_mode_ = params.initial_size.display_mode; |
708 | 712 |
709 webview_ = | 713 webview_ = |
710 WebView::create(this, is_hidden() ? blink::WebPageVisibilityStateHidden | 714 WebView::create(this, is_hidden() ? blink::WebPageVisibilityStateHidden |
711 : blink::WebPageVisibilityStateVisible); | 715 : blink::WebPageVisibilityStateVisible); |
712 RenderWidget::Init(opener_view_routing_id, webview_->widget()); | 716 RenderWidget::Init(show_callback, webview_->widget()); |
713 | 717 |
714 g_view_map.Get().insert(std::make_pair(webview(), this)); | 718 g_view_map.Get().insert(std::make_pair(webview(), this)); |
715 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this)); | 719 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this)); |
716 | 720 |
717 const base::CommandLine& command_line = | 721 const base::CommandLine& command_line = |
718 *base::CommandLine::ForCurrentProcess(); | 722 *base::CommandLine::ForCurrentProcess(); |
719 | 723 |
720 if (command_line.HasSwitch(switches::kStatsCollectionController)) | 724 if (command_line.HasSwitch(switches::kStatsCollectionController)) |
721 stats_collection_observer_.reset(new StatsCollectionObserver(this)); | 725 stats_collection_observer_.reset(new StatsCollectionObserver(this)); |
722 | 726 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 content_detectors_.push_back(base::MakeUnique<AddressDetector>()); | 798 content_detectors_.push_back(base::MakeUnique<AddressDetector>()); |
795 const std::string& contry_iso = | 799 const std::string& contry_iso = |
796 params.renderer_preferences.network_contry_iso; | 800 params.renderer_preferences.network_contry_iso; |
797 if (!contry_iso.empty()) { | 801 if (!contry_iso.empty()) { |
798 content_detectors_.push_back( | 802 content_detectors_.push_back( |
799 base::MakeUnique<PhoneNumberDetector>(contry_iso)); | 803 base::MakeUnique<PhoneNumberDetector>(contry_iso)); |
800 } | 804 } |
801 content_detectors_.push_back(base::MakeUnique<EmailDetector>()); | 805 content_detectors_.push_back(base::MakeUnique<EmailDetector>()); |
802 #endif | 806 #endif |
803 | 807 |
804 // If this is a popup, we must wait for the CreatingNew_ACK message before | 808 // If this RenderView's creation was initiated by an opener page in this |
805 // completing initialization. Otherwise, we can finish it now. | 809 // process, (e.g. window.open()), we won't be visible until we ask the opener, |
806 if (opener_id_ == MSG_ROUTING_NONE) | 810 // via show_callback, to make us visible. Otherwise, we went through a |
| 811 // browser-initiated creation, and show() won't be called. |
| 812 if (!was_created_by_renderer) |
807 did_show_ = true; | 813 did_show_ = true; |
808 | 814 |
809 // Set the main frame's name. Only needs to be done for WebLocalFrames, | 815 // Set the main frame's name. Only needs to be done for WebLocalFrames, |
810 // since the remote case was handled as part of SetReplicatedState on the | 816 // since the remote case was handled as part of SetReplicatedState on the |
811 // proxy above. | 817 // proxy above. |
812 if (!params.replicated_frame_state.name.empty() && | 818 if (!params.replicated_frame_state.name.empty() && |
813 webview()->mainFrame()->isWebLocalFrame()) { | 819 webview()->mainFrame()->isWebLocalFrame()) { |
814 webview()->mainFrame()->setName( | 820 webview()->mainFrame()->setName( |
815 blink::WebString::fromUTF8(params.replicated_frame_state.name)); | 821 blink::WebString::fromUTF8(params.replicated_frame_state.name)); |
816 } | 822 } |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 settings->setDoubleTapToZoomEnabled(true); | 1189 settings->setDoubleTapToZoomEnabled(true); |
1184 web_view->setMaximumLegibleScale(prefs.default_maximum_page_scale_factor); | 1190 web_view->setMaximumLegibleScale(prefs.default_maximum_page_scale_factor); |
1185 #endif | 1191 #endif |
1186 | 1192 |
1187 #if defined(OS_WIN) | 1193 #if defined(OS_WIN) |
1188 WebRuntimeFeatures::enableMiddleClickAutoscroll(true); | 1194 WebRuntimeFeatures::enableMiddleClickAutoscroll(true); |
1189 #endif | 1195 #endif |
1190 } | 1196 } |
1191 | 1197 |
1192 /*static*/ | 1198 /*static*/ |
1193 RenderViewImpl* RenderViewImpl::Create(CompositorDependencies* compositor_deps, | 1199 RenderViewImpl* RenderViewImpl::Create( |
1194 const mojom::CreateViewParams& params, | 1200 CompositorDependencies* compositor_deps, |
1195 bool was_created_by_renderer) { | 1201 const mojom::CreateViewParams& params, |
| 1202 const RenderWidget::ShowCallback& show_callback) { |
1196 DCHECK(params.view_id != MSG_ROUTING_NONE); | 1203 DCHECK(params.view_id != MSG_ROUTING_NONE); |
1197 RenderViewImpl* render_view = NULL; | 1204 RenderViewImpl* render_view = NULL; |
1198 if (g_create_render_view_impl) | 1205 if (g_create_render_view_impl) |
1199 render_view = g_create_render_view_impl(compositor_deps, params); | 1206 render_view = g_create_render_view_impl(compositor_deps, params); |
1200 else | 1207 else |
1201 render_view = new RenderViewImpl(compositor_deps, params); | 1208 render_view = new RenderViewImpl(compositor_deps, params); |
1202 | 1209 |
1203 render_view->Initialize(params, was_created_by_renderer); | 1210 render_view->Initialize(params, show_callback); |
1204 return render_view; | 1211 return render_view; |
1205 } | 1212 } |
1206 | 1213 |
1207 // static | 1214 // static |
1208 void RenderViewImpl::InstallCreateHook(RenderViewImpl* ( | 1215 void RenderViewImpl::InstallCreateHook(RenderViewImpl* ( |
1209 *create_render_view_impl)(CompositorDependencies* compositor_deps, | 1216 *create_render_view_impl)(CompositorDependencies* compositor_deps, |
1210 const mojom::CreateViewParams&)) { | 1217 const mojom::CreateViewParams&)) { |
1211 CHECK(!g_create_render_view_impl); | 1218 CHECK(!g_create_render_view_impl); |
1212 g_create_render_view_impl = create_render_view_impl; | 1219 g_create_render_view_impl = create_render_view_impl; |
1213 } | 1220 } |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries()); | 1466 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries()); |
1460 | 1467 |
1461 HistoryEntry* entry = history_controller_->GetCurrentEntry(); | 1468 HistoryEntry* entry = history_controller_->GetCurrentEntry(); |
1462 if (!entry) | 1469 if (!entry) |
1463 return; | 1470 return; |
1464 | 1471 |
1465 Send(new ViewHostMsg_UpdateState(GetRoutingID(), | 1472 Send(new ViewHostMsg_UpdateState(GetRoutingID(), |
1466 HistoryEntryToPageState(entry))); | 1473 HistoryEntryToPageState(entry))); |
1467 } | 1474 } |
1468 | 1475 |
| 1476 void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget, |
| 1477 WebNavigationPolicy policy, |
| 1478 const gfx::Rect& initial_rect) { |
| 1479 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(), |
| 1480 initial_rect)); |
| 1481 } |
| 1482 |
| 1483 void RenderViewImpl::ShowCreatedFullscreenWidget( |
| 1484 RenderWidget* fullscreen_widget, |
| 1485 WebNavigationPolicy policy, |
| 1486 const gfx::Rect& initial_rect) { |
| 1487 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(), |
| 1488 fullscreen_widget->routing_id())); |
| 1489 } |
| 1490 |
| 1491 void RenderViewImpl::ShowCreatedViewWidget(bool opened_by_user_gesture, |
| 1492 RenderWidget* render_view_to_show, |
| 1493 WebNavigationPolicy policy, |
| 1494 const gfx::Rect& initial_rect) { |
| 1495 // |render_view_to_show| represents a pending view opened (e.g. a popup opened |
| 1496 // via window.open()) by this object, but not yet shown (it's offscreen, and |
| 1497 // still owned by the opener). Sending |ViewHostMsg_ShowView| will move it off |
| 1498 // the opener's pending list, into e.g. its own tab or window. |
| 1499 Send(new ViewHostMsg_ShowView(GetRoutingID(), |
| 1500 render_view_to_show->routing_id(), |
| 1501 NavigationPolicyToDisposition(policy), |
| 1502 initial_rect, opened_by_user_gesture)); |
| 1503 } |
| 1504 |
1469 void RenderViewImpl::SendFrameStateUpdates() { | 1505 void RenderViewImpl::SendFrameStateUpdates() { |
1470 // We only use this path in OOPIF-enabled modes. | 1506 // We only use this path in OOPIF-enabled modes. |
1471 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); | 1507 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); |
1472 | 1508 |
1473 // Tell each frame with pending state to send its UpdateState message. | 1509 // Tell each frame with pending state to send its UpdateState message. |
1474 for (int render_frame_routing_id : frames_with_pending_state_) { | 1510 for (int render_frame_routing_id : frames_with_pending_state_) { |
1475 RenderFrameImpl* frame = | 1511 RenderFrameImpl* frame = |
1476 RenderFrameImpl::FromRoutingID(render_frame_routing_id); | 1512 RenderFrameImpl::FromRoutingID(render_frame_routing_id); |
1477 if (frame) | 1513 if (frame) |
1478 frame->SendUpdateState(); | 1514 frame->SendUpdateState(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 // WebCore will take care of setting the correct name. | 1627 // WebCore will take care of setting the correct name. |
1592 view_params.replicated_frame_state = FrameReplicationState(); | 1628 view_params.replicated_frame_state = FrameReplicationState(); |
1593 view_params.hidden = is_background_tab; | 1629 view_params.hidden = is_background_tab; |
1594 view_params.never_visible = never_visible; | 1630 view_params.never_visible = never_visible; |
1595 view_params.initial_size = initial_size; | 1631 view_params.initial_size = initial_size; |
1596 view_params.enable_auto_resize = false; | 1632 view_params.enable_auto_resize = false; |
1597 view_params.min_size = gfx::Size(); | 1633 view_params.min_size = gfx::Size(); |
1598 view_params.max_size = gfx::Size(); | 1634 view_params.max_size = gfx::Size(); |
1599 view_params.page_zoom_level = page_zoom_level_; | 1635 view_params.page_zoom_level = page_zoom_level_; |
1600 | 1636 |
| 1637 RenderWidget::ShowCallback show_callback = |
| 1638 base::Bind(&RenderViewImpl::ShowCreatedViewWidget, this->AsWeakPtr(), |
| 1639 opened_by_user_gesture); |
| 1640 |
1601 RenderViewImpl* view = | 1641 RenderViewImpl* view = |
1602 RenderViewImpl::Create(compositor_deps_, view_params, true); | 1642 RenderViewImpl::Create(compositor_deps_, view_params, show_callback); |
1603 view->opened_by_user_gesture_ = opened_by_user_gesture; | |
1604 | 1643 |
1605 return view->webview(); | 1644 return view->webview(); |
1606 } | 1645 } |
1607 | 1646 |
1608 WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) { | 1647 WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) { |
1609 RenderWidget* widget = RenderWidget::Create(GetRoutingID(), compositor_deps_, | 1648 RenderWidget* widget = RenderWidget::CreateForPopup(this, compositor_deps_, |
1610 popup_type, screen_info_); | 1649 popup_type, screen_info_); |
1611 if (!widget) | 1650 if (!widget) |
1612 return NULL; | 1651 return NULL; |
1613 if (screen_metrics_emulator_) { | 1652 if (screen_metrics_emulator_) { |
1614 widget->SetPopupOriginAdjustmentsForEmulation( | 1653 widget->SetPopupOriginAdjustmentsForEmulation( |
1615 screen_metrics_emulator_.get()); | 1654 screen_metrics_emulator_.get()); |
1616 } | 1655 } |
1617 return widget->GetWebWidget(); | 1656 return widget->GetWebWidget(); |
1618 } | 1657 } |
1619 | 1658 |
1620 WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() { | 1659 WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() { |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 void RenderViewImpl::didFocus() { | 1939 void RenderViewImpl::didFocus() { |
1901 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed | 1940 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
1902 // we won't have to test for user gesture anymore and we can | 1941 // we won't have to test for user gesture anymore and we can |
1903 // move that code back to render_widget.cc | 1942 // move that code back to render_widget.cc |
1904 if (WebUserGestureIndicator::isProcessingUserGesture() && | 1943 if (WebUserGestureIndicator::isProcessingUserGesture() && |
1905 !RenderThreadImpl::current()->layout_test_mode()) { | 1944 !RenderThreadImpl::current()->layout_test_mode()) { |
1906 Send(new ViewHostMsg_Focus(GetRoutingID())); | 1945 Send(new ViewHostMsg_Focus(GetRoutingID())); |
1907 } | 1946 } |
1908 } | 1947 } |
1909 | 1948 |
1910 // We are supposed to get a single call to Show for a newly created RenderView | 1949 // We are supposed to get a single call to show() for a newly created RenderView |
1911 // that was created via RenderViewImpl::CreateWebView. So, we wait until this | 1950 // that was created via RenderViewImpl::createView. We wait until this point to |
1912 // point to dispatch the ShowView message. | 1951 // run |show_callback|, which is bound to our opener's ShowCreatedViewWidget() |
| 1952 // method. |
1913 // | 1953 // |
1914 // This method provides us with the information about how to display the newly | 1954 // This method provides us with the information about how to display the newly |
1915 // created RenderView (i.e., as a blocked popup or as a new tab). | 1955 // created RenderView (i.e., as a blocked popup or as a new tab). |
1916 // | |
1917 void RenderViewImpl::show(WebNavigationPolicy policy) { | 1956 void RenderViewImpl::show(WebNavigationPolicy policy) { |
1918 if (did_show_) { | 1957 if (did_show_ && !webkit_preferences_.supports_multiple_windows) { |
1919 // When supports_multiple_windows is disabled, popups are reusing | 1958 // When supports_multiple_windows is disabled, popups are reusing |
1920 // the same view. In some scenarios, this makes WebKit to call show() twice. | 1959 // the same view. In some scenarios, this makes WebKit to call show() twice. |
1921 if (webkit_preferences_.supports_multiple_windows) | |
1922 NOTREACHED() << "received extraneous Show call"; | |
1923 return; | 1960 return; |
1924 } | 1961 } |
1925 did_show_ = true; | |
1926 | 1962 |
1927 DCHECK(opener_id_ != MSG_ROUTING_NONE); | 1963 RenderWidget::show(policy); |
1928 | |
1929 // NOTE: initial_rect_ may still have its default values at this point, but | |
1930 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the | |
1931 // browser process will impose a default position otherwise. | |
1932 Send(new ViewHostMsg_ShowView(opener_id_, GetRoutingID(), | |
1933 NavigationPolicyToDisposition(policy), | |
1934 initial_rect_, opened_by_user_gesture_)); | |
1935 SetPendingWindowRect(initial_rect_); | |
1936 } | 1964 } |
1937 | 1965 |
1938 void RenderViewImpl::onMouseDown(const WebNode& mouse_down_node) { | 1966 void RenderViewImpl::onMouseDown(const WebNode& mouse_down_node) { |
1939 for (auto& observer : observers_) | 1967 for (auto& observer : observers_) |
1940 observer.OnMouseDown(mouse_down_node); | 1968 observer.OnMouseDown(mouse_down_node); |
1941 } | 1969 } |
1942 | 1970 |
1943 void RenderViewImpl::didHandleGestureEvent( | 1971 void RenderViewImpl::didHandleGestureEvent( |
1944 const WebGestureEvent& event, | 1972 const WebGestureEvent& event, |
1945 bool event_cancelled) { | 1973 bool event_cancelled) { |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2968 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2996 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
2969 } | 2997 } |
2970 | 2998 |
2971 std::unique_ptr<InputEventAck> ack( | 2999 std::unique_ptr<InputEventAck> ack( |
2972 new InputEventAck(InputEventAckSource::MAIN_THREAD, input_event->type, | 3000 new InputEventAck(InputEventAckSource::MAIN_THREAD, input_event->type, |
2973 INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); | 3001 INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
2974 OnInputEventAck(std::move(ack)); | 3002 OnInputEventAck(std::move(ack)); |
2975 } | 3003 } |
2976 | 3004 |
2977 } // namespace content | 3005 } // namespace content |
OLD | NEW |