| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer in the | |
| 12 * documentation and/or other materials provided with the distribution. | |
| 13 * | |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #include "public/web/WebGeolocationPermissionRequestManager.h" | |
| 27 | |
| 28 #include "modules/geolocation/Geolocation.h" | |
| 29 #include "platform/heap/Handle.h" | |
| 30 #include "public/web/WebGeolocationPermissionRequest.h" | |
| 31 #include "wtf/HashMap.h" | |
| 32 | |
| 33 namespace blink { | |
| 34 | |
| 35 typedef HeapHashMap<Member<Geolocation>, int> GeolocationIdMap; | |
| 36 typedef HeapHashMap<int, Member<Geolocation>> IdGeolocationMap; | |
| 37 | |
| 38 class WebGeolocationPermissionRequestManagerPrivate final : public GarbageCollec
ted<WebGeolocationPermissionRequestManagerPrivate> { | |
| 39 public: | |
| 40 DEFINE_INLINE_TRACE() | |
| 41 { | |
| 42 visitor->trace(m_geolocationIdMap); | |
| 43 visitor->trace(m_idGeolocationMap); | |
| 44 } | |
| 45 | |
| 46 GeolocationIdMap m_geolocationIdMap; | |
| 47 IdGeolocationMap m_idGeolocationMap; | |
| 48 }; | |
| 49 | |
| 50 int WebGeolocationPermissionRequestManager::add(const WebGeolocationPermissionRe
quest& permissionRequest) | |
| 51 { | |
| 52 Geolocation* geolocation = permissionRequest.geolocation(); | |
| 53 WebGeolocationPermissionRequestManagerPrivate* manager = ensureManager(); | |
| 54 DCHECK(!manager->m_geolocationIdMap.contains(geolocation)); | |
| 55 static int lastId; | |
| 56 int id = ++lastId; | |
| 57 manager->m_geolocationIdMap.add(geolocation, id); | |
| 58 manager->m_idGeolocationMap.add(id, geolocation); | |
| 59 return id; | |
| 60 } | |
| 61 | |
| 62 bool WebGeolocationPermissionRequestManager::remove(const WebGeolocationPermissi
onRequest& permissionRequest, int& id) | |
| 63 { | |
| 64 Geolocation* geolocation = permissionRequest.geolocation(); | |
| 65 WebGeolocationPermissionRequestManagerPrivate* manager = ensureManager(); | |
| 66 GeolocationIdMap::iterator it = manager->m_geolocationIdMap.find(geolocation
); | |
| 67 if (it == manager->m_geolocationIdMap.end()) | |
| 68 return false; | |
| 69 id = it->value; | |
| 70 manager->m_geolocationIdMap.remove(it); | |
| 71 manager->m_idGeolocationMap.remove(id); | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 bool WebGeolocationPermissionRequestManager::remove(int id, WebGeolocationPermis
sionRequest& permissionRequest) | |
| 76 { | |
| 77 WebGeolocationPermissionRequestManagerPrivate* manager = ensureManager(); | |
| 78 IdGeolocationMap::iterator it = manager->m_idGeolocationMap.find(id); | |
| 79 if (it == manager->m_idGeolocationMap.end()) | |
| 80 return false; | |
| 81 Geolocation* geolocation = it->value; | |
| 82 permissionRequest = WebGeolocationPermissionRequest(geolocation); | |
| 83 manager->m_idGeolocationMap.remove(it); | |
| 84 manager->m_geolocationIdMap.remove(geolocation); | |
| 85 return true; | |
| 86 } | |
| 87 | |
| 88 WebGeolocationPermissionRequestManagerPrivate* WebGeolocationPermissionRequestMa
nager::ensureManager() | |
| 89 { | |
| 90 if (m_private.isNull()) | |
| 91 m_private = new WebGeolocationPermissionRequestManagerPrivate; | |
| 92 | |
| 93 return m_private.get(); | |
| 94 } | |
| 95 | |
| 96 void WebGeolocationPermissionRequestManager::reset() | |
| 97 { | |
| 98 m_private.reset(); | |
| 99 } | |
| 100 | |
| 101 } // namespace blink | |
| OLD | NEW |