diff options
author | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 12:11:28 +0000 |
---|---|---|
committer | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 12:11:28 +0000 |
commit | 58c321dd57a1fc00c2c51b0a8b6e547fdf32aa74 (patch) | |
tree | cdd273a38ba1b449952d5701e6ceb6f46142c073 /chrome/renderer | |
parent | 2375d294b30e5d0b0bc63d26a417203959ef32af (diff) | |
download | chromium_src-58c321dd57a1fc00c2c51b0a8b6e547fdf32aa74.zip chromium_src-58c321dd57a1fc00c2c51b0a8b6e547fdf32aa74.tar.gz chromium_src-58c321dd57a1fc00c2c51b0a8b6e547fdf32aa74.tar.bz2 |
Second try for:
http://src.chromium.org/viewvc/chrome?view=rev&revision=39374
Initial Geolocation implementation
Adds IPC plumbing.
Adds Infobar buttons for requesting permission
This change specifically:
ui_test_utils::WaitForAppModalDialog registers for listening to notifications too late, i.e., after the dialog had been triggered.
Exposes AppModalDialogObserver so that we can register, trigger the dialog, then wait for it.
Review URL: http://codereview.chromium.org/647048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39435 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/geolocation_dispatcher.cc | 104 | ||||
-rw-r--r-- | chrome/renderer/geolocation_dispatcher.h | 57 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 13 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 9 |
4 files changed, 183 insertions, 0 deletions
diff --git a/chrome/renderer/geolocation_dispatcher.cc b/chrome/renderer/geolocation_dispatcher.cc new file mode 100644 index 0000000..fedad06 --- /dev/null +++ b/chrome/renderer/geolocation_dispatcher.cc @@ -0,0 +1,104 @@ +// 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/renderer/geolocation_dispatcher.h" + +#include "base/command_line.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/renderer/render_view.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/WebKit/chromium/public/WebCString.h" + +using WebKit::WebFrame; + +GeolocationDispatcher::GeolocationDispatcher(RenderView* render_view) + : render_view_(render_view) { + render_view_->Send(new ViewHostMsg_Geolocation_RegisterDispatcher( + render_view_->routing_id())); +} + +GeolocationDispatcher::~GeolocationDispatcher() { + render_view_->Send(new ViewHostMsg_Geolocation_UnregisterDispatcher( + render_view_->routing_id())); +} + +bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message) + IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PermissionSet, + OnGeolocationPermissionSet) + IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PositionUpdated, + OnGeolocationPositionUpdated) + IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_Error, OnGeolocationError) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void GeolocationDispatcher::requestPermissionForFrame( + int bridge_id, const WebKit::WebURL& url) { + render_view_->Send(new ViewHostMsg_Geolocation_RequestPermission( + bridge_id, render_view_->routing_id(), GURL(url).GetOrigin())); +} + +void GeolocationDispatcher::startUpdating(int bridge_id, bool hasHighAccuracy) { + render_view_->Send(new ViewHostMsg_Geolocation_StartUpdating( + bridge_id, render_view_->routing_id(), hasHighAccuracy)); +} + +void GeolocationDispatcher::stopUpdating(int bridge_id) { + render_view_->Send(new ViewHostMsg_Geolocation_StopUpdating( + bridge_id, render_view_->routing_id())); +} + +void GeolocationDispatcher::suspend(int bridge_id) { + render_view_->Send(new ViewHostMsg_Geolocation_Suspend( + bridge_id, render_view_->routing_id())); +} + +void GeolocationDispatcher::resume(int bridge_id) { + render_view_->Send(new ViewHostMsg_Geolocation_Resume( + bridge_id, render_view_->routing_id())); +} + +int GeolocationDispatcher::attachBridge( + WebKit::WebGeolocationServiceBridge* bridge) { + return bridges_map_.Add(bridge); +} + +void GeolocationDispatcher::dettachBridge(int bridge_id) { + bridges_map_.Remove(bridge_id); +} + +void GeolocationDispatcher::OnGeolocationPermissionSet(int bridge_id, + bool allowed) { + WebKit::WebGeolocationServiceBridge* bridge = bridges_map_.Lookup(bridge_id); + if (bridge) { + bridge->setIsAllowed(allowed); + } +} + +void GeolocationDispatcher::OnGeolocationPositionUpdated( + const Geoposition& geoposition) { + for (IDMap<WebKit::WebGeolocationServiceBridge>::iterator it(&bridges_map_); + !it.IsAtEnd(); it.Advance()) { + it.GetCurrentValue()->setLastPosition( + geoposition.latitude, geoposition.longitude, + geoposition.is_valid_altitude(), geoposition.altitude, + geoposition.accuracy, + geoposition.is_valid_altitude_accuracy(), geoposition.altitude_accuracy, + geoposition.is_valid_heading(), geoposition.heading, + geoposition.is_valid_speed(), geoposition.speed, + geoposition.timestamp); + } +} + +void GeolocationDispatcher::OnGeolocationError(int code, + const std::string& message) { + for (IDMap<WebKit::WebGeolocationServiceBridge>::iterator it(&bridges_map_); + !it.IsAtEnd(); it.Advance()) { + it.GetCurrentValue()->setLastError( + code, WebKit::WebString::fromUTF8(message)); + } +} diff --git a/chrome/renderer/geolocation_dispatcher.h b/chrome/renderer/geolocation_dispatcher.h new file mode 100644 index 0000000..31fdab4c --- /dev/null +++ b/chrome/renderer/geolocation_dispatcher.h @@ -0,0 +1,57 @@ +// 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_RENDERER_GEOLOCATION_DISPATCHER_H_ +#define CHROME_RENDERER_GEOLOCATION_DISPATCHER_H_ + +#include "base/basictypes.h" +#include "base/id_map.h" +#include "chrome/common/geoposition.h" +#include "ipc/ipc_message.h" +#include "googleurl/src/gurl.h" +#include "third_party/WebKit/WebKit/chromium/public/GeolocationServiceBridgeChromium.h" + +class GURL; +class RenderView; + +// GeolocationDispatcher is a delegate for Geolocation messages used by +// WebKit. +// It's the complement of GeolocationDispatcherHost (owned by RenderViewHost). +class GeolocationDispatcher : public WebKit::WebGeolocationServiceInterface { + public: + explicit GeolocationDispatcher(RenderView* render_view); + virtual ~GeolocationDispatcher(); + + // Called to possibly handle the incoming IPC message. Returns true if + // handled. Called in render thread. + bool OnMessageReceived(const IPC::Message& msg); + + // WebKit::GeolocationServiceInterfaceChromium. + void requestPermissionForFrame(int bridge_id, const WebKit::WebURL& url); + void startUpdating(int bridge_id, bool hasHighAccuracy); + void stopUpdating(int bridge_id); + void suspend(int bridge_id); + void resume(int bridge_id); + int attachBridge(WebKit::WebGeolocationServiceBridge* geolocation_service); + void dettachBridge(int bridge_id); + + private: + // Permission for using geolocation has been set. + void OnGeolocationPermissionSet(int bridge_id, bool is_allowed); + + // We have an updated geolocation position. + void OnGeolocationPositionUpdated(const Geoposition& geoposition); + + // An error has happened when fetching a geolocation position. + void OnGeolocationError(int code, const std::string& message); + + RenderView* render_view_; + + // The geolocation services attached to this dispatcher. + IDMap<WebKit::WebGeolocationServiceBridge> bridges_map_; + + DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcher); +}; + +#endif // CHROME_RENDERER_GEOLOCATION_DISPATCHER_H_ diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 14c57af..282d6ec 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -45,6 +45,7 @@ #include "chrome/renderer/extensions/event_bindings.h" #include "chrome/renderer/extensions/extension_process_bindings.h" #include "chrome/renderer/extensions/renderer_extension_bindings.h" +#include "chrome/renderer/geolocation_dispatcher.h" #include "chrome/renderer/localized_error.h" #include "chrome/renderer/media/audio_renderer_impl.h" #include "chrome/renderer/navigation_state.h" @@ -68,6 +69,7 @@ #include "skia/ext/bitmap_platform_device.h" #include "skia/ext/image_operations.h" #include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h" +#include "third_party/WebKit/WebKit/chromium/public/GeolocationServiceBridgeChromium.h" #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" @@ -482,6 +484,10 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { return; if (notification_provider_->OnMessageReceived(message)) return; + if (geolocation_dispatcher_.get() && + geolocation_dispatcher_->OnMessageReceived(message)) { + return; + } IPC_BEGIN_MESSAGE_MAP(RenderView, message) IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail) @@ -4497,3 +4503,10 @@ void RenderView::GPUPluginBuffersSwapped(gfx::PluginWindowHandle window) { Send(new ViewHostMsg_GPUPluginBuffersSwapped(routing_id(), window)); } #endif + +WebKit::WebGeolocationServiceInterface* RenderView::getGeolocationService() { + if (!geolocation_dispatcher_.get()) + geolocation_dispatcher_.reset(new GeolocationDispatcher(this)); + return geolocation_dispatcher_.get(); +} + diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 691ce8a..8f453b9 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -69,6 +69,7 @@ class DictionaryValue; class DevToolsAgent; class DevToolsClient; class FilePath; +class GeolocationDispatcher; class GURL; class ListValue; class NavigationState; @@ -89,6 +90,10 @@ struct FileUploadData; } namespace WebKit { +class WebGeolocationServiceInterfaceChromium; +} + +namespace WebKit { class WebAccessibilityCache; class WebDataSource; class WebDragData; @@ -259,6 +264,7 @@ class RenderView : public RenderWidget, virtual WebKit::WebNotificationPresenter* GetNotificationPresenter() { return notification_provider_.get(); } + virtual WebKit::WebGeolocationServiceInterface* getGeolocationService(); // Sets the content settings that back allowScripts(), allowImages(), and // allowPlugins(). @@ -1105,6 +1111,9 @@ class RenderView : public RenderWidget, std::set<WebPluginDelegateProxy*> plugin_delegates_; #endif + // The geolocation dispatcher attached to this view, lazily initialized. + scoped_ptr<GeolocationDispatcher> geolocation_dispatcher_; + DISALLOW_COPY_AND_ASSIGN(RenderView); }; |