Chromium Code Reviews| 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), |
| 30 weak_ptr_factory_(this) { | |
| 29 } | 31 } |
| 30 | 32 |
| 31 GeolocationDispatcher::~GeolocationDispatcher() {} | 33 GeolocationDispatcher::~GeolocationDispatcher() {} |
| 32 | 34 |
| 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() { | 35 void GeolocationDispatcher::startUpdating() { |
| 43 if (!geolocation_service_.get()) { | 36 if (!geolocation_service_.get()) { |
| 44 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 37 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
| 45 &geolocation_service_); | 38 &geolocation_service_); |
| 46 geolocation_service_.set_client(this); | 39 geolocation_service_.set_client(this); |
| 47 } | 40 } |
| 48 if (enable_high_accuracy_) | 41 if (enable_high_accuracy_) |
| 49 geolocation_service_->SetHighAccuracy(true); | 42 geolocation_service_->SetHighAccuracy(true); |
| 50 } | 43 } |
| 51 | 44 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 75 // would have to fetch it synchronously to give a good value here. The | 68 // would have to fetch it synchronously to give a good value here. The |
| 76 // WebCore::GeolocationController already caches the last position it | 69 // WebCore::GeolocationController already caches the last position it |
| 77 // receives, so there is not much benefit to more position caching here. | 70 // receives, so there is not much benefit to more position caching here. |
| 78 return false; | 71 return false; |
| 79 } | 72 } |
| 80 | 73 |
| 81 // TODO(jknotten): Change the messages to use a security origin, so no | 74 // TODO(jknotten): Change the messages to use a security origin, so no |
| 82 // conversion is necessary. | 75 // conversion is necessary. |
| 83 void GeolocationDispatcher::requestPermission( | 76 void GeolocationDispatcher::requestPermission( |
| 84 const WebGeolocationPermissionRequest& permissionRequest) { | 77 const WebGeolocationPermissionRequest& permissionRequest) { |
| 85 int bridge_id = pending_permissions_->add(permissionRequest); | 78 if (!permission_service_.get()) { |
| 86 base::string16 origin = permissionRequest.securityOrigin().toString(); | 79 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
| 87 Send(new GeolocationHostMsg_RequestPermission( | 80 &permission_service_); |
| 88 routing_id(), bridge_id, GURL(origin), | 81 } |
| 89 blink::WebUserGestureIndicator::isProcessingUserGesture())); | 82 |
| 83 int permission_request_id = pending_permissions_->add(permissionRequest); | |
| 84 | |
| 85 PermissionName permission = PERMISSION_NAME_GEOLOCATION; | |
| 86 | |
| 87 permission_service_->RequestPermission( | |
| 88 permission, | |
| 89 permissionRequest.securityOrigin().toString().utf8(), | |
| 90 base::Bind(&GeolocationDispatcher::OnPermissionSet, | |
| 91 weak_ptr_factory_.GetWeakPtr(), | |
|
blundell
2014/11/14 12:11:52
This doesn't need to be a weak ptr, as |permission
| |
| 92 permission_request_id)); | |
| 90 } | 93 } |
| 91 | 94 |
| 92 void GeolocationDispatcher::cancelPermissionRequest( | 95 void GeolocationDispatcher::cancelPermissionRequest( |
| 93 const WebGeolocationPermissionRequest& permissionRequest) { | 96 const blink::WebGeolocationPermissionRequest& permissionRequest) { |
| 94 int bridge_id; | 97 int permission_request_id; |
| 95 pending_permissions_->remove(permissionRequest, bridge_id); | 98 pending_permissions_->remove(permissionRequest, permission_request_id); |
| 96 } | 99 } |
| 97 | 100 |
| 98 // Permission for using geolocation has been set. | 101 // Permission for using geolocation has been set. |
| 99 void GeolocationDispatcher::OnPermissionSet(int bridge_id, bool is_allowed) { | 102 void GeolocationDispatcher::OnPermissionSet( |
| 103 int permission_request_id, | |
| 104 PermissionStatus status) { | |
| 100 WebGeolocationPermissionRequest permissionRequest; | 105 WebGeolocationPermissionRequest permissionRequest; |
| 101 if (!pending_permissions_->remove(bridge_id, permissionRequest)) | 106 if (!pending_permissions_->remove(permission_request_id, permissionRequest)) |
| 102 return; | 107 return; |
| 103 permissionRequest.setIsAllowed(is_allowed); | 108 |
| 109 permissionRequest.setIsAllowed(status == PERMISSION_STATUS_GRANTED); | |
| 104 } | 110 } |
| 105 | 111 |
| 106 void GeolocationDispatcher::OnLocationUpdate(MojoGeopositionPtr geoposition) { | 112 void GeolocationDispatcher::OnLocationUpdate(MojoGeopositionPtr geoposition) { |
| 107 DCHECK(geolocation_service_.get()); | 113 DCHECK(geolocation_service_.get()); |
| 108 | 114 |
| 109 if (geoposition->valid) { | 115 if (geoposition->valid) { |
| 110 controller_->positionChanged(WebGeolocationPosition( | 116 controller_->positionChanged(WebGeolocationPosition( |
| 111 geoposition->timestamp, | 117 geoposition->timestamp, |
| 112 geoposition->latitude, | 118 geoposition->latitude, |
| 113 geoposition->longitude, | 119 geoposition->longitude, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 133 default: | 139 default: |
| 134 NOTREACHED() << geoposition->error_code; | 140 NOTREACHED() << geoposition->error_code; |
| 135 return; | 141 return; |
| 136 } | 142 } |
| 137 controller_->errorOccurred(WebGeolocationError( | 143 controller_->errorOccurred(WebGeolocationError( |
| 138 code, blink::WebString::fromUTF8(geoposition->error_message))); | 144 code, blink::WebString::fromUTF8(geoposition->error_message))); |
| 139 } | 145 } |
| 140 } | 146 } |
| 141 | 147 |
| 142 } // namespace content | 148 } // namespace content |
| OLD | NEW |