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

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

Issue 6151011: Introduce RenderView::Observer interface so that RenderView doesn't have to k... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 "chrome/renderer/geolocation_dispatcher.h" 5 #include "chrome/renderer/geolocation_dispatcher.h"
6 6
7 #include "chrome/renderer/render_view.h"
8 #include "ipc/ipc_message.h"
9 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPermissionRequ est.h" 7 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPermissionRequ est.h"
10 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPermissionRequ estManager.h" 8 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPermissionRequ estManager.h"
11 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationClient.h" 9 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationClient.h"
12 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPosition.h" 10 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPosition.h"
13 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationError.h" 11 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationError.h"
14 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" 12 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
15 13
16 using namespace WebKit; 14 using namespace WebKit;
17 15
18 GeolocationDispatcher::GeolocationDispatcher(RenderView* render_view) 16 GeolocationDispatcher::GeolocationDispatcher()
19 : render_view_(render_view), 17 : pending_permissions_(new WebGeolocationPermissionRequestManager()),
20 pending_permissions_(new WebGeolocationPermissionRequestManager()),
21 enable_high_accuracy_(false), 18 enable_high_accuracy_(false),
22 updating_(false) { 19 updating_(false) {
23 } 20 }
24 21
25 GeolocationDispatcher::~GeolocationDispatcher() {} 22 GeolocationDispatcher::~GeolocationDispatcher() {}
26 23
27 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) { 24 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) {
28 bool handled = true; 25 bool handled = true;
29 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message) 26 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message)
30 IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PermissionSet, 27 IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PermissionSet,
31 OnGeolocationPermissionSet) 28 OnGeolocationPermissionSet)
32 IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PositionUpdated, 29 IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PositionUpdated,
33 OnGeolocationPositionUpdated) 30 OnGeolocationPositionUpdated)
34 IPC_MESSAGE_UNHANDLED(handled = false) 31 IPC_MESSAGE_UNHANDLED(handled = false)
35 IPC_END_MESSAGE_MAP() 32 IPC_END_MESSAGE_MAP()
36 return handled; 33 return handled;
37 } 34 }
38 35
39 void GeolocationDispatcher::geolocationDestroyed() { 36 void GeolocationDispatcher::geolocationDestroyed() {
40 controller_.reset(); 37 controller_.reset();
41 DCHECK(!updating_); 38 DCHECK(!updating_);
42 } 39 }
43 40
44 void GeolocationDispatcher::startUpdating() { 41 void GeolocationDispatcher::startUpdating() {
45 GURL url; 42 GURL url;
46 render_view_->Send(new ViewHostMsg_Geolocation_StartUpdating( 43 Send(new ViewHostMsg_Geolocation_StartUpdating(
47 render_view_->routing_id(), url, enable_high_accuracy_)); 44 routing_id(), url, enable_high_accuracy_));
48 updating_ = true; 45 updating_ = true;
49 } 46 }
50 47
51 void GeolocationDispatcher::stopUpdating() { 48 void GeolocationDispatcher::stopUpdating() {
52 render_view_->Send(new ViewHostMsg_Geolocation_StopUpdating( 49 Send(new ViewHostMsg_Geolocation_StopUpdating(routing_id()));
53 render_view_->routing_id()));
54 updating_ = false; 50 updating_ = false;
55 } 51 }
56 52
57 void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) { 53 void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) {
58 // GeolocationController calls setEnableHighAccuracy(true) before 54 // GeolocationController calls setEnableHighAccuracy(true) before
59 // startUpdating in response to the first high-accuracy Geolocation 55 // startUpdating in response to the first high-accuracy Geolocation
60 // subscription. When the last high-accuracy Geolocation unsubscribes 56 // subscription. When the last high-accuracy Geolocation unsubscribes
61 // it calls setEnableHighAccuracy(false) after stopUpdating. 57 // it calls setEnableHighAccuracy(false) after stopUpdating.
62 bool has_changed = enable_high_accuracy_ != enable_high_accuracy; 58 bool has_changed = enable_high_accuracy_ != enable_high_accuracy;
63 enable_high_accuracy_ = enable_high_accuracy; 59 enable_high_accuracy_ = enable_high_accuracy;
(...skipping 14 matching lines...) Expand all
78 // receives, so there is not much benefit to more position caching here. 74 // receives, so there is not much benefit to more position caching here.
79 return false; 75 return false;
80 } 76 }
81 77
82 // TODO(jknotten): Change the messages to use a security origin, so no 78 // TODO(jknotten): Change the messages to use a security origin, so no
83 // conversion is necessary. 79 // conversion is necessary.
84 void GeolocationDispatcher::requestPermission( 80 void GeolocationDispatcher::requestPermission(
85 const WebGeolocationPermissionRequest& permissionRequest) { 81 const WebGeolocationPermissionRequest& permissionRequest) {
86 int bridge_id = pending_permissions_->add(permissionRequest); 82 int bridge_id = pending_permissions_->add(permissionRequest);
87 string16 origin = permissionRequest.securityOrigin().toString(); 83 string16 origin = permissionRequest.securityOrigin().toString();
88 render_view_->Send(new ViewHostMsg_Geolocation_RequestPermission( 84 Send(new ViewHostMsg_Geolocation_RequestPermission(
89 render_view_->routing_id(), bridge_id, GURL(origin))); 85 routing_id(), bridge_id, GURL(origin)));
90 } 86 }
91 87
92 // TODO(jknotten): Change the messages to use a security origin, so no 88 // TODO(jknotten): Change the messages to use a security origin, so no
93 // conversion is necessary. 89 // conversion is necessary.
94 void GeolocationDispatcher::cancelPermissionRequest( 90 void GeolocationDispatcher::cancelPermissionRequest(
95 const WebGeolocationPermissionRequest& permissionRequest) { 91 const WebGeolocationPermissionRequest& permissionRequest) {
96 int bridge_id; 92 int bridge_id;
97 if (!pending_permissions_->remove(permissionRequest, bridge_id)) 93 if (!pending_permissions_->remove(permissionRequest, bridge_id))
98 return; 94 return;
99 string16 origin = permissionRequest.securityOrigin().toString(); 95 string16 origin = permissionRequest.securityOrigin().toString();
100 render_view_->Send(new ViewHostMsg_Geolocation_CancelPermissionRequest( 96 Send(new ViewHostMsg_Geolocation_CancelPermissionRequest(
101 render_view_->routing_id(), bridge_id, GURL(origin))); 97 routing_id(), bridge_id, GURL(origin)));
102 } 98 }
103 99
104 // Permission for using geolocation has been set. 100 // Permission for using geolocation has been set.
105 void GeolocationDispatcher::OnGeolocationPermissionSet( 101 void GeolocationDispatcher::OnGeolocationPermissionSet(
106 int bridge_id, bool is_allowed) { 102 int bridge_id, bool is_allowed) {
107 WebGeolocationPermissionRequest permissionRequest; 103 WebGeolocationPermissionRequest permissionRequest;
108 if (!pending_permissions_->remove(bridge_id, permissionRequest)) 104 if (!pending_permissions_->remove(bridge_id, permissionRequest))
109 return; 105 return;
110 permissionRequest.setIsAllowed(is_allowed); 106 permissionRequest.setIsAllowed(is_allowed);
111 } 107 }
(...skipping 26 matching lines...) Expand all
138 default: 134 default:
139 DCHECK(false); 135 DCHECK(false);
140 NOTREACHED() << geoposition.error_code; 136 NOTREACHED() << geoposition.error_code;
141 return; 137 return;
142 } 138 }
143 controller_->errorOccurred( 139 controller_->errorOccurred(
144 WebGeolocationError( 140 WebGeolocationError(
145 code, WebKit::WebString::fromUTF8(geoposition.error_message))); 141 code, WebKit::WebString::fromUTF8(geoposition.error_message)));
146 } 142 }
147 } 143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698