diff options
author | jknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-18 08:26:32 +0000 |
---|---|---|
committer | jknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-18 08:26:32 +0000 |
commit | c715ce96b3df17c073f6fac83cd4d3190db5d265 (patch) | |
tree | 95679e179b8d3623bb3ef8084ba1fdb146244261 /chrome | |
parent | e0f465d25399bc018bfa6000022eacca935488dc (diff) | |
download | chromium_src-c715ce96b3df17c073f6fac83cd4d3190db5d265.zip chromium_src-c715ce96b3df17c073f6fac83cd4d3190db5d265.tar.gz chromium_src-c715ce96b3df17c073f6fac83cd4d3190db5d265.tar.bz2 |
Upstream Geolocation global enable/disable preference.
Chrome for Android presents a checkbox in its user interface to
control whether sites may request access to the geolocation API. This
requires a new preference, "geolocation.enabled" to model this global
switch.
When geolocation.enabled is true, Chrome for Android will prompt the
user (with an infobar) to confirm whether access should be
granted. Sites that have been previously authorised by the user will
be granted access automatically.
When geolocation.enabled is false, Chrome for Android should prevent
any access to the geolocation API for all sites (even those sites
previously authorised).
BUG=None
TEST=unit_test:GeolocationPermissionContextTests.GeolocationEnabledDisabled
Review URL: https://chromiumcodereview.appspot.com/10532126
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142679 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
8 files changed, 75 insertions, 3 deletions
diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc index e48fba1..fb376a7 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc @@ -584,6 +584,14 @@ ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( new GeolocationInfoBarQueueController(this, profile))) { } +void ChromeGeolocationPermissionContext::RegisterUserPrefs( + PrefService *user_prefs) { +#if defined(OS_ANDROID) + user_prefs->RegisterBooleanPref(prefs::kGeolocationEnabled, true, + PrefService::UNSYNCABLE_PREF); +#endif +} + ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { } @@ -601,6 +609,17 @@ void ChromeGeolocationPermissionContext::RequestGeolocationPermission( } DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); +#if defined(OS_ANDROID) + // Check to see if the feature in its entirety has been disabled. + // This must happen before other services (e.g. tabs, extensions) + // get an opportunity to allow the geolocation request. + if (!profile_->GetPrefs()->GetBoolean(prefs::kGeolocationEnabled)) { + NotifyPermissionSet(render_process_id, render_view_id, bridge_id, + requesting_frame, callback, false); + return; + } +#endif + ExtensionService* extension_service = profile_->GetExtensionService(); if (extension_service) { const extensions::Extension* extension = diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context.h b/chrome/browser/geolocation/chrome_geolocation_permission_context.h index e03ebd0..ef37b60 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context.h +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -10,6 +10,7 @@ #include "content/public/browser/geolocation_permission_context.h" class GeolocationInfoBarQueueController; +class PrefService; class Profile; // Chrome specific implementation of GeolocationPermissionContext; manages @@ -30,6 +31,8 @@ class ChromeGeolocationPermissionContext base::Callback<void(bool)> callback, bool allowed); + static void RegisterUserPrefs(PrefService *user_prefs); + // GeolocationPermissionContext implementation: virtual void RequestGeolocationPermission( int render_process_id, diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc index 02f8bfe..18ffab2 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc @@ -30,6 +30,11 @@ #include "content/public/test/web_contents_tester.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(OS_ANDROID) +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/common/pref_names.h" +#endif + using content::BrowserThread; using content::MockRenderProcessHost; using content::RenderViewHostTester; @@ -268,6 +273,32 @@ TEST_F(GeolocationPermissionContextTests, SinglePermission) { infobar_0->InfoBarClosed(); } +#if defined(OS_ANDROID) +TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { + profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( + CONTENT_SETTINGS_TYPE_GEOLOCATION, + CONTENT_SETTING_ALLOW); + + // Check that the request is denied with preference disabled, + // even though the default policy allows it. + GURL requesting_frame("http://www.example.com/geolocation"); + NavigateAndCommit(requesting_frame); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); + profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, false); + RequestGeolocationPermission( + process_id(), render_id(), bridge_id(), requesting_frame); + ASSERT_EQ(0U, infobar_tab_helper()->infobar_count()); + CheckPermissionMessageSent(bridge_id(), false); + + // Reenable the preference and check that the request now goes though. + profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, true); + RequestGeolocationPermission( + process_id(), render_id(), bridge_id() + 1, requesting_frame); + ASSERT_EQ(0U, infobar_tab_helper()->infobar_count()); + CheckPermissionMessageSent(bridge_id() + 1, true); +} +#endif + TEST_F(GeolocationPermissionContextTests, QueuedPermission) { GURL requesting_frame_0("http://www.example.com/geolocation"); GURL requesting_frame_1("http://www.example-2.com/geolocation"); diff --git a/chrome/browser/geolocation/geolocation_prefs.cc b/chrome/browser/geolocation/geolocation_prefs.cc index be20326..3ba7b3f 100644 --- a/chrome/browser/geolocation/geolocation_prefs.cc +++ b/chrome/browser/geolocation/geolocation_prefs.cc @@ -1,14 +1,20 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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/geolocation/geolocation_prefs.h" #include "chrome/browser/geolocation/chrome_access_token_store.h" +#include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" namespace geolocation { void RegisterPrefs(PrefService* prefs) { // Fan out to all geolocation sub-components that use prefs. ChromeAccessTokenStore::RegisterPrefs(prefs); } + +void RegisterUserPrefs(PrefService* user_prefs) { + ChromeGeolocationPermissionContext::RegisterUserPrefs(user_prefs); +} + } // namespace geolocation diff --git a/chrome/browser/geolocation/geolocation_prefs.h b/chrome/browser/geolocation/geolocation_prefs.h index cc39b66..c718912 100644 --- a/chrome/browser/geolocation/geolocation_prefs.h +++ b/chrome/browser/geolocation/geolocation_prefs.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -10,6 +10,7 @@ class PrefService; namespace geolocation { void RegisterPrefs(PrefService* prefs); +void RegisterUserPrefs(PrefService* user_prefs); } #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PREFS_H_ diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index be9fcdb..9b83d0f 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -215,6 +215,10 @@ void RegisterUserPrefs(PrefService* user_prefs) { BrowserWindowGtk::RegisterUserPrefs(user_prefs); #endif +#if defined(OS_ANDROID) + geolocation::RegisterUserPrefs(user_prefs); +#endif + #if defined(USE_ASH) ash::RegisterChromeLauncherUserPrefs(user_prefs); #endif diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 33595a7..c8eb8f1 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -941,6 +941,11 @@ const char kPinnedTabs[] = "pinned_tabs"; const char kGeolocationDefaultContentSetting[] = "geolocation.default_content_setting"; +#if defined(OS_ANDROID) +// Boolean that controls the enabled-state of Geolocation. +const char kGeolocationEnabled[] = "geolocation.enabled"; +#endif + // Dictionary that maps [frame, toplevel] to their Geolocation content setting. const char kGeolocationContentSettings[] = "geolocation.content_settings"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index b6aa68e..2f192d4 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -601,6 +601,9 @@ extern const char kWebAppCreateInQuickLaunchBar[]; extern const char kGeolocationAccessToken[]; extern const char kGeolocationDefaultContentSetting[]; extern const char kGeolocationContentSettings[]; +#if defined(OS_ANDROID) +extern const char kGeolocationEnabled[]; +#endif extern const char kRemoteAccessHostFirewallTraversal[]; |