summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-31 06:53:41 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-31 06:53:41 +0000
commit317f96c98a5a2da64db09d7f717fbadd0586e786 (patch)
tree73b8dc4cf66e294a93759da3b73eca1b6345adca /chrome
parentb93a206d2157e787fe522f4e21920e293f52e91f (diff)
downloadchromium_src-317f96c98a5a2da64db09d7f717fbadd0586e786.zip
chromium_src-317f96c98a5a2da64db09d7f717fbadd0586e786.tar.gz
chromium_src-317f96c98a5a2da64db09d7f717fbadd0586e786.tar.bz2
Quota InfoBar
For persistent storage request we need to show 'request quota' infoBar if the requested storage size (or requested new quota size) is greater than the current quota, and to show an infoBar we need to let the browser know which render view is requesting the storage. This patch includes necessary plumbing to send render process_id/view_id to the browser process and the info bar implementation itself. BUG=61676 TEST=none Review URL: http://codereview.chromium.org/6976026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87275 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/generated_resources.grd12
-rw-r--r--chrome/browser/chrome_content_browser_client.cc6
-rw-r--r--chrome/browser/chrome_content_browser_client.h3
-rw-r--r--chrome/browser/chrome_quota_permission_context.cc166
-rw-r--r--chrome/browser/chrome_quota_permission_context.h30
-rw-r--r--chrome/chrome_browser.gypi2
6 files changed, 219 insertions, 0 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 178df33..c43488e 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -12592,6 +12592,18 @@ Keep your key file in a safe place. You will need it to create new versions of y
Report abuse
</message>
+ <!-- Quota messages -->
+ <message name="IDS_REQUEST_QUOTA_INFOBAR_QUESTION" desc="Question asked on the info bar whenever webapp requests new (larger) quota to persistently store data on the user's local computer (e.g. for persistent-type filesystem).">
+ <ph name="URL">
+ $1<ex>html5rocks.com</ex>
+ </ph> wants to permanently store data on your local computer.
+ </message>
+ <message name="IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION" desc="Question asked on the info bar whenever webapp requests new (larger) quota to persistently store large data on the user's local computer (e.g. for persistent-type filesystem).">
+ <ph name="URL">
+ $1<ex>html5rocks.com</ex>
+ </ph> wants to permanently store large data on your local computer.
+ </message>
+
</messages>
<includes>
<if expr="pp_ifdef('_google_chrome')">
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index 3204252..d6dcc57 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/character_encoding.h"
#include "chrome/browser/chrome_plugin_message_filter.h"
+#include "chrome/browser/chrome_quota_permission_context.h"
#include "chrome/browser/chrome_worker_message_filter.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
@@ -304,6 +305,11 @@ bool ChromeContentBrowserClient::AllowSetCookie(
return allow;
}
+QuotaPermissionContext*
+ChromeContentBrowserClient::CreateQuotaPermissionContext() {
+ return new ChromeQuotaPermissionContext();
+}
+
#if defined(OS_LINUX)
int ChromeContentBrowserClient::GetCrashSignalFD(
const std::string& process_type) {
diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h
index bd41834..33bcb65 100644
--- a/chrome/browser/chrome_content_browser_client.h
+++ b/chrome/browser/chrome_content_browser_client.h
@@ -8,6 +8,8 @@
#include "content/browser/content_browser_client.h"
+class QuotaPermissionContext;
+
namespace chrome {
class ChromeContentBrowserClient : public content::ContentBrowserClient {
@@ -40,6 +42,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
int render_process_id,
int render_view_id,
net::CookieOptions* options);
+ virtual QuotaPermissionContext* CreateQuotaPermissionContext();
#if defined(OS_POSIX) && !defined(OS_MACOSX)
// Can return an optional fd for crash handling, otherwise returns -1.
virtual int GetCrashSignalFD(const std::string& process_type);
diff --git a/chrome/browser/chrome_quota_permission_context.cc b/chrome/browser/chrome_quota_permission_context.cc
new file mode 100644
index 0000000..f5de89d
--- /dev/null
+++ b/chrome/browser/chrome_quota_permission_context.cc
@@ -0,0 +1,166 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chrome_quota_permission_context.h"
+
+#include <string>
+
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
+#include "chrome/browser/tab_contents/tab_util.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/common/pref_names.h"
+#include "content/browser/browser_thread.h"
+#include "content/browser/tab_contents/navigation_controller.h"
+#include "content/browser/tab_contents/tab_contents.h"
+#include "googleurl/src/gurl.h"
+#include "grit/generated_resources.h"
+#include "grit/locale_settings.h"
+#include "net/base/net_util.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "webkit/quota/quota_types.h"
+
+namespace {
+
+// If we requested larger quota than this threshold, show a different
+// message to the user.
+const int64 kRequestLargeQuotaThreshold = 5 * 1024 * 1024;
+
+class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate {
+ public:
+ typedef QuotaPermissionContext::PermissionCallback PermissionCallback;
+
+ RequestQuotaInfoBarDelegate(
+ TabContents* tab_contents,
+ ChromeQuotaPermissionContext* context,
+ const GURL& origin_url,
+ int64 requested_quota,
+ const std::string& display_languages,
+ PermissionCallback* callback)
+ : ConfirmInfoBarDelegate(tab_contents),
+ context_(context),
+ origin_url_(origin_url),
+ display_languages_(display_languages),
+ requested_quota_(requested_quota),
+ callback_(callback) {}
+
+ private:
+ virtual ~RequestQuotaInfoBarDelegate() {
+ // Make sure we've dispatched the callback.
+ DCHECK(!callback_.get());
+ }
+
+ virtual bool ShouldExpire(
+ const NavigationController::LoadCommittedDetails& details)
+ const OVERRIDE {
+ return false;
+ }
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual void InfoBarDismissed() OVERRIDE;
+ virtual bool Accept() OVERRIDE;
+ virtual bool Cancel() OVERRIDE;
+
+ scoped_refptr<ChromeQuotaPermissionContext> context_;
+ GURL origin_url_;
+ std::string display_languages_;
+ int64 requested_quota_;
+ scoped_ptr<PermissionCallback> callback_;
+ DISALLOW_COPY_AND_ASSIGN(RequestQuotaInfoBarDelegate);
+};
+
+void RequestQuotaInfoBarDelegate::InfoBarDismissed() {
+ context_->DispatchCallbackOnIOThread(
+ callback_.release(), QuotaPermissionContext::kResponseCancelled);
+}
+
+string16 RequestQuotaInfoBarDelegate::GetMessageText() const {
+ return l10n_util::GetStringFUTF16(
+ (requested_quota_ > kRequestLargeQuotaThreshold ?
+ IDS_REQUEST_LARGE_QUOTA_INFOBAR_QUESTION :
+ IDS_REQUEST_QUOTA_INFOBAR_QUESTION),
+ net::FormatUrl(origin_url_, display_languages_));
+}
+
+bool RequestQuotaInfoBarDelegate::Accept() {
+ context_->DispatchCallbackOnIOThread(
+ callback_.release(), QuotaPermissionContext::kResponseAllow);
+ return true;
+}
+
+bool RequestQuotaInfoBarDelegate::Cancel() {
+ context_->DispatchCallbackOnIOThread(
+ callback_.release(), QuotaPermissionContext::kResponseCancelled);
+ return true;
+}
+
+} // anonymous namespace
+
+ChromeQuotaPermissionContext::ChromeQuotaPermissionContext() {
+}
+
+ChromeQuotaPermissionContext::~ChromeQuotaPermissionContext() {
+}
+
+void ChromeQuotaPermissionContext::RequestQuotaPermission(
+ const GURL& origin_url,
+ quota::StorageType type,
+ int64 requested_quota,
+ int render_process_id,
+ int render_view_id,
+ PermissionCallback* callback_ptr) {
+ scoped_ptr<PermissionCallback> callback(callback_ptr);
+ if (type != quota::kStorageTypePersistent) {
+ // For now we only support requesting quota with this interface
+ // for Persistent storage type.
+ callback->Run(kResponseDisallow);
+ return;
+ }
+
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &ChromeQuotaPermissionContext::RequestQuotaPermission,
+ origin_url, type, requested_quota,
+ render_process_id, render_view_id, callback.release()));
+ return;
+ }
+
+ TabContents* tab_contents =
+ tab_util::GetTabContentsByID(render_process_id, render_view_id);
+ if (!tab_contents) {
+ // The tab may have gone away or the request may not be from a tab.
+ LOG(WARNING) << "Attempt to request quota tabless renderer: "
+ << render_process_id << "," << render_view_id;
+ DispatchCallbackOnIOThread(callback.release(), kResponseCancelled);
+ return;
+ }
+
+ TabContentsWrapper* wrapper =
+ TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
+ wrapper->AddInfoBar(new RequestQuotaInfoBarDelegate(
+ tab_contents, this,
+ origin_url, requested_quota,
+ tab_contents->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
+ callback.release()));
+}
+
+void ChromeQuotaPermissionContext::DispatchCallbackOnIOThread(
+ PermissionCallback* callback_ptr,
+ Response response) {
+ DCHECK(callback_ptr);
+ scoped_ptr<PermissionCallback> callback(callback_ptr);
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this, &ChromeQuotaPermissionContext::DispatchCallbackOnIOThread,
+ callback.release(), response));
+ return;
+ }
+ callback->Run(response);
+}
diff --git a/chrome/browser/chrome_quota_permission_context.h b/chrome/browser/chrome_quota_permission_context.h
new file mode 100644
index 0000000..5bfdbcc
--- /dev/null
+++ b/chrome/browser/chrome_quota_permission_context.h
@@ -0,0 +1,30 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROME_QUOTA_PERMISSION_CONTEXT_H_
+#define CHROME_BROWSER_CHROME_QUOTA_PERMISSION_CONTEXT_H_
+
+#include "base/compiler_specific.h"
+#include "content/browser/quota_permission_context.h"
+
+class ChromeQuotaPermissionContext : public QuotaPermissionContext {
+ public:
+ ChromeQuotaPermissionContext();
+ virtual ~ChromeQuotaPermissionContext();
+
+ // The callback will be dispatched on the IO thread.
+ virtual void RequestQuotaPermission(
+ const GURL& origin_url,
+ quota::StorageType type,
+ int64 new_quota,
+ int render_process_id,
+ int render_view_id,
+ PermissionCallback* callback) OVERRIDE;
+
+ void DispatchCallbackOnIOThread(
+ PermissionCallback* callback,
+ Response response);
+};
+
+#endif // CHROME_BROWSER_CHROME_QUOTA_PERMISSION_CONTEXT_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 2f56439..990c747 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -353,6 +353,8 @@
'browser/chrome_content_browser_client.h',
'browser/chrome_plugin_message_filter.cc',
'browser/chrome_plugin_message_filter.h',
+ 'browser/chrome_quota_permission_context.cc',
+ 'browser/chrome_quota_permission_context.h',
'browser/chrome_worker_message_filter.cc',
'browser/chrome_worker_message_filter.h',
'browser/chromeos/audio_handler.cc',