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 #include "content/renderer/geolocation_dispatcher.h" | 5 #include "content/renderer/geolocation_dispatcher.h" |
6 | 6 |
7 #include "content/common/geolocation_messages.h" | 7 #include "content/child/child_thread.h" |
| 8 #include "content/public/common/geoposition.h" |
8 #include "content/renderer/render_view_impl.h" | 9 #include "content/renderer/render_view_impl.h" |
9 #include "third_party/WebKit/public/platform/WebString.h" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
10 #include "third_party/WebKit/public/web/WebGeolocationPermissionRequest.h" | 11 #include "third_party/WebKit/public/web/WebGeolocationPermissionRequest.h" |
11 #include "third_party/WebKit/public/web/WebGeolocationPermissionRequestManager.h
" | 12 #include "third_party/WebKit/public/web/WebGeolocationPermissionRequestManager.h
" |
12 #include "third_party/WebKit/public/web/WebGeolocationClient.h" | 13 #include "third_party/WebKit/public/web/WebGeolocationClient.h" |
13 #include "third_party/WebKit/public/web/WebGeolocationPosition.h" | 14 #include "third_party/WebKit/public/web/WebGeolocationPosition.h" |
14 #include "third_party/WebKit/public/web/WebGeolocationError.h" | 15 #include "third_party/WebKit/public/web/WebGeolocationError.h" |
15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 16 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
16 | 17 |
17 using blink::WebGeolocationController; | 18 using blink::WebGeolocationController; |
18 using blink::WebGeolocationError; | 19 using blink::WebGeolocationError; |
19 using blink::WebGeolocationPermissionRequest; | 20 using blink::WebGeolocationPermissionRequest; |
20 using blink::WebGeolocationPermissionRequestManager; | 21 using blink::WebGeolocationPermissionRequestManager; |
21 using blink::WebGeolocationPosition; | 22 using blink::WebGeolocationPosition; |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 | 25 |
25 GeolocationDispatcher::GeolocationDispatcher(RenderFrame* render_frame) | 26 GeolocationDispatcher::GeolocationDispatcher(RenderFrame* render_frame) |
26 : RenderFrameObserver(render_frame), | 27 : RenderFrameObserver(render_frame), |
27 pending_permissions_(new WebGeolocationPermissionRequestManager()), | 28 pending_permissions_(new WebGeolocationPermissionRequestManager()), |
28 enable_high_accuracy_(false) { | 29 enable_high_accuracy_(false) { |
29 } | 30 } |
30 | 31 |
31 GeolocationDispatcher::~GeolocationDispatcher() {} | 32 GeolocationDispatcher::~GeolocationDispatcher() {} |
32 | 33 |
33 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) { | |
34 bool handled = true; | |
35 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message) | |
36 IPC_MESSAGE_HANDLER(GeolocationMsg_PermissionSet, OnPermissionSet) | |
37 IPC_MESSAGE_UNHANDLED(handled = false) | |
38 IPC_END_MESSAGE_MAP() | |
39 return handled; | |
40 } | |
41 | |
42 void GeolocationDispatcher::startUpdating() { | 34 void GeolocationDispatcher::startUpdating() { |
43 if (!geolocation_service_.get()) { | 35 if (!geolocation_service_.get()) { |
44 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 36 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
45 &geolocation_service_); | 37 &geolocation_service_); |
46 geolocation_service_.set_client(this); | 38 geolocation_service_.set_client(this); |
47 } | 39 } |
48 if (enable_high_accuracy_) | 40 if (enable_high_accuracy_) |
49 geolocation_service_->SetHighAccuracy(true); | 41 geolocation_service_->SetHighAccuracy(true); |
50 } | 42 } |
51 | 43 |
(...skipping 23 matching lines...) Expand all Loading... |
75 // would have to fetch it synchronously to give a good value here. The | 67 // would have to fetch it synchronously to give a good value here. The |
76 // WebCore::GeolocationController already caches the last position it | 68 // WebCore::GeolocationController already caches the last position it |
77 // receives, so there is not much benefit to more position caching here. | 69 // receives, so there is not much benefit to more position caching here. |
78 return false; | 70 return false; |
79 } | 71 } |
80 | 72 |
81 // TODO(jknotten): Change the messages to use a security origin, so no | 73 // TODO(jknotten): Change the messages to use a security origin, so no |
82 // conversion is necessary. | 74 // conversion is necessary. |
83 void GeolocationDispatcher::requestPermission( | 75 void GeolocationDispatcher::requestPermission( |
84 const WebGeolocationPermissionRequest& permissionRequest) { | 76 const WebGeolocationPermissionRequest& permissionRequest) { |
85 int bridge_id = pending_permissions_->add(permissionRequest); | 77 if (!permission_service_.get()) { |
86 base::string16 origin = permissionRequest.securityOrigin().toString(); | 78 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
87 Send(new GeolocationHostMsg_RequestPermission( | 79 &permission_service_); |
88 routing_id(), bridge_id, GURL(origin), | 80 } |
89 blink::WebUserGestureIndicator::isProcessingUserGesture())); | 81 |
| 82 int permission_request_id = pending_permissions_->add(permissionRequest); |
| 83 |
| 84 PermissionName permission = PERMISSION_NAME_GEOLOCATION; |
| 85 |
| 86 permission_service_->RequestPermission( |
| 87 permission, |
| 88 permissionRequest.securityOrigin().toString().utf8(), |
| 89 base::Bind(&GeolocationDispatcher::OnPermissionSet, |
| 90 base::Unretained(this), |
| 91 permission_request_id)); |
90 } | 92 } |
91 | 93 |
92 void GeolocationDispatcher::cancelPermissionRequest( | 94 void GeolocationDispatcher::cancelPermissionRequest( |
93 const WebGeolocationPermissionRequest& permissionRequest) { | 95 const blink::WebGeolocationPermissionRequest& permissionRequest) { |
94 int bridge_id; | 96 int permission_request_id; |
95 pending_permissions_->remove(permissionRequest, bridge_id); | 97 pending_permissions_->remove(permissionRequest, permission_request_id); |
96 } | 98 } |
97 | 99 |
98 // Permission for using geolocation has been set. | 100 // Permission for using geolocation has been set. |
99 void GeolocationDispatcher::OnPermissionSet(int bridge_id, bool is_allowed) { | 101 void GeolocationDispatcher::OnPermissionSet( |
| 102 int permission_request_id, |
| 103 PermissionStatus status) { |
100 WebGeolocationPermissionRequest permissionRequest; | 104 WebGeolocationPermissionRequest permissionRequest; |
101 if (!pending_permissions_->remove(bridge_id, permissionRequest)) | 105 if (!pending_permissions_->remove(permission_request_id, permissionRequest)) |
102 return; | 106 return; |
103 permissionRequest.setIsAllowed(is_allowed); | 107 |
| 108 permissionRequest.setIsAllowed(status == PERMISSION_STATUS_GRANTED); |
104 } | 109 } |
105 | 110 |
106 void GeolocationDispatcher::OnLocationUpdate(MojoGeopositionPtr geoposition) { | 111 void GeolocationDispatcher::OnLocationUpdate(MojoGeopositionPtr geoposition) { |
107 DCHECK(geolocation_service_.get()); | 112 DCHECK(geolocation_service_.get()); |
108 | 113 |
109 if (geoposition->valid) { | 114 if (geoposition->valid) { |
110 controller_->positionChanged(WebGeolocationPosition( | 115 controller_->positionChanged(WebGeolocationPosition( |
111 geoposition->timestamp, | 116 geoposition->timestamp, |
112 geoposition->latitude, | 117 geoposition->latitude, |
113 geoposition->longitude, | 118 geoposition->longitude, |
(...skipping 19 matching lines...) Expand all Loading... |
133 default: | 138 default: |
134 NOTREACHED() << geoposition->error_code; | 139 NOTREACHED() << geoposition->error_code; |
135 return; | 140 return; |
136 } | 141 } |
137 controller_->errorOccurred(WebGeolocationError( | 142 controller_->errorOccurred(WebGeolocationError( |
138 code, blink::WebString::fromUTF8(geoposition->error_message))); | 143 code, blink::WebString::fromUTF8(geoposition->error_message))); |
139 } | 144 } |
140 } | 145 } |
141 | 146 |
142 } // namespace content | 147 } // namespace content |
OLD | NEW |