| 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/public/common/geoposition.h" | 7 #include "content/public/common/geoposition.h" |
| 8 #include "content/renderer/render_view_impl.h" | 8 #include "content/renderer/render_view_impl.h" |
| 9 #include "third_party/WebKit/public/platform/WebString.h" | 9 #include "third_party/WebKit/public/platform/WebString.h" |
| 10 #include "third_party/WebKit/public/web/WebGeolocationPermissionRequest.h" | 10 #include "third_party/WebKit/public/web/WebGeolocationPermissionRequest.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // would have to fetch it synchronously to give a good value here. The | 65 // would have to fetch it synchronously to give a good value here. The |
| 66 // WebCore::GeolocationController already caches the last position it | 66 // WebCore::GeolocationController already caches the last position it |
| 67 // receives, so there is not much benefit to more position caching here. | 67 // receives, so there is not much benefit to more position caching here. |
| 68 return false; | 68 return false; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // TODO(jknotten): Change the messages to use a security origin, so no | 71 // TODO(jknotten): Change the messages to use a security origin, so no |
| 72 // conversion is necessary. | 72 // conversion is necessary. |
| 73 void GeolocationDispatcher::requestPermission( | 73 void GeolocationDispatcher::requestPermission( |
| 74 const WebGeolocationPermissionRequest& permissionRequest) { | 74 const WebGeolocationPermissionRequest& permissionRequest) { |
| 75 num_pending_permission_requests_++; |
| 75 if (!permission_service_.get()) { | 76 if (!permission_service_.get()) { |
| 76 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 77 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
| 77 mojo::GetProxy(&permission_service_)); | 78 mojo::GetProxy(&permission_service_)); |
| 78 } | 79 } |
| 79 | 80 |
| 80 int permission_request_id = pending_permissions_->add(permissionRequest); | 81 int permission_request_id = pending_permissions_->add(permissionRequest); |
| 81 | 82 |
| 82 permission_service_->RequestPermission( | 83 permission_service_->RequestPermission( |
| 83 blink::mojom::PermissionName::GEOLOCATION, | 84 blink::mojom::PermissionName::GEOLOCATION, |
| 84 permissionRequest.getSecurityOrigin().toString().utf8(), | 85 permissionRequest.getSecurityOrigin().toString().utf8(), |
| 85 base::Bind(&GeolocationDispatcher::OnPermissionSet, | 86 base::Bind(&GeolocationDispatcher::OnPermissionSet, |
| 86 base::Unretained(this), permission_request_id)); | 87 base::Unretained(this), permission_request_id)); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void GeolocationDispatcher::cancelPermissionRequest( | 90 void GeolocationDispatcher::cancelPermissionRequest( |
| 90 const blink::WebGeolocationPermissionRequest& permissionRequest) { | 91 const blink::WebGeolocationPermissionRequest& permissionRequest) { |
| 91 int permission_request_id; | 92 int permission_request_id; |
| 92 pending_permissions_->remove(permissionRequest, permission_request_id); | 93 pending_permissions_->remove(permissionRequest, permission_request_id); |
| 94 if (--num_pending_permission_requests_ == 0) |
| 95 permission_service_.reset(); |
| 93 } | 96 } |
| 94 | 97 |
| 95 // Permission for using geolocation has been set. | 98 // Permission for using geolocation has been set. |
| 96 void GeolocationDispatcher::OnPermissionSet( | 99 void GeolocationDispatcher::OnPermissionSet( |
| 97 int permission_request_id, | 100 int permission_request_id, |
| 98 blink::mojom::PermissionStatus status) { | 101 blink::mojom::PermissionStatus status) { |
| 99 WebGeolocationPermissionRequest permissionRequest; | 102 WebGeolocationPermissionRequest permissionRequest; |
| 100 if (!pending_permissions_->remove(permission_request_id, permissionRequest)) | 103 if (!pending_permissions_->remove(permission_request_id, permissionRequest)) |
| 101 return; | 104 return; |
| 102 | 105 |
| 106 if (--num_pending_permission_requests_ == 0) |
| 107 permission_service_.reset(); |
| 108 |
| 103 permissionRequest.setIsAllowed(status == | 109 permissionRequest.setIsAllowed(status == |
| 104 blink::mojom::PermissionStatus::GRANTED); | 110 blink::mojom::PermissionStatus::GRANTED); |
| 105 } | 111 } |
| 106 | 112 |
| 107 void GeolocationDispatcher::QueryNextPosition() { | 113 void GeolocationDispatcher::QueryNextPosition() { |
| 108 DCHECK(geolocation_service_); | 114 DCHECK(geolocation_service_); |
| 109 geolocation_service_->QueryNextPosition( | 115 geolocation_service_->QueryNextPosition( |
| 110 base::Bind(&GeolocationDispatcher::OnPositionUpdate, | 116 base::Bind(&GeolocationDispatcher::OnPositionUpdate, |
| 111 base::Unretained(this))); | 117 base::Unretained(this))); |
| 112 } | 118 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 142 default: | 148 default: |
| 143 NOTREACHED() << geoposition->error_code; | 149 NOTREACHED() << geoposition->error_code; |
| 144 return; | 150 return; |
| 145 } | 151 } |
| 146 controller_->errorOccurred(WebGeolocationError( | 152 controller_->errorOccurred(WebGeolocationError( |
| 147 code, blink::WebString::fromUTF8(geoposition->error_message))); | 153 code, blink::WebString::fromUTF8(geoposition->error_message))); |
| 148 } | 154 } |
| 149 } | 155 } |
| 150 | 156 |
| 151 } // namespace content | 157 } // namespace content |
| OLD | NEW |