OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2014 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 are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "InternalsGeolocation.h" | |
32 | |
33 #include "core/dom/Document.h" | |
34 #include "core/page/Page.h" | |
35 #include "core/testing/Internals.h" | |
36 #include "modules/geolocation/GeolocationController.h" | |
37 #include "modules/geolocation/GeolocationError.h" | |
38 #include "modules/geolocation/GeolocationPosition.h" | |
39 #include "modules/geolocation/testing/GeolocationClientMock.h" | |
40 #include "wtf/CurrentTime.h" | |
41 | |
42 namespace blink { | |
43 | |
44 void InternalsGeolocation::setGeolocationClientMock(Internals&, Document* docume
nt) | |
45 { | |
46 ASSERT(document); | |
47 if (!document->frame()) | |
48 return; | |
49 | |
50 GeolocationClientMock* client = new GeolocationClientMock(); | |
51 for (Frame* childFrame = document->page()->mainFrame(); childFrame; childFra
me = childFrame->tree().traverseNext()) { | |
52 if (childFrame->isLocalFrame()) | |
53 GeolocationController::from(toLocalFrame(childFrame))->setClientForT
est(client); | |
54 } | |
55 } | |
56 | |
57 void InternalsGeolocation::setGeolocationPosition(Internals&, Document* document
, double latitude, double longitude, double accuracy) | |
58 { | |
59 ASSERT(document); | |
60 if (!document->frame()) | |
61 return; | |
62 | |
63 GeolocationClientMock* client = geolocationClient(document); | |
64 if (!client) | |
65 return; | |
66 client->setPosition(GeolocationPosition::create(currentTime(), latitude, lon
gitude, accuracy)); | |
67 } | |
68 | |
69 void InternalsGeolocation::setGeolocationPositionUnavailableError(Internals&, Do
cument* document, const String& message) | |
70 { | |
71 ASSERT(document); | |
72 if (!document->frame()) | |
73 return; | |
74 | |
75 GeolocationClientMock* client = geolocationClient(document); | |
76 if (!client) | |
77 return; | |
78 client->setPositionUnavailableError(message); | |
79 } | |
80 | |
81 void InternalsGeolocation::setGeolocationPermission(Internals&, Document* docume
nt, bool allowed) | |
82 { | |
83 ASSERT(document); | |
84 if (!document->frame()) | |
85 return; | |
86 | |
87 GeolocationClientMock* client = geolocationClient(document); | |
88 if (!client) | |
89 return; | |
90 client->setPermission(allowed); | |
91 } | |
92 | |
93 int InternalsGeolocation::numberOfPendingGeolocationPermissionRequests(Internals
&, Document* document) | |
94 { | |
95 ASSERT(document); | |
96 if (!document->frame()) | |
97 return -1; | |
98 | |
99 GeolocationClientMock* client = geolocationClient(document); | |
100 if (!client) | |
101 return -1; | |
102 return client->numberOfPendingPermissionRequests(); | |
103 } | |
104 | |
105 GeolocationClientMock* InternalsGeolocation::geolocationClient(Document* documen
t) | |
106 { | |
107 ASSERT(document); | |
108 if (!document->frame()) | |
109 return nullptr; | |
110 | |
111 GeolocationController* controller = GeolocationController::from(document->fr
ame()); | |
112 if (!controller->hasClientForTest()) | |
113 return nullptr; | |
114 return static_cast<GeolocationClientMock*>(controller->client()); | |
115 } | |
116 | |
117 } // namespace blink | |
OLD | NEW |