1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/geolocation/geolocation_dispatcher_host.h"
#include "chrome/common/geoposition.h"
#include "chrome/browser/geolocation/geolocation_permission_context.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_view_host_notification_task.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
#include "chrome/common/render_messages.h"
GeolocationDispatcherHost::GeolocationDispatcherHost(
int resource_message_filter_process_id,
GeolocationPermissionContext* geolocation_permission_context)
: resource_message_filter_process_id_(resource_message_filter_process_id),
geolocation_permission_context_(geolocation_permission_context) {
// This is initialized by ResourceMessageFilter. Do not add any non-trivial
// initialization here, defer to OnRegisterBridge which is triggered whenever
// a javascript geolocation object is actually initialized.
}
GeolocationDispatcherHost::~GeolocationDispatcherHost() {
if (location_arbitrator_)
location_arbitrator_->RemoveObserver(this);
}
bool GeolocationDispatcherHost::OnMessageReceived(
const IPC::Message& msg, bool* msg_was_ok) {
*msg_was_ok = true;
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(GeolocationDispatcherHost, msg, *msg_was_ok)
IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RegisterDispatcher,
OnRegisterDispatcher)
IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_UnregisterDispatcher,
OnUnregisterDispatcher)
IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_RequestPermission,
OnRequestPermission)
IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StartUpdating,
OnStartUpdating)
IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_StopUpdating,
OnStopUpdating)
IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Suspend,
OnSuspend)
IPC_MESSAGE_HANDLER(ViewHostMsg_Geolocation_Resume,
OnResume)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void GeolocationDispatcherHost::OnLocationUpdate(
const Geoposition& geoposition) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
for (std::set<GeolocationServiceRenderId>::iterator geo =
geolocation_renderers_.begin();
geo != geolocation_renderers_.end();
++geo) {
IPC::Message* message;
if (geoposition.IsValidFix()) {
message = new ViewMsg_Geolocation_PositionUpdated(
geo->render_view_id, geoposition);
} else {
DCHECK(geoposition.IsInitialized());
message = new ViewMsg_Geolocation_Error(
geo->render_view_id, geoposition.error_code,
WideToUTF8(geoposition.error_message));
}
CallRenderViewHost(
geo->process_id, geo->render_view_id,
&RenderViewHost::Send, message);
}
}
void GeolocationDispatcherHost::OnRegisterDispatcher(int render_view_id) {
// TODO(bulach): is this the right way to get the RendererViewHost process id
// to be used by RenderViewHost::FromID?
RegisterDispatcher(
resource_message_filter_process_id_, render_view_id);
}
void GeolocationDispatcherHost::OnUnregisterDispatcher(int render_view_id) {
UnregisterDispatcher(
resource_message_filter_process_id_, render_view_id);
}
void GeolocationDispatcherHost::OnRequestPermission(
int render_view_id, int bridge_id, const std::string& host) {
LOG(INFO) << "permission request";
geolocation_permission_context_->RequestGeolocationPermission(
resource_message_filter_process_id_, render_view_id, bridge_id,
host);
}
void GeolocationDispatcherHost::OnStartUpdating(
int render_view_id, int bridge_id, bool high_accuracy) {
LOG(INFO) << "start updating" << render_view_id;
if (!location_arbitrator_)
location_arbitrator_ = GeolocationArbitrator::GetInstance();
location_arbitrator_->AddObserver(
this, GeolocationArbitrator::UpdateOptions(high_accuracy));
}
void GeolocationDispatcherHost::OnStopUpdating(
int render_view_id, int bridge_id) {
LOG(INFO) << "stop updating" << render_view_id;
if (location_arbitrator_)
location_arbitrator_->RemoveObserver(this);
location_arbitrator_ = NULL;
}
void GeolocationDispatcherHost::OnSuspend(
int render_view_id, int bridge_id) {
LOG(INFO) << "suspend" << render_view_id;
// TODO(bulach): connect this with GeolocationServiceProvider.
}
void GeolocationDispatcherHost::OnResume(
int render_view_id, int bridge_id) {
LOG(INFO) << "resume" << render_view_id;
// TODO(bulach): connect this with GeolocationServiceProvider.
}
void GeolocationDispatcherHost::RegisterDispatcher(
int process_id, int render_view_id) {
if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
ChromeThread::PostTask(
ChromeThread::IO, FROM_HERE,
NewRunnableMethod(
this, &GeolocationDispatcherHost::RegisterDispatcher,
process_id, render_view_id));
return;
}
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
GeolocationServiceRenderId geolocation_render_id(
process_id, render_view_id);
std::set<GeolocationServiceRenderId>::const_iterator existing =
geolocation_renderers_.find(geolocation_render_id);
DCHECK(existing == geolocation_renderers_.end());
geolocation_renderers_.insert(geolocation_render_id);
}
void GeolocationDispatcherHost::UnregisterDispatcher(
int process_id, int render_view_id) {
if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
ChromeThread::PostTask(
ChromeThread::IO, FROM_HERE,
NewRunnableMethod(
this, &GeolocationDispatcherHost::UnregisterDispatcher,
process_id, render_view_id));
return;
}
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
GeolocationServiceRenderId geolocation_render_id(
process_id, render_view_id);
std::set<GeolocationServiceRenderId>::iterator existing =
geolocation_renderers_.find(geolocation_render_id);
DCHECK(existing != geolocation_renderers_.end());
geolocation_renderers_.erase(existing);
}
|