[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/chrome_quota_permission_context.h" |
| 6 | |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 9 | #include <string> |
| 10 | |
[email protected] | c8d98dd | 2011-10-18 23:12:08 | [diff] [blame] | 11 | #include "base/bind.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 13 | #include "base/strings/utf_string_conversions.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 14 | #include "build/build_config.h" |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 15 | #include "chrome/browser/permissions/permission_request.h" |
timloh | 5b34b67 | 2017-03-08 01:49:34 | [diff] [blame] | 16 | #include "chrome/browser/permissions/permission_request_manager.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 17 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 18 | #include "chrome/browser/tab_contents/tab_util.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 19 | #include "chrome/grit/generated_resources.h" |
palmer | a6615c59 | 2015-09-24 00:49:09 | [diff] [blame] | 20 | #include "components/url_formatter/elide_url.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 21 | #include "content/public/browser/browser_thread.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 22 | #include "content/public/browser/navigation_details.h" |
[email protected] | 4f822f02 | 2012-12-20 19:11:42 | [diff] [blame] | 23 | #include "content/public/browser/web_contents.h" |
pilgrim | 1633055 | 2014-09-10 01:32:22 | [diff] [blame] | 24 | #include "storage/common/quota/quota_types.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 25 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 26 | #include "url/gurl.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 27 | |
estade | 6d95d1d | 2015-10-02 18:55:23 | [diff] [blame] | 28 | #if defined(OS_ANDROID) |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 29 | #include "chrome/browser/android/android_theme_resources.h" |
estade | 6d95d1d | 2015-10-02 18:55:23 | [diff] [blame] | 30 | #include "chrome/browser/infobars/infobar_service.h" |
| 31 | #include "components/infobars/core/confirm_infobar_delegate.h" |
| 32 | #include "components/infobars/core/infobar.h" |
| 33 | #else |
estade | 1e235b6 | 2017-02-15 01:40:34 | [diff] [blame] | 34 | #include "ui/vector_icons/vector_icons.h" |
estade | 6d95d1d | 2015-10-02 18:55:23 | [diff] [blame] | 35 | #endif |
| 36 | |
[email protected] | c032489d | 2014-02-11 19:07:24 | [diff] [blame] | 37 | namespace { |
| 38 | |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame^] | 39 | // On Android, if the site requested larger quota than this threshold, show a |
| 40 | // different message to the user. |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 41 | const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024; |
[email protected] | c032489d | 2014-02-11 19:07:24 | [diff] [blame] | 42 | |
| 43 | // QuotaPermissionRequest --------------------------------------------- |
| 44 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 45 | class QuotaPermissionRequest : public PermissionRequest { |
[email protected] | c032489d | 2014-02-11 19:07:24 | [diff] [blame] | 46 | public: |
| 47 | QuotaPermissionRequest( |
| 48 | ChromeQuotaPermissionContext* context, |
| 49 | const GURL& origin_url, |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame^] | 50 | bool is_large_quota_request_, |
[email protected] | c032489d | 2014-02-11 19:07:24 | [diff] [blame] | 51 | const content::QuotaPermissionContext::PermissionCallback& callback); |
| 52 | |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 53 | ~QuotaPermissionRequest() override; |
[email protected] | c032489d | 2014-02-11 19:07:24 | [diff] [blame] | 54 | |
benwells | 46b02fa | 2016-04-20 02:37:02 | [diff] [blame] | 55 | private: |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 56 | // PermissionRequest: |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 57 | IconId GetIconId() const override; |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame^] | 58 | #if defined(OS_ANDROID) |
| 59 | base::string16 GetMessageText() const override; |
| 60 | #endif |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 61 | base::string16 GetMessageTextFragment() const override; |
johnme | fe4e96d | 2016-01-27 16:14:41 | [diff] [blame] | 62 | GURL GetOrigin() const override; |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 63 | void PermissionGranted() override; |
| 64 | void PermissionDenied() override; |
| 65 | void Cancelled() override; |
| 66 | void RequestFinished() override; |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 67 | PermissionRequestType GetPermissionRequestType() const override; |
[email protected] | c032489d | 2014-02-11 19:07:24 | [diff] [blame] | 68 | |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame^] | 69 | const scoped_refptr<ChromeQuotaPermissionContext> context_; |
| 70 | const GURL origin_url_; |
| 71 | const bool is_large_quota_request_; |
[email protected] | c032489d | 2014-02-11 19:07:24 | [diff] [blame] | 72 | content::QuotaPermissionContext::PermissionCallback callback_; |
| 73 | |
| 74 | DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); |
| 75 | }; |
| 76 | |
| 77 | QuotaPermissionRequest::QuotaPermissionRequest( |
| 78 | ChromeQuotaPermissionContext* context, |
| 79 | const GURL& origin_url, |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame^] | 80 | bool is_large_quota_request, |
[email protected] | c032489d | 2014-02-11 19:07:24 | [diff] [blame] | 81 | const content::QuotaPermissionContext::PermissionCallback& callback) |
| 82 | : context_(context), |
| 83 | origin_url_(origin_url), |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame^] | 84 | is_large_quota_request_(is_large_quota_request), |
| 85 | callback_(callback) { |
| 86 | // Suppress unused private field warning on desktop |
| 87 | (void)is_large_quota_request_; |
| 88 | } |
[email protected] | c032489d | 2014-02-11 19:07:24 | [diff] [blame] | 89 | |
| 90 | QuotaPermissionRequest::~QuotaPermissionRequest() {} |
| 91 | |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 92 | PermissionRequest::IconId QuotaPermissionRequest::GetIconId() const { |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 93 | // TODO(gbillock): get the proper image here |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 94 | #if defined(OS_ANDROID) |
| 95 | return IDR_ANDROID_INFOBAR_WARNING; |
| 96 | #else |
estade | 1e235b6 | 2017-02-15 01:40:34 | [diff] [blame] | 97 | return ui::kWarningIcon; |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 98 | #endif |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 99 | } |
| 100 | |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame^] | 101 | #if defined(OS_ANDROID) |
| 102 | base::string16 QuotaPermissionRequest::GetMessageText() const { |
| 103 | // If the site requested larger quota than this threshold, show a different |
| 104 | // message to the user. |
| 105 | return l10n_util::GetStringFUTF16( |
| 106 | (is_large_quota_request_ ? IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION |
| 107 | : IDS_REQUEST_QUOTA_INFOBAR_QUESTION), |
| 108 | url_formatter::FormatUrlForSecurityDisplay(origin_url_)); |
| 109 | } |
| 110 | #endif |
| 111 | |
[email protected] | c032489d | 2014-02-11 19:07:24 | [diff] [blame] | 112 | base::string16 QuotaPermissionRequest::GetMessageTextFragment() const { |
| 113 | return l10n_util::GetStringUTF16(IDS_REQUEST_QUOTA_PERMISSION_FRAGMENT); |
| 114 | } |
| 115 | |
johnme | fe4e96d | 2016-01-27 16:14:41 | [diff] [blame] | 116 | GURL QuotaPermissionRequest::GetOrigin() const { |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 117 | return origin_url_; |
[email protected] | c032489d | 2014-02-11 19:07:24 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void QuotaPermissionRequest::PermissionGranted() { |
| 121 | context_->DispatchCallbackOnIOThread( |
| 122 | callback_, |
| 123 | content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_ALLOW); |
| 124 | callback_ = content::QuotaPermissionContext::PermissionCallback(); |
| 125 | } |
| 126 | |
| 127 | void QuotaPermissionRequest::PermissionDenied() { |
| 128 | context_->DispatchCallbackOnIOThread( |
| 129 | callback_, |
| 130 | content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_DISALLOW); |
| 131 | callback_ = content::QuotaPermissionContext::PermissionCallback(); |
| 132 | } |
| 133 | |
| 134 | void QuotaPermissionRequest::Cancelled() { |
| 135 | } |
| 136 | |
| 137 | void QuotaPermissionRequest::RequestFinished() { |
| 138 | if (!callback_.is_null()) { |
| 139 | context_->DispatchCallbackOnIOThread( |
| 140 | callback_, |
| 141 | content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED); |
| 142 | } |
| 143 | |
| 144 | delete this; |
| 145 | } |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 146 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 147 | PermissionRequestType QuotaPermissionRequest::GetPermissionRequestType() const { |
| 148 | return PermissionRequestType::QUOTA; |
benwells | 46b02fa | 2016-04-20 02:37:02 | [diff] [blame] | 149 | } |
| 150 | |
estade | 6d95d1d | 2015-10-02 18:55:23 | [diff] [blame] | 151 | #if defined(OS_ANDROID) |
[email protected] | 49c71ac | 2013-05-03 01:36:22 | [diff] [blame] | 152 | // RequestQuotaInfoBarDelegate ------------------------------------------------ |
| 153 | |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 154 | class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 155 | public: |
[email protected] | 39308cb | 2013-12-06 03:01:48 | [diff] [blame] | 156 | // Creates a request quota infobar and delegate and adds the infobar to |
| 157 | // |infobar_service|. |
[email protected] | 0be0993 | 2013-01-08 02:03:50 | [diff] [blame] | 158 | static void Create( |
| 159 | InfoBarService* infobar_service, |
| 160 | ChromeQuotaPermissionContext* context, |
| 161 | const GURL& origin_url, |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 162 | int64_t requested_quota, |
[email protected] | 9a88ea99 | 2013-07-10 21:21:57 | [diff] [blame] | 163 | const content::QuotaPermissionContext::PermissionCallback& callback); |
[email protected] | 0be0993 | 2013-01-08 02:03:50 | [diff] [blame] | 164 | |
| 165 | private: |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 166 | RequestQuotaInfoBarDelegate( |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 167 | ChromeQuotaPermissionContext* context, |
| 168 | const GURL& origin_url, |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 169 | int64_t requested_quota, |
[email protected] | 9a88ea99 | 2013-07-10 21:21:57 | [diff] [blame] | 170 | const content::QuotaPermissionContext::PermissionCallback& callback); |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 171 | ~RequestQuotaInfoBarDelegate() override; |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 172 | |
[email protected] | 49c71ac | 2013-05-03 01:36:22 | [diff] [blame] | 173 | // ConfirmInfoBarDelegate: |
dfalcantara | ac4d93b | 2015-12-30 20:07:24 | [diff] [blame] | 174 | infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 175 | base::string16 GetMessageText() const override; |
| 176 | bool Accept() override; |
| 177 | bool Cancel() override; |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 178 | |
| 179 | scoped_refptr<ChromeQuotaPermissionContext> context_; |
| 180 | GURL origin_url_; |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 181 | int64_t requested_quota_; |
[email protected] | 9a88ea99 | 2013-07-10 21:21:57 | [diff] [blame] | 182 | content::QuotaPermissionContext::PermissionCallback callback_; |
[email protected] | 49c71ac | 2013-05-03 01:36:22 | [diff] [blame] | 183 | |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 184 | DISALLOW_COPY_AND_ASSIGN(RequestQuotaInfoBarDelegate); |
| 185 | }; |
| 186 | |
[email protected] | 0be0993 | 2013-01-08 02:03:50 | [diff] [blame] | 187 | // static |
| 188 | void RequestQuotaInfoBarDelegate::Create( |
| 189 | InfoBarService* infobar_service, |
| 190 | ChromeQuotaPermissionContext* context, |
| 191 | const GURL& origin_url, |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 192 | int64_t requested_quota, |
[email protected] | 9a88ea99 | 2013-07-10 21:21:57 | [diff] [blame] | 193 | const content::QuotaPermissionContext::PermissionCallback& callback) { |
sdefresne | 316da45 | 2014-12-22 17:30:59 | [diff] [blame] | 194 | infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 195 | std::unique_ptr<ConfirmInfoBarDelegate>(new RequestQuotaInfoBarDelegate( |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 196 | context, origin_url, requested_quota, callback)))); |
[email protected] | 0be0993 | 2013-01-08 02:03:50 | [diff] [blame] | 197 | } |
| 198 | |
[email protected] | 49c71ac | 2013-05-03 01:36:22 | [diff] [blame] | 199 | RequestQuotaInfoBarDelegate::RequestQuotaInfoBarDelegate( |
[email protected] | 49c71ac | 2013-05-03 01:36:22 | [diff] [blame] | 200 | ChromeQuotaPermissionContext* context, |
| 201 | const GURL& origin_url, |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 202 | int64_t requested_quota, |
[email protected] | 9a88ea99 | 2013-07-10 21:21:57 | [diff] [blame] | 203 | const content::QuotaPermissionContext::PermissionCallback& callback) |
[email protected] | 39308cb | 2013-12-06 03:01:48 | [diff] [blame] | 204 | : ConfirmInfoBarDelegate(), |
[email protected] | 49c71ac | 2013-05-03 01:36:22 | [diff] [blame] | 205 | context_(context), |
| 206 | origin_url_(origin_url), |
[email protected] | 49c71ac | 2013-05-03 01:36:22 | [diff] [blame] | 207 | requested_quota_(requested_quota), |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 208 | callback_(callback) {} |
[email protected] | 49c71ac | 2013-05-03 01:36:22 | [diff] [blame] | 209 | |
| 210 | RequestQuotaInfoBarDelegate::~RequestQuotaInfoBarDelegate() { |
| 211 | if (!callback_.is_null()) { |
| 212 | context_->DispatchCallbackOnIOThread( |
| 213 | callback_, |
[email protected] | 9a88ea99 | 2013-07-10 21:21:57 | [diff] [blame] | 214 | content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED); |
[email protected] | 49c71ac | 2013-05-03 01:36:22 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
dfalcantara | ac4d93b | 2015-12-30 20:07:24 | [diff] [blame] | 218 | infobars::InfoBarDelegate::InfoBarIdentifier |
| 219 | RequestQuotaInfoBarDelegate::GetIdentifier() const { |
| 220 | return REQUEST_QUOTA_INFOBAR_DELEGATE; |
| 221 | } |
| 222 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 223 | base::string16 RequestQuotaInfoBarDelegate::GetMessageText() const { |
[email protected] | 9a88ea99 | 2013-07-10 21:21:57 | [diff] [blame] | 224 | // If the site requested larger quota than this threshold, show a different |
| 225 | // message to the user. |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 226 | return l10n_util::GetStringFUTF16( |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 227 | (requested_quota_ > kRequestLargeQuotaThreshold |
| 228 | ? IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION |
| 229 | : IDS_REQUEST_QUOTA_INFOBAR_QUESTION), |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 230 | url_formatter::FormatUrlForSecurityDisplay(origin_url_)); |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | bool RequestQuotaInfoBarDelegate::Accept() { |
| 234 | context_->DispatchCallbackOnIOThread( |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 235 | callback_, |
[email protected] | 9a88ea99 | 2013-07-10 21:21:57 | [diff] [blame] | 236 | content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_ALLOW); |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 237 | return true; |
| 238 | } |
| 239 | |
| 240 | bool RequestQuotaInfoBarDelegate::Cancel() { |
| 241 | context_->DispatchCallbackOnIOThread( |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 242 | callback_, |
[email protected] | 9a88ea99 | 2013-07-10 21:21:57 | [diff] [blame] | 243 | content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED); |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 244 | return true; |
| 245 | } |
estade | 6d95d1d | 2015-10-02 18:55:23 | [diff] [blame] | 246 | #endif |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 247 | |
[email protected] | 49c71ac | 2013-05-03 01:36:22 | [diff] [blame] | 248 | } // namespace |
| 249 | |
| 250 | |
| 251 | // ChromeQuotaPermissionContext ----------------------------------------------- |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 252 | |
[email protected] | 9a88ea99 | 2013-07-10 21:21:57 | [diff] [blame] | 253 | ChromeQuotaPermissionContext::ChromeQuotaPermissionContext() { |
| 254 | } |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 255 | |
| 256 | void ChromeQuotaPermissionContext::RequestQuotaPermission( |
[email protected] | f78aa772 | 2014-04-04 00:04:25 | [diff] [blame] | 257 | const content::StorageQuotaParams& params, |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 258 | int render_process_id, |
[email protected] | c8d98dd | 2011-10-18 23:12:08 | [diff] [blame] | 259 | const PermissionCallback& callback) { |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 260 | if (params.storage_type != storage::kStorageTypePersistent) { |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 261 | // For now we only support requesting quota with this interface |
| 262 | // for Persistent storage type. |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 263 | callback.Run(QUOTA_PERMISSION_RESPONSE_DISALLOW); |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 264 | return; |
| 265 | } |
| 266 | |
[email protected] | 9a88ea99 | 2013-07-10 21:21:57 | [diff] [blame] | 267 | if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 268 | content::BrowserThread::PostTask( |
| 269 | content::BrowserThread::UI, FROM_HERE, |
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 270 | base::BindOnce(&ChromeQuotaPermissionContext::RequestQuotaPermission, |
| 271 | this, params, render_process_id, callback)); |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 272 | return; |
| 273 | } |
| 274 | |
nick | 6206d82 | 2016-12-09 20:05:03 | [diff] [blame] | 275 | content::WebContents* web_contents = tab_util::GetWebContentsByFrameID( |
| 276 | render_process_id, params.render_frame_id); |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 277 | if (!web_contents) { |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 278 | // The tab may have gone away or the request may not be from a tab. |
| 279 | LOG(WARNING) << "Attempt to request quota tabless renderer: " |
nick | 6206d82 | 2016-12-09 20:05:03 | [diff] [blame] | 280 | << render_process_id << "," << params.render_frame_id; |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 281 | DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 282 | return; |
| 283 | } |
| 284 | |
timloh | 5b34b67 | 2017-03-08 01:49:34 | [diff] [blame] | 285 | if (PermissionRequestManager::IsEnabled()) { |
| 286 | PermissionRequestManager* permission_request_manager = |
| 287 | PermissionRequestManager::FromWebContents(web_contents); |
| 288 | if (permission_request_manager) { |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame^] | 289 | bool is_large_quota_request = |
| 290 | params.requested_size > kRequestLargeQuotaThreshold; |
| 291 | permission_request_manager->AddRequest(new QuotaPermissionRequest( |
| 292 | this, params.origin_url, is_large_quota_request, callback)); |
timloh | 5b34b67 | 2017-03-08 01:49:34 | [diff] [blame] | 293 | return; |
| 294 | } |
estade | 6d95d1d | 2015-10-02 18:55:23 | [diff] [blame] | 295 | #if defined(OS_ANDROID) |
timloh | 5b34b67 | 2017-03-08 01:49:34 | [diff] [blame] | 296 | } else { |
| 297 | InfoBarService* infobar_service = |
| 298 | InfoBarService::FromWebContents(web_contents); |
| 299 | if (infobar_service) { |
| 300 | RequestQuotaInfoBarDelegate::Create(infobar_service, this, |
| 301 | params.origin_url, |
| 302 | params.requested_size, callback); |
| 303 | return; |
| 304 | } |
estade | 6d95d1d | 2015-10-02 18:55:23 | [diff] [blame] | 305 | #endif |
timloh | 5b34b67 | 2017-03-08 01:49:34 | [diff] [blame] | 306 | } |
[email protected] | c032489d | 2014-02-11 19:07:24 | [diff] [blame] | 307 | |
estade | 6d95d1d | 2015-10-02 18:55:23 | [diff] [blame] | 308 | // The tab has no UI service for presenting the permissions request. |
| 309 | LOG(WARNING) << "Attempt to request quota from a background page: " |
nick | 6206d82 | 2016-12-09 20:05:03 | [diff] [blame] | 310 | << render_process_id << "," << params.render_frame_id; |
estade | 6d95d1d | 2015-10-02 18:55:23 | [diff] [blame] | 311 | DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( |
[email protected] | c8d98dd | 2011-10-18 23:12:08 | [diff] [blame] | 315 | const PermissionCallback& callback, |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 316 | QuotaPermissionResponse response) { |
[email protected] | c8d98dd | 2011-10-18 23:12:08 | [diff] [blame] | 317 | DCHECK_EQ(false, callback.is_null()); |
| 318 | |
[email protected] | 9a88ea99 | 2013-07-10 21:21:57 | [diff] [blame] | 319 | if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
| 320 | content::BrowserThread::PostTask( |
| 321 | content::BrowserThread::IO, FROM_HERE, |
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 322 | base::BindOnce( |
| 323 | &ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, this, |
| 324 | callback, response)); |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 325 | return; |
| 326 | } |
[email protected] | c8d98dd | 2011-10-18 23:12:08 | [diff] [blame] | 327 | |
| 328 | callback.Run(response); |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 329 | } |
[email protected] | 649d1c0 | 2012-04-27 02:56:21 | [diff] [blame] | 330 | |
| 331 | ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} |