| 1 | /* |
| 2 | * Copyright (C) 2000 Harri Porten (porten@kde.org) |
| 3 | * Copyright (c) 2000 Daniel Molkentin (molkentin@kde.org) |
| 4 | * Copyright (c) 2000 Stefan Schimanski (schimmi@kde.org) |
| 5 | * Copyright (C) 2003, 2004, 2005, 2006 Apple Inc. |
| 6 | * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | */ |
| 22 | |
| 23 | #include "config.h" |
| 24 | |
| 25 | #if ENABLE(GEOLOCATION) |
| 26 | |
| 27 | #include "NavigatorGeolocation.h" |
| 28 | |
| 29 | #include "DOMWindow.h" |
| 30 | #include "Document.h" |
| 31 | #include "Frame.h" |
| 32 | #include "Geolocation.h" |
| 33 | #include "Navigator.h" |
| 34 | |
| 35 | namespace WebCore { |
| 36 | |
| 37 | NavigatorGeolocation::NavigatorGeolocation(DOMWindow* window) |
| 38 | : DOMWindowProperty(window) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | NavigatorGeolocation::~NavigatorGeolocation() = default; |
| 43 | |
| 44 | const char* NavigatorGeolocation::supplementName() |
| 45 | { |
| 46 | return "NavigatorGeolocation" ; |
| 47 | } |
| 48 | |
| 49 | NavigatorGeolocation* NavigatorGeolocation::from(Navigator* navigator) |
| 50 | { |
| 51 | NavigatorGeolocation* supplement = static_cast<NavigatorGeolocation*>(Supplement<Navigator>::from(navigator, supplementName())); |
| 52 | if (!supplement) { |
| 53 | auto newSupplement = std::make_unique<NavigatorGeolocation>(navigator->window()); |
| 54 | supplement = newSupplement.get(); |
| 55 | provideTo(navigator, supplementName(), WTFMove(newSupplement)); |
| 56 | } |
| 57 | return supplement; |
| 58 | } |
| 59 | |
| 60 | #if PLATFORM(IOS_FAMILY) |
| 61 | void NavigatorGeolocation::resetAllGeolocationPermission() |
| 62 | { |
| 63 | if (m_geolocation) |
| 64 | m_geolocation->resetAllGeolocationPermission(); |
| 65 | } |
| 66 | #endif // PLATFORM(IOS_FAMILY) |
| 67 | |
| 68 | Geolocation* NavigatorGeolocation::geolocation(Navigator& navigator) |
| 69 | { |
| 70 | return NavigatorGeolocation::from(&navigator)->geolocation(); |
| 71 | } |
| 72 | |
| 73 | Geolocation* NavigatorGeolocation::geolocation() const |
| 74 | { |
| 75 | if (!m_geolocation) |
| 76 | m_geolocation = Geolocation::create(window() ? window()->document() : nullptr); |
| 77 | return m_geolocation.get(); |
| 78 | } |
| 79 | |
| 80 | } // namespace WebCore |
| 81 | |
| 82 | #endif // ENABLE(GEOLOCATION) |
| 83 | |