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