| 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/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/tab_contents/tab_util.h" | 17 #include "chrome/browser/tab_contents/tab_util.h" |
| 17 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | |
| 18 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 19 #include "chrome/grit/locale_settings.h" | 19 #include "chrome/grit/locale_settings.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 "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 25 #include "storage/common/quota/quota_types.h" | 25 #include "storage/common/quota/quota_types.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 28 | 28 |
| 29 #if defined(OS_ANDROID) | 29 #if defined(OS_ANDROID) |
| 30 #include "chrome/browser/infobars/infobar_service.h" | 30 #include "chrome/browser/infobars/infobar_service.h" |
| 31 #include "components/infobars/core/confirm_infobar_delegate.h" | 31 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 32 #include "components/infobars/core/infobar.h" | 32 #include "components/infobars/core/infobar.h" |
| 33 #else | 33 #else |
| 34 #include "chrome/browser/permissions/permission_request_manager.h" | 34 #include "chrome/browser/permissions/permission_request_manager.h" |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 #if defined(OS_ANDROID) | 39 #if defined(OS_ANDROID) |
| 40 // If the site requested larger quota than this threshold, show a different | 40 // If the site requested larger quota than this threshold, show a different |
| 41 // message to the user. | 41 // message to the user. |
| 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 PermissionRequest { |
| 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 const content::QuotaPermissionContext::PermissionCallback& callback); | 52 const content::QuotaPermissionContext::PermissionCallback& callback); |
| 53 | 53 |
| 54 ~QuotaPermissionRequest() override; | 54 ~QuotaPermissionRequest() override; |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 // PermissionBubbleRequest: | 57 // PermissionRequest: |
| 58 int GetIconId() const override; | 58 int GetIconId() const override; |
| 59 base::string16 GetMessageTextFragment() const override; | 59 base::string16 GetMessageTextFragment() const override; |
| 60 GURL GetOrigin() const override; | 60 GURL GetOrigin() const override; |
| 61 void PermissionGranted() override; | 61 void PermissionGranted() override; |
| 62 void PermissionDenied() override; | 62 void PermissionDenied() override; |
| 63 void Cancelled() override; | 63 void Cancelled() override; |
| 64 void RequestFinished() override; | 64 void RequestFinished() override; |
| 65 PermissionBubbleType GetPermissionBubbleType() const override; | 65 PermissionRequestType GetPermissionRequestType() const override; |
| 66 | 66 |
| 67 scoped_refptr<ChromeQuotaPermissionContext> context_; | 67 scoped_refptr<ChromeQuotaPermissionContext> context_; |
| 68 GURL origin_url_; | 68 GURL origin_url_; |
| 69 content::QuotaPermissionContext::PermissionCallback callback_; | 69 content::QuotaPermissionContext::PermissionCallback callback_; |
| 70 | 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); | 71 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 QuotaPermissionRequest::QuotaPermissionRequest( | 74 QuotaPermissionRequest::QuotaPermissionRequest( |
| 75 ChromeQuotaPermissionContext* context, | 75 ChromeQuotaPermissionContext* context, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 void QuotaPermissionRequest::RequestFinished() { | 114 void QuotaPermissionRequest::RequestFinished() { |
| 115 if (!callback_.is_null()) { | 115 if (!callback_.is_null()) { |
| 116 context_->DispatchCallbackOnIOThread( | 116 context_->DispatchCallbackOnIOThread( |
| 117 callback_, | 117 callback_, |
| 118 content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED); | 118 content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED); |
| 119 } | 119 } |
| 120 | 120 |
| 121 delete this; | 121 delete this; |
| 122 } | 122 } |
| 123 | 123 |
| 124 PermissionBubbleType QuotaPermissionRequest::GetPermissionBubbleType() const { | 124 PermissionRequestType QuotaPermissionRequest::GetPermissionRequestType() const { |
| 125 return PermissionBubbleType::QUOTA; | 125 return PermissionRequestType::QUOTA; |
| 126 } | 126 } |
| 127 | 127 |
| 128 #if defined(OS_ANDROID) | 128 #if defined(OS_ANDROID) |
| 129 // RequestQuotaInfoBarDelegate ------------------------------------------------ | 129 // RequestQuotaInfoBarDelegate ------------------------------------------------ |
| 130 | 130 |
| 131 class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { | 131 class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 132 public: | 132 public: |
| 133 // Creates a request quota infobar and delegate and adds the infobar to | 133 // Creates a request quota infobar and delegate and adds the infobar to |
| 134 // |infobar_service|. | 134 // |infobar_service|. |
| 135 static void Create( | 135 static void Create( |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 content::BrowserThread::IO, FROM_HERE, | 295 content::BrowserThread::IO, FROM_HERE, |
| 296 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, | 296 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, |
| 297 this, callback, response)); | 297 this, callback, response)); |
| 298 return; | 298 return; |
| 299 } | 299 } |
| 300 | 300 |
| 301 callback.Run(response); | 301 callback.Run(response); |
| 302 } | 302 } |
| 303 | 303 |
| 304 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} | 304 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} |
| OLD | NEW |