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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 tab_util::GetWebContentsByID(render_process_id, | 274 tab_util::GetWebContentsByID(render_process_id, |
275 params.render_view_id); | 275 params.render_view_id); |
276 if (!web_contents) { | 276 if (!web_contents) { |
277 // The tab may have gone away or the request may not be from a tab. | 277 // The tab may have gone away or the request may not be from a tab. |
278 LOG(WARNING) << "Attempt to request quota tabless renderer: " | 278 LOG(WARNING) << "Attempt to request quota tabless renderer: " |
279 << render_process_id << "," << params.render_view_id; | 279 << render_process_id << "," << params.render_view_id; |
280 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); | 280 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
281 return; | 281 return; |
282 } | 282 } |
283 | 283 |
| 284 // TODO(gbillock): adapt this to be a better indicator of background page tab. |
| 285 InfoBarService* infobar_service = |
| 286 InfoBarService::FromWebContents(web_contents); |
| 287 if (!infobar_service) { |
| 288 // The tab has no infobar service. |
| 289 LOG(WARNING) << "Attempt to request quota from a background page: " |
| 290 << render_process_id << "," << params.render_view_id; |
| 291 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
| 292 return; |
| 293 } |
| 294 |
284 if (PermissionBubbleManager::Enabled()) { | 295 if (PermissionBubbleManager::Enabled()) { |
285 PermissionBubbleManager* bubble_manager = | 296 PermissionBubbleManager* bubble_manager = |
286 PermissionBubbleManager::FromWebContents(web_contents); | 297 PermissionBubbleManager::FromWebContents(web_contents); |
287 if (bubble_manager) { | 298 if (bubble_manager) { |
288 bubble_manager->AddRequest(new QuotaPermissionRequest(this, | 299 bubble_manager->AddRequest(new QuotaPermissionRequest(this, |
289 params.origin_url, params.requested_size, params.user_gesture, | 300 params.origin_url, params.requested_size, params.user_gesture, |
290 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> | 301 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> |
291 GetPrefs()->GetString(prefs::kAcceptLanguages), | 302 GetPrefs()->GetString(prefs::kAcceptLanguages), |
292 callback)); | 303 callback)); |
293 } | 304 } |
294 return; | 305 return; |
295 } | 306 } |
296 | 307 |
297 InfoBarService* infobar_service = | |
298 InfoBarService::FromWebContents(web_contents); | |
299 if (!infobar_service) { | |
300 // The tab has no infobar service. | |
301 LOG(WARNING) << "Attempt to request quota from a background page: " | |
302 << render_process_id << "," << params.render_view_id; | |
303 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); | |
304 return; | |
305 } | |
306 RequestQuotaInfoBarDelegate::Create( | 308 RequestQuotaInfoBarDelegate::Create( |
307 infobar_service, this, params.origin_url, params.requested_size, | 309 infobar_service, this, params.origin_url, params.requested_size, |
308 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> | 310 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> |
309 GetPrefs()->GetString(prefs::kAcceptLanguages), | 311 GetPrefs()->GetString(prefs::kAcceptLanguages), |
310 callback); | 312 callback); |
311 } | 313 } |
312 | 314 |
313 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( | 315 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( |
314 const PermissionCallback& callback, | 316 const PermissionCallback& callback, |
315 QuotaPermissionResponse response) { | 317 QuotaPermissionResponse response) { |
316 DCHECK_EQ(false, callback.is_null()); | 318 DCHECK_EQ(false, callback.is_null()); |
317 | 319 |
318 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { | 320 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
319 content::BrowserThread::PostTask( | 321 content::BrowserThread::PostTask( |
320 content::BrowserThread::IO, FROM_HERE, | 322 content::BrowserThread::IO, FROM_HERE, |
321 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, | 323 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, |
322 this, callback, response)); | 324 this, callback, response)); |
323 return; | 325 return; |
324 } | 326 } |
325 | 327 |
326 callback.Run(response); | 328 callback.Run(response); |
327 } | 329 } |
328 | 330 |
329 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} | 331 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} |
OLD | NEW |