summaryrefslogtreecommitdiffstats
path: root/chrome/browser/geolocation
diff options
context:
space:
mode:
authorjknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-14 17:45:50 +0000
committerjknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-14 17:45:50 +0000
commitffd0abdc00f3c8e8e711d86c8633976db3963f42 (patch)
tree0f8e55a221d3eaa3f18af47b61dae31c078890b3 /chrome/browser/geolocation
parent52dd1112a84d627fa45b7c5051f14b5b118f5a83 (diff)
downloadchromium_src-ffd0abdc00f3c8e8e711d86c8633976db3963f42.zip
chromium_src-ffd0abdc00f3c8e8e711d86c8633976db3963f42.tar.gz
chromium_src-ffd0abdc00f3c8e8e711d86c8633976db3963f42.tar.bz2
Client-based geolocation support.
Add in support for client-based geolocation in WebKit. Default to disabled (ENABLE_CLIENT_BASED_GEOLOCATION=0) in features_override.gypi until all the WebKit patches (see https://bugs.webkit.org/show_bug.cgi?id=45752) have landed. When we switch over to client-based geolocation, we should remove the old non-client-based geolocation code. BUG=55907 Review URL: http://codereview.chromium.org/5612005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69156 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/geolocation')
-rw-r--r--chrome/browser/geolocation/geolocation_dispatcher_host.cc (renamed from chrome/browser/geolocation/geolocation_dispatcher_host_old.cc)94
-rw-r--r--chrome/browser/geolocation/geolocation_dispatcher_host.h31
-rw-r--r--chrome/browser/geolocation/geolocation_dispatcher_host_old.h39
-rw-r--r--chrome/browser/geolocation/geolocation_permission_context.cc10
-rw-r--r--chrome/browser/geolocation/geolocation_permission_context.h2
-rw-r--r--chrome/browser/geolocation/mock_location_provider.cc4
6 files changed, 94 insertions, 86 deletions
diff --git a/chrome/browser/geolocation/geolocation_dispatcher_host_old.cc b/chrome/browser/geolocation/geolocation_dispatcher_host.cc
index ca5298d..4f4020b3 100644
--- a/chrome/browser/geolocation/geolocation_dispatcher_host_old.cc
+++ b/chrome/browser/geolocation/geolocation_dispatcher_host.cc
@@ -2,7 +2,7 @@
// 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_dispatcher_host_old.h"
+#include "chrome/browser/geolocation/geolocation_dispatcher_host.h"
#include <map>
#include <set>
@@ -19,24 +19,21 @@
#include "ipc/ipc_message.h"
namespace {
-class GeolocationDispatcherHostOldImpl : public GeolocationDispatcherHostOld,
- public GeolocationObserver {
+class GeolocationDispatcherHostImpl : public GeolocationDispatcherHost,
+ public GeolocationObserver {
public:
- GeolocationDispatcherHostOldImpl(
- int resource_message_filter_process_id,
+ GeolocationDispatcherHostImpl(
+ int render_process_id,
GeolocationPermissionContext* geolocation_permission_context);
- // GeolocationDispatcherHostOld
- // Called to possibly handle the incoming IPC message. Returns true if
- // handled. Called in the browser process.
+ // GeolocationDispatcherHost
virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok);
- // GeolocationArbitrator::Delegate
+ // GeolocationObserver
virtual void OnLocationUpdate(const Geoposition& position);
private:
- friend class base::RefCountedThreadSafe<GeolocationDispatcherHostOldImpl>;
- virtual ~GeolocationDispatcherHostOldImpl();
+ virtual ~GeolocationDispatcherHostImpl();
void OnRegisterDispatcher(int render_view_id);
void OnUnregisterDispatcher(int render_view_id);
@@ -55,7 +52,7 @@ class GeolocationDispatcherHostOldImpl : public GeolocationDispatcherHostOld,
// options, based on |bridge_update_options_|.
void RefreshGeolocationObserverOptions();
- int resource_message_filter_process_id_;
+ int render_process_id_;
scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;
// Iterated when sending location updates to renderer processes. The fan out
@@ -70,13 +67,13 @@ class GeolocationDispatcherHostOldImpl : public GeolocationDispatcherHostOld,
// Only set whilst we are registered with the arbitrator.
GeolocationProvider* location_provider_;
- DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHostOldImpl);
+ DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHostImpl);
};
-GeolocationDispatcherHostOldImpl::GeolocationDispatcherHostOldImpl(
- int resource_message_filter_process_id,
+GeolocationDispatcherHostImpl::GeolocationDispatcherHostImpl(
+ int render_process_id,
GeolocationPermissionContext* geolocation_permission_context)
- : resource_message_filter_process_id_(resource_message_filter_process_id),
+ : render_process_id_(render_process_id),
geolocation_permission_context_(geolocation_permission_context),
location_provider_(NULL) {
// This is initialized by ResourceMessageFilter. Do not add any non-trivial
@@ -84,17 +81,17 @@ GeolocationDispatcherHostOldImpl::GeolocationDispatcherHostOldImpl(
// a javascript geolocation object is actually initialized.
}
-GeolocationDispatcherHostOldImpl::~GeolocationDispatcherHostOldImpl() {
+GeolocationDispatcherHostImpl::~GeolocationDispatcherHostImpl() {
if (location_provider_)
location_provider_->RemoveObserver(this);
}
-bool GeolocationDispatcherHostOldImpl::OnMessageReceived(
+bool GeolocationDispatcherHostImpl::OnMessageReceived(
const IPC::Message& msg, bool* msg_was_ok) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
*msg_was_ok = true;
bool handled = true;
- IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHostOldImpl, msg, *msg_was_ok)
+ IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHostImpl, msg, *msg_was_ok)
IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RegisterDispatcher,
OnRegisterDispatcher)
IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_UnregisterDispatcher,
@@ -116,103 +113,112 @@ bool GeolocationDispatcherHostOldImpl::OnMessageReceived(
return handled;
}
-void GeolocationDispatcherHostOldImpl::OnLocationUpdate(
+void GeolocationDispatcherHostImpl::OnLocationUpdate(
const Geoposition& geoposition) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
for (std::set<int>::iterator it = geolocation_renderer_ids_.begin();
it != geolocation_renderer_ids_.end(); ++it) {
IPC::Message* message =
new ViewMsg_Geolocation_PositionUpdated(*it, geoposition);
- CallRenderViewHost(resource_message_filter_process_id_, *it,
+ CallRenderViewHost(render_process_id_, *it,
&RenderViewHost::Send, message);
}
}
-void GeolocationDispatcherHostOldImpl::OnRegisterDispatcher(
+void GeolocationDispatcherHostImpl::OnRegisterDispatcher(
int render_view_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK_EQ(0u, geolocation_renderer_ids_.count(render_view_id));
geolocation_renderer_ids_.insert(render_view_id);
}
-void GeolocationDispatcherHostOldImpl::OnUnregisterDispatcher(
+void GeolocationDispatcherHostImpl::OnUnregisterDispatcher(
int render_view_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK_EQ(1u, geolocation_renderer_ids_.count(render_view_id));
geolocation_renderer_ids_.erase(render_view_id);
}
-void GeolocationDispatcherHostOldImpl::OnRequestPermission(
+void GeolocationDispatcherHostImpl::OnRequestPermission(
int render_view_id,
int bridge_id,
const GURL& requesting_frame) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":"
+ DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":"
<< render_view_id << ":" << bridge_id;
geolocation_permission_context_->RequestGeolocationPermission(
- resource_message_filter_process_id_, render_view_id, bridge_id,
+ render_process_id_, render_view_id, bridge_id,
requesting_frame);
}
-void GeolocationDispatcherHostOldImpl::OnCancelPermissionRequest(
+void GeolocationDispatcherHostImpl::OnCancelPermissionRequest(
int render_view_id,
int bridge_id,
const GURL& requesting_frame) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":"
+ DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":"
<< render_view_id << ":" << bridge_id;
geolocation_permission_context_->CancelGeolocationPermissionRequest(
- resource_message_filter_process_id_, render_view_id, bridge_id,
+ render_process_id_, render_view_id, bridge_id,
requesting_frame);
}
-void GeolocationDispatcherHostOldImpl::OnStartUpdating(
+void GeolocationDispatcherHostImpl::OnStartUpdating(
int render_view_id,
int bridge_id,
const GURL& requesting_frame,
bool enable_high_accuracy) {
+#if defined(ENABLE_CLIENT_BASED_GEOLOCATION)
+ // StartUpdating() can be invoked as a result of high-accuracy mode
+ // being enabled / disabled. No need to register the dispatcher again.
+ if (!geolocation_renderer_ids_.count(render_view_id))
+ OnRegisterDispatcher(render_view_id);
+#endif
// WebKit sends the startupdating request before checking permissions, to
// optimize the no-location-available case and reduce latency in the success
// case (location lookup happens in parallel with the permission request).
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":"
+ DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":"
<< render_view_id << ":" << bridge_id;
bridge_update_options_[std::make_pair(render_view_id, bridge_id)] =
GeolocationObserverOptions(enable_high_accuracy);
geolocation_permission_context_->StartUpdatingRequested(
- resource_message_filter_process_id_, render_view_id, bridge_id,
+ render_process_id_, render_view_id, bridge_id,
requesting_frame);
RefreshGeolocationObserverOptions();
}
-void GeolocationDispatcherHostOldImpl::OnStopUpdating(int render_view_id,
+void GeolocationDispatcherHostImpl::OnStopUpdating(int render_view_id,
int bridge_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":"
+ DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":"
<< render_view_id << ":" << bridge_id;
if (bridge_update_options_.erase(std::make_pair(render_view_id, bridge_id)))
RefreshGeolocationObserverOptions();
geolocation_permission_context_->StopUpdatingRequested(
- resource_message_filter_process_id_, render_view_id, bridge_id);
+ render_process_id_, render_view_id, bridge_id);
+#if defined(ENABLE_CLIENT_BASED_GEOLOCATION)
+ OnUnregisterDispatcher(render_view_id);
+#endif
}
-void GeolocationDispatcherHostOldImpl::OnSuspend(int render_view_id,
+void GeolocationDispatcherHostImpl::OnSuspend(int render_view_id,
int bridge_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":"
+ DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":"
<< render_view_id << ":" << bridge_id;
// TODO(bulach): connect this with GeolocationArbitrator.
}
-void GeolocationDispatcherHostOldImpl::OnResume(int render_view_id,
+void GeolocationDispatcherHostImpl::OnResume(int render_view_id,
int bridge_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DVLOG(1) << __FUNCTION__ << " " << resource_message_filter_process_id_ << ":"
+ DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":"
<< render_view_id << ":" << bridge_id;
// TODO(bulach): connect this with GeolocationArbitrator.
}
-void GeolocationDispatcherHostOldImpl::RefreshGeolocationObserverOptions() {
+void GeolocationDispatcherHostImpl::RefreshGeolocationObserverOptions() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (bridge_update_options_.empty()) {
if (location_provider_) {
@@ -230,10 +236,10 @@ void GeolocationDispatcherHostOldImpl::RefreshGeolocationObserverOptions() {
}
} // namespace
-GeolocationDispatcherHostOld* GeolocationDispatcherHostOld::New(
- int resource_message_filter_process_id,
+GeolocationDispatcherHost* GeolocationDispatcherHost::New(
+ int render_process_id,
GeolocationPermissionContext* geolocation_permission_context) {
- return new GeolocationDispatcherHostOldImpl(
- resource_message_filter_process_id,
+ return new GeolocationDispatcherHostImpl(
+ render_process_id,
geolocation_permission_context);
}
diff --git a/chrome/browser/geolocation/geolocation_dispatcher_host.h b/chrome/browser/geolocation/geolocation_dispatcher_host.h
new file mode 100644
index 0000000..293cb33
--- /dev/null
+++ b/chrome/browser/geolocation/geolocation_dispatcher_host.h
@@ -0,0 +1,31 @@
+// 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_DISPATCHER_HOST_H_
+#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
+#pragma once
+
+#include "chrome/browser/browser_message_filter.h"
+
+class GeolocationPermissionContext;
+
+// GeolocationDispatcherHost is a browser filter for Geolocation messages.
+// It's the complement of GeolocationDispatcher (owned by RenderView).
+
+class GeolocationDispatcherHost : public BrowserMessageFilter {
+ public:
+ static GeolocationDispatcherHost* New(
+ int render_process_id,
+ GeolocationPermissionContext* geolocation_permission_context);
+
+ virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok) = 0;
+
+ protected:
+ GeolocationDispatcherHost() {}
+ virtual ~GeolocationDispatcherHost() {}
+
+ DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost);
+};
+
+#endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
diff --git a/chrome/browser/geolocation/geolocation_dispatcher_host_old.h b/chrome/browser/geolocation/geolocation_dispatcher_host_old.h
deleted file mode 100644
index 655049a..0000000
--- a/chrome/browser/geolocation/geolocation_dispatcher_host_old.h
+++ /dev/null
@@ -1,39 +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_DISPATCHER_HOST_OLD_H_
-#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_OLD_H_
-#pragma once
-
-#include "base/ref_counted.h"
-
-class GeolocationPermissionContext;
-namespace IPC { class Message; }
-
-// GeolocationDispatcherHostOld is a delegate for Geolocation messages used by
-// ResourceMessageFilter.
-// It's the complement of GeolocationDispatcher (owned by RenderView).
-
-// TODO(jknotten): Remove this class once the new client-based implementation is
-// checked in (see http://crbug.com/59908).
-class GeolocationDispatcherHostOld
- : public base::RefCountedThreadSafe<GeolocationDispatcherHostOld> {
- public:
- static GeolocationDispatcherHostOld* New(
- int resource_message_filter_process_id,
- GeolocationPermissionContext* geolocation_permission_context);
-
- // Called to possibly handle the incoming IPC message. Returns true if
- // handled. Called in the browser process.
- virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok) = 0;
-
- protected:
- friend class base::RefCountedThreadSafe<GeolocationDispatcherHostOld>;
- GeolocationDispatcherHostOld() {}
- virtual ~GeolocationDispatcherHostOld() {}
-
- DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHostOld);
-};
-
-#endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_OLD_H_
diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc
index 2a8e542..1f8160d 100644
--- a/chrome/browser/geolocation/geolocation_permission_context.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context.cc
@@ -10,7 +10,6 @@
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
-#include "chrome/browser/geolocation/geolocation_dispatcher_host_old.h"
#include "chrome/browser/geolocation/geolocation_provider.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/prefs/pref_service.h"
@@ -440,6 +439,12 @@ void GeolocationPermissionContext::StartUpdatingRequested(
// Note we cannot store the arbitrator as a member as it is not thread safe.
GeolocationProvider* provider = GeolocationProvider::GetInstance();
+#if defined(ENABLE_CLIENT_BASED_GEOLOCATION)
+ // Client-based Geolocation uses a preemptive permission model, so permission
+ // ought to have been requested and granted before the controller requests
+ // the client to start updating.
+ DCHECK(provider->HasPermissionBeenGranted());
+#else
// WebKit will not request permission until it has received a valid
// location, but the google network location provider will not give a
// valid location until the user has granted permission. So we cut the Gordian
@@ -449,11 +454,14 @@ void GeolocationPermissionContext::StartUpdatingRequested(
RequestGeolocationPermission(render_process_id, render_view_id, bridge_id,
requesting_frame);
}
+#endif
}
void GeolocationPermissionContext::StopUpdatingRequested(
int render_process_id, int render_view_id, int bridge_id) {
+#if !defined(ENABLE_CLIENT_BASED_GEOLOCATION)
CancelPendingInfoBarRequest(render_process_id, render_view_id, bridge_id);
+#endif
}
void GeolocationPermissionContext::NotifyPermissionSet(
diff --git a/chrome/browser/geolocation/geolocation_permission_context.h b/chrome/browser/geolocation/geolocation_permission_context.h
index 432c9a2..c2a08e7 100644
--- a/chrome/browser/geolocation/geolocation_permission_context.h
+++ b/chrome/browser/geolocation/geolocation_permission_context.h
@@ -46,7 +46,7 @@ class GeolocationPermissionContext
// Called when a geolocation object wants to start receiving location updates.
// This also applies global policy around which location providers may be
- // enbaled at a given time (e.g. prior to the user agreeing to any geolocation
+ // enabled at a given time (e.g. prior to the user agreeing to any geolocation
// permission requests).
void StartUpdatingRequested(
int render_process_id, int render_view_id, int bridge_id,
diff --git a/chrome/browser/geolocation/mock_location_provider.cc b/chrome/browser/geolocation/mock_location_provider.cc
index 689ab9c..e3575f0 100644
--- a/chrome/browser/geolocation/mock_location_provider.cc
+++ b/chrome/browser/geolocation/mock_location_provider.cc
@@ -78,7 +78,9 @@ class AutoMockLocationProvider : public MockLocationProvider {
position_.accuracy = 3;
position_.latitude = 4.3;
position_.longitude = -7.8;
- position_.timestamp = base::Time::FromDoubleT(4567.8);
+ // Webkit compares the timestamp to wall clock time, so we need it to be
+ // contemporary.
+ position_.timestamp = base::Time::Now();
} else {
position_.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE;
}