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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024; | 43 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024; |
44 #endif | 44 #endif |
45 | 45 |
46 // QuotaPermissionRequest --------------------------------------------- | 46 // QuotaPermissionRequest --------------------------------------------- |
47 | 47 |
48 class QuotaPermissionRequest : public PermissionRequest { | 48 class QuotaPermissionRequest : public PermissionRequest { |
49 public: | 49 public: |
50 QuotaPermissionRequest( | 50 QuotaPermissionRequest( |
51 ChromeQuotaPermissionContext* context, | 51 ChromeQuotaPermissionContext* context, |
52 const GURL& origin_url, | 52 const GURL& origin_url, |
53 int64_t requested_quota, | |
53 const content::QuotaPermissionContext::PermissionCallback& callback); | 54 const content::QuotaPermissionContext::PermissionCallback& callback); |
54 | 55 |
55 ~QuotaPermissionRequest() override; | 56 ~QuotaPermissionRequest() override; |
56 | 57 |
57 private: | 58 private: |
58 // PermissionRequest: | 59 // PermissionRequest: |
59 IconId GetIconId() const override; | 60 IconId GetIconId() const override; |
61 #if defined(OS_ANDROID) | |
62 base::string16 GetMessageText() const override; | |
63 #endif | |
60 base::string16 GetMessageTextFragment() const override; | 64 base::string16 GetMessageTextFragment() const override; |
61 GURL GetOrigin() const override; | 65 GURL GetOrigin() const override; |
62 void PermissionGranted() override; | 66 void PermissionGranted() override; |
63 void PermissionDenied() override; | 67 void PermissionDenied() override; |
64 void Cancelled() override; | 68 void Cancelled() override; |
65 void RequestFinished() override; | 69 void RequestFinished() override; |
66 PermissionRequestType GetPermissionRequestType() const override; | 70 PermissionRequestType GetPermissionRequestType() const override; |
67 | 71 |
68 scoped_refptr<ChromeQuotaPermissionContext> context_; | 72 scoped_refptr<ChromeQuotaPermissionContext> context_; |
69 GURL origin_url_; | 73 GURL origin_url_; |
74 int64_t requested_quota_; | |
70 content::QuotaPermissionContext::PermissionCallback callback_; | 75 content::QuotaPermissionContext::PermissionCallback callback_; |
71 | 76 |
72 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); | 77 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); |
73 }; | 78 }; |
74 | 79 |
75 QuotaPermissionRequest::QuotaPermissionRequest( | 80 QuotaPermissionRequest::QuotaPermissionRequest( |
76 ChromeQuotaPermissionContext* context, | 81 ChromeQuotaPermissionContext* context, |
77 const GURL& origin_url, | 82 const GURL& origin_url, |
83 int64_t requested_quota, | |
78 const content::QuotaPermissionContext::PermissionCallback& callback) | 84 const content::QuotaPermissionContext::PermissionCallback& callback) |
79 : context_(context), | 85 : context_(context), |
80 origin_url_(origin_url), | 86 origin_url_(origin_url), |
81 callback_(callback) {} | 87 requested_quota_(requested_quota), |
88 callback_(callback) { | |
89 // Suppress unused private field warning on desktop | |
Lei Zhang
2017/05/31 07:28:22
Why not make |requested_quota_| Android only?
Timothy Loh
2017/06/01 04:12:39
I figured it'd be messier to have the ifdefs for i
| |
90 (void)requested_quota_; | |
91 } | |
82 | 92 |
83 QuotaPermissionRequest::~QuotaPermissionRequest() {} | 93 QuotaPermissionRequest::~QuotaPermissionRequest() {} |
84 | 94 |
85 PermissionRequest::IconId QuotaPermissionRequest::GetIconId() const { | 95 PermissionRequest::IconId QuotaPermissionRequest::GetIconId() const { |
86 // TODO(gbillock): get the proper image here | 96 // TODO(gbillock): get the proper image here |
87 #if defined(OS_ANDROID) | 97 #if defined(OS_ANDROID) |
88 return IDR_ANDROID_INFOBAR_WARNING; | 98 return IDR_ANDROID_INFOBAR_WARNING; |
89 #else | 99 #else |
90 return ui::kWarningIcon; | 100 return ui::kWarningIcon; |
91 #endif | 101 #endif |
92 } | 102 } |
93 | 103 |
104 #if defined(OS_ANDROID) | |
105 base::string16 QuotaPermissionRequest::GetMessageText() const { | |
106 // If the site requested larger quota than this threshold, show a different | |
107 // message to the user. | |
108 return l10n_util::GetStringFUTF16( | |
109 (requested_quota_ > kRequestLargeQuotaThreshold | |
Lei Zhang
2017/05/31 07:28:22
BTW, this is really a criticism of the original co
Timothy Loh
2017/06/01 04:12:39
I took the liberty to fix this (and const a couple
| |
110 ? IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION | |
111 : IDS_REQUEST_QUOTA_INFOBAR_QUESTION), | |
112 url_formatter::FormatUrlForSecurityDisplay(origin_url_)); | |
113 } | |
114 #endif | |
115 | |
94 base::string16 QuotaPermissionRequest::GetMessageTextFragment() const { | 116 base::string16 QuotaPermissionRequest::GetMessageTextFragment() const { |
95 return l10n_util::GetStringUTF16(IDS_REQUEST_QUOTA_PERMISSION_FRAGMENT); | 117 return l10n_util::GetStringUTF16(IDS_REQUEST_QUOTA_PERMISSION_FRAGMENT); |
96 } | 118 } |
97 | 119 |
98 GURL QuotaPermissionRequest::GetOrigin() const { | 120 GURL QuotaPermissionRequest::GetOrigin() const { |
99 return origin_url_; | 121 return origin_url_; |
100 } | 122 } |
101 | 123 |
102 void QuotaPermissionRequest::PermissionGranted() { | 124 void QuotaPermissionRequest::PermissionGranted() { |
103 context_->DispatchCallbackOnIOThread( | 125 context_->DispatchCallbackOnIOThread( |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 LOG(WARNING) << "Attempt to request quota tabless renderer: " | 283 LOG(WARNING) << "Attempt to request quota tabless renderer: " |
262 << render_process_id << "," << params.render_frame_id; | 284 << render_process_id << "," << params.render_frame_id; |
263 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); | 285 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
264 return; | 286 return; |
265 } | 287 } |
266 | 288 |
267 if (PermissionRequestManager::IsEnabled()) { | 289 if (PermissionRequestManager::IsEnabled()) { |
268 PermissionRequestManager* permission_request_manager = | 290 PermissionRequestManager* permission_request_manager = |
269 PermissionRequestManager::FromWebContents(web_contents); | 291 PermissionRequestManager::FromWebContents(web_contents); |
270 if (permission_request_manager) { | 292 if (permission_request_manager) { |
271 permission_request_manager->AddRequest( | 293 permission_request_manager->AddRequest(new QuotaPermissionRequest( |
272 new QuotaPermissionRequest(this, params.origin_url, callback)); | 294 this, params.origin_url, params.requested_size, callback)); |
273 return; | 295 return; |
274 } | 296 } |
275 #if defined(OS_ANDROID) | 297 #if defined(OS_ANDROID) |
276 } else { | 298 } else { |
277 InfoBarService* infobar_service = | 299 InfoBarService* infobar_service = |
278 InfoBarService::FromWebContents(web_contents); | 300 InfoBarService::FromWebContents(web_contents); |
279 if (infobar_service) { | 301 if (infobar_service) { |
280 RequestQuotaInfoBarDelegate::Create(infobar_service, this, | 302 RequestQuotaInfoBarDelegate::Create(infobar_service, this, |
281 params.origin_url, | 303 params.origin_url, |
282 params.requested_size, callback); | 304 params.requested_size, callback); |
(...skipping 19 matching lines...) Expand all Loading... | |
302 base::BindOnce( | 324 base::BindOnce( |
303 &ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, this, | 325 &ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, this, |
304 callback, response)); | 326 callback, response)); |
305 return; | 327 return; |
306 } | 328 } |
307 | 329 |
308 callback.Run(response); | 330 callback.Run(response); |
309 } | 331 } |
310 | 332 |
311 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} | 333 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} |
OLD | NEW |