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

Unified Diff: chrome/browser/geolocation/geolocation_permission_context.cc

Issue 650180: Initial Geolocation location bar icons. (Closed)
Patch Set: Addresses Peter and Brett's comments. Created 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/geolocation/geolocation_permission_context.cc
diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc
index f9fa9e2e4bd9fe2311aa5b3c5da15a57d420e8a5..3620c38422f4ec1213ad4334c8c6f40abc9b2f65 100644
--- a/chrome/browser/geolocation/geolocation_permission_context.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context.cc
@@ -6,11 +6,12 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
-#include "base/file_util.h"
+#include "googleurl/src/gurl.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/geolocation/geolocation_dispatcher_host.h"
+#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
@@ -18,18 +19,12 @@
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_util.h"
-#include "chrome/common/json_value_serializer.h"
#include "chrome/common/render_messages.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
namespace {
-const FilePath::CharType kGeolocationPermissionPath[] =
- FILE_PATH_LITERAL("Geolocation");
-
-const wchar_t kAllowedDictionaryKey[] = L"allowed";
-
// This is the delegate used to display the confirmation info bar.
class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
@@ -73,7 +68,7 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
private:
bool SetPermission(bool confirm) {
- context_->SetPermission(
+ context_->SetPermissionFromInfobar(
render_process_id_, render_view_id_, bridge_id_, host_, confirm);
return true;
}
@@ -84,66 +79,12 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
int bridge_id_;
std::string host_;
};
-
-// 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))) {
+ HostContentSettingsMap* host_content_settings_map)
+ : host_content_settings_map_(host_content_settings_map) {
+ DCHECK(host_content_settings_map_);
}
GeolocationPermissionContext::~GeolocationPermissionContext() {
@@ -153,50 +94,45 @@ void GeolocationPermissionContext::RequestGeolocationPermission(
int render_process_id, int render_view_id, int bridge_id,
const std::string& host) {
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);
+ ContentSetting content_setting =
+ host_content_settings_map_->GetContentSetting(
+ host, CONTENT_SETTINGS_TYPE_GEOLOCATION);
+ if (content_setting == CONTENT_SETTING_ASK) {
+ RequestPermissionFromUI(render_process_id, render_view_id, bridge_id, host);
+ } else if (content_setting == CONTENT_SETTING_ALLOW) {
+ NotifyPermissionSet(render_process_id, render_view_id, bridge_id, host,
+ true);
+ } else if (content_setting == CONTENT_SETTING_BLOCK) {
+ NotifyPermissionSet(render_process_id, render_view_id, bridge_id, host,
+ false);
} else {
- HandlePermissionMemoryCacheMiss(
- render_process_id, render_view_id, bridge_id, host);
+ NOTREACHED() << "unknown content setting" << content_setting;
}
}
-void GeolocationPermissionContext::SetPermission(
+void GeolocationPermissionContext::SetPermissionFromInfobar(
int render_process_id, int render_view_id, int bridge_id,
const std::string& host, bool allowed) {
- SetPermissionMemoryCacheOnIOThread(host, allowed);
- SetPermissionOnFileThread(host, allowed);
- NotifyPermissionSet(render_process_id, render_view_id, bridge_id, allowed);
+ host_content_settings_map_->SetContentSetting(
+ host, CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
+ NotifyPermissionSet(
+ render_process_id, render_view_id, bridge_id, host, 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::SetPermissionFromContentBubble(
+ TabContents* tab_contents, const std::string& host, bool allowed) {
+ int render_process_id = tab_contents->render_view_host()->process()->id();
+ int render_view_id = tab_contents->render_view_host()->routing_id();
+ host_content_settings_map_->SetContentSetting(
+ host, CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
+ RenderViewHostDelegate::Resource* resource = tab_util::GetTabContentsByID(
+ render_process_id, render_view_id);
+ resource->OnGeolocationPermissionSet(host, allowed);
+ // TODO(bulach): should we traverse all registered bridges? JS callbacks will
+ // have already been triggered at this point, so they have already received
+ // their position updated or error callbacks.
}
void GeolocationPermissionContext::RequestPermissionFromUI(
@@ -219,7 +155,8 @@ void GeolocationPermissionContext::RequestPermissionFromUI(
LOG(WARNING) << "Attempt to use geolocaiton tabless renderer: "
<< render_process_id << "," << render_view_id << "," << bridge_id
<< " (geolocation is not supported in extensions)";
- NotifyPermissionSet(render_process_id, render_view_id, bridge_id, false);
+ NotifyPermissionSet(render_process_id, render_view_id, bridge_id, host,
+ false);
return;
}
tab_contents->AddInfoBar(
@@ -229,58 +166,26 @@ void GeolocationPermissionContext::RequestPermissionFromUI(
}
void GeolocationPermissionContext::NotifyPermissionSet(
- int render_process_id, int render_view_id, int bridge_id, bool allowed) {
+ int render_process_id, int render_view_id, int bridge_id,
+ const std::string& host, bool allowed) {
if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
NewRunnableMethod(
this, &GeolocationPermissionContext::NotifyPermissionSet,
- render_process_id, render_view_id, bridge_id, allowed));
+ render_process_id, render_view_id, bridge_id,
+ host, allowed));
return;
}
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+
+ RenderViewHostDelegate::Resource* resource = tab_util::GetTabContentsByID(
+ render_process_id, render_view_id);
+ resource->OnGeolocationPermissionSet(host, allowed);
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
-}
« no previous file with comments | « chrome/browser/geolocation/geolocation_permission_context.h ('k') | chrome/browser/gtk/content_blocked_bubble_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698