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: third_party/WebKit/WebCore/page/Geolocation.cpp

Issue 46097: WebKit merge 41660:41709 (WebKit side).... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 m_timer.stop(); 50 m_timer.stop();
51 51
52 RefPtr<PositionError> error = PositionError::create(PositionError::TIMEOUT, "Timed out"); 52 RefPtr<PositionError> error = PositionError::create(PositionError::TIMEOUT, "Timed out");
53 m_errorCallback->handleEvent(error.get()); 53 m_errorCallback->handleEvent(error.get());
54 } 54 }
55 55
56 Geolocation::Geolocation(Frame* frame) 56 Geolocation::Geolocation(Frame* frame)
57 : m_frame(frame) 57 : m_frame(frame)
58 , m_service(GeolocationService::create(this)) 58 , m_service(GeolocationService::create(this))
59 , m_allowGeolocation(Unknown) 59 , m_allowGeolocation(Unknown)
60 , m_shouldClearCache(false)
60 { 61 {
62 if (!m_frame)
63 return;
61 ASSERT(m_frame->document()); 64 ASSERT(m_frame->document());
62 m_frame->document()->setUsingGeolocation(true); 65 m_frame->document()->setUsingGeolocation(true);
63 } 66 }
64 67
65 void Geolocation::disconnectFrame() 68 void Geolocation::disconnectFrame()
66 { 69 {
67 m_service->stopUpdating(); 70 m_service->stopUpdating();
68 m_frame = 0; 71 m_frame = 0;
69 } 72 }
70 73
71 void Geolocation::getCurrentPosition(PassRefPtr<PositionCallback> successCallbac k, PassRefPtr<PositionErrorCallback> errorCallback, PositionOptions* options) 74 void Geolocation::getCurrentPosition(PassRefPtr<PositionCallback> successCallbac k, PassRefPtr<PositionErrorCallback> errorCallback, PositionOptions* options)
72 { 75 {
73 RefPtr<GeoNotifier> notifier = GeoNotifier::create(successCallback, errorCal lback, options); 76 RefPtr<GeoNotifier> notifier = GeoNotifier::create(successCallback, errorCal lback, options);
74 77
75 if (!shouldAllowGeolocation()) {
76 if (notifier->m_errorCallback) {
77 RefPtr<PositionError> error = WebCore::PositionError::create(Positio nError::PERMISSION_DENIED, "Disallowed Geolocation");
78 notifier->m_errorCallback->handleEvent(error.get());
79 }
80 return;
81 }
82
83 if (!m_service->startUpdating(options)) { 78 if (!m_service->startUpdating(options)) {
84 if (notifier->m_errorCallback) { 79 if (notifier->m_errorCallback) {
85 RefPtr<PositionError> error = PositionError::create(PositionError::P ERMISSION_DENIED, "Unable to Start"); 80 RefPtr<PositionError> error = PositionError::create(PositionError::P ERMISSION_DENIED, "Unable to Start");
86 notifier->m_errorCallback->handleEvent(error.get()); 81 notifier->m_errorCallback->handleEvent(error.get());
87 } 82 }
88 return; 83 return;
89 } 84 }
90 85
91 m_oneShots.add(notifier); 86 m_oneShots.add(notifier);
92 } 87 }
93 88
94 int Geolocation::watchPosition(PassRefPtr<PositionCallback> successCallback, Pas sRefPtr<PositionErrorCallback> errorCallback, PositionOptions* options) 89 int Geolocation::watchPosition(PassRefPtr<PositionCallback> successCallback, Pas sRefPtr<PositionErrorCallback> errorCallback, PositionOptions* options)
95 { 90 {
96 RefPtr<GeoNotifier> notifier = GeoNotifier::create(successCallback, errorCal lback, options); 91 RefPtr<GeoNotifier> notifier = GeoNotifier::create(successCallback, errorCal lback, options);
97 92
98 if (!shouldAllowGeolocation()) {
99 if (notifier->m_errorCallback) {
100 RefPtr<PositionError> error = WebCore::PositionError::create(Positio nError::PERMISSION_DENIED, "Disallowed Geolocation");
101 notifier->m_errorCallback->handleEvent(error.get());
102 }
103 return 0;
104 }
105
106 if (!m_service->startUpdating(options)) { 93 if (!m_service->startUpdating(options)) {
107 if (notifier->m_errorCallback) { 94 if (notifier->m_errorCallback) {
108 RefPtr<PositionError> error = PositionError::create(PositionError::P ERMISSION_DENIED, "Unable to Start"); 95 RefPtr<PositionError> error = PositionError::create(PositionError::P ERMISSION_DENIED, "Unable to Start");
109 notifier->m_errorCallback->handleEvent(error.get()); 96 notifier->m_errorCallback->handleEvent(error.get());
110 } 97 }
111 return 0; 98 return 0;
112 } 99 }
113 100
114 static int sIdentifier = 0; 101 static int sIdentifier = 0;
115 102
(...skipping 15 matching lines...) Expand all
131 if (hasListeners()) 118 if (hasListeners())
132 m_service->suspend(); 119 m_service->suspend();
133 } 120 }
134 121
135 void Geolocation::resume() 122 void Geolocation::resume()
136 { 123 {
137 if (hasListeners()) 124 if (hasListeners())
138 m_service->resume(); 125 m_service->resume();
139 } 126 }
140 127
128 void Geolocation::setIsAllowed(bool allowed)
129 {
130 m_allowGeolocation = allowed ? Yes : No;
131
132 if (isAllowed())
133 geolocationServicePositionChanged(m_service.get());
134 else {
135 WTF::RefPtr<WebCore::PositionError> error = WebCore::PositionError::crea te(PositionError::PERMISSION_DENIED, "User disallowed GeoLocation");
136 handleError(error.get());
137 }
138 }
139
141 void Geolocation::sendErrorToOneShots(PositionError* error) 140 void Geolocation::sendErrorToOneShots(PositionError* error)
142 { 141 {
143 Vector<RefPtr<GeoNotifier> > copy; 142 Vector<RefPtr<GeoNotifier> > copy;
144 copyToVector(m_oneShots, copy); 143 copyToVector(m_oneShots, copy);
145 144
146 Vector<RefPtr<GeoNotifier> >::const_iterator end = copy.end(); 145 Vector<RefPtr<GeoNotifier> >::const_iterator end = copy.end();
147 for (Vector<RefPtr<GeoNotifier> >::const_iterator it = copy.begin(); it != e nd; ++it) { 146 for (Vector<RefPtr<GeoNotifier> >::const_iterator it = copy.begin(); it != e nd; ++it) {
148 RefPtr<GeoNotifier> notifier = *it; 147 RefPtr<GeoNotifier> notifier = *it;
149 148
150 if (notifier->m_errorCallback) 149 if (notifier->m_errorCallback)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 void Geolocation::handleError(PositionError* error) 208 void Geolocation::handleError(PositionError* error)
210 { 209 {
211 ASSERT(error); 210 ASSERT(error);
212 211
213 sendErrorToOneShots(error); 212 sendErrorToOneShots(error);
214 sendErrorToWatchers(error); 213 sendErrorToWatchers(error);
215 214
216 m_oneShots.clear(); 215 m_oneShots.clear();
217 } 216 }
218 217
218 void Geolocation::requestPermission()
219 {
220 if (m_allowGeolocation > Unknown)
221 return;
222
223 if (!m_frame)
224 return;
225
226 Page* page = m_frame->page();
227 if (!page)
228 return;
229
230 // Ask the chrome: it maintains the geolocation challenge policy itself.
231 page->chrome()->requestGeolocationPermissionForFrame(m_frame, this);
232
233 m_allowGeolocation = InProgress;
234 }
235
219 void Geolocation::geolocationServicePositionChanged(GeolocationService* service) 236 void Geolocation::geolocationServicePositionChanged(GeolocationService* service)
220 { 237 {
221 ASSERT(service->lastPosition()); 238 ASSERT(service->lastPosition());
222 239
240 requestPermission();
241 if (!isAllowed())
242 return;
243
223 sendPositionToOneShots(service->lastPosition()); 244 sendPositionToOneShots(service->lastPosition());
224 sendPositionToWatchers(service->lastPosition()); 245 sendPositionToWatchers(service->lastPosition());
225 246
226 m_oneShots.clear(); 247 m_oneShots.clear();
227 248
228 if (!hasListeners()) 249 if (!hasListeners())
229 m_service->stopUpdating(); 250 m_service->stopUpdating();
230 } 251 }
231 252
232 void Geolocation::geolocationServiceErrorOccurred(GeolocationService* service) 253 void Geolocation::geolocationServiceErrorOccurred(GeolocationService* service)
233 { 254 {
234 ASSERT(service->lastError()); 255 ASSERT(service->lastError());
235 256
236 handleError(service->lastError()); 257 handleError(service->lastError());
237 } 258 }
238 259
239 bool Geolocation::shouldAllowGeolocation()
240 {
241 if (!m_frame)
242 return false;
243
244 Page* page = m_frame->page();
245 if (!page)
246 return false;
247
248 if (m_allowGeolocation == Unknown)
249 m_allowGeolocation = page->chrome()->shouldAllowGeolocationForFrame(m_fr ame) ? Yes : No;
250 return m_allowGeolocation == Yes;
251 }
252
253 } // namespace WebCore 260 } // namespace WebCore
OLDNEW
« no previous file with comments | « third_party/WebKit/WebCore/page/Geolocation.h ('k') | third_party/WebKit/WebCore/page/Geoposition.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698