| 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   InfoBarService* infobar_service = | 
 |  285       InfoBarService::FromWebContents(web_contents); | 
 |  286   if (!infobar_service) { | 
 |  287     // The tab has no infobar service. | 
 |  288     LOG(WARNING) << "Attempt to request quota from a background page: " | 
 |  289                  << render_process_id << "," << params.render_view_id; | 
 |  290     DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); | 
 |  291     return; | 
 |  292   } | 
 |  293  | 
|  284   if (PermissionBubbleManager::Enabled()) { |  294   if (PermissionBubbleManager::Enabled()) { | 
|  285     PermissionBubbleManager* bubble_manager = |  295     PermissionBubbleManager* bubble_manager = | 
|  286         PermissionBubbleManager::FromWebContents(web_contents); |  296         PermissionBubbleManager::FromWebContents(web_contents); | 
|  287     if (bubble_manager) { |  297     if (bubble_manager) { | 
|  288       bubble_manager->AddRequest(new QuotaPermissionRequest(this, |  298       bubble_manager->AddRequest(new QuotaPermissionRequest(this, | 
|  289               params.origin_url, params.requested_size, params.user_gesture, |  299               params.origin_url, params.requested_size, params.user_gesture, | 
|  290               Profile::FromBrowserContext(web_contents->GetBrowserContext())-> |  300               Profile::FromBrowserContext(web_contents->GetBrowserContext())-> | 
|  291                   GetPrefs()->GetString(prefs::kAcceptLanguages), |  301                   GetPrefs()->GetString(prefs::kAcceptLanguages), | 
|  292               callback)); |  302               callback)); | 
|  293     } |  303     } | 
|  294     return; |  304     return; | 
|  295   } |  305   } | 
|  296  |  306  | 
|  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( |  307   RequestQuotaInfoBarDelegate::Create( | 
|  307       infobar_service, this, params.origin_url, params.requested_size, |  308       infobar_service, this, params.origin_url, params.requested_size, | 
|  308       Profile::FromBrowserContext(web_contents->GetBrowserContext())-> |  309       Profile::FromBrowserContext(web_contents->GetBrowserContext())-> | 
|  309           GetPrefs()->GetString(prefs::kAcceptLanguages), |  310           GetPrefs()->GetString(prefs::kAcceptLanguages), | 
|  310       callback); |  311       callback); | 
|  311 } |  312 } | 
|  312  |  313  | 
|  313 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( |  314 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( | 
|  314     const PermissionCallback& callback, |  315     const PermissionCallback& callback, | 
|  315     QuotaPermissionResponse response) { |  316     QuotaPermissionResponse response) { | 
|  316   DCHECK_EQ(false, callback.is_null()); |  317   DCHECK_EQ(false, callback.is_null()); | 
|  317  |  318  | 
|  318   if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |  319   if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { | 
|  319     content::BrowserThread::PostTask( |  320     content::BrowserThread::PostTask( | 
|  320         content::BrowserThread::IO, FROM_HERE, |  321         content::BrowserThread::IO, FROM_HERE, | 
|  321         base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, |  322         base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, | 
|  322                    this, callback, response)); |  323                    this, callback, response)); | 
|  323     return; |  324     return; | 
|  324   } |  325   } | 
|  325  |  326  | 
|  326   callback.Run(response); |  327   callback.Run(response); | 
|  327 } |  328 } | 
|  328  |  329  | 
|  329 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} |  330 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} | 
| OLD | NEW |