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

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

Issue 11193051: To fix the cross-site post submission bug. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Structure and Tests Created 8 years, 1 month 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 (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/bind.h" 10 #include "base/bind.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 #include "ui/gfx/point.h" 178 #include "ui/gfx/point.h"
179 #include "ui/gfx/rect.h" 179 #include "ui/gfx/rect.h"
180 #include "ui/gfx/size_conversions.h" 180 #include "ui/gfx/size_conversions.h"
181 #include "v8/include/v8.h" 181 #include "v8/include/v8.h"
182 #include "webkit/appcache/web_application_cache_host_impl.h" 182 #include "webkit/appcache/web_application_cache_host_impl.h"
183 #include "webkit/base/file_path_string_conversions.h" 183 #include "webkit/base/file_path_string_conversions.h"
184 #include "webkit/dom_storage/dom_storage_types.h" 184 #include "webkit/dom_storage/dom_storage_types.h"
185 #include "webkit/glue/alt_error_page_resource_fetcher.h" 185 #include "webkit/glue/alt_error_page_resource_fetcher.h"
186 #include "webkit/glue/dom_operations.h" 186 #include "webkit/glue/dom_operations.h"
187 #include "webkit/glue/glue_serialize.h" 187 #include "webkit/glue/glue_serialize.h"
188 #include "webkit/glue/resource_request_body.h"
188 #include "webkit/glue/web_intent_service_data.h" 189 #include "webkit/glue/web_intent_service_data.h"
189 #include "webkit/glue/webdropdata.h" 190 #include "webkit/glue/webdropdata.h"
190 #include "webkit/glue/webkit_constants.h" 191 #include "webkit/glue/webkit_constants.h"
191 #include "webkit/glue/webkit_glue.h" 192 #include "webkit/glue/webkit_glue.h"
192 #include "webkit/glue/weburlresponse_extradata_impl.h" 193 #include "webkit/glue/weburlresponse_extradata_impl.h"
193 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" 194 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
194 #include "webkit/media/webmediaplayer_impl.h" 195 #include "webkit/media/webmediaplayer_impl.h"
195 #include "webkit/media/webmediaplayer_ms.h" 196 #include "webkit/media/webmediaplayer_ms.h"
196 #include "webkit/plugins/npapi/plugin_list.h" 197 #include "webkit/plugins/npapi/plugin_list.h"
197 #include "webkit/plugins/npapi/webplugin_delegate.h" 198 #include "webkit/plugins/npapi/webplugin_delegate.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 using WebKit::WebVector; 314 using WebKit::WebVector;
314 using WebKit::WebView; 315 using WebKit::WebView;
315 using WebKit::WebWidget; 316 using WebKit::WebWidget;
316 using WebKit::WebWindowFeatures; 317 using WebKit::WebWindowFeatures;
317 using appcache::WebApplicationCacheHostImpl; 318 using appcache::WebApplicationCacheHostImpl;
318 using base::Time; 319 using base::Time;
319 using base::TimeDelta; 320 using base::TimeDelta;
320 321
321 using webkit_glue::AltErrorPageResourceFetcher; 322 using webkit_glue::AltErrorPageResourceFetcher;
322 using webkit_glue::ResourceFetcher; 323 using webkit_glue::ResourceFetcher;
324 using webkit_glue::ResourceRequestBody;
323 using webkit_glue::WebPreferences; 325 using webkit_glue::WebPreferences;
324 using webkit_glue::WebURLResponseExtraDataImpl; 326 using webkit_glue::WebURLResponseExtraDataImpl;
325 327
326 #if defined(OS_ANDROID) 328 #if defined(OS_ANDROID)
327 using WebKit::WebContentDetectionResult; 329 using WebKit::WebContentDetectionResult;
328 using WebKit::WebFloatPoint; 330 using WebKit::WebFloatPoint;
329 using WebKit::WebFloatRect; 331 using WebKit::WebFloatRect;
330 using WebKit::WebHitTestResult; 332 using WebKit::WebHitTestResult;
331 #endif 333 #endif
332 334
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 1127
1126 if (!params.extra_headers.empty()) { 1128 if (!params.extra_headers.empty()) {
1127 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(), 1129 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1128 params.extra_headers.end(), "\n"); 1130 params.extra_headers.end(), "\n");
1129 i.GetNext(); ) { 1131 i.GetNext(); ) {
1130 request.addHTTPHeaderField(WebString::fromUTF8(i.name()), 1132 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1131 WebString::fromUTF8(i.values())); 1133 WebString::fromUTF8(i.values()));
1132 } 1134 }
1133 } 1135 }
1134 1136
1135 if (params.is_post) { 1137 // Deal With Cross-Process Post Submission
michaeln 2012/11/05 23:38:29 Since this isn't always for cross-process post han
irobert 2012/11/06 05:39:20 Done.
1136 request.setHTTPMethod(WebString::fromUTF8("POST")); 1138 if(params.is_post) {
1137
1138 // Set post data.
1139 WebHTTPBody http_body; 1139 WebHTTPBody http_body;
1140 http_body.initialize(); 1140 http_body.initialize();
1141 http_body.appendData(WebData( 1141 const std::vector<ResourceRequestBody::Element>* uploads =
1142 reinterpret_cast<const char*>( 1142 params.browser_initiated_post_data->elements();
1143 &params.browser_initiated_post_data.front()), 1143 std::vector<ResourceRequestBody::Element>::const_iterator iter;
1144 params.browser_initiated_post_data.size())); 1144 for (iter = uploads->begin(); iter != uploads->end(); ++iter) {
1145 switch (iter->type()) {
1146 case ResourceRequestBody::Element::TYPE_BYTES: {
1147 http_body.appendData(WebData(iter->bytes(),
1148 static_cast<int>(iter->length())));
1149 break;
1150 }
1151 case ResourceRequestBody::Element::TYPE_FILE: {
1152 http_body.appendFileRange(
1153 WebString::fromUTF8(iter->path().value()),
1154 static_cast<long long>(iter->offset()),
1155 static_cast<long long>(iter->length()),
1156 iter->expected_modification_time().ToDoubleT());
1157 break;
1158 }
1159 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM: {
1160 CHECK(false);
1161 break;
1162 }
1163 case ResourceRequestBody::Element:: TYPE_BLOB: {
1164 CHECK(false);
1165 break;
1166 }
1167 default:
1168 NOTREACHED();
1169 }
1170 }
1145 request.setHTTPBody(http_body); 1171 request.setHTTPBody(http_body);
1172 request.setHTTPMethod(WebString::fromUTF8("POST"));
michaeln 2012/11/05 23:38:29 If it's OK to assume POST as the method here, grea
irobert 2012/11/06 05:39:20 We can assume this from the original code, this pi
michaeln 2012/11/06 22:18:41 Not sure i follow. If content shows up that looks
irobert 2012/11/06 22:25:45 PUT method submission will not end up in this bloc
1173 request.setHTTPHeaderField(
1174 WebString::fromUTF8("Content-Type"),
1175 WebString::fromUTF8(params.extra_headers));
1146 } 1176 }
1147
1148 main_frame->loadRequest(request); 1177 main_frame->loadRequest(request);
1149 } 1178 }
1150
1151 // In case LoadRequest failed before DidCreateDataSource was called. 1179 // In case LoadRequest failed before DidCreateDataSource was called.
1152 pending_navigation_params_.reset(); 1180 pending_navigation_params_.reset();
1153 } 1181 }
1154 1182
1155 bool RenderViewImpl::IsBackForwardToStaleEntry( 1183 bool RenderViewImpl::IsBackForwardToStaleEntry(
1156 const ViewMsg_Navigate_Params& params, 1184 const ViewMsg_Navigate_Params& params,
1157 bool is_reload) { 1185 bool is_reload) {
1158 // Make sure this isn't a back/forward to an entry we have already cropped 1186 // Make sure this isn't a back/forward to an entry we have already cropped
1159 // or replaced from our history, before the browser knew about it. If so, 1187 // or replaced from our history, before the browser knew about it. If so,
1160 // a new navigation has committed in the mean time, and we can ignore this. 1188 // a new navigation has committed in the mean time, and we can ignore this.
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 const Referrer& referrer, 1685 const Referrer& referrer,
1658 WebNavigationPolicy policy) { 1686 WebNavigationPolicy policy) {
1659 Send(new ViewHostMsg_OpenURL( 1687 Send(new ViewHostMsg_OpenURL(
1660 routing_id_, 1688 routing_id_,
1661 url, 1689 url,
1662 referrer, 1690 referrer,
1663 NavigationPolicyToDisposition(policy), 1691 NavigationPolicyToDisposition(policy),
1664 frame->identifier())); 1692 frame->identifier()));
1665 } 1693 }
1666 1694
1695 // Handle cross-process Post submit Navigation.
1696 void RenderViewImpl::OpenPostURL(
1697 WebFrame* frame,
1698 const GURL& url,
1699 const Referrer& referrer,
1700 WebNavigationPolicy policy,
1701 const ViewMsg_PostRequest_Params& request) {
1702 Send(new ViewHostMsg_OpenPostURL(
1703 routing_id_,
1704 url,
1705 referrer,
1706 NavigationPolicyToDisposition(policy),
1707 frame->identifier(),
1708 request));
1709 }
1710
1667 // WebViewDelegate ------------------------------------------------------------ 1711 // WebViewDelegate ------------------------------------------------------------
1668 1712
1669 void RenderViewImpl::LoadNavigationErrorPage( 1713 void RenderViewImpl::LoadNavigationErrorPage(
1670 WebFrame* frame, 1714 WebFrame* frame,
1671 const WebURLRequest& failed_request, 1715 const WebURLRequest& failed_request,
1672 const WebURLError& error, 1716 const WebURLError& error,
1673 const std::string& html, 1717 const std::string& html,
1674 bool replace) { 1718 bool replace) {
1675 std::string alt_html; 1719 std::string alt_html;
1676 const std::string* error_html; 1720 const std::string* error_html;
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after
2720 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 2764 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2721 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) && 2765 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2722 !frame->parent() && (is_content_initiated || is_redirect)) { 2766 !frame->parent() && (is_content_initiated || is_redirect)) {
2723 WebString origin_str = frame->document().securityOrigin().toString(); 2767 WebString origin_str = frame->document().securityOrigin().toString();
2724 GURL frame_url(origin_str.utf8().data()); 2768 GURL frame_url(origin_str.utf8().data());
2725 // TODO(cevans): revisit whether this site check is still necessary once 2769 // TODO(cevans): revisit whether this site check is still necessary once
2726 // crbug.com/101395 is fixed. 2770 // crbug.com/101395 is fixed.
2727 if (!net::RegistryControlledDomainService::SameDomainOrHost(frame_url, 2771 if (!net::RegistryControlledDomainService::SameDomainOrHost(frame_url,
2728 url) || 2772 url) ||
2729 frame_url.scheme() != url.scheme()) { 2773 frame_url.scheme() != url.scheme()) {
2730 OpenURL(frame, url, referrer, default_policy); 2774 WebString method = request.httpMethod();
2775 if(method != WebString("POST")) {
2776 OpenURL(frame, url, referrer, default_policy);
2777 } else {
2778 scoped_refptr<ResourceRequestBody> request_body =
2779 new ResourceRequestBody();
2780 WebHTTPBody body = request.httpBody();
2781 WebKit::WebHTTPBody::Element element;
2782 for (int i=0; body.elementAt(i, element); i++) {
2783 switch (element.type) {
2784 case WebHTTPBody::Element::TypeData:
2785 if (!element.data.isEmpty())
2786 request_body->AppendBytes(
2787 element.data.data(), static_cast<int>(element.data.size()));
2788 break;
2789 case WebHTTPBody::Element::TypeFile: {
2790 if (element.fileLength == -1) {
2791 request_body->AppendFileRange(
2792 FilePath(element.filePath.utf8()),
2793 0, kuint64max, base::Time());
2794 } else {
2795 request_body->AppendFileRange(
2796 FilePath(element.filePath.utf8()),
2797 static_cast<uint64>(element.fileStart),
2798 static_cast<uint64>(element.fileLength),
2799 base::Time::FromDoubleT(element.modificationTime));
2800 }
2801 break;
2802 }
2803 case WebHTTPBody::Element::TypeURL: {
2804 CHECK(false);
2805 break;
2806 }
2807 case WebHTTPBody::Element::TypeBlob:
2808 CHECK(false);
2809 break;
2810 default:
2811 NOTREACHED();
2812 }
2813 }
2814
2815 // Extract Header Info.
2816 WebString ContentType =
2817 request.httpHeaderField(WebString::fromUTF8("Content-Type"));
2818 std::string ContentTypeStr (ContentType.utf8().data(),
2819 ContentType.utf8().length());
2820
2821 ViewMsg_PostRequest_Params params;
2822 params.extra_header = ContentTypeStr;
2823 params.request_body = request_body;
2824 OpenPostURL(frame, url, referrer, default_policy, params);
2825 }
2731 return WebKit::WebNavigationPolicyIgnore; 2826 return WebKit::WebNavigationPolicyIgnore;
2732 } 2827 }
2733 } 2828 }
2734 2829
2735 // If the browser is interested, then give it a chance to look at the request. 2830 // If the browser is interested, then give it a chance to look at the request.
2736 if (is_content_initiated) { 2831 if (is_content_initiated) {
2737 bool browser_handles_request = 2832 bool browser_handles_request =
2738 renderer_preferences_.browser_handles_non_local_top_level_requests && 2833 renderer_preferences_.browser_handles_non_local_top_level_requests &&
2739 IsNonLocalTopLevelNavigation(url, frame, type); 2834 IsNonLocalTopLevelNavigation(url, frame, type);
2740 if (!browser_handles_request) { 2835 if (!browser_handles_request) {
(...skipping 3602 matching lines...) Expand 10 before | Expand all | Expand 10 after
6343 } 6438 }
6344 #endif 6439 #endif
6345 6440
6346 void RenderViewImpl::OnReleaseDisambiguationPopupDIB( 6441 void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
6347 TransportDIB::Handle dib_handle) { 6442 TransportDIB::Handle dib_handle) {
6348 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); 6443 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
6349 RenderProcess::current()->ReleaseTransportDIB(dib); 6444 RenderProcess::current()->ReleaseTransportDIB(dib);
6350 } 6445 }
6351 6446
6352 } // namespace content 6447 } // namespace content
OLDNEW
« content/public/common/frame_navigate_params.h ('K') | « content/renderer/render_view_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698