OLD | NEW |
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 "android_webview/browser/aw_cookie_access_policy.h" | 5 #include "android_webview/browser/aw_cookie_access_policy.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "android_webview/browser/aw_contents_io_thread_client.h" | 9 #include "android_webview/browser/aw_contents_io_thread_client.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/resource_request_info.h" | 12 #include "content/public/browser/resource_request_info.h" |
| 13 #include "content/public/browser/websocket_handshake_request_info.h" |
13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
14 | 15 |
15 using base::AutoLock; | 16 using base::AutoLock; |
16 using content::BrowserThread; | 17 using content::BrowserThread; |
17 using content::ResourceRequestInfo; | 18 using content::ResourceRequestInfo; |
| 19 using content::WebSocketHandshakeRequestInfo; |
18 using net::StaticCookiePolicy; | 20 using net::StaticCookiePolicy; |
19 | 21 |
20 namespace android_webview { | 22 namespace android_webview { |
21 | 23 |
22 namespace { | 24 namespace { |
23 base::LazyInstance<AwCookieAccessPolicy>::Leaky g_lazy_instance; | 25 base::LazyInstance<AwCookieAccessPolicy>::Leaky g_lazy_instance; |
24 } // namespace | 26 } // namespace |
25 | 27 |
26 AwCookieAccessPolicy::~AwCookieAccessPolicy() { | 28 AwCookieAccessPolicy::~AwCookieAccessPolicy() { |
27 } | 29 } |
(...skipping 22 matching lines...) Expand all Loading... |
50 std::unique_ptr<AwContentsIoThreadClient> io_thread_client = | 52 std::unique_ptr<AwContentsIoThreadClient> io_thread_client = |
51 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id); | 53 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id); |
52 if (!io_thread_client) { | 54 if (!io_thread_client) { |
53 return false; | 55 return false; |
54 } | 56 } |
55 return io_thread_client->ShouldAcceptThirdPartyCookies(); | 57 return io_thread_client->ShouldAcceptThirdPartyCookies(); |
56 } | 58 } |
57 | 59 |
58 bool AwCookieAccessPolicy::GetShouldAcceptThirdPartyCookies( | 60 bool AwCookieAccessPolicy::GetShouldAcceptThirdPartyCookies( |
59 const net::URLRequest& request) { | 61 const net::URLRequest& request) { |
| 62 int child_id = 0; |
| 63 int frame_id = 0; |
60 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); | 64 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); |
61 if (!info) { | 65 if (info) { |
62 return false; | 66 child_id = info->GetChildID(); |
| 67 frame_id = info->GetRenderFrameID(); |
| 68 } else { |
| 69 const WebSocketHandshakeRequestInfo* websocket_info = |
| 70 WebSocketHandshakeRequestInfo::ForRequest(&request); |
| 71 if (!websocket_info) |
| 72 return false; |
| 73 child_id = websocket_info->GetChildId(); |
| 74 frame_id = websocket_info->GetRenderFrameId(); |
63 } | 75 } |
64 return GetShouldAcceptThirdPartyCookies(info->GetChildID(), | 76 return GetShouldAcceptThirdPartyCookies(child_id, frame_id); |
65 info->GetRenderFrameID()); | |
66 } | 77 } |
67 | 78 |
68 bool AwCookieAccessPolicy::OnCanGetCookies(const net::URLRequest& request, | 79 bool AwCookieAccessPolicy::OnCanGetCookies(const net::URLRequest& request, |
69 const net::CookieList& cookie_list) { | 80 const net::CookieList& cookie_list) { |
70 bool global = GetShouldAcceptCookies(); | 81 bool global = GetShouldAcceptCookies(); |
71 bool thirdParty = GetShouldAcceptThirdPartyCookies(request); | 82 bool thirdParty = GetShouldAcceptThirdPartyCookies(request); |
72 return AwStaticCookiePolicy(global, thirdParty) | 83 return AwStaticCookiePolicy(global, thirdParty) |
73 .AllowGet(request.url(), request.first_party_for_cookies()); | 84 .AllowGet(request.url(), request.first_party_for_cookies()); |
74 } | 85 } |
75 | 86 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 net::OK; | 147 net::OK; |
137 } | 148 } |
138 | 149 |
139 bool AwStaticCookiePolicy::AllowGet(const GURL& url, | 150 bool AwStaticCookiePolicy::AllowGet(const GURL& url, |
140 const GURL& first_party) const { | 151 const GURL& first_party) const { |
141 return StaticCookiePolicy(GetPolicy(url)).CanGetCookies(url, first_party) == | 152 return StaticCookiePolicy(GetPolicy(url)).CanGetCookies(url, first_party) == |
142 net::OK; | 153 net::OK; |
143 } | 154 } |
144 | 155 |
145 } // namespace android_webview | 156 } // namespace android_webview |
OLD | NEW |