1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ 6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ 7 8 #include <map> 9 #include <vector> 10 11 #include "base/callback_forward.h" 12 #include "base/memory/weak_ptr.h" 13 #include "content/browser/geolocation/geolocation_provider_impl.h" 14 #include "content/public/browser/web_contents_observer.h" 15 16 class GURL; 17 18 namespace content { 19 20 // GeolocationDispatcherHost is an observer for Geolocation messages. 21 // It's the complement of GeolocationDispatcher (owned by RenderView). 22 class GeolocationDispatcherHost : public WebContentsObserver { 23 public: 24 explicit GeolocationDispatcherHost(WebContents* web_contents); 25 virtual ~GeolocationDispatcherHost(); 26 27 // Pause or resumes geolocation. Resuming when nothing is paused is a no-op. 28 // If the web contents is paused while not currently using geolocation but 29 // then goes on to do so before being resumed, then it will not get 30 // geolocation updates until it is resumed. 31 void PauseOrResume(bool should_pause); 32 33 private: 34 // WebContentsObserver 35 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE; 36 virtual void RenderViewHostChanged(RenderViewHost* old_host, 37 RenderViewHost* new_host) OVERRIDE; 38 virtual bool OnMessageReceived( 39 const IPC::Message& msg, RenderFrameHost* render_frame_host) OVERRIDE; 40 41 // Message handlers: 42 void OnRequestPermission(RenderFrameHost* render_frame_host, 43 int bridge_id, 44 const GURL& requesting_frame, 45 bool user_gesture); 46 void OnCancelPermissionRequest(RenderFrameHost* render_frame_host, 47 int bridge_id, 48 const GURL& requesting_frame); 49 void OnStartUpdating(RenderFrameHost* render_frame_host, 50 const GURL& requesting_frame, 51 bool enable_high_accuracy); 52 void OnStopUpdating(RenderFrameHost* render_frame_host); 53 54 // Updates the geolocation provider with the currently required update 55 // options. 56 void RefreshGeolocationOptions(); 57 58 void OnLocationUpdate(const Geoposition& position); 59 60 void SendGeolocationPermissionResponse(int render_process_id, 61 int render_frame_id, 62 int bridge_id, 63 bool allowed); 64 65 // A map from the RenderFrameHosts that have requested geolocation updates to 66 // the type of accuracy they requested (true = high accuracy). 67 std::map<RenderFrameHost*, bool> updating_frames_; 68 bool paused_; 69 70 struct PendingPermission { 71 PendingPermission(int render_frame_id, 72 int render_process_id, 73 int bridge_id); 74 ~PendingPermission(); 75 int render_frame_id; 76 int render_process_id; 77 int bridge_id; 78 base::Closure cancel; 79 }; 80 std::vector<PendingPermission> pending_permissions_; 81 82 scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_; 83 84 base::WeakPtrFactory<GeolocationDispatcherHost> weak_factory_; 85 86 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost); 87 }; 88 89 } // namespace content 90 91 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ 92