| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 12 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 13 #include "chrome/browser/infobars/infobar.h" |
| 13 #include "chrome/browser/infobars/infobar_service.h" | 14 #include "chrome/browser/infobars/infobar_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/tab_contents/tab_util.h" | 16 #include "chrome/browser/tab_contents/tab_util.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/navigation_details.h" | 19 #include "content/public/browser/navigation_details.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 21 #include "grit/locale_settings.h" | 22 #include "grit/locale_settings.h" |
| 22 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 #include "webkit/common/quota/quota_types.h" | 26 #include "webkit/common/quota/quota_types.h" |
| 26 | 27 |
| 27 | 28 |
| 28 | 29 |
| 29 // RequestQuotaInfoBarDelegate ------------------------------------------------ | 30 // RequestQuotaInfoBarDelegate ------------------------------------------------ |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { | 34 class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 34 public: | 35 public: |
| 35 // Creates a request quota infobar delegate and adds it to |infobar_service|. | 36 // Creates a request quota infobar and delegate and adds the infobar to |
| 37 // |infobar_service|. |
| 36 static void Create( | 38 static void Create( |
| 37 InfoBarService* infobar_service, | 39 InfoBarService* infobar_service, |
| 38 ChromeQuotaPermissionContext* context, | 40 ChromeQuotaPermissionContext* context, |
| 39 const GURL& origin_url, | 41 const GURL& origin_url, |
| 40 int64 requested_quota, | 42 int64 requested_quota, |
| 41 const std::string& display_languages, | 43 const std::string& display_languages, |
| 42 const content::QuotaPermissionContext::PermissionCallback& callback); | 44 const content::QuotaPermissionContext::PermissionCallback& callback); |
| 43 | 45 |
| 44 private: | 46 private: |
| 45 RequestQuotaInfoBarDelegate( | 47 RequestQuotaInfoBarDelegate( |
| 46 InfoBarService* infobar_service, | |
| 47 ChromeQuotaPermissionContext* context, | 48 ChromeQuotaPermissionContext* context, |
| 48 const GURL& origin_url, | 49 const GURL& origin_url, |
| 49 int64 requested_quota, | 50 int64 requested_quota, |
| 50 const std::string& display_languages, | 51 const std::string& display_languages, |
| 51 const content::QuotaPermissionContext::PermissionCallback& callback); | 52 const content::QuotaPermissionContext::PermissionCallback& callback); |
| 52 virtual ~RequestQuotaInfoBarDelegate(); | 53 virtual ~RequestQuotaInfoBarDelegate(); |
| 53 | 54 |
| 54 // ConfirmInfoBarDelegate: | 55 // ConfirmInfoBarDelegate: |
| 55 virtual bool ShouldExpireInternal( | 56 virtual bool ShouldExpireInternal( |
| 56 const content::LoadCommittedDetails& details) const OVERRIDE; | 57 const content::LoadCommittedDetails& details) const OVERRIDE; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 68 }; | 69 }; |
| 69 | 70 |
| 70 // static | 71 // static |
| 71 void RequestQuotaInfoBarDelegate::Create( | 72 void RequestQuotaInfoBarDelegate::Create( |
| 72 InfoBarService* infobar_service, | 73 InfoBarService* infobar_service, |
| 73 ChromeQuotaPermissionContext* context, | 74 ChromeQuotaPermissionContext* context, |
| 74 const GURL& origin_url, | 75 const GURL& origin_url, |
| 75 int64 requested_quota, | 76 int64 requested_quota, |
| 76 const std::string& display_languages, | 77 const std::string& display_languages, |
| 77 const content::QuotaPermissionContext::PermissionCallback& callback) { | 78 const content::QuotaPermissionContext::PermissionCallback& callback) { |
| 78 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 79 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( |
| 79 new RequestQuotaInfoBarDelegate(infobar_service, context, origin_url, | 80 scoped_ptr<ConfirmInfoBarDelegate>(new RequestQuotaInfoBarDelegate( |
| 80 requested_quota, display_languages, | 81 context, origin_url, requested_quota, display_languages, callback)))); |
| 81 callback))); | |
| 82 } | 82 } |
| 83 | 83 |
| 84 RequestQuotaInfoBarDelegate::RequestQuotaInfoBarDelegate( | 84 RequestQuotaInfoBarDelegate::RequestQuotaInfoBarDelegate( |
| 85 InfoBarService* infobar_service, | |
| 86 ChromeQuotaPermissionContext* context, | 85 ChromeQuotaPermissionContext* context, |
| 87 const GURL& origin_url, | 86 const GURL& origin_url, |
| 88 int64 requested_quota, | 87 int64 requested_quota, |
| 89 const std::string& display_languages, | 88 const std::string& display_languages, |
| 90 const content::QuotaPermissionContext::PermissionCallback& callback) | 89 const content::QuotaPermissionContext::PermissionCallback& callback) |
| 91 : ConfirmInfoBarDelegate(infobar_service), | 90 : ConfirmInfoBarDelegate(), |
| 92 context_(context), | 91 context_(context), |
| 93 origin_url_(origin_url), | 92 origin_url_(origin_url), |
| 94 display_languages_(display_languages), | 93 display_languages_(display_languages), |
| 95 requested_quota_(requested_quota), | 94 requested_quota_(requested_quota), |
| 96 callback_(callback) { | 95 callback_(callback) { |
| 97 } | 96 } |
| 98 | 97 |
| 99 RequestQuotaInfoBarDelegate::~RequestQuotaInfoBarDelegate() { | 98 RequestQuotaInfoBarDelegate::~RequestQuotaInfoBarDelegate() { |
| 100 if (!callback_.is_null()) { | 99 if (!callback_.is_null()) { |
| 101 context_->DispatchCallbackOnIOThread( | 100 context_->DispatchCallbackOnIOThread( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 content::BrowserThread::IO, FROM_HERE, | 200 content::BrowserThread::IO, FROM_HERE, |
| 202 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, | 201 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, |
| 203 this, callback, response)); | 202 this, callback, response)); |
| 204 return; | 203 return; |
| 205 } | 204 } |
| 206 | 205 |
| 207 callback.Run(response); | 206 callback.Run(response); |
| 208 } | 207 } |
| 209 | 208 |
| 210 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} | 209 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} |
| OLD | NEW |