Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/browser/chrome_quota_permission_context.cc

Issue 1841653003: Drop |languages| from {Format,Elide}Url* and IDNToUnicode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo in elide_url.cc Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/tab_contents/tab_util.h" 16 #include "chrome/browser/tab_contents/tab_util.h"
17 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" 17 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
18 #include "chrome/common/pref_names.h"
19 #include "chrome/grit/generated_resources.h" 18 #include "chrome/grit/generated_resources.h"
20 #include "chrome/grit/locale_settings.h" 19 #include "chrome/grit/locale_settings.h"
21 #include "components/prefs/pref_service.h"
22 #include "components/url_formatter/elide_url.h" 20 #include "components/url_formatter/elide_url.h"
23 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/navigation_details.h" 22 #include "content/public/browser/navigation_details.h"
25 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
26 #include "grit/theme_resources.h" 24 #include "grit/theme_resources.h"
27 #include "storage/common/quota/quota_types.h" 25 #include "storage/common/quota/quota_types.h"
28 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
29 #include "url/gurl.h" 27 #include "url/gurl.h"
30 28
31 #if defined(OS_ANDROID) 29 #if defined(OS_ANDROID)
(...skipping 11 matching lines...) Expand all
43 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024; 41 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024;
44 42
45 // QuotaPermissionRequest --------------------------------------------- 43 // QuotaPermissionRequest ---------------------------------------------
46 44
47 class QuotaPermissionRequest : public PermissionBubbleRequest { 45 class QuotaPermissionRequest : public PermissionBubbleRequest {
48 public: 46 public:
49 QuotaPermissionRequest( 47 QuotaPermissionRequest(
50 ChromeQuotaPermissionContext* context, 48 ChromeQuotaPermissionContext* context,
51 const GURL& origin_url, 49 const GURL& origin_url,
52 int64_t requested_quota, 50 int64_t requested_quota,
53 const std::string& display_languages,
54 const content::QuotaPermissionContext::PermissionCallback& callback); 51 const content::QuotaPermissionContext::PermissionCallback& callback);
55 52
56 ~QuotaPermissionRequest() override; 53 ~QuotaPermissionRequest() override;
57 54
58 // PermissionBubbleRequest: 55 // PermissionBubbleRequest:
59 int GetIconId() const override; 56 int GetIconId() const override;
60 base::string16 GetMessageText() const override; 57 base::string16 GetMessageText() const override;
61 base::string16 GetMessageTextFragment() const override; 58 base::string16 GetMessageTextFragment() const override;
62 GURL GetOrigin() const override; 59 GURL GetOrigin() const override;
63 void PermissionGranted() override; 60 void PermissionGranted() override;
64 void PermissionDenied() override; 61 void PermissionDenied() override;
65 void Cancelled() override; 62 void Cancelled() override;
66 void RequestFinished() override; 63 void RequestFinished() override;
67 64
68 private: 65 private:
69 scoped_refptr<ChromeQuotaPermissionContext> context_; 66 scoped_refptr<ChromeQuotaPermissionContext> context_;
70 GURL origin_url_; 67 GURL origin_url_;
71 std::string display_languages_;
72 int64_t requested_quota_; 68 int64_t requested_quota_;
73 content::QuotaPermissionContext::PermissionCallback callback_; 69 content::QuotaPermissionContext::PermissionCallback callback_;
74 70
75 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest); 71 DISALLOW_COPY_AND_ASSIGN(QuotaPermissionRequest);
76 }; 72 };
77 73
78 QuotaPermissionRequest::QuotaPermissionRequest( 74 QuotaPermissionRequest::QuotaPermissionRequest(
79 ChromeQuotaPermissionContext* context, 75 ChromeQuotaPermissionContext* context,
80 const GURL& origin_url, 76 const GURL& origin_url,
81 int64_t requested_quota, 77 int64_t requested_quota,
82 const std::string& display_languages,
83 const content::QuotaPermissionContext::PermissionCallback& callback) 78 const content::QuotaPermissionContext::PermissionCallback& callback)
84 : context_(context), 79 : context_(context),
85 origin_url_(origin_url), 80 origin_url_(origin_url),
86 display_languages_(display_languages),
87 requested_quota_(requested_quota), 81 requested_quota_(requested_quota),
88 callback_(callback) {} 82 callback_(callback) {}
89 83
90 QuotaPermissionRequest::~QuotaPermissionRequest() {} 84 QuotaPermissionRequest::~QuotaPermissionRequest() {}
91 85
92 int QuotaPermissionRequest::GetIconId() const { 86 int QuotaPermissionRequest::GetIconId() const {
93 // TODO(gbillock): get the proper image here 87 // TODO(gbillock): get the proper image here
94 return IDR_INFOBAR_WARNING; 88 return IDR_INFOBAR_WARNING;
95 } 89 }
96 90
97 base::string16 QuotaPermissionRequest::GetMessageText() const { 91 base::string16 QuotaPermissionRequest::GetMessageText() const {
98 return l10n_util::GetStringFUTF16( 92 return l10n_util::GetStringFUTF16(
99 (requested_quota_ > kRequestLargeQuotaThreshold 93 (requested_quota_ > kRequestLargeQuotaThreshold
100 ? IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION 94 ? IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION
101 : IDS_REQUEST_QUOTA_INFOBAR_QUESTION), 95 : IDS_REQUEST_QUOTA_INFOBAR_QUESTION),
102 url_formatter::FormatUrlForSecurityDisplay(origin_url_, 96 url_formatter::FormatUrlForSecurityDisplay(origin_url_));
103 display_languages_));
104 } 97 }
105 98
106 base::string16 QuotaPermissionRequest::GetMessageTextFragment() const { 99 base::string16 QuotaPermissionRequest::GetMessageTextFragment() const {
107 return l10n_util::GetStringUTF16(IDS_REQUEST_QUOTA_PERMISSION_FRAGMENT); 100 return l10n_util::GetStringUTF16(IDS_REQUEST_QUOTA_PERMISSION_FRAGMENT);
108 } 101 }
109 102
110 GURL QuotaPermissionRequest::GetOrigin() const { 103 GURL QuotaPermissionRequest::GetOrigin() const {
111 return origin_url_; 104 return origin_url_;
112 } 105 }
113 106
(...skipping 29 matching lines...) Expand all
143 136
144 class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { 137 class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate {
145 public: 138 public:
146 // Creates a request quota infobar and delegate and adds the infobar to 139 // Creates a request quota infobar and delegate and adds the infobar to
147 // |infobar_service|. 140 // |infobar_service|.
148 static void Create( 141 static void Create(
149 InfoBarService* infobar_service, 142 InfoBarService* infobar_service,
150 ChromeQuotaPermissionContext* context, 143 ChromeQuotaPermissionContext* context,
151 const GURL& origin_url, 144 const GURL& origin_url,
152 int64_t requested_quota, 145 int64_t requested_quota,
153 const std::string& display_languages,
154 const content::QuotaPermissionContext::PermissionCallback& callback); 146 const content::QuotaPermissionContext::PermissionCallback& callback);
155 147
156 private: 148 private:
157 RequestQuotaInfoBarDelegate( 149 RequestQuotaInfoBarDelegate(
158 ChromeQuotaPermissionContext* context, 150 ChromeQuotaPermissionContext* context,
159 const GURL& origin_url, 151 const GURL& origin_url,
160 int64_t requested_quota, 152 int64_t requested_quota,
161 const std::string& display_languages,
162 const content::QuotaPermissionContext::PermissionCallback& callback); 153 const content::QuotaPermissionContext::PermissionCallback& callback);
163 ~RequestQuotaInfoBarDelegate() override; 154 ~RequestQuotaInfoBarDelegate() override;
164 155
165 // ConfirmInfoBarDelegate: 156 // ConfirmInfoBarDelegate:
166 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; 157 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
167 base::string16 GetMessageText() const override; 158 base::string16 GetMessageText() const override;
168 bool Accept() override; 159 bool Accept() override;
169 bool Cancel() override; 160 bool Cancel() override;
170 161
171 scoped_refptr<ChromeQuotaPermissionContext> context_; 162 scoped_refptr<ChromeQuotaPermissionContext> context_;
172 GURL origin_url_; 163 GURL origin_url_;
173 std::string display_languages_;
174 int64_t requested_quota_; 164 int64_t requested_quota_;
175 content::QuotaPermissionContext::PermissionCallback callback_; 165 content::QuotaPermissionContext::PermissionCallback callback_;
176 166
177 DISALLOW_COPY_AND_ASSIGN(RequestQuotaInfoBarDelegate); 167 DISALLOW_COPY_AND_ASSIGN(RequestQuotaInfoBarDelegate);
178 }; 168 };
179 169
180 // static 170 // static
181 void RequestQuotaInfoBarDelegate::Create( 171 void RequestQuotaInfoBarDelegate::Create(
182 InfoBarService* infobar_service, 172 InfoBarService* infobar_service,
183 ChromeQuotaPermissionContext* context, 173 ChromeQuotaPermissionContext* context,
184 const GURL& origin_url, 174 const GURL& origin_url,
185 int64_t requested_quota, 175 int64_t requested_quota,
186 const std::string& display_languages,
187 const content::QuotaPermissionContext::PermissionCallback& callback) { 176 const content::QuotaPermissionContext::PermissionCallback& callback) {
188 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( 177 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
189 scoped_ptr<ConfirmInfoBarDelegate>(new RequestQuotaInfoBarDelegate( 178 scoped_ptr<ConfirmInfoBarDelegate>(new RequestQuotaInfoBarDelegate(
190 context, origin_url, requested_quota, display_languages, callback)))); 179 context, origin_url, requested_quota, callback))));
191 } 180 }
192 181
193 RequestQuotaInfoBarDelegate::RequestQuotaInfoBarDelegate( 182 RequestQuotaInfoBarDelegate::RequestQuotaInfoBarDelegate(
194 ChromeQuotaPermissionContext* context, 183 ChromeQuotaPermissionContext* context,
195 const GURL& origin_url, 184 const GURL& origin_url,
196 int64_t requested_quota, 185 int64_t requested_quota,
197 const std::string& display_languages,
198 const content::QuotaPermissionContext::PermissionCallback& callback) 186 const content::QuotaPermissionContext::PermissionCallback& callback)
199 : ConfirmInfoBarDelegate(), 187 : ConfirmInfoBarDelegate(),
200 context_(context), 188 context_(context),
201 origin_url_(origin_url), 189 origin_url_(origin_url),
202 display_languages_(display_languages),
203 requested_quota_(requested_quota), 190 requested_quota_(requested_quota),
204 callback_(callback) {} 191 callback_(callback) {}
205 192
206 RequestQuotaInfoBarDelegate::~RequestQuotaInfoBarDelegate() { 193 RequestQuotaInfoBarDelegate::~RequestQuotaInfoBarDelegate() {
207 if (!callback_.is_null()) { 194 if (!callback_.is_null()) {
208 context_->DispatchCallbackOnIOThread( 195 context_->DispatchCallbackOnIOThread(
209 callback_, 196 callback_,
210 content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED); 197 content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED);
211 } 198 }
212 } 199 }
213 200
214 infobars::InfoBarDelegate::InfoBarIdentifier 201 infobars::InfoBarDelegate::InfoBarIdentifier
215 RequestQuotaInfoBarDelegate::GetIdentifier() const { 202 RequestQuotaInfoBarDelegate::GetIdentifier() const {
216 return REQUEST_QUOTA_INFOBAR_DELEGATE; 203 return REQUEST_QUOTA_INFOBAR_DELEGATE;
217 } 204 }
218 205
219 base::string16 RequestQuotaInfoBarDelegate::GetMessageText() const { 206 base::string16 RequestQuotaInfoBarDelegate::GetMessageText() const {
220 // If the site requested larger quota than this threshold, show a different 207 // If the site requested larger quota than this threshold, show a different
221 // message to the user. 208 // message to the user.
222 return l10n_util::GetStringFUTF16( 209 return l10n_util::GetStringFUTF16(
223 (requested_quota_ > kRequestLargeQuotaThreshold 210 (requested_quota_ > kRequestLargeQuotaThreshold
224 ? IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION 211 ? IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION
225 : IDS_REQUEST_QUOTA_INFOBAR_QUESTION), 212 : IDS_REQUEST_QUOTA_INFOBAR_QUESTION),
226 url_formatter::FormatUrlForSecurityDisplay(origin_url_, 213 url_formatter::FormatUrlForSecurityDisplay(origin_url_));
227 display_languages_));
228 } 214 }
229 215
230 bool RequestQuotaInfoBarDelegate::Accept() { 216 bool RequestQuotaInfoBarDelegate::Accept() {
231 context_->DispatchCallbackOnIOThread( 217 context_->DispatchCallbackOnIOThread(
232 callback_, 218 callback_,
233 content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_ALLOW); 219 content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_ALLOW);
234 return true; 220 return true;
235 } 221 }
236 222
237 bool RequestQuotaInfoBarDelegate::Cancel() { 223 bool RequestQuotaInfoBarDelegate::Cancel() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); 265 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED);
280 return; 266 return;
281 } 267 }
282 268
283 #if defined(OS_ANDROID) 269 #if defined(OS_ANDROID)
284 InfoBarService* infobar_service = 270 InfoBarService* infobar_service =
285 InfoBarService::FromWebContents(web_contents); 271 InfoBarService::FromWebContents(web_contents);
286 if (infobar_service) { 272 if (infobar_service) {
287 RequestQuotaInfoBarDelegate::Create( 273 RequestQuotaInfoBarDelegate::Create(
288 infobar_service, this, params.origin_url, params.requested_size, 274 infobar_service, this, params.origin_url, params.requested_size,
289 Profile::FromBrowserContext(web_contents->GetBrowserContext())->
290 GetPrefs()->GetString(prefs::kAcceptLanguages),
291 callback); 275 callback);
292 return; 276 return;
293 } 277 }
294 #else 278 #else
295 PermissionBubbleManager* bubble_manager = 279 PermissionBubbleManager* bubble_manager =
296 PermissionBubbleManager::FromWebContents(web_contents); 280 PermissionBubbleManager::FromWebContents(web_contents);
297 if (bubble_manager) { 281 if (bubble_manager) {
298 bubble_manager->AddRequest(new QuotaPermissionRequest( 282 bubble_manager->AddRequest(new QuotaPermissionRequest(
299 this, params.origin_url, params.requested_size, 283 this, params.origin_url, params.requested_size, callback));
300 Profile::FromBrowserContext(web_contents->GetBrowserContext())
301 ->GetPrefs()
302 ->GetString(prefs::kAcceptLanguages),
303 callback));
304 return; 284 return;
305 } 285 }
306 #endif 286 #endif
307 287
308 // The tab has no UI service for presenting the permissions request. 288 // The tab has no UI service for presenting the permissions request.
309 LOG(WARNING) << "Attempt to request quota from a background page: " 289 LOG(WARNING) << "Attempt to request quota from a background page: "
310 << render_process_id << "," << params.render_view_id; 290 << render_process_id << "," << params.render_view_id;
311 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); 291 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED);
312 } 292 }
313 293
314 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( 294 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread(
315 const PermissionCallback& callback, 295 const PermissionCallback& callback,
316 QuotaPermissionResponse response) { 296 QuotaPermissionResponse response) {
317 DCHECK_EQ(false, callback.is_null()); 297 DCHECK_EQ(false, callback.is_null());
318 298
319 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { 299 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) {
320 content::BrowserThread::PostTask( 300 content::BrowserThread::PostTask(
321 content::BrowserThread::IO, FROM_HERE, 301 content::BrowserThread::IO, FROM_HERE,
322 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, 302 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread,
323 this, callback, response)); 303 this, callback, response));
324 return; 304 return;
325 } 305 }
326 306
327 callback.Run(response); 307 callback.Run(response);
328 } 308 }
329 309
330 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} 310 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698