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

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

Issue 2703253005: Support PermissionRequestManager for quota permissions on Android. (Closed)
Patch Set: add a test Created 3 years, 9 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/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/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/tab_contents/tab_util.h" 18 #include "chrome/browser/tab_contents/tab_util.h"
18 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
19 #include "chrome/grit/locale_settings.h" 20 #include "chrome/grit/locale_settings.h"
20 #include "components/url_formatter/elide_url.h" 21 #include "components/url_formatter/elide_url.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/navigation_details.h" 23 #include "content/public/browser/navigation_details.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.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"
33 #else 34 #else
34 #include "chrome/browser/permissions/permission_request_manager.h"
35 #include "ui/vector_icons/vector_icons.h" 35 #include "ui/vector_icons/vector_icons.h"
36 #endif 36 #endif
37 37
38 namespace { 38 namespace {
39 39
40 #if defined(OS_ANDROID) 40 #if defined(OS_ANDROID)
41 // 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
42 // message to the user. 42 // message to the user.
43 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024; 43 const int64_t kRequestLargeQuotaThreshold = 5 * 1024 * 1024;
44 #endif 44 #endif
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID( 257 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID(
258 render_process_id, params.render_frame_id); 258 render_process_id, params.render_frame_id);
259 if (!web_contents) { 259 if (!web_contents) {
260 // The tab may have gone away or the request may not be from a tab. 260 // The tab may have gone away or the request may not be from a tab.
261 LOG(WARNING) << "Attempt to request quota tabless renderer: " 261 LOG(WARNING) << "Attempt to request quota tabless renderer: "
262 << render_process_id << "," << params.render_frame_id; 262 << render_process_id << "," << params.render_frame_id;
263 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); 263 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED);
264 return; 264 return;
265 } 265 }
266 266
267 if (PermissionRequestManager::IsEnabled()) {
268 PermissionRequestManager* permission_request_manager =
269 PermissionRequestManager::FromWebContents(web_contents);
270 if (permission_request_manager) {
271 permission_request_manager->AddRequest(
272 new QuotaPermissionRequest(this, params.origin_url, callback));
273 return;
274 }
267 #if defined(OS_ANDROID) 275 #if defined(OS_ANDROID)
268 InfoBarService* infobar_service = 276 } else {
269 InfoBarService::FromWebContents(web_contents); 277 InfoBarService* infobar_service =
270 if (infobar_service) { 278 InfoBarService::FromWebContents(web_contents);
271 RequestQuotaInfoBarDelegate::Create( 279 if (infobar_service) {
272 infobar_service, this, params.origin_url, params.requested_size, 280 RequestQuotaInfoBarDelegate::Create(infobar_service, this,
273 callback); 281 params.origin_url,
274 return; 282 params.requested_size, callback);
283 return;
284 }
285 #endif
275 } 286 }
276 #else
277 PermissionRequestManager* permission_request_manager =
278 PermissionRequestManager::FromWebContents(web_contents);
279 if (permission_request_manager) {
280 permission_request_manager->AddRequest(
281 new QuotaPermissionRequest(this, params.origin_url, callback));
282 return;
283 }
284 #endif
285 287
286 // The tab has no UI service for presenting the permissions request. 288 // The tab has no UI service for presenting the permissions request.
287 LOG(WARNING) << "Attempt to request quota from a background page: " 289 LOG(WARNING) << "Attempt to request quota from a background page: "
288 << render_process_id << "," << params.render_frame_id; 290 << render_process_id << "," << params.render_frame_id;
289 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED); 291 DispatchCallbackOnIOThread(callback, QUOTA_PERMISSION_RESPONSE_CANCELLED);
290 } 292 }
291 293
292 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread( 294 void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread(
293 const PermissionCallback& callback, 295 const PermissionCallback& callback,
294 QuotaPermissionResponse response) { 296 QuotaPermissionResponse response) {
295 DCHECK_EQ(false, callback.is_null()); 297 DCHECK_EQ(false, callback.is_null());
296 298
297 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { 299 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) {
298 content::BrowserThread::PostTask( 300 content::BrowserThread::PostTask(
299 content::BrowserThread::IO, FROM_HERE, 301 content::BrowserThread::IO, FROM_HERE,
300 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread, 302 base::Bind(&ChromeQuotaPermissionContext::DispatchCallbackOnIOThread,
301 this, callback, response)); 303 this, callback, response));
302 return; 304 return;
303 } 305 }
304 306
305 callback.Run(response); 307 callback.Run(response);
306 } 308 }
307 309
308 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {} 310 ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698