OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "modules/geolocation/GeolocationController.h" | 37 #include "modules/geolocation/GeolocationController.h" |
38 #include "modules/geolocation/GeolocationError.h" | 38 #include "modules/geolocation/GeolocationError.h" |
39 #include "modules/geolocation/GeolocationPosition.h" | 39 #include "modules/geolocation/GeolocationPosition.h" |
40 #include "modules/geolocation/testing/GeolocationClientMock.h" | 40 #include "modules/geolocation/testing/GeolocationClientMock.h" |
41 #include "wtf/CurrentTime.h" | 41 #include "wtf/CurrentTime.h" |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 void InternalsGeolocation::setGeolocationClientMock(Internals&, Document* docume
nt) | 45 void InternalsGeolocation::setGeolocationClientMock(Internals&, Document* docume
nt) |
46 { | 46 { |
47 ASSERT(document && document->frame()); | 47 ASSERT(document); |
| 48 if (!document->frame()) |
| 49 return; |
| 50 |
48 GeolocationClientMock* client = new GeolocationClientMock(); | 51 GeolocationClientMock* client = new GeolocationClientMock(); |
49 | |
50 for (Frame* childFrame = document->page()->mainFrame(); childFrame; childFra
me = childFrame->tree().traverseNext()) { | 52 for (Frame* childFrame = document->page()->mainFrame(); childFrame; childFra
me = childFrame->tree().traverseNext()) { |
51 if (childFrame->isLocalFrame()) | 53 if (childFrame->isLocalFrame()) |
52 GeolocationController::from(toLocalFrame(childFrame))->setClientForT
est(client); | 54 GeolocationController::from(toLocalFrame(childFrame))->setClientForT
est(client); |
53 } | 55 } |
54 } | 56 } |
55 | 57 |
56 void InternalsGeolocation::setGeolocationPosition(Internals&, Document* document
, double latitude, double longitude, double accuracy) | 58 void InternalsGeolocation::setGeolocationPosition(Internals&, Document* document
, double latitude, double longitude, double accuracy) |
57 { | 59 { |
58 ASSERT(document && document->frame()); | 60 ASSERT(document); |
| 61 if (!document->frame()) |
| 62 return; |
| 63 |
59 GeolocationClientMock* client = geolocationClient(document); | 64 GeolocationClientMock* client = geolocationClient(document); |
60 if (!client) | 65 if (!client) |
61 return; | 66 return; |
62 client->setPosition(GeolocationPosition::create(currentTime(), latitude, lon
gitude, accuracy)); | 67 client->setPosition(GeolocationPosition::create(currentTime(), latitude, lon
gitude, accuracy)); |
63 } | 68 } |
64 | 69 |
65 void InternalsGeolocation::setGeolocationPositionUnavailableError(Internals&, Do
cument* document, const String& message) | 70 void InternalsGeolocation::setGeolocationPositionUnavailableError(Internals&, Do
cument* document, const String& message) |
66 { | 71 { |
67 ASSERT(document && document->frame()); | 72 ASSERT(document); |
| 73 if (!document->frame()) |
| 74 return; |
| 75 |
68 GeolocationClientMock* client = geolocationClient(document); | 76 GeolocationClientMock* client = geolocationClient(document); |
69 if (!client) | 77 if (!client) |
70 return; | 78 return; |
71 client->setPositionUnavailableError(message); | 79 client->setPositionUnavailableError(message); |
72 } | 80 } |
73 | 81 |
74 void InternalsGeolocation::setGeolocationPermission(Internals&, Document* docume
nt, bool allowed) | 82 void InternalsGeolocation::setGeolocationPermission(Internals&, Document* docume
nt, bool allowed) |
75 { | 83 { |
76 ASSERT(document && document->frame()); | 84 ASSERT(document); |
| 85 if (!document->frame()) |
| 86 return; |
| 87 |
77 GeolocationClientMock* client = geolocationClient(document); | 88 GeolocationClientMock* client = geolocationClient(document); |
78 if (!client) | 89 if (!client) |
79 return; | 90 return; |
80 client->setPermission(allowed); | 91 client->setPermission(allowed); |
81 } | 92 } |
82 | 93 |
83 int InternalsGeolocation::numberOfPendingGeolocationPermissionRequests(Internals
&, Document* document) | 94 int InternalsGeolocation::numberOfPendingGeolocationPermissionRequests(Internals
&, Document* document) |
84 { | 95 { |
85 ASSERT(document && document->frame()); | 96 ASSERT(document); |
| 97 if (!document->frame()) |
| 98 return -1; |
| 99 |
86 GeolocationClientMock* client = geolocationClient(document); | 100 GeolocationClientMock* client = geolocationClient(document); |
87 if (!client) | 101 if (!client) |
88 return -1; | 102 return -1; |
89 return client->numberOfPendingPermissionRequests(); | 103 return client->numberOfPendingPermissionRequests(); |
90 } | 104 } |
91 | 105 |
92 GeolocationClientMock* InternalsGeolocation::geolocationClient(Document* documen
t) | 106 GeolocationClientMock* InternalsGeolocation::geolocationClient(Document* documen
t) |
93 { | 107 { |
| 108 ASSERT(document); |
| 109 if (!document->frame()) |
| 110 return nullptr; |
| 111 |
94 GeolocationController* controller = GeolocationController::from(document->fr
ame()); | 112 GeolocationController* controller = GeolocationController::from(document->fr
ame()); |
95 if (!controller->hasClientForTest()) | 113 if (!controller->hasClientForTest()) |
96 return 0; | 114 return nullptr; |
97 return static_cast<GeolocationClientMock*>(controller->client()); | 115 return static_cast<GeolocationClientMock*>(controller->client()); |
98 } | 116 } |
99 | 117 |
100 } // namespace blink | 118 } // namespace blink |
OLD | NEW |