| OLD | NEW |
| 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 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) | 1118 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
| 1119 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) | 1119 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
| 1120 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor) | 1120 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor) |
| 1121 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, | 1121 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 1122 OnSetZoomLevelForLoadingURL) | 1122 OnSetZoomLevelForLoadingURL) |
| 1123 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) | 1123 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
| 1124 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, | 1124 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 1125 OnResetPageEncodingToDefault) | 1125 OnResetPageEncodingToDefault) |
| 1126 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) | 1126 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
| 1127 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) | 1127 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) |
| 1128 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) | |
| 1129 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) | 1128 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 1130 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) | 1129 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 1131 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) | 1130 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 1132 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) | 1131 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
| 1133 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved) | 1132 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved) |
| 1134 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, | 1133 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 1135 OnDragSourceSystemDragEnded) | 1134 OnDragSourceSystemDragEnded) |
| 1136 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) | 1135 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
| 1137 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) | 1136 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
| 1138 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) | 1137 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| (...skipping 2103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3242 | 3241 |
| 3243 return false; | 3242 return false; |
| 3244 } | 3243 } |
| 3245 | 3244 |
| 3246 void RenderViewImpl::EvaluateScript(const base::string16& frame_xpath, | 3245 void RenderViewImpl::EvaluateScript(const base::string16& frame_xpath, |
| 3247 const base::string16& jscript, | 3246 const base::string16& jscript, |
| 3248 int id, | 3247 int id, |
| 3249 bool notify_result) { | 3248 bool notify_result) { |
| 3250 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 3249 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 3251 v8::Handle<v8::Value> result; | 3250 v8::Handle<v8::Value> result; |
| 3252 WebFrame* web_frame = GetChildFrame(frame_xpath); | 3251 |
| 3252 WebFrame* web_frame; |
| 3253 if (frame_xpath.empty()) { |
| 3254 web_frame = webview()->mainFrame(); |
| 3255 } else { |
| 3256 // The |frame_xpath| string can represent a frame deep down the tree (across |
| 3257 // multiple frame DOMs). |
| 3258 // |
| 3259 // For example, |
| 3260 // /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 3261 // should break into 2 xpaths: |
| 3262 // /html/body/table/tbody/tr/td/iframe |
| 3263 // /frameset/frame[0] |
| 3264 std::vector<base::string16> xpaths; |
| 3265 base::SplitString(frame_xpath, '\n', &xpaths); |
| 3266 |
| 3267 WebFrame* frame = webview()->mainFrame(); |
| 3268 for (std::vector<base::string16>::const_iterator i = xpaths.begin(); |
| 3269 frame && i != xpaths.end(); ++i) { |
| 3270 frame = frame->findChildByExpression(*i); |
| 3271 } |
| 3272 |
| 3273 web_frame = frame; |
| 3274 } |
| 3275 |
| 3253 if (web_frame) | 3276 if (web_frame) |
| 3254 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript)); | 3277 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript)); |
| 3255 if (notify_result) { | 3278 if (notify_result) { |
| 3256 base::ListValue list; | 3279 base::ListValue list; |
| 3257 if (!result.IsEmpty() && web_frame) { | 3280 if (!result.IsEmpty() && web_frame) { |
| 3258 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); | 3281 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); |
| 3259 v8::Context::Scope context_scope(context); | 3282 v8::Context::Scope context_scope(context); |
| 3260 V8ValueConverterImpl converter; | 3283 V8ValueConverterImpl converter; |
| 3261 converter.SetDateAllowed(true); | 3284 converter.SetDateAllowed(true); |
| 3262 converter.SetRegExpAllowed(true); | 3285 converter.SetRegExpAllowed(true); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3680 | 3703 |
| 3681 void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { | 3704 void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { |
| 3682 webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); | 3705 webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
| 3683 } | 3706 } |
| 3684 | 3707 |
| 3685 void RenderViewImpl::OnResetPageEncodingToDefault() { | 3708 void RenderViewImpl::OnResetPageEncodingToDefault() { |
| 3686 WebString no_encoding; | 3709 WebString no_encoding; |
| 3687 webview()->setPageEncoding(no_encoding); | 3710 webview()->setPageEncoding(no_encoding); |
| 3688 } | 3711 } |
| 3689 | 3712 |
| 3690 WebFrame* RenderViewImpl::GetChildFrame(const base::string16& xpath) const { | |
| 3691 if (xpath.empty()) | |
| 3692 return webview()->mainFrame(); | |
| 3693 | |
| 3694 // xpath string can represent a frame deep down the tree (across multiple | |
| 3695 // frame DOMs). | |
| 3696 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] | |
| 3697 // should break into 2 xpaths | |
| 3698 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] | |
| 3699 std::vector<base::string16> xpaths; | |
| 3700 base::SplitString(xpath, '\n', &xpaths); | |
| 3701 | |
| 3702 WebFrame* frame = webview()->mainFrame(); | |
| 3703 for (std::vector<base::string16>::const_iterator i = xpaths.begin(); | |
| 3704 frame && i != xpaths.end(); ++i) { | |
| 3705 frame = frame->findChildByExpression(*i); | |
| 3706 } | |
| 3707 | |
| 3708 return frame; | |
| 3709 } | |
| 3710 | |
| 3711 void RenderViewImpl::OnScriptEvalRequest(const base::string16& frame_xpath, | 3713 void RenderViewImpl::OnScriptEvalRequest(const base::string16& frame_xpath, |
| 3712 const base::string16& jscript, | 3714 const base::string16& jscript, |
| 3713 int id, | 3715 int id, |
| 3714 bool notify_result) { | 3716 bool notify_result) { |
| 3715 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest", | 3717 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest", |
| 3716 TRACE_EVENT_SCOPE_THREAD); | 3718 TRACE_EVENT_SCOPE_THREAD); |
| 3717 EvaluateScript(frame_xpath, jscript, id, notify_result); | 3719 EvaluateScript(frame_xpath, jscript, id, notify_result); |
| 3718 } | 3720 } |
| 3719 | 3721 |
| 3720 void RenderViewImpl::OnPostMessageEvent( | 3722 void RenderViewImpl::OnPostMessageEvent( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3755 // We must pass in the target_origin to do the security check on this side, | 3757 // We must pass in the target_origin to do the security check on this side, |
| 3756 // since it may have changed since the original postMessage call was made. | 3758 // since it may have changed since the original postMessage call was made. |
| 3757 WebSecurityOrigin target_origin; | 3759 WebSecurityOrigin target_origin; |
| 3758 if (!params.target_origin.empty()) { | 3760 if (!params.target_origin.empty()) { |
| 3759 target_origin = | 3761 target_origin = |
| 3760 WebSecurityOrigin::createFromString(WebString(params.target_origin)); | 3762 WebSecurityOrigin::createFromString(WebString(params.target_origin)); |
| 3761 } | 3763 } |
| 3762 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); | 3764 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); |
| 3763 } | 3765 } |
| 3764 | 3766 |
| 3765 void RenderViewImpl::OnCSSInsertRequest(const base::string16& frame_xpath, | |
| 3766 const std::string& css) { | |
| 3767 WebFrame* frame = GetChildFrame(frame_xpath); | |
| 3768 if (!frame) | |
| 3769 return; | |
| 3770 | |
| 3771 frame->document().insertStyleSheet(WebString::fromUTF8(css)); | |
| 3772 } | |
| 3773 | |
| 3774 void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { | 3767 void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { |
| 3775 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) && | 3768 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) && |
| 3776 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) { | 3769 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) { |
| 3777 new WebUIExtensionData(this); | 3770 new WebUIExtensionData(this); |
| 3778 } | 3771 } |
| 3779 | 3772 |
| 3780 enabled_bindings_ |= enabled_bindings_flags; | 3773 enabled_bindings_ |= enabled_bindings_flags; |
| 3781 | 3774 |
| 3782 // Keep track of the total bindings accumulated in this process. | 3775 // Keep track of the total bindings accumulated in this process. |
| 3783 RenderProcess::current()->AddBindings(enabled_bindings_flags); | 3776 RenderProcess::current()->AddBindings(enabled_bindings_flags); |
| (...skipping 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5223 for (size_t i = 0; i < icon_urls.size(); i++) { | 5216 for (size_t i = 0; i < icon_urls.size(); i++) { |
| 5224 WebURL url = icon_urls[i].iconURL(); | 5217 WebURL url = icon_urls[i].iconURL(); |
| 5225 if (!url.isEmpty()) | 5218 if (!url.isEmpty()) |
| 5226 urls.push_back(FaviconURL(url, | 5219 urls.push_back(FaviconURL(url, |
| 5227 ToFaviconType(icon_urls[i].iconType()))); | 5220 ToFaviconType(icon_urls[i].iconType()))); |
| 5228 } | 5221 } |
| 5229 SendUpdateFaviconURL(urls); | 5222 SendUpdateFaviconURL(urls); |
| 5230 } | 5223 } |
| 5231 | 5224 |
| 5232 } // namespace content | 5225 } // namespace content |
| OLD | NEW |