OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/renderer/geolocation_dispatcher.h" | 5 #include "chrome/renderer/geolocation_dispatcher.h" |
6 | 6 |
7 #include "chrome/renderer/render_view.h" | |
8 #include "ipc/ipc_message.h" | |
9 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPermissionRequ
est.h" | 7 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPermissionRequ
est.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPermissionRequ
estManager.h" | 8 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPermissionRequ
estManager.h" |
11 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationClient.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationClient.h" |
12 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPosition.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPosition.h" |
13 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationError.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationError.h" |
14 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
15 | 13 |
16 using namespace WebKit; | 14 using namespace WebKit; |
17 | 15 |
18 GeolocationDispatcher::GeolocationDispatcher(RenderView* render_view) | 16 GeolocationDispatcher::GeolocationDispatcher(RenderView* render_view) |
19 : render_view_(render_view), | 17 : RenderView::Observer(render_view), |
20 pending_permissions_(new WebGeolocationPermissionRequestManager()), | 18 pending_permissions_(new WebGeolocationPermissionRequestManager()), |
21 enable_high_accuracy_(false), | 19 enable_high_accuracy_(false), |
22 updating_(false) { | 20 updating_(false) { |
23 } | 21 } |
24 | 22 |
25 GeolocationDispatcher::~GeolocationDispatcher() {} | 23 GeolocationDispatcher::~GeolocationDispatcher() {} |
26 | 24 |
27 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) { | 25 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) { |
28 bool handled = true; | 26 bool handled = true; |
29 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message) | 27 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message) |
30 IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PermissionSet, | 28 IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PermissionSet, |
31 OnGeolocationPermissionSet) | 29 OnGeolocationPermissionSet) |
32 IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PositionUpdated, | 30 IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PositionUpdated, |
33 OnGeolocationPositionUpdated) | 31 OnGeolocationPositionUpdated) |
34 IPC_MESSAGE_UNHANDLED(handled = false) | 32 IPC_MESSAGE_UNHANDLED(handled = false) |
35 IPC_END_MESSAGE_MAP() | 33 IPC_END_MESSAGE_MAP() |
36 return handled; | 34 return handled; |
37 } | 35 } |
38 | 36 |
39 void GeolocationDispatcher::geolocationDestroyed() { | 37 void GeolocationDispatcher::geolocationDestroyed() { |
40 controller_.reset(); | 38 controller_.reset(); |
41 DCHECK(!updating_); | 39 DCHECK(!updating_); |
42 } | 40 } |
43 | 41 |
44 void GeolocationDispatcher::startUpdating() { | 42 void GeolocationDispatcher::startUpdating() { |
45 GURL url; | 43 GURL url; |
46 render_view_->Send(new ViewHostMsg_Geolocation_StartUpdating( | 44 Send(new ViewHostMsg_Geolocation_StartUpdating( |
47 render_view_->routing_id(), url, enable_high_accuracy_)); | 45 routing_id(), url, enable_high_accuracy_)); |
48 updating_ = true; | 46 updating_ = true; |
49 } | 47 } |
50 | 48 |
51 void GeolocationDispatcher::stopUpdating() { | 49 void GeolocationDispatcher::stopUpdating() { |
52 render_view_->Send(new ViewHostMsg_Geolocation_StopUpdating( | 50 Send(new ViewHostMsg_Geolocation_StopUpdating(routing_id())); |
53 render_view_->routing_id())); | |
54 updating_ = false; | 51 updating_ = false; |
55 } | 52 } |
56 | 53 |
57 void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) { | 54 void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) { |
58 // GeolocationController calls setEnableHighAccuracy(true) before | 55 // GeolocationController calls setEnableHighAccuracy(true) before |
59 // startUpdating in response to the first high-accuracy Geolocation | 56 // startUpdating in response to the first high-accuracy Geolocation |
60 // subscription. When the last high-accuracy Geolocation unsubscribes | 57 // subscription. When the last high-accuracy Geolocation unsubscribes |
61 // it calls setEnableHighAccuracy(false) after stopUpdating. | 58 // it calls setEnableHighAccuracy(false) after stopUpdating. |
62 bool has_changed = enable_high_accuracy_ != enable_high_accuracy; | 59 bool has_changed = enable_high_accuracy_ != enable_high_accuracy; |
63 enable_high_accuracy_ = enable_high_accuracy; | 60 enable_high_accuracy_ = enable_high_accuracy; |
(...skipping 14 matching lines...) Expand all Loading... |
78 // receives, so there is not much benefit to more position caching here. | 75 // receives, so there is not much benefit to more position caching here. |
79 return false; | 76 return false; |
80 } | 77 } |
81 | 78 |
82 // TODO(jknotten): Change the messages to use a security origin, so no | 79 // TODO(jknotten): Change the messages to use a security origin, so no |
83 // conversion is necessary. | 80 // conversion is necessary. |
84 void GeolocationDispatcher::requestPermission( | 81 void GeolocationDispatcher::requestPermission( |
85 const WebGeolocationPermissionRequest& permissionRequest) { | 82 const WebGeolocationPermissionRequest& permissionRequest) { |
86 int bridge_id = pending_permissions_->add(permissionRequest); | 83 int bridge_id = pending_permissions_->add(permissionRequest); |
87 string16 origin = permissionRequest.securityOrigin().toString(); | 84 string16 origin = permissionRequest.securityOrigin().toString(); |
88 render_view_->Send(new ViewHostMsg_Geolocation_RequestPermission( | 85 Send(new ViewHostMsg_Geolocation_RequestPermission( |
89 render_view_->routing_id(), bridge_id, GURL(origin))); | 86 routing_id(), bridge_id, GURL(origin))); |
90 } | 87 } |
91 | 88 |
92 // TODO(jknotten): Change the messages to use a security origin, so no | 89 // TODO(jknotten): Change the messages to use a security origin, so no |
93 // conversion is necessary. | 90 // conversion is necessary. |
94 void GeolocationDispatcher::cancelPermissionRequest( | 91 void GeolocationDispatcher::cancelPermissionRequest( |
95 const WebGeolocationPermissionRequest& permissionRequest) { | 92 const WebGeolocationPermissionRequest& permissionRequest) { |
96 int bridge_id; | 93 int bridge_id; |
97 if (!pending_permissions_->remove(permissionRequest, bridge_id)) | 94 if (!pending_permissions_->remove(permissionRequest, bridge_id)) |
98 return; | 95 return; |
99 string16 origin = permissionRequest.securityOrigin().toString(); | 96 string16 origin = permissionRequest.securityOrigin().toString(); |
100 render_view_->Send(new ViewHostMsg_Geolocation_CancelPermissionRequest( | 97 Send(new ViewHostMsg_Geolocation_CancelPermissionRequest( |
101 render_view_->routing_id(), bridge_id, GURL(origin))); | 98 routing_id(), bridge_id, GURL(origin))); |
102 } | 99 } |
103 | 100 |
104 // Permission for using geolocation has been set. | 101 // Permission for using geolocation has been set. |
105 void GeolocationDispatcher::OnGeolocationPermissionSet( | 102 void GeolocationDispatcher::OnGeolocationPermissionSet( |
106 int bridge_id, bool is_allowed) { | 103 int bridge_id, bool is_allowed) { |
107 WebGeolocationPermissionRequest permissionRequest; | 104 WebGeolocationPermissionRequest permissionRequest; |
108 if (!pending_permissions_->remove(bridge_id, permissionRequest)) | 105 if (!pending_permissions_->remove(bridge_id, permissionRequest)) |
109 return; | 106 return; |
110 permissionRequest.setIsAllowed(is_allowed); | 107 permissionRequest.setIsAllowed(is_allowed); |
111 } | 108 } |
(...skipping 26 matching lines...) Expand all Loading... |
138 default: | 135 default: |
139 DCHECK(false); | 136 DCHECK(false); |
140 NOTREACHED() << geoposition.error_code; | 137 NOTREACHED() << geoposition.error_code; |
141 return; | 138 return; |
142 } | 139 } |
143 controller_->errorOccurred( | 140 controller_->errorOccurred( |
144 WebGeolocationError( | 141 WebGeolocationError( |
145 code, WebKit::WebString::fromUTF8(geoposition.error_message))); | 142 code, WebKit::WebString::fromUTF8(geoposition.error_message))); |
146 } | 143 } |
147 } | 144 } |
OLD | NEW |