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 "InternalsGeolocation.h" 3309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/dom/Document.h" 35f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#include "core/page/Page.h" 3609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/testing/Internals.h" 3709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/geolocation/GeolocationController.h" 3809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/geolocation/GeolocationError.h" 3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/geolocation/GeolocationPosition.h" 4009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/geolocation/testing/GeolocationClientMock.h" 4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "wtf/CurrentTime.h" 4209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 43c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 45d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void InternalsGeolocation::setGeolocationClientMock(Internals&, Document* document) 4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 47f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) ASSERT(document && document->frame()); 4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) GeolocationClientMock* client = new GeolocationClientMock(); 49f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) 505d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) for (Frame* childFrame = document->page()->mainFrame(); childFrame; childFrame = childFrame->tree().traverseNext()) { 515d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) if (childFrame->isLocalFrame()) 525d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) GeolocationController::from(toLocalFrame(childFrame))->setClientForTest(client); 535d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) } 5409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 5509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 56d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void InternalsGeolocation::setGeolocationPosition(Internals&, Document* document, double latitude, double longitude, double accuracy) 5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 58f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) ASSERT(document && document->frame()); 5909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) GeolocationClientMock* client = geolocationClient(document); 6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!client) 6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return; 6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) client->setPosition(GeolocationPosition::create(currentTime(), latitude, longitude, accuracy)); 6309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 6409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 65d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void InternalsGeolocation::setGeolocationPositionUnavailableError(Internals&, Document* document, const String& message) 6609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 67f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) ASSERT(document && document->frame()); 6809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) GeolocationClientMock* client = geolocationClient(document); 6909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!client) 7009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return; 7109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) client->setPositionUnavailableError(message); 7209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 7309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 74d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void InternalsGeolocation::setGeolocationPermission(Internals&, Document* document, bool allowed) 7509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 76f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) ASSERT(document && document->frame()); 7709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) GeolocationClientMock* client = geolocationClient(document); 7809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!client) 7909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return; 8009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) client->setPermission(allowed); 8109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 8209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 83d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)int InternalsGeolocation::numberOfPendingGeolocationPermissionRequests(Internals&, Document* document) 8409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 85f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) ASSERT(document && document->frame()); 8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) GeolocationClientMock* client = geolocationClient(document); 8709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!client) 8809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return -1; 8909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return client->numberOfPendingPermissionRequests(); 9009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 9109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 9209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)GeolocationClientMock* InternalsGeolocation::geolocationClient(Document* document) 9309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 94f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) GeolocationController* controller = GeolocationController::from(document->frame()); 9509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!controller->hasClientForTest()) 9609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return 0; 9709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return static_cast<GeolocationClientMock*>(controller->client()); 9809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 9909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 100c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 101