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" | 13 #include "content/browser/geolocation/geolocation_provider_impl.h" |
14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
15 | 15 |
16 class GURL; | 16 class GURL; |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 // GeolocationDispatcherHost is an observer for Geolocation messages. | 20 // GeolocationDispatcherHost is an observer for Geolocation permissions-related |
21 // It's the complement of GeolocationDispatcher (owned by RenderView). | 21 // messages. In this role, it's the complement of GeolocationDispatcher (owned |
| 22 // by RenderFrame). |
| 23 // TODO(blundell): Eliminate this class in favor of having |
| 24 // Mojo handle permissions for geolocation once there is resolution on how |
| 25 // that will work. crbug.com/420498 |
22 class GeolocationDispatcherHost : public WebContentsObserver { | 26 class GeolocationDispatcherHost : public WebContentsObserver { |
23 public: | 27 public: |
24 explicit GeolocationDispatcherHost(WebContents* web_contents); | 28 explicit GeolocationDispatcherHost(WebContents* web_contents); |
25 virtual ~GeolocationDispatcherHost(); | 29 virtual ~GeolocationDispatcherHost(); |
26 | 30 |
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: | 31 private: |
34 // WebContentsObserver | 32 // 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( | 33 virtual bool OnMessageReceived( |
39 const IPC::Message& msg, RenderFrameHost* render_frame_host) OVERRIDE; | 34 const IPC::Message& msg, RenderFrameHost* render_frame_host) OVERRIDE; |
40 | 35 |
41 // Message handlers: | 36 // Message handlers: |
42 void OnRequestPermission(RenderFrameHost* render_frame_host, | 37 void OnRequestPermission(RenderFrameHost* render_frame_host, |
43 int bridge_id, | 38 int bridge_id, |
44 const GURL& requesting_frame, | 39 const GURL& requesting_frame, |
45 bool user_gesture); | 40 bool user_gesture); |
46 void OnCancelPermissionRequest(RenderFrameHost* render_frame_host, | 41 void OnCancelPermissionRequest(RenderFrameHost* render_frame_host, |
47 int bridge_id, | 42 int bridge_id, |
48 const GURL& requesting_frame); | 43 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 | 44 |
60 void SendGeolocationPermissionResponse(int render_process_id, | 45 void SendGeolocationPermissionResponse(int render_process_id, |
61 int render_frame_id, | 46 int render_frame_id, |
62 int bridge_id, | 47 int bridge_id, |
63 bool allowed); | 48 bool allowed); |
64 | 49 |
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 { | 50 struct PendingPermission { |
71 PendingPermission(int render_frame_id, | 51 PendingPermission(int render_frame_id, |
72 int render_process_id, | 52 int render_process_id, |
73 int bridge_id); | 53 int bridge_id); |
74 ~PendingPermission(); | 54 ~PendingPermission(); |
75 int render_frame_id; | 55 int render_frame_id; |
76 int render_process_id; | 56 int render_process_id; |
77 int bridge_id; | 57 int bridge_id; |
78 }; | 58 }; |
79 std::vector<PendingPermission> pending_permissions_; | 59 std::vector<PendingPermission> pending_permissions_; |
80 | 60 |
81 scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_; | |
82 | |
83 base::WeakPtrFactory<GeolocationDispatcherHost> weak_factory_; | 61 base::WeakPtrFactory<GeolocationDispatcherHost> weak_factory_; |
84 | 62 |
85 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost); | 63 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost); |
86 }; | 64 }; |
87 | 65 |
88 } // namespace content | 66 } // namespace content |
89 | 67 |
90 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ | 68 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ |
OLD | NEW |