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

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

Issue 628773003: Partially convert geolocation IPC to Mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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
« no previous file with comments | « content/renderer/geolocation_dispatcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/common/geolocation_messages.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"
11 #include "third_party/WebKit/public/web/WebGeolocationPermissionRequestManager.h " 11 #include "third_party/WebKit/public/web/WebGeolocationPermissionRequestManager.h "
12 #include "third_party/WebKit/public/web/WebGeolocationClient.h" 12 #include "third_party/WebKit/public/web/WebGeolocationClient.h"
13 #include "third_party/WebKit/public/web/WebGeolocationPosition.h" 13 #include "third_party/WebKit/public/web/WebGeolocationPosition.h"
14 #include "third_party/WebKit/public/web/WebGeolocationError.h" 14 #include "third_party/WebKit/public/web/WebGeolocationError.h"
15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
16 16
17 using blink::WebGeolocationController; 17 using blink::WebGeolocationController;
18 using blink::WebGeolocationError; 18 using blink::WebGeolocationError;
19 using blink::WebGeolocationPermissionRequest; 19 using blink::WebGeolocationPermissionRequest;
20 using blink::WebGeolocationPermissionRequestManager; 20 using blink::WebGeolocationPermissionRequestManager;
21 using blink::WebGeolocationPosition; 21 using blink::WebGeolocationPosition;
22 22
23 namespace content { 23 namespace content {
24 24
25 GeolocationDispatcher::GeolocationDispatcher(RenderFrame* render_frame) 25 GeolocationDispatcher::GeolocationDispatcher(RenderFrame* render_frame)
26 : RenderFrameObserver(render_frame), 26 : RenderFrameObserver(render_frame),
27 pending_permissions_(new WebGeolocationPermissionRequestManager()), 27 pending_permissions_(new WebGeolocationPermissionRequestManager()),
28 enable_high_accuracy_(false), 28 enable_high_accuracy_(false) {
29 updating_(false) {
30 } 29 }
31 30
32 GeolocationDispatcher::~GeolocationDispatcher() {} 31 GeolocationDispatcher::~GeolocationDispatcher() {}
33 32
34 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) { 33 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) {
35 bool handled = true; 34 bool handled = true;
36 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message) 35 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message)
37 IPC_MESSAGE_HANDLER(GeolocationMsg_PermissionSet, OnPermissionSet) 36 IPC_MESSAGE_HANDLER(GeolocationMsg_PermissionSet, OnPermissionSet)
38 IPC_MESSAGE_HANDLER(GeolocationMsg_PositionUpdated, OnPositionUpdated)
39 IPC_MESSAGE_UNHANDLED(handled = false) 37 IPC_MESSAGE_UNHANDLED(handled = false)
40 IPC_END_MESSAGE_MAP() 38 IPC_END_MESSAGE_MAP()
41 return handled; 39 return handled;
42 } 40 }
43 41
44 void GeolocationDispatcher::startUpdating() { 42 void GeolocationDispatcher::startUpdating() {
45 GURL url; 43 if (!geolocation_service_.get()) {
46 Send(new GeolocationHostMsg_StartUpdating( 44 render_frame()->GetServiceRegistry()->ConnectToRemoteService(
47 routing_id(), url, enable_high_accuracy_)); 45 &geolocation_service_);
48 updating_ = true; 46 geolocation_service_.set_client(this);
47 }
48 if (enable_high_accuracy_)
49 geolocation_service_->SetHighAccuracy(true);
49 } 50 }
50 51
51 void GeolocationDispatcher::stopUpdating() { 52 void GeolocationDispatcher::stopUpdating() {
52 Send(new GeolocationHostMsg_StopUpdating(routing_id())); 53 geolocation_service_.reset();
53 updating_ = false;
54 } 54 }
55 55
56 void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) { 56 void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) {
57 // GeolocationController calls setEnableHighAccuracy(true) before 57 // GeolocationController calls setEnableHighAccuracy(true) before
58 // startUpdating in response to the first high-accuracy Geolocation 58 // startUpdating in response to the first high-accuracy Geolocation
59 // subscription. When the last high-accuracy Geolocation unsubscribes 59 // subscription. When the last high-accuracy Geolocation unsubscribes
60 // it calls setEnableHighAccuracy(false) after stopUpdating. 60 // it calls setEnableHighAccuracy(false) after stopUpdating.
61 bool has_changed = enable_high_accuracy_ != enable_high_accuracy; 61 bool has_changed = enable_high_accuracy_ != enable_high_accuracy;
62 enable_high_accuracy_ = enable_high_accuracy; 62 enable_high_accuracy_ = enable_high_accuracy;
63 // We have a different accuracy requirement. Request browser to update. 63 // We have a different accuracy requirement. Request browser to update.
64 if (updating_ && has_changed) 64 if (geolocation_service_.get() && has_changed)
65 startUpdating(); 65 geolocation_service_->SetHighAccuracy(enable_high_accuracy_);
66 } 66 }
67 67
68 void GeolocationDispatcher::setController( 68 void GeolocationDispatcher::setController(
69 WebGeolocationController* controller) { 69 WebGeolocationController* controller) {
70 controller_.reset(controller); 70 controller_.reset(controller);
71 } 71 }
72 72
73 bool GeolocationDispatcher::lastPosition(WebGeolocationPosition&) { 73 bool GeolocationDispatcher::lastPosition(WebGeolocationPosition&) {
74 // The latest position is stored in the browser, not the renderer, so we 74 // The latest position is stored in the browser, not the renderer, so we
75 // would have to fetch it synchronously to give a good value here. The 75 // would have to fetch it synchronously to give a good value here. The
(...skipping 20 matching lines...) Expand all
96 } 96 }
97 97
98 // Permission for using geolocation has been set. 98 // Permission for using geolocation has been set.
99 void GeolocationDispatcher::OnPermissionSet(int bridge_id, bool is_allowed) { 99 void GeolocationDispatcher::OnPermissionSet(int bridge_id, bool is_allowed) {
100 WebGeolocationPermissionRequest permissionRequest; 100 WebGeolocationPermissionRequest permissionRequest;
101 if (!pending_permissions_->remove(bridge_id, permissionRequest)) 101 if (!pending_permissions_->remove(bridge_id, permissionRequest))
102 return; 102 return;
103 permissionRequest.setIsAllowed(is_allowed); 103 permissionRequest.setIsAllowed(is_allowed);
104 } 104 }
105 105
106 // We have an updated geolocation position or error code. 106 void GeolocationDispatcher::OnLocationUpdate(MojoGeopositionPtr geoposition) {
107 void GeolocationDispatcher::OnPositionUpdated( 107 DCHECK(geolocation_service_.get());
108 const Geoposition& geoposition) {
109 // It is possible for the browser process to have queued an update message
110 // before receiving the stop updating message.
111 if (!updating_)
112 return;
113 108
114 if (geoposition.Validate()) { 109 if (geoposition->valid) {
115 controller_->positionChanged( 110 controller_->positionChanged(WebGeolocationPosition(
116 WebGeolocationPosition( 111 geoposition->timestamp,
117 geoposition.timestamp.ToDoubleT(), 112 geoposition->latitude,
118 geoposition.latitude, geoposition.longitude, 113 geoposition->longitude,
119 geoposition.accuracy, 114 geoposition->accuracy,
120 // Lowest point on land is at approximately -400 meters. 115 // Lowest point on land is at approximately -400 meters.
121 geoposition.altitude > -10000., 116 geoposition->altitude > -10000.,
122 geoposition.altitude, 117 geoposition->altitude,
123 geoposition.altitude_accuracy >= 0., 118 geoposition->altitude_accuracy >= 0.,
124 geoposition.altitude_accuracy, 119 geoposition->altitude_accuracy,
125 geoposition.heading >= 0. && geoposition.heading <= 360., 120 geoposition->heading >= 0. && geoposition->heading <= 360.,
126 geoposition.heading, 121 geoposition->heading,
127 geoposition.speed >= 0., 122 geoposition->speed >= 0.,
128 geoposition.speed)); 123 geoposition->speed));
129 } else { 124 } else {
130 WebGeolocationError::Error code; 125 WebGeolocationError::Error code;
131 switch (geoposition.error_code) { 126 switch (geoposition->error_code) {
132 case Geoposition::ERROR_CODE_PERMISSION_DENIED: 127 case Geoposition::ERROR_CODE_PERMISSION_DENIED:
133 code = WebGeolocationError::ErrorPermissionDenied; 128 code = WebGeolocationError::ErrorPermissionDenied;
134 break; 129 break;
135 case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE: 130 case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE:
136 code = WebGeolocationError::ErrorPositionUnavailable; 131 code = WebGeolocationError::ErrorPositionUnavailable;
137 break; 132 break;
138 default: 133 default:
139 NOTREACHED() << geoposition.error_code; 134 NOTREACHED() << geoposition->error_code;
140 return; 135 return;
141 } 136 }
142 controller_->errorOccurred( 137 controller_->errorOccurred(WebGeolocationError(
143 WebGeolocationError( 138 code, blink::WebString::fromUTF8(geoposition->error_message)));
144 code, blink::WebString::fromUTF8(geoposition.error_message)));
145 } 139 }
146 } 140 }
147 141
148 } // namespace content 142 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/geolocation_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698