109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)/*
209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Copyright (C) 2014 Google Inc. All rights reserved.
309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *
409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * modification, are permitted provided that the following conditions are
609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * met:
709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *
809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *     * Redistributions of source code must retain the above copyright
909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * notice, this list of conditions and the following disclaimer.
1009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *     * Redistributions in binary form must reproduce the above
1109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
1209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * in the documentation and/or other materials provided with the
1309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * distribution.
1409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
1509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * contributors may be used to endorse or promote products derived from
1609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * this software without specific prior written permission.
1709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *
1809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) */
3009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
3109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "config.h"
3209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/geolocation/GeolocationInspectorAgent.h"
3309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/geolocation/GeolocationController.h"
3509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
36c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
3709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
38c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)PassOwnPtrWillBeRawPtr<GeolocationInspectorAgent> GeolocationInspectorAgent::create()
3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
40c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    return adoptPtrWillBeNoop(new GeolocationInspectorAgent());
4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
4209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
4309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)GeolocationInspectorAgent::~GeolocationInspectorAgent()
4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
4509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
47f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)GeolocationInspectorAgent::GeolocationInspectorAgent()
4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    : InspectorBaseAgent<GeolocationInspectorAgent>("Geolocation")
4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    , m_geolocationOverridden(false)
5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
5209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
5309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void GeolocationInspectorAgent::setGeolocationOverride(ErrorString* error, const double* latitude, const double* longitude, const double* accuracy)
5409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
55f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    GeolocationPosition* position = (*m_controllers.begin())->lastPosition();
5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (!m_geolocationOverridden && position)
5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_platformGeolocationPosition = position;
5809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
5909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_geolocationOverridden = true;
6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (latitude && longitude && accuracy)
61d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_geolocationPosition = GeolocationPosition::create(currentTime(), *latitude, *longitude, *accuracy);
6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    else
6309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_geolocationPosition.clear();
6409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
655d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    for (GeolocationControllers::iterator it = m_controllers.begin(); it != m_controllers.end(); ++it)
66f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        (*it)->positionChanged(0); // Kick location update.
6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
6809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
6909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void GeolocationInspectorAgent::clearGeolocationOverride(ErrorString*)
7009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
7109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (!m_geolocationOverridden)
7209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return;
7309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_geolocationOverridden = false;
7409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_geolocationPosition.clear();
7509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
765d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    if (GeolocationPosition* platformPosition = m_platformGeolocationPosition.get()) {
775d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        for (GeolocationControllers::iterator it = m_controllers.begin(); it != m_controllers.end(); ++it)
785d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)            (*it)->positionChanged(platformPosition);
79f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    }
8009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
8109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
8209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)GeolocationPosition* GeolocationInspectorAgent::overrideGeolocationPosition(GeolocationPosition* position)
8309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
8409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (m_geolocationOverridden) {
8509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (position)
8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            m_platformGeolocationPosition = position;
8709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return m_geolocationPosition.get();
8809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
8909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return position;
9009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
9109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
92c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)void GeolocationInspectorAgent::addController(GeolocationController* controller)
93f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles){
94f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    m_controllers.add(controller);
95f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)}
96f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
97c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)void GeolocationInspectorAgent::removeController(GeolocationController* controller)
98f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles){
99f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    m_controllers.remove(controller);
100f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)}
101f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
102c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)void GeolocationInspectorAgent::trace(Visitor* visitor)
103c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles){
104c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#if ENABLE(OILPAN)
105c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    visitor->trace(m_controllers);
106c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#endif
107c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    visitor->trace(m_geolocationPosition);
108c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    visitor->trace(m_platformGeolocationPosition);
109c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    InspectorBaseAgent::trace(visitor);
110c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)}
111c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
112c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
113