1 | /* |
2 | * Copyright (C) 2011 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 "GeolocationPermissionRequestManager.h" |
28 | |
29 | #if ENABLE(GEOLOCATION) |
30 | |
31 | #include "WebCoreArgumentCoders.h" |
32 | #include "WebFrame.h" |
33 | #include "WebPage.h" |
34 | #include "WebPageProxyMessages.h" |
35 | #include <WebCore/Document.h> |
36 | #include <WebCore/Frame.h> |
37 | #include <WebCore/FrameLoader.h> |
38 | #include <WebCore/Geolocation.h> |
39 | #include <WebCore/SecurityOrigin.h> |
40 | #include <WebCore/SecurityOriginData.h> |
41 | |
42 | namespace WebKit { |
43 | using namespace WebCore; |
44 | |
45 | static uint64_t generateGeolocationID() |
46 | { |
47 | static uint64_t uniqueGeolocationID = 1; |
48 | return uniqueGeolocationID++; |
49 | } |
50 | |
51 | GeolocationPermissionRequestManager::GeolocationPermissionRequestManager(WebPage& page) |
52 | : m_page(page) |
53 | { |
54 | } |
55 | |
56 | void GeolocationPermissionRequestManager::startRequestForGeolocation(Geolocation& geolocation) |
57 | { |
58 | Frame* frame = geolocation.frame(); |
59 | |
60 | ASSERT_WITH_MESSAGE(frame, "It is not well understood in which cases the Geolocation is alive after its frame goes away. If you hit this assertion, please add a test covering this case." ); |
61 | if (!frame) { |
62 | geolocation.setIsAllowed(false); |
63 | return; |
64 | } |
65 | |
66 | uint64_t geolocationID = generateGeolocationID(); |
67 | |
68 | m_geolocationToIDMap.set(&geolocation, geolocationID); |
69 | m_idToGeolocationMap.set(geolocationID, &geolocation); |
70 | |
71 | WebFrame* webFrame = WebFrame::fromCoreFrame(*frame); |
72 | ASSERT(webFrame); |
73 | |
74 | SecurityOrigin& origin = frame->document()->securityOrigin(); |
75 | |
76 | m_page.send(Messages::WebPageProxy::RequestGeolocationPermissionForFrame(geolocationID, webFrame->frameID(), origin.data().databaseIdentifier())); |
77 | } |
78 | |
79 | void GeolocationPermissionRequestManager::cancelRequestForGeolocation(Geolocation& geolocation) |
80 | { |
81 | uint64_t geolocationID = m_geolocationToIDMap.take(&geolocation); |
82 | if (!geolocationID) |
83 | return; |
84 | m_idToGeolocationMap.remove(geolocationID); |
85 | } |
86 | |
87 | void GeolocationPermissionRequestManager::didReceiveGeolocationPermissionDecision(uint64_t geolocationID, bool allowed) |
88 | { |
89 | Geolocation* geolocation = m_idToGeolocationMap.take(geolocationID); |
90 | if (!geolocation) |
91 | return; |
92 | m_geolocationToIDMap.remove(geolocation); |
93 | |
94 | geolocation->setIsAllowed(allowed); |
95 | } |
96 | |
97 | } // namespace WebKit |
98 | |
99 | #endif // ENABLE(GEOLOCATION) |
100 | |