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

Side by Side Diff: content/browser/android/media_resource_getter_impl.cc

Issue 12595005: Parsing filesystem url before giving it to media player (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixing nits Created 7 years, 9 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) 2013 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/android/cookie_getter_impl.h" 5 #include "content/browser/android/media_resource_getter_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/browser/child_process_security_policy_impl.h" 8 #include "content/browser/child_process_security_policy_impl.h"
9 #include "content/browser/fileapi/browser_file_system_helper.h"
9 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/content_browser_client.h" 12 #include "content/public/browser/content_browser_client.h"
12 #include "content/public/common/content_client.h" 13 #include "content/public/common/content_client.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 #include "net/cookies/cookie_monster.h" 15 #include "net/cookies/cookie_monster.h"
15 #include "net/cookies/cookie_store.h" 16 #include "net/cookies/cookie_store.h"
16 #include "net/url_request/url_request_context.h" 17 #include "net/url_request/url_request_context.h"
17 #include "net/url_request/url_request_context_getter.h" 18 #include "net/url_request/url_request_context_getter.h"
18 19
19 namespace content { 20 namespace content {
20 21
21 static void ReturnCookieOnUIThread( 22 static void ReturnResultOnUIThread(
22 const media::CookieGetter::GetCookieCB& callback, 23 const base::Callback<void(const std::string&)>& callback,
23 const std::string& cookies) { 24 const std::string& result) {
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
25 BrowserThread::PostTask( 25 BrowserThread::PostTask(
26 BrowserThread::UI, FROM_HERE, base::Bind(callback, cookies)); 26 BrowserThread::UI, FROM_HERE, base::Bind(callback, result));
27 } 27 }
28 28
29 // The task object that retrieves cookie on the IO thread. 29 // The task object that retrieves cookie on the IO thread.
30 // TODO(qinmin): refactor this class to make the code reusable by others as 30 // TODO(qinmin): refactor this class to make the code reusable by others as
31 // there are lots of duplicated functionalities elsewhere. 31 // there are lots of duplicated functionalities elsewhere.
32 class CookieGetterTask 32 class CookieGetterTask
33 : public base::RefCountedThreadSafe<CookieGetterTask> { 33 : public base::RefCountedThreadSafe<CookieGetterTask> {
34 public: 34 public:
35 CookieGetterTask(BrowserContext* browser_context, 35 CookieGetterTask(BrowserContext* browser_context,
36 int renderer_id, int routing_id); 36 int renderer_id, int routing_id);
37 37
38 // Called by CookieGetterImpl to start getting cookies for a URL. 38 // Called by CookieGetterImpl to start getting cookies for a URL.
39 void RequestCookies( 39 void RequestCookies(
40 const GURL& url, const GURL& first_party_for_cookies, 40 const GURL& url, const GURL& first_party_for_cookies,
41 const media::CookieGetter::GetCookieCB& callback); 41 const media::MediaResourceGetter::GetCookieCB& callback);
42 42
43 private: 43 private:
44 friend class base::RefCountedThreadSafe<CookieGetterTask>; 44 friend class base::RefCountedThreadSafe<CookieGetterTask>;
45 virtual ~CookieGetterTask(); 45 virtual ~CookieGetterTask();
46 46
47 void CheckPolicyForCookies( 47 void CheckPolicyForCookies(
48 const GURL& url, const GURL& first_party_for_cookies, 48 const GURL& url, const GURL& first_party_for_cookies,
49 const media::CookieGetter::GetCookieCB& callback, 49 const media::MediaResourceGetter::GetCookieCB& callback,
50 const net::CookieList& cookie_list); 50 const net::CookieList& cookie_list);
51 51
52 // Context getter used to get the CookieStore. 52 // Context getter used to get the CookieStore.
53 net::URLRequestContextGetter* context_getter_; 53 net::URLRequestContextGetter* context_getter_;
54 54
55 // Resource context for checking cookie policies. 55 // Resource context for checking cookie policies.
56 ResourceContext* resource_context_; 56 ResourceContext* resource_context_;
57 57
58 // Render process id, used to check whether the process can access cookies. 58 // Render process id, used to check whether the process can access cookies.
59 int renderer_id_; 59 int renderer_id_;
60 60
61 // Routing id for the render view, used to check tab specific cookie policy. 61 // Routing id for the render view, used to check tab specific cookie policy.
62 int routing_id_; 62 int routing_id_;
63 63
64 DISALLOW_COPY_AND_ASSIGN(CookieGetterTask); 64 DISALLOW_COPY_AND_ASSIGN(CookieGetterTask);
65 }; 65 };
66 66
67 CookieGetterTask::CookieGetterTask( 67 CookieGetterTask::CookieGetterTask(
68 BrowserContext* browser_context, int renderer_id, int routing_id) 68 BrowserContext* browser_context, int renderer_id, int routing_id)
69 : context_getter_(browser_context->GetRequestContext()), 69 : context_getter_(browser_context->GetRequestContext()),
70 resource_context_(browser_context->GetResourceContext()), 70 resource_context_(browser_context->GetResourceContext()),
71 renderer_id_(renderer_id), 71 renderer_id_(renderer_id),
72 routing_id_(routing_id) { 72 routing_id_(routing_id) {
73 } 73 }
74 74
75 CookieGetterTask::~CookieGetterTask() {} 75 CookieGetterTask::~CookieGetterTask() {}
76 76
77 void CookieGetterTask::RequestCookies( 77 void CookieGetterTask::RequestCookies(
78 const GURL& url, const GURL& first_party_for_cookies, 78 const GURL& url, const GURL& first_party_for_cookies,
79 const media::CookieGetter::GetCookieCB& callback) { 79 const media::MediaResourceGetter::GetCookieCB& callback) {
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
81 ChildProcessSecurityPolicyImpl* policy = 81 ChildProcessSecurityPolicyImpl* policy =
82 ChildProcessSecurityPolicyImpl::GetInstance(); 82 ChildProcessSecurityPolicyImpl::GetInstance();
83 if (!policy->CanAccessCookiesForOrigin(renderer_id_, url)) { 83 if (!policy->CanAccessCookiesForOrigin(renderer_id_, url)) {
84 callback.Run(std::string()); 84 callback.Run(std::string());
85 return; 85 return;
86 } 86 }
87 87
88 net::CookieStore* cookie_store = 88 net::CookieStore* cookie_store =
89 context_getter_->GetURLRequestContext()->cookie_store(); 89 context_getter_->GetURLRequestContext()->cookie_store();
90 if (!cookie_store) { 90 if (!cookie_store) {
91 callback.Run(std::string()); 91 callback.Run(std::string());
92 return; 92 return;
93 } 93 }
94 94
95 net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); 95 net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster();
96 if (cookie_monster) { 96 if (cookie_monster) {
97 cookie_monster->GetAllCookiesForURLAsync(url, base::Bind( 97 cookie_monster->GetAllCookiesForURLAsync(url, base::Bind(
98 &CookieGetterTask::CheckPolicyForCookies, this, 98 &CookieGetterTask::CheckPolicyForCookies, this,
99 url, first_party_for_cookies, callback)); 99 url, first_party_for_cookies, callback));
100 } else { 100 } else {
101 callback.Run(std::string()); 101 callback.Run(std::string());
102 } 102 }
103 } 103 }
104 104
105 void CookieGetterTask::CheckPolicyForCookies( 105 void CookieGetterTask::CheckPolicyForCookies(
106 const GURL& url, const GURL& first_party_for_cookies, 106 const GURL& url, const GURL& first_party_for_cookies,
107 const media::CookieGetter::GetCookieCB& callback, 107 const media::MediaResourceGetter::GetCookieCB& callback,
108 const net::CookieList& cookie_list) { 108 const net::CookieList& cookie_list) {
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
110 if (GetContentClient()->browser()->AllowGetCookie( 110 if (GetContentClient()->browser()->AllowGetCookie(
111 url, first_party_for_cookies, cookie_list, 111 url, first_party_for_cookies, cookie_list,
112 resource_context_, renderer_id_, routing_id_)) { 112 resource_context_, renderer_id_, routing_id_)) {
113 net::CookieStore* cookie_store = 113 net::CookieStore* cookie_store =
114 context_getter_->GetURLRequestContext()->cookie_store(); 114 context_getter_->GetURLRequestContext()->cookie_store();
115 cookie_store->GetCookiesWithOptionsAsync( 115 cookie_store->GetCookiesWithOptionsAsync(
116 url, net::CookieOptions(), callback); 116 url, net::CookieOptions(), callback);
117 } else { 117 } else {
118 callback.Run(std::string()); 118 callback.Run(std::string());
119 } 119 }
120 } 120 }
121 121
122 CookieGetterImpl::CookieGetterImpl( 122 // The task object that retrieves platform path on the FILE thread.
123 BrowserContext* browser_context, int renderer_id, int routing_id) 123 class PlatformPathGetterTask
124 : public base::RefCountedThreadSafe<PlatformPathGetterTask> {
125 public:
126 PlatformPathGetterTask(fileapi::FileSystemContext* file_system_context,
127 int renderer_id);
128
129 // Called by MediaResourceGetterImpl to get the platform path from a file
130 // system URL.
131 void RequestPlaformPath(
132 const GURL& url,
133 const media::MediaResourceGetter::GetPlatformPathCB& callback);
134
135 private:
136 friend class base::RefCountedThreadSafe<PlatformPathGetterTask>;
137 virtual ~PlatformPathGetterTask();
138
139 // File system context for getting the platform path.
140 fileapi::FileSystemContext* file_system_context_;
141
142 // Render process id, used to check whether the process can access the URL.
143 int renderer_id_;
144
145 DISALLOW_COPY_AND_ASSIGN(PlatformPathGetterTask);
146 };
147
148 PlatformPathGetterTask::PlatformPathGetterTask(
149 fileapi::FileSystemContext* file_system_context, int renderer_id)
150 : file_system_context_(file_system_context),
151 renderer_id_(renderer_id) {
152 }
153
154 PlatformPathGetterTask::~PlatformPathGetterTask() {}
155
156 void PlatformPathGetterTask::RequestPlaformPath(
157 const GURL& url,
158 const media::MediaResourceGetter::GetPlatformPathCB& callback) {
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
160 base::FilePath platform_path;
161 SyncGetPlatformPath(file_system_context_,
palmer 2013/03/18 19:54:34 At some point, possibly here or inside SyncGetPlat
qinmin 2013/03/18 22:27:59 For filesystem url, the data are actually stored u
162 renderer_id_,
163 url,
164 &platform_path);
165 callback.Run(platform_path.value());
166 }
167
168 MediaResourceGetterImpl::MediaResourceGetterImpl(
169 BrowserContext* browser_context,
170 fileapi::FileSystemContext* file_system_context,
171 int renderer_id, int routing_id)
124 : browser_context_(browser_context), 172 : browser_context_(browser_context),
173 file_system_context_(file_system_context),
125 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)), 174 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)),
126 renderer_id_(renderer_id), 175 renderer_id_(renderer_id),
127 routing_id_(routing_id) { 176 routing_id_(routing_id) {
128 } 177 }
129 178
130 CookieGetterImpl::~CookieGetterImpl() {} 179 MediaResourceGetterImpl::~MediaResourceGetterImpl() {}
131 180
132 void CookieGetterImpl::GetCookies(const std::string& url, 181 void MediaResourceGetterImpl::GetCookies(const GURL& url,
133 const std::string& first_party_for_cookies, 182 const GURL& first_party_for_cookies,
palmer 2013/03/18 19:54:34 I'm new to this area of code; please forgive my ig
qinmin 2013/03/18 22:27:59 added a line in MediaPlayerBridge ctor to set has_
134 const GetCookieCB& callback) { 183 const GetCookieCB& callback) {
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
136 scoped_refptr<CookieGetterTask> task = new CookieGetterTask( 185 scoped_refptr<CookieGetterTask> task = new CookieGetterTask(
137 browser_context_, renderer_id_, routing_id_); 186 browser_context_, renderer_id_, routing_id_);
138 187
139 GetCookieCB cb = base::Bind( 188 GetCookieCB cb = base::Bind(&MediaResourceGetterImpl::GetCookiesCallback,
140 &CookieGetterImpl::GetCookiesCallback, weak_this_.GetWeakPtr(), callback); 189 weak_this_.GetWeakPtr(), callback);
141 BrowserThread::PostTask( 190 BrowserThread::PostTask(
142 BrowserThread::IO, 191 BrowserThread::IO,
143 FROM_HERE, 192 FROM_HERE,
144 base::Bind(&CookieGetterTask::RequestCookies, 193 base::Bind(&CookieGetterTask::RequestCookies,
145 task, GURL(url), GURL(first_party_for_cookies), 194 task, url, first_party_for_cookies,
146 base::Bind(&ReturnCookieOnUIThread, cb))); 195 base::Bind(&ReturnResultOnUIThread, cb)));
147 } 196 }
148 197
149 void CookieGetterImpl::GetCookiesCallback( 198 void MediaResourceGetterImpl::GetCookiesCallback(
150 const GetCookieCB& callback, const std::string& cookies) { 199 const GetCookieCB& callback, const std::string& cookies) {
151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
152 callback.Run(cookies); 201 callback.Run(cookies);
153 } 202 }
154 203
204 void MediaResourceGetterImpl::GetPlatformPathFromFileSystemURL(
205 const GURL& url, const GetPlatformPathCB& callback) {
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
207 scoped_refptr<PlatformPathGetterTask> task = new PlatformPathGetterTask(
208 file_system_context_, renderer_id_);
209
210 GetPlatformPathCB cb = base::Bind(
211 &MediaResourceGetterImpl::GetPlatformPathCallback,
212 weak_this_.GetWeakPtr(), callback);
213 BrowserThread::PostTask(
214 BrowserThread::FILE,
215 FROM_HERE,
216 base::Bind(&PlatformPathGetterTask::RequestPlaformPath,
217 task, url,
218 base::Bind(&ReturnResultOnUIThread, cb)));
219 }
220
221 void MediaResourceGetterImpl::GetPlatformPathCallback(
222 const GetPlatformPathCB& callback, const std::string& platform_path) {
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
224 callback.Run(platform_path);
225 }
226
155 } // namespace content 227 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698