| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/permissions/permission_request.h" | 15 #include "chrome/browser/permissions/permission_request.h" |
| 16 #include "chrome/browser/permissions/permission_request_manager.h" | 16 #include "chrome/browser/permissions/permission_request_manager.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/tab_contents/tab_util.h" | 18 #include "chrome/browser/tab_contents/tab_util.h" |
| 19 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 20 #include "components/url_formatter/elide_url.h" | 20 #include "components/url_formatter/elide_url.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/navigation_details.h" | 22 #include "content/public/browser/navigation_details.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "device/vr/features/features.h" |
| 24 #include "storage/common/quota/quota_types.h" | 25 #include "storage/common/quota/quota_types.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 27 | 28 |
| 28 #if defined(OS_ANDROID) | 29 #if defined(OS_ANDROID) |
| 29 #include "chrome/browser/android/android_theme_resources.h" | 30 #include "chrome/browser/android/android_theme_resources.h" |
| 30 #include "chrome/browser/infobars/infobar_service.h" | 31 #include "chrome/browser/infobars/infobar_service.h" |
| 31 #include "components/infobars/core/confirm_infobar_delegate.h" | 32 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 32 #include "components/infobars/core/infobar.h" | 33 #include "components/infobars/core/infobar.h" |
| 34 |
| 35 #if BUILDFLAG(ENABLE_VR) |
| 36 #include "chrome/browser/android/vr_shell/vr_tab_helper.h" |
| 37 #endif // BUILDFLAG(ENABLE_VR) |
| 38 |
| 33 #else | 39 #else |
| 34 #include "ui/vector_icons/vector_icons.h" | 40 #include "ui/vector_icons/vector_icons.h" |
| 35 #endif | 41 #endif // defined(OS_ANDROID) |
| 36 | 42 |
| 37 namespace { | 43 namespace { |
| 38 | 44 |
| 39 // On Android, if the site requested larger quota than this threshold, show a | 45 // On Android, if the site requested larger quota than this threshold, show a |
| 40 // different message to the user. | 46 // different message to the user. |
| 41 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024; | 47 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024; |
| 42 | 48 |
| 43 // QuotaPermissionRequest --------------------------------------------- | 49 // QuotaPermissionRequest --------------------------------------------- |
| 44 | 50 |
| 45 class QuotaPermissionRequest : public PermissionRequest { | 51 class QuotaPermissionRequest : public PermissionRequest { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID( | 281 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID( |
| 276 render_process_id, params.render_frame_id); | 282 render_process_id, params.render_frame_id); |
| 277 if (!web_contents) { | 283 if (!web_contents) { |
| 278 // The tab may have gone away or the request may not be from a tab. | 284 // The tab may have gone away or the request may not be from a tab. |
| 279 LOG(WARNING) << "Attempt to request quota tabless renderer: " | 285 LOG(WARNING) << "Attempt to request quota tabless renderer: " |
| 280 << render_process_id << "," << params.render_frame_id; | 286 << render_process_id << "," << params.render_frame_id; |
| 281 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); | 287 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
| 282 return; | 288 return; |
| 283 } | 289 } |
| 284 | 290 |
| 291 #if BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) |
| 292 if (vr_shell::VrTabHelper::IsInVr(web_contents)) { |
| 293 LOG(WARNING) << "Attempt to request quota from VR: " |
| 294 << render_process_id << "," << params.render_frame_id; |
| 295 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); |
| 296 return; |
| 297 } |
| 298 #endif |
| 299 |
| 285 if (PermissionRequestManager::IsEnabled()) { | 300 if (PermissionRequestManager::IsEnabled()) { |
| 286 PermissionRequestManager* permission_request_manager = | 301 PermissionRequestManager* permission_request_manager = |
| 287 PermissionRequestManager::FromWebContents(web_contents); | 302 PermissionRequestManager::FromWebContents(web_contents); |
| 288 if (permission_request_manager) { | 303 if (permission_request_manager) { |
| 289 bool is_large_quota_request = | 304 bool is_large_quota_request = |
| 290 params.requested_size > kRequestLargeQuotaThreshold; | 305 params.requested_size > kRequestLargeQuotaThreshold; |
| 291 permission_request_manager->AddRequest(new QuotaPermissionRequest( | 306 permission_request_manager->AddRequest(new QuotaPermissionRequest( |
| 292 this, params.origin_url, is_large_quota_request, callback)); | 307 this, params.origin_url, is_large_quota_request, callback)); |
| 293 return; | 308 return; |
| 294 } | 309 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 322 base::BindOnce( | 337 base::BindOnce( |
| 323 &ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, this, | 338 &ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, this, |
| 324 callback, response)); | 339 callback, response)); |
| 325 return; | 340 return; |
| 326 } | 341 } |
| 327 | 342 |
| 328 callback.Run(response); | 343 callback.Run(response); |
| 329 } | 344 } |
| 330 | 345 |
| 331 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} | 346 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} |
| OLD | NEW |