GeolocationPermissionRequestManager.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2011 Apple 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
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "GeolocationPermissionRequestManager.h"
  27. #if ENABLE(GEOLOCATION)
  28. #include "WebCoreArgumentCoders.h"
  29. #include "WebFrame.h"
  30. #include "WebPage.h"
  31. #include "WebPageProxyMessages.h"
  32. #include <WebCore/Frame.h>
  33. #include <WebCore/FrameLoader.h>
  34. #include <WebCore/Geolocation.h>
  35. #include <WebCore/SecurityOrigin.h>
  36. using namespace WebCore;
  37. namespace WebKit {
  38. static uint64_t generateGeolocationID()
  39. {
  40. static uint64_t uniqueGeolocationID = 1;
  41. return uniqueGeolocationID++;
  42. }
  43. GeolocationPermissionRequestManager::GeolocationPermissionRequestManager(WebPage* page)
  44. : m_page(page)
  45. {
  46. }
  47. void GeolocationPermissionRequestManager::startRequestForGeolocation(Geolocation* geolocation)
  48. {
  49. uint64_t geolocationID = generateGeolocationID();
  50. m_geolocationToIDMap.set(geolocation, geolocationID);
  51. m_idToGeolocationMap.set(geolocationID, geolocation);
  52. Frame* frame = geolocation->frame();
  53. WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader()->client());
  54. WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
  55. ASSERT(webFrame);
  56. SecurityOrigin* origin = frame->document()->securityOrigin();
  57. m_page->send(Messages::WebPageProxy::RequestGeolocationPermissionForFrame(geolocationID, webFrame->frameID(), origin->databaseIdentifier()));
  58. }
  59. void GeolocationPermissionRequestManager::cancelRequestForGeolocation(Geolocation* geolocation)
  60. {
  61. GeolocationToIDMap::iterator it = m_geolocationToIDMap.find(geolocation);
  62. if (it == m_geolocationToIDMap.end())
  63. return;
  64. uint64_t geolocationID = it->value;
  65. m_geolocationToIDMap.remove(it);
  66. m_idToGeolocationMap.remove(geolocationID);
  67. }
  68. void GeolocationPermissionRequestManager::didReceiveGeolocationPermissionDecision(uint64_t geolocationID, bool allowed)
  69. {
  70. IDToGeolocationMap::iterator it = m_idToGeolocationMap.find(geolocationID);
  71. if (it == m_idToGeolocationMap.end())
  72. return;
  73. Geolocation* geolocation = it->value;
  74. geolocation->setIsAllowed(allowed);
  75. m_idToGeolocationMap.remove(it);
  76. m_geolocationToIDMap.remove(geolocation);
  77. }
  78. } // namespace WebKit
  79. #endif // ENABLE(GEOLOCATION)