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

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

Issue 208793005: Remove JavaScript execution from RenderViewHost. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 6 years, 8 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
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) 1086 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
1087 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) 1087 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
1088 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) 1088 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
1089 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) 1089 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
1090 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) 1090 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
1091 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, 1091 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1092 OnSetZoomLevelForLoadingURL) 1092 OnSetZoomLevelForLoadingURL)
1093 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) 1093 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
1094 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, 1094 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1095 OnResetPageEncodingToDefault) 1095 OnResetPageEncodingToDefault)
1096 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
1097 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) 1096 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
1098 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) 1097 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
1099 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) 1098 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
1100 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) 1099 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
1101 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) 1100 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
1102 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved) 1101 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
1103 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, 1102 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
1104 OnDragSourceSystemDragEnded) 1103 OnDragSourceSystemDragEnded)
1105 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) 1104 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
1106 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) 1105 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
(...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after
3047 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox")) 3046 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
3048 return true; 3047 return true;
3049 break; 3048 break;
3050 } 3049 }
3051 } 3050 }
3052 } 3051 }
3053 3052
3054 return false; 3053 return false;
3055 } 3054 }
3056 3055
3057 void RenderViewImpl::EvaluateScript(const base::string16& frame_xpath,
3058 const base::string16& jscript,
3059 int id,
3060 bool notify_result) {
3061 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
3062 v8::Handle<v8::Value> result;
3063
3064 WebFrame* web_frame;
3065 if (frame_xpath.empty()) {
3066 web_frame = webview()->mainFrame();
3067 } else {
3068 // The |frame_xpath| string can represent a frame deep down the tree (across
3069 // multiple frame DOMs).
3070 //
3071 // For example,
3072 // /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3073 // should break into 2 xpaths:
3074 // /html/body/table/tbody/tr/td/iframe
3075 // /frameset/frame[0]
3076 std::vector<base::string16> xpaths;
3077 base::SplitString(frame_xpath, '\n', &xpaths);
3078
3079 WebFrame* frame = webview()->mainFrame();
3080 for (std::vector<base::string16>::const_iterator i = xpaths.begin();
3081 frame && i != xpaths.end(); ++i) {
3082 frame = frame->findChildByExpression(*i);
3083 }
3084
3085 web_frame = frame;
3086 }
3087
3088 if (web_frame)
3089 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3090 if (notify_result) {
3091 base::ListValue list;
3092 if (!result.IsEmpty() && web_frame) {
3093 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3094 v8::Context::Scope context_scope(context);
3095 V8ValueConverterImpl converter;
3096 converter.SetDateAllowed(true);
3097 converter.SetRegExpAllowed(true);
3098 base::Value* result_value = converter.FromV8Value(result, context);
3099 list.Set(0, result_value ? result_value : base::Value::CreateNullValue());
3100 } else {
3101 list.Set(0, base::Value::CreateNullValue());
3102 }
3103 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3104 }
3105 }
3106
3107 bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { 3056 bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
3108 return (!send_preferred_size_changes_ || 3057 return (!send_preferred_size_changes_ ||
3109 (disable_scrollbars_size_limit_.width() <= width || 3058 (disable_scrollbars_size_limit_.width() <= width ||
3110 disable_scrollbars_size_limit_.height() <= height)); 3059 disable_scrollbars_size_limit_.height() <= height));
3111 } 3060 }
3112 3061
3113 int RenderViewImpl::GetEnabledBindings() const { 3062 int RenderViewImpl::GetEnabledBindings() const {
3114 return enabled_bindings_; 3063 return enabled_bindings_;
3115 } 3064 }
3116 3065
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
3440 3389
3441 void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { 3390 void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
3442 webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); 3391 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
3443 } 3392 }
3444 3393
3445 void RenderViewImpl::OnResetPageEncodingToDefault() { 3394 void RenderViewImpl::OnResetPageEncodingToDefault() {
3446 WebString no_encoding; 3395 WebString no_encoding;
3447 webview()->setPageEncoding(no_encoding); 3396 webview()->setPageEncoding(no_encoding);
3448 } 3397 }
3449 3398
3450 void RenderViewImpl::OnScriptEvalRequest(const base::string16& frame_xpath,
3451 const base::string16& jscript,
3452 int id,
3453 bool notify_result) {
3454 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest",
3455 TRACE_EVENT_SCOPE_THREAD);
3456 EvaluateScript(frame_xpath, jscript, id, notify_result);
3457 }
3458
3459 void RenderViewImpl::OnPostMessageEvent( 3399 void RenderViewImpl::OnPostMessageEvent(
3460 const ViewMsg_PostMessage_Params& params) { 3400 const ViewMsg_PostMessage_Params& params) {
3461 // TODO(nasko): Support sending to subframes. 3401 // TODO(nasko): Support sending to subframes.
3462 WebFrame* frame = webview()->mainFrame(); 3402 WebFrame* frame = webview()->mainFrame();
3463 3403
3464 // Find the source frame if it exists. 3404 // Find the source frame if it exists.
3465 WebFrame* source_frame = NULL; 3405 WebFrame* source_frame = NULL;
3466 if (params.source_routing_id != MSG_ROUTING_NONE) { 3406 if (params.source_routing_id != MSG_ROUTING_NONE) {
3467 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); 3407 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
3468 if (source_view) 3408 if (source_view)
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after
4909 std::vector<gfx::Size> sizes(icon_urls[i].sizes().size()); 4849 std::vector<gfx::Size> sizes(icon_urls[i].sizes().size());
4910 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); 4850 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
4911 if (!url.isEmpty()) 4851 if (!url.isEmpty())
4912 urls.push_back( 4852 urls.push_back(
4913 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes)); 4853 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes));
4914 } 4854 }
4915 SendUpdateFaviconURL(urls); 4855 SendUpdateFaviconURL(urls);
4916 } 4856 }
4917 4857
4918 } // namespace content 4858 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698