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 19 matching lines...) Expand all Loading... |
30 #include "chrome/browser/android/android_theme_resources.h" | 30 #include "chrome/browser/android/android_theme_resources.h" |
31 #include "chrome/browser/infobars/infobar_service.h" | 31 #include "chrome/browser/infobars/infobar_service.h" |
32 #include "components/infobars/core/confirm_infobar_delegate.h" | 32 #include "components/infobars/core/confirm_infobar_delegate.h" |
33 #include "components/infobars/core/infobar.h" | 33 #include "components/infobars/core/infobar.h" |
34 #else | 34 #else |
35 #include "ui/vector_icons/vector_icons.h" | 35 #include "ui/vector_icons/vector_icons.h" |
36 #endif | 36 #endif |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 #if defined(OS_ANDROID) | 40 // On Android, if the site requested larger quota than this threshold, show a |
41 // If the site requested larger quota than this threshold, show a different | 41 // different message to the user. |
42 // message to the user. | |
43 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024; | 42 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024; |
44 #endif | |
45 | 43 |
46 // QuotaPermissionRequest --------------------------------------------- | 44 // QuotaPermissionRequest --------------------------------------------- |
47 | 45 |
48 class QuotaPermissionRequest : public PermissionRequest { | 46 class QuotaPermissionRequest : public PermissionRequest { |
49 public: | 47 public: |
50 QuotaPermissionRequest( | 48 QuotaPermissionRequest( |
51 ChromeQuotaPermissionContext* context, | 49 ChromeQuotaPermissionContext* context, |
52 const GURL& origin_url, | 50 const GURL& origin_url, |
| 51 bool is_large_quota_request_, |
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 // PermissionRequest: | 57 // PermissionRequest: |
59 IconId GetIconId() const override; | 58 IconId GetIconId() const override; |
| 59 #if defined(OS_ANDROID) |
| 60 base::string16 GetMessageText() const override; |
| 61 #endif |
60 base::string16 GetMessageTextFragment() const override; | 62 base::string16 GetMessageTextFragment() const override; |
61 GURL GetOrigin() const override; | 63 GURL GetOrigin() const override; |
62 void PermissionGranted() override; | 64 void PermissionGranted() override; |
63 void PermissionDenied() override; | 65 void PermissionDenied() override; |
64 void Cancelled() override; | 66 void Cancelled() override; |
65 void RequestFinished() override; | 67 void RequestFinished() override; |
66 PermissionRequestType GetPermissionRequestType() const override; | 68 PermissionRequestType GetPermissionRequestType() const override; |
67 | 69 |
68 scoped_refptr<ChromeQuotaPermissionContext> context_; | 70 const scoped_refptr<ChromeQuotaPermissionContext> context_; |
69 GURL origin_url_; | 71 const GURL origin_url_; |
| 72 const bool is_large_quota_request_; |
70 content::QuotaPermissionContext::PermissionCallback callback_; | 73 content::QuotaPermissionContext::PermissionCallback callback_; |
71 | 74 |
72 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); | 75 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); |
73 }; | 76 }; |
74 | 77 |
75 QuotaPermissionRequest::QuotaPermissionRequest( | 78 QuotaPermissionRequest::QuotaPermissionRequest( |
76 ChromeQuotaPermissionContext* context, | 79 ChromeQuotaPermissionContext* context, |
77 const GURL& origin_url, | 80 const GURL& origin_url, |
| 81 bool is_large_quota_request, |
78 const content::QuotaPermissionContext::PermissionCallback& callback) | 82 const content::QuotaPermissionContext::PermissionCallback& callback) |
79 : context_(context), | 83 : context_(context), |
80 origin_url_(origin_url), | 84 origin_url_(origin_url), |
81 callback_(callback) {} | 85 is_large_quota_request_(is_large_quota_request), |
| 86 callback_(callback) { |
| 87 // Suppress unused private field warning on desktop |
| 88 (void)is_large_quota_request_; |
| 89 } |
82 | 90 |
83 QuotaPermissionRequest::~QuotaPermissionRequest() {} | 91 QuotaPermissionRequest::~QuotaPermissionRequest() {} |
84 | 92 |
85 PermissionRequest::IconId QuotaPermissionRequest::GetIconId() const { | 93 PermissionRequest::IconId QuotaPermissionRequest::GetIconId() const { |
86 // TODO(gbillock): get the proper image here | 94 // TODO(gbillock): get the proper image here |
87 #if defined(OS_ANDROID) | 95 #if defined(OS_ANDROID) |
88 return IDR_ANDROID_INFOBAR_WARNING; | 96 return IDR_ANDROID_INFOBAR_WARNING; |
89 #else | 97 #else |
90 return ui::kWarningIcon; | 98 return ui::kWarningIcon; |
91 #endif | 99 #endif |
92 } | 100 } |
93 | 101 |
| 102 #if defined(OS_ANDROID) |
| 103 base::string16 QuotaPermissionRequest::GetMessageText() const { |
| 104 // If the site requested larger quota than this threshold, show a different |
| 105 // message to the user. |
| 106 return l10n_util::GetStringFUTF16( |
| 107 (is_large_quota_request_ ? IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION |
| 108 : IDS_REQUEST_QUOTA_INFOBAR_QUESTION), |
| 109 url_formatter::FormatUrlForSecurityDisplay(origin_url_)); |
| 110 } |
| 111 #endif |
| 112 |
94 base::string16 QuotaPermissionRequest::GetMessageTextFragment() const { | 113 base::string16 QuotaPermissionRequest::GetMessageTextFragment() const { |
95 return l10n_util::GetStringUTF16(IDS_REQUEST_QUOTA_PERMISSION_FRAGMENT); | 114 return l10n_util::GetStringUTF16(IDS_REQUEST_QUOTA_PERMISSION_FRAGMENT); |
96 } | 115 } |
97 | 116 |
98 GURL QuotaPermissionRequest::GetOrigin() const { | 117 GURL QuotaPermissionRequest::GetOrigin() const { |
99 return origin_url_; | 118 return origin_url_; |
100 } | 119 } |
101 | 120 |
102 void QuotaPermissionRequest::PermissionGranted() { | 121 void QuotaPermissionRequest::PermissionGranted() { |
103 context_->DispatchCallbackOnIOThread( | 122 context_->DispatchCallbackOnIOThread( |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 LOG(WARNING) << "Attempt to request quota tabless renderer: " | 280 LOG(WARNING) << "Attempt to request quota tabless renderer: " |
262 << render_process_id << "," << params.render_frame_id; | 281 << render_process_id << "," << params.render_frame_id; |
263 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); | 282 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
264 return; | 283 return; |
265 } | 284 } |
266 | 285 |
267 if (PermissionRequestManager::IsEnabled()) { | 286 if (PermissionRequestManager::IsEnabled()) { |
268 PermissionRequestManager* permission_request_manager = | 287 PermissionRequestManager* permission_request_manager = |
269 PermissionRequestManager::FromWebContents(web_contents); | 288 PermissionRequestManager::FromWebContents(web_contents); |
270 if (permission_request_manager) { | 289 if (permission_request_manager) { |
271 permission_request_manager->AddRequest( | 290 bool is_large_quota_request = |
272 new QuotaPermissionRequest(this, params.origin_url, callback)); | 291 params.requested_size > kRequestLargeQuotaThreshold; |
| 292 permission_request_manager->AddRequest(new QuotaPermissionRequest( |
| 293 this, params.origin_url, is_large_quota_request, callback)); |
273 return; | 294 return; |
274 } | 295 } |
275 #if defined(OS_ANDROID) | 296 #if defined(OS_ANDROID) |
276 } else { | 297 } else { |
277 InfoBarService* infobar_service = | 298 InfoBarService* infobar_service = |
278 InfoBarService::FromWebContents(web_contents); | 299 InfoBarService::FromWebContents(web_contents); |
279 if (infobar_service) { | 300 if (infobar_service) { |
280 RequestQuotaInfoBarDelegate::Create(infobar_service, this, | 301 RequestQuotaInfoBarDelegate::Create(infobar_service, this, |
281 params.origin_url, | 302 params.origin_url, |
282 params.requested_size, callback); | 303 params.requested_size, callback); |
(...skipping 19 matching lines...) Expand all Loading... |
302 base::BindOnce( | 323 base::BindOnce( |
303 &ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, this, | 324 &ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, this, |
304 callback, response)); | 325 callback, response)); |
305 return; | 326 return; |
306 } | 327 } |
307 | 328 |
308 callback.Run(response); | 329 callback.Run(response); |
309 } | 330 } |
310 | 331 |
311 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} | 332 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} |
OLD | NEW |