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

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

Issue 6703003: Move a bunch of html5 renderer code to content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/geolocation_dispatcher.h ('k') | chrome/renderer/indexed_db_dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/geolocation_dispatcher.h"
6
7 #include "chrome/common/render_messages.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationPermiss ionRequest.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationPermiss ionRequestManager.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationClient. h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationPositio n.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationError.h "
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
14
15 using namespace WebKit;
16
17 GeolocationDispatcher::GeolocationDispatcher(RenderView* render_view)
18 : RenderViewObserver(render_view),
19 pending_permissions_(new WebGeolocationPermissionRequestManager()),
20 enable_high_accuracy_(false),
21 updating_(false) {
22 }
23
24 GeolocationDispatcher::~GeolocationDispatcher() {}
25
26 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) {
27 bool handled = true;
28 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message)
29 IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PermissionSet,
30 OnGeolocationPermissionSet)
31 IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PositionUpdated,
32 OnGeolocationPositionUpdated)
33 IPC_MESSAGE_UNHANDLED(handled = false)
34 IPC_END_MESSAGE_MAP()
35 return handled;
36 }
37
38 void GeolocationDispatcher::geolocationDestroyed() {
39 controller_.reset();
40 DCHECK(!updating_);
41 }
42
43 void GeolocationDispatcher::startUpdating() {
44 GURL url;
45 Send(new ViewHostMsg_Geolocation_StartUpdating(
46 routing_id(), url, enable_high_accuracy_));
47 updating_ = true;
48 }
49
50 void GeolocationDispatcher::stopUpdating() {
51 Send(new ViewHostMsg_Geolocation_StopUpdating(routing_id()));
52 updating_ = false;
53 }
54
55 void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) {
56 // GeolocationController calls setEnableHighAccuracy(true) before
57 // startUpdating in response to the first high-accuracy Geolocation
58 // subscription. When the last high-accuracy Geolocation unsubscribes
59 // it calls setEnableHighAccuracy(false) after stopUpdating.
60 bool has_changed = enable_high_accuracy_ != enable_high_accuracy;
61 enable_high_accuracy_ = enable_high_accuracy;
62 // We have a different accuracy requirement. Request browser to update.
63 if (updating_ && has_changed)
64 startUpdating();
65 }
66
67 void GeolocationDispatcher::setController(
68 WebGeolocationController* controller) {
69 controller_.reset(controller);
70 }
71
72 bool GeolocationDispatcher::lastPosition(WebGeolocationPosition&) {
73 // The latest position is stored in the browser, not the renderer, so we
74 // would have to fetch it synchronously to give a good value here. The
75 // WebCore::GeolocationController already caches the last position it
76 // receives, so there is not much benefit to more position caching here.
77 return false;
78 }
79
80 // TODO(jknotten): Change the messages to use a security origin, so no
81 // conversion is necessary.
82 void GeolocationDispatcher::requestPermission(
83 const WebGeolocationPermissionRequest& permissionRequest) {
84 int bridge_id = pending_permissions_->add(permissionRequest);
85 string16 origin = permissionRequest.securityOrigin().toString();
86 Send(new ViewHostMsg_Geolocation_RequestPermission(
87 routing_id(), bridge_id, GURL(origin)));
88 }
89
90 // TODO(jknotten): Change the messages to use a security origin, so no
91 // conversion is necessary.
92 void GeolocationDispatcher::cancelPermissionRequest(
93 const WebGeolocationPermissionRequest& permissionRequest) {
94 int bridge_id;
95 if (!pending_permissions_->remove(permissionRequest, bridge_id))
96 return;
97 string16 origin = permissionRequest.securityOrigin().toString();
98 Send(new ViewHostMsg_Geolocation_CancelPermissionRequest(
99 routing_id(), bridge_id, GURL(origin)));
100 }
101
102 // Permission for using geolocation has been set.
103 void GeolocationDispatcher::OnGeolocationPermissionSet(
104 int bridge_id, bool is_allowed) {
105 WebGeolocationPermissionRequest permissionRequest;
106 if (!pending_permissions_->remove(bridge_id, permissionRequest))
107 return;
108 permissionRequest.setIsAllowed(is_allowed);
109 }
110
111 // We have an updated geolocation position or error code.
112 void GeolocationDispatcher::OnGeolocationPositionUpdated(
113 const Geoposition& geoposition) {
114 // It is possible for the browser process to have queued an update message
115 // before receiving the stop updating message.
116 if (!updating_)
117 return;
118
119 DCHECK(geoposition.IsInitialized());
120 if (geoposition.IsValidFix()) {
121 controller_->positionChanged(
122 WebGeolocationPosition(
123 geoposition.timestamp.ToDoubleT(),
124 geoposition.latitude, geoposition.longitude,
125 geoposition.accuracy,
126 geoposition.is_valid_altitude(), geoposition.altitude,
127 geoposition.is_valid_altitude_accuracy(),
128 geoposition.altitude_accuracy,
129 geoposition.is_valid_heading(), geoposition.heading,
130 geoposition.is_valid_speed(), geoposition.speed));
131 } else {
132 WebGeolocationError::Error code;
133 switch (geoposition.error_code) {
134 case Geoposition::ERROR_CODE_PERMISSION_DENIED:
135 code = WebGeolocationError::ErrorPermissionDenied;
136 break;
137 case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE:
138 code = WebGeolocationError::ErrorPositionUnavailable;
139 break;
140 default:
141 DCHECK(false);
142 NOTREACHED() << geoposition.error_code;
143 return;
144 }
145 controller_->errorOccurred(
146 WebGeolocationError(
147 code, WebKit::WebString::fromUTF8(geoposition.error_message)));
148 }
149 }
OLDNEW
« no previous file with comments | « chrome/renderer/geolocation_dispatcher.h ('k') | chrome/renderer/indexed_db_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698