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> |
| 8 |
7 #include <string> | 9 #include <string> |
8 | 10 |
9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/macros.h" |
10 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
11 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "build/build_config.h" |
12 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/tab_contents/tab_util.h" | 17 #include "chrome/browser/tab_contents/tab_util.h" |
14 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 18 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
15 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
16 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
17 #include "chrome/grit/locale_settings.h" | 21 #include "chrome/grit/locale_settings.h" |
18 #include "components/url_formatter/elide_url.h" | 22 #include "components/url_formatter/elide_url.h" |
19 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/navigation_details.h" | 24 #include "content/public/browser/navigation_details.h" |
21 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
22 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
23 #include "storage/common/quota/quota_types.h" | 27 #include "storage/common/quota/quota_types.h" |
24 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
25 #include "url/gurl.h" | 29 #include "url/gurl.h" |
26 | 30 |
27 #if defined(OS_ANDROID) | 31 #if defined(OS_ANDROID) |
28 #include "chrome/browser/infobars/infobar_service.h" | 32 #include "chrome/browser/infobars/infobar_service.h" |
29 #include "components/infobars/core/confirm_infobar_delegate.h" | 33 #include "components/infobars/core/confirm_infobar_delegate.h" |
30 #include "components/infobars/core/infobar.h" | 34 #include "components/infobars/core/infobar.h" |
31 #else | 35 #else |
32 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 36 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
33 #endif | 37 #endif |
34 | 38 |
35 namespace { | 39 namespace { |
36 | 40 |
37 // If the site requested larger quota than this threshold, show a different | 41 // If the site requested larger quota than this threshold, show a different |
38 // message to the user. | 42 // message to the user. |
39 const int64 kRequestLargeQuotaThreshold = 5 * 1024 * 1024; | 43 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024; |
40 | 44 |
41 // QuotaPermissionRequest --------------------------------------------- | 45 // QuotaPermissionRequest --------------------------------------------- |
42 | 46 |
43 class QuotaPermissionRequest : public PermissionBubbleRequest { | 47 class QuotaPermissionRequest : public PermissionBubbleRequest { |
44 public: | 48 public: |
45 QuotaPermissionRequest( | 49 QuotaPermissionRequest( |
46 ChromeQuotaPermissionContext* context, | 50 ChromeQuotaPermissionContext* context, |
47 const GURL& origin_url, | 51 const GURL& origin_url, |
48 int64 requested_quota, | 52 int64_t requested_quota, |
49 bool user_gesture, | 53 bool user_gesture, |
50 const std::string& display_languages, | 54 const std::string& display_languages, |
51 const content::QuotaPermissionContext::PermissionCallback& callback); | 55 const content::QuotaPermissionContext::PermissionCallback& callback); |
52 | 56 |
53 ~QuotaPermissionRequest() override; | 57 ~QuotaPermissionRequest() override; |
54 | 58 |
55 // PermissionBubbleRequest: | 59 // PermissionBubbleRequest: |
56 int GetIconId() const override; | 60 int GetIconId() const override; |
57 base::string16 GetMessageText() const override; | 61 base::string16 GetMessageText() const override; |
58 base::string16 GetMessageTextFragment() const override; | 62 base::string16 GetMessageTextFragment() const override; |
59 bool HasUserGesture() const override; | 63 bool HasUserGesture() const override; |
60 GURL GetRequestingHostname() const override; | 64 GURL GetRequestingHostname() const override; |
61 void PermissionGranted() override; | 65 void PermissionGranted() override; |
62 void PermissionDenied() override; | 66 void PermissionDenied() override; |
63 void Cancelled() override; | 67 void Cancelled() override; |
64 void RequestFinished() override; | 68 void RequestFinished() override; |
65 | 69 |
66 private: | 70 private: |
67 scoped_refptr<ChromeQuotaPermissionContext> context_; | 71 scoped_refptr<ChromeQuotaPermissionContext> context_; |
68 GURL origin_url_; | 72 GURL origin_url_; |
69 std::string display_languages_; | 73 std::string display_languages_; |
70 int64 requested_quota_; | 74 int64_t requested_quota_; |
71 bool user_gesture_; | 75 bool user_gesture_; |
72 content::QuotaPermissionContext::PermissionCallback callback_; | 76 content::QuotaPermissionContext::PermissionCallback callback_; |
73 | 77 |
74 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); | 78 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); |
75 }; | 79 }; |
76 | 80 |
77 QuotaPermissionRequest::QuotaPermissionRequest( | 81 QuotaPermissionRequest::QuotaPermissionRequest( |
78 ChromeQuotaPermissionContext* context, | 82 ChromeQuotaPermissionContext* context, |
79 const GURL& origin_url, | 83 const GURL& origin_url, |
80 int64 requested_quota, | 84 int64_t requested_quota, |
81 bool user_gesture, | 85 bool user_gesture, |
82 const std::string& display_languages, | 86 const std::string& display_languages, |
83 const content::QuotaPermissionContext::PermissionCallback& callback) | 87 const content::QuotaPermissionContext::PermissionCallback& callback) |
84 : context_(context), | 88 : context_(context), |
85 origin_url_(origin_url), | 89 origin_url_(origin_url), |
86 display_languages_(display_languages), | 90 display_languages_(display_languages), |
87 requested_quota_(requested_quota), | 91 requested_quota_(requested_quota), |
88 user_gesture_(user_gesture), | 92 user_gesture_(user_gesture), |
89 callback_(callback) {} | 93 callback_(callback) {} |
90 | 94 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // RequestQuotaInfoBarDelegate ------------------------------------------------ | 151 // RequestQuotaInfoBarDelegate ------------------------------------------------ |
148 | 152 |
149 class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { | 153 class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { |
150 public: | 154 public: |
151 // Creates a request quota infobar and delegate and adds the infobar to | 155 // Creates a request quota infobar and delegate and adds the infobar to |
152 // |infobar_service|. | 156 // |infobar_service|. |
153 static void Create( | 157 static void Create( |
154 InfoBarService* infobar_service, | 158 InfoBarService* infobar_service, |
155 ChromeQuotaPermissionContext* context, | 159 ChromeQuotaPermissionContext* context, |
156 const GURL& origin_url, | 160 const GURL& origin_url, |
157 int64 requested_quota, | 161 int64_t requested_quota, |
158 const std::string& display_languages, | 162 const std::string& display_languages, |
159 const content::QuotaPermissionContext::PermissionCallback& callback); | 163 const content::QuotaPermissionContext::PermissionCallback& callback); |
160 | 164 |
161 private: | 165 private: |
162 RequestQuotaInfoBarDelegate( | 166 RequestQuotaInfoBarDelegate( |
163 ChromeQuotaPermissionContext* context, | 167 ChromeQuotaPermissionContext* context, |
164 const GURL& origin_url, | 168 const GURL& origin_url, |
165 int64 requested_quota, | 169 int64_t requested_quota, |
166 const std::string& display_languages, | 170 const std::string& display_languages, |
167 const content::QuotaPermissionContext::PermissionCallback& callback); | 171 const content::QuotaPermissionContext::PermissionCallback& callback); |
168 ~RequestQuotaInfoBarDelegate() override; | 172 ~RequestQuotaInfoBarDelegate() override; |
169 | 173 |
170 // ConfirmInfoBarDelegate: | 174 // ConfirmInfoBarDelegate: |
171 base::string16 GetMessageText() const override; | 175 base::string16 GetMessageText() const override; |
172 bool Accept() override; | 176 bool Accept() override; |
173 bool Cancel() override; | 177 bool Cancel() override; |
174 | 178 |
175 scoped_refptr<ChromeQuotaPermissionContext> context_; | 179 scoped_refptr<ChromeQuotaPermissionContext> context_; |
176 GURL origin_url_; | 180 GURL origin_url_; |
177 std::string display_languages_; | 181 std::string display_languages_; |
178 int64 requested_quota_; | 182 int64_t requested_quota_; |
179 content::QuotaPermissionContext::PermissionCallback callback_; | 183 content::QuotaPermissionContext::PermissionCallback callback_; |
180 | 184 |
181 DISALLOW_COPY_AND_ASSIGN(RequestQuotaInfoBarDelegate); | 185 DISALLOW_COPY_AND_ASSIGN(RequestQuotaInfoBarDelegate); |
182 }; | 186 }; |
183 | 187 |
184 // static | 188 // static |
185 void RequestQuotaInfoBarDelegate::Create( | 189 void RequestQuotaInfoBarDelegate::Create( |
186 InfoBarService* infobar_service, | 190 InfoBarService* infobar_service, |
187 ChromeQuotaPermissionContext* context, | 191 ChromeQuotaPermissionContext* context, |
188 const GURL& origin_url, | 192 const GURL& origin_url, |
189 int64 requested_quota, | 193 int64_t requested_quota, |
190 const std::string& display_languages, | 194 const std::string& display_languages, |
191 const content::QuotaPermissionContext::PermissionCallback& callback) { | 195 const content::QuotaPermissionContext::PermissionCallback& callback) { |
192 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | 196 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
193 scoped_ptr<ConfirmInfoBarDelegate>(new RequestQuotaInfoBarDelegate( | 197 scoped_ptr<ConfirmInfoBarDelegate>(new RequestQuotaInfoBarDelegate( |
194 context, origin_url, requested_quota, display_languages, callback)))); | 198 context, origin_url, requested_quota, display_languages, callback)))); |
195 } | 199 } |
196 | 200 |
197 RequestQuotaInfoBarDelegate::RequestQuotaInfoBarDelegate( | 201 RequestQuotaInfoBarDelegate::RequestQuotaInfoBarDelegate( |
198 ChromeQuotaPermissionContext* context, | 202 ChromeQuotaPermissionContext* context, |
199 const GURL& origin_url, | 203 const GURL& origin_url, |
200 int64 requested_quota, | 204 int64_t requested_quota, |
201 const std::string& display_languages, | 205 const std::string& display_languages, |
202 const content::QuotaPermissionContext::PermissionCallback& callback) | 206 const content::QuotaPermissionContext::PermissionCallback& callback) |
203 : ConfirmInfoBarDelegate(), | 207 : ConfirmInfoBarDelegate(), |
204 context_(context), | 208 context_(context), |
205 origin_url_(origin_url), | 209 origin_url_(origin_url), |
206 display_languages_(display_languages), | 210 display_languages_(display_languages), |
207 requested_quota_(requested_quota), | 211 requested_quota_(requested_quota), |
208 callback_(callback) { | 212 callback_(callback) {} |
209 } | |
210 | 213 |
211 RequestQuotaInfoBarDelegate::~RequestQuotaInfoBarDelegate() { | 214 RequestQuotaInfoBarDelegate::~RequestQuotaInfoBarDelegate() { |
212 if (!callback_.is_null()) { | 215 if (!callback_.is_null()) { |
213 context_->DispatchCallbackOnIOThread( | 216 context_->DispatchCallbackOnIOThread( |
214 callback_, | 217 callback_, |
215 content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED); | 218 content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED); |
216 } | 219 } |
217 } | 220 } |
218 | 221 |
219 base::string16 RequestQuotaInfoBarDelegate::GetMessageText() const { | 222 base::string16 RequestQuotaInfoBarDelegate::GetMessageText() const { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 content::BrowserThread::IO, FROM_HERE, | 324 content::BrowserThread::IO, FROM_HERE, |
322 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, | 325 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, |
323 this, callback, response)); | 326 this, callback, response)); |
324 return; | 327 return; |
325 } | 328 } |
326 | 329 |
327 callback.Run(response); | 330 callback.Run(response); |
328 } | 331 } |
329 | 332 |
330 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} | 333 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} |
OLD | NEW |