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 "chrome/browser/chrome_quota_permission_context.h" | 5 #include "chrome/browser/chrome_quota_permission_context.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 233 |
234 } // namespace | 234 } // namespace |
235 | 235 |
236 | 236 |
237 // ChromeQuotaPermissionContext ----------------------------------------------- | 237 // ChromeQuotaPermissionContext ----------------------------------------------- |
238 | 238 |
239 ChromeQuotaPermissionContext::ChromeQuotaPermissionContext() { | 239 ChromeQuotaPermissionContext::ChromeQuotaPermissionContext() { |
240 } | 240 } |
241 | 241 |
242 void ChromeQuotaPermissionContext::RequestQuotaPermission( | 242 void ChromeQuotaPermissionContext::RequestQuotaPermission( |
243 const GURL& origin_url, | 243 const quota::RequestStorageQuotaParams& params, |
244 quota::StorageType type, | |
245 int64 requested_quota, | |
246 int render_process_id, | 244 int render_process_id, |
247 int render_view_id, | |
248 const PermissionCallback& callback) { | 245 const PermissionCallback& callback) { |
249 if (type != quota::kStorageTypePersistent) { | 246 if (params.storage_type != quota::kStorageTypePersistent) { |
250 // For now we only support requesting quota with this interface | 247 // For now we only support requesting quota with this interface |
251 // for Persistent storage type. | 248 // for Persistent storage type. |
252 callback.Run(QUOTA_PERMISSION_RESPONSE_DISALLOW); | 249 callback.Run(QUOTA_PERMISSION_RESPONSE_DISALLOW); |
253 return; | 250 return; |
254 } | 251 } |
255 | 252 |
256 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 253 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
257 content::BrowserThread::PostTask( | 254 content::BrowserThread::PostTask( |
258 content::BrowserThread::UI, FROM_HERE, | 255 content::BrowserThread::UI, FROM_HERE, |
259 base::Bind(&ChromeQuotaPermissionContext::RequestQuotaPermission, this, | 256 base::Bind(&ChromeQuotaPermissionContext::RequestQuotaPermission, this, |
260 origin_url, type, requested_quota, render_process_id, | 257 params, render_process_id, callback)); |
261 render_view_id, callback)); | |
262 return; | 258 return; |
263 } | 259 } |
264 | 260 |
265 content::WebContents* web_contents = | 261 content::WebContents* web_contents = |
266 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 262 tab_util::GetWebContentsByID(render_process_id, |
| 263 params.render_view_id); |
267 if (!web_contents) { | 264 if (!web_contents) { |
268 // The tab may have gone away or the request may not be from a tab. | 265 // The tab may have gone away or the request may not be from a tab. |
269 LOG(WARNING) << "Attempt to request quota tabless renderer: " | 266 LOG(WARNING) << "Attempt to request quota tabless renderer: " |
270 << render_process_id << "," << render_view_id; | 267 << render_process_id << "," << params.render_view_id; |
271 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); | 268 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
272 return; | 269 return; |
273 } | 270 } |
274 | 271 |
275 if (PermissionBubbleManager::Enabled()) { | 272 if (PermissionBubbleManager::Enabled()) { |
276 PermissionBubbleManager* bubble_manager = | 273 PermissionBubbleManager* bubble_manager = |
277 PermissionBubbleManager::FromWebContents(web_contents); | 274 PermissionBubbleManager::FromWebContents(web_contents); |
278 bubble_manager->AddRequest(new QuotaPermissionRequest(this, | 275 bubble_manager->AddRequest(new QuotaPermissionRequest(this, |
279 origin_url, requested_quota, | 276 params.origin_url, params.requested_size, |
280 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> | 277 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> |
281 GetPrefs()->GetString(prefs::kAcceptLanguages), | 278 GetPrefs()->GetString(prefs::kAcceptLanguages), |
282 callback)); | 279 callback)); |
283 return; | 280 return; |
284 } | 281 } |
285 | 282 |
286 InfoBarService* infobar_service = | 283 InfoBarService* infobar_service = |
287 InfoBarService::FromWebContents(web_contents); | 284 InfoBarService::FromWebContents(web_contents); |
288 if (!infobar_service) { | 285 if (!infobar_service) { |
289 // The tab has no infobar service. | 286 // The tab has no infobar service. |
290 LOG(WARNING) << "Attempt to request quota from a background page: " | 287 LOG(WARNING) << "Attempt to request quota from a background page: " |
291 << render_process_id << "," << render_view_id; | 288 << render_process_id << "," << params.render_view_id; |
292 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); | 289 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
293 return; | 290 return; |
294 } | 291 } |
295 RequestQuotaInfoBarDelegate::Create( | 292 RequestQuotaInfoBarDelegate::Create( |
296 infobar_service, this, origin_url, requested_quota, | 293 infobar_service, this, params.origin_url, params.requested_size, |
297 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> | 294 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> |
298 GetPrefs()->GetString(prefs::kAcceptLanguages), | 295 GetPrefs()->GetString(prefs::kAcceptLanguages), |
299 callback); | 296 callback); |
300 } | 297 } |
301 | 298 |
302 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( | 299 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( |
303 const PermissionCallback& callback, | 300 const PermissionCallback& callback, |
304 QuotaPermissionResponse response) { | 301 QuotaPermissionResponse response) { |
305 DCHECK_EQ(false, callback.is_null()); | 302 DCHECK_EQ(false, callback.is_null()); |
306 | 303 |
307 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { | 304 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
308 content::BrowserThread::PostTask( | 305 content::BrowserThread::PostTask( |
309 content::BrowserThread::IO, FROM_HERE, | 306 content::BrowserThread::IO, FROM_HERE, |
310 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, | 307 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, |
311 this, callback, response)); | 308 this, callback, response)); |
312 return; | 309 return; |
313 } | 310 } |
314 | 311 |
315 callback.Run(response); | 312 callback.Run(response); |
316 } | 313 } |
317 | 314 |
318 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} | 315 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} |
OLD | NEW |