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.
5 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
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"
20 // GeolocationDispatcherHost is an observer for Geolocation messages.
21 // It's the complement of GeolocationDispatcher (owned by RenderView).
22 class GeolocationDispatcherHost
: public WebContentsObserver
{
24 explicit GeolocationDispatcherHost(WebContents
* web_contents
);
25 virtual ~GeolocationDispatcherHost();
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
);
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
;
42 void OnRequestPermission(RenderFrameHost
* render_frame_host
,
44 const GURL
& requesting_frame
,
46 void OnCancelPermissionRequest(RenderFrameHost
* render_frame_host
,
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
);
54 // Updates the geolocation provider with the currently required update
56 void RefreshGeolocationOptions();
58 void OnLocationUpdate(const Geoposition
& position
);
60 void SendGeolocationPermissionResponse(int render_process_id
,
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_
;
70 struct PendingPermission
{
71 PendingPermission(int render_frame_id
,
72 int render_process_id
,
76 int render_process_id
;
80 std::vector
<PendingPermission
> pending_permissions_
;
82 scoped_ptr
<GeolocationProvider::Subscription
> geolocation_subscription_
;
84 base::WeakPtrFactory
<GeolocationDispatcherHost
> weak_factory_
;
86 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost
);
89 } // namespace content
91 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_