OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ |
6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/memory/weak_ptr.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" | 13 #include "content/public/browser/web_contents_observer.h" |
15 | 14 |
16 class GURL; | 15 class GURL; |
17 | 16 |
18 namespace content { | 17 namespace content { |
19 | 18 |
20 // GeolocationDispatcherHost is an observer for Geolocation messages. | 19 // GeolocationDispatcherHost is an observer for Geolocation permissions-related |
21 // It's the complement of GeolocationDispatcher (owned by RenderView). | 20 // messages. In this role, it's the complement of GeolocationDispatcher (owned |
21 // by RenderFrame). | |
22 // TODO(blundell): Eliminate this class in favor of having | |
23 // Mojo handle permissions for geolocation once there is resolution on how | |
24 // that will work. crbug.com/420498 | |
22 class GeolocationDispatcherHost : public WebContentsObserver { | 25 class GeolocationDispatcherHost : public WebContentsObserver { |
23 public: | 26 public: |
24 explicit GeolocationDispatcherHost(WebContents* web_contents); | 27 explicit GeolocationDispatcherHost(WebContents* web_contents); |
25 ~GeolocationDispatcherHost() override; | 28 ~GeolocationDispatcherHost() override; |
26 | 29 |
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 // 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); | |
36 | |
37 // Disables geolocation override. | |
38 void ClearOverride(); | |
39 | |
40 private: | 30 private: |
41 // WebContentsObserver | 31 // WebContentsObserver |
42 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; | 32 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
Michael van Ouwerkerk
2014/10/24 10:25:42
Drop the 'virtual' - https://groups.google.com/a/c
blundell
2014/10/24 11:45:18
Done.
| |
43 void RenderViewHostChanged(RenderViewHost* old_host, | 33 virtual void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, |
Michael van Ouwerkerk
2014/10/24 10:25:42
And here.
blundell
2014/10/24 11:45:18
Done.
| |
44 RenderViewHost* new_host) override; | 34 const LoadCommittedDetails& details, |
45 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, | 35 const FrameNavigateParams& params) override; |
46 const LoadCommittedDetails& details, | |
47 const FrameNavigateParams& params) override; | |
48 bool OnMessageReceived(const IPC::Message& msg, | 36 bool OnMessageReceived(const IPC::Message& msg, |
49 RenderFrameHost* render_frame_host) override; | 37 RenderFrameHost* render_frame_host) override; |
50 | 38 |
51 // Message handlers: | 39 // Message handlers: |
52 // TODO(mlamouri): |requesting_origin| should be a security origin to | 40 // TODO(mlamouri): |requesting_origin| should be a security origin to |
53 // guarantee that a proper origin is passed. | 41 // guarantee that a proper origin is passed. |
54 void OnRequestPermission(RenderFrameHost* render_frame_host, | 42 void OnRequestPermission(RenderFrameHost* render_frame_host, |
55 int bridge_id, | 43 int bridge_id, |
56 const GURL& requesting_origin, | 44 const GURL& requesting_origin, |
57 bool user_gesture); | 45 bool user_gesture); |
58 void OnStartUpdating(RenderFrameHost* render_frame_host, | |
59 const GURL& requesting_origin, | |
60 bool enable_high_accuracy); | |
61 void OnStopUpdating(RenderFrameHost* render_frame_host); | |
62 | |
63 // Updates the geolocation provider with the currently required update | |
64 // options. | |
65 void RefreshGeolocationOptions(); | |
66 | |
67 void OnLocationUpdate(const Geoposition& position); | |
68 void UpdateGeoposition(RenderFrameHost* frame, const Geoposition& position); | |
69 | 46 |
70 void SendGeolocationPermissionResponse(int render_process_id, | 47 void SendGeolocationPermissionResponse(int render_process_id, |
71 int render_frame_id, | 48 int render_frame_id, |
72 int bridge_id, | 49 int bridge_id, |
73 bool allowed); | 50 bool allowed); |
74 | 51 |
75 // Clear pending permissions associated with a given frame and request the | 52 // Clear pending permissions associated with a given frame and request the |
76 // browser to cancel the permission requests. | 53 // browser to cancel the permission requests. |
77 void CancelPermissionRequestsForFrame(RenderFrameHost* render_frame_host); | 54 void CancelPermissionRequestsForFrame(RenderFrameHost* render_frame_host); |
78 | 55 |
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_; | |
82 bool paused_; | |
83 | |
84 struct PendingPermission { | 56 struct PendingPermission { |
85 PendingPermission(int render_frame_id, | 57 PendingPermission(int render_frame_id, |
86 int render_process_id, | 58 int render_process_id, |
87 int bridge_id, | 59 int bridge_id, |
88 const GURL& origin); | 60 const GURL& origin); |
89 ~PendingPermission(); | 61 ~PendingPermission(); |
90 int render_frame_id; | 62 int render_frame_id; |
91 int render_process_id; | 63 int render_process_id; |
92 int bridge_id; | 64 int bridge_id; |
93 GURL origin; | 65 GURL origin; |
94 }; | 66 }; |
95 std::vector<PendingPermission> pending_permissions_; | 67 std::vector<PendingPermission> pending_permissions_; |
96 | 68 |
97 scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_; | |
98 scoped_ptr<Geoposition> geoposition_override_; | |
99 | |
100 base::WeakPtrFactory<GeolocationDispatcherHost> weak_factory_; | 69 base::WeakPtrFactory<GeolocationDispatcherHost> weak_factory_; |
101 | 70 |
102 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost); | 71 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost); |
103 }; | 72 }; |
104 | 73 |
105 } // namespace content | 74 } // namespace content |
106 | 75 |
107 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ | 76 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ |
OLD | NEW |