summaryrefslogtreecommitdiffstats
path: root/chrome/browser/geolocation
diff options
context:
space:
mode:
authorjbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-19 15:45:49 +0000
committerjbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-19 15:45:49 +0000
commit5d4451ebf298d9d71f716cc0135f465cec41fcd0 (patch)
tree4b7c389798e5f13614e603e2e8e310cb424a46d1 /chrome/browser/geolocation
parentc8d0c9e77e84c2aaa7f772b253c20c04450dc06b (diff)
downloadchromium_src-5d4451ebf298d9d71f716cc0135f465cec41fcd0.zip
chromium_src-5d4451ebf298d9d71f716cc0135f465cec41fcd0.tar.gz
chromium_src-5d4451ebf298d9d71f716cc0135f465cec41fcd0.tar.bz2
Roll ANGLE r704:r705
BUG= TEST=try Review URL: http://codereview.chromium.org/7375016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93026 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/geolocation')
-rw-r--r--chrome/browser/geolocation/access_token_store.cc110
-rw-r--r--chrome/browser/geolocation/access_token_store_browsertest.cc153
-rw-r--r--chrome/browser/geolocation/chrome_geolocation_permission_context.cc630
-rw-r--r--chrome/browser/geolocation/chrome_geolocation_permission_context.h62
-rw-r--r--chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc495
-rw-r--r--chrome/browser/geolocation/geolocation_browsertest.cc654
-rw-r--r--chrome/browser/geolocation/geolocation_content_settings_map.cc228
-rw-r--r--chrome/browser/geolocation/geolocation_content_settings_map.h112
-rw-r--r--chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc317
-rw-r--r--chrome/browser/geolocation/geolocation_exceptions_table_model.cc255
-rw-r--r--chrome/browser/geolocation/geolocation_exceptions_table_model.h62
-rw-r--r--chrome/browser/geolocation/geolocation_exceptions_table_model_unittest.cc143
-rw-r--r--chrome/browser/geolocation/geolocation_prefs.cc14
-rw-r--r--chrome/browser/geolocation/geolocation_prefs.h15
-rw-r--r--chrome/browser/geolocation/geolocation_settings_state.cc107
-rw-r--r--chrome/browser/geolocation/geolocation_settings_state.h73
-rw-r--r--chrome/browser/geolocation/geolocation_settings_state_unittest.cc186
-rw-r--r--chrome/browser/geolocation/wifi_data_provider_chromeos.cc233
-rw-r--r--chrome/browser/geolocation/wifi_data_provider_chromeos.h73
-rw-r--r--chrome/browser/geolocation/wifi_data_provider_unittest_chromeos.cc78
20 files changed, 0 insertions, 4000 deletions
diff --git a/chrome/browser/geolocation/access_token_store.cc b/chrome/browser/geolocation/access_token_store.cc
deleted file mode 100644
index f76bcc5..0000000
--- a/chrome/browser/geolocation/access_token_store.cc
+++ /dev/null
@@ -1,110 +0,0 @@
-// 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 "content/browser/geolocation/access_token_store.h"
-
-#include "base/string_piece.h"
-#include "base/utf_string_conversions.h"
-#include "base/values.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/prefs/scoped_user_pref_update.h"
-#include "chrome/common/pref_names.h"
-#include "content/browser/browser_thread.h"
-#include "googleurl/src/gurl.h"
-
-namespace {
-class ChromePrefsAccessTokenStore : public AccessTokenStore {
- public:
- ChromePrefsAccessTokenStore();
-
- private:
- void LoadDictionaryStoreInUIThread(
- scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request);
-
- // AccessTokenStore
- virtual void DoLoadAccessTokens(
- scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request);
- virtual void SaveAccessToken(
- const GURL& server_url, const string16& access_token);
-
- DISALLOW_COPY_AND_ASSIGN(ChromePrefsAccessTokenStore);
-};
-
-ChromePrefsAccessTokenStore::ChromePrefsAccessTokenStore() {
-}
-
-void ChromePrefsAccessTokenStore::LoadDictionaryStoreInUIThread(
- scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (request->canceled())
- return;
- const DictionaryValue* token_dictionary =
- g_browser_process->local_state()->GetDictionary(
- prefs::kGeolocationAccessToken);
-
- AccessTokenStore::AccessTokenSet access_token_set;
- // The dictionary value could be NULL if the pref has never been set.
- if (token_dictionary != NULL) {
- for (DictionaryValue::key_iterator it = token_dictionary->begin_keys();
- it != token_dictionary->end_keys(); ++it) {
- GURL url(*it);
- if (!url.is_valid())
- continue;
- token_dictionary->GetStringWithoutPathExpansion(*it,
- &access_token_set[url]);
- }
- }
- request->ForwardResultAsync(MakeTuple(access_token_set));
-}
-
-void ChromePrefsAccessTokenStore::DoLoadAccessTokens(
- scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request) {
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod(
- this, &ChromePrefsAccessTokenStore::LoadDictionaryStoreInUIThread,
- request));
-}
-
-void SetAccessTokenOnUIThread(const GURL& server_url, const string16& token) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DictionaryPrefUpdate update(g_browser_process->local_state(),
- prefs::kGeolocationAccessToken);
- DictionaryValue* access_token_dictionary = update.Get();
- access_token_dictionary->SetWithoutPathExpansion(
- server_url.spec(), Value::CreateStringValue(token));
-}
-
-void ChromePrefsAccessTokenStore::SaveAccessToken(
- const GURL& server_url, const string16& access_token) {
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableFunction(
- &SetAccessTokenOnUIThread, server_url, access_token));
-}
-} // namespace
-
-AccessTokenStore::AccessTokenStore() {
-}
-
-AccessTokenStore::~AccessTokenStore() {
-}
-
-void AccessTokenStore::RegisterPrefs(PrefService* prefs) {
- prefs->RegisterDictionaryPref(prefs::kGeolocationAccessToken);
-}
-
-AccessTokenStore::Handle AccessTokenStore::LoadAccessTokens(
- CancelableRequestConsumerBase* consumer,
- LoadAccessTokensCallbackType* callback) {
- scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request(
- new CancelableRequest<LoadAccessTokensCallbackType>(callback));
- AddRequest(request, consumer);
- DCHECK(request->handle());
-
- DoLoadAccessTokens(request);
- return request->handle();
-}
-
-// Creates a new access token store backed by the global chome prefs.
-AccessTokenStore* NewChromePrefsAccessTokenStore() {
- return new ChromePrefsAccessTokenStore;
-}
diff --git a/chrome/browser/geolocation/access_token_store_browsertest.cc b/chrome/browser/geolocation/access_token_store_browsertest.cc
deleted file mode 100644
index d29f7a9a..0000000
--- a/chrome/browser/geolocation/access_token_store_browsertest.cc
+++ /dev/null
@@ -1,153 +0,0 @@
-// Copyright (c) 2010 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 "content/browser/geolocation/access_token_store.h"
-
-#include "base/string_util.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/test/in_process_browser_test.h"
-#include "chrome/test/ui_test_utils.h"
-#include "content/browser/browser_thread.h"
-
-namespace {
-
-// The token store factory implementation expects to be used from any well-known
-// chrome thread other than UI. We could use any arbitrary thread; IO is
-// a good choice as this is the expected usage.
-const BrowserThread::ID kExpectedClientThreadId = BrowserThread::IO;
-const char* kRefServerUrl1 = "https://test.domain.example/foo?id=bar.bar";
-const char* kRefServerUrl2 = "http://another.domain.example/foo?id=bar.bar#2";
-
-class GeolocationAccessTokenStoreTest
- : public InProcessBrowserTest {
- public:
- GeolocationAccessTokenStoreTest()
- : token_to_expect_(NULL), token_to_set_(NULL) {}
-
- void DoTestStepAndWaitForResults(
- const char* ref_url, const string16* token_to_expect,
- const string16* token_to_set);
-
- void OnAccessTokenStoresLoaded(
- AccessTokenStore::AccessTokenSet access_token_set);
-
- scoped_refptr<AccessTokenStore> token_store_;
- CancelableRequestConsumer request_consumer_;
- GURL ref_url_;
- const string16* token_to_expect_;
- const string16* token_to_set_;
-};
-
-void StartTestStepFromClientThread(
- scoped_refptr<AccessTokenStore>* store,
- CancelableRequestConsumerBase* consumer,
- AccessTokenStore::LoadAccessTokensCallbackType* callback) {
- ASSERT_TRUE(BrowserThread::CurrentlyOn(kExpectedClientThreadId));
- if (*store == NULL)
- (*store) = NewChromePrefsAccessTokenStore();
- (*store)->LoadAccessTokens(consumer, callback);
-}
-
-struct TokenLoadClientForTest {
- void NotReachedCallback(AccessTokenStore::AccessTokenSet /*tokens*/) {
- NOTREACHED() << "This request should have been canceled before callback";
- }
-};
-
-void RunCancelTestInClientTread() {
- ASSERT_TRUE(BrowserThread::CurrentlyOn(kExpectedClientThreadId));
- scoped_refptr<AccessTokenStore> store(NewChromePrefsAccessTokenStore());
- CancelableRequestConsumer consumer;
- TokenLoadClientForTest load_client;
-
- // Single request, canceled explicitly
- CancelableRequestProvider::Handle first_handle =
- store->LoadAccessTokens(&consumer, NewCallback(
- &load_client, &TokenLoadClientForTest::NotReachedCallback));
- EXPECT_TRUE(consumer.HasPendingRequests());
- // Test this handle is valid.
- consumer.GetClientData(store.get(), first_handle);
- store->CancelRequest(first_handle);
- EXPECT_FALSE(consumer.HasPendingRequests());
-
- // 2 requests, canceled globally.
- store->LoadAccessTokens(&consumer, NewCallback(
- &load_client, &TokenLoadClientForTest::NotReachedCallback));
- store->LoadAccessTokens(&consumer, NewCallback(
- &load_client, &TokenLoadClientForTest::NotReachedCallback));
- EXPECT_TRUE(consumer.HasPendingRequests());
- EXPECT_EQ(2u, consumer.PendingRequestCount());
- consumer.CancelAllRequests();
- EXPECT_FALSE(consumer.HasPendingRequests());
- EXPECT_EQ(0u, consumer.PendingRequestCount());
-
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask);
-}
-
-void GeolocationAccessTokenStoreTest::DoTestStepAndWaitForResults(
- const char* ref_url, const string16* token_to_expect,
- const string16* token_to_set) {
- ref_url_ = GURL(ref_url);
- token_to_expect_ = token_to_expect;
- token_to_set_ = token_to_set;
-
- BrowserThread::PostTask(
- kExpectedClientThreadId, FROM_HERE, NewRunnableFunction(
- &StartTestStepFromClientThread, &token_store_, &request_consumer_,
- NewCallback(this,
- &GeolocationAccessTokenStoreTest::OnAccessTokenStoresLoaded)));
- ui_test_utils::RunMessageLoop();
-}
-
-void GeolocationAccessTokenStoreTest::OnAccessTokenStoresLoaded(
- AccessTokenStore::AccessTokenSet access_token_set) {
- ASSERT_TRUE(BrowserThread::CurrentlyOn(kExpectedClientThreadId))
- << "Callback from token factory should be from the same thread as the "
- "LoadAccessTokenStores request was made on";
- EXPECT_TRUE(token_to_set_ || token_to_expect_) << "No work to do?";
- AccessTokenStore::AccessTokenSet::const_iterator item =
- access_token_set.find(ref_url_);
- if (!token_to_expect_) {
- EXPECT_TRUE(item == access_token_set.end());
- } else {
- EXPECT_FALSE(item == access_token_set.end());
- EXPECT_EQ(*token_to_expect_, item->second);
- }
-
- if (token_to_set_) {
- scoped_refptr<AccessTokenStore> store(
- NewChromePrefsAccessTokenStore());
- store->SaveAccessToken(ref_url_, *token_to_set_);
- }
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask);
-}
-
-IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, SetAcrossInstances) {
- const string16 ref_token1 = ASCIIToUTF16("jksdfo90,'s#\"#1*(");
- const string16 ref_token2 = ASCIIToUTF16("\1\2\3\4\5\6\7\10\11\12=023");
- ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- DoTestStepAndWaitForResults(kRefServerUrl1, NULL, &ref_token1);
- // Check it was set, and change to new value.
- DoTestStepAndWaitForResults(kRefServerUrl1, &ref_token1, &ref_token2);
- // And change back.
- DoTestStepAndWaitForResults(kRefServerUrl1, &ref_token2, &ref_token1);
- DoTestStepAndWaitForResults(kRefServerUrl1, &ref_token1, NULL);
-
- // Set a second server URL
- DoTestStepAndWaitForResults(kRefServerUrl2, NULL, &ref_token2);
- DoTestStepAndWaitForResults(kRefServerUrl2, &ref_token2, NULL);
- DoTestStepAndWaitForResults(kRefServerUrl1, &ref_token1, NULL);
-}
-
-IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, CancelRequest) {
- BrowserThread::PostTask(
- kExpectedClientThreadId, FROM_HERE, NewRunnableFunction(
- RunCancelTestInClientTread));
- ui_test_utils::RunMessageLoop();
-}
-
-} // namespace
diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc
deleted file mode 100644
index 6e8ed8e..0000000
--- a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc
+++ /dev/null
@@ -1,630 +0,0 @@
-// 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/geolocation/chrome_geolocation_permission_context.h"
-
-#include <functional>
-#include <string>
-#include <vector>
-
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/content_settings/tab_specific_content_settings.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
-#include "chrome/browser/google/google_util.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/extensions/extension.h"
-#include "chrome/common/pref_names.h"
-#include "content/browser/browser_thread.h"
-#include "content/browser/geolocation/geolocation_provider.h"
-#include "content/browser/renderer_host/render_view_host.h"
-#include "content/common/content_notification_types.h"
-#include "content/common/notification_registrar.h"
-#include "content/common/notification_source.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
-#include "grit/theme_resources.h"
-#include "grit/theme_resources_standard.h"
-#include "net/base/net_util.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-
-// GeolocationInfoBarQueueController ------------------------------------------
-
-// This class controls the geolocation infobar queue per profile, and it's an
-// internal class to GeolocationPermissionContext.
-// An alternate approach would be to have this queue per tab, and use
-// notifications to broadcast when permission is set / listen to notification to
-// cancel pending requests. This may be specially useful if there are other
-// things listening for such notifications.
-// For the time being this class is self-contained and it doesn't seem pulling
-// the notification infrastructure would simplify.
-class GeolocationInfoBarQueueController : NotificationObserver {
- public:
- GeolocationInfoBarQueueController(
- ChromeGeolocationPermissionContext* geolocation_permission_context,
- Profile* profile);
- ~GeolocationInfoBarQueueController();
-
- // The InfoBar will be displayed immediately if the tab is not already
- // displaying one, otherwise it'll be queued.
- void CreateInfoBarRequest(int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame,
- const GURL& emebedder);
-
- // Cancels a specific infobar request.
- void CancelInfoBarRequest(int render_process_id,
- int render_view_id,
- int bridge_id);
-
- // Called by the InfoBarDelegate to notify it's closed. It'll display a new
- // InfoBar if there's any request pending for this tab.
- void OnInfoBarClosed(int render_process_id,
- int render_view_id,
- int bridge_id);
-
- // Called by the InfoBarDelegate to notify permission has been set.
- // It'll notify and dismiss any other pending InfoBar request for the same
- // |requesting_frame| and embedder.
- void OnPermissionSet(int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame,
- const GURL& embedder,
- bool allowed);
-
- // NotificationObserver
- virtual void Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- private:
- struct PendingInfoBarRequest;
- class RequestEquals;
-
- typedef std::vector<PendingInfoBarRequest> PendingInfoBarRequests;
-
- // Shows the first pending infobar for this tab.
- void ShowQueuedInfoBar(int render_process_id, int render_view_id);
-
- // Cancels an InfoBar request and returns the next iterator position.
- PendingInfoBarRequests::iterator CancelInfoBarRequestInternal(
- PendingInfoBarRequests::iterator i);
-
- NotificationRegistrar registrar_;
-
- ChromeGeolocationPermissionContext* const geolocation_permission_context_;
- Profile* const profile_;
- PendingInfoBarRequests pending_infobar_requests_;
-};
-
-
-// GeolocationConfirmInfoBarDelegate ------------------------------------------
-
-namespace {
-
-class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
- public:
- GeolocationConfirmInfoBarDelegate(
- TabContents* tab_contents,
- GeolocationInfoBarQueueController* controller,
- int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame_url,
- const std::string& display_languages);
-
- private:
- virtual ~GeolocationConfirmInfoBarDelegate();
-
- // ConfirmInfoBarDelegate:
- virtual gfx::Image* GetIcon() const OVERRIDE;
- virtual Type GetInfoBarType() const OVERRIDE;
- virtual string16 GetMessageText() const OVERRIDE;
- virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
- virtual bool Accept() OVERRIDE;
- virtual bool Cancel() OVERRIDE;
- virtual string16 GetLinkText() const OVERRIDE;
- virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
-
- TabContents* tab_contents_;
- GeolocationInfoBarQueueController* controller_;
- int render_process_id_;
- int render_view_id_;
- int bridge_id_;
- GURL requesting_frame_url_;
- std::string display_languages_;
-
- DISALLOW_IMPLICIT_CONSTRUCTORS(GeolocationConfirmInfoBarDelegate);
-};
-
-GeolocationConfirmInfoBarDelegate::GeolocationConfirmInfoBarDelegate(
- TabContents* tab_contents,
- GeolocationInfoBarQueueController* controller,
- int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame_url,
- const std::string& display_languages)
- : ConfirmInfoBarDelegate(tab_contents),
- tab_contents_(tab_contents),
- controller_(controller),
- render_process_id_(render_process_id),
- render_view_id_(render_view_id),
- bridge_id_(bridge_id),
- requesting_frame_url_(requesting_frame_url),
- display_languages_(display_languages) {
-}
-
-GeolocationConfirmInfoBarDelegate::~GeolocationConfirmInfoBarDelegate() {
- controller_->OnInfoBarClosed(render_process_id_, render_view_id_,
- bridge_id_);
-}
-
-gfx::Image* GeolocationConfirmInfoBarDelegate::GetIcon() const {
- return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
- IDR_GEOLOCATION_INFOBAR_ICON);
-}
-
-InfoBarDelegate::Type
- GeolocationConfirmInfoBarDelegate::GetInfoBarType() const {
- return PAGE_ACTION_TYPE;
-}
-
-string16 GeolocationConfirmInfoBarDelegate::GetMessageText() const {
- return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION,
- net::FormatUrl(requesting_frame_url_.GetOrigin(), display_languages_));
-}
-
-string16 GeolocationConfirmInfoBarDelegate::GetButtonLabel(
- InfoBarButton button) const {
- return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
- IDS_GEOLOCATION_ALLOW_BUTTON : IDS_GEOLOCATION_DENY_BUTTON);
-}
-
-bool GeolocationConfirmInfoBarDelegate::Accept() {
- controller_->OnPermissionSet(render_process_id_, render_view_id_, bridge_id_,
- requesting_frame_url_, tab_contents_->GetURL(), true);
- return true;
-}
-
-bool GeolocationConfirmInfoBarDelegate::Cancel() {
- controller_->OnPermissionSet(render_process_id_, render_view_id_, bridge_id_,
- requesting_frame_url_, tab_contents_->GetURL(), false);
- return true;
-}
-
-string16 GeolocationConfirmInfoBarDelegate::GetLinkText() const {
- return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
-}
-
-bool GeolocationConfirmInfoBarDelegate::LinkClicked(
- WindowOpenDisposition disposition) {
- const char kGeolocationLearnMoreUrl[] =
-#if defined(OS_CHROMEOS)
- "https://www.google.com/support/chromeos/bin/answer.py?answer=142065";
-#else
- "https://www.google.com/support/chrome/bin/answer.py?answer=142065";
-#endif
-
- // Ignore the click disposition and always open in a new top level tab.
- tab_contents_->OpenURL(
- google_util::AppendGoogleLocaleParam(GURL(kGeolocationLearnMoreUrl)),
- GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
- return false; // Do not dismiss the info bar.
-}
-
-} // namespace
-
-
-// GeolocationInfoBarQueueController::PendingInfoBarRequest -------------------
-
-struct GeolocationInfoBarQueueController::PendingInfoBarRequest {
- public:
- PendingInfoBarRequest(int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame,
- const GURL& embedder);
-
- bool IsForTab(int p_render_process_id, int p_render_view_id) const;
- bool IsForPair(const GURL& p_requesting_frame,
- const GURL& p_embedder) const;
- bool Equals(int p_render_process_id,
- int p_render_view_id,
- int p_bridge_id) const;
-
- int render_process_id;
- int render_view_id;
- int bridge_id;
- GURL requesting_frame;
- GURL embedder;
- InfoBarDelegate* infobar_delegate;
-};
-
-GeolocationInfoBarQueueController::PendingInfoBarRequest::PendingInfoBarRequest(
- int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame,
- const GURL& embedder)
- : render_process_id(render_process_id),
- render_view_id(render_view_id),
- bridge_id(bridge_id),
- requesting_frame(requesting_frame),
- embedder(embedder),
- infobar_delegate(NULL) {
-}
-
-bool GeolocationInfoBarQueueController::PendingInfoBarRequest::IsForTab(
- int p_render_process_id,
- int p_render_view_id) const {
- return (render_process_id == p_render_process_id) &&
- (render_view_id == p_render_view_id);
-}
-
-bool GeolocationInfoBarQueueController::PendingInfoBarRequest::IsForPair(
- const GURL& p_requesting_frame,
- const GURL& p_embedder) const {
- return (requesting_frame == p_requesting_frame) && (embedder == p_embedder);
-}
-
-bool GeolocationInfoBarQueueController::PendingInfoBarRequest::Equals(
- int p_render_process_id,
- int p_render_view_id,
- int p_bridge_id) const {
- return IsForTab(p_render_process_id, p_render_view_id) &&
- (bridge_id == p_bridge_id);
-}
-
-
-// GeolocationInfoBarQueueController::RequestEquals ---------------------------
-
-// Useful predicate for checking PendingInfoBarRequest equality.
-class GeolocationInfoBarQueueController::RequestEquals
- : public std::unary_function<PendingInfoBarRequest, bool> {
- public:
- RequestEquals(int render_process_id, int render_view_id, int bridge_id);
-
- bool operator()(const PendingInfoBarRequest& request) const;
-
- private:
- int render_process_id_;
- int render_view_id_;
- int bridge_id_;
-};
-
-GeolocationInfoBarQueueController::RequestEquals::RequestEquals(
- int render_process_id,
- int render_view_id,
- int bridge_id)
- : render_process_id_(render_process_id),
- render_view_id_(render_view_id),
- bridge_id_(bridge_id) {
-}
-
-bool GeolocationInfoBarQueueController::RequestEquals::operator()(
- const PendingInfoBarRequest& request) const {
- return request.Equals(render_process_id_, render_view_id_, bridge_id_);
-}
-
-
-// GeolocationInfoBarQueueController ------------------------------------------
-
-GeolocationInfoBarQueueController::GeolocationInfoBarQueueController(
- ChromeGeolocationPermissionContext* geolocation_permission_context,
- Profile* profile)
- : geolocation_permission_context_(geolocation_permission_context),
- profile_(profile) {
-}
-
-GeolocationInfoBarQueueController::~GeolocationInfoBarQueueController() {
-}
-
-void GeolocationInfoBarQueueController::CreateInfoBarRequest(
- int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame,
- const GURL& embedder) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- // We shouldn't get duplicate requests.
- DCHECK(std::find_if(pending_infobar_requests_.begin(),
- pending_infobar_requests_.end(),
- RequestEquals(render_process_id, render_view_id, bridge_id)) ==
- pending_infobar_requests_.end());
-
- pending_infobar_requests_.push_back(PendingInfoBarRequest(render_process_id,
- render_view_id, bridge_id, requesting_frame, embedder));
- ShowQueuedInfoBar(render_process_id, render_view_id);
-}
-
-void GeolocationInfoBarQueueController::CancelInfoBarRequest(
- int render_process_id,
- int render_view_id,
- int bridge_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- PendingInfoBarRequests::iterator i = std::find_if(
- pending_infobar_requests_.begin(), pending_infobar_requests_.end(),
- RequestEquals(render_process_id, render_view_id, bridge_id));
- // TODO(pkasting): Can this conditional become a DCHECK()?
- if (i != pending_infobar_requests_.end())
- CancelInfoBarRequestInternal(i);
-}
-
-void GeolocationInfoBarQueueController::OnInfoBarClosed(int render_process_id,
- int render_view_id,
- int bridge_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- PendingInfoBarRequests::iterator i = std::find_if(
- pending_infobar_requests_.begin(), pending_infobar_requests_.end(),
- RequestEquals(render_process_id, render_view_id, bridge_id));
- if (i != pending_infobar_requests_.end())
- pending_infobar_requests_.erase(i);
-
- ShowQueuedInfoBar(render_process_id, render_view_id);
-}
-
-void GeolocationInfoBarQueueController::OnPermissionSet(
- int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame,
- const GURL& embedder,
- bool allowed) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- ContentSetting content_setting =
- allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
- profile_->GetGeolocationContentSettingsMap()->SetContentSetting(
- requesting_frame.GetOrigin(), embedder.GetOrigin(), content_setting);
-
- for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin();
- i != pending_infobar_requests_.end(); ) {
- if (i->IsForPair(requesting_frame, embedder)) {
- // Cancel this request first, then notify listeners. TODO(pkasting): Why
- // is this order important?
- // NOTE: If the pending request had an infobar, TabContents will close it
- // either synchronously or asynchronously, which will then pump the queue
- // via OnInfoBarClosed().
- PendingInfoBarRequest copied_request = *i;
- // Don't let CancelInfoBarRequestInternal() call RemoveInfoBar() on the
- // delegate that's currently calling us. That delegate is in either
- // Accept() or Cancel(), so its owning InfoBar will call RemoveInfoBar()
- // later on in this callstack anyway; and if we do it here, and it causes
- // the delegate to be deleted, our GURL& args will point to garbage and we
- // may also cause other problems during stack unwinding.
- if (i->Equals(render_process_id, render_view_id, bridge_id))
- i->infobar_delegate = NULL;
- i = CancelInfoBarRequestInternal(i);
-
- geolocation_permission_context_->NotifyPermissionSet(
- copied_request.render_process_id, copied_request.render_view_id,
- copied_request.bridge_id, copied_request.requesting_frame, allowed);
- } else {
- ++i;
- }
- }
-}
-
-void GeolocationInfoBarQueueController::Observe(
- int type, const NotificationSource& source,
- const NotificationDetails& details) {
- registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
- source);
- TabContents* tab_contents = Source<TabContents>(source).ptr();
- for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin();
- i != pending_infobar_requests_.end();) {
- if (i->infobar_delegate == NULL &&
- tab_contents == tab_util::GetTabContentsByID(i->render_process_id,
- i->render_view_id)) {
- i = pending_infobar_requests_.erase(i);
- } else {
- ++i;
- }
- }
-}
-
-void GeolocationInfoBarQueueController::ShowQueuedInfoBar(int render_process_id,
- int render_view_id) {
- TabContents* tab_contents =
- tab_util::GetTabContentsByID(render_process_id, render_view_id);
- TabContentsWrapper* wrapper = NULL;
- if (tab_contents)
- wrapper = TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
- for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin();
- i != pending_infobar_requests_.end(); ) {
- if (i->IsForTab(render_process_id, render_view_id)) {
- if (!wrapper) {
- i = pending_infobar_requests_.erase(i);
- continue;
- }
-
- if (!i->infobar_delegate) {
- if (!registrar_.IsRegistered(
- this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
- Source<TabContents>(tab_contents))) {
- registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
- Source<TabContents>(tab_contents));
- }
- i->infobar_delegate = new GeolocationConfirmInfoBarDelegate(
- tab_contents, this, render_process_id, render_view_id, i->bridge_id,
- i->requesting_frame,
- profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
- wrapper->AddInfoBar(i->infobar_delegate);
- }
- break;
- }
- ++i;
- }
-}
-
-GeolocationInfoBarQueueController::PendingInfoBarRequests::iterator
- GeolocationInfoBarQueueController::CancelInfoBarRequestInternal(
- PendingInfoBarRequests::iterator i) {
- InfoBarDelegate* delegate = i->infobar_delegate;
- if (!delegate)
- return pending_infobar_requests_.erase(i);
-
- TabContents* tab_contents =
- tab_util::GetTabContentsByID(i->render_process_id, i->render_view_id);
- if (!tab_contents)
- return pending_infobar_requests_.erase(i);
-
- // TabContents will destroy the InfoBar, which will remove from our vector
- // asynchronously.
- TabContentsWrapper* wrapper =
- TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
- wrapper->RemoveInfoBar(i->infobar_delegate);
- return ++i;
-}
-
-
-// GeolocationPermissionContext -----------------------------------------------
-
-ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext(
- Profile* profile)
- : profile_(profile),
- ALLOW_THIS_IN_INITIALIZER_LIST(geolocation_infobar_queue_controller_(
- new GeolocationInfoBarQueueController(this, profile))) {
-}
-
-ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() {
-}
-
-void ChromeGeolocationPermissionContext::RequestGeolocationPermission(
- int render_process_id, int render_view_id, int bridge_id,
- const GURL& requesting_frame) {
- if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod(
- this, &ChromeGeolocationPermissionContext::RequestGeolocationPermission,
- render_process_id, render_view_id, bridge_id, requesting_frame));
- return;
- }
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- ExtensionService* extensions = profile_->GetExtensionService();
- if (extensions) {
- const Extension* ext = extensions->GetExtensionByURL(requesting_frame);
- if (!ext)
- ext = extensions->GetExtensionByWebExtent(requesting_frame);
- if (ext && ext->HasAPIPermission(ExtensionAPIPermission::kGeolocation)) {
- // Make sure this matches the current extension.
- RenderViewHost* rvh = RenderViewHost::FromID(render_process_id,
- render_view_id);
- if (rvh && rvh->site_instance()) {
- ExtensionProcessManager* epm = profile_->GetExtensionProcessManager();
- const Extension* current_ext = epm->GetExtensionForSiteInstance(
- rvh->site_instance()->id());
- if (ext == current_ext) {
- NotifyPermissionSet(render_process_id, render_view_id, bridge_id,
- requesting_frame, true);
- 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 at all.
- LOG(WARNING) << "Attempt to use geolocation tabless renderer: "
- << render_process_id << "," << render_view_id << ","
- << bridge_id << " (can't prompt user without a visible tab)";
- NotifyPermissionSet(render_process_id, render_view_id, bridge_id,
- requesting_frame, false);
- return;
- }
-
- GURL embedder = tab_contents->GetURL();
- if (!requesting_frame.is_valid() || !embedder.is_valid()) {
- LOG(WARNING) << "Attempt to use geolocation from an invalid URL: "
- << requesting_frame << "," << embedder
- << " (geolocation is not supported in popups)";
- NotifyPermissionSet(render_process_id, render_view_id, bridge_id,
- requesting_frame, false);
- return;
- }
-
- 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.
- geolocation_infobar_queue_controller_->CreateInfoBarRequest(
- render_process_id, render_view_id, bridge_id, requesting_frame,
- embedder);
- }
-}
-
-void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest(
- int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame) {
- CancelPendingInfoBarRequest(render_process_id, render_view_id, bridge_id);
-}
-
-void ChromeGeolocationPermissionContext::NotifyPermissionSet(
- int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame,
- bool allowed) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- // TabContents may have gone away (or not exists for extension).
- TabSpecificContentSettings* content_settings =
- TabSpecificContentSettings::Get(render_process_id, render_view_id);
- if (content_settings) {
- content_settings->OnGeolocationPermissionSet(requesting_frame.GetOrigin(),
- allowed);
- }
-
- SetGeolocationPermissionResponse(render_process_id, render_view_id, bridge_id,
- allowed);
-
- if (allowed) {
- BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, NewRunnableMethod(
- this,
- &ChromeGeolocationPermissionContext::NotifyArbitratorPermissionGranted,
- requesting_frame));
- }
-}
-
-void ChromeGeolocationPermissionContext::NotifyArbitratorPermissionGranted(
- const GURL& requesting_frame) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- GeolocationProvider::GetInstance()->OnPermissionGranted(requesting_frame);
-}
-
-void ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest(
- int render_process_id,
- int render_view_id,
- int bridge_id) {
- if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod(
- this, &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest,
- render_process_id, render_view_id, bridge_id));
- return;
- }
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- geolocation_infobar_queue_controller_->CancelInfoBarRequest(render_process_id,
- render_view_id, bridge_id);
-}
diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context.h b/chrome/browser/geolocation/chrome_geolocation_permission_context.h
deleted file mode 100644
index 2195362..0000000
--- a/chrome/browser/geolocation/chrome_geolocation_permission_context.h
+++ /dev/null
@@ -1,62 +0,0 @@
-// 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_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_
-#define CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_
-#pragma once
-
-#include "base/memory/scoped_ptr.h"
-#include "content/browser/geolocation/geolocation_permission_context.h"
-
-class GeolocationInfoBarQueueController;
-class Profile;
-
-// Chrome specific implementation of GeolocationPermissionContext; manages
-// Geolocation permissions flow, and delegates UI handling via
-// GeolocationInfoBarQueueController.
-class ChromeGeolocationPermissionContext : public GeolocationPermissionContext {
- public:
- explicit ChromeGeolocationPermissionContext(Profile* profile);
-
- // Notifies whether or not the corresponding bridge is allowed to use
- // geolocation via
- // GeolocationPermissionContext::SetGeolocationPermissionResponse().
- void NotifyPermissionSet(int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame,
- bool allowed);
-
- // GeolocationPermissionContext
- virtual void RequestGeolocationPermission(int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame);
-
- virtual void CancelGeolocationPermissionRequest(int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame);
-
- private:
- virtual ~ChromeGeolocationPermissionContext();
-
- // Calls GeolocationArbitrator::OnPermissionGranted.
- void NotifyArbitratorPermissionGranted(const GURL& requesting_frame);
-
- // Removes any pending InfoBar request.
- void CancelPendingInfoBarRequest(int render_process_id,
- int render_view_id,
- int bridge_id);
-
- // This must only be accessed from the UI thread.
- Profile* const profile_;
-
- scoped_ptr<GeolocationInfoBarQueueController>
- geolocation_infobar_queue_controller_;
-
- DISALLOW_COPY_AND_ASSIGN(ChromeGeolocationPermissionContext);
-};
-
-#endif // CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_
diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc
deleted file mode 100644
index 86635ac..0000000
--- a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc
+++ /dev/null
@@ -1,495 +0,0 @@
-// 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 <set>
-
-#include "base/memory/scoped_vector.h"
-#include "chrome/browser/content_settings/tab_specific_content_settings.h"
-#include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
-#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
-#include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
-#include "chrome/browser/tab_contents/infobar.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
-#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
-#include "chrome/test/testing_profile.h"
-#include "content/browser/browser_thread.h"
-#include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h"
-#include "content/browser/geolocation/location_arbitrator.h"
-#include "content/browser/geolocation/location_provider.h"
-#include "content/browser/geolocation/mock_location_provider.h"
-#include "content/browser/renderer_host/mock_render_process_host.h"
-#include "content/browser/tab_contents/test_tab_contents.h"
-#include "chrome/common/chrome_notification_types.h"
-#include "content/common/geolocation_messages.h"
-#include "content/common/notification_registrar.h"
-#include "content/common/notification_service.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-// ClosedDelegateTracker ------------------------------------------------------
-
-namespace {
-
-// We need to track which infobars were closed.
-class ClosedDelegateTracker : public NotificationObserver {
- public:
- ClosedDelegateTracker();
- virtual ~ClosedDelegateTracker();
-
- // NotificationObserver:
- virtual void Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- size_t size() const {
- return removed_infobar_delegates_.size();
- }
-
- bool Contains(InfoBarDelegate* delegate) const;
- void Clear();
-
- private:
- NotificationRegistrar registrar_;
- std::set<InfoBarDelegate*> removed_infobar_delegates_;
-};
-
-ClosedDelegateTracker::ClosedDelegateTracker() {
- registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
- NotificationService::AllSources());
-}
-
-ClosedDelegateTracker::~ClosedDelegateTracker() {
-}
-
-void ClosedDelegateTracker::Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED);
- removed_infobar_delegates_.insert(
- Details<InfoBarRemovedDetails>(details)->first);
-}
-
-bool ClosedDelegateTracker::Contains(InfoBarDelegate* delegate) const {
- return removed_infobar_delegates_.count(delegate) != 0;
-}
-
-void ClosedDelegateTracker::Clear() {
- removed_infobar_delegates_.clear();
-}
-
-} // namespace
-
-
-// GeolocationPermissionContextTests ------------------------------------------
-
-// This class sets up GeolocationArbitrator.
-class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness {
- public:
- GeolocationPermissionContextTests();
-
- protected:
- virtual ~GeolocationPermissionContextTests();
-
- int process_id() { return contents()->render_view_host()->process()->id(); }
- int process_id_for_tab(int tab) {
- return extra_tabs_[tab]->tab_contents()->render_view_host()->process()->
- id();
- }
- int render_id() { return contents()->render_view_host()->routing_id(); }
- int render_id_for_tab(int tab) {
- return extra_tabs_[tab]->tab_contents()->render_view_host()->routing_id();
- }
- int bridge_id() const { return 42; } // Not relevant at this level.
-
- void CheckPermissionMessageSent(int bridge_id, bool allowed);
- void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed);
- void CheckPermissionMessageSentInternal(MockRenderProcessHost* process,
- int bridge_id,
- bool allowed);
- void AddNewTab(const GURL& url);
- void CheckTabContentsState(const GURL& requesting_frame,
- ContentSetting expected_content_setting);
-
- scoped_refptr<ChromeGeolocationPermissionContext>
- geolocation_permission_context_;
- ClosedDelegateTracker closed_delegate_tracker_;
- ScopedVector<TabContentsWrapper> extra_tabs_;
-
- private:
- // TabContentsWrapperTestHarness:
- virtual void SetUp();
- virtual void TearDown();
-
- BrowserThread ui_thread_;
- scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_;
-};
-
-GeolocationPermissionContextTests::GeolocationPermissionContextTests()
- : TabContentsWrapperTestHarness(),
- ui_thread_(BrowserThread::UI, MessageLoop::current()),
- dependency_factory_(
- new GeolocationArbitratorDependencyFactoryWithLocationProvider(
- &NewAutoSuccessMockNetworkLocationProvider)) {
-}
-
-GeolocationPermissionContextTests::~GeolocationPermissionContextTests() {
-}
-
-void GeolocationPermissionContextTests::CheckPermissionMessageSent(
- int bridge_id,
- bool allowed) {
- CheckPermissionMessageSentInternal(process(), bridge_id, allowed);
-}
-
-void GeolocationPermissionContextTests::CheckPermissionMessageSentForTab(
- int tab,
- int bridge_id,
- bool allowed) {
- CheckPermissionMessageSentInternal(static_cast<MockRenderProcessHost*>(
- extra_tabs_[tab]->tab_contents()->render_view_host()->process()),
- bridge_id, allowed);
-}
-
-void GeolocationPermissionContextTests::CheckPermissionMessageSentInternal(
- MockRenderProcessHost* process,
- int bridge_id,
- bool allowed) {
- MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
- MessageLoop::current()->Run();
- const IPC::Message* message = process->sink().GetFirstMessageMatching(
- GeolocationMsg_PermissionSet::ID);
- ASSERT_TRUE(message);
- GeolocationMsg_PermissionSet::Param param;
- GeolocationMsg_PermissionSet::Read(message, &param);
- EXPECT_EQ(bridge_id, param.a);
- EXPECT_EQ(allowed, param.b);
- process->sink().ClearMessages();
-}
-
-void GeolocationPermissionContextTests::AddNewTab(const GURL& url) {
- TabContents* new_tab =
- new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
- new_tab->controller().LoadURL(url, GURL(), PageTransition::TYPED);
- static_cast<TestRenderViewHost*>(new_tab->render_manager()->current_host())->
- SendNavigate(extra_tabs_.size() + 1, url);
- extra_tabs_.push_back(new TabContentsWrapper(new_tab));
-}
-
-void GeolocationPermissionContextTests::CheckTabContentsState(
- const GURL& requesting_frame,
- ContentSetting expected_content_setting) {
- TabSpecificContentSettings* content_settings =
- contents_wrapper()->content_settings();
- const GeolocationSettingsState::StateMap& state_map =
- content_settings->geolocation_settings_state().state_map();
- EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin()));
- EXPECT_EQ(0U, state_map.count(requesting_frame));
- GeolocationSettingsState::StateMap::const_iterator settings =
- state_map.find(requesting_frame.GetOrigin());
- ASSERT_FALSE(settings == state_map.end())
- << "geolocation state not found " << requesting_frame;
- EXPECT_EQ(expected_content_setting, settings->second);
-}
-
-void GeolocationPermissionContextTests::SetUp() {
- TabContentsWrapperTestHarness::SetUp();
- GeolocationArbitrator::SetDependencyFactoryForTest(
- dependency_factory_.get());
- geolocation_permission_context_ =
- new ChromeGeolocationPermissionContext(profile());
-}
-
-void GeolocationPermissionContextTests::TearDown() {
- GeolocationArbitrator::SetDependencyFactoryForTest(NULL);
- TabContentsWrapperTestHarness::TearDown();
-}
-
-
-// Tests ----------------------------------------------------------------------
-
-TEST_F(GeolocationPermissionContextTests, SinglePermission) {
- GURL requesting_frame("http://www.example.com/geolocation");
- NavigateAndCommit(requesting_frame);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id(), render_id(), bridge_id(), requesting_frame);
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
- ConfirmInfoBarDelegate* infobar_0 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
- infobar_0->Cancel();
- contents_wrapper()->RemoveInfoBar(infobar_0);
- EXPECT_EQ(1U, closed_delegate_tracker_.size());
- EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
- infobar_0->InfoBarClosed();
-}
-
-TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
- GURL requesting_frame_0("http://www.example.com/geolocation");
- GURL requesting_frame_1("http://www.example-2.com/geolocation");
- EXPECT_EQ(CONTENT_SETTING_ASK,
- profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
- requesting_frame_0, requesting_frame_0));
- EXPECT_EQ(CONTENT_SETTING_ASK,
- profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
- requesting_frame_1, requesting_frame_0));
-
- NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
- // Request permission for two frames.
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id(), render_id(), bridge_id(), requesting_frame_0);
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
- // Ensure only one infobar is created.
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
- ConfirmInfoBarDelegate* infobar_0 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_0);
- string16 text_0 = infobar_0->GetMessageText();
-
- // Accept the first frame.
- infobar_0->Accept();
- CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
- CheckPermissionMessageSent(bridge_id(), true);
-
- contents_wrapper()->RemoveInfoBar(infobar_0);
- EXPECT_EQ(1U, closed_delegate_tracker_.size());
- EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
- closed_delegate_tracker_.Clear();
- infobar_0->InfoBarClosed();
- // Now we should have a new infobar for the second frame.
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
-
- ConfirmInfoBarDelegate* infobar_1 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_1);
- string16 text_1 = infobar_1->GetMessageText();
- EXPECT_NE(text_0, text_1);
-
- // Cancel (block) this frame.
- infobar_1->Cancel();
- CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
- CheckPermissionMessageSent(bridge_id() + 1, false);
- contents_wrapper()->RemoveInfoBar(infobar_1);
- EXPECT_EQ(1U, closed_delegate_tracker_.size());
- EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
- infobar_1->InfoBarClosed();
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
- // Ensure the persisted permissions are ok.
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
- requesting_frame_0, requesting_frame_0));
- EXPECT_EQ(CONTENT_SETTING_BLOCK,
- profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
- requesting_frame_1, requesting_frame_0));
-}
-
-TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
- GURL requesting_frame_0("http://www.example.com/geolocation");
- GURL requesting_frame_1("http://www.example-2.com/geolocation");
- EXPECT_EQ(CONTENT_SETTING_ASK,
- profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
- requesting_frame_0, requesting_frame_0));
- EXPECT_EQ(CONTENT_SETTING_ASK,
- profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
- requesting_frame_1, requesting_frame_0));
-
- NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
- // Request permission for two frames.
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id(), render_id(), bridge_id(), requesting_frame_0);
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
-
- ConfirmInfoBarDelegate* infobar_0 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_0);
- string16 text_0 = infobar_0->GetMessageText();
-
- // Simulate the frame going away, ensure the infobar for this frame
- // is removed and the next pending infobar is created.
- geolocation_permission_context_->CancelGeolocationPermissionRequest(
- process_id(), render_id(), bridge_id(), requesting_frame_0);
- EXPECT_EQ(1U, closed_delegate_tracker_.size());
- EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
- closed_delegate_tracker_.Clear();
- infobar_0->InfoBarClosed();
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
-
- ConfirmInfoBarDelegate* infobar_1 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_1);
- string16 text_1 = infobar_1->GetMessageText();
- EXPECT_NE(text_0, text_1);
-
- // Allow this frame.
- infobar_1->Accept();
- CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
- CheckPermissionMessageSent(bridge_id() + 1, true);
- contents_wrapper()->RemoveInfoBar(infobar_1);
- EXPECT_EQ(1U, closed_delegate_tracker_.size());
- EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
- infobar_1->InfoBarClosed();
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
- // Ensure the persisted permissions are ok.
- EXPECT_EQ(CONTENT_SETTING_ASK,
- profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
- requesting_frame_0, requesting_frame_0));
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
- requesting_frame_1, requesting_frame_0));
-}
-
-TEST_F(GeolocationPermissionContextTests, InvalidURL) {
- GURL invalid_embedder;
- GURL requesting_frame("about:blank");
- NavigateAndCommit(invalid_embedder);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id(), render_id(), bridge_id(), requesting_frame);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
- CheckPermissionMessageSent(bridge_id(), false);
-}
-
-TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
- GURL url_a("http://www.example.com/geolocation");
- GURL url_b("http://www.example-2.com/geolocation");
- NavigateAndCommit(url_a);
- AddNewTab(url_b);
- AddNewTab(url_a);
-
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id(), render_id(), bridge_id(), url_a);
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
-
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b);
- EXPECT_EQ(1U, extra_tabs_[0]->infobar_count());
-
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a);
- ASSERT_EQ(1U, extra_tabs_[1]->infobar_count());
-
- ConfirmInfoBarDelegate* removed_infobar =
- extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
-
- // Accept the first tab.
- ConfirmInfoBarDelegate* infobar_0 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_0);
- infobar_0->Accept();
- CheckPermissionMessageSent(bridge_id(), true);
- contents_wrapper()->RemoveInfoBar(infobar_0);
- EXPECT_EQ(2U, closed_delegate_tracker_.size());
- EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
- infobar_0->InfoBarClosed();
- // Now the infobar for the tab with the same origin should have gone.
- EXPECT_EQ(0U, extra_tabs_[1]->infobar_count());
- CheckPermissionMessageSentForTab(1, bridge_id(), true);
- EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
- closed_delegate_tracker_.Clear();
- // Destroy the infobar that has just been removed.
- removed_infobar->InfoBarClosed();
-
- // But the other tab should still have the info bar...
- ASSERT_EQ(1U, extra_tabs_[0]->infobar_count());
- ConfirmInfoBarDelegate* infobar_1 =
- extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
- infobar_1->Cancel();
- extra_tabs_[0]->RemoveInfoBar(infobar_1);
- EXPECT_EQ(1U, closed_delegate_tracker_.size());
- EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
- infobar_1->InfoBarClosed();
-
- extra_tabs_.reset();
-}
-
-TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
- GURL url_a("http://www.example.com/geolocation");
- GURL url_b("http://www.example-2.com/geolocation");
- NavigateAndCommit(url_a);
- AddNewTab(url_a);
-
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id(), render_id(), bridge_id(), url_a);
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
-
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a);
- EXPECT_EQ(1U, extra_tabs_[0]->infobar_count());
-
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b);
- ASSERT_EQ(1U, extra_tabs_[0]->infobar_count());
-
- ConfirmInfoBarDelegate* removed_infobar =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
-
- // Accept the second tab.
- ConfirmInfoBarDelegate* infobar_0 =
- extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_0);
- infobar_0->Accept();
- CheckPermissionMessageSentForTab(0, bridge_id(), true);
- extra_tabs_[0]->RemoveInfoBar(infobar_0);
- EXPECT_EQ(2U, closed_delegate_tracker_.size());
- EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
- infobar_0->InfoBarClosed();
- // Now the infobar for the tab with the same origin should have gone.
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
- CheckPermissionMessageSent(bridge_id(), true);
- EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
- closed_delegate_tracker_.Clear();
- // Destroy the infobar that has just been removed.
- removed_infobar->InfoBarClosed();
-
- // And we should have the queued infobar displayed now.
- ASSERT_EQ(1U, extra_tabs_[0]->infobar_count());
-
- // Accept the second infobar.
- ConfirmInfoBarDelegate* infobar_1 =
- extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_1);
- infobar_1->Accept();
- CheckPermissionMessageSentForTab(0, bridge_id() + 1, true);
- extra_tabs_[0]->RemoveInfoBar(infobar_1);
- EXPECT_EQ(1U, closed_delegate_tracker_.size());
- EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
- infobar_1->InfoBarClosed();
-
- extra_tabs_.reset();
-}
-
-TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
- GURL requesting_frame_0("http://www.example.com/geolocation");
- GURL requesting_frame_1("http://www.example-2.com/geolocation");
- EXPECT_EQ(
- CONTENT_SETTING_ASK,
- profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
- requesting_frame_0, requesting_frame_0));
- EXPECT_EQ(
- CONTENT_SETTING_ASK,
- profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
- requesting_frame_1, requesting_frame_0));
-
- NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
- // Request permission for two frames.
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id(), render_id(), bridge_id(), requesting_frame_0);
- geolocation_permission_context_->RequestGeolocationPermission(
- process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
- // Ensure only one infobar is created.
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
- ConfirmInfoBarDelegate* infobar_0 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_0);
-
- // Delete the tab contents.
- DeleteContents();
- infobar_0->InfoBarClosed();
-}
diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc
deleted file mode 100644
index 01cf36e..0000000
--- a/chrome/browser/geolocation/geolocation_browsertest.cc
+++ /dev/null
@@ -1,654 +0,0 @@
-// 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 "base/compiler_specific.h"
-#include "base/stringprintf.h"
-#include "base/string_number_conversions.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/content_settings/tab_specific_content_settings.h"
-#include "chrome/browser/dom_operation_notification_details.h"
-#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
-#include "chrome/browser/geolocation/geolocation_settings_state.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
-#include "chrome/browser/tab_contents/infobar.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
-#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/test/in_process_browser_test.h"
-#include "chrome/test/ui_test_utils.h"
-#include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h"
-#include "content/browser/geolocation/location_arbitrator.h"
-#include "content/browser/geolocation/mock_location_provider.h"
-#include "content/browser/renderer_host/render_view_host.h"
-#include "content/browser/tab_contents/tab_contents.h"
-#include "content/common/geoposition.h"
-#include "content/common/notification_details.h"
-#include "content/common/notification_service.h"
-#include "net/base/net_util.h"
-#include "net/test/test_server.h"
-
-namespace {
-
-// Used to block until an iframe is loaded via a javascript call.
-// Note: NavigateToURLBlockUntilNavigationsComplete doesn't seem to work for
-// multiple embedded iframes, as notifications seem to be 'batched'. Instead, we
-// load and wait one single frame here by calling a javascript function.
-class IFrameLoader : public NotificationObserver {
- public:
- IFrameLoader(Browser* browser, int iframe_id, const GURL& url)
- : navigation_completed_(false),
- javascript_completed_(false) {
- NavigationController* controller =
- &browser->GetSelectedTabContents()->controller();
- registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
- Source<NavigationController>(controller));
- registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE,
- NotificationService::AllSources());
- std::string script = base::StringPrintf(
- "window.domAutomationController.setAutomationId(0);"
- "window.domAutomationController.send(addIFrame(%d, \"%s\"));",
- iframe_id,
- url.spec().c_str());
- browser->GetSelectedTabContents()->render_view_host()->
- ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(script));
- ui_test_utils::RunMessageLoop();
-
- EXPECT_EQ(base::StringPrintf("\"%d\"", iframe_id), javascript_response_);
- registrar_.RemoveAll();
- // Now that we loaded the iframe, let's fetch its src.
- script = base::StringPrintf(
- "window.domAutomationController.send(getIFrameSrc(%d))", iframe_id);
- std::string iframe_src;
- EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
- browser->GetSelectedTabContents()->render_view_host(),
- L"", UTF8ToWide(script), &iframe_src));
- iframe_url_ = GURL(iframe_src);
- }
-
- GURL iframe_url() const { return iframe_url_; }
-
- virtual void Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- if (type == content::NOTIFICATION_LOAD_STOP) {
- navigation_completed_ = true;
- } else if (type == chrome::NOTIFICATION_DOM_OPERATION_RESPONSE) {
- Details<DomOperationNotificationDetails> dom_op_details(details);
- javascript_response_ = dom_op_details->json();
- javascript_completed_ = true;
- }
- if (javascript_completed_ && navigation_completed_)
- MessageLoopForUI::current()->Quit();
- }
-
- private:
- NotificationRegistrar registrar_;
-
- // If true the navigation has completed.
- bool navigation_completed_;
-
- // If true the javascript call has completed.
- bool javascript_completed_;
-
- std::string javascript_response_;
-
- // The URL for the iframe we just loaded.
- GURL iframe_url_;
-
- DISALLOW_COPY_AND_ASSIGN(IFrameLoader);
-};
-
-class GeolocationNotificationObserver : public NotificationObserver {
- public:
- // If |wait_for_infobar| is true, AddWatchAndWaitForNotification will block
- // until the infobar has been displayed; otherwise it will block until the
- // navigation is completed.
- explicit GeolocationNotificationObserver(bool wait_for_infobar)
- : wait_for_infobar_(wait_for_infobar),
- infobar_(NULL),
- navigation_started_(false),
- navigation_completed_(false) {
- registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE,
- NotificationService::AllSources());
- if (wait_for_infobar) {
- registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
- NotificationService::AllSources());
- } else {
- registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- NotificationService::AllSources());
- registrar_.Add(this, content::NOTIFICATION_LOAD_START,
- NotificationService::AllSources());
- registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
- NotificationService::AllSources());
- }
- }
-
- void AddWatchAndWaitForNotification(RenderViewHost* render_view_host,
- const std::wstring& iframe_xpath) {
- LOG(WARNING) << "will add geolocation watch";
- std::string script =
- "window.domAutomationController.setAutomationId(0);"
- "window.domAutomationController.send(geoStart());";
- render_view_host->ExecuteJavascriptInWebFrame(WideToUTF16Hack(iframe_xpath),
- UTF8ToUTF16(script));
- ui_test_utils::RunMessageLoop();
- registrar_.RemoveAll();
- LOG(WARNING) << "got geolocation watch" << javascript_response_;
- EXPECT_NE("\"0\"", javascript_response_);
- if (wait_for_infobar_) {
- EXPECT_TRUE(infobar_);
- } else {
- EXPECT_TRUE(navigation_completed_);
- }
- }
-
- // NotificationObserver
- virtual void Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- if (type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED) {
- infobar_ = Details<InfoBarAddedDetails>(details).ptr();
- ASSERT_TRUE(infobar_->GetIcon());
- ASSERT_TRUE(infobar_->AsConfirmInfoBarDelegate());
- } else if (type == chrome::NOTIFICATION_DOM_OPERATION_RESPONSE) {
- Details<DomOperationNotificationDetails> dom_op_details(details);
- javascript_response_ = dom_op_details->json();
- LOG(WARNING) << "javascript_response " << javascript_response_;
- } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED ||
- type == content::NOTIFICATION_LOAD_START) {
- navigation_started_ = true;
- } else if (type == content::NOTIFICATION_LOAD_STOP) {
- if (navigation_started_) {
- navigation_started_ = false;
- navigation_completed_ = true;
- }
- }
-
- // We're either waiting for just the inforbar, or for both a javascript
- // prompt and response.
- if (wait_for_infobar_ && infobar_)
- MessageLoopForUI::current()->Quit();
- else if (navigation_completed_ && !javascript_response_.empty())
- MessageLoopForUI::current()->Quit();
- }
-
- NotificationRegistrar registrar_;
- bool wait_for_infobar_;
- InfoBarDelegate* infobar_;
- bool navigation_started_;
- bool navigation_completed_;
- std::string javascript_response_;
-};
-
-void NotifyGeoposition(const Geoposition& geoposition) {
- DCHECK(MockLocationProvider::instance_);
- MockLocationProvider::instance_->HandlePositionChanged(geoposition);
- LOG(WARNING) << "MockLocationProvider listeners updated";
-}
-
-// This is a browser test for Geolocation.
-// It exercises various integration points from javascript <-> browser:
-// 1. Infobar is displayed when a geolocation is requested from an unauthorized
-// origin.
-// 2. Denying the infobar triggers the correct error callback.
-// 3. Allowing the infobar does not trigger an error, and allow a geoposition to
-// be passed to javascript.
-// 4. Permissions persisted in disk are respected.
-// 5. Incognito profiles don't use saved permissions.
-class GeolocationBrowserTest : public InProcessBrowserTest {
- public:
- GeolocationBrowserTest()
- : infobar_(NULL),
- current_browser_(NULL),
- html_for_tests_("files/geolocation/simple.html"),
- started_test_server_(false),
- dependency_factory_(
- new GeolocationArbitratorDependencyFactoryWithLocationProvider(
- &NewAutoSuccessMockNetworkLocationProvider)) {
- EnableDOMAutomation();
- }
-
- // InProcessBrowserTest
- virtual void SetUpInProcessBrowserTestFixture() {
- GeolocationArbitrator::SetDependencyFactoryForTest(
- dependency_factory_.get());
- }
-
- // InProcessBrowserTest
- virtual void TearDownInProcessBrowserTestFixture() {
- LOG(WARNING) << "TearDownInProcessBrowserTestFixture. Test Finished.";
- GeolocationArbitrator::SetDependencyFactoryForTest(NULL);
- }
-
- enum InitializationOptions {
- INITIALIZATION_NONE,
- INITIALIZATION_OFFTHERECORD,
- INITIALIZATION_NEWTAB,
- INITIALIZATION_IFRAMES,
- };
-
- bool Initialize(InitializationOptions options) WARN_UNUSED_RESULT {
- if (!started_test_server_)
- started_test_server_ = test_server()->Start();
- EXPECT_TRUE(started_test_server_);
- if (!started_test_server_)
- return false;
-
- current_url_ = test_server()->GetURL(html_for_tests_);
- LOG(WARNING) << "before navigate";
- if (options == INITIALIZATION_OFFTHERECORD) {
- ui_test_utils::OpenURLOffTheRecord(browser()->profile(), current_url_);
- current_browser_ = BrowserList::FindTabbedBrowser(
- browser()->profile()->GetOffTheRecordProfile(), false);
- } else if (options == INITIALIZATION_NEWTAB) {
- current_browser_ = browser();
- current_browser_->NewTab();
- ui_test_utils::NavigateToURL(current_browser_, current_url_);
- } else if (options == INITIALIZATION_IFRAMES) {
- current_browser_ = browser();
- ui_test_utils::NavigateToURL(current_browser_, current_url_);
- } else {
- current_browser_ = browser();
- ui_test_utils::NavigateToURL(current_browser_, current_url_);
- }
- LOG(WARNING) << "after navigate";
-
- EXPECT_TRUE(current_browser_);
- if (!current_browser_)
- return false;
-
- return true;
- }
-
- void LoadIFrames(int number_iframes) {
- // Limit to 3 iframes.
- DCHECK(0 < number_iframes && number_iframes <= 3);
- iframe_urls_.resize(number_iframes);
- for (int i = 0; i < number_iframes; ++i) {
- IFrameLoader loader(current_browser_, i, GURL());
- iframe_urls_[i] = loader.iframe_url();
- }
- }
-
- void AddGeolocationWatch(bool wait_for_infobar) {
- GeolocationNotificationObserver notification_observer(wait_for_infobar);
- notification_observer.AddWatchAndWaitForNotification(
- current_browser_->GetSelectedTabContents()->render_view_host(),
- iframe_xpath_);
- if (wait_for_infobar) {
- EXPECT_TRUE(notification_observer.infobar_);
- infobar_ = notification_observer.infobar_;
- }
- }
-
- Geoposition GeopositionFromLatLong(double latitude, double longitude) {
- Geoposition geoposition;
- geoposition.latitude = latitude;
- geoposition.longitude = longitude;
- geoposition.accuracy = 0;
- geoposition.error_code = Geoposition::ERROR_CODE_NONE;
- // Webkit compares the timestamp to wall clock time, so we need
- // it to be contemporary.
- geoposition.timestamp = base::Time::Now();
- EXPECT_TRUE(geoposition.IsValidFix());
- return geoposition;
- }
-
- void CheckGeoposition(const Geoposition& geoposition) {
- // Checks we have no error.
- CheckStringValueFromJavascript("0", "geoGetLastError()");
- CheckStringValueFromJavascript(base::DoubleToString(geoposition.latitude),
- "geoGetLastPositionLatitude()");
- CheckStringValueFromJavascript(base::DoubleToString(geoposition.longitude),
- "geoGetLastPositionLongitude()");
- }
-
- void SetInfobarResponse(const GURL& requesting_url, bool allowed) {
- TabContentsWrapper* tab_contents_wrapper =
- current_browser_->GetSelectedTabContentsWrapper();
- TabSpecificContentSettings* content_settings =
- tab_contents_wrapper->content_settings();
- const GeolocationSettingsState& settings_state =
- content_settings->geolocation_settings_state();
- size_t state_map_size = settings_state.state_map().size();
- ASSERT_TRUE(infobar_);
- LOG(WARNING) << "will set infobar response";
- if (allowed)
- infobar_->AsConfirmInfoBarDelegate()->Accept();
- else
- infobar_->AsConfirmInfoBarDelegate()->Cancel();
- WaitForNavigation();
- tab_contents_wrapper->RemoveInfoBar(infobar_);
- LOG(WARNING) << "infobar response set";
- infobar_ = NULL;
- EXPECT_GT(settings_state.state_map().size(), state_map_size);
- GURL requesting_origin = requesting_url.GetOrigin();
- EXPECT_EQ(1U, settings_state.state_map().count(requesting_origin));
- ContentSetting expected_setting =
- allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
- EXPECT_EQ(expected_setting,
- settings_state.state_map().find(requesting_origin)->second);
- }
-
- void WaitForNavigation() {
- LOG(WARNING) << "will block for navigation";
- NavigationController* controller =
- &current_browser_->GetSelectedTabContents()->controller();
- ui_test_utils::WaitForNavigation(controller);
- LOG(WARNING) << "navigated";
- }
-
- void CheckStringValueFromJavascriptForTab(
- const std::string& expected, const std::string& function,
- TabContents* tab_contents) {
- std::string script = base::StringPrintf(
- "window.domAutomationController.send(%s)", function.c_str());
- std::string result;
- ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
- tab_contents->render_view_host(),
- iframe_xpath_, UTF8ToWide(script), &result));
- EXPECT_EQ(expected, result);
- }
-
- void CheckStringValueFromJavascript(
- const std::string& expected, const std::string& function) {
- CheckStringValueFromJavascriptForTab(
- expected, function, current_browser_->GetSelectedTabContents());
- }
-
- InfoBarDelegate* infobar_;
- Browser* current_browser_;
- // path element of a URL referencing the html content for this test.
- std::string html_for_tests_;
- // This member defines the iframe (or top-level page, if empty) where the
- // javascript calls will run.
- std::wstring iframe_xpath_;
- // The current url for the top level page.
- GURL current_url_;
- // If not empty, the GURLs for the iframes loaded by LoadIFrames().
- std::vector<GURL> iframe_urls_;
-
- // TODO(phajdan.jr): Remove after we can ask TestServer whether it is started.
- bool started_test_server_;
-
- scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_;
-};
-
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DisplaysPermissionBar) {
- ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
- AddGeolocationWatch(true);
-}
-
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, Geoposition) {
- ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
- AddGeolocationWatch(true);
- SetInfobarResponse(current_url_, true);
- CheckGeoposition(MockLocationProvider::instance_->position_);
-}
-
-// Crashy, http://crbug.com/70585.
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest,
- DISABLED_ErrorOnPermissionDenied) {
- ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
- AddGeolocationWatch(true);
- // Infobar was displayed, deny access and check for error code.
- SetInfobarResponse(current_url_, false);
- CheckStringValueFromJavascript("1", "geoGetLastError()");
-}
-
-// http://crbug.com/44589. Hangs on Mac, crashes on Windows
-#if defined(OS_MACOSX) || defined(OS_WIN)
-#define MAYBE_NoInfobarForSecondTab DISABLED_NoInfobarForSecondTab
-#else
-#define MAYBE_NoInfobarForSecondTab NoInfobarForSecondTab
-#endif
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForSecondTab) {
- ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
- AddGeolocationWatch(true);
- SetInfobarResponse(current_url_, true);
- // Disables further prompts from this tab.
- CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
-
- // Checks infobar will not be created a second tab.
- ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB));
- AddGeolocationWatch(false);
- CheckGeoposition(MockLocationProvider::instance_->position_);
-}
-
-// http://crbug.com/44589. Hangs on Mac, crashes on Windows
-#if defined(OS_MACOSX) || defined(OS_WIN)
-#define MAYBE_NoInfobarForDeniedOrigin DISABLED_NoInfobarForDeniedOrigin
-#else
-#define MAYBE_NoInfobarForDeniedOrigin NoInfobarForDeniedOrigin
-#endif
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForDeniedOrigin) {
- ASSERT_TRUE(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.
- CheckStringValueFromJavascript("1", "geoGetLastError()");
- // Checks infobar will not be created a second tab.
- ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB));
- AddGeolocationWatch(false);
- CheckStringValueFromJavascript("1", "geoGetLastError()");
-}
-
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForAllowedOrigin) {
- ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
- current_browser_->profile()->GetGeolocationContentSettingsMap()->
- SetContentSetting(current_url_, current_url_, CONTENT_SETTING_ALLOW);
- // Checks no infobar will be created and there's no error callback.
- AddGeolocationWatch(false);
- CheckGeoposition(MockLocationProvider::instance_->position_);
-}
-
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForOffTheRecord) {
- // First, check infobar will be created for regular profile
- ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
- AddGeolocationWatch(true);
- // Response will be persisted
- SetInfobarResponse(current_url_, true);
- CheckGeoposition(MockLocationProvider::instance_->position_);
- // Disables further prompts from this tab.
- CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
- // Go incognito, and checks no infobar will be created.
- ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD));
- AddGeolocationWatch(false);
- CheckGeoposition(MockLocationProvider::instance_->position_);
-}
-
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, IFramesWithFreshPosition) {
- html_for_tests_ = "files/geolocation/iframes_different_origin.html";
- ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES));
- LoadIFrames(2);
- LOG(WARNING) << "frames loaded";
-
- iframe_xpath_ = L"//iframe[@id='iframe_0']";
- AddGeolocationWatch(true);
- SetInfobarResponse(iframe_urls_[0], true);
- CheckGeoposition(MockLocationProvider::instance_->position_);
- // Disables further prompts from this iframe.
- CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
-
- // Test second iframe from a different origin with a cached geoposition will
- // create the infobar.
- iframe_xpath_ = L"//iframe[@id='iframe_1']";
- AddGeolocationWatch(true);
-
- // Back to the first frame, enable navigation and refresh geoposition.
- iframe_xpath_ = L"//iframe[@id='iframe_0']";
- CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)");
- // MockLocationProvider must have been created.
- ASSERT_TRUE(MockLocationProvider::instance_);
- Geoposition fresh_position = GeopositionFromLatLong(3.17, 4.23);
- NotifyGeoposition(fresh_position);
- WaitForNavigation();
- CheckGeoposition(fresh_position);
-
- // Disable navigation for this frame.
- CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
-
- // Now go ahead an authorize the second frame.
- iframe_xpath_ = L"//iframe[@id='iframe_1']";
- // Infobar was displayed, allow access and check there's no error code.
- SetInfobarResponse(iframe_urls_[1], true);
- LOG(WARNING) << "Checking position...";
- CheckGeoposition(fresh_position);
- LOG(WARNING) << "...done.";
-}
-
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, IFramesWithCachedPosition) {
- html_for_tests_ = "files/geolocation/iframes_different_origin.html";
- ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES));
- LoadIFrames(2);
-
- iframe_xpath_ = L"//iframe[@id='iframe_0']";
- AddGeolocationWatch(true);
- SetInfobarResponse(iframe_urls_[0], true);
- CheckGeoposition(MockLocationProvider::instance_->position_);
-
- // Refresh geoposition, but let's not yet create the watch on the second frame
- // so that it'll fetch from cache.
- // MockLocationProvider must have been created.
- ASSERT_TRUE(MockLocationProvider::instance_);
- Geoposition cached_position = GeopositionFromLatLong(5.67, 8.09);
- NotifyGeoposition(cached_position);
- WaitForNavigation();
- CheckGeoposition(cached_position);
-
- // Disable navigation for this frame.
- CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
-
- // Now go ahead an authorize the second frame.
- iframe_xpath_ = L"//iframe[@id='iframe_1']";
- AddGeolocationWatch(true);
- // WebKit will use its cache, but we also broadcast a position shortly
- // afterwards. We're only interested in the first navigation for the success
- // callback from the cached position.
- CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)");
- SetInfobarResponse(iframe_urls_[1], true);
- CheckGeoposition(cached_position);
-}
-
-// See http://crbug.com/56033
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest,
- DISABLED_CancelPermissionForFrame) {
- html_for_tests_ = "files/geolocation/iframes_different_origin.html";
- ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES));
- LoadIFrames(2);
- LOG(WARNING) << "frames loaded";
-
- iframe_xpath_ = L"//iframe[@id='iframe_0']";
- AddGeolocationWatch(true);
- SetInfobarResponse(iframe_urls_[0], true);
- CheckGeoposition(MockLocationProvider::instance_->position_);
- // Disables further prompts from this iframe.
- CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
-
- // Test second iframe from a different origin with a cached geoposition will
- // create the infobar.
- iframe_xpath_ = L"//iframe[@id='iframe_1']";
- AddGeolocationWatch(true);
-
- size_t num_infobars_before_cancel =
- current_browser_->GetSelectedTabContentsWrapper()->infobar_count();
- // Change the iframe, and ensure the infobar is gone.
- IFrameLoader change_iframe_1(current_browser_, 1, current_url_);
- size_t num_infobars_after_cancel =
- current_browser_->GetSelectedTabContentsWrapper()->infobar_count();
- EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1);
-}
-
-// Disabled, http://crbug.com/66959.
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_InvalidUrlRequest) {
- // Tests that an invalid URL (e.g. from a popup window) is rejected
- // correctly. Also acts as a regression test for http://crbug.com/40478
- html_for_tests_ = "files/geolocation/invalid_request_url.html";
- ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
- TabContents* original_tab = current_browser_->GetSelectedTabContents();
- CheckStringValueFromJavascript("1", "requestGeolocationFromInvalidUrl()");
- CheckStringValueFromJavascriptForTab("1", "isAlive()", original_tab);
-}
-
-// Crashy, http://crbug.com/66400.
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_NoInfoBarBeforeStart) {
- // See http://crbug.com/42789
- html_for_tests_ = "files/geolocation/iframes_different_origin.html";
- ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES));
- LoadIFrames(2);
- LOG(WARNING) << "frames loaded";
-
- // Access navigator.geolocation, but ensure it won't request permission.
- iframe_xpath_ = L"//iframe[@id='iframe_1']";
- CheckStringValueFromJavascript("object", "geoAccessNavigatorGeolocation()");
-
- iframe_xpath_ = L"//iframe[@id='iframe_0']";
- AddGeolocationWatch(true);
- SetInfobarResponse(iframe_urls_[0], true);
- CheckGeoposition(MockLocationProvider::instance_->position_);
- CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
-
- // Permission should be requested after adding a watch.
- iframe_xpath_ = L"//iframe[@id='iframe_1']";
- AddGeolocationWatch(true);
- SetInfobarResponse(iframe_urls_[1], true);
- CheckGeoposition(MockLocationProvider::instance_->position_);
-}
-
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) {
- html_for_tests_ = "files/geolocation/two_watches.html";
- ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
- // First, set the JavaScript to navigate when it receives |final_position|.
- const Geoposition final_position = GeopositionFromLatLong(3.17, 4.23);
- std::string script = base::StringPrintf(
- "window.domAutomationController.send(geoSetFinalPosition(%f, %f))",
- final_position.latitude, final_position.longitude);
- std::string js_result;
- EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
- current_browser_->GetSelectedTabContents()->render_view_host(),
- L"", UTF8ToWide(script), &js_result));
- EXPECT_EQ(js_result, "ok");
-
- // Send a position which both geolocation watches will receive.
- AddGeolocationWatch(true);
- SetInfobarResponse(current_url_, true);
- CheckGeoposition(MockLocationProvider::instance_->position_);
-
- // The second watch will now have cancelled. Ensure an update still makes
- // its way through to the first watcher.
- NotifyGeoposition(final_position);
- WaitForNavigation();
- CheckGeoposition(final_position);
-}
-
-// Hangs flakily, http://crbug.com/70588.
-IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_TabDestroyed) {
- html_for_tests_ = "files/geolocation/tab_destroyed.html";
- ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES));
- LoadIFrames(3);
-
- iframe_xpath_ = L"//iframe[@id='iframe_0']";
- AddGeolocationWatch(true);
-
- iframe_xpath_ = L"//iframe[@id='iframe_1']";
- AddGeolocationWatch(false);
-
- iframe_xpath_ = L"//iframe[@id='iframe_2']";
- AddGeolocationWatch(false);
-
- std::string script =
- "window.domAutomationController.setAutomationId(0);"
- "window.domAutomationController.send(window.close());";
- bool result =
- ui_test_utils::ExecuteJavaScript(
- current_browser_->GetSelectedTabContents()->render_view_host(),
- L"", UTF8ToWide(script));
- EXPECT_EQ(result, true);
-}
-
-} // namespace
diff --git a/chrome/browser/geolocation/geolocation_content_settings_map.cc b/chrome/browser/geolocation/geolocation_content_settings_map.cc
deleted file mode 100644
index 5620421..0000000
--- a/chrome/browser/geolocation/geolocation_content_settings_map.cc
+++ /dev/null
@@ -1,228 +0,0 @@
-// 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.
-
-// Implementation of the geolocation content settings map. Styled on
-// HostContentSettingsMap however unlike that class, this one does not hold
-// an additional in-memory copy of the settings as it does not need to support
-// thread safe synchronous access to the settings; all geolocation permissions
-// are read and written in the UI thread. (If in future this is no longer the
-// case, refer to http://codereview.chromium.org/1525018 for a previous version
-// with caching. Note that as we must observe the prefs store for settings
-// changes, e.g. coming from the sync engine, the simplest design would be to
-// always write-through changes straight to the prefs store, and rely on the
-// notification observer to subsequently update any cached copy).
-
-#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
-
-#include <string>
-
-#include "base/string_piece.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/content_settings/content_settings_details.h"
-#include "chrome/browser/content_settings/content_settings_pattern.h"
-#include "chrome/browser/content_settings/host_content_settings_map.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/prefs/scoped_user_pref_update.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/common/url_constants.h"
-#include "content/browser/browser_thread.h"
-#include "content/common/notification_service.h"
-#include "content/common/notification_source.h"
-#include "net/base/dns_util.h"
-#include "net/base/static_cookie_policy.h"
-
-GeolocationContentSettingsMap::GeolocationContentSettingsMap(Profile* profile)
- : profile_(profile) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- prefs_registrar_.Init(profile_->GetPrefs());
- prefs_registrar_.Add(prefs::kGeolocationContentSettings, this);
- notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
- Source<Profile>(profile_));
- notification_registrar_.Add(
- this,
- chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED,
- Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()));
-}
-
-// static
-void GeolocationContentSettingsMap::RegisterUserPrefs(PrefService* prefs) {
- prefs->RegisterDictionaryPref(prefs::kGeolocationContentSettings,
- PrefService::SYNCABLE_PREF);
-}
-
-ContentSetting GeolocationContentSettingsMap::GetContentSetting(
- const GURL& requesting_url,
- const GURL& embedding_url) const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(requesting_url.is_valid() && embedding_url.is_valid());
- GURL requesting_origin(requesting_url.GetOrigin());
- GURL embedding_origin(embedding_url.GetOrigin());
- DCHECK(requesting_origin.is_valid() && embedding_origin.is_valid());
- // If the profile is destroyed (and set to NULL) return CONTENT_SETTING_BLOCK.
- if (!profile_)
- return CONTENT_SETTING_BLOCK;
- const DictionaryValue* all_settings_dictionary =
- profile_->GetPrefs()->GetDictionary(prefs::kGeolocationContentSettings);
- // Careful: The returned value could be NULL if the pref has never been set.
- if (all_settings_dictionary != NULL) {
- DictionaryValue* requesting_origin_settings;
- if (all_settings_dictionary->GetDictionaryWithoutPathExpansion(
- requesting_origin.spec(), &requesting_origin_settings)) {
- int setting;
- if (requesting_origin_settings->GetIntegerWithoutPathExpansion(
- embedding_origin.spec(), &setting))
- return IntToContentSetting(setting);
- // Check for any-embedder setting
- if (requesting_origin != embedding_origin &&
- requesting_origin_settings->GetIntegerWithoutPathExpansion(
- "", &setting))
- return IntToContentSetting(setting);
- }
- }
- return profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
- CONTENT_SETTINGS_TYPE_GEOLOCATION);
-}
-
-GeolocationContentSettingsMap::AllOriginsSettings
- GeolocationContentSettingsMap::GetAllOriginsSettings() const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- AllOriginsSettings content_settings;
- const DictionaryValue* all_settings_dictionary =
- profile_->GetPrefs()->GetDictionary(prefs::kGeolocationContentSettings);
- // Careful: The returned value could be NULL if the pref has never been set.
- if (all_settings_dictionary != NULL) {
- for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys());
- i != all_settings_dictionary->end_keys(); ++i) {
- const std::string& origin(*i);
- GURL origin_as_url(origin);
- if (!origin_as_url.is_valid())
- continue;
- DictionaryValue* requesting_origin_settings_dictionary = NULL;
- bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion(
- origin, &requesting_origin_settings_dictionary);
- DCHECK(found);
- if (!requesting_origin_settings_dictionary)
- continue;
- GetOneOriginSettingsFromDictionary(
- requesting_origin_settings_dictionary,
- &content_settings[origin_as_url]);
- }
- }
- return content_settings;
-}
-
-void GeolocationContentSettingsMap::SetContentSetting(
- const GURL& requesting_url,
- const GURL& embedding_url,
- ContentSetting setting) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(requesting_url.is_valid());
- DCHECK(embedding_url.is_valid() || embedding_url.is_empty());
- GURL requesting_origin(requesting_url.GetOrigin());
- GURL embedding_origin(embedding_url.GetOrigin());
- DCHECK(requesting_origin.is_valid());
- DCHECK(embedding_origin.is_valid() || embedding_url.is_empty());
- if (!profile_)
- return;
- PrefService* prefs = profile_->GetPrefs();
-
- DictionaryPrefUpdate update(prefs, prefs::kGeolocationContentSettings);
- DictionaryValue* all_settings_dictionary = update.Get();
- DictionaryValue* requesting_origin_settings_dictionary = NULL;
- all_settings_dictionary->GetDictionaryWithoutPathExpansion(
- requesting_origin.spec(), &requesting_origin_settings_dictionary);
- if (setting == CONTENT_SETTING_DEFAULT) {
- if (requesting_origin_settings_dictionary) {
- requesting_origin_settings_dictionary->RemoveWithoutPathExpansion(
- embedding_origin.spec(), NULL);
- if (requesting_origin_settings_dictionary->empty())
- all_settings_dictionary->RemoveWithoutPathExpansion(
- requesting_origin.spec(), NULL);
- }
- } else {
- if (!requesting_origin_settings_dictionary) {
- requesting_origin_settings_dictionary = new DictionaryValue;
- all_settings_dictionary->SetWithoutPathExpansion(
- requesting_origin.spec(), requesting_origin_settings_dictionary);
- }
- DCHECK(requesting_origin_settings_dictionary);
- requesting_origin_settings_dictionary->SetWithoutPathExpansion(
- embedding_origin.spec(), Value::CreateIntegerValue(setting));
- }
-}
-
-void GeolocationContentSettingsMap::ResetToDefault() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (!profile_)
- return;
- PrefService* prefs = profile_->GetPrefs();
- prefs->ClearPref(prefs::kGeolocationContentSettings);
- profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
- CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_DEFAULT);
-}
-
-void GeolocationContentSettingsMap::NotifyObservers(
- const ContentSettingsDetails& details) {
- NotificationService::current()->Notify(
- chrome::NOTIFICATION_GEOLOCATION_SETTINGS_CHANGED,
- Source<GeolocationContentSettingsMap>(this),
- Details<const ContentSettingsDetails>(&details));
-}
-
-void GeolocationContentSettingsMap::Observe(
- int type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- if (type == chrome::NOTIFICATION_PREF_CHANGED) {
- } else if (type == chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED) {
- const ContentSettingsType& content_type =
- Details<ContentSettingsDetails>(details).ptr()->type();
- if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
- ContentSettingsDetails details(ContentSettingsPattern(),
- ContentSettingsPattern(),
- CONTENT_SETTINGS_TYPE_DEFAULT,
- std::string());
- NotifyObservers(details);
- }
- } else if (chrome::NOTIFICATION_PROFILE_DESTROYED == type) {
- UnregisterObservers();
- } else {
- NOTREACHED();
- }
-}
-
-void GeolocationContentSettingsMap::UnregisterObservers() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (!profile_)
- return;
- prefs_registrar_.RemoveAll();
- notification_registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
- Source<Profile>(profile_));
- profile_ = NULL;
-}
-
-GeolocationContentSettingsMap::~GeolocationContentSettingsMap() {
- UnregisterObservers();
-}
-
-// static
-void GeolocationContentSettingsMap::GetOneOriginSettingsFromDictionary(
- const DictionaryValue* dictionary,
- OneOriginSettings* one_origin_settings) {
- for (DictionaryValue::key_iterator i(dictionary->begin_keys());
- i != dictionary->end_keys(); ++i) {
- const std::string& target(*i);
- int setting = 0;
- bool found = dictionary->GetIntegerWithoutPathExpansion(target, &setting);
- DCHECK(found);
- GURL target_url(target);
- // An empty URL has a special meaning (wildcard), so only accept invalid
- // URLs if the original version was empty (avoids treating corrupted prefs
- // as the wildcard entry; see http://crbug.com/39685)
- if (target_url.is_valid() || target.empty())
- (*one_origin_settings)[target_url] = IntToContentSetting(setting);
- }
-}
diff --git a/chrome/browser/geolocation/geolocation_content_settings_map.h b/chrome/browser/geolocation/geolocation_content_settings_map.h
deleted file mode 100644
index 286e1f9..0000000
--- a/chrome/browser/geolocation/geolocation_content_settings_map.h
+++ /dev/null
@@ -1,112 +0,0 @@
-// 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.
-
-// Maps [requesting_origin, embedder] to content settings. Written on the UI
-// thread and read on any thread. One instance per profile. This is based on
-// HostContentSettingsMap but differs significantly in two aspects:
-// - It maps [requesting_origin.GetOrigin(), embedder.GetOrigin()] => setting
-// rather than host => setting.
-// - It manages only Geolocation.
-
-#ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_
-#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_
-#pragma once
-
-#include <map>
-
-#include "base/basictypes.h"
-#include "base/memory/ref_counted.h"
-#include "chrome/browser/prefs/pref_change_registrar.h"
-#include "chrome/common/content_settings.h"
-#include "content/common/notification_observer.h"
-#include "content/common/notification_registrar.h"
-#include "googleurl/src/gurl.h"
-
-class ContentSettingsDetails;
-class PrefService;
-class Profile;
-
-namespace base {
-class DictionaryValue;
-}
-
-class GeolocationContentSettingsMap
- : public base::RefCountedThreadSafe<GeolocationContentSettingsMap>,
- public NotificationObserver {
- public:
- typedef std::map<GURL, ContentSetting> OneOriginSettings;
- typedef std::map<GURL, OneOriginSettings> AllOriginsSettings;
-
- explicit GeolocationContentSettingsMap(Profile* profile);
-
- virtual ~GeolocationContentSettingsMap();
-
- static void RegisterUserPrefs(PrefService* prefs);
-
- // Returns a single ContentSetting which applies to the given |requesting_url|
- // when embedded in a top-level page from |embedding_url|. To determine the
- // setting for a top-level page, as opposed to a frame embedded in a page,
- // pass the page's URL for both arguments.
- //
- // This should only be called on the UI thread.
- // Both arguments should be valid GURLs.
- ContentSetting GetContentSetting(const GURL& requesting_url,
- const GURL& embedding_url) const;
-
- // Returns the settings for all origins with any non-default settings.
- //
- // This should only be called on the UI thread.
- AllOriginsSettings GetAllOriginsSettings() const;
-
- // Sets the content setting for a particular (requesting origin, embedding
- // origin) pair. If the embedding origin is the same as the requesting
- // origin, this represents the setting used when the requesting origin is
- // itself the top-level page. If |embedder| is the empty GURL, |setting|
- // becomes the default setting for the requesting origin when embedded on any
- // page that does not have an explicit setting. Passing
- // CONTENT_SETTING_DEFAULT for |setting| effectively removes that setting and
- // allows future requests to return the all-embedders or global defaults (as
- // applicable).
- //
- // This should only be called on the UI thread. |requesting_url| should be
- // a valid GURL, and |embedding_url| should be valid or empty.
- void SetContentSetting(const GURL& requesting_url,
- const GURL& embedding_url,
- ContentSetting setting);
-
- // Resets all settings.
- //
- // This should only be called on the UI thread.
- void ResetToDefault();
-
- // NotificationObserver implementation.
- virtual void Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- private:
- friend class base::RefCountedThreadSafe<GeolocationContentSettingsMap>;
-
- // Sends a CONTENT_SETTINGS_CHANGED notification.
- void NotifyObservers(const ContentSettingsDetails& details);
-
- void UnregisterObservers();
-
- // Sets the fields of |one_origin_settings| based on the values in
- // |dictionary|.
- static void GetOneOriginSettingsFromDictionary(
- const base::DictionaryValue* dictionary,
- OneOriginSettings* one_origin_settings);
-
- // The profile we're associated with.
- Profile* profile_;
-
- // Registrar to register for PREF_CHANGED notifications.
- PrefChangeRegistrar prefs_registrar_;
- NotificationRegistrar notification_registrar_;
-
- DISALLOW_COPY_AND_ASSIGN(GeolocationContentSettingsMap);
-};
-
-#endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_
diff --git a/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc b/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc
deleted file mode 100644
index b99abe7..0000000
--- a/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc
+++ /dev/null
@@ -1,317 +0,0 @@
-// 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 "base/message_loop.h"
-#include "chrome/browser/content_settings/content_settings_details.h"
-#include "chrome/browser/content_settings/host_content_settings_map.h"
-#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/prefs/scoped_user_pref_update.h"
-#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/test/testing_profile.h"
-#include "content/browser/browser_thread.h"
-#include "content/common/notification_registrar.h"
-#include "content/common/notification_service.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using ::testing::_;
-
-namespace {
-
-class MockGeolocationSettingsObserver : public NotificationObserver {
- public:
- MockGeolocationSettingsObserver();
-
- virtual void Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- MOCK_METHOD2(OnContentSettingsChanged,
- void(GeolocationContentSettingsMap*,
- ContentSettingsType));
-
- private:
- NotificationRegistrar registrar_;
-};
-
-MockGeolocationSettingsObserver::MockGeolocationSettingsObserver() {
- registrar_.Add(this, chrome::NOTIFICATION_GEOLOCATION_SETTINGS_CHANGED,
- NotificationService::AllSources());
-}
-
-void MockGeolocationSettingsObserver::Observe(
- int type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- GeolocationContentSettingsMap* map =
- Source<GeolocationContentSettingsMap>(source).ptr();
- ContentSettingsDetails* settings_details =
- Details<ContentSettingsDetails>(details).ptr();
- OnContentSettingsChanged(map,
- settings_details->type());
- // This checks that calling a Get function from an observer doesn't
- // deadlock.
- // TODO(bauerb): Move into expectation setup.
- map->GetContentSetting(GURL("http://random-hostname.com/"),
- GURL("http://foo.random-hostname.com/"));
-}
-
-class GeolocationContentSettingsMapTests : public testing::Test {
- public:
- GeolocationContentSettingsMapTests()
- : ui_thread_(BrowserThread::UI, &message_loop_) {
- }
-
- protected:
- MessageLoop message_loop_;
- BrowserThread ui_thread_;
-};
-
-TEST_F(GeolocationContentSettingsMapTests, Embedder) {
- TestingProfile profile;
- GeolocationContentSettingsMap* map =
- profile.GetGeolocationContentSettingsMap();
- GURL top_level("http://www.toplevel0.com/foo/bar");
- EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(top_level, top_level));
- // Now set the permission for requester_0.
- map->SetContentSetting(top_level, top_level, CONTENT_SETTING_ALLOW);
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(top_level, top_level));
-
- GURL requester_0("http://www.frame0.com/foo/bar");
- EXPECT_EQ(CONTENT_SETTING_ASK,
- map->GetContentSetting(requester_0, top_level));
- // Now set the permission for only requester_1.
- map->SetContentSetting(requester_0, top_level, CONTENT_SETTING_ALLOW);
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(top_level, top_level));
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(requester_0, top_level));
- // Block only requester_1.
- map->SetContentSetting(requester_0, top_level, CONTENT_SETTING_BLOCK);
- EXPECT_EQ(CONTENT_SETTING_BLOCK,
- map->GetContentSetting(requester_0, top_level));
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(top_level, top_level));
-}
-
-TEST_F(GeolocationContentSettingsMapTests, MultipleEmbeddersAndOrigins) {
- TestingProfile profile;
- GeolocationContentSettingsMap* map =
- profile.GetGeolocationContentSettingsMap();
- GURL requester_0("http://www.iframe0.com/foo/bar");
- GURL requester_1("http://www.iframe1.co.uk/bar/foo");
- GURL embedder_0("http://www.toplevel0.com/foo/bar");
- EXPECT_EQ(CONTENT_SETTING_ASK,
- map->GetContentSetting(requester_0, embedder_0));
- EXPECT_EQ(CONTENT_SETTING_ASK,
- map->GetContentSetting(requester_1, embedder_0));
- // Now set the permission for only one origin.
- map->SetContentSetting(requester_0, embedder_0, CONTENT_SETTING_ALLOW);
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(requester_0, embedder_0));
- EXPECT_EQ(CONTENT_SETTING_ASK,
- map->GetContentSetting(requester_1, embedder_0));
- // Set the permission for the other origin.
- map->SetContentSetting(requester_1, embedder_0, CONTENT_SETTING_ALLOW);
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(requester_1, embedder_0));
- // Check they're not allowed on a different embedder.
- GURL embedder_1("http://www.toplevel1.com/foo/bar");
- EXPECT_EQ(CONTENT_SETTING_ASK,
- map->GetContentSetting(requester_0, embedder_1));
- EXPECT_EQ(CONTENT_SETTING_ASK,
- map->GetContentSetting(requester_1, embedder_1));
- // Check all settings are valid.
- GeolocationContentSettingsMap::AllOriginsSettings content_settings(
- map->GetAllOriginsSettings());
- EXPECT_EQ(0U, content_settings.count(requester_0));
- EXPECT_EQ(1U, content_settings.count(requester_0.GetOrigin()));
- GeolocationContentSettingsMap::OneOriginSettings one_origin_settings(
- content_settings[requester_0.GetOrigin()]);
- EXPECT_EQ(CONTENT_SETTING_ALLOW, one_origin_settings[embedder_0.GetOrigin()]);
-
- EXPECT_EQ(0U, content_settings.count(requester_1));
- EXPECT_EQ(1U, content_settings.count(requester_1.GetOrigin()));
- one_origin_settings = content_settings[requester_1.GetOrigin()];
- EXPECT_EQ(CONTENT_SETTING_ALLOW, one_origin_settings[embedder_0.GetOrigin()]);
- // Block requester_1 on the first embedder and add it to the second.
- map->SetContentSetting(requester_1, embedder_0, CONTENT_SETTING_BLOCK);
- map->SetContentSetting(requester_1, embedder_1, CONTENT_SETTING_ALLOW);
- EXPECT_EQ(CONTENT_SETTING_BLOCK,
- map->GetContentSetting(requester_1, embedder_0));
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(requester_1, embedder_1));
-}
-
-TEST_F(GeolocationContentSettingsMapTests, SetContentSettingDefault) {
- TestingProfile profile;
- GeolocationContentSettingsMap* map =
- profile.GetGeolocationContentSettingsMap();
- GURL top_level("http://www.toplevel0.com/foo/bar");
- map->SetContentSetting(top_level, top_level, CONTENT_SETTING_ALLOW);
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(top_level, top_level));
- // Set to CONTENT_SETTING_DEFAULT and check the actual value has changed.
- map->SetContentSetting(top_level, top_level, CONTENT_SETTING_DEFAULT);
- EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(top_level, top_level));
-}
-
-TEST_F(GeolocationContentSettingsMapTests, Reset) {
- TestingProfile profile;
- GeolocationContentSettingsMap* map =
- profile.GetGeolocationContentSettingsMap();
- GURL requester_0("http://www.iframe0.com/foo/bar");
- GURL embedder_0("http://www.toplevel0.com/foo/bar");
- map->SetContentSetting(requester_0, embedder_0, CONTENT_SETTING_ALLOW);
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(requester_0, embedder_0));
- GeolocationContentSettingsMap::AllOriginsSettings content_settings(
- map->GetAllOriginsSettings());
- EXPECT_EQ(1U, content_settings.size());
-
- // Set to CONTENT_SETTING_DEFAULT and check the actual value has changed.
- map->SetContentSetting(requester_0, embedder_0, CONTENT_SETTING_DEFAULT);
- EXPECT_EQ(CONTENT_SETTING_ASK,
- map->GetContentSetting(requester_0, embedder_0));
- content_settings = map->GetAllOriginsSettings();
- EXPECT_TRUE(content_settings.empty());
-}
-
-TEST_F(GeolocationContentSettingsMapTests, ClearsWhenSettingBackToDefault) {
- TestingProfile profile;
- GeolocationContentSettingsMap* map =
- profile.GetGeolocationContentSettingsMap();
- GURL requester_0("http://www.iframe0.com/foo/bar");
- GURL requester_1("http://www.iframe1.com/foo/bar");
- GURL embedder_0("http://www.toplevel0.com/foo/bar");
- map->SetContentSetting(requester_0, embedder_0, CONTENT_SETTING_ALLOW);
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(requester_0, embedder_0));
- GeolocationContentSettingsMap::AllOriginsSettings content_settings(
- map->GetAllOriginsSettings());
- EXPECT_EQ(1U, content_settings.size());
-
- map->SetContentSetting(requester_1, embedder_0, CONTENT_SETTING_ALLOW);
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(requester_1, embedder_0));
- content_settings = map->GetAllOriginsSettings();
- EXPECT_EQ(2U, content_settings.size());
- EXPECT_EQ(1U, content_settings[requester_0.GetOrigin()].size());
- EXPECT_EQ(1U, content_settings[requester_1.GetOrigin()].size());
-
- // Set to default.
- map->SetContentSetting(requester_0, embedder_0, CONTENT_SETTING_DEFAULT);
- content_settings = map->GetAllOriginsSettings();
- EXPECT_EQ(1U, content_settings.size());
-
- map->SetContentSetting(requester_1, embedder_0, CONTENT_SETTING_DEFAULT);
- content_settings = map->GetAllOriginsSettings();
- EXPECT_TRUE(content_settings.empty());
-}
-
-TEST_F(GeolocationContentSettingsMapTests, WildCardForEmptyEmbedder) {
- TestingProfile profile;
- GeolocationContentSettingsMap* map =
- profile.GetGeolocationContentSettingsMap();
- GURL requester_0("http://www.iframe0.com/foo/bar");
- GURL embedder_0("http://www.toplevel0.com/foo/bar");
- GURL embedder_1("http://www.toplevel1.com/foo/bar");
- GURL empty_url;
- map->SetContentSetting(requester_0, embedder_0, CONTENT_SETTING_BLOCK);
- map->SetContentSetting(requester_0, empty_url, CONTENT_SETTING_ALLOW);
- EXPECT_EQ(CONTENT_SETTING_BLOCK,
- map->GetContentSetting(requester_0, embedder_0));
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(requester_0, embedder_1));
- EXPECT_EQ(CONTENT_SETTING_ASK,
- map->GetContentSetting(requester_0, requester_0));
-
- // Change the wildcard behavior.
- map->SetContentSetting(requester_0, embedder_0, CONTENT_SETTING_ALLOW);
- map->SetContentSetting(requester_0, empty_url, CONTENT_SETTING_BLOCK);
- profile.GetHostContentSettingsMap()->SetDefaultContentSetting(
- CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW);
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(requester_0, embedder_0));
- EXPECT_EQ(CONTENT_SETTING_BLOCK,
- map->GetContentSetting(requester_0, embedder_1));
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(requester_0, requester_0));
-}
-
-TEST_F(GeolocationContentSettingsMapTests, IgnoreInvalidURLsInPrefs) {
- TestingProfile profile;
- {
- DictionaryPrefUpdate update(profile.GetPrefs(),
- prefs::kGeolocationContentSettings);
- DictionaryValue* all_settings_dictionary = update.Get();
- // For simplicity, use the overloads that do path expansion. As '.' is the
- // path separator, we can't have dotted hostnames (which is fine).
- all_settings_dictionary->SetInteger("http://a/.http://b/",
- CONTENT_SETTING_ALLOW);
- all_settings_dictionary->SetInteger("bad_requester.http://b/",
- CONTENT_SETTING_ALLOW);
- all_settings_dictionary->SetInteger("http://a/.bad-embedder",
- CONTENT_SETTING_ALLOW);
- }
-
- GeolocationContentSettingsMap* map =
- profile.GetGeolocationContentSettingsMap();
- EXPECT_EQ(CONTENT_SETTING_ASK,
- profile.GetHostContentSettingsMap()->GetDefaultContentSetting(
- CONTENT_SETTINGS_TYPE_GEOLOCATION));
-
- // Check the valid entry was read OK.
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- map->GetContentSetting(GURL("http://a/"), GURL("http://b/")));
- // But everything else should be according to the default.
- EXPECT_EQ(CONTENT_SETTING_ASK,
- map->GetContentSetting(GURL("http://a/"),
- GURL("http://bad-embedder")));
- EXPECT_EQ(CONTENT_SETTING_ASK,
- map->GetContentSetting(GURL("http://a/"),
- GURL("http://example.com")));
- EXPECT_EQ(CONTENT_SETTING_ASK,
- map->GetContentSetting(GURL("http://bad_requester/"),
- GURL("http://b/")));
-}
-
-TEST_F(GeolocationContentSettingsMapTests, Observe) {
- TestingProfile profile;
- GeolocationContentSettingsMap* map =
- profile.GetGeolocationContentSettingsMap();
- MockGeolocationSettingsObserver observer;
-
- EXPECT_EQ(CONTENT_SETTING_ASK,
- profile.GetHostContentSettingsMap()->GetDefaultContentSetting(
- CONTENT_SETTINGS_TYPE_GEOLOCATION));
-
- // Test if a GEOLOCATION_SETTINGS_CHANGED notification is sent after
- // the geolocation default content setting was changed through calling the
- // SetDefaultContentSetting method.
- EXPECT_CALL(
- observer,
- OnContentSettingsChanged(map, CONTENT_SETTINGS_TYPE_DEFAULT));
- profile.GetHostContentSettingsMap()->SetDefaultContentSetting(
- CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK);
- ::testing::Mock::VerifyAndClearExpectations(&observer);
-
- // Test if a GEOLOCATION_SETTINGS_CHANGED notification is sent after the
- // obsolete preference kGeolocationDefaultContentSetting was changed.
- PrefService* prefs = profile.GetPrefs();
- EXPECT_CALL(
- observer,
- OnContentSettingsChanged(map, CONTENT_SETTINGS_TYPE_DEFAULT));
- prefs->SetInteger(prefs::kGeolocationDefaultContentSetting,
- CONTENT_SETTING_ALLOW);
-
- EXPECT_EQ(CONTENT_SETTING_ALLOW,
- profile.GetHostContentSettingsMap()->GetDefaultContentSetting(
- CONTENT_SETTINGS_TYPE_GEOLOCATION));
-}
-
-} // namespace
diff --git a/chrome/browser/geolocation/geolocation_exceptions_table_model.cc b/chrome/browser/geolocation/geolocation_exceptions_table_model.cc
deleted file mode 100644
index df32cb7..0000000
--- a/chrome/browser/geolocation/geolocation_exceptions_table_model.cc
+++ /dev/null
@@ -1,255 +0,0 @@
-// Copyright (c) 2010 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_exceptions_table_model.h"
-
-#include "ui/base/l10n/l10n_util.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/common/content_settings_helper.h"
-#include "chrome/common/url_constants.h"
-#include "grit/generated_resources.h"
-#include "ui/base/l10n/l10n_util_collator.h"
-#include "ui/base/models/table_model_observer.h"
-
-namespace {
-// Return -1, 0, or 1 depending on whether |origin1| should be sorted before,
-// equal to, or after |origin2|.
-int CompareOrigins(const GURL& origin1, const GURL& origin2) {
- if (origin1 == origin2)
- return 0;
-
- // Sort alphabetically by host name.
- std::string origin1_host(origin1.host());
- std::string origin2_host(origin2.host());
- if (origin1_host != origin2_host)
- return origin1_host < origin2_host ? -1 : 1;
-
- // We'll show non-HTTP schemes, so sort them alphabetically, but put HTTP
- // first.
- std::string origin1_scheme(origin1.scheme());
- std::string origin2_scheme(origin2.scheme());
- if (origin1_scheme != origin2_scheme) {
- if (origin1_scheme == chrome::kHttpScheme)
- return -1;
- if (origin2_scheme == chrome::kHttpScheme)
- return 1;
- return origin1_scheme < origin2_scheme ? -1 : 1;
- }
-
- // Sort by port number. This has to differ if the origins are really origins
- // (and not longer URLs). An unspecified port will be -1 and thus
- // automatically come first (which is what we want).
- int origin1_port = origin1.IntPort();
- int origin2_port = origin2.IntPort();
- DCHECK(origin1_port != origin2_port);
- return origin1_port < origin2_port ? -1 : 1;
-}
-} // namespace
-
-struct GeolocationExceptionsTableModel::Entry {
- Entry(const GURL& in_origin,
- const GURL& in_embedding_origin,
- ContentSetting in_setting)
- : origin(in_origin),
- embedding_origin(in_embedding_origin),
- setting(in_setting) {
- }
-
- GURL origin;
- GURL embedding_origin;
- ContentSetting setting;
-};
-
-GeolocationExceptionsTableModel::GeolocationExceptionsTableModel(
- GeolocationContentSettingsMap* map)
- : map_(map),
- observer_(NULL) {
- GeolocationContentSettingsMap::AllOriginsSettings settings(
- map_->GetAllOriginsSettings());
- GeolocationContentSettingsMap::AllOriginsSettings::const_iterator i;
- for (i = settings.begin(); i != settings.end(); ++i)
- AddEntriesForOrigin(i->first, i->second);
-}
-
-GeolocationExceptionsTableModel::~GeolocationExceptionsTableModel() {}
-
-bool GeolocationExceptionsTableModel::CanRemoveRows(
- const Rows& rows) const {
- for (Rows::const_iterator i(rows.begin()); i != rows.end(); ++i) {
- const Entry& entry = entries_[*i];
- if ((entry.origin == entry.embedding_origin) &&
- (entry.setting == CONTENT_SETTING_DEFAULT)) {
- for (size_t j = (*i) + 1;
- (j < entries_.size()) && (entries_[j].origin == entry.origin); ++j) {
- if (!rows.count(j))
- return false;
- }
- }
- }
- return !rows.empty();
-}
-
-void GeolocationExceptionsTableModel::RemoveRows(const Rows& rows) {
- for (Rows::const_reverse_iterator i(rows.rbegin()); i != rows.rend(); ++i) {
- size_t row = *i;
- Entry* entry = &entries_[row];
- GURL entry_origin(entry->origin); // Copy, not reference, since we'll erase
- // |entry| before we're done with this.
- bool next_has_same_origin = ((row + 1) < entries_.size()) &&
- (entries_[row + 1].origin == entry_origin);
- bool has_children = (entry_origin == entry->embedding_origin) &&
- next_has_same_origin;
- map_->SetContentSetting(entry_origin, entry->embedding_origin,
- CONTENT_SETTING_DEFAULT);
- if (has_children) {
- entry->setting = CONTENT_SETTING_DEFAULT;
- if (observer_)
- observer_->OnItemsChanged(row, 1);
- continue;
- }
- do {
- entries_.erase(entries_.begin() + row); // Note: |entry| is now garbage.
- if (observer_)
- observer_->OnItemsRemoved(row, 1);
- // If we remove the last non-default child of a default parent, we should
- // remove the parent too. We do these removals one-at-a-time because the
- // table view will end up being called back as each row is removed, in
- // turn calling back to CanRemoveRows(), and if we've already removed
- // more entries than the view has, we'll have problems.
- if ((row == 0) || rows.count(row - 1))
- break;
- entry = &entries_[--row];
- } while (!next_has_same_origin && (entry->origin == entry_origin) &&
- (entry->origin == entry->embedding_origin) &&
- (entry->setting == CONTENT_SETTING_DEFAULT));
- }
-}
-
-void GeolocationExceptionsTableModel::RemoveAll() {
- int old_row_count = RowCount();
- entries_.clear();
- map_->ResetToDefault();
- if (observer_)
- observer_->OnItemsRemoved(0, old_row_count);
-}
-
-int GeolocationExceptionsTableModel::RowCount() {
- return entries_.size();
-}
-
-string16 GeolocationExceptionsTableModel::GetText(int row,
- int column_id) {
- const Entry& entry = entries_[row];
- if (column_id == IDS_EXCEPTIONS_HOSTNAME_HEADER) {
- if (entry.origin == entry.embedding_origin) {
- return content_settings_helper::OriginToString16(entry.origin);
- }
- string16 indent(ASCIIToUTF16(" "));
- if (entry.embedding_origin.is_empty()) {
- // NOTE: As long as the user cannot add/edit entries from the exceptions
- // dialog, it's impossible to actually have a non-default setting for some
- // origin "embedded on any other site", so this row will never appear. If
- // we add the ability to add/edit exceptions, we'll need to decide when to
- // display this and how "removing" it will function.
- return indent + l10n_util::GetStringUTF16(
- IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ANY_OTHER);
- }
- return indent + l10n_util::GetStringFUTF16(
- IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST,
- content_settings_helper::OriginToString16(entry.embedding_origin));
- }
-
- if (column_id == IDS_EXCEPTIONS_ACTION_HEADER) {
- switch (entry.setting) {
- case CONTENT_SETTING_ALLOW:
- return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON);
- case CONTENT_SETTING_BLOCK:
- return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON);
- case CONTENT_SETTING_ASK:
- return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ASK_BUTTON);
- case CONTENT_SETTING_DEFAULT:
- return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_NOT_SET_BUTTON);
- default:
- break;
- }
- }
-
- NOTREACHED();
- return string16();
-}
-
-void GeolocationExceptionsTableModel::SetObserver(
- ui::TableModelObserver* observer) {
- observer_ = observer;
-}
-
-int GeolocationExceptionsTableModel::CompareValues(int row1,
- int row2,
- int column_id) {
- DCHECK(row1 >= 0 && row1 < RowCount() &&
- row2 >= 0 && row2 < RowCount());
-
- const Entry& entry1 = entries_[row1];
- const Entry& entry2 = entries_[row2];
-
- // Sort top-level requesting origins, keeping all embedded (child) rules
- // together.
- int origin_comparison = CompareOrigins(entry1.origin, entry2.origin);
- if (origin_comparison == 0) {
- // The non-embedded rule comes before all embedded rules.
- bool entry1_origins_same = entry1.origin == entry1.embedding_origin;
- bool entry2_origins_same = entry2.origin == entry2.embedding_origin;
- if (entry1_origins_same != entry2_origins_same)
- return entry1_origins_same ? -1 : 1;
-
- // The "default" embedded rule comes after all other embedded rules.
- bool embedding_origin1_empty = entry1.embedding_origin.is_empty();
- bool embedding_origin2_empty = entry2.embedding_origin.is_empty();
- if (embedding_origin1_empty != embedding_origin2_empty)
- return embedding_origin2_empty ? -1 : 1;
-
- origin_comparison =
- CompareOrigins(entry1.embedding_origin, entry2.embedding_origin);
- } else if (column_id == IDS_EXCEPTIONS_ACTION_HEADER) {
- // The rows are in different origins. We need to find out how the top-level
- // origins will compare.
- while (entries_[row1].origin != entries_[row1].embedding_origin)
- --row1;
- while (entries_[row2].origin != entries_[row2].embedding_origin)
- --row2;
- }
-
- // The entries are at the same "scope". If we're sorting by action, then do
- // that now.
- if (column_id == IDS_EXCEPTIONS_ACTION_HEADER) {
- int compare_text = l10n_util::CompareString16WithCollator(
- GetCollator(), GetText(row1, column_id), GetText(row2, column_id));
- if (compare_text != 0)
- return compare_text;
- }
-
- // Sort by the relevant origin.
- return origin_comparison;
-}
-
-void GeolocationExceptionsTableModel::AddEntriesForOrigin(
- const GURL& origin,
- const GeolocationContentSettingsMap::OneOriginSettings& settings) {
- GeolocationContentSettingsMap::OneOriginSettings::const_iterator parent =
- settings.find(origin);
-
- // Add the "parent" entry for the non-embedded setting.
- entries_.push_back(Entry(origin, origin,
- (parent == settings.end()) ? CONTENT_SETTING_DEFAULT : parent->second));
-
- // Add the "children" for any embedded settings.
- GeolocationContentSettingsMap::OneOriginSettings::const_iterator i;
- for (i = settings.begin(); i != settings.end(); ++i) {
- // Skip the non-embedded setting which we already added above.
- if (i == parent)
- continue;
-
- entries_.push_back(Entry(origin, i->first, i->second));
- }
-}
diff --git a/chrome/browser/geolocation/geolocation_exceptions_table_model.h b/chrome/browser/geolocation/geolocation_exceptions_table_model.h
deleted file mode 100644
index 0617b46..0000000
--- a/chrome/browser/geolocation/geolocation_exceptions_table_model.h
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (c) 2010 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_GEOLOCATION_GEOLOCATION_EXCEPTIONS_TABLE_MODEL_H_
-#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_EXCEPTIONS_TABLE_MODEL_H_
-#pragma once
-
-#include <vector>
-
-#include "base/compiler_specific.h"
-#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
-#include "chrome/browser/remove_rows_table_model.h"
-#include "chrome/common/content_settings.h"
-#include "chrome/common/content_settings_types.h"
-
-class GeolocationExceptionsTableModel : public RemoveRowsTableModel {
- public:
- explicit GeolocationExceptionsTableModel(
- GeolocationContentSettingsMap* map);
- virtual ~GeolocationExceptionsTableModel();
-
- // RemoveRowsTableModel overrides:
-
- // Return whether the given set of rows can be removed. A parent with setting
- // of CONTENT_SETTING_DEFAULT can't be removed unless all its children are
- // also being removed.
- virtual bool CanRemoveRows(const Rows& rows) const;
-
- // Removes the exceptions at the specified indexes. If an exception is a
- // parent, and it has children, the row in model will be updated to have
- // CONTENT_SETTING_DEFAULT. If it is the only child of a
- // CONTENT_SETTING_DEFAULT parent, the parent will be removed from the model
- // too.
- virtual void RemoveRows(const Rows& rows);
-
- // Removes all the exceptions from both the map and model.
- virtual void RemoveAll();
-
- // TableModel overrides:
- virtual int RowCount() OVERRIDE;
- virtual string16 GetText(int row, int column_id) OVERRIDE;
- virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
- virtual int CompareValues(int row1, int row2, int column_id) OVERRIDE;
-
- private:
- void AddEntriesForOrigin(
- const GURL& origin,
- const GeolocationContentSettingsMap::OneOriginSettings& settings);
-
- GeolocationContentSettingsMap* map_;
-
- struct Entry;
- typedef std::vector<Entry> EntriesVector;
- EntriesVector entries_;
-
- ui::TableModelObserver* observer_;
-
- DISALLOW_COPY_AND_ASSIGN(GeolocationExceptionsTableModel);
-};
-
-#endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_EXCEPTIONS_TABLE_MODEL_H_
diff --git a/chrome/browser/geolocation/geolocation_exceptions_table_model_unittest.cc b/chrome/browser/geolocation/geolocation_exceptions_table_model_unittest.cc
deleted file mode 100644
index 4c6c997..0000000
--- a/chrome/browser/geolocation/geolocation_exceptions_table_model_unittest.cc
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright (c) 2010 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_exceptions_table_model.h"
-#include "chrome/common/content_settings_helper.h"
-#include "chrome/test/testing_profile.h"
-#include "content/browser/browser_thread.h"
-#include "content/browser/renderer_host/test_render_view_host.h"
-#include "grit/generated_resources.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace {
-const GURL kUrl0("http://www.example.com");
-const GURL kUrl1("http://www.example1.com");
-const GURL kUrl2("http://www.example2.com");
-
-class GeolocationExceptionsTableModelTest : public RenderViewHostTestHarness {
- public:
- GeolocationExceptionsTableModelTest()
- : ui_thread_(BrowserThread::UI, MessageLoop::current()) {}
-
- virtual ~GeolocationExceptionsTableModelTest() {}
-
- virtual void SetUp() {
- RenderViewHostTestHarness::SetUp();
- ResetModel();
- }
-
- virtual void TearDown() {
- model_.reset(NULL);
- RenderViewHostTestHarness::TearDown();
- }
-
- virtual void ResetModel() {
- model_.reset(new GeolocationExceptionsTableModel(
- profile()->GetGeolocationContentSettingsMap()));
- }
-
- void CreateAllowedSamples() {
- scoped_refptr<GeolocationContentSettingsMap> map(
- profile()->GetGeolocationContentSettingsMap());
- map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_ALLOW);
- map->SetContentSetting(kUrl0, kUrl1, CONTENT_SETTING_ALLOW);
- map->SetContentSetting(kUrl0, kUrl2, CONTENT_SETTING_ALLOW);
- ResetModel();
- EXPECT_EQ(3, model_->RowCount());
- }
-
- protected:
- BrowserThread ui_thread_;
- scoped_ptr<GeolocationExceptionsTableModel> model_;
-};
-
-TEST_F(GeolocationExceptionsTableModelTest, CanRemoveException) {
- EXPECT_EQ(0, model_->RowCount());
-
- scoped_refptr<GeolocationContentSettingsMap> map(
- profile()->GetGeolocationContentSettingsMap());
-
- // Ensure a single entry can be removed.
- map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_ALLOW);
- ResetModel();
- EXPECT_EQ(1, model_->RowCount());
- GeolocationExceptionsTableModel::Rows rows;
- rows.insert(0U);
- EXPECT_TRUE(model_->CanRemoveRows(rows));
-
-
- // Ensure an entry with children can't be removed.
- map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_DEFAULT);
- map->SetContentSetting(kUrl0, kUrl1, CONTENT_SETTING_ALLOW);
- map->SetContentSetting(kUrl0, kUrl2, CONTENT_SETTING_BLOCK);
- ResetModel();
- EXPECT_EQ(3, model_->RowCount());
- EXPECT_FALSE(model_->CanRemoveRows(rows));
-
- // Ensure it can be removed if removing all children.
- rows.clear();
- rows.insert(1U);
- rows.insert(2U);
- EXPECT_TRUE(model_->CanRemoveRows(rows));
-}
-
-TEST_F(GeolocationExceptionsTableModelTest, RemoveExceptions) {
- CreateAllowedSamples();
- scoped_refptr<GeolocationContentSettingsMap> map(
- profile()->GetGeolocationContentSettingsMap());
-
- // Test removing parent exception.
- GeolocationExceptionsTableModel::Rows rows;
- rows.insert(0U);
- model_->RemoveRows(rows);
- EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0));
- EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetContentSetting(kUrl0, kUrl1));
- EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetContentSetting(kUrl0, kUrl2));
-
- ResetModel();
- EXPECT_EQ(3, model_->RowCount());
-
- // Test removing remaining children.
- rows.clear();
- rows.insert(1U);
- rows.insert(2U);
- model_->RemoveRows(rows);
- EXPECT_EQ(0, model_->RowCount());
- EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0));
- EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl1));
- EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl2));
-}
-
-TEST_F(GeolocationExceptionsTableModelTest, RemoveAll) {
- CreateAllowedSamples();
- scoped_refptr<GeolocationContentSettingsMap> map(
- profile()->GetGeolocationContentSettingsMap());
-
- model_->RemoveAll();
- EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0));
- EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl1));
- EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl2));
- EXPECT_EQ(0, model_->RowCount());
-}
-
-TEST_F(GeolocationExceptionsTableModelTest, GetText) {
- CreateAllowedSamples();
-
- // Ensure the parent doesn't have any indentation.
- string16 text = model_->GetText(0, IDS_EXCEPTIONS_HOSTNAME_HEADER);
- EXPECT_EQ(content_settings_helper::OriginToString16(kUrl0), text);
-
- // Ensure there's some indentation on the children nodes.
- text = model_->GetText(1, IDS_EXCEPTIONS_HOSTNAME_HEADER);
- EXPECT_NE(content_settings_helper::OriginToString16(kUrl1), text);
- EXPECT_NE(string16::npos,
- text.find(content_settings_helper::OriginToString16(kUrl1)));
-
- text = model_->GetText(2, IDS_EXCEPTIONS_HOSTNAME_HEADER);
- EXPECT_NE(content_settings_helper::OriginToString16(kUrl2), text);
- EXPECT_NE(string16::npos,
- text.find(content_settings_helper::OriginToString16(kUrl2)));
-}
-
-} // namespace
diff --git a/chrome/browser/geolocation/geolocation_prefs.cc b/chrome/browser/geolocation/geolocation_prefs.cc
deleted file mode 100644
index c618ed9..0000000
--- a/chrome/browser/geolocation/geolocation_prefs.cc
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (c) 2010 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 "content/browser/geolocation/access_token_store.h"
-
-namespace geolocation {
-void RegisterPrefs(PrefService* prefs) {
- // Fan out to all geolocation sub-components that use prefs.
- AccessTokenStore::RegisterPrefs(prefs);
-}
-} // namespace geolocation
diff --git a/chrome/browser/geolocation/geolocation_prefs.h b/chrome/browser/geolocation/geolocation_prefs.h
deleted file mode 100644
index cc39b66..0000000
--- a/chrome/browser/geolocation/geolocation_prefs.h
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (c) 2010 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_GEOLOCATION_GEOLOCATION_PREFS_H_
-#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PREFS_H_
-#pragma once
-
-class PrefService;
-
-namespace geolocation {
-void RegisterPrefs(PrefService* prefs);
-}
-
-#endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PREFS_H_
diff --git a/chrome/browser/geolocation/geolocation_settings_state.cc b/chrome/browser/geolocation/geolocation_settings_state.cc
deleted file mode 100644
index b07436e..0000000
--- a/chrome/browser/geolocation/geolocation_settings_state.cc
+++ /dev/null
@@ -1,107 +0,0 @@
-// 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/geolocation/geolocation_settings_state.h"
-
-#include <string>
-
-#include "base/string_piece.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/content_settings/host_content_settings_map.h"
-#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/pref_names.h"
-#include "content/browser/tab_contents/navigation_details.h"
-#include "content/browser/tab_contents/navigation_entry.h"
-#include "net/base/net_util.h"
-
-GeolocationSettingsState::GeolocationSettingsState(Profile* profile)
- : profile_(profile) {
-}
-
-GeolocationSettingsState::~GeolocationSettingsState() {
-}
-
-void GeolocationSettingsState::OnGeolocationPermissionSet(
- const GURL& requesting_origin, bool allowed) {
- state_map_[requesting_origin] =
- allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
-}
-
-void GeolocationSettingsState::DidNavigate(
- const content::LoadCommittedDetails& details) {
- if (details.entry)
- embedder_url_ = details.entry->url();
- if (state_map_.empty())
- return;
- if (!details.entry ||
- details.previous_url.GetOrigin() != details.entry->url().GetOrigin()) {
- state_map_.clear();
- return;
- }
- // We're in the same origin, check if there's any icon to be displayed.
- unsigned int tab_state_flags = 0;
- GetDetailedInfo(NULL, &tab_state_flags);
- if (!(tab_state_flags & TABSTATE_HAS_ANY_ICON))
- state_map_.clear();
-}
-
-void GeolocationSettingsState::ClearStateMap() {
- state_map_.clear();
-}
-
-void GeolocationSettingsState::GetDetailedInfo(
- FormattedHostsPerState* formatted_hosts_per_state,
- unsigned int* tab_state_flags) const {
- DCHECK(tab_state_flags);
- DCHECK(embedder_url_.is_valid());
- ContentSetting default_setting =
- profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
- CONTENT_SETTINGS_TYPE_GEOLOCATION);
- std::set<std::string> formatted_hosts;
- std::set<std::string> repeated_formatted_hosts;
-
- // Build a set of repeated formatted hosts
- for (StateMap::const_iterator i(state_map_.begin());
- i != state_map_.end(); ++i) {
- std::string formatted_host = GURLToFormattedHost(i->first);
- if (!formatted_hosts.insert(formatted_host).second) {
- repeated_formatted_hosts.insert(formatted_host);
- }
- }
-
- for (StateMap::const_iterator i(state_map_.begin());
- i != state_map_.end(); ++i) {
- if (i->second == CONTENT_SETTING_ALLOW)
- *tab_state_flags |= TABSTATE_HAS_ANY_ALLOWED;
- if (formatted_hosts_per_state) {
- std::string formatted_host = GURLToFormattedHost(i->first);
- std::string final_formatted_host =
- repeated_formatted_hosts.find(formatted_host) ==
- repeated_formatted_hosts.end() ?
- formatted_host :
- i->first.spec();
- (*formatted_hosts_per_state)[i->second].insert(final_formatted_host);
- }
-
- const ContentSetting saved_setting =
- profile_->GetGeolocationContentSettingsMap()->GetContentSetting(
- i->first, embedder_url_);
- if (saved_setting != default_setting)
- *tab_state_flags |= TABSTATE_HAS_EXCEPTION;
- if (saved_setting != i->second)
- *tab_state_flags |= TABSTATE_HAS_CHANGED;
- if (saved_setting != CONTENT_SETTING_ASK)
- *tab_state_flags |= TABSTATE_HAS_ANY_ICON;
- }
-}
-
-std::string GeolocationSettingsState::GURLToFormattedHost(
- const GURL& url) const {
- string16 display_host;
- net::AppendFormattedHost(url,
- profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), &display_host);
- return UTF16ToUTF8(display_host);
-}
diff --git a/chrome/browser/geolocation/geolocation_settings_state.h b/chrome/browser/geolocation/geolocation_settings_state.h
deleted file mode 100644
index fd94f12..0000000
--- a/chrome/browser/geolocation/geolocation_settings_state.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright (c) 2010 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_GEOLOCATION_GEOLOCATION_SETTINGS_STATE_H_
-#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_SETTINGS_STATE_H_
-#pragma once
-
-#include <map>
-#include <set>
-
-#include "chrome/common/content_settings.h"
-#include "googleurl/src/gurl.h"
-
-class GeolocationContentSettingsMap;
-class Profile;
-
-namespace content {
-struct LoadCommittedDetails;
-}
-
-// This class manages the geolocation state per tab, and provides information
-// and presentation data about the geolocation usage.
-class GeolocationSettingsState {
- public:
- explicit GeolocationSettingsState(Profile* profile);
- virtual ~GeolocationSettingsState();
-
- typedef std::map<GURL, ContentSetting> StateMap;
- const StateMap& state_map() const {
- return state_map_;
- }
-
- // Sets the state for |requesting_origin|.
- void OnGeolocationPermissionSet(const GURL& requesting_origin, bool allowed);
-
- // Delegated by TabContents to indicate a navigation has happened and we
- // may need to clear our settings.
- void DidNavigate(const content::LoadCommittedDetails& details);
-
- void ClearStateMap();
-
- enum TabState {
- TABSTATE_NONE = 0,
- // There's at least one entry with non-default setting.
- TABSTATE_HAS_EXCEPTION = 1 << 1,
- // There's at least one entry with a non-ASK setting.
- TABSTATE_HAS_ANY_ICON = 1 << 2,
- // There's at least one entry with ALLOWED setting.
- TABSTATE_HAS_ANY_ALLOWED = 1 << 3,
- // There's at least one entry that doesn't match the saved setting.
- TABSTATE_HAS_CHANGED = 1 << 4,
- };
-
- // Maps ContentSetting to a set of hosts formatted for presentation.
- typedef std::map<ContentSetting, std::set<std::string> >
- FormattedHostsPerState;
-
- // Returns an (optional) |formatted_hosts_per_state| and a mask of TabState.
- void GetDetailedInfo(FormattedHostsPerState* formatted_hosts_per_state,
- unsigned int* tab_state_flags) const;
-
- private:
- std::string GURLToFormattedHost(const GURL& url) const;
-
- Profile* profile_;
- StateMap state_map_;
- GURL embedder_url_;
-
- DISALLOW_COPY_AND_ASSIGN(GeolocationSettingsState);
-};
-
-#endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_SETTINGS_STATE_H_
diff --git a/chrome/browser/geolocation/geolocation_settings_state_unittest.cc b/chrome/browser/geolocation/geolocation_settings_state_unittest.cc
deleted file mode 100644
index f7c5e7b..0000000
--- a/chrome/browser/geolocation/geolocation_settings_state_unittest.cc
+++ /dev/null
@@ -1,186 +0,0 @@
-// Copyright (c) 2010 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_content_settings_map.h"
-#include "chrome/browser/geolocation/geolocation_settings_state.h"
-#include "chrome/test/testing_profile.h"
-#include "content/browser/browser_thread.h"
-#include "content/browser/tab_contents/navigation_details.h"
-#include "content/browser/tab_contents/navigation_entry.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace {
-
-class GeolocationSettingsStateTests : public testing::Test {
- public:
- GeolocationSettingsStateTests()
- : ui_thread_(BrowserThread::UI, &message_loop_) {
- }
-
- protected:
- MessageLoop message_loop_;
- BrowserThread ui_thread_;
-};
-
-TEST_F(GeolocationSettingsStateTests, ClearOnNewOrigin) {
- TestingProfile profile;
- GeolocationSettingsState state(&profile);
- GURL url_0("http://www.example.com");
-
- NavigationEntry entry;
- entry.set_url(url_0);
- content::LoadCommittedDetails load_committed_details;
- load_committed_details.entry = &entry;
- state.DidNavigate(load_committed_details);
-
- profile.GetGeolocationContentSettingsMap()->SetContentSetting(
- url_0, url_0, CONTENT_SETTING_ALLOW);
- state.OnGeolocationPermissionSet(url_0, true);
-
- GURL url_1("http://www.example1.com");
- profile.GetGeolocationContentSettingsMap()->SetContentSetting(
- url_1, url_0, CONTENT_SETTING_BLOCK);
- state.OnGeolocationPermissionSet(url_1, false);
-
- GeolocationSettingsState::StateMap state_map =
- state.state_map();
- EXPECT_EQ(2U, state_map.size());
-
- GeolocationSettingsState::FormattedHostsPerState formatted_host_per_state;
- unsigned int tab_state_flags = 0;
- state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
- EXPECT_TRUE(tab_state_flags &
- GeolocationSettingsState::TABSTATE_HAS_ANY_ALLOWED)
- << tab_state_flags;
- EXPECT_TRUE(tab_state_flags &
- GeolocationSettingsState::TABSTATE_HAS_EXCEPTION)
- << tab_state_flags;
- EXPECT_FALSE(tab_state_flags &
- GeolocationSettingsState::TABSTATE_HAS_CHANGED)
- << tab_state_flags;
- EXPECT_TRUE(tab_state_flags &
- GeolocationSettingsState::TABSTATE_HAS_ANY_ICON)
- << tab_state_flags;
- EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
- EXPECT_EQ(1U,
- formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
- url_0.host()));
-
- EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size());
- EXPECT_EQ(1U,
- formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
- url_1.host()));
-
- state.OnGeolocationPermissionSet(url_0, false);
-
- formatted_host_per_state.clear();
- tab_state_flags = 0;
- state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
- EXPECT_FALSE(tab_state_flags &
- GeolocationSettingsState::TABSTATE_HAS_ANY_ALLOWED)
- << tab_state_flags;
- EXPECT_TRUE(tab_state_flags &
- GeolocationSettingsState::TABSTATE_HAS_EXCEPTION)
- << tab_state_flags;
- EXPECT_TRUE(tab_state_flags &
- GeolocationSettingsState::TABSTATE_HAS_CHANGED)
- << tab_state_flags;
- EXPECT_TRUE(tab_state_flags &
- GeolocationSettingsState::TABSTATE_HAS_ANY_ICON)
- << tab_state_flags;
- EXPECT_EQ(0U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
- EXPECT_EQ(2U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size());
- EXPECT_EQ(1U,
- formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
- url_0.host()));
- EXPECT_EQ(1U,
- formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
- url_1.host()));
-
- state.OnGeolocationPermissionSet(url_0, true);
-
- load_committed_details.previous_url = url_0;
- state.DidNavigate(load_committed_details);
-
- GeolocationSettingsState::StateMap new_state_map =
- state.state_map();
- EXPECT_EQ(state_map.size(), new_state_map.size());
-
- GURL different_url("http://foo.com");
- entry.set_url(different_url);
- state.DidNavigate(load_committed_details);
-
- EXPECT_TRUE(state.state_map().empty());
-
- formatted_host_per_state.clear();
- tab_state_flags = 0;
- state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
- EXPECT_TRUE(formatted_host_per_state.empty());
- EXPECT_EQ(0U, tab_state_flags);
-}
-
-TEST_F(GeolocationSettingsStateTests, ShowPortOnSameHost) {
- TestingProfile profile;
- GeolocationSettingsState state(&profile);
- GURL url_0("http://www.example.com");
-
- NavigationEntry entry;
- entry.set_url(url_0);
- content::LoadCommittedDetails load_committed_details;
- load_committed_details.entry = &entry;
- state.DidNavigate(load_committed_details);
-
- profile.GetGeolocationContentSettingsMap()->SetContentSetting(
- url_0, url_0, CONTENT_SETTING_ALLOW);
- state.OnGeolocationPermissionSet(url_0, true);
-
- GURL url_1("https://www.example.com");
- profile.GetGeolocationContentSettingsMap()->SetContentSetting(
- url_1, url_0, CONTENT_SETTING_ALLOW);
- state.OnGeolocationPermissionSet(url_1, true);
-
- GURL url_2("http://www.example1.com");
- profile.GetGeolocationContentSettingsMap()->SetContentSetting(
- url_2, url_0, CONTENT_SETTING_ALLOW);
- state.OnGeolocationPermissionSet(url_2, true);
-
- GeolocationSettingsState::StateMap state_map =
- state.state_map();
- EXPECT_EQ(3U, state_map.size());
-
- GeolocationSettingsState::FormattedHostsPerState formatted_host_per_state;
- unsigned int tab_state_flags = 0;
- state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
-
- EXPECT_EQ(3U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
- EXPECT_EQ(1U,
- formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
- url_0.spec()));
- EXPECT_EQ(1U,
- formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
- url_1.spec()));
- EXPECT_EQ(1U,
- formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
- url_2.host()));
-
- state.OnGeolocationPermissionSet(url_1, false);
- formatted_host_per_state.clear();
- tab_state_flags = 0;
- state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
-
- EXPECT_EQ(2U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
- EXPECT_EQ(1U,
- formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
- url_0.spec()));
- EXPECT_EQ(1U,
- formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
- url_2.host()));
- EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size());
- EXPECT_EQ(1U,
- formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
- url_1.spec()));
-}
-
-
-} // namespace
diff --git a/chrome/browser/geolocation/wifi_data_provider_chromeos.cc b/chrome/browser/geolocation/wifi_data_provider_chromeos.cc
deleted file mode 100644
index 0d7c314..0000000
--- a/chrome/browser/geolocation/wifi_data_provider_chromeos.cc
+++ /dev/null
@@ -1,233 +0,0 @@
-// 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.
-
-// Provides wifi scan API binding for chromeos, using proprietary APIs.
-
-#include "chrome/browser/geolocation/wifi_data_provider_chromeos.h"
-
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/chromeos/cros/cros_library.h"
-#include "chrome/browser/chromeos/cros/network_library.h"
-#include "content/browser/browser_thread.h"
-
-namespace {
-// The time periods between successive polls of the wifi data.
-const int kDefaultPollingIntervalMilliseconds = 10 * 1000; // 10s
-const int kNoChangePollingIntervalMilliseconds = 2 * 60 * 1000; // 2 mins
-const int kTwoNoChangePollingIntervalMilliseconds = 10 * 60 * 1000; // 10 mins
-const int kNoWifiPollingIntervalMilliseconds = 20 * 1000; // 20s
-}
-
-namespace chromeos {
-namespace {
-// Wifi API binding to network_library.h, to allow reuse of the polling behavior
-// defined in WifiDataProviderCommon.
-class NetworkLibraryWlanApi : public WifiDataProviderCommon::WlanApiInterface {
- public:
- // Does not transfer ownership, |lib| must remain valid for lifetime of
- // this object.
- explicit NetworkLibraryWlanApi(NetworkLibrary* lib);
- ~NetworkLibraryWlanApi();
-
- // WifiDataProviderCommon::WlanApiInterface
- bool GetAccessPointData(WifiData::AccessPointDataSet* data);
-
- private:
- NetworkLibrary* network_library_;
-
- DISALLOW_COPY_AND_ASSIGN(NetworkLibraryWlanApi);
-};
-
-NetworkLibraryWlanApi::NetworkLibraryWlanApi(NetworkLibrary* lib)
- : network_library_(lib) {
- DCHECK(network_library_ != NULL);
-}
-
-NetworkLibraryWlanApi::~NetworkLibraryWlanApi() {
-}
-
-bool NetworkLibraryWlanApi::GetAccessPointData(
- WifiData::AccessPointDataSet* result) {
- WifiAccessPointVector access_points;
- if (!network_library_->GetWifiAccessPoints(&access_points))
- return false;
- for (WifiAccessPointVector::const_iterator i = access_points.begin();
- i != access_points.end(); ++i) {
- AccessPointData ap_data;
- ap_data.mac_address = ASCIIToUTF16(i->mac_address);
- ap_data.radio_signal_strength = i->signal_strength;
- ap_data.channel = i->channel;
- ap_data.signal_to_noise = i->signal_to_noise;
- ap_data.ssid = UTF8ToUTF16(i->name);
- result->insert(ap_data);
- }
- return !result->empty() || network_library_->wifi_enabled();
-}
-
-} // namespace
-} // namespace chromeos
-
-template<>
-WifiDataProviderImplBase* WifiDataProvider::DefaultFactoryFunction() {
- return new WifiDataProviderChromeOs();
-}
-
-WifiDataProviderChromeOs::WifiDataProviderChromeOs() :
- started_(false) {
-}
-
-WifiDataProviderChromeOs::~WifiDataProviderChromeOs() {
-}
-
-bool WifiDataProviderChromeOs::StartDataProvider() {
- DCHECK(CalledOnClientThread());
-
- DCHECK(polling_policy_ == NULL);
- polling_policy_.reset(NewPollingPolicy());
- DCHECK(polling_policy_ != NULL);
-
- ScheduleStart();
- return true;
-}
-
-void WifiDataProviderChromeOs::StopDataProvider() {
- DCHECK(CalledOnClientThread());
-
- polling_policy_.reset();
- ScheduleStop();
-}
-
-bool WifiDataProviderChromeOs::GetData(WifiData* data) {
- DCHECK(CalledOnClientThread());
- DCHECK(data);
- *data = wifi_data_;
- return is_first_scan_complete_;
-}
-
-WifiDataProviderCommon::WlanApiInterface*
- WifiDataProviderChromeOs::NewWlanApi(chromeos::NetworkLibrary* lib) {
- return new chromeos::NetworkLibraryWlanApi(lib);
-}
-
-WifiDataProviderCommon::WlanApiInterface*
- WifiDataProviderChromeOs::NewWlanApi() {
- chromeos::CrosLibrary* cros_lib = chromeos::CrosLibrary::Get();
- DCHECK(cros_lib);
- if (!cros_lib->EnsureLoaded())
- return NULL;
- return NewWlanApi(cros_lib->GetNetworkLibrary());
-}
-
-PollingPolicyInterface* WifiDataProviderChromeOs::NewPollingPolicy() {
- return new GenericPollingPolicy<kDefaultPollingIntervalMilliseconds,
- kNoChangePollingIntervalMilliseconds,
- kTwoNoChangePollingIntervalMilliseconds,
- kNoWifiPollingIntervalMilliseconds>;
-}
-
-void WifiDataProviderChromeOs::DoStartTaskOnUIThread() {
- CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- wlan_api_.reset(NewWlanApi());
- if (wlan_api_ == NULL) {
- client_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &WifiDataProviderChromeOs::DidStartFailed));
- return;
- }
- DoWifiScanTaskOnUIThread();
-}
-
-void WifiDataProviderChromeOs::DoStopTaskOnUIThread() {
- CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- wlan_api_.reset();
-}
-
-void WifiDataProviderChromeOs::DidStartFailed() {
- CHECK(CalledOnClientThread());
- // Error! Can't do scans, so don't try and schedule one.
- is_first_scan_complete_ = true;
-}
-
-void WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread() {
- CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- // This method could be scheduled after a DoStopTaskOnUIThread.
- if (!wlan_api_.get())
- return;
-
- WifiData new_data;
-
- if (!wlan_api_->GetAccessPointData(&new_data.access_point_data)) {
- client_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &WifiDataProviderChromeOs::DidWifiScanTaskNoResults));
- }
- else {
- client_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &WifiDataProviderChromeOs::DidWifiScanTask,
- new_data));
- }
-}
-
-void WifiDataProviderChromeOs::DidWifiScanTaskNoResults() {
- DCHECK(CalledOnClientThread());
- // Schedule next scan if started (StopDataProvider could have been called
- // in between DoWifiScanTaskOnUIThread and this method).
- if (started_)
- ScheduleNextScan(polling_policy_->NoWifiInterval());
- MaybeNotifyListeners(false);
-}
-
-void WifiDataProviderChromeOs::DidWifiScanTask(const WifiData& new_data) {
- DCHECK(CalledOnClientThread());
- bool update_available = wifi_data_.DiffersSignificantly(new_data);
- wifi_data_ = new_data;
- // Schedule next scan if started (StopDataProvider could have been called
- // in between DoWifiScanTaskOnUIThread and this method).
- if (started_) {
- polling_policy_->UpdatePollingInterval(update_available);
- ScheduleNextScan(polling_policy_->PollingInterval());
- }
- MaybeNotifyListeners(update_available);
-}
-
-void WifiDataProviderChromeOs::MaybeNotifyListeners(bool update_available) {
- if (update_available || !is_first_scan_complete_) {
- is_first_scan_complete_ = true;
- NotifyListeners();
- }
-}
-
-void WifiDataProviderChromeOs::ScheduleNextScan(int interval) {
- DCHECK(CalledOnClientThread());
- DCHECK(started_);
- BrowserThread::PostDelayedTask(
- BrowserThread::UI,
- FROM_HERE,
- NewRunnableMethod(this,
- &WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread),
- interval);
-}
-
-void WifiDataProviderChromeOs::ScheduleStop() {
- DCHECK(CalledOnClientThread());
- DCHECK(started_);
- started_ = false;
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- NewRunnableMethod(this,
- &WifiDataProviderChromeOs::DoStopTaskOnUIThread));
-}
-
-void WifiDataProviderChromeOs::ScheduleStart() {
- DCHECK(CalledOnClientThread());
- DCHECK(!started_);
- started_ = true;
- // Perform first scan ASAP regardless of the polling policy. If this scan
- // fails we'll retry at a rate in line with the polling policy.
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- NewRunnableMethod(this,
- &WifiDataProviderChromeOs::DoStartTaskOnUIThread));
-}
diff --git a/chrome/browser/geolocation/wifi_data_provider_chromeos.h b/chrome/browser/geolocation/wifi_data_provider_chromeos.h
deleted file mode 100644
index 76b6174..0000000
--- a/chrome/browser/geolocation/wifi_data_provider_chromeos.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// 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_GEOLOCATION_WIFI_DATA_PROVIDER_CHROMEOS_H_
-#define CHROME_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_CHROMEOS_H_
-#pragma once
-
-#include "content/browser/geolocation/wifi_data_provider_common.h"
-
-namespace chromeos {
-class NetworkLibrary;
-}
-
-class WifiDataProviderChromeOs : public WifiDataProviderImplBase {
- public:
- WifiDataProviderChromeOs();
-
- // WifiDataProviderImplBase
- virtual bool StartDataProvider();
- virtual void StopDataProvider();
- virtual bool GetData(WifiData* data);
-
- // Allows injection of |lib| for testing.
- static WifiDataProviderCommon::WlanApiInterface* NewWlanApi(
- chromeos::NetworkLibrary* lib);
-
- private:
- virtual ~WifiDataProviderChromeOs();
-
- // UI thread
- void DoWifiScanTaskOnUIThread(); // The polling task
- void DoStartTaskOnUIThread();
- void DoStopTaskOnUIThread();
-
- // Client thread
- void DidWifiScanTaskNoResults();
- void DidWifiScanTask(const WifiData& new_data);
- void MaybeNotifyListeners(bool update_available);
- void DidStartFailed();
-
- // WifiDataProviderCommon
- virtual WifiDataProviderCommon::WlanApiInterface* NewWlanApi();
- virtual PollingPolicyInterface* NewPollingPolicy();
-
- // Will schedule a scan; i.e. enqueue DoWifiScanTask deferred task.
- void ScheduleNextScan(int interval);
-
- // Will schedule starting of the scanning process.
- void ScheduleStart();
-
- // Will schedule stopping of the scanning process.
- void ScheduleStop();
-
- // Underlying OS wifi API. (UI thread)
- scoped_ptr<WifiDataProviderCommon::WlanApiInterface> wlan_api_;
-
- // Controls the polling update interval. (client thread)
- scoped_ptr<PollingPolicyInterface> polling_policy_;
-
- // The latest wifi data. (client thread)
- WifiData wifi_data_;
-
- // Whether we have strated the data provider. (client thread)
- bool started_;
-
- // Whether we've successfully completed a scan for WiFi data. (client thread)
- bool is_first_scan_complete_;
-
- DISALLOW_COPY_AND_ASSIGN(WifiDataProviderChromeOs);
-};
-
-#endif // CHROME_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_CHROMEOS_H_
diff --git a/chrome/browser/geolocation/wifi_data_provider_unittest_chromeos.cc b/chrome/browser/geolocation/wifi_data_provider_unittest_chromeos.cc
deleted file mode 100644
index 4795bc8..0000000
--- a/chrome/browser/geolocation/wifi_data_provider_unittest_chromeos.cc
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright (c) 2010 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 "base/utf_string_conversions.h"
-#include "chrome/browser/chromeos/cros/mock_network_library.h"
-#include "chrome/browser/geolocation/wifi_data_provider_chromeos.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using ::testing::DoAll;
-using ::testing::NotNull;
-using ::testing::Return;
-using ::testing::ReturnRef;
-using ::testing::SetArgumentPointee;
-
-namespace chromeos {
-
-class GeolocationChromeOsWifiDataProviderTest : public testing::Test {
- protected:
- GeolocationChromeOsWifiDataProviderTest()
- : api_(WifiDataProviderChromeOs::NewWlanApi(&net_lib_)) {
- }
-
- static WifiAccessPointVector MakeWifiAps(int ssids, int aps_per_ssid) {
- WifiAccessPointVector ret;
- for (int i = 0; i < ssids; ++i) {
- for (int j = 0; j < aps_per_ssid; ++j) {
- WifiAccessPoint ap;
- ap.name = StringPrintf("SSID %d", i);
- ap.channel = i * 10 + j;
- ap.mac_address = StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X",
- i, j, 3, 4, 5, 6);
- ap.signal_strength = j;
- ap.signal_to_noise = i;
- ret.push_back(ap);
- }
- }
- return ret;
- }
-
- chromeos::MockNetworkLibrary net_lib_;
- scoped_ptr<WifiDataProviderCommon::WlanApiInterface> api_;
- WifiData::AccessPointDataSet ap_data_;
-};
-
-TEST_F(GeolocationChromeOsWifiDataProviderTest, WifiPoweredOff) {
- EXPECT_CALL(net_lib_, GetWifiAccessPoints(NotNull()))
- .WillOnce(Return(false));
- EXPECT_FALSE(api_->GetAccessPointData(&ap_data_));
- EXPECT_EQ(0u, ap_data_.size());
-}
-
-TEST_F(GeolocationChromeOsWifiDataProviderTest, NoAccessPointsInRange) {
- EXPECT_CALL(net_lib_, GetWifiAccessPoints(NotNull()))
- .WillOnce(Return(true));
- EXPECT_CALL(net_lib_, wifi_enabled())
- .WillRepeatedly(Return(true));
- EXPECT_TRUE(api_->GetAccessPointData(&ap_data_));
- EXPECT_EQ(0u, ap_data_.size());
-}
-
-TEST_F(GeolocationChromeOsWifiDataProviderTest, GetOneAccessPoint) {
- EXPECT_CALL(net_lib_, GetWifiAccessPoints(NotNull()))
- .WillOnce(DoAll(SetArgumentPointee<0>(MakeWifiAps(1, 1)), Return(true)));
- EXPECT_TRUE(api_->GetAccessPointData(&ap_data_));
- ASSERT_EQ(1u, ap_data_.size());
- EXPECT_EQ("00:00:03:04:05:06", UTF16ToUTF8(ap_data_.begin()->mac_address));
- EXPECT_EQ("SSID 0", UTF16ToUTF8(ap_data_.begin()->ssid));
-}
-
-TEST_F(GeolocationChromeOsWifiDataProviderTest, GetManyAccessPoints) {
- EXPECT_CALL(net_lib_, GetWifiAccessPoints(NotNull()))
- .WillOnce(DoAll(SetArgumentPointee<0>(MakeWifiAps(3, 4)), Return(true)));
- EXPECT_TRUE(api_->GetAccessPointData(&ap_data_));
- ASSERT_EQ(12u, ap_data_.size());
-}
-
-} // namespace chromeos