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

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

Issue 2498463002: RenderWidget/RenderView: encapsulate ViewHostMsg_Show, etc, in a callback (Closed)
Patch Set: More IPC messing. Created 4 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
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/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
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 bool was_created_by_renderer = !show_callback.is_null();
703 #if defined(OS_ANDROID)
704 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
705 // HandleNavigation.
706 was_created_by_renderer_ = was_created_by_renderer;
707 #endif
702 WebFrame* opener_frame = RenderFrameImpl::ResolveOpener( 708 WebFrame* opener_frame = RenderFrameImpl::ResolveOpener(
703 params.opener_frame_route_id, &opener_view_routing_id); 709 params.opener_frame_route_id, nullptr);
704 if (!was_created_by_renderer)
705 opener_view_routing_id = MSG_ROUTING_NONE;
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
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 is a popup, we won't be visible until we ask our opener (via
alexmos 2016/11/17 09:51:09 nit: is it really correct to say "If this is a pop
ncarter (slow) 2016/11/17 19:33:11 I amended the comment. There are three widget-sho
alexmos 2016/11/17 22:27:43 Acknowledged.
805 // completing initialization. Otherwise, we can finish it now. 809 // show_callback) to make us visible. Otherwise, we expect that show() will
806 if (opener_id_ == MSG_ROUTING_NONE) 810 // never be called.
811 if (!was_created_by_renderer)
807 did_show_ = true; 812 did_show_ = true;
808 813
809 // Set the main frame's name. Only needs to be done for WebLocalFrames, 814 // 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 815 // since the remote case was handled as part of SetReplicatedState on the
811 // proxy above. 816 // proxy above.
812 if (!params.replicated_frame_state.name.empty() && 817 if (!params.replicated_frame_state.name.empty() &&
813 webview()->mainFrame()->isWebLocalFrame()) { 818 webview()->mainFrame()->isWebLocalFrame()) {
814 webview()->mainFrame()->setName( 819 webview()->mainFrame()->setName(
815 blink::WebString::fromUTF8(params.replicated_frame_state.name)); 820 blink::WebString::fromUTF8(params.replicated_frame_state.name));
816 } 821 }
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 settings->setDoubleTapToZoomEnabled(true); 1188 settings->setDoubleTapToZoomEnabled(true);
1184 web_view->setMaximumLegibleScale(prefs.default_maximum_page_scale_factor); 1189 web_view->setMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
1185 #endif 1190 #endif
1186 1191
1187 #if defined(OS_WIN) 1192 #if defined(OS_WIN)
1188 WebRuntimeFeatures::enableMiddleClickAutoscroll(true); 1193 WebRuntimeFeatures::enableMiddleClickAutoscroll(true);
1189 #endif 1194 #endif
1190 } 1195 }
1191 1196
1192 /*static*/ 1197 /*static*/
1193 RenderViewImpl* RenderViewImpl::Create(CompositorDependencies* compositor_deps, 1198 RenderViewImpl* RenderViewImpl::Create(
1194 const mojom::CreateViewParams& params, 1199 CompositorDependencies* compositor_deps,
1195 bool was_created_by_renderer) { 1200 const mojom::CreateViewParams& params,
1201 const RenderWidget::ShowCallback& show_callback) {
1196 DCHECK(params.view_id != MSG_ROUTING_NONE); 1202 DCHECK(params.view_id != MSG_ROUTING_NONE);
1197 RenderViewImpl* render_view = NULL; 1203 RenderViewImpl* render_view = NULL;
1198 if (g_create_render_view_impl) 1204 if (g_create_render_view_impl)
1199 render_view = g_create_render_view_impl(compositor_deps, params); 1205 render_view = g_create_render_view_impl(compositor_deps, params);
1200 else 1206 else
1201 render_view = new RenderViewImpl(compositor_deps, params); 1207 render_view = new RenderViewImpl(compositor_deps, params);
1202 1208
1203 render_view->Initialize(params, was_created_by_renderer); 1209 render_view->Initialize(params, show_callback);
1204 return render_view; 1210 return render_view;
1205 } 1211 }
1206 1212
1207 // static 1213 // static
1208 void RenderViewImpl::InstallCreateHook(RenderViewImpl* ( 1214 void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1209 *create_render_view_impl)(CompositorDependencies* compositor_deps, 1215 *create_render_view_impl)(CompositorDependencies* compositor_deps,
1210 const mojom::CreateViewParams&)) { 1216 const mojom::CreateViewParams&)) {
1211 CHECK(!g_create_render_view_impl); 1217 CHECK(!g_create_render_view_impl);
1212 g_create_render_view_impl = create_render_view_impl; 1218 g_create_render_view_impl = create_render_view_impl;
1213 } 1219 }
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries()); 1465 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
1460 1466
1461 HistoryEntry* entry = history_controller_->GetCurrentEntry(); 1467 HistoryEntry* entry = history_controller_->GetCurrentEntry();
1462 if (!entry) 1468 if (!entry)
1463 return; 1469 return;
1464 1470
1465 Send(new ViewHostMsg_UpdateState(GetRoutingID(), 1471 Send(new ViewHostMsg_UpdateState(GetRoutingID(),
1466 HistoryEntryToPageState(entry))); 1472 HistoryEntryToPageState(entry)));
1467 } 1473 }
1468 1474
1475 void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1476 WebNavigationPolicy policy,
1477 const gfx::Rect& initial_rect) {
1478 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1479 initial_rect));
1480 }
1481
1482 void RenderViewImpl::ShowCreatedFullscreenWidget(
1483 RenderWidget* fullscreen_widget,
1484 WebNavigationPolicy policy,
1485 const gfx::Rect& initial_rect) {
1486 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1487 fullscreen_widget->routing_id()));
1488 }
1489
1490 void RenderViewImpl::ShowCreatedViewWidget(bool opened_by_user_gesture,
1491 RenderWidget* render_view_to_show,
1492 WebNavigationPolicy policy,
1493 const gfx::Rect& initial_rect) {
1494 // |render_view_to_show| represents a pending view opened (e.g. a popup opened
1495 // via window.open()) by this object, but not yet shown (it's offscreen, and
1496 // still owned by the opener). Sending |ViewHostMsg_ShowView| will move it off
1497 // the opener's pending list, into e.g. its own tab or window.
1498 Send(new ViewHostMsg_ShowView(GetRoutingID(),
1499 render_view_to_show->routing_id(),
1500 NavigationPolicyToDisposition(policy),
1501 initial_rect, opened_by_user_gesture));
1502 }
1503
1469 void RenderViewImpl::SendFrameStateUpdates() { 1504 void RenderViewImpl::SendFrameStateUpdates() {
1470 // We only use this path in OOPIF-enabled modes. 1505 // We only use this path in OOPIF-enabled modes.
1471 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); 1506 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
1472 1507
1473 // Tell each frame with pending state to send its UpdateState message. 1508 // Tell each frame with pending state to send its UpdateState message.
1474 for (int render_frame_routing_id : frames_with_pending_state_) { 1509 for (int render_frame_routing_id : frames_with_pending_state_) {
1475 RenderFrameImpl* frame = 1510 RenderFrameImpl* frame =
1476 RenderFrameImpl::FromRoutingID(render_frame_routing_id); 1511 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1477 if (frame) 1512 if (frame)
1478 frame->SendUpdateState(); 1513 frame->SendUpdateState();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1591 // WebCore will take care of setting the correct name. 1626 // WebCore will take care of setting the correct name.
1592 view_params.replicated_frame_state = FrameReplicationState(); 1627 view_params.replicated_frame_state = FrameReplicationState();
1593 view_params.hidden = is_background_tab; 1628 view_params.hidden = is_background_tab;
1594 view_params.never_visible = never_visible; 1629 view_params.never_visible = never_visible;
1595 view_params.initial_size = initial_size; 1630 view_params.initial_size = initial_size;
1596 view_params.enable_auto_resize = false; 1631 view_params.enable_auto_resize = false;
1597 view_params.min_size = gfx::Size(); 1632 view_params.min_size = gfx::Size();
1598 view_params.max_size = gfx::Size(); 1633 view_params.max_size = gfx::Size();
1599 view_params.page_zoom_level = page_zoom_level_; 1634 view_params.page_zoom_level = page_zoom_level_;
1600 1635
1636 RenderWidget::ShowCallback show_callback =
1637 base::Bind(&RenderViewImpl::ShowCreatedViewWidget, this->AsWeakPtr(),
1638 opened_by_user_gesture);
1639
1601 RenderViewImpl* view = 1640 RenderViewImpl* view =
1602 RenderViewImpl::Create(compositor_deps_, view_params, true); 1641 RenderViewImpl::Create(compositor_deps_, view_params, show_callback);
1603 view->opened_by_user_gesture_ = opened_by_user_gesture;
1604 1642
1605 return view->webview(); 1643 return view->webview();
1606 } 1644 }
1607 1645
1608 WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) { 1646 WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) {
1609 RenderWidget* widget = RenderWidget::Create(GetRoutingID(), compositor_deps_, 1647 RenderWidget* widget = RenderWidget::CreateForPopup(this, compositor_deps_,
1610 popup_type, screen_info_); 1648 popup_type, screen_info_);
1611 if (!widget) 1649 if (!widget)
1612 return NULL; 1650 return NULL;
1613 if (screen_metrics_emulator_) { 1651 if (screen_metrics_emulator_) {
1614 widget->SetPopupOriginAdjustmentsForEmulation( 1652 widget->SetPopupOriginAdjustmentsForEmulation(
1615 screen_metrics_emulator_.get()); 1653 screen_metrics_emulator_.get());
1616 } 1654 }
1617 return widget->GetWebWidget(); 1655 return widget->GetWebWidget();
1618 } 1656 }
1619 1657
1620 WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() { 1658 WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed 1939 // 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 1940 // we won't have to test for user gesture anymore and we can
1903 // move that code back to render_widget.cc 1941 // move that code back to render_widget.cc
1904 if (WebUserGestureIndicator::isProcessingUserGesture() && 1942 if (WebUserGestureIndicator::isProcessingUserGesture() &&
1905 !RenderThreadImpl::current()->layout_test_mode()) { 1943 !RenderThreadImpl::current()->layout_test_mode()) {
1906 Send(new ViewHostMsg_Focus(GetRoutingID())); 1944 Send(new ViewHostMsg_Focus(GetRoutingID()));
1907 } 1945 }
1908 } 1946 }
1909 1947
1910 // We are supposed to get a single call to Show for a newly created RenderView 1948 // 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 1949 // that was created via RenderViewImpl::CreateWebView. So, we wait until this
alexmos 2016/11/17 09:51:09 Perhaps update this while you're here?
ncarter (slow) 2016/11/17 19:33:11 Done.
1912 // point to dispatch the ShowView message. 1950 // point to dispatch the ShowView message.
1913 // 1951 //
1914 // This method provides us with the information about how to display the newly 1952 // 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). 1953 // created RenderView (i.e., as a blocked popup or as a new tab).
1916 // 1954 //
1917 void RenderViewImpl::show(WebNavigationPolicy policy) { 1955 void RenderViewImpl::show(WebNavigationPolicy policy) {
1918 if (did_show_) { 1956 if (did_show_ && !webkit_preferences_.supports_multiple_windows) {
alexmos 2016/11/17 09:51:09 Just to confirm, the NOTREACHED is gone because if
ncarter (slow) 2016/11/17 19:33:11 Correct.
1919 // When supports_multiple_windows is disabled, popups are reusing 1957 // When supports_multiple_windows is disabled, popups are reusing
1920 // the same view. In some scenarios, this makes WebKit to call show() twice. 1958 // 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; 1959 return;
1924 } 1960 }
1925 did_show_ = true;
1926 1961
1927 DCHECK(opener_id_ != MSG_ROUTING_NONE); 1962 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 } 1963 }
1937 1964
1938 void RenderViewImpl::onMouseDown(const WebNode& mouse_down_node) { 1965 void RenderViewImpl::onMouseDown(const WebNode& mouse_down_node) {
1939 for (auto& observer : observers_) 1966 for (auto& observer : observers_)
1940 observer.OnMouseDown(mouse_down_node); 1967 observer.OnMouseDown(mouse_down_node);
1941 } 1968 }
1942 1969
1943 void RenderViewImpl::didHandleGestureEvent( 1970 void RenderViewImpl::didHandleGestureEvent(
1944 const WebGestureEvent& event, 1971 const WebGestureEvent& event,
1945 bool event_cancelled) { 1972 bool event_cancelled) {
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
2968 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 2995 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2969 } 2996 }
2970 2997
2971 std::unique_ptr<InputEventAck> ack( 2998 std::unique_ptr<InputEventAck> ack(
2972 new InputEventAck(InputEventAckSource::MAIN_THREAD, input_event->type, 2999 new InputEventAck(InputEventAckSource::MAIN_THREAD, input_event->type,
2973 INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); 3000 INPUT_EVENT_ACK_STATE_NOT_CONSUMED));
2974 OnInputEventAck(std::move(ack)); 3001 OnInputEventAck(std::move(ack));
2975 } 3002 }
2976 3003
2977 } // namespace content 3004 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698