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

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: 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/web_service_worker_provider_impl.h" 24 #include "content/child/service_worker/web_service_worker_provider_impl.h"
24 #include "content/child/web_socket_stream_handle_impl.h" 25 #include "content/child/web_socket_stream_handle_impl.h"
25 #include "content/common/frame_messages.h" 26 #include "content/common/frame_messages.h"
27 #include "content/common/input_messages.h"
26 #include "content/common/socket_stream_handle_data.h" 28 #include "content/common/socket_stream_handle_data.h"
27 #include "content/common/swapped_out_messages.h" 29 #include "content/common/swapped_out_messages.h"
28 #include "content/common/view_messages.h" 30 #include "content/common/view_messages.h"
29 #include "content/public/common/bindings_policy.h" 31 #include "content/public/common/bindings_policy.h"
30 #include "content/public/common/content_constants.h" 32 #include "content/public/common/content_constants.h"
31 #include "content/public/common/content_switches.h" 33 #include "content/public/common/content_switches.h"
32 #include "content/public/common/context_menu_params.h" 34 #include "content/public/common/context_menu_params.h"
33 #include "content/public/common/url_constants.h" 35 #include "content/public/common/url_constants.h"
34 #include "content/public/common/url_utils.h" 36 #include "content/public/common/url_utils.h"
35 #include "content/public/renderer/content_renderer_client.h" 37 #include "content/public/renderer/content_renderer_client.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 #endif 87 #endif
86 88
87 #if defined(ENABLE_WEBRTC) 89 #if defined(ENABLE_WEBRTC)
88 #include "content/renderer/media/rtc_peer_connection_handler.h" 90 #include "content/renderer/media/rtc_peer_connection_handler.h"
89 #endif 91 #endif
90 92
91 using blink::WebContextMenuData; 93 using blink::WebContextMenuData;
92 using blink::WebData; 94 using blink::WebData;
93 using blink::WebDataSource; 95 using blink::WebDataSource;
94 using blink::WebDocument; 96 using blink::WebDocument;
97 using blink::WebElement;
95 using blink::WebFrame; 98 using blink::WebFrame;
96 using blink::WebHistoryItem; 99 using blink::WebHistoryItem;
97 using blink::WebHTTPBody; 100 using blink::WebHTTPBody;
98 using blink::WebNavigationPolicy; 101 using blink::WebNavigationPolicy;
99 using blink::WebNavigationType; 102 using blink::WebNavigationType;
103 using blink::WebNode;
100 using blink::WebPluginParams; 104 using blink::WebPluginParams;
101 using blink::WebReferrerPolicy; 105 using blink::WebReferrerPolicy;
102 using blink::WebSearchableFormData; 106 using blink::WebSearchableFormData;
103 using blink::WebSecurityOrigin; 107 using blink::WebSecurityOrigin;
104 using blink::WebSecurityPolicy; 108 using blink::WebSecurityPolicy;
105 using blink::WebServiceWorkerProvider; 109 using blink::WebServiceWorkerProvider;
106 using blink::WebStorageQuotaCallbacks; 110 using blink::WebStorageQuotaCallbacks;
107 using blink::WebString; 111 using blink::WebString;
108 using blink::WebURL; 112 using blink::WebURL;
109 using blink::WebURLError; 113 using blink::WebURLError;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 PepperPluginInstanceImpl* instance) { 353 PepperPluginInstanceImpl* instance) {
350 render_view_->set_pepper_last_mouse_event_target(instance); 354 render_view_->set_pepper_last_mouse_event_target(instance);
351 } 355 }
352 356
353 void RenderFrameImpl::PepperTextInputTypeChanged( 357 void RenderFrameImpl::PepperTextInputTypeChanged(
354 PepperPluginInstanceImpl* instance) { 358 PepperPluginInstanceImpl* instance) {
355 if (instance != render_view_->focused_pepper_plugin()) 359 if (instance != render_view_->focused_pepper_plugin())
356 return; 360 return;
357 361
358 GetRenderWidget()->UpdateTextInputType(); 362 GetRenderWidget()->UpdateTextInputType();
359 if (render_view_->renderer_accessibility()) { 363 if (render_view_->renderer_accessibility())
360 render_view_->renderer_accessibility()->FocusedNodeChanged( 364 render_view_->renderer_accessibility()->FocusedNodeChanged(WebNode());
361 blink::WebNode());
362 }
363 } 365 }
364 366
365 void RenderFrameImpl::PepperCaretPositionChanged( 367 void RenderFrameImpl::PepperCaretPositionChanged(
366 PepperPluginInstanceImpl* instance) { 368 PepperPluginInstanceImpl* instance) {
367 if (instance != render_view_->focused_pepper_plugin()) 369 if (instance != render_view_->focused_pepper_plugin())
368 return; 370 return;
369 GetRenderWidget()->UpdateSelectionBounds(); 371 GetRenderWidget()->UpdateSelectionBounds();
370 } 372 }
371 373
372 void RenderFrameImpl::PepperCancelComposition( 374 void RenderFrameImpl::PepperCancelComposition(
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 IPC_BEGIN_MESSAGE_MAP_EX(RenderFrameImpl, msg, msg_is_ok) 535 IPC_BEGIN_MESSAGE_MAP_EX(RenderFrameImpl, msg, msg_is_ok)
534 IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate) 536 IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate)
535 IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut) 537 IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut)
536 IPC_MESSAGE_HANDLER(FrameMsg_BuffersSwapped, OnBuffersSwapped) 538 IPC_MESSAGE_HANDLER(FrameMsg_BuffersSwapped, OnBuffersSwapped)
537 IPC_MESSAGE_HANDLER_GENERIC(FrameMsg_CompositorFrameSwapped, 539 IPC_MESSAGE_HANDLER_GENERIC(FrameMsg_CompositorFrameSwapped,
538 OnCompositorFrameSwapped(msg)) 540 OnCompositorFrameSwapped(msg))
539 IPC_MESSAGE_HANDLER(FrameMsg_ChildFrameProcessGone, OnChildFrameProcessGone) 541 IPC_MESSAGE_HANDLER(FrameMsg_ChildFrameProcessGone, OnChildFrameProcessGone)
540 IPC_MESSAGE_HANDLER(FrameMsg_ContextMenuClosed, OnContextMenuClosed) 542 IPC_MESSAGE_HANDLER(FrameMsg_ContextMenuClosed, OnContextMenuClosed)
541 IPC_MESSAGE_HANDLER(FrameMsg_CustomContextMenuAction, 543 IPC_MESSAGE_HANDLER(FrameMsg_CustomContextMenuAction,
542 OnCustomContextMenuAction) 544 OnCustomContextMenuAction)
545 IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut)
546 IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy)
547 IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste)
543 IPC_END_MESSAGE_MAP_EX() 548 IPC_END_MESSAGE_MAP_EX()
544 549
545 if (!msg_is_ok) { 550 if (!msg_is_ok) {
546 // The message had a handler, but its deserialization failed. 551 // The message had a handler, but its deserialization failed.
547 // Kill the renderer to avoid potential spoofing attacks. 552 // Kill the renderer to avoid potential spoofing attacks.
548 CHECK(false) << "Unable to deserialize message in RenderFrameImpl."; 553 CHECK(false) << "Unable to deserialize message in RenderFrameImpl.";
549 } 554 }
550 555
551 return handled; 556 return handled;
552 } 557 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 ContextMenuClient* client = 836 ContextMenuClient* client =
832 pending_context_menus_.Lookup(custom_context.request_id); 837 pending_context_menus_.Lookup(custom_context.request_id);
833 if (client) 838 if (client)
834 client->OnMenuAction(custom_context.request_id, action); 839 client->OnMenuAction(custom_context.request_id, action);
835 } else { 840 } else {
836 // Internal request, forward to WebKit. 841 // Internal request, forward to WebKit.
837 render_view_->webview()->performCustomContextMenuAction(action); 842 render_view_->webview()->performCustomContextMenuAction(action);
838 } 843 }
839 } 844 }
840 845
846 void RenderFrameImpl::OnCut() {
847 base::AutoReset<bool> handling_select_range(
848 &render_view_->handling_select_range_, true);
849 frame_->executeCommand(WebString::fromUTF8("Cut"), GetFocusedElement());
850 }
851
852 void RenderFrameImpl::OnCopy() {
853 base::AutoReset<bool> handling_select_range(
854 &render_view_->handling_select_range_, true);
855 WebNode current_node = render_view_->context_menu_node_.isNull() ?
856 GetFocusedElement() : render_view_->context_menu_node_;
857 frame_->executeCommand(WebString::fromUTF8("Copy"), current_node);
858 }
859
860 void RenderFrameImpl::OnPaste() {
861 base::AutoReset<bool> handling_select_range(
862 &render_view_->handling_select_range_, true);
863 frame_->executeCommand(WebString::fromUTF8("Paste"), GetFocusedElement());
864 }
865
841 bool RenderFrameImpl::ShouldUpdateSelectionTextFromContextMenuParams( 866 bool RenderFrameImpl::ShouldUpdateSelectionTextFromContextMenuParams(
842 const base::string16& selection_text, 867 const base::string16& selection_text,
843 size_t selection_text_offset, 868 size_t selection_text_offset,
844 const gfx::Range& selection_range, 869 const gfx::Range& selection_range,
845 const ContextMenuParams& params) { 870 const ContextMenuParams& params) {
846 base::string16 trimmed_selection_text; 871 base::string16 trimmed_selection_text;
847 if (!selection_text.empty() && !selection_range.is_empty()) { 872 if (!selection_text.empty() && !selection_range.is_empty()) {
848 const int start = selection_range.GetMin() - selection_text_offset; 873 const int start = selection_range.GetMin() - selection_text_offset;
849 const size_t length = selection_range.length(); 874 const size_t length = selection_range.length();
850 if (start >= 0 && start + length <= selection_text.length()) { 875 if (start >= 0 && start + length <= selection_text.length()) {
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 2333
2309 render_view_->last_page_id_sent_to_browser_ = 2334 render_view_->last_page_id_sent_to_browser_ =
2310 std::max(render_view_->last_page_id_sent_to_browser_, 2335 std::max(render_view_->last_page_id_sent_to_browser_,
2311 render_view_->page_id_); 2336 render_view_->page_id_);
2312 2337
2313 // If we end up reusing this WebRequest (for example, due to a #ref click), 2338 // If we end up reusing this WebRequest (for example, due to a #ref click),
2314 // we don't want the transition type to persist. Just clear it. 2339 // we don't want the transition type to persist. Just clear it.
2315 navigation_state->set_transition_type(PAGE_TRANSITION_LINK); 2340 navigation_state->set_transition_type(PAGE_TRANSITION_LINK);
2316 } 2341 }
2317 2342
2343 WebElement RenderFrameImpl::GetFocusedElement() {
2344 WebDocument doc = frame_->document();
2345 if (!doc.isNull())
2346 return doc.focusedElement();
2347
2348 return WebElement();
2349 }
2350
2318 void RenderFrameImpl::didStartLoading() { 2351 void RenderFrameImpl::didStartLoading() {
2319 Send(new FrameHostMsg_DidStartLoading(routing_id_)); 2352 Send(new FrameHostMsg_DidStartLoading(routing_id_));
2320 } 2353 }
2321 2354
2322 void RenderFrameImpl::didStopLoading() { 2355 void RenderFrameImpl::didStopLoading() {
2323 Send(new FrameHostMsg_DidStopLoading(routing_id_)); 2356 Send(new FrameHostMsg_DidStopLoading(routing_id_));
2324 } 2357 }
2325 2358
2326 WebNavigationPolicy RenderFrameImpl::DecidePolicyForNavigation( 2359 WebNavigationPolicy RenderFrameImpl::DecidePolicyForNavigation(
2327 RenderFrame* render_frame, 2360 RenderFrame* render_frame,
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
2576 policy == blink::WebNavigationPolicyNewForegroundTab || 2609 policy == blink::WebNavigationPolicyNewForegroundTab ||
2577 policy == blink::WebNavigationPolicyNewWindow || 2610 policy == blink::WebNavigationPolicyNewWindow ||
2578 policy == blink::WebNavigationPolicyNewPopup) { 2611 policy == blink::WebNavigationPolicyNewPopup) {
2579 WebUserGestureIndicator::consumeUserGesture(); 2612 WebUserGestureIndicator::consumeUserGesture();
2580 } 2613 }
2581 2614
2582 Send(new FrameHostMsg_OpenURL(routing_id_, params)); 2615 Send(new FrameHostMsg_OpenURL(routing_id_, params));
2583 } 2616 }
2584 2617
2585 } // namespace content 2618 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698