summaryrefslogtreecommitdiffstats
path: root/chrome/browser/geolocation
diff options
context:
space:
mode:
authorbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-26 14:55:11 +0000
committerbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-26 14:55:11 +0000
commitbbdc45e247357ae5428b0f0df6e03a6d6a0f3870 (patch)
treef5acabee59ab30dfeec67bd4d18285dfaf5e9a1d /chrome/browser/geolocation
parentb0505262af47a4662044f517cd6f921ad6000bb5 (diff)
downloadchromium_src-bbdc45e247357ae5428b0f0df6e03a6d6a0f3870.zip
chromium_src-bbdc45e247357ae5428b0f0df6e03a6d6a0f3870.tar.gz
chromium_src-bbdc45e247357ae5428b0f0df6e03a6d6a0f3870.tar.bz2
Revert 42757 - Uses GeolocationContentSettingsMap on GeolocationPermissionContext to persist settings.
TEST=geolocation_browsertest.cc Review URL: http://codereview.chromium.org/1141004 TBR=bulach@chromium.org Review URL: http://codereview.chromium.org/1394005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42759 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/geolocation')
-rw-r--r--chrome/browser/geolocation/geolocation_browsertest.cc55
-rw-r--r--chrome/browser/geolocation/geolocation_permission_context.cc65
-rw-r--r--chrome/browser/geolocation/geolocation_permission_context.h1
3 files changed, 51 insertions, 70 deletions
diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc
index 753d430..647ecb6 100644
--- a/chrome/browser/geolocation/geolocation_browsertest.cc
+++ b/chrome/browser/geolocation/geolocation_browsertest.cc
@@ -8,7 +8,6 @@
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/dom_operation_notification_details.h"
-#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/browser/geolocation/location_arbitrator.h"
#include "chrome/browser/geolocation/location_provider.h"
#include "chrome/browser/geolocation/mock_location_provider.h"
@@ -172,8 +171,7 @@ void NotifyGeopositionOnIOThread(const Geoposition& geoposition) {
class GeolocationBrowserTest : public InProcessBrowserTest {
public:
GeolocationBrowserTest()
- : infobar_(NULL),
- current_browser_(NULL),
+ : infobar_(NULL), current_browser_(NULL),
html_for_tests_("files/geolocation/simple.html") {
EnableDOMAutomation();
}
@@ -238,9 +236,6 @@ class GeolocationBrowserTest : public InProcessBrowserTest {
}
EXPECT_TRUE(notification_observer.infobar_);
infobar_ = notification_observer.infobar_;
- } else {
- // Infobar wasn't displayed, so we need to wait for the JS prompt instead.
- WaitForJSPrompt();
}
}
@@ -386,13 +381,17 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_ErrorOnPermissionDenied) {
#endif
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForSecondTab) {
+#if 0
+ // TODO(bulach): enable this test once we use HostContentSettingsMap instead
+ // of files.
Initialize(INITIALIZATION_NONE);
- AddGeolocationWatch(true);
+ SendGeoposition(true, GeopositionFromLatLong(0, 0));
SetInfobarResponse(current_url_, true);
// Checks infobar will not be created a second tab.
Initialize(INITIALIZATION_NEWTAB);
- AddGeolocationWatch(false);
- CheckGeoposition(MockLocationProvider::instance_->position_);
+ SendGeoposition(false, GeopositionFromLatLong(0, 0));
+ CheckStringValueFromJavascript("0", "geoGetLastError()");
+#endif
}
#if defined(OS_MACOSX)
@@ -404,16 +403,19 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForSecondTab) {
#endif
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForDeniedOrigin) {
+#if 0
+ // TODO(bulach): enable this test once we use HostContentSettingsMap instead
+ // of files.
+ WritePermissionFile("{\"allowed\":false}");
+ // Checks no infobar will be created.
Initialize(INITIALIZATION_NONE);
- current_browser_->profile()->GetGeolocationContentSettingsMap()->
- SetContentSetting(current_url_, current_url_, CONTENT_SETTING_BLOCK);
- AddGeolocationWatch(false);
- // Checks we have an error for this denied origin.
+ SendGeoposition(false, GeopositionFromLatLong(0, 0));
CheckStringValueFromJavascript("1", "geoGetLastError()");
// Checks infobar will not be created a second tab.
Initialize(INITIALIZATION_NEWTAB);
- AddGeolocationWatch(false);
+ SendGeoposition(false, GeopositionFromLatLong(0, 0));
CheckStringValueFromJavascript("1", "geoGetLastError()");
+#endif
}
#if defined(OS_MACOSX)
@@ -426,13 +428,15 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForDeniedOrigin) {
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest,
MAYBE_NoInfobarForAllowedOrigin) {
- Initialize(INITIALIZATION_NONE);
- current_browser_->profile()->GetGeolocationContentSettingsMap()->
- SetContentSetting(current_url_, current_url_, CONTENT_SETTING_ALLOW);
+#if 0
+ // TODO(bulach): enable this test once we use HostContentSettingsMap instead
+ // of files.
+ WritePermissionFile("{\"allowed\":true}");
// Checks no infobar will be created and there's no error callback.
Initialize(INITIALIZATION_NONE);
- AddGeolocationWatch(false);
- CheckGeoposition(MockLocationProvider::instance_->position_);
+ SendGeoposition(false, GeopositionFromLatLong(0, 0));
+ CheckStringValueFromJavascript("0", "geoGetLastError()");
+#endif
}
#if defined(OS_MACOSX)
@@ -443,19 +447,20 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest,
#define MAYBE_InfobarForOffTheRecord InfobarForOffTheRecord
#endif
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForOffTheRecord) {
- // First, check infobar will be created for regular profile
+IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_InfobarForOffTheRecord) {
+ // Checks infobar will be created for regular profile.
Initialize(INITIALIZATION_NONE);
AddGeolocationWatch(true);
- // Response will be persisted
SetInfobarResponse(current_url_, true);
CheckGeoposition(MockLocationProvider::instance_->position_);
// Disables further prompts from this tab.
CheckStringValueFromJavascript("false", "geoEnableAlerts(false)");
- // Go off the record, and checks no infobar will be created.
+ // Go off the record, and checks infobar will be created and an error callback
+ // is triggered.
Initialize(INITIALIZATION_OFFTHERECORD);
- AddGeolocationWatch(false);
- CheckGeoposition(MockLocationProvider::instance_->position_);
+ AddGeolocationWatch(true);
+ SetInfobarResponse(current_url_, false);
+ CheckStringValueFromJavascript("1", "geoGetLastError()");
}
#if defined(OS_MACOSX)
diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc
index e812e00..d71a935 100644
--- a/chrome/browser/geolocation/geolocation_permission_context.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context.cc
@@ -10,7 +10,6 @@
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/chrome_thread.h"
-#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/browser/geolocation/geolocation_dispatcher_host.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_process_host.h"
@@ -117,55 +116,14 @@ GeolocationPermissionContext::~GeolocationPermissionContext() {
void GeolocationPermissionContext::RequestGeolocationPermission(
int render_process_id, int render_view_id, int bridge_id,
const GURL& requesting_frame) {
- if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
- ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(this,
- &GeolocationPermissionContext::RequestGeolocationPermission,
- render_process_id, render_view_id, bridge_id, requesting_frame));
- return;
- }
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
-
- 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 at all.
- LOG(WARNING) << "Attempt to use geolocation 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,
- requesting_frame, false);
- return;
- }
-
- GURL embedder = tab_contents->GetURL();
- ContentSetting content_setting =
- profile_->GetGeolocationContentSettingsMap()->GetContentSetting(
- requesting_frame, embedder);
- if (content_setting == CONTENT_SETTING_BLOCK) {
- NotifyPermissionSet(render_process_id, render_view_id, bridge_id,
- requesting_frame, false);
- } else if (content_setting == CONTENT_SETTING_ALLOW) {
- NotifyPermissionSet(render_process_id, render_view_id, bridge_id,
- requesting_frame, true);
- } else { // setting == ask. Prompt the user.
- RequestPermissionFromUI(render_process_id, render_view_id, bridge_id,
- requesting_frame);
- }
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ 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 GURL& requesting_frame, bool allowed) {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
- TabContents* tab_contents =
- tab_util::GetTabContentsByID(render_process_id, render_view_id);
- GURL embedder = tab_contents->GetURL();
- ContentSetting content_setting =
- allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
- profile_->GetGeolocationContentSettingsMap()->SetContentSetting(
- requesting_frame.GetOrigin(), embedder.GetOrigin(), content_setting);
NotifyPermissionSet(render_process_id, render_view_id, bridge_id,
requesting_frame, allowed);
}
@@ -184,6 +142,14 @@ GeolocationArbitrator* GeolocationPermissionContext::StartUpdatingRequested(
void GeolocationPermissionContext::RequestPermissionFromUI(
int render_process_id, int render_view_id, int bridge_id,
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, requesting_frame));
+ return;
+ }
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
TabContents* tab_contents =
@@ -204,6 +170,15 @@ void GeolocationPermissionContext::RequestPermissionFromUI(
void GeolocationPermissionContext::NotifyPermissionSet(
int render_process_id, int render_view_id, int bridge_id,
const GURL& requesting_frame, 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, requesting_frame,
+ allowed));
+ return;
+ }
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
RenderViewHostDelegate::Resource* resource =
diff --git a/chrome/browser/geolocation/geolocation_permission_context.h b/chrome/browser/geolocation/geolocation_permission_context.h
index a537452..996a54f 100644
--- a/chrome/browser/geolocation/geolocation_permission_context.h
+++ b/chrome/browser/geolocation/geolocation_permission_context.h
@@ -27,6 +27,7 @@ class GeolocationPermissionContext
// The render is requesting permission to use Geolocation.
// Response will be sent asynchronously as ViewMsg_Geolocation_PermissionSet.
+ // Must be called from the IO thread.
void RequestGeolocationPermission(
int render_process_id, int render_view_id, int bridge_id,
const GURL& requesting_frame);