| 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 24 matching lines...) Expand all Loading... |
| 35 const int64 kRequestLargeQuotaThreshold = 5 * 1024 * 1024; | 35 const int64 kRequestLargeQuotaThreshold = 5 * 1024 * 1024; |
| 36 | 36 |
| 37 // QuotaPermissionRequest --------------------------------------------- | 37 // QuotaPermissionRequest --------------------------------------------- |
| 38 | 38 |
| 39 class QuotaPermissionRequest : public PermissionBubbleRequest { | 39 class QuotaPermissionRequest : public PermissionBubbleRequest { |
| 40 public: | 40 public: |
| 41 QuotaPermissionRequest( | 41 QuotaPermissionRequest( |
| 42 ChromeQuotaPermissionContext* context, | 42 ChromeQuotaPermissionContext* context, |
| 43 const GURL& origin_url, | 43 const GURL& origin_url, |
| 44 int64 requested_quota, | 44 int64 requested_quota, |
| 45 bool user_gesture, |
| 45 const std::string& display_languages, | 46 const std::string& display_languages, |
| 46 const content::QuotaPermissionContext::PermissionCallback& callback); | 47 const content::QuotaPermissionContext::PermissionCallback& callback); |
| 47 | 48 |
| 48 virtual ~QuotaPermissionRequest(); | 49 virtual ~QuotaPermissionRequest(); |
| 49 | 50 |
| 50 // PermissionBubbleRequest: | 51 // PermissionBubbleRequest: |
| 51 virtual int GetIconID() const OVERRIDE; | 52 virtual int GetIconID() const OVERRIDE; |
| 52 virtual base::string16 GetMessageText() const OVERRIDE; | 53 virtual base::string16 GetMessageText() const OVERRIDE; |
| 53 virtual base::string16 GetMessageTextFragment() const OVERRIDE; | 54 virtual base::string16 GetMessageTextFragment() const OVERRIDE; |
| 54 virtual bool HasUserGesture() const OVERRIDE; | 55 virtual bool HasUserGesture() const OVERRIDE; |
| 55 virtual GURL GetRequestingHostname() const OVERRIDE; | 56 virtual GURL GetRequestingHostname() const OVERRIDE; |
| 56 virtual void PermissionGranted() OVERRIDE; | 57 virtual void PermissionGranted() OVERRIDE; |
| 57 virtual void PermissionDenied() OVERRIDE; | 58 virtual void PermissionDenied() OVERRIDE; |
| 58 virtual void Cancelled() OVERRIDE; | 59 virtual void Cancelled() OVERRIDE; |
| 59 virtual void RequestFinished() OVERRIDE; | 60 virtual void RequestFinished() OVERRIDE; |
| 60 | 61 |
| 61 private: | 62 private: |
| 62 scoped_refptr<ChromeQuotaPermissionContext> context_; | 63 scoped_refptr<ChromeQuotaPermissionContext> context_; |
| 63 GURL origin_url_; | 64 GURL origin_url_; |
| 64 std::string display_languages_; | 65 std::string display_languages_; |
| 65 int64 requested_quota_; | 66 int64 requested_quota_; |
| 67 bool user_gesture_; |
| 66 content::QuotaPermissionContext::PermissionCallback callback_; | 68 content::QuotaPermissionContext::PermissionCallback callback_; |
| 67 | 69 |
| 68 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); | 70 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 QuotaPermissionRequest::QuotaPermissionRequest( | 73 QuotaPermissionRequest::QuotaPermissionRequest( |
| 72 ChromeQuotaPermissionContext* context, | 74 ChromeQuotaPermissionContext* context, |
| 73 const GURL& origin_url, | 75 const GURL& origin_url, |
| 74 int64 requested_quota, | 76 int64 requested_quota, |
| 77 bool user_gesture, |
| 75 const std::string& display_languages, | 78 const std::string& display_languages, |
| 76 const content::QuotaPermissionContext::PermissionCallback& callback) | 79 const content::QuotaPermissionContext::PermissionCallback& callback) |
| 77 : context_(context), | 80 : context_(context), |
| 78 origin_url_(origin_url), | 81 origin_url_(origin_url), |
| 79 display_languages_(display_languages), | 82 display_languages_(display_languages), |
| 80 requested_quota_(requested_quota), | 83 requested_quota_(requested_quota), |
| 84 user_gesture_(user_gesture), |
| 81 callback_(callback) {} | 85 callback_(callback) {} |
| 82 | 86 |
| 83 QuotaPermissionRequest::~QuotaPermissionRequest() {} | 87 QuotaPermissionRequest::~QuotaPermissionRequest() {} |
| 84 | 88 |
| 85 int QuotaPermissionRequest::GetIconID() const { | 89 int QuotaPermissionRequest::GetIconID() const { |
| 86 // TODO(gbillock): get the proper image here | 90 // TODO(gbillock): get the proper image here |
| 87 return IDR_INFOBAR_WARNING; | 91 return IDR_INFOBAR_WARNING; |
| 88 } | 92 } |
| 89 | 93 |
| 90 base::string16 QuotaPermissionRequest::GetMessageText() const { | 94 base::string16 QuotaPermissionRequest::GetMessageText() const { |
| 91 return l10n_util::GetStringFUTF16( | 95 return l10n_util::GetStringFUTF16( |
| 92 (requested_quota_ > kRequestLargeQuotaThreshold ? | 96 (requested_quota_ > kRequestLargeQuotaThreshold ? |
| 93 IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION : | 97 IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION : |
| 94 IDS_REQUEST_QUOTA_INFOBAR_QUESTION), | 98 IDS_REQUEST_QUOTA_INFOBAR_QUESTION), |
| 95 net::FormatUrl(origin_url_, display_languages_)); | 99 net::FormatUrl(origin_url_, display_languages_)); |
| 96 } | 100 } |
| 97 | 101 |
| 98 base::string16 QuotaPermissionRequest::GetMessageTextFragment() const { | 102 base::string16 QuotaPermissionRequest::GetMessageTextFragment() const { |
| 99 return l10n_util::GetStringUTF16(IDS_REQUEST_QUOTA_PERMISSION_FRAGMENT); | 103 return l10n_util::GetStringUTF16(IDS_REQUEST_QUOTA_PERMISSION_FRAGMENT); |
| 100 } | 104 } |
| 101 | 105 |
| 102 bool QuotaPermissionRequest::HasUserGesture() const { | 106 bool QuotaPermissionRequest::HasUserGesture() const { |
| 103 // TODO(gbillock): plumb this through | 107 return user_gesture_; |
| 104 return false; | |
| 105 } | 108 } |
| 106 | 109 |
| 107 GURL QuotaPermissionRequest::GetRequestingHostname() const { | 110 GURL QuotaPermissionRequest::GetRequestingHostname() const { |
| 108 return origin_url_; | 111 return origin_url_; |
| 109 } | 112 } |
| 110 | 113 |
| 111 void QuotaPermissionRequest::PermissionGranted() { | 114 void QuotaPermissionRequest::PermissionGranted() { |
| 112 context_->DispatchCallbackOnIOThread( | 115 context_->DispatchCallbackOnIOThread( |
| 113 callback_, | 116 callback_, |
| 114 content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_ALLOW); | 117 content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_ALLOW); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 244 |
| 242 } // namespace | 245 } // namespace |
| 243 | 246 |
| 244 | 247 |
| 245 // ChromeQuotaPermissionContext ----------------------------------------------- | 248 // ChromeQuotaPermissionContext ----------------------------------------------- |
| 246 | 249 |
| 247 ChromeQuotaPermissionContext::ChromeQuotaPermissionContext() { | 250 ChromeQuotaPermissionContext::ChromeQuotaPermissionContext() { |
| 248 } | 251 } |
| 249 | 252 |
| 250 void ChromeQuotaPermissionContext::RequestQuotaPermission( | 253 void ChromeQuotaPermissionContext::RequestQuotaPermission( |
| 251 const GURL& origin_url, | 254 const content::RequestStorageQuotaParams& params, |
| 252 quota::StorageType type, | |
| 253 int64 requested_quota, | |
| 254 int render_process_id, | 255 int render_process_id, |
| 255 int render_view_id, | |
| 256 const PermissionCallback& callback) { | 256 const PermissionCallback& callback) { |
| 257 if (type != quota::kStorageTypePersistent) { | 257 if (params.storage_type != quota::kStorageTypePersistent) { |
| 258 // For now we only support requesting quota with this interface | 258 // For now we only support requesting quota with this interface |
| 259 // for Persistent storage type. | 259 // for Persistent storage type. |
| 260 callback.Run(QUOTA_PERMISSION_RESPONSE_DISALLOW); | 260 callback.Run(QUOTA_PERMISSION_RESPONSE_DISALLOW); |
| 261 return; | 261 return; |
| 262 } | 262 } |
| 263 | 263 |
| 264 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 264 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 265 content::BrowserThread::PostTask( | 265 content::BrowserThread::PostTask( |
| 266 content::BrowserThread::UI, FROM_HERE, | 266 content::BrowserThread::UI, FROM_HERE, |
| 267 base::Bind(&ChromeQuotaPermissionContext::RequestQuotaPermission, this, | 267 base::Bind(&ChromeQuotaPermissionContext::RequestQuotaPermission, this, |
| 268 origin_url, type, requested_quota, render_process_id, | 268 params, render_process_id, callback)); |
| 269 render_view_id, callback)); | |
| 270 return; | 269 return; |
| 271 } | 270 } |
| 272 | 271 |
| 273 content::WebContents* web_contents = | 272 content::WebContents* web_contents = |
| 274 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 273 tab_util::GetWebContentsByID(render_process_id, |
| 274 params.render_view_id); |
| 275 if (!web_contents) { | 275 if (!web_contents) { |
| 276 // The tab may have gone away or the request may not be from a tab. | 276 // The tab may have gone away or the request may not be from a tab. |
| 277 LOG(WARNING) << "Attempt to request quota tabless renderer: " | 277 LOG(WARNING) << "Attempt to request quota tabless renderer: " |
| 278 << render_process_id << "," << render_view_id; | 278 << render_process_id << "," << params.render_view_id; |
| 279 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); | 279 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
| 280 return; | 280 return; |
| 281 } | 281 } |
| 282 | 282 |
| 283 if (PermissionBubbleManager::Enabled()) { | 283 if (PermissionBubbleManager::Enabled()) { |
| 284 PermissionBubbleManager* bubble_manager = | 284 PermissionBubbleManager* bubble_manager = |
| 285 PermissionBubbleManager::FromWebContents(web_contents); | 285 PermissionBubbleManager::FromWebContents(web_contents); |
| 286 bubble_manager->AddRequest(new QuotaPermissionRequest(this, | 286 bubble_manager->AddRequest(new QuotaPermissionRequest(this, |
| 287 origin_url, requested_quota, | 287 params.origin_url, params.requested_size, params.user_gesture, |
| 288 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> | 288 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> |
| 289 GetPrefs()->GetString(prefs::kAcceptLanguages), | 289 GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 290 callback)); | 290 callback)); |
| 291 return; | 291 return; |
| 292 } | 292 } |
| 293 | 293 |
| 294 InfoBarService* infobar_service = | 294 InfoBarService* infobar_service = |
| 295 InfoBarService::FromWebContents(web_contents); | 295 InfoBarService::FromWebContents(web_contents); |
| 296 if (!infobar_service) { | 296 if (!infobar_service) { |
| 297 // The tab has no infobar service. | 297 // The tab has no infobar service. |
| 298 LOG(WARNING) << "Attempt to request quota from a background page: " | 298 LOG(WARNING) << "Attempt to request quota from a background page: " |
| 299 << render_process_id << "," << render_view_id; | 299 << render_process_id << "," << params.render_view_id; |
| 300 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); | 300 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
| 301 return; | 301 return; |
| 302 } | 302 } |
| 303 RequestQuotaInfoBarDelegate::Create( | 303 RequestQuotaInfoBarDelegate::Create( |
| 304 infobar_service, this, origin_url, requested_quota, | 304 infobar_service, this, params.origin_url, params.requested_size, |
| 305 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> | 305 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> |
| 306 GetPrefs()->GetString(prefs::kAcceptLanguages), | 306 GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 307 callback); | 307 callback); |
| 308 } | 308 } |
| 309 | 309 |
| 310 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( | 310 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( |
| 311 const PermissionCallback& callback, | 311 const PermissionCallback& callback, |
| 312 QuotaPermissionResponse response) { | 312 QuotaPermissionResponse response) { |
| 313 DCHECK_EQ(false, callback.is_null()); | 313 DCHECK_EQ(false, callback.is_null()); |
| 314 | 314 |
| 315 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { | 315 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
| 316 content::BrowserThread::PostTask( | 316 content::BrowserThread::PostTask( |
| 317 content::BrowserThread::IO, FROM_HERE, | 317 content::BrowserThread::IO, FROM_HERE, |
| 318 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, | 318 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, |
| 319 this, callback, response)); | 319 this, callback, response)); |
| 320 return; | 320 return; |
| 321 } | 321 } |
| 322 | 322 |
| 323 callback.Run(response); | 323 callback.Run(response); |
| 324 } | 324 } |
| 325 | 325 |
| 326 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} | 326 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} |
| OLD | NEW |