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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024; | 42 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024; |
43 #endif | 43 #endif |
44 | 44 |
45 // QuotaPermissionRequest --------------------------------------------- | 45 // QuotaPermissionRequest --------------------------------------------- |
46 | 46 |
47 class QuotaPermissionRequest : public PermissionBubbleRequest { | 47 class QuotaPermissionRequest : public PermissionBubbleRequest { |
48 public: | 48 public: |
49 QuotaPermissionRequest( | 49 QuotaPermissionRequest( |
50 ChromeQuotaPermissionContext* context, | 50 ChromeQuotaPermissionContext* context, |
51 const GURL& origin_url, | 51 const GURL& origin_url, |
52 int64_t requested_quota, | |
53 const content::QuotaPermissionContext::PermissionCallback& callback); | 52 const content::QuotaPermissionContext::PermissionCallback& callback); |
54 | 53 |
55 ~QuotaPermissionRequest() override; | 54 ~QuotaPermissionRequest() override; |
56 | 55 |
57 private: | 56 private: |
58 // PermissionBubbleRequest: | 57 // PermissionBubbleRequest: |
59 int GetIconId() const override; | 58 int GetIconId() const override; |
60 base::string16 GetMessageTextFragment() const override; | 59 base::string16 GetMessageTextFragment() const override; |
61 GURL GetOrigin() const override; | 60 GURL GetOrigin() const override; |
62 void PermissionGranted() override; | 61 void PermissionGranted() override; |
63 void PermissionDenied() override; | 62 void PermissionDenied() override; |
64 void Cancelled() override; | 63 void Cancelled() override; |
65 void RequestFinished() override; | 64 void RequestFinished() override; |
66 PermissionBubbleType GetPermissionBubbleType() const override; | 65 PermissionBubbleType GetPermissionBubbleType() const override; |
67 | 66 |
68 scoped_refptr<ChromeQuotaPermissionContext> context_; | 67 scoped_refptr<ChromeQuotaPermissionContext> context_; |
69 GURL origin_url_; | 68 GURL origin_url_; |
70 int64_t requested_quota_; | |
71 content::QuotaPermissionContext::PermissionCallback callback_; | 69 content::QuotaPermissionContext::PermissionCallback callback_; |
72 | 70 |
73 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); | 71 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); |
74 }; | 72 }; |
75 | 73 |
76 QuotaPermissionRequest::QuotaPermissionRequest( | 74 QuotaPermissionRequest::QuotaPermissionRequest( |
77 ChromeQuotaPermissionContext* context, | 75 ChromeQuotaPermissionContext* context, |
78 const GURL& origin_url, | 76 const GURL& origin_url, |
79 int64_t requested_quota, | |
80 const content::QuotaPermissionContext::PermissionCallback& callback) | 77 const content::QuotaPermissionContext::PermissionCallback& callback) |
81 : context_(context), | 78 : context_(context), |
82 origin_url_(origin_url), | 79 origin_url_(origin_url), |
83 requested_quota_(requested_quota), | |
84 callback_(callback) {} | 80 callback_(callback) {} |
85 | 81 |
86 QuotaPermissionRequest::~QuotaPermissionRequest() {} | 82 QuotaPermissionRequest::~QuotaPermissionRequest() {} |
87 | 83 |
88 int QuotaPermissionRequest::GetIconId() const { | 84 int QuotaPermissionRequest::GetIconId() const { |
89 // TODO(gbillock): get the proper image here | 85 // TODO(gbillock): get the proper image here |
90 return IDR_INFOBAR_WARNING; | 86 return IDR_INFOBAR_WARNING; |
91 } | 87 } |
92 | 88 |
93 base::string16 QuotaPermissionRequest::GetMessageTextFragment() const { | 89 base::string16 QuotaPermissionRequest::GetMessageTextFragment() const { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 if (infobar_service) { | 266 if (infobar_service) { |
271 RequestQuotaInfoBarDelegate::Create( | 267 RequestQuotaInfoBarDelegate::Create( |
272 infobar_service, this, params.origin_url, params.requested_size, | 268 infobar_service, this, params.origin_url, params.requested_size, |
273 callback); | 269 callback); |
274 return; | 270 return; |
275 } | 271 } |
276 #else | 272 #else |
277 PermissionBubbleManager* bubble_manager = | 273 PermissionBubbleManager* bubble_manager = |
278 PermissionBubbleManager::FromWebContents(web_contents); | 274 PermissionBubbleManager::FromWebContents(web_contents); |
279 if (bubble_manager) { | 275 if (bubble_manager) { |
280 bubble_manager->AddRequest(new QuotaPermissionRequest( | 276 bubble_manager->AddRequest( |
281 this, params.origin_url, params.requested_size, callback)); | 277 new QuotaPermissionRequest(this, params.origin_url, callback)); |
282 return; | 278 return; |
283 } | 279 } |
284 #endif | 280 #endif |
285 | 281 |
286 // The tab has no UI service for presenting the permissions request. | 282 // The tab has no UI service for presenting the permissions request. |
287 LOG(WARNING) << "Attempt to request quota from a background page: " | 283 LOG(WARNING) << "Attempt to request quota from a background page: " |
288 << render_process_id << "," << params.render_view_id; | 284 << render_process_id << "," << params.render_view_id; |
289 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); | 285 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
290 } | 286 } |
291 | 287 |
292 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( | 288 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( |
293 const PermissionCallback& callback, | 289 const PermissionCallback& callback, |
294 QuotaPermissionResponse response) { | 290 QuotaPermissionResponse response) { |
295 DCHECK_EQ(false, callback.is_null()); | 291 DCHECK_EQ(false, callback.is_null()); |
296 | 292 |
297 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { | 293 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
298 content::BrowserThread::PostTask( | 294 content::BrowserThread::PostTask( |
299 content::BrowserThread::IO, FROM_HERE, | 295 content::BrowserThread::IO, FROM_HERE, |
300 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, | 296 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, |
301 this, callback, response)); | 297 this, callback, response)); |
302 return; | 298 return; |
303 } | 299 } |
304 | 300 |
305 callback.Run(response); | 301 callback.Run(response); |
306 } | 302 } |
307 | 303 |
308 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} | 304 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} |
OLD | NEW |