933399974365c40dd192def6cebc3c23ab2b2437
[WebKit-https.git] / WebCore / platform / chromium / GeolocationServiceChromium.cpp
1 /*
2  * Copyright (c) 2010, 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 "config.h"
32 #include "GeolocationServiceChromium.h"
33
34 #include "ChromiumBridge.h"
35
36 namespace WebCore {
37
38 GeolocationServiceChromium::GeolocationServiceChromium(GeolocationServiceClient* c)
39         : GeolocationService(c),
40           m_geolocation(static_cast<Geolocation*>(c)),
41           m_geolocationServiceBridge(ChromiumBridge::createGeolocationServiceBridge(this)),
42           m_lastError(PositionError::create(PositionError::POSITION_UNAVAILABLE, ""))
43 {
44 }
45
46 void GeolocationServiceChromium::setIsAllowed(bool allowed)
47 {
48     m_geolocation->setIsAllowed(allowed);
49 }
50
51 void GeolocationServiceChromium::setLastPosition(PassRefPtr<Geoposition> geoposition)
52 {
53     m_lastPosition = geoposition;
54     positionChanged();
55 }
56
57 void GeolocationServiceChromium::setLastError(int errorCode, const String& message)
58 {
59     m_lastError = PositionError::create(static_cast<PositionError::ErrorCode>(errorCode), message);
60     errorOccurred();
61 }
62
63 Frame* GeolocationServiceChromium::frame()
64 {
65     return m_geolocation->frame();
66 }
67
68 bool GeolocationServiceChromium::startUpdating(PositionOptions* options)
69 {
70     return m_geolocationServiceBridge->startUpdating(options);
71 }
72
73 void GeolocationServiceChromium::stopUpdating()
74 {
75     return m_geolocationServiceBridge->stopUpdating();
76 }
77
78 void GeolocationServiceChromium::suspend()
79 {
80     return m_geolocationServiceBridge->suspend();
81 }
82
83 void GeolocationServiceChromium::resume()
84 {
85     return m_geolocationServiceBridge->resume();
86 }
87
88 Geoposition* GeolocationServiceChromium::lastPosition() const
89 {
90     return m_lastPosition.get();
91 }
92
93 PositionError* GeolocationServiceChromium::lastError() const
94 {
95     return m_lastError.get();
96 }
97
98 static GeolocationService* createGeolocationServiceChromium(GeolocationServiceClient* c)
99 {
100     return new GeolocationServiceChromium(c);
101 }
102
103 // Sets up the factory function for GeolocationService.
104 GeolocationService::FactoryFunction* GeolocationService::s_factoryFunction = &createGeolocationServiceChromium;
105
106 } // namespace WebCore