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

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 11193051: To fix the cross-site post submission bug. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix FileRead Permission Created 8 years, 2 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 (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/browser/web_contents/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include "content/public/common/frame_navigate_params.h"
8
7 #include <utility> 9 #include <utility>
8 10
9 #include "base/command_line.h" 11 #include "base/command_line.h"
10 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
11 #include "base/metrics/stats_counters.h" 13 #include "base/metrics/stats_counters.h"
12 #include "base/string16.h" 14 #include "base/string16.h"
13 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
14 #include "base/string_util.h" 16 #include "base/string_util.h"
15 #include "base/sys_info.h" 17 #include "base/sys_info.h"
16 #include "base/time.h" 18 #include "base/time.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 using content::SessionStorageNamespace; 166 using content::SessionStorageNamespace;
165 using content::SiteInstance; 167 using content::SiteInstance;
166 using content::UserMetricsAction; 168 using content::UserMetricsAction;
167 using content::WebContents; 169 using content::WebContents;
168 using content::WebContentsDelegate; 170 using content::WebContentsDelegate;
169 using content::WebContentsObserver; 171 using content::WebContentsObserver;
170 using content::WebUI; 172 using content::WebUI;
171 using content::WebUIController; 173 using content::WebUIController;
172 using content::WebUIControllerFactory; 174 using content::WebUIControllerFactory;
173 using webkit_glue::WebPreferences; 175 using webkit_glue::WebPreferences;
176 using content::WebHTTPPOSTBodyParams;
174 177
175 namespace { 178 namespace {
176 179
177 // Amount of time we wait between when a key event is received and the renderer 180 // Amount of time we wait between when a key event is received and the renderer
178 // is queried for its state and pushed to the NavigationEntry. 181 // is queried for its state and pushed to the NavigationEntry.
179 const int kQueryStateDelay = 5000; 182 const int kQueryStateDelay = 5000;
180 183
181 const int kSyncWaitDelay = 40; 184 const int kSyncWaitDelay = 40;
182 185
183 const char kDotGoogleDotCom[] = ".google.com"; 186 const char kDotGoogleDotCom[] = ".google.com";
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 #endif 358 #endif
356 is_showing_before_unload_dialog_(false), 359 is_showing_before_unload_dialog_(false),
357 opener_web_ui_type_(WebUI::kNoWebUI), 360 opener_web_ui_type_(WebUI::kNoWebUI),
358 closed_by_user_gesture_(false), 361 closed_by_user_gesture_(false),
359 minimum_zoom_percent_( 362 minimum_zoom_percent_(
360 static_cast<int>(content::kMinimumZoomFactor * 100)), 363 static_cast<int>(content::kMinimumZoomFactor * 100)),
361 maximum_zoom_percent_( 364 maximum_zoom_percent_(
362 static_cast<int>(content::kMaximumZoomFactor * 100)), 365 static_cast<int>(content::kMaximumZoomFactor * 100)),
363 temporary_zoom_settings_(false), 366 temporary_zoom_settings_(false),
364 content_restrictions_(0), 367 content_restrictions_(0),
365 color_chooser_(NULL) { 368 color_chooser_(NULL) {
366 } 369 }
367 370
368 WebContentsImpl::~WebContentsImpl() { 371 WebContentsImpl::~WebContentsImpl() {
369 is_being_destroyed_ = true; 372 is_being_destroyed_ = true;
370 373
371 for (std::set<RenderWidgetHostImpl*>::iterator iter = 374 for (std::set<RenderWidgetHostImpl*>::iterator iter =
372 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) { 375 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
373 (*iter)->DetachDelegate(); 376 (*iter)->DetachDelegate();
374 } 377 }
375 created_widgets_.clear(); 378 created_widgets_.clear();
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 std::string embedder_channel_name; 1638 std::string embedder_channel_name;
1636 int embedder_container_id; 1639 int embedder_container_id;
1637 GetBrowserPluginEmbedderInfo(dest_render_view_host, 1640 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1638 &embedder_channel_name, 1641 &embedder_channel_name,
1639 &embedder_container_id); 1642 &embedder_container_id);
1640 ViewMsg_Navigate_Params navigate_params; 1643 ViewMsg_Navigate_Params navigate_params;
1641 MakeNavigateParams(entry, controller_, delegate_, reload_type, 1644 MakeNavigateParams(entry, controller_, delegate_, reload_type,
1642 embedder_channel_name, 1645 embedder_channel_name,
1643 embedder_container_id, 1646 embedder_container_id,
1644 &navigate_params); 1647 &navigate_params);
1648
1649 navigate_params.post_data = entry.post_data;
michaeln 2012/10/23 23:22:18 another copy
1650
1645 dest_render_view_host->Navigate(navigate_params); 1651 dest_render_view_host->Navigate(navigate_params);
1646 1652
1647 if (entry.GetPageID() == -1) { 1653 if (entry.GetPageID() == -1) {
1648 // HACK!! This code suppresses javascript: URLs from being added to 1654 // HACK!! This code suppresses javascript: URLs from being added to
1649 // session history, which is what we want to do for javascript: URLs that 1655 // session history, which is what we want to do for javascript: URLs that
1650 // do not generate content. What we really need is a message from the 1656 // do not generate content. What we really need is a message from the
1651 // renderer telling us that a new page was not created. The same message 1657 // renderer telling us that a new page was not created. The same message
1652 // could be used for mailto: URLs and the like. 1658 // could be used for mailto: URLs and the like.
1653 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme)) 1659 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
1654 return false; 1660 return false;
(...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2944 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) { 2950 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2945 return; 2951 return;
2946 } 2952 }
2947 2953
2948 // Delegate to RequestTransferURL because this is just the generic 2954 // Delegate to RequestTransferURL because this is just the generic
2949 // case where |old_request_id| is empty. 2955 // case where |old_request_id| is empty.
2950 RequestTransferURL(url, referrer, disposition, source_frame_id, 2956 RequestTransferURL(url, referrer, disposition, source_frame_id,
2951 GlobalRequestID()); 2957 GlobalRequestID());
2952 } 2958 }
2953 2959
2960 void WebContentsImpl::RequestOpenPostURL(RenderViewHost* rvh,
2961 const GURL& url,
2962 const content::Referrer& referrer,
2963 WindowOpenDisposition disposition,
2964 int64 source_frame_id,
2965 bool is_post,
2966 std::vector<content::WebHTTPPOSTBodyParams> data) {
2967 // If this came from a swapped out RenderViewHost, we only allow the request
2968 // if we are still in the same BrowsingInstance.
2969 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2970 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2971 return;
2972 }
2973
2974 // Delegate to RequestTransferURL because this is just the generic
2975 // case where |old_request_id| is empty.
2976 RequestTransferPostURL(url, referrer, disposition, source_frame_id,
2977 GlobalRequestID(), is_post, data);
2978 }
2979
2954 void WebContentsImpl::RequestTransferURL( 2980 void WebContentsImpl::RequestTransferURL(
2955 const GURL& url, 2981 const GURL& url,
2956 const content::Referrer& referrer, 2982 const content::Referrer& referrer,
2957 WindowOpenDisposition disposition, 2983 WindowOpenDisposition disposition,
2958 int64 source_frame_id, 2984 int64 source_frame_id,
2959 const GlobalRequestID& old_request_id) { 2985 const GlobalRequestID& old_request_id) {
2960 WebContents* new_contents = NULL; 2986 WebContents* new_contents = NULL;
2961 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK; 2987 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
2962 if (render_manager_.web_ui()) { 2988 if (render_manager_.web_ui()) {
2963 // When we're a Web UI, it will provide a page transition type for us (this 2989 // When we're a Web UI, it will provide a page transition type for us (this
(...skipping 21 matching lines...) Expand all
2985 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 3011 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2986 DidOpenRequestedURL(new_contents, 3012 DidOpenRequestedURL(new_contents,
2987 url, 3013 url,
2988 referrer, 3014 referrer,
2989 disposition, 3015 disposition,
2990 transition_type, 3016 transition_type,
2991 source_frame_id)); 3017 source_frame_id));
2992 } 3018 }
2993 } 3019 }
2994 3020
3021 void WebContentsImpl::RequestTransferPostURL(
3022 const GURL& url,
3023 const content::Referrer& referrer,
3024 WindowOpenDisposition disposition,
3025 int64 source_frame_id,
3026 const GlobalRequestID& old_request_id,
3027 bool is_post,
3028 std::vector<content::WebHTTPPOSTBodyParams> post_data) {
3029 WebContents* new_contents = NULL;
3030 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
3031 if (render_manager_.web_ui()) {
3032 // When we're a Web UI, it will provide a page transition type for us (this
3033 // is so the new tab page can specify AUTO_BOOKMARK for automatically
3034 // generated suggestions).
3035 //
3036 // Note also that we hide the referrer for Web UI pages. We don't really
3037 // want web sites to see a referrer of "chrome://blah" (and some
3038 // chrome: URLs might have search terms or other stuff we don't want to
3039 // send to the site), so we send no referrer.
3040 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
3041 render_manager_.web_ui()->GetLinkTransitionType(),
3042 false /* is_renderer_initiated */);
3043 params.transferred_global_request_id = old_request_id;
3044 new_contents = OpenURL(params);
3045 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
3046 } else {
3047 OpenURLParams params(url, referrer, source_frame_id, disposition,
3048 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
3049 if (is_post) {
3050 // Todo: Don't know whether this will conflict with other unexpect situati on or not.
3051 params.transition = content::PAGE_TRANSITION_FORM_SUBMIT;
3052 params.post_data = post_data/*.front()*/;
3053 }
3054 params.transferred_global_request_id = old_request_id;
3055 new_contents = OpenURL(params);
3056 }
3057 if (new_contents) {
3058 // Notify observers.
3059 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3060 DidOpenRequestedURL(new_contents,
3061 url,
3062 referrer,
3063 disposition,
3064 transition_type,
3065 source_frame_id));
3066 }
3067 }
3068
2995 void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { 3069 void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2996 // Tell the active RenderViewHost to run unload handlers and close, as long 3070 // Tell the active RenderViewHost to run unload handlers and close, as long
2997 // as the request came from a RenderViewHost in the same BrowsingInstance. 3071 // as the request came from a RenderViewHost in the same BrowsingInstance.
2998 // In most cases, we receive this from a swapped out RenderViewHost. 3072 // In most cases, we receive this from a swapped out RenderViewHost.
2999 // It is possible to receive it from one that has just been swapped in, 3073 // It is possible to receive it from one that has just been swapped in,
3000 // in which case we might as well deliver the message anyway. 3074 // in which case we might as well deliver the message anyway.
3001 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) 3075 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3002 GetRenderViewHost()->ClosePage(); 3076 GetRenderViewHost()->ClosePage();
3003 } 3077 }
3004 3078
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
3428 } 3502 }
3429 } 3503 }
3430 3504
3431 content::BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() { 3505 content::BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() {
3432 return browser_plugin_guest_.get(); 3506 return browser_plugin_guest_.get();
3433 } 3507 }
3434 3508
3435 content::BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() { 3509 content::BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() {
3436 return browser_plugin_embedder_.get(); 3510 return browser_plugin_embedder_.get();
3437 } 3511 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698