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

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

Issue 722153003: Implement basic mojo Permission service and use it for Geolocation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 6 years, 1 month 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/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
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 PermissionPtr permission = Permission::New();
86 permission->name = PERMISSION_NAME_GEOLOCATION;
87
88 permission_service_->RequestPermission(
89 permission.Clone(),
qsr 2014/11/14 09:20:26 You should pass the permission, instead of cloning
mlamouri (slow - plz ping) 2014/11/14 11:37:11 For some reasons, I had to Clone(), it wouldn't co
qsr 2014/11/14 11:49:27 When I say pass, I mean calling the Pass() method
90 permissionRequest.securityOrigin().toString().utf8(),
91 base::Bind(&GeolocationDispatcher::OnPermissionSet,
92 weak_ptr_factory_.GetWeakPtr(),
93 permission_request_id));
90 } 94 }
91 95
92 void GeolocationDispatcher::cancelPermissionRequest( 96 void GeolocationDispatcher::cancelPermissionRequest(
93 const WebGeolocationPermissionRequest& permissionRequest) { 97 const blink::WebGeolocationPermissionRequest& permissionRequest) {
94 int bridge_id; 98 int permission_request_id;
95 pending_permissions_->remove(permissionRequest, bridge_id); 99 pending_permissions_->remove(permissionRequest, permission_request_id);
96 } 100 }
97 101
98 // Permission for using geolocation has been set. 102 // Permission for using geolocation has been set.
99 void GeolocationDispatcher::OnPermissionSet(int bridge_id, bool is_allowed) { 103 void GeolocationDispatcher::OnPermissionSet(
104 int permission_request_id,
105 PermissionStatus status) {
100 WebGeolocationPermissionRequest permissionRequest; 106 WebGeolocationPermissionRequest permissionRequest;
101 if (!pending_permissions_->remove(bridge_id, permissionRequest)) 107 if (!pending_permissions_->remove(permission_request_id, permissionRequest))
102 return; 108 return;
103 permissionRequest.setIsAllowed(is_allowed); 109
110 permissionRequest.setIsAllowed(status == PERMISSION_STATUS_GRANTED);
104 } 111 }
105 112
106 void GeolocationDispatcher::OnLocationUpdate(MojoGeopositionPtr geoposition) { 113 void GeolocationDispatcher::OnLocationUpdate(MojoGeopositionPtr geoposition) {
107 DCHECK(geolocation_service_.get()); 114 DCHECK(geolocation_service_.get());
108 115
109 if (geoposition->valid) { 116 if (geoposition->valid) {
110 controller_->positionChanged(WebGeolocationPosition( 117 controller_->positionChanged(WebGeolocationPosition(
111 geoposition->timestamp, 118 geoposition->timestamp,
112 geoposition->latitude, 119 geoposition->latitude,
113 geoposition->longitude, 120 geoposition->longitude,
(...skipping 19 matching lines...) Expand all
133 default: 140 default:
134 NOTREACHED() << geoposition->error_code; 141 NOTREACHED() << geoposition->error_code;
135 return; 142 return;
136 } 143 }
137 controller_->errorOccurred(WebGeolocationError( 144 controller_->errorOccurred(WebGeolocationError(
138 code, blink::WebString::fromUTF8(geoposition->error_message))); 145 code, blink::WebString::fromUTF8(geoposition->error_message)));
139 } 146 }
140 } 147 }
141 148
142 } // namespace content 149 } // namespace content
OLDNEW
« content/common/permission_service.mojom ('K') | « content/renderer/geolocation_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698