OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2009 Torch Mobile, Inc. | 3 * Copyright (C) 2009 Torch Mobile, Inc. |
4 * Copyright 2010, The Android Open Source Project | 4 * Copyright 2010, The Android Open Source Project |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 10 matching lines...) Expand all Loading... | |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include "config.h" | 28 #include "config.h" |
29 #include "modules/geolocation/Geolocation.h" | 29 #include "modules/geolocation/Geolocation.h" |
30 | 30 |
31 #include "bindings/core/v8/CallbackPromiseAdapter.h" | |
Michael van Ouwerkerk
2014/07/15 18:04:41
As we discussed offline, it seems quite possible t
| |
32 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
33 #include "bindings/core/v8/ScriptState.h" | |
31 #include "core/dom/DOMException.h" | 34 #include "core/dom/DOMException.h" |
32 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
33 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
37 #include "core/frame/LocalDOMWindow.h" | |
34 #include "modules/geolocation/Coordinates.h" | 38 #include "modules/geolocation/Coordinates.h" |
39 #include "modules/geolocation/GeofencingController.h" | |
40 #include "modules/geolocation/GeofencingError.h" | |
35 #include "modules/geolocation/GeofencingRegion.h" | 41 #include "modules/geolocation/GeofencingRegion.h" |
36 #include "modules/geolocation/GeolocationController.h" | 42 #include "modules/geolocation/GeolocationController.h" |
37 #include "modules/geolocation/GeolocationError.h" | 43 #include "modules/geolocation/GeolocationError.h" |
38 #include "modules/geolocation/GeolocationPosition.h" | 44 #include "modules/geolocation/GeolocationPosition.h" |
45 #include "modules/serviceworkers/NavigatorServiceWorker.h" | |
46 #include "modules/serviceworkers/ServiceWorkerContainer.h" | |
47 #include "public/platform/WebGeofencingClient.h" | |
48 #include "public/platform/WebGeofencingRegion.h" | |
39 #include "wtf/CurrentTime.h" | 49 #include "wtf/CurrentTime.h" |
40 | 50 |
41 namespace WebCore { | 51 namespace WebCore { |
42 | 52 |
43 static const char permissionDeniedErrorMessage[] = "User denied Geolocation"; | 53 static const char permissionDeniedErrorMessage[] = "User denied Geolocation"; |
44 static const char failedToStartServiceErrorMessage[] = "Failed to start Geolocat ion service"; | 54 static const char failedToStartServiceErrorMessage[] = "Failed to start Geolocat ion service"; |
45 static const char framelessDocumentErrorMessage[] = "Geolocation cannot be used in frameless documents"; | 55 static const char framelessDocumentErrorMessage[] = "Geolocation cannot be used in frameless documents"; |
46 | 56 |
47 static Geoposition* createGeoposition(GeolocationPosition* position) | 57 static Geoposition* createGeoposition(GeolocationPosition* position) |
48 { | 58 { |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 if (startUpdating(notifier)) | 687 if (startUpdating(notifier)) |
678 notifier->startTimer(); | 688 notifier->startTimer(); |
679 else | 689 else |
680 notifier->setFatalError(PositionError::create(PositionError::POS ITION_UNAVAILABLE, failedToStartServiceErrorMessage)); | 690 notifier->setFatalError(PositionError::create(PositionError::POS ITION_UNAVAILABLE, failedToStartServiceErrorMessage)); |
681 } else { | 691 } else { |
682 notifier->setFatalError(PositionError::create(PositionError::PERMISS ION_DENIED, permissionDeniedErrorMessage)); | 692 notifier->setFatalError(PositionError::create(PositionError::PERMISS ION_DENIED, permissionDeniedErrorMessage)); |
683 } | 693 } |
684 } | 694 } |
685 } | 695 } |
686 | 696 |
697 namespace { | |
698 | |
699 // Copy of same class in ServiceWorkerContainer.cpp | |
700 class UndefinedValue { | |
701 public: | |
702 typedef blink::WebGeofencingError WebType; | |
703 static V8UndefinedType from(ScriptPromiseResolver* resolver, WebType* value) | |
704 { | |
705 ASSERT(!value); // Anything passed here will be leaked. | |
706 return V8UndefinedType(); | |
707 } | |
708 | |
709 private: | |
710 UndefinedValue(); | |
711 }; | |
712 | |
713 class RegionArray { | |
714 public: | |
715 typedef blink::WebVector<blink::WebGeofencingRegion> WebType; | |
716 static HeapVector<Member<GeofencingRegion> > from(ScriptPromiseResolver* res olver, WebType* regionsRaw) | |
717 { | |
718 OwnPtr<WebType> webRegions = adoptPtr(regionsRaw); | |
719 HeapVector<Member<GeofencingRegion> > regions; | |
720 for (size_t i = 0; i < webRegions->size(); ++i) { | |
721 regions.append((GeofencingRegion*)(*webRegions)[i]); | |
722 } | |
723 return regions; | |
724 } | |
725 private: | |
726 RegionArray(); | |
727 }; | |
728 | |
729 } | |
730 | |
687 ScriptPromise Geolocation::registerRegion(ScriptState* scriptState, GeofencingRe gion* region) | 731 ScriptPromise Geolocation::registerRegion(ScriptState* scriptState, GeofencingRe gion* region) |
688 { | 732 { |
689 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); | 733 ASSERT(scriptState->executionContext()->isDocument()); |
734 | |
735 Document* document = toDocument(scriptState->executionContext()); | |
736 if (!document->domWindow() || !document->frame()) | |
737 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Document is detached from window.")); | |
738 | |
739 blink::WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWor ker::serviceWorker(document->domWindow()->navigator())->provider(); | |
740 if (!serviceWorkerProvider) | |
741 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "No Service Worker installed for this document.")); | |
742 | |
743 blink::WebGeofencingClient* client = GeofencingController::clientFrom(docume nt->frame()); | |
744 if (!client) | |
745 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | |
746 | |
747 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
748 ScriptPromise promise = resolver->promise(); | |
749 client->registerRegion(region, new CallbackPromiseAdapter<UndefinedValue, Ge ofencingError>(resolver), serviceWorkerProvider); | |
750 return promise; | |
690 } | 751 } |
691 | 752 |
692 ScriptPromise Geolocation::unregisterRegion(ScriptState* scriptState, const Stri ng& regionId) | 753 ScriptPromise Geolocation::unregisterRegion(ScriptState* scriptState, const Stri ng& regionId) |
693 { | 754 { |
694 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); | 755 ASSERT(scriptState->executionContext()->isDocument()); |
756 | |
757 Document* document = toDocument(scriptState->executionContext()); | |
758 if (!document->domWindow() || !document->frame()) | |
759 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Document is detached from window.")); | |
760 | |
761 blink::WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWor ker::serviceWorker(document->domWindow()->navigator())->provider(); | |
762 if (!serviceWorkerProvider) | |
763 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "No Service Worker installed for this document.")); | |
764 | |
765 blink::WebGeofencingClient* client = GeofencingController::clientFrom(docume nt->frame()); | |
766 if (!client) | |
767 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | |
768 | |
769 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
770 ScriptPromise promise = resolver->promise(); | |
771 client->unregisterRegion(regionId, new CallbackPromiseAdapter<UndefinedValue , GeofencingError>(resolver), serviceWorkerProvider); | |
772 return promise; | |
695 } | 773 } |
696 | 774 |
697 ScriptPromise Geolocation::getRegisteredRegions(ScriptState* scriptState) const | 775 ScriptPromise Geolocation::getRegisteredRegions(ScriptState* scriptState) const |
698 { | 776 { |
699 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); | 777 ASSERT(scriptState->executionContext()->isDocument()); |
778 | |
779 Document* document = toDocument(scriptState->executionContext()); | |
780 if (!document->domWindow() || !document->frame()) | |
781 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Document is detached from window.")); | |
782 | |
783 blink::WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWor ker::serviceWorker(document->domWindow()->navigator())->provider(); | |
784 if (!serviceWorkerProvider) | |
785 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "No Service Worker installed for this document.")); | |
786 | |
787 blink::WebGeofencingClient* client = GeofencingController::clientFrom(docume nt->frame()); | |
788 if (!client) | |
789 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | |
790 | |
791 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
792 ScriptPromise promise = resolver->promise(); | |
793 client->getRegisteredRegions(new CallbackPromiseAdapter<RegionArray, Geofenc ingError>(resolver), serviceWorkerProvider); | |
794 return promise; | |
700 } | 795 } |
701 | 796 |
702 } // namespace WebCore | 797 } // namespace WebCore |
OLD | NEW |