1 | /* |
2 | * Copyright (C) 2011, 2012, 2013 Apple 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 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "WebGeolocationManager.h" |
28 | |
29 | #include "WebGeolocationManagerMessages.h" |
30 | #include "WebGeolocationManagerProxyMessages.h" |
31 | #include "WebPage.h" |
32 | #include "WebProcess.h" |
33 | #include <WebCore/Geolocation.h> |
34 | #include <WebCore/GeolocationController.h> |
35 | #include <WebCore/GeolocationError.h> |
36 | #include <WebCore/GeolocationPosition.h> |
37 | #include <WebCore/Page.h> |
38 | |
39 | namespace WebKit { |
40 | using namespace WebCore; |
41 | |
42 | const char* WebGeolocationManager::supplementName() |
43 | { |
44 | return "WebGeolocationManager" ; |
45 | } |
46 | |
47 | WebGeolocationManager::WebGeolocationManager(WebProcess& process) |
48 | : m_process(process) |
49 | { |
50 | m_process.addMessageReceiver(Messages::WebGeolocationManager::messageReceiverName(), *this); |
51 | } |
52 | |
53 | void WebGeolocationManager::registerWebPage(WebPage& page) |
54 | { |
55 | bool wasUpdating = isUpdating(); |
56 | |
57 | m_pageSet.add(&page); |
58 | |
59 | if (!wasUpdating) |
60 | m_process.parentProcessConnection()->send(Messages::WebGeolocationManagerProxy::StartUpdating(), 0); |
61 | } |
62 | |
63 | void WebGeolocationManager::unregisterWebPage(WebPage& page) |
64 | { |
65 | bool highAccuracyWasEnabled = isHighAccuracyEnabled(); |
66 | |
67 | m_pageSet.remove(&page); |
68 | m_highAccuracyPageSet.remove(&page); |
69 | |
70 | if (!isUpdating()) |
71 | m_process.parentProcessConnection()->send(Messages::WebGeolocationManagerProxy::StopUpdating(), 0); |
72 | else { |
73 | bool highAccuracyShouldBeEnabled = isHighAccuracyEnabled(); |
74 | if (highAccuracyWasEnabled != highAccuracyShouldBeEnabled) |
75 | m_process.parentProcessConnection()->send(Messages::WebGeolocationManagerProxy::SetEnableHighAccuracy(highAccuracyShouldBeEnabled), 0); |
76 | } |
77 | } |
78 | |
79 | void WebGeolocationManager::setEnableHighAccuracyForPage(WebPage& page, bool enabled) |
80 | { |
81 | bool highAccuracyWasEnabled = isHighAccuracyEnabled(); |
82 | |
83 | if (enabled) |
84 | m_highAccuracyPageSet.add(&page); |
85 | else |
86 | m_highAccuracyPageSet.remove(&page); |
87 | |
88 | bool highAccuracyShouldBeEnabled = isHighAccuracyEnabled(); |
89 | if (highAccuracyWasEnabled != highAccuracyShouldBeEnabled) |
90 | m_process.parentProcessConnection()->send(Messages::WebGeolocationManagerProxy::SetEnableHighAccuracy(highAccuracyShouldBeEnabled), 0); |
91 | } |
92 | |
93 | void WebGeolocationManager::didChangePosition(const GeolocationPosition& position) |
94 | { |
95 | #if ENABLE(GEOLOCATION) |
96 | for (auto& page : copyToVector(m_pageSet)) { |
97 | if (page->corePage()) |
98 | GeolocationController::from(page->corePage())->positionChanged(position); |
99 | } |
100 | #else |
101 | UNUSED_PARAM(position); |
102 | #endif // ENABLE(GEOLOCATION) |
103 | } |
104 | |
105 | void WebGeolocationManager::didFailToDeterminePosition(const String& errorMessage) |
106 | { |
107 | #if ENABLE(GEOLOCATION) |
108 | // FIXME: Add localized error string. |
109 | auto error = GeolocationError::create(GeolocationError::PositionUnavailable, errorMessage); |
110 | |
111 | for (auto& page : copyToVector(m_pageSet)) { |
112 | if (page->corePage()) |
113 | GeolocationController::from(page->corePage())->errorOccurred(error.get()); |
114 | } |
115 | #else |
116 | UNUSED_PARAM(errorMessage); |
117 | #endif // ENABLE(GEOLOCATION) |
118 | } |
119 | |
120 | #if PLATFORM(IOS_FAMILY) |
121 | void WebGeolocationManager::resetPermissions() |
122 | { |
123 | m_process.resetAllGeolocationPermissions(); |
124 | } |
125 | #endif // PLATFORM(IOS_FAMILY) |
126 | |
127 | } // namespace WebKit |
128 | |