summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-19 13:19:57 +0000
committerbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-19 13:19:57 +0000
commit6e14e4f148f308917dc5de8b09e6307e851a39a1 (patch)
tree5e162017ee13a1cfc35fc38372c09eebab086517 /chrome
parent8bc90e59bad05168abc098d6068df109a650a011 (diff)
downloadchromium_src-6e14e4f148f308917dc5de8b09e6307e851a39a1.zip
chromium_src-6e14e4f148f308917dc5de8b09e6307e851a39a1.tar.gz
chromium_src-6e14e4f148f308917dc5de8b09e6307e851a39a1.tar.bz2
Uses GURL instead of host for requesting Geolocation permission.
Tidy up GeolocationPermissionContext. (in preparation for http://codereview.chromium.org/1033004). Review URL: http://codereview.chromium.org/1074004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42099 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/geolocation/geolocation_dispatcher_host.cc6
-rw-r--r--chrome/browser/geolocation/geolocation_dispatcher_host.h4
-rw-r--r--chrome/browser/geolocation/geolocation_permission_context.cc172
-rw-r--r--chrome/browser/geolocation/geolocation_permission_context.h45
-rw-r--r--chrome/common/render_messages_internal.h4
-rw-r--r--chrome/renderer/geolocation_dispatcher.cc4
6 files changed, 40 insertions, 195 deletions
diff --git a/chrome/browser/geolocation/geolocation_dispatcher_host.cc b/chrome/browser/geolocation/geolocation_dispatcher_host.cc
index 0e2ac79..71e61ff 100644
--- a/chrome/browser/geolocation/geolocation_dispatcher_host.cc
+++ b/chrome/browser/geolocation/geolocation_dispatcher_host.cc
@@ -88,15 +88,15 @@ void GeolocationDispatcherHost::OnUnregisterDispatcher(int render_view_id) {
}
void GeolocationDispatcherHost::OnRequestPermission(
- int render_view_id, int bridge_id, const std::string& host) {
+ int render_view_id, int bridge_id, const GURL& requesting_frame) {
LOG(INFO) << "permission request";
geolocation_permission_context_->RequestGeolocationPermission(
resource_message_filter_process_id_, render_view_id, bridge_id,
- host);
+ requesting_frame);
}
void GeolocationDispatcherHost::OnStartUpdating(
- int render_view_id, int bridge_id, const std::string& host,
+ int render_view_id, int bridge_id, const GURL& requesting_frame,
bool enable_high_accuracy) {
// WebKit sends the startupdating request before checking permissions, to
// optimize the no-location-available case.
diff --git a/chrome/browser/geolocation/geolocation_dispatcher_host.h b/chrome/browser/geolocation/geolocation_dispatcher_host.h
index feb1585..8fdec4d 100644
--- a/chrome/browser/geolocation/geolocation_dispatcher_host.h
+++ b/chrome/browser/geolocation/geolocation_dispatcher_host.h
@@ -43,9 +43,9 @@ class GeolocationDispatcherHost
void OnRegisterDispatcher(int render_view_id);
void OnUnregisterDispatcher(int render_view_id);
void OnRequestPermission(
- int render_view_id, int bridge_id, const std::string& host);
+ int render_view_id, int bridge_id, const GURL& requesting_frame);
void OnStartUpdating(
- int render_view_id, int bridge_id, const std::string& host,
+ int render_view_id, int bridge_id, const GURL& requesting_frame,
bool enable_high_accuracy);
void OnStopUpdating(int render_view_id, int bridge_id);
void OnSuspend(int render_view_id, int bridge_id);
diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc
index 2ff2f12..b8cb61f 100644
--- a/chrome/browser/geolocation/geolocation_permission_context.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context.cc
@@ -37,14 +37,14 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
GeolocationConfirmInfoBarDelegate(
TabContents* tab_contents, GeolocationPermissionContext* context,
int render_process_id, int render_view_id, int bridge_id,
- const std::string& host)
+ const GURL& requesting_frame_url)
: ConfirmInfoBarDelegate(tab_contents),
tab_contents_(tab_contents),
context_(context),
render_process_id_(render_process_id),
render_view_id_(render_view_id),
bridge_id_(bridge_id),
- host_(host) {
+ requesting_frame_url_(requesting_frame_url) {
}
// ConfirmInfoBarDelegate
@@ -67,7 +67,8 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
}
virtual std::wstring GetMessageText() const {
return l10n_util::GetStringF(
- IDS_GEOLOCATION_INFOBAR_QUESTION, UTF8ToWide(host_));
+ IDS_GEOLOCATION_INFOBAR_QUESTION,
+ UTF8ToWide(requesting_frame_url_.GetOrigin().spec()));
}
virtual SkBitmap* GetIcon() const {
return ResourceBundle::GetSharedInstance().GetBitmapNamed(
@@ -87,7 +88,8 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
private:
bool SetPermission(bool confirm) {
context_->SetPermission(
- render_process_id_, render_view_id_, bridge_id_, host_, confirm);
+ render_process_id_, render_view_id_, bridge_id_, requesting_frame_url_,
+ confirm);
return true;
}
@@ -96,70 +98,16 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
int render_process_id_;
int render_view_id_;
int bridge_id_;
- std::string host_;
+ GURL requesting_frame_url_;
DISALLOW_IMPLICIT_CONSTRUCTORS(GeolocationConfirmInfoBarDelegate);
};
-// TODO(bulach): use HostContentSettingsMap instead!
-FilePath::StringType StdStringToFilePathString(const std::string& std_string) {
-#if defined(OS_WIN)
- return UTF8ToWide(std_string);
-#else
- return std_string;
-#endif
-}
-
-// Returns true if permission was successfully read from file, and *allowed
-// be set accordingly.
-// Returns false otherwise.
-bool ReadPermissionFromFile(
- const std::string& host, const FilePath& permissions_path, bool* allowed) {
- DCHECK(allowed);
- *allowed = false;
- // TODO(bulach): this is probably wrong! is there any utility to convert a URL
- // to FilePath?
- FilePath permission_file(
- permissions_path.Append(StdStringToFilePathString(host)));
- if (!file_util::PathExists(permission_file))
- return false;
- JSONFileValueSerializer serializer(permission_file);
- scoped_ptr<Value> root_value(serializer.Deserialize(NULL));
- bool ret = root_value.get() &&
- root_value->GetType() == Value::TYPE_DICTIONARY;
- DictionaryValue* dictionary = static_cast<DictionaryValue*>(root_value.get());
- return ret &&
- dictionary->GetBoolean(kAllowedDictionaryKey, allowed);
-}
-
-void SavePermissionToFile(
- const std::string& host, const FilePath& permissions_path, bool allowed) {
-#if 0
- if (!file_util::DirectoryExists(permissions_path))
- file_util::CreateDirectory(permissions_path);
- // TODO(bulach): this is probably wrong! is there any utility to convert a URL
- // to FilePath?
- FilePath permission_file(
- permissions_path.Append(StdStringToFilePathString(
- host)));
- DictionaryValue dictionary;
- dictionary.SetBoolean(kAllowedDictionaryKey, allowed);
- std::string permission_data;
- JSONStringValueSerializer serializer(&permission_data);
- serializer.Serialize(dictionary);
- file_util::WriteFile(
- permission_file, permission_data.c_str(), permission_data.length());
-#endif // if 0
-}
-
} // namespace
GeolocationPermissionContext::GeolocationPermissionContext(
Profile* profile)
- : profile_(profile),
- is_off_the_record_(profile->IsOffTheRecord()),
- permissions_path_(profile->GetPath().Append(FilePath(
- kGeolocationPermissionPath))) {
+ : profile_(profile) {
}
GeolocationPermissionContext::~GeolocationPermissionContext() {
@@ -167,63 +115,27 @@ GeolocationPermissionContext::~GeolocationPermissionContext() {
void GeolocationPermissionContext::RequestGeolocationPermission(
int render_process_id, int render_view_id, int bridge_id,
- const std::string& host) {
+ const GURL& requesting_frame) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- std::map<std::string, bool>::const_iterator permission =
- permissions_.find(host);
- if (permission != permissions_.end()) {
- NotifyPermissionSet(
- render_process_id, render_view_id, bridge_id, permission->second);
- } else {
- HandlePermissionMemoryCacheMiss(
- render_process_id, render_view_id, bridge_id, host);
- }
+ RequestPermissionFromUI(render_process_id, render_view_id, bridge_id,
+ requesting_frame);
}
void GeolocationPermissionContext::SetPermission(
int render_process_id, int render_view_id, int bridge_id,
- const std::string& host, bool allowed) {
- SetPermissionMemoryCacheOnIOThread(host, allowed);
- SetPermissionOnFileThread(host, allowed);
+ const GURL& requesting_frame, bool allowed) {
NotifyPermissionSet(render_process_id, render_view_id, bridge_id, allowed);
}
-void GeolocationPermissionContext::HandlePermissionMemoryCacheMiss(
- int render_process_id, int render_view_id, int bridge_id,
- const std::string& host) {
- if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) {
- ChromeThread::PostTask(
- ChromeThread::FILE, FROM_HERE,
- NewRunnableMethod(
- this,
- &GeolocationPermissionContext::HandlePermissionMemoryCacheMiss,
- render_process_id, render_view_id, bridge_id, host));
- return;
- }
-
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
- // TODO(bulach): should we save a file per host or have some smarter
- // storage? Use HostContentSettingsMap instead.
- bool allowed;
- if (is_off_the_record_ ||
- !ReadPermissionFromFile(host, permissions_path_, &allowed)) {
- RequestPermissionFromUI(
- render_process_id, render_view_id, bridge_id, host);
- } else {
- SetPermissionMemoryCacheOnIOThread(host, allowed);
- NotifyPermissionSet(render_process_id, render_view_id, bridge_id, allowed);
- }
-}
-
void GeolocationPermissionContext::RequestPermissionFromUI(
int render_process_id, int render_view_id, int bridge_id,
- const std::string& host) {
+ const GURL& requesting_frame) {
if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(
- this, &GeolocationPermissionContext::RequestPermissionFromUI,
- render_process_id, render_view_id, bridge_id, host));
+ NewRunnableMethod(this,
+ &GeolocationPermissionContext::RequestPermissionFromUI,
+ render_process_id, render_view_id, bridge_id, requesting_frame));
return;
}
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
@@ -238,10 +150,8 @@ void GeolocationPermissionContext::RequestPermissionFromUI(
NotifyPermissionSet(render_process_id, render_view_id, bridge_id, false);
return;
}
- tab_contents->AddInfoBar(
- new GeolocationConfirmInfoBarDelegate(
- tab_contents, this, render_process_id, render_view_id,
- bridge_id, host));
+ tab_contents->AddInfoBar(new GeolocationConfirmInfoBarDelegate(tab_contents,
+ this, render_process_id, render_view_id, bridge_id, requesting_frame));
}
void GeolocationPermissionContext::NotifyPermissionSet(
@@ -249,8 +159,8 @@ void GeolocationPermissionContext::NotifyPermissionSet(
if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(
- this, &GeolocationPermissionContext::NotifyPermissionSet,
+ NewRunnableMethod(this,
+ &GeolocationPermissionContext::NotifyPermissionSet,
render_process_id, render_view_id, bridge_id, allowed));
return;
}
@@ -259,44 +169,6 @@ void GeolocationPermissionContext::NotifyPermissionSet(
CallRenderViewHost(
render_process_id, render_view_id,
&RenderViewHost::Send,
- new ViewMsg_Geolocation_PermissionSet(
- render_view_id, bridge_id, allowed));
-}
-
-void GeolocationPermissionContext::SetPermissionMemoryCacheOnIOThread(
- const std::string& host, bool allowed) {
- if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(
- this,
- &GeolocationPermissionContext::SetPermissionMemoryCacheOnIOThread,
- host, allowed));
- return;
- }
-
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- permissions_[host] = allowed;
-}
-
-void GeolocationPermissionContext::SetPermissionOnFileThread(
- const std::string& host, bool allowed) {
- if (is_off_the_record_)
- return;
- if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) {
- ChromeThread::PostTask(
- ChromeThread::FILE, FROM_HERE,
- NewRunnableMethod(
- this, &GeolocationPermissionContext::SetPermissionOnFileThread,
- host, allowed));
- return;
- }
-
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
-
- // TODO(bulach): should we save a file per host or have some smarter
- // storage? Use HostContentSettingsMap instead.
-#if 0
- SavePermissionToFile(host, permissions_path_, allowed);
-#endif
+ new ViewMsg_Geolocation_PermissionSet(render_view_id, bridge_id,
+ allowed));
}
diff --git a/chrome/browser/geolocation/geolocation_permission_context.h b/chrome/browser/geolocation/geolocation_permission_context.h
index 6b79fd75..6e387f1 100644
--- a/chrome/browser/geolocation/geolocation_permission_context.h
+++ b/chrome/browser/geolocation/geolocation_permission_context.h
@@ -11,15 +11,14 @@
#include "base/ref_counted.h"
class GeolocationDispatcherHost;
+class GURL;
class Profile;
class RenderViewHost;
-// GeolocationPermissionContext manages Geolocation permissions per host.
-// It keeps an in-memory cache of permissions, and if not available, loads
-// from disk. If there's no data, it'll trigger the UI elements to ask the
-// user for permission.
-// Regardless of where the permission data came from, it always notifies the
-// requesting render_view asynchronously via ViewMsg_Geolocation_PermissionSet.
+// GeolocationPermissionContext manages Geolocation permissions flow,
+// creating UI elements to ask the user for permission when necessary.
+// It always notifies the requesting render_view asynchronously via
+// ViewMsg_Geolocation_PermissionSet.
class GeolocationPermissionContext
: public base::RefCountedThreadSafe<GeolocationPermissionContext> {
public:
@@ -30,36 +29,22 @@ class GeolocationPermissionContext
// Must be called from the IO thread.
void RequestGeolocationPermission(
int render_process_id, int render_view_id, int bridge_id,
- const std::string& host);
+ const GURL& requesting_frame);
// Called once the user sets the geolocation permission.
- // It'll update the internal state on different threads via
- // SetPermissionMemoryCacheOnIOThread and SetPermissionOnFileThread.
+ // It'll notify the render via ViewMsg_Geolocation_PermissionSet.
void SetPermission(
int render_process_id, int render_view_id, int bridge_id,
- const std::string& host, bool allowed);
+ const GURL& requesting_frame, bool allowed);
private:
friend class base::RefCountedThreadSafe<GeolocationPermissionContext>;
virtual ~GeolocationPermissionContext();
- // This is initially called on the IO thread by the public API
- // RequestGeolocationPermission when there's no data available in the
- // in-memory cache.
- // It forwards a call to the FILE thread which tries to load permission data
- // from disk:
- // - If available, it will call SetPermissionMemoryCacheOnIOThread() to write
- // the in-memory cache in the IO thread, and NotifyPermissionSet to send the
- // message to the corresponding render.
- // - If not available, it'll delegate to RequestPermissionDataFromUI.
- void HandlePermissionMemoryCacheMiss(
- int render_process_id, int render_view_id, int bridge_id,
- const std::string& host);
-
// Triggers the associated UI element to request permission.
void RequestPermissionFromUI(
int render_process_id, int render_view_id, int bridge_id,
- const std::string& host);
+ const GURL& requesting_frame);
// Notifies whether or not the corresponding render is allowed to use
// geolocation.
@@ -67,20 +52,8 @@ class GeolocationPermissionContext
int render_process_id, int render_view_id, int bridge_id,
bool allowed);
- // Sets permissions_ cache (if not on IO thread, will forward to it).
- void SetPermissionMemoryCacheOnIOThread(
- const std::string& host, bool allowed);
- // Sets permissions file data (if not on FILE thread, will forward to it).
- void SetPermissionOnFileThread(const std::string& host, bool allowed);
-
// This should only be accessed from the UI thread.
Profile* const profile_;
- // Indicates whether profile_ is off the record.
- bool const is_off_the_record_;
- // The path where geolocation permission data is stored.
- FilePath const permissions_path_;
- // This should only be accessed from the UI thread.
- std::map<std::string, bool> permissions_;
DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContext);
};
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index b6ee2a4..c645104 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -2240,7 +2240,7 @@ IPC_BEGIN_MESSAGES(ViewHost)
IPC_MESSAGE_CONTROL3(ViewHostMsg_Geolocation_RequestPermission,
int /* render_view_id */,
int /* bridge_id */,
- std::string /* host of the page*/)
+ GURL /* GURL of the frame requesting geolocation */)
// The |render_view_id| and |bridge_id| requests Geolocation service to start
// updating.
@@ -2250,7 +2250,7 @@ IPC_BEGIN_MESSAGES(ViewHost)
IPC_MESSAGE_CONTROL4(ViewHostMsg_Geolocation_StartUpdating,
int /* render_view_id */,
int /* bridge_id */,
- std::string /* host */,
+ GURL /* GURL of the frame requesting geolocation */,
bool /* enable_high_accuracy */)
// The |render_view_id| and |bridge_id| requests Geolocation service to stop
diff --git a/chrome/renderer/geolocation_dispatcher.cc b/chrome/renderer/geolocation_dispatcher.cc
index f7f827f..227add0 100644
--- a/chrome/renderer/geolocation_dispatcher.cc
+++ b/chrome/renderer/geolocation_dispatcher.cc
@@ -39,13 +39,13 @@ bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) {
void GeolocationDispatcher::requestPermissionForFrame(
int bridge_id, const WebKit::WebURL& url) {
render_view_->Send(new ViewHostMsg_Geolocation_RequestPermission(
- render_view_->routing_id(), bridge_id, GURL(url).host()));
+ render_view_->routing_id(), bridge_id, GURL(url)));
}
void GeolocationDispatcher::startUpdating(
int bridge_id, const WebKit::WebURL& url, bool enableHighAccuracy) {
render_view_->Send(new ViewHostMsg_Geolocation_StartUpdating(
- render_view_->routing_id(), bridge_id, GURL(url).host(),
+ render_view_->routing_id(), bridge_id, GURL(url),
enableHighAccuracy));
}