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 ~GeolocationDispatcherHost() override
;
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
);
33 // Enables geolocation override. This method is used by DevTools to
34 // trigger possible location-specific behavior in particular web contents.
35 void SetOverride(scoped_ptr
<Geoposition
> geoposition
);
37 // Disables geolocation override.
41 // WebContentsObserver
42 void RenderFrameDeleted(RenderFrameHost
* render_frame_host
) override
;
43 void RenderViewHostChanged(RenderViewHost
* old_host
,
44 RenderViewHost
* new_host
) override
;
45 void DidNavigateAnyFrame(RenderFrameHost
* render_frame_host
,
46 const LoadCommittedDetails
& details
,
47 const FrameNavigateParams
& params
) override
;
48 bool OnMessageReceived(const IPC::Message
& msg
,
49 RenderFrameHost
* render_frame_host
) override
;
52 // TODO(mlamouri): |requesting_origin| should be a security origin to
53 // guarantee that a proper origin is passed.
54 void OnRequestPermission(RenderFrameHost
* render_frame_host
,
56 const GURL
& requesting_origin
,
58 void OnStartUpdating(RenderFrameHost
* render_frame_host
,
59 const GURL
& requesting_origin
,
60 bool enable_high_accuracy
);
61 void OnStopUpdating(RenderFrameHost
* render_frame_host
);
63 // Updates the geolocation provider with the currently required update
65 void RefreshGeolocationOptions();
67 void OnLocationUpdate(const Geoposition
& position
);
68 void UpdateGeoposition(RenderFrameHost
* frame
, const Geoposition
& position
);
70 void SendGeolocationPermissionResponse(int render_process_id
,
75 // Clear pending permissions associated with a given frame and request the
76 // browser to cancel the permission requests.
77 void CancelPermissionRequestsForFrame(RenderFrameHost
* render_frame_host
);
79 // A map from the RenderFrameHosts that have requested geolocation updates to
80 // the type of accuracy they requested (true = high accuracy).
81 std::map
<RenderFrameHost
*, bool> updating_frames_
;
84 struct PendingPermission
{
85 PendingPermission(int render_frame_id
,
86 int render_process_id
,
91 int render_process_id
;
95 std::vector
<PendingPermission
> pending_permissions_
;
97 scoped_ptr
<GeolocationProvider::Subscription
> geolocation_subscription_
;
98 scoped_ptr
<Geoposition
> geoposition_override_
;
100 base::WeakPtrFactory
<GeolocationDispatcherHost
> weak_factory_
;
102 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost
);
105 } // namespace content
107 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_