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

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

Issue 183923030: Almost finish moving context_menu_node_ from RenderViewImpl to RenderFrameImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 6 years, 9 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_frame_impl.h" 5 #include "content/renderer/render_frame_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/auto_reset.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/debug/alias.h" 12 #include "base/debug/alias.h"
12 #include "base/debug/dump_without_crashing.h" 13 #include "base/debug/dump_without_crashing.h"
13 #include "base/i18n/char_iterator.h" 14 #include "base/i18n/char_iterator.h"
14 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
15 #include "base/process/kill.h" 16 #include "base/process/kill.h"
16 #include "base/process/process.h" 17 #include "base/process/process.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "content/child/appcache/appcache_dispatcher.h" 20 #include "content/child/appcache/appcache_dispatcher.h"
20 #include "content/child/plugin_messages.h" 21 #include "content/child/plugin_messages.h"
21 #include "content/child/quota_dispatcher.h" 22 #include "content/child/quota_dispatcher.h"
22 #include "content/child/request_extra_data.h" 23 #include "content/child/request_extra_data.h"
23 #include "content/child/service_worker/service_worker_network_provider.h" 24 #include "content/child/service_worker/service_worker_network_provider.h"
24 #include "content/child/service_worker/web_service_worker_provider_impl.h" 25 #include "content/child/service_worker/web_service_worker_provider_impl.h"
25 #include "content/child/web_socket_stream_handle_impl.h" 26 #include "content/child/web_socket_stream_handle_impl.h"
26 #include "content/common/frame_messages.h" 27 #include "content/common/frame_messages.h"
28 #include "content/common/input_messages.h"
27 #include "content/common/service_worker/service_worker_types.h" 29 #include "content/common/service_worker/service_worker_types.h"
28 #include "content/common/socket_stream_handle_data.h" 30 #include "content/common/socket_stream_handle_data.h"
29 #include "content/common/swapped_out_messages.h" 31 #include "content/common/swapped_out_messages.h"
30 #include "content/common/view_messages.h" 32 #include "content/common/view_messages.h"
31 #include "content/public/common/bindings_policy.h" 33 #include "content/public/common/bindings_policy.h"
32 #include "content/public/common/content_constants.h" 34 #include "content/public/common/content_constants.h"
33 #include "content/public/common/content_switches.h" 35 #include "content/public/common/content_switches.h"
34 #include "content/public/common/context_menu_params.h" 36 #include "content/public/common/context_menu_params.h"
35 #include "content/public/common/url_constants.h" 37 #include "content/public/common/url_constants.h"
36 #include "content/public/common/url_utils.h" 38 #include "content/public/common/url_utils.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 #endif 89 #endif
88 90
89 #if defined(ENABLE_WEBRTC) 91 #if defined(ENABLE_WEBRTC)
90 #include "content/renderer/media/rtc_peer_connection_handler.h" 92 #include "content/renderer/media/rtc_peer_connection_handler.h"
91 #endif 93 #endif
92 94
93 using blink::WebContextMenuData; 95 using blink::WebContextMenuData;
94 using blink::WebData; 96 using blink::WebData;
95 using blink::WebDataSource; 97 using blink::WebDataSource;
96 using blink::WebDocument; 98 using blink::WebDocument;
99 using blink::WebElement;
97 using blink::WebFrame; 100 using blink::WebFrame;
98 using blink::WebHistoryItem; 101 using blink::WebHistoryItem;
99 using blink::WebHTTPBody; 102 using blink::WebHTTPBody;
100 using blink::WebNavigationPolicy; 103 using blink::WebNavigationPolicy;
101 using blink::WebNavigationType; 104 using blink::WebNavigationType;
105 using blink::WebNode;
102 using blink::WebPluginParams; 106 using blink::WebPluginParams;
103 using blink::WebReferrerPolicy; 107 using blink::WebReferrerPolicy;
104 using blink::WebSearchableFormData; 108 using blink::WebSearchableFormData;
105 using blink::WebSecurityOrigin; 109 using blink::WebSecurityOrigin;
106 using blink::WebSecurityPolicy; 110 using blink::WebSecurityPolicy;
107 using blink::WebServiceWorkerProvider; 111 using blink::WebServiceWorkerProvider;
108 using blink::WebStorageQuotaCallbacks; 112 using blink::WebStorageQuotaCallbacks;
109 using blink::WebString; 113 using blink::WebString;
110 using blink::WebURL; 114 using blink::WebURL;
111 using blink::WebURLError; 115 using blink::WebURLError;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 PepperPluginInstanceImpl* instance) { 355 PepperPluginInstanceImpl* instance) {
352 render_view_->set_pepper_last_mouse_event_target(instance); 356 render_view_->set_pepper_last_mouse_event_target(instance);
353 } 357 }
354 358
355 void RenderFrameImpl::PepperTextInputTypeChanged( 359 void RenderFrameImpl::PepperTextInputTypeChanged(
356 PepperPluginInstanceImpl* instance) { 360 PepperPluginInstanceImpl* instance) {
357 if (instance != render_view_->focused_pepper_plugin()) 361 if (instance != render_view_->focused_pepper_plugin())
358 return; 362 return;
359 363
360 GetRenderWidget()->UpdateTextInputType(); 364 GetRenderWidget()->UpdateTextInputType();
361 if (render_view_->renderer_accessibility()) { 365 if (render_view_->renderer_accessibility())
362 render_view_->renderer_accessibility()->FocusedNodeChanged( 366 render_view_->renderer_accessibility()->FocusedNodeChanged(WebNode());
363 blink::WebNode());
364 }
365 } 367 }
366 368
367 void RenderFrameImpl::PepperCaretPositionChanged( 369 void RenderFrameImpl::PepperCaretPositionChanged(
368 PepperPluginInstanceImpl* instance) { 370 PepperPluginInstanceImpl* instance) {
369 if (instance != render_view_->focused_pepper_plugin()) 371 if (instance != render_view_->focused_pepper_plugin())
370 return; 372 return;
371 GetRenderWidget()->UpdateSelectionBounds(); 373 GetRenderWidget()->UpdateSelectionBounds();
372 } 374 }
373 375
374 void RenderFrameImpl::PepperCancelComposition( 376 void RenderFrameImpl::PepperCancelComposition(
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 IPC_BEGIN_MESSAGE_MAP_EX(RenderFrameImpl, msg, msg_is_ok) 537 IPC_BEGIN_MESSAGE_MAP_EX(RenderFrameImpl, msg, msg_is_ok)
536 IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate) 538 IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate)
537 IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut) 539 IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut)
538 IPC_MESSAGE_HANDLER(FrameMsg_BuffersSwapped, OnBuffersSwapped) 540 IPC_MESSAGE_HANDLER(FrameMsg_BuffersSwapped, OnBuffersSwapped)
539 IPC_MESSAGE_HANDLER_GENERIC(FrameMsg_CompositorFrameSwapped, 541 IPC_MESSAGE_HANDLER_GENERIC(FrameMsg_CompositorFrameSwapped,
540 OnCompositorFrameSwapped(msg)) 542 OnCompositorFrameSwapped(msg))
541 IPC_MESSAGE_HANDLER(FrameMsg_ChildFrameProcessGone, OnChildFrameProcessGone) 543 IPC_MESSAGE_HANDLER(FrameMsg_ChildFrameProcessGone, OnChildFrameProcessGone)
542 IPC_MESSAGE_HANDLER(FrameMsg_ContextMenuClosed, OnContextMenuClosed) 544 IPC_MESSAGE_HANDLER(FrameMsg_ContextMenuClosed, OnContextMenuClosed)
543 IPC_MESSAGE_HANDLER(FrameMsg_CustomContextMenuAction, 545 IPC_MESSAGE_HANDLER(FrameMsg_CustomContextMenuAction,
544 OnCustomContextMenuAction) 546 OnCustomContextMenuAction)
547 IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut)
548 IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy)
549 IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste)
545 IPC_END_MESSAGE_MAP_EX() 550 IPC_END_MESSAGE_MAP_EX()
546 551
547 if (!msg_is_ok) { 552 if (!msg_is_ok) {
548 // The message had a handler, but its deserialization failed. 553 // The message had a handler, but its deserialization failed.
549 // Kill the renderer to avoid potential spoofing attacks. 554 // Kill the renderer to avoid potential spoofing attacks.
550 CHECK(false) << "Unable to deserialize message in RenderFrameImpl."; 555 CHECK(false) << "Unable to deserialize message in RenderFrameImpl.";
551 } 556 }
552 557
553 return handled; 558 return handled;
554 } 559 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 ContextMenuClient* client = 838 ContextMenuClient* client =
834 pending_context_menus_.Lookup(custom_context.request_id); 839 pending_context_menus_.Lookup(custom_context.request_id);
835 if (client) 840 if (client)
836 client->OnMenuAction(custom_context.request_id, action); 841 client->OnMenuAction(custom_context.request_id, action);
837 } else { 842 } else {
838 // Internal request, forward to WebKit. 843 // Internal request, forward to WebKit.
839 render_view_->webview()->performCustomContextMenuAction(action); 844 render_view_->webview()->performCustomContextMenuAction(action);
840 } 845 }
841 } 846 }
842 847
848 void RenderFrameImpl::OnCut() {
849 base::AutoReset<bool> handling_select_range(
850 &render_view_->handling_select_range_, true);
851 frame_->executeCommand(WebString::fromUTF8("Cut"), GetFocusedElement());
852 }
853
854 void RenderFrameImpl::OnCopy() {
855 base::AutoReset<bool> handling_select_range(
856 &render_view_->handling_select_range_, true);
857 WebNode current_node = render_view_->context_menu_node_.isNull() ?
858 GetFocusedElement() : render_view_->context_menu_node_;
859 frame_->executeCommand(WebString::fromUTF8("Copy"), current_node);
860 }
861
862 void RenderFrameImpl::OnPaste() {
863 base::AutoReset<bool> handling_select_range(
864 &render_view_->handling_select_range_, true);
865 frame_->executeCommand(WebString::fromUTF8("Paste"), GetFocusedElement());
866 }
867
843 bool RenderFrameImpl::ShouldUpdateSelectionTextFromContextMenuParams( 868 bool RenderFrameImpl::ShouldUpdateSelectionTextFromContextMenuParams(
844 const base::string16& selection_text, 869 const base::string16& selection_text,
845 size_t selection_text_offset, 870 size_t selection_text_offset,
846 const gfx::Range& selection_range, 871 const gfx::Range& selection_range,
847 const ContextMenuParams& params) { 872 const ContextMenuParams& params) {
848 base::string16 trimmed_selection_text; 873 base::string16 trimmed_selection_text;
849 if (!selection_text.empty() && !selection_range.is_empty()) { 874 if (!selection_text.empty() && !selection_range.is_empty()) {
850 const int start = selection_range.GetMin() - selection_text_offset; 875 const int start = selection_range.GetMin() - selection_text_offset;
851 const size_t length = selection_range.length(); 876 const size_t length = selection_range.length();
852 if (start >= 0 && start + length <= selection_text.length()) { 877 if (start >= 0 && start + length <= selection_text.length()) {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 1120
1096 // |frame| is invalid after here. 1121 // |frame| is invalid after here.
1097 frame->close(); 1122 frame->close();
1098 1123
1099 if (is_subframe) { 1124 if (is_subframe) {
1100 delete this; 1125 delete this;
1101 // Object is invalid after this point. 1126 // Object is invalid after this point.
1102 } 1127 }
1103 } 1128 }
1104 1129
1130 void RenderFrameImpl::frameFocused() {
1131 Send(new FrameHostMsg_FrameFocused(routing_id_));
1132 }
1133
1105 void RenderFrameImpl::willClose(blink::WebFrame* frame) { 1134 void RenderFrameImpl::willClose(blink::WebFrame* frame) {
1106 DCHECK(!frame_ || frame_ == frame); 1135 DCHECK(!frame_ || frame_ == frame);
1107 // Call back to RenderViewImpl for observers to be notified. 1136 // Call back to RenderViewImpl for observers to be notified.
1108 // TODO(nasko): Remove once we have RenderFrameObserver. 1137 // TODO(nasko): Remove once we have RenderFrameObserver.
1109 render_view_->willClose(frame); 1138 render_view_->willClose(frame);
1110 } 1139 }
1111 1140
1112 void RenderFrameImpl::didChangeName(blink::WebFrame* frame, 1141 void RenderFrameImpl::didChangeName(blink::WebFrame* frame,
1113 const blink::WebString& name) { 1142 const blink::WebString& name) {
1114 DCHECK(!frame_ || frame_ == frame); 1143 DCHECK(!frame_ || frame_ == frame);
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2356 2385
2357 render_view_->last_page_id_sent_to_browser_ = 2386 render_view_->last_page_id_sent_to_browser_ =
2358 std::max(render_view_->last_page_id_sent_to_browser_, 2387 std::max(render_view_->last_page_id_sent_to_browser_,
2359 render_view_->page_id_); 2388 render_view_->page_id_);
2360 2389
2361 // If we end up reusing this WebRequest (for example, due to a #ref click), 2390 // If we end up reusing this WebRequest (for example, due to a #ref click),
2362 // we don't want the transition type to persist. Just clear it. 2391 // we don't want the transition type to persist. Just clear it.
2363 navigation_state->set_transition_type(PAGE_TRANSITION_LINK); 2392 navigation_state->set_transition_type(PAGE_TRANSITION_LINK);
2364 } 2393 }
2365 2394
2395 WebElement RenderFrameImpl::GetFocusedElement() {
2396 WebDocument doc = frame_->document();
2397 if (!doc.isNull())
2398 return doc.focusedElement();
2399
2400 return WebElement();
2401 }
2402
2366 void RenderFrameImpl::didStartLoading() { 2403 void RenderFrameImpl::didStartLoading() {
2367 Send(new FrameHostMsg_DidStartLoading(routing_id_)); 2404 Send(new FrameHostMsg_DidStartLoading(routing_id_));
2368 } 2405 }
2369 2406
2370 void RenderFrameImpl::didStopLoading() { 2407 void RenderFrameImpl::didStopLoading() {
2371 Send(new FrameHostMsg_DidStopLoading(routing_id_)); 2408 Send(new FrameHostMsg_DidStopLoading(routing_id_));
2372 } 2409 }
2373 2410
2374 WebNavigationPolicy RenderFrameImpl::DecidePolicyForNavigation( 2411 WebNavigationPolicy RenderFrameImpl::DecidePolicyForNavigation(
2375 RenderFrame* render_frame, 2412 RenderFrame* render_frame,
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2623 policy == blink::WebNavigationPolicyNewForegroundTab || 2660 policy == blink::WebNavigationPolicyNewForegroundTab ||
2624 policy == blink::WebNavigationPolicyNewWindow || 2661 policy == blink::WebNavigationPolicyNewWindow ||
2625 policy == blink::WebNavigationPolicyNewPopup) { 2662 policy == blink::WebNavigationPolicyNewPopup) {
2626 WebUserGestureIndicator::consumeUserGesture(); 2663 WebUserGestureIndicator::consumeUserGesture();
2627 } 2664 }
2628 2665
2629 Send(new FrameHostMsg_OpenURL(routing_id_, params)); 2666 Send(new FrameHostMsg_OpenURL(routing_id_, params));
2630 } 2667 }
2631 2668
2632 } // namespace content 2669 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698