Commit 8c0b1dca authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

Fix third party cookies not being sent in WebView iframes.

The issue was in:
AwCookieAccessPolicy::GetShouldAcceptThirdPartyCookies()

AwContentsIoThreadClient::FromID(render_process_id, render_frame_id) was
used, but at this point a navigation request is not associated with a
renderer process yet. It caused the cookies not being sent with the
request.

The solution was to use
AwContentsIoThreadClient::FromID(frame_tree_node_id) instead.

Bug: 793648, 794939
Change-Id: I5bda7affab67645cfd64c105b06c8a628047dd79
Reviewed-on: https://chromium-review.googlesource.com/827018
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524098}
parent a3ec9613
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "android_webview/browser/aw_contents_io_thread_client.h" #include "android_webview/browser/aw_contents_io_thread_client.h"
#include "base/logging.h" #include "base/logging.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/resource_request_info.h" #include "content/public/browser/resource_request_info.h"
#include "content/public/browser/websocket_handshake_request_info.h" #include "content/public/browser/websocket_handshake_request_info.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
...@@ -48,9 +49,14 @@ void AwCookieAccessPolicy::SetShouldAcceptCookies(bool allow) { ...@@ -48,9 +49,14 @@ void AwCookieAccessPolicy::SetShouldAcceptCookies(bool allow) {
bool AwCookieAccessPolicy::GetShouldAcceptThirdPartyCookies( bool AwCookieAccessPolicy::GetShouldAcceptThirdPartyCookies(
int render_process_id, int render_process_id,
int render_frame_id) { int render_frame_id,
int frame_tree_node_id) {
std::unique_ptr<AwContentsIoThreadClient> io_thread_client = std::unique_ptr<AwContentsIoThreadClient> io_thread_client =
AwContentsIoThreadClient::FromID(render_process_id, render_frame_id); (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId)
? AwContentsIoThreadClient::FromID(frame_tree_node_id)
: AwContentsIoThreadClient::FromID(render_process_id,
render_frame_id);
if (!io_thread_client) { if (!io_thread_client) {
return false; return false;
} }
...@@ -60,20 +66,23 @@ bool AwCookieAccessPolicy::GetShouldAcceptThirdPartyCookies( ...@@ -60,20 +66,23 @@ bool AwCookieAccessPolicy::GetShouldAcceptThirdPartyCookies(
bool AwCookieAccessPolicy::GetShouldAcceptThirdPartyCookies( bool AwCookieAccessPolicy::GetShouldAcceptThirdPartyCookies(
const net::URLRequest& request) { const net::URLRequest& request) {
int child_id = 0; int child_id = 0;
int frame_id = 0; int render_frame_id = 0;
int frame_tree_node_id = content::RenderFrameHost::kNoFrameTreeNodeId;
const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
if (info) { if (info) {
child_id = info->GetChildID(); child_id = info->GetChildID();
frame_id = info->GetRenderFrameID(); render_frame_id = info->GetRenderFrameID();
frame_tree_node_id = info->GetFrameTreeNodeId();
} else { } else {
const WebSocketHandshakeRequestInfo* websocket_info = const WebSocketHandshakeRequestInfo* websocket_info =
WebSocketHandshakeRequestInfo::ForRequest(&request); WebSocketHandshakeRequestInfo::ForRequest(&request);
if (!websocket_info) if (!websocket_info)
return false; return false;
child_id = websocket_info->GetChildId(); child_id = websocket_info->GetChildId();
frame_id = websocket_info->GetRenderFrameId(); render_frame_id = websocket_info->GetRenderFrameId();
} }
return GetShouldAcceptThirdPartyCookies(child_id, frame_id); return GetShouldAcceptThirdPartyCookies(child_id, render_frame_id,
frame_tree_node_id);
} }
bool AwCookieAccessPolicy::OnCanGetCookies(const net::URLRequest& request, bool AwCookieAccessPolicy::OnCanGetCookies(const net::URLRequest& request,
...@@ -100,8 +109,9 @@ bool AwCookieAccessPolicy::AllowGetCookie(const GURL& url, ...@@ -100,8 +109,9 @@ bool AwCookieAccessPolicy::AllowGetCookie(const GURL& url,
int render_process_id, int render_process_id,
int render_frame_id) { int render_frame_id) {
bool global = GetShouldAcceptCookies(); bool global = GetShouldAcceptCookies();
bool thirdParty = bool thirdParty = GetShouldAcceptThirdPartyCookies(
GetShouldAcceptThirdPartyCookies(render_process_id, render_frame_id); render_process_id, render_frame_id,
content::RenderFrameHost::kNoFrameTreeNodeId);
return AwStaticCookiePolicy(global, thirdParty).AllowGet(url, first_party); return AwStaticCookiePolicy(global, thirdParty).AllowGet(url, first_party);
} }
...@@ -113,8 +123,9 @@ bool AwCookieAccessPolicy::AllowSetCookie(const GURL& url, ...@@ -113,8 +123,9 @@ bool AwCookieAccessPolicy::AllowSetCookie(const GURL& url,
int render_frame_id, int render_frame_id,
const net::CookieOptions& options) { const net::CookieOptions& options) {
bool global = GetShouldAcceptCookies(); bool global = GetShouldAcceptCookies();
bool thirdParty = bool thirdParty = GetShouldAcceptThirdPartyCookies(
GetShouldAcceptThirdPartyCookies(render_process_id, render_frame_id); render_process_id, render_frame_id,
content::RenderFrameHost::kNoFrameTreeNodeId);
return AwStaticCookiePolicy(global, thirdParty).AllowSet(url, first_party); return AwStaticCookiePolicy(global, thirdParty).AllowSet(url, first_party);
} }
......
...@@ -36,8 +36,12 @@ class AwCookieAccessPolicy { ...@@ -36,8 +36,12 @@ class AwCookieAccessPolicy {
void SetShouldAcceptCookies(bool allow); void SetShouldAcceptCookies(bool allow);
// Can we read/write third party cookies? // Can we read/write third party cookies?
// |render_process_id| and |render_frame_id| must be valid.
// Navigation requests are not associated with a renderer process. In this
// case, |frame_tree_node_id| must be valid instead.
bool GetShouldAcceptThirdPartyCookies(int render_process_id, bool GetShouldAcceptThirdPartyCookies(int render_process_id,
int render_frame_id); int render_frame_id,
int frame_tree_node_id);
bool GetShouldAcceptThirdPartyCookies(const net::URLRequest& request); bool GetShouldAcceptThirdPartyCookies(const net::URLRequest& request);
// These are the functions called when operating over cookies from the // These are the functions called when operating over cookies from the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment