From f71428e2754483bed8b8959cab09a359ce18d8e4 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 19 Nov 2014 01:51:04 -0800 Subject: [PATCH] Use content::Referrer to pass around referrers in the plugin code BUG=434628 R=bauerb@chromium.org,mkwst@chromium.org Review URL: https://codereview.chromium.org/736743003 Cr-Commit-Position: refs/heads/master@{#304791} --- content/child/npapi/plugin_url_fetcher.cc | 2 +- content/child/npapi/plugin_url_fetcher.h | 7 ++++--- content/child/npapi/webplugin_delegate.h | 3 ++- content/child/npapi/webplugin_delegate_impl.cc | 2 +- content/child/npapi/webplugin_delegate_impl.h | 2 +- content/child/plugin_messages.h | 1 + content/child/request_info.cc | 3 +-- content/child/request_info.h | 9 +++------ content/child/resource_dispatcher.cc | 12 ++++++------ content/child/resource_dispatcher_unittest.cc | 2 +- content/child/web_url_loader_impl.cc | 5 ++--- content/plugin/webplugin_delegate_stub.cc | 2 +- content/renderer/npapi/webplugin_delegate_proxy.cc | 5 +++-- content/renderer/npapi/webplugin_delegate_proxy.h | 2 +- content/renderer/npapi/webplugin_impl.cc | 15 ++++++++------- content/renderer/npapi/webplugin_impl.h | 12 ++++++------ 16 files changed, 42 insertions(+), 42 deletions(-) diff --git a/content/child/npapi/plugin_url_fetcher.cc b/content/child/npapi/plugin_url_fetcher.cc index ff3e79884dfc..c7db56ce9ca8 100644 --- a/content/child/npapi/plugin_url_fetcher.cc +++ b/content/child/npapi/plugin_url_fetcher.cc @@ -83,7 +83,7 @@ PluginURLFetcher::PluginURLFetcher(PluginStreamUrl* plugin_stream, const std::string& method, const char* buf, unsigned int len, - const GURL& referrer, + const Referrer& referrer, const std::string& range, bool notify_redirects, bool is_plugin_src_load, diff --git a/content/child/npapi/plugin_url_fetcher.h b/content/child/npapi/plugin_url_fetcher.h index 57eb5a5beba4..ace77ff02656 100644 --- a/content/child/npapi/plugin_url_fetcher.h +++ b/content/child/npapi/plugin_url_fetcher.h @@ -9,6 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "content/public/child/request_peer.h" +#include "content/public/common/referrer.h" #include "url/gurl.h" namespace content { @@ -25,7 +26,7 @@ class PluginURLFetcher : public RequestPeer { const std::string& method, const char* buf, unsigned int len, - const GURL& referrer, + const Referrer& referrer, const std::string& range, bool notify_redirects, bool is_plugin_src_load, @@ -43,7 +44,7 @@ class PluginURLFetcher : public RequestPeer { void URLRedirectResponse(bool allow); GURL first_party_for_cookies() { return first_party_for_cookies_; } - GURL referrer() { return referrer_; } + Referrer referrer() { return referrer_; } int origin_pid() { return origin_pid_; } int render_frame_id() { return render_frame_id_; } int render_view_id() { return render_view_id_; } @@ -72,7 +73,7 @@ class PluginURLFetcher : public RequestPeer { PluginStreamUrl* plugin_stream_; GURL url_; GURL first_party_for_cookies_; - GURL referrer_; + Referrer referrer_; bool notify_redirects_; bool is_plugin_src_load_; int origin_pid_; diff --git a/content/child/npapi/webplugin_delegate.h b/content/child/npapi/webplugin_delegate.h index eaef885a38cd..8f13c8d80d2a 100644 --- a/content/child/npapi/webplugin_delegate.h +++ b/content/child/npapi/webplugin_delegate.h @@ -28,6 +28,7 @@ class Rect; namespace content { +struct Referrer; class WebPluginResourceClient; // This is the interface that a plugin implementation needs to provide. @@ -138,7 +139,7 @@ class WebPluginDelegate { const std::string& method, const char* buf, unsigned int len, - const GURL& referrer, + const Referrer& referrer, bool notify_redirects, bool is_plugin_src_load, int origin_pid, diff --git a/content/child/npapi/webplugin_delegate_impl.cc b/content/child/npapi/webplugin_delegate_impl.cc index e53cbc382c1a..4041db427108 100644 --- a/content/child/npapi/webplugin_delegate_impl.cc +++ b/content/child/npapi/webplugin_delegate_impl.cc @@ -311,7 +311,7 @@ void WebPluginDelegateImpl::FetchURL(unsigned long resource_id, const std::string& method, const char* buf, unsigned int len, - const GURL& referrer, + const Referrer& referrer, bool notify_redirects, bool is_plugin_src_load, int origin_pid, diff --git a/content/child/npapi/webplugin_delegate_impl.h b/content/child/npapi/webplugin_delegate_impl.h index e37a651a1e42..efafa81bbfd2 100644 --- a/content/child/npapi/webplugin_delegate_impl.h +++ b/content/child/npapi/webplugin_delegate_impl.h @@ -121,7 +121,7 @@ class WebPluginDelegateImpl : public WebPluginDelegate { const std::string& method, const char* buf, unsigned int len, - const GURL& referrer, + const Referrer& referrer, bool notify_redirects, bool is_plugin_src_load, int origin_pid, diff --git a/content/child/plugin_messages.h b/content/child/plugin_messages.h index 2e17c98a4a89..d2ea4d9493db 100644 --- a/content/child/plugin_messages.h +++ b/content/child/plugin_messages.h @@ -61,6 +61,7 @@ IPC_STRUCT_BEGIN(PluginMsg_FetchURL_Params) IPC_STRUCT_MEMBER(std::string, method) IPC_STRUCT_MEMBER(std::vector, post_data) IPC_STRUCT_MEMBER(GURL, referrer) + IPC_STRUCT_MEMBER(blink::WebReferrerPolicy, referrer_policy) IPC_STRUCT_MEMBER(bool, notify_redirect) IPC_STRUCT_MEMBER(bool, is_plugin_src_load) IPC_STRUCT_MEMBER(int, render_frame_id) diff --git a/content/child/request_info.cc b/content/child/request_info.cc index e52f2aa688ff..7752081e362a 100644 --- a/content/child/request_info.cc +++ b/content/child/request_info.cc @@ -7,8 +7,7 @@ namespace content { RequestInfo::RequestInfo() - : referrer_policy(blink::WebReferrerPolicyDefault), - load_flags(0), + : load_flags(0), requestor_pid(0), request_type(RESOURCE_TYPE_MAIN_FRAME), fetch_request_context_type(REQUEST_CONTEXT_TYPE_UNSPECIFIED), diff --git a/content/child/request_info.h b/content/child/request_info.h index 6861741905b4..e66a26be0177 100644 --- a/content/child/request_info.h +++ b/content/child/request_info.h @@ -11,6 +11,7 @@ #include "content/common/content_export.h" #include "content/common/service_worker/service_worker_types.h" +#include "content/public/common/referrer.h" #include "content/public/common/request_context_frame_type.h" #include "content/public/common/request_context_type.h" #include "content/public/common/resource_type.h" @@ -36,12 +37,8 @@ struct CONTENT_EXPORT RequestInfo { // third-party cookie blocking policy. GURL first_party_for_cookies; - // Optional parameter, a URL with similar constraints in how it must be - // encoded as the url member. - GURL referrer; - - // The referrer policy that applies to the referrer. - blink::WebReferrerPolicy referrer_policy; + // Optional parameter, the referrer to use for the request for the url member. + Referrer referrer; // For HTTP(S) requests, the headers parameter can be a \r\n-delimited and // \r\n-terminated list of MIME headers. They should be ASCII-encoded using diff --git a/content/child/resource_dispatcher.cc b/content/child/resource_dispatcher.cc index ea91f9571120..0e8bd3647a07 100644 --- a/content/child/resource_dispatcher.cc +++ b/content/child/resource_dispatcher.cc @@ -116,8 +116,8 @@ IPCResourceLoaderBridge::IPCResourceLoaderBridge( request_.method = request_info.method; request_.url = request_info.url; request_.first_party_for_cookies = request_info.first_party_for_cookies; - request_.referrer = request_info.referrer; - request_.referrer_policy = request_info.referrer_policy; + request_.referrer = request_info.referrer.url; + request_.referrer_policy = request_info.referrer.policy; request_.headers = request_info.headers; request_.load_flags = request_info.load_flags; request_.origin_pid = request_info.requestor_pid; @@ -135,17 +135,17 @@ IPCResourceLoaderBridge::IPCResourceLoaderBridge( request_.enable_load_timing = request_info.enable_load_timing; request_.enable_upload_progress = request_info.enable_upload_progress; - if ((request_info.referrer_policy == blink::WebReferrerPolicyDefault || - request_info.referrer_policy == + if ((request_info.referrer.policy == blink::WebReferrerPolicyDefault || + request_info.referrer.policy == blink::WebReferrerPolicyNoReferrerWhenDowngrade) && - request_info.referrer.SchemeIsSecure() && + request_info.referrer.url.SchemeIsSecure() && !request_info.url.SchemeIsSecure()) { // Debug code for crbug.com/422871 base::debug::DumpWithoutCrashing(); DLOG(FATAL) << "Trying to send secure referrer for insecure request " << "without an appropriate referrer policy.\n" << "URL = " << request_info.url << "\n" - << "Referrer = " << request_info.referrer; + << "Referrer = " << request_info.referrer.url; } const RequestExtraData kEmptyData; diff --git a/content/child/resource_dispatcher_unittest.cc b/content/child/resource_dispatcher_unittest.cc index 434433eced7e..f0201c8a3e61 100644 --- a/content/child/resource_dispatcher_unittest.cc +++ b/content/child/resource_dispatcher_unittest.cc @@ -322,7 +322,7 @@ class ResourceDispatcherTest : public testing::Test, public IPC::Sender { request_info.method = "GET"; request_info.url = GURL(kTestPageUrl); request_info.first_party_for_cookies = GURL(kTestPageUrl); - request_info.referrer = GURL(); + request_info.referrer = Referrer(); request_info.headers = std::string(); request_info.load_flags = 0; request_info.requestor_pid = 0; diff --git a/content/child/web_url_loader_impl.cc b/content/child/web_url_loader_impl.cc index bd6fe10b6bc2..e3b7727c06bf 100644 --- a/content/child/web_url_loader_impl.cc +++ b/content/child/web_url_loader_impl.cc @@ -460,7 +460,8 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, request_info.method = method; request_info.url = url; request_info.first_party_for_cookies = request.firstPartyForCookies(); - request_info.referrer = referrer_url; + referrer_policy_ = request.referrerPolicy(); + request_info.referrer = Referrer(referrer_url, referrer_policy_); request_info.headers = GetWebURLRequestHeaders(request); request_info.load_flags = GetLoadFlagsForWebURLRequest(request); request_info.enable_load_timing = true; @@ -482,8 +483,6 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, request_info.fetch_request_context_type = GetRequestContextType(request); request_info.fetch_frame_type = GetRequestContextFrameType(request); request_info.extra_data = request.extraData(); - referrer_policy_ = request.referrerPolicy(); - request_info.referrer_policy = request.referrerPolicy(); bridge_.reset(resource_dispatcher_->CreateBridge(request_info)); if (!request.httpBody().isNull()) { diff --git a/content/plugin/webplugin_delegate_stub.cc b/content/plugin/webplugin_delegate_stub.cc index 81267b5f64fa..21d81126b122 100644 --- a/content/plugin/webplugin_delegate_stub.cc +++ b/content/plugin/webplugin_delegate_stub.cc @@ -438,7 +438,7 @@ void WebPluginDelegateStub::OnFetchURL( params.method, data, static_cast(params.post_data.size()), - params.referrer, + Referrer(params.referrer, params.referrer_policy), params.notify_redirect, params.is_plugin_src_load, channel_->renderer_id(), diff --git a/content/renderer/npapi/webplugin_delegate_proxy.cc b/content/renderer/npapi/webplugin_delegate_proxy.cc index 3576b19fa0d2..b1f5d747d65b 100644 --- a/content/renderer/npapi/webplugin_delegate_proxy.cc +++ b/content/renderer/npapi/webplugin_delegate_proxy.cc @@ -1121,7 +1121,7 @@ void WebPluginDelegateProxy::FetchURL(unsigned long resource_id, const std::string& method, const char* buf, unsigned int len, - const GURL& referrer, + const Referrer& referrer, bool notify_redirects, bool is_plugin_src_load, int origin_pid, @@ -1137,7 +1137,8 @@ void WebPluginDelegateProxy::FetchURL(unsigned long resource_id, params.post_data.resize(len); memcpy(¶ms.post_data.front(), buf, len); } - params.referrer = referrer; + params.referrer = referrer.url; + params.referrer_policy = referrer.policy; params.notify_redirect = notify_redirects; params.is_plugin_src_load = is_plugin_src_load; params.render_frame_id = render_frame_id; diff --git a/content/renderer/npapi/webplugin_delegate_proxy.h b/content/renderer/npapi/webplugin_delegate_proxy.h index 5b8c62c6aa14..2a308de79a30 100644 --- a/content/renderer/npapi/webplugin_delegate_proxy.h +++ b/content/renderer/npapi/webplugin_delegate_proxy.h @@ -137,7 +137,7 @@ class WebPluginDelegateProxy const std::string& method, const char* buf, unsigned int len, - const GURL& referrer, + const Referrer& referrer, bool notify_redirects, bool is_plugin_src_load, int origin_pid, diff --git a/content/renderer/npapi/webplugin_impl.cc b/content/renderer/npapi/webplugin_impl.cc index 4370dec79222..2c75d42b189b 100644 --- a/content/renderer/npapi/webplugin_impl.cc +++ b/content/renderer/npapi/webplugin_impl.cc @@ -650,7 +650,7 @@ bool WebPluginImpl::SetPostData(WebURLRequest* request, return rv; } -bool WebPluginImpl::IsValidUrl(const GURL& url, Referrer referrer_flag) { +bool WebPluginImpl::IsValidUrl(const GURL& url, ReferrerValue referrer_flag) { if (referrer_flag == PLUGIN_SRC && mime_type_ == kFlashPluginSwfMimeType && url.GetOrigin() != plugin_url_.GetOrigin()) { @@ -682,7 +682,7 @@ WebPluginImpl::RoutingStatus WebPluginImpl::RouteToFrame( const char* buf, unsigned int len, int notify_id, - Referrer referrer_flag) { + ReferrerValue referrer_flag) { // If there is no target, there is nothing to do if (!target) return NOT_ROUTED; @@ -1161,7 +1161,7 @@ void WebPluginImpl::HandleURLRequestInternal(const char* url, unsigned int len, int notify_id, bool popups_allowed, - Referrer referrer_flag, + ReferrerValue referrer_flag, bool notify_redirects, bool is_plugin_src_load) { // For this request, we either route the output to a frame @@ -1233,8 +1233,9 @@ void WebPluginImpl::HandleURLRequestInternal(const char* url, // WebFrameImpl::setReferrerForRequest does. WebURLRequest request(complete_url); SetReferrer(&request, referrer_flag); - GURL referrer( - request.httpHeaderField(WebString::fromUTF8("Referer")).utf8()); + Referrer referrer( + GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), + request.referrerPolicy()); GURL first_party_for_cookies = webframe_->document().firstPartyForCookies(); delegate_->FetchURL(resource_id, notify_id, complete_url, @@ -1269,7 +1270,7 @@ bool WebPluginImpl::InitiateHTTPRequest(unsigned long resource_id, const char* buf, int buf_len, const char* range_info, - Referrer referrer_flag, + ReferrerValue referrer_flag, bool notify_redirects, bool is_plugin_src_load) { if (!client) { @@ -1520,7 +1521,7 @@ void WebPluginImpl::TearDownPluginInstance( } void WebPluginImpl::SetReferrer(blink::WebURLRequest* request, - Referrer referrer_flag) { + ReferrerValue referrer_flag) { switch (referrer_flag) { case DOCUMENT_URL: webframe_->setReferrerForRequest(*request, GURL()); diff --git a/content/renderer/npapi/webplugin_impl.h b/content/renderer/npapi/webplugin_impl.h index 6115d08346f0..4f73da4153b2 100644 --- a/content/renderer/npapi/webplugin_impl.h +++ b/content/renderer/npapi/webplugin_impl.h @@ -155,7 +155,7 @@ class WebPluginImpl : public WebPlugin, // Determines the referrer value sent along with outgoing HTTP requests // issued by plugins. - enum Referrer { + enum ReferrerValue { PLUGIN_SRC, DOCUMENT_URL, NO_REFERRER @@ -172,7 +172,7 @@ class WebPluginImpl : public WebPlugin, const char* buf, unsigned int len, int notify_id, - Referrer referrer_flag); + ReferrerValue referrer_flag); // Returns the next avaiable resource id. Returns 0 if the operation fails. // It may fail if the page has already been closed. @@ -187,7 +187,7 @@ class WebPluginImpl : public WebPlugin, const char* buf, int len, const char* range_info, - Referrer referrer_flag, + ReferrerValue referrer_flag, bool notify_redirects, bool check_mixed_scripting); @@ -242,7 +242,7 @@ class WebPluginImpl : public WebPlugin, unsigned int len, int notify_id, bool popups_allowed, - Referrer referrer_flag, + ReferrerValue referrer_flag, bool notify_redirects, bool check_mixed_scripting); @@ -260,10 +260,10 @@ class WebPluginImpl : public WebPlugin, ClientInfo* GetClientInfoFromLoader(blink::WebURLLoader* loader); // Helper function to set the referrer on the request passed in. - void SetReferrer(blink::WebURLRequest* request, Referrer referrer_flag); + void SetReferrer(blink::WebURLRequest* request, ReferrerValue referrer_flag); // Check for invalid chars like @, ;, \ before the first / (in path). - bool IsValidUrl(const GURL& url, Referrer referrer_flag); + bool IsValidUrl(const GURL& url, ReferrerValue referrer_flag); std::vector clients_; -- 2.11.4.GIT