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

Side by Side Diff: content/browser/renderer_host/render_view_host_impl.cc

Issue 2571583008: Support tracking focused element for OOPIFs. (Closed)
Patch Set: Fixed some compile errors Created 4 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
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/renderer_host/render_view_host_impl.h" 5 #include "content/browser/renderer_host/render_view_host_impl.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 20 matching lines...) Expand all
31 #include "components/variations/variations_associated_data.h" 31 #include "components/variations/variations_associated_data.h"
32 #include "content/browser/bad_message.h" 32 #include "content/browser/bad_message.h"
33 #include "content/browser/child_process_security_policy_impl.h" 33 #include "content/browser/child_process_security_policy_impl.h"
34 #include "content/browser/dom_storage/session_storage_namespace_impl.h" 34 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
35 #include "content/browser/frame_host/frame_tree.h" 35 #include "content/browser/frame_host/frame_tree.h"
36 #include "content/browser/gpu/compositor_util.h" 36 #include "content/browser/gpu/compositor_util.h"
37 #include "content/browser/gpu/gpu_data_manager_impl.h" 37 #include "content/browser/gpu/gpu_data_manager_impl.h"
38 #include "content/browser/gpu/gpu_process_host.h" 38 #include "content/browser/gpu/gpu_process_host.h"
39 #include "content/browser/host_zoom_map_impl.h" 39 #include "content/browser/host_zoom_map_impl.h"
40 #include "content/browser/loader/resource_dispatcher_host_impl.h" 40 #include "content/browser/loader/resource_dispatcher_host_impl.h"
41 #include "content/browser/renderer_host/dip_util.h"
42 #include "content/browser/renderer_host/render_process_host_impl.h" 41 #include "content/browser/renderer_host/render_process_host_impl.h"
43 #include "content/browser/renderer_host/render_view_host_delegate.h" 42 #include "content/browser/renderer_host/render_view_host_delegate.h"
44 #include "content/browser/renderer_host/render_view_host_delegate_view.h" 43 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
45 #include "content/browser/renderer_host/render_widget_host_delegate.h" 44 #include "content/browser/renderer_host/render_widget_host_delegate.h"
46 #include "content/browser/renderer_host/render_widget_host_view_base.h" 45 #include "content/browser/renderer_host/render_widget_host_view_base.h"
47 #include "content/common/browser_plugin/browser_plugin_messages.h" 46 #include "content/common/browser_plugin/browser_plugin_messages.h"
48 #include "content/common/content_switches_internal.h" 47 #include "content/common/content_switches_internal.h"
49 #include "content/common/frame_messages.h" 48 #include "content/common/frame_messages.h"
50 #include "content/common/input_messages.h" 49 #include "content/common/input_messages.h"
51 #include "content/common/inter_process_time_ticks_converter.h" 50 #include "content/common/inter_process_time_ticks_converter.h"
52 #include "content/common/render_message_filter.mojom.h" 51 #include "content/common/render_message_filter.mojom.h"
53 #include "content/common/renderer.mojom.h" 52 #include "content/common/renderer.mojom.h"
54 #include "content/common/site_isolation_policy.h" 53 #include "content/common/site_isolation_policy.h"
55 #include "content/common/speech_recognition_messages.h" 54 #include "content/common/speech_recognition_messages.h"
56 #include "content/common/swapped_out_messages.h" 55 #include "content/common/swapped_out_messages.h"
57 #include "content/common/view_messages.h" 56 #include "content/common/view_messages.h"
58 #include "content/public/browser/ax_event_notification_details.h" 57 #include "content/public/browser/ax_event_notification_details.h"
59 #include "content/public/browser/browser_accessibility_state.h" 58 #include "content/public/browser/browser_accessibility_state.h"
60 #include "content/public/browser/browser_context.h" 59 #include "content/public/browser/browser_context.h"
61 #include "content/public/browser/browser_message_filter.h" 60 #include "content/public/browser/browser_message_filter.h"
62 #include "content/public/browser/content_browser_client.h" 61 #include "content/public/browser/content_browser_client.h"
63 #include "content/public/browser/focused_node_details.h"
64 #include "content/public/browser/native_web_keyboard_event.h" 62 #include "content/public/browser/native_web_keyboard_event.h"
65 #include "content/public/browser/notification_details.h" 63 #include "content/public/browser/notification_details.h"
66 #include "content/public/browser/notification_service.h" 64 #include "content/public/browser/notification_service.h"
67 #include "content/public/browser/notification_types.h" 65 #include "content/public/browser/notification_types.h"
68 #include "content/public/browser/render_frame_host.h" 66 #include "content/public/browser/render_frame_host.h"
69 #include "content/public/browser/render_widget_host_iterator.h" 67 #include "content/public/browser/render_widget_host_iterator.h"
70 #include "content/public/browser/storage_partition.h" 68 #include "content/public/browser/storage_partition.h"
71 #include "content/public/browser/user_metrics.h" 69 #include "content/public/browser/user_metrics.h"
72 #include "content/public/common/bindings_policy.h" 70 #include "content/public/common/bindings_policy.h"
73 #include "content/public/common/content_constants.h" 71 #include "content/public/common/content_constants.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 frames_ref_count_(0), 200 frames_ref_count_(0),
203 delegate_(delegate), 201 delegate_(delegate),
204 instance_(static_cast<SiteInstanceImpl*>(instance)), 202 instance_(static_cast<SiteInstanceImpl*>(instance)),
205 enabled_bindings_(0), 203 enabled_bindings_(0),
206 is_active_(!swapped_out), 204 is_active_(!swapped_out),
207 is_swapped_out_(swapped_out), 205 is_swapped_out_(swapped_out),
208 main_frame_routing_id_(main_frame_routing_id), 206 main_frame_routing_id_(main_frame_routing_id),
209 is_waiting_for_close_ack_(false), 207 is_waiting_for_close_ack_(false),
210 sudden_termination_allowed_(false), 208 sudden_termination_allowed_(false),
211 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), 209 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING),
212 is_focused_element_editable_(false),
213 updating_web_preferences_(false), 210 updating_web_preferences_(false),
214 render_view_ready_on_process_launch_(false), 211 render_view_ready_on_process_launch_(false),
215 weak_factory_(this) { 212 weak_factory_(this) {
216 DCHECK(instance_.get()); 213 DCHECK(instance_.get());
217 CHECK(delegate_); // http://crbug.com/82827 214 CHECK(delegate_); // http://crbug.com/82827
218 215
219 GetWidget()->set_owner_delegate(this); 216 GetWidget()->set_owner_delegate(this);
220 217
221 GetProcess()->AddObserver(this); 218 GetProcess()->AddObserver(this);
222 219
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL, OnUpdateTargetURL) 765 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL, OnUpdateTargetURL)
769 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose) 766 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose)
770 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnRequestMove) 767 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnRequestMove)
771 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentAvailableInMainFrame, 768 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentAvailableInMainFrame,
772 OnDocumentAvailableInMainFrame) 769 OnDocumentAvailableInMainFrame)
773 IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange, 770 IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange,
774 OnDidContentsPreferredSizeChange) 771 OnDidContentsPreferredSizeChange)
775 IPC_MESSAGE_HANDLER(ViewHostMsg_RouteCloseEvent, 772 IPC_MESSAGE_HANDLER(ViewHostMsg_RouteCloseEvent,
776 OnRouteCloseEvent) 773 OnRouteCloseEvent)
777 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) 774 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus)
778 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged)
779 IPC_MESSAGE_HANDLER(ViewHostMsg_ClosePage_ACK, OnClosePageACK) 775 IPC_MESSAGE_HANDLER(ViewHostMsg_ClosePage_ACK, OnClosePageACK)
780 IPC_MESSAGE_HANDLER(ViewHostMsg_DidZoomURL, OnDidZoomURL) 776 IPC_MESSAGE_HANDLER(ViewHostMsg_DidZoomURL, OnDidZoomURL)
781 IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnFocus) 777 IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnFocus)
782 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeTouched, OnFocusedNodeTouched)
783 IPC_MESSAGE_UNHANDLED(handled = false) 778 IPC_MESSAGE_UNHANDLED(handled = false)
784 IPC_END_MESSAGE_MAP() 779 IPC_END_MESSAGE_MAP()
785 780
786 return handled; 781 return handled;
787 } 782 }
788 783
789 void RenderViewHostImpl::RenderWidgetDidInit() { 784 void RenderViewHostImpl::RenderWidgetDidInit() {
790 PostRenderViewReady(); 785 PostRenderViewReady();
791 } 786 }
792 787
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 // Have the delegate route this to the active RenderViewHost. 909 // Have the delegate route this to the active RenderViewHost.
915 delegate_->RouteCloseEvent(this); 910 delegate_->RouteCloseEvent(this);
916 } 911 }
917 912
918 void RenderViewHostImpl::OnTakeFocus(bool reverse) { 913 void RenderViewHostImpl::OnTakeFocus(bool reverse) {
919 RenderViewHostDelegateView* view = delegate_->GetDelegateView(); 914 RenderViewHostDelegateView* view = delegate_->GetDelegateView();
920 if (view) 915 if (view)
921 view->TakeFocus(reverse); 916 view->TakeFocus(reverse);
922 } 917 }
923 918
924 void RenderViewHostImpl::OnFocusedNodeChanged(
925 bool is_editable_node,
926 const gfx::Rect& node_bounds_in_viewport) {
927 is_focused_element_editable_ = is_editable_node;
928
929 // None of the rest makes sense without a view.
930 if (!GetWidget()->GetView())
931 return;
932
933 // Convert node_bounds to screen coordinates.
934 gfx::Rect view_bounds_in_screen = GetWidget()->GetView()->GetViewBounds();
935 gfx::Point origin = node_bounds_in_viewport.origin();
936 origin.Offset(view_bounds_in_screen.x(), view_bounds_in_screen.y());
937 gfx::Rect node_bounds_in_screen(origin.x(), origin.y(),
938 node_bounds_in_viewport.width(),
939 node_bounds_in_viewport.height());
940
941 GetWidget()->GetView()->FocusedNodeChanged(
942 is_editable_node, node_bounds_in_screen);
943
944 FocusedNodeDetails details = {is_editable_node, node_bounds_in_screen};
945 NotificationService::current()->Notify(NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
946 Source<RenderViewHost>(this),
947 Details<FocusedNodeDetails>(&details));
948 }
949
950 void RenderViewHostImpl::OnClosePageACK() { 919 void RenderViewHostImpl::OnClosePageACK() {
951 GetWidget()->decrement_in_flight_event_count(); 920 GetWidget()->decrement_in_flight_event_count();
952 ClosePageIgnoringUnloadEvents(); 921 ClosePageIgnoringUnloadEvents();
953 } 922 }
954 923
955 void RenderViewHostImpl::OnFocus() { 924 void RenderViewHostImpl::OnFocus() {
956 // Note: We allow focus and blur from swapped out RenderViewHosts, even when 925 // Note: We allow focus and blur from swapped out RenderViewHosts, even when
957 // the active RenderViewHost is in a different BrowsingInstance (e.g., WebUI). 926 // the active RenderViewHost is in a different BrowsingInstance (e.g., WebUI).
958 delegate_->Activate(); 927 delegate_->Activate();
959 } 928 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 // This is defensive code to avoid infinite loops due to code run inside 961 // This is defensive code to avoid infinite loops due to code run inside
993 // UpdateWebkitPreferences() accidentally updating more preferences and thus 962 // UpdateWebkitPreferences() accidentally updating more preferences and thus
994 // calling back into this code. See crbug.com/398751 for one past example. 963 // calling back into this code. See crbug.com/398751 for one past example.
995 if (updating_web_preferences_) 964 if (updating_web_preferences_)
996 return; 965 return;
997 updating_web_preferences_ = true; 966 updating_web_preferences_ = true;
998 UpdateWebkitPreferences(ComputeWebkitPrefs()); 967 UpdateWebkitPreferences(ComputeWebkitPrefs());
999 updating_web_preferences_ = false; 968 updating_web_preferences_ = false;
1000 } 969 }
1001 970
1002 void RenderViewHostImpl::ClearFocusedElement() { 971 void RenderViewHostImpl::ClearFocusedElement() {
ncarter (slow) 2016/12/16 19:17:21 Should we consider just moving this method to be p
EhsanK 2016/12/20 16:39:10 Yes absolutely. I didn't do this for two reasons:
1003 is_focused_element_editable_ = false; 972 if (delegate_)
1004 Send(new ViewMsg_ClearFocusedElement(GetRoutingID())); 973 delegate_->ClearFocusedElement();
1005 } 974 }
1006 975
1007 bool RenderViewHostImpl::IsFocusedElementEditable() { 976 bool RenderViewHostImpl::IsFocusedElementEditable() {
ncarter (slow) 2016/12/16 19:17:21 Same question here. There are a couple more caller
EhsanK 2016/12/20 16:39:10 +1 to moving to WebContentsImpl. Maybe I leave a T
1008 return is_focused_element_editable_; 977 return delegate_ && delegate_->IsFocusedElementEditable();
1009 } 978 }
1010 979
1011 void RenderViewHostImpl::Zoom(PageZoom zoom) { 980 void RenderViewHostImpl::Zoom(PageZoom zoom) {
1012 Send(new ViewMsg_Zoom(GetRoutingID(), zoom)); 981 Send(new ViewMsg_Zoom(GetRoutingID(), zoom));
1013 } 982 }
1014 983
1015 void RenderViewHostImpl::DisableScrollbarsForThreshold(const gfx::Size& size) { 984 void RenderViewHostImpl::DisableScrollbarsForThreshold(const gfx::Size& size) {
1016 Send(new ViewMsg_DisableScrollbarsForSmallWindows(GetRoutingID(), size)); 985 Send(new ViewMsg_DisableScrollbarsForSmallWindows(GetRoutingID(), size));
1017 } 986 }
1018 987
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 const GURL& url) { 1020 const GURL& url) {
1052 HostZoomMapImpl* host_zoom_map = 1021 HostZoomMapImpl* host_zoom_map =
1053 static_cast<HostZoomMapImpl*>(HostZoomMap::Get(GetSiteInstance())); 1022 static_cast<HostZoomMapImpl*>(HostZoomMap::Get(GetSiteInstance()));
1054 1023
1055 host_zoom_map->SetZoomLevelForView(GetProcess()->GetID(), 1024 host_zoom_map->SetZoomLevelForView(GetProcess()->GetID(),
1056 GetRoutingID(), 1025 GetRoutingID(),
1057 zoom_level, 1026 zoom_level,
1058 net::GetHostOrSpecFromURL(url)); 1027 net::GetHostOrSpecFromURL(url));
1059 } 1028 }
1060 1029
1061 void RenderViewHostImpl::OnFocusedNodeTouched(bool editable) {
1062 #if defined(OS_WIN)
1063 // We use the cursor position to determine where the touch occurred.
1064 // TODO(ananta)
1065 // Pass this information from blink.
1066 // In site isolation mode, we may not have a RenderViewHostImpl instance
1067 // which means that displaying the OSK is not going to work. We should
1068 // probably move this to RenderWidgetHostImpl and call the view from there.
1069 // https://bugs.chromium.org/p/chromium/issues/detail?id=613326
1070 POINT cursor_pos = {};
1071 ::GetCursorPos(&cursor_pos);
1072 float scale = GetScaleFactorForView(GetWidget()->GetView());
1073 gfx::Point location_dips_screen =
1074 gfx::ConvertPointToDIP(scale, gfx::Point(cursor_pos));
1075 if (GetWidget()->GetView())
1076 GetWidget()->GetView()->FocusedNodeTouched(location_dips_screen, editable);
1077 #endif
1078 }
1079
1080 void RenderViewHostImpl::SelectWordAroundCaret() { 1030 void RenderViewHostImpl::SelectWordAroundCaret() {
1081 Send(new ViewMsg_SelectWordAroundCaret(GetRoutingID())); 1031 Send(new ViewMsg_SelectWordAroundCaret(GetRoutingID()));
1082 } 1032 }
1083 1033
1084 void RenderViewHostImpl::PostRenderViewReady() { 1034 void RenderViewHostImpl::PostRenderViewReady() {
1085 if (GetProcess()->IsReady()) { 1035 if (GetProcess()->IsReady()) {
1086 BrowserThread::PostTask( 1036 BrowserThread::PostTask(
1087 BrowserThread::UI, 1037 BrowserThread::UI,
1088 FROM_HERE, 1038 FROM_HERE,
1089 base::Bind(&RenderViewHostImpl::RenderViewReady, 1039 base::Bind(&RenderViewHostImpl::RenderViewReady,
1090 weak_factory_.GetWeakPtr())); 1040 weak_factory_.GetWeakPtr()));
1091 } else { 1041 } else {
1092 render_view_ready_on_process_launch_ = true; 1042 render_view_ready_on_process_launch_ = true;
1093 } 1043 }
1094 } 1044 }
1095 1045
1096 void RenderViewHostImpl::RenderViewReady() { 1046 void RenderViewHostImpl::RenderViewReady() {
1097 delegate_->RenderViewReady(this); 1047 delegate_->RenderViewReady(this);
1098 } 1048 }
1099 1049
1100 } // namespace content 1050 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698