0

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}
This commit is contained in:
jochen
2014-11-19 01:51:04 -08:00
committed by Commit bot
parent 48bbd92e73
commit f71428e275
16 changed files with 42 additions and 42 deletions

@ -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,

@ -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_;

@ -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,

@ -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,

@ -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,

@ -61,6 +61,7 @@ IPC_STRUCT_BEGIN(PluginMsg_FetchURL_Params)
IPC_STRUCT_MEMBER(std::string, method)
IPC_STRUCT_MEMBER(std::vector<char>, 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)

@ -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),

@ -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

@ -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;

@ -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;

@ -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()) {

@ -438,7 +438,7 @@ void WebPluginDelegateStub::OnFetchURL(
params.method,
data,
static_cast<unsigned int>(params.post_data.size()),
params.referrer,
Referrer(params.referrer, params.referrer_policy),
params.notify_redirect,
params.is_plugin_src_load,
channel_->renderer_id(),

@ -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(&params.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;

@ -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,

@ -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());

@ -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<ClientInfo> clients_;