Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: content/renderer/geolocation_dispatcher.cc

Issue 1373883003: Move geolocation and permission mojoms into components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 void GeolocationDispatcher::requestPermission( 74 void GeolocationDispatcher::requestPermission(
75 const WebGeolocationPermissionRequest& permissionRequest) { 75 const WebGeolocationPermissionRequest& permissionRequest) {
76 if (!permission_service_.get()) { 76 if (!permission_service_.get()) {
77 render_frame()->GetServiceRegistry()->ConnectToRemoteService( 77 render_frame()->GetServiceRegistry()->ConnectToRemoteService(
78 mojo::GetProxy(&permission_service_)); 78 mojo::GetProxy(&permission_service_));
79 } 79 }
80 80
81 int permission_request_id = pending_permissions_->add(permissionRequest); 81 int permission_request_id = pending_permissions_->add(permissionRequest);
82 82
83 permission_service_->RequestPermission( 83 permission_service_->RequestPermission(
84 PERMISSION_NAME_GEOLOCATION, 84 permission::NAME_GEOLOCATION,
85 permissionRequest.securityOrigin().toString().utf8(), 85 permissionRequest.securityOrigin().toString().utf8(),
86 blink::WebUserGestureIndicator::isProcessingUserGesture(), 86 blink::WebUserGestureIndicator::isProcessingUserGesture(),
87 base::Bind(&GeolocationDispatcher::OnPermissionSet, 87 base::Bind(&GeolocationDispatcher::OnPermissionSet,
88 base::Unretained(this), 88 base::Unretained(this), permission_request_id));
89 permission_request_id));
90 } 89 }
91 90
92 void GeolocationDispatcher::cancelPermissionRequest( 91 void GeolocationDispatcher::cancelPermissionRequest(
93 const blink::WebGeolocationPermissionRequest& permissionRequest) { 92 const blink::WebGeolocationPermissionRequest& permissionRequest) {
94 int permission_request_id; 93 int permission_request_id;
95 pending_permissions_->remove(permissionRequest, permission_request_id); 94 pending_permissions_->remove(permissionRequest, permission_request_id);
96 } 95 }
97 96
98 // Permission for using geolocation has been set. 97 // Permission for using geolocation has been set.
99 void GeolocationDispatcher::OnPermissionSet( 98 void GeolocationDispatcher::OnPermissionSet(int permission_request_id,
100 int permission_request_id, 99 permission::Status status) {
101 PermissionStatus status) {
102 WebGeolocationPermissionRequest permissionRequest; 100 WebGeolocationPermissionRequest permissionRequest;
103 if (!pending_permissions_->remove(permission_request_id, permissionRequest)) 101 if (!pending_permissions_->remove(permission_request_id, permissionRequest))
104 return; 102 return;
105 103
106 permissionRequest.setIsAllowed(status == PERMISSION_STATUS_GRANTED); 104 permissionRequest.setIsAllowed(status == permission::STATUS_GRANTED);
107 } 105 }
108 106
109 void GeolocationDispatcher::QueryNextPosition() { 107 void GeolocationDispatcher::QueryNextPosition() {
110 DCHECK(geolocation_service_); 108 DCHECK(geolocation_service_);
111 geolocation_service_->QueryNextPosition( 109 geolocation_service_->QueryNextPosition(
112 base::Bind(&GeolocationDispatcher::OnPositionUpdate, 110 base::Bind(&GeolocationDispatcher::OnPositionUpdate,
113 base::Unretained(this))); 111 base::Unretained(this)));
114 } 112 }
115 113
116 void GeolocationDispatcher::OnPositionUpdate(MojoGeopositionPtr geoposition) { 114 void GeolocationDispatcher::OnPositionUpdate(
115 geolocation::GeopositionPtr geoposition) {
117 QueryNextPosition(); 116 QueryNextPosition();
118 117
119 if (geoposition->valid) { 118 if (geoposition->valid) {
120 controller_->positionChanged(WebGeolocationPosition( 119 controller_->positionChanged(WebGeolocationPosition(
121 geoposition->timestamp, 120 geoposition->timestamp,
122 geoposition->latitude, 121 geoposition->latitude,
123 geoposition->longitude, 122 geoposition->longitude,
124 geoposition->accuracy, 123 geoposition->accuracy,
125 // Lowest point on land is at approximately -400 meters. 124 // Lowest point on land is at approximately -400 meters.
126 geoposition->altitude > -10000., 125 geoposition->altitude > -10000.,
127 geoposition->altitude, 126 geoposition->altitude,
128 geoposition->altitude_accuracy >= 0., 127 geoposition->altitude_accuracy >= 0.,
129 geoposition->altitude_accuracy, 128 geoposition->altitude_accuracy,
130 geoposition->heading >= 0. && geoposition->heading <= 360., 129 geoposition->heading >= 0. && geoposition->heading <= 360.,
131 geoposition->heading, 130 geoposition->heading,
132 geoposition->speed >= 0., 131 geoposition->speed >= 0.,
133 geoposition->speed)); 132 geoposition->speed));
134 } else { 133 } else {
135 WebGeolocationError::Error code; 134 WebGeolocationError::Error code;
136 switch (geoposition->error_code) { 135 switch (geoposition->error_code) {
137 case Geoposition::ERROR_CODE_PERMISSION_DENIED: 136 case geolocation::Geoposition::ERROR_CODE_PERMISSION_DENIED:
138 code = WebGeolocationError::ErrorPermissionDenied; 137 code = WebGeolocationError::ErrorPermissionDenied;
139 break; 138 break;
140 case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE: 139 case geolocation::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE:
141 code = WebGeolocationError::ErrorPositionUnavailable; 140 code = WebGeolocationError::ErrorPositionUnavailable;
142 break; 141 break;
143 default: 142 default:
144 NOTREACHED() << geoposition->error_code; 143 NOTREACHED() << geoposition->error_code;
145 return; 144 return;
146 } 145 }
147 controller_->errorOccurred(WebGeolocationError( 146 controller_->errorOccurred(WebGeolocationError(
148 code, blink::WebString::fromUTF8(geoposition->error_message))); 147 code, blink::WebString::fromUTF8(geoposition->error_message)));
149 } 148 }
150 } 149 }
151 150
152 } // namespace content 151 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/geolocation_dispatcher.h ('k') | content/renderer/media/media_permission_dispatcher_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698