| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/webshare/NavigatorShare.h" | 5 #include "modules/webshare/NavigatorShare.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| 11 #include "core/frame/Navigator.h" | 11 #include "core/frame/Navigator.h" |
| 12 #include "core/frame/UseCounter.h" |
| 12 #include "modules/webshare/ShareData.h" | 13 #include "modules/webshare/ShareData.h" |
| 13 #include "platform/UserGestureIndicator.h" | 14 #include "platform/UserGestureIndicator.h" |
| 14 #include "platform/mojo/MojoHelper.h" | 15 #include "platform/mojo/MojoHelper.h" |
| 15 #include "public/platform/InterfaceProvider.h" | 16 #include "public/platform/InterfaceProvider.h" |
| 16 #include "public/platform/Platform.h" | 17 #include "public/platform/Platform.h" |
| 17 | 18 |
| 18 namespace blink { | 19 namespace blink { |
| 19 | 20 |
| 20 class NavigatorShare::ShareClientImpl final : public GarbageCollected<ShareClien
tImpl> { | 21 class NavigatorShare::ShareClientImpl final : public GarbageCollected<ShareClien
tImpl> { |
| 21 public: | 22 public: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 { | 76 { |
| 76 } | 77 } |
| 77 | 78 |
| 78 const char* NavigatorShare::supplementName() | 79 const char* NavigatorShare::supplementName() |
| 79 { | 80 { |
| 80 return "NavigatorShare"; | 81 return "NavigatorShare"; |
| 81 } | 82 } |
| 82 | 83 |
| 83 ScriptPromise NavigatorShare::share(ScriptState* scriptState, const ShareData& s
hareData) | 84 ScriptPromise NavigatorShare::share(ScriptState* scriptState, const ShareData& s
hareData) |
| 84 { | 85 { |
| 86 Document* doc = toDocument(scriptState->getExecutionContext()); |
| 87 DCHECK(doc); |
| 88 UseCounter::count(*doc, UseCounter::WebShareShare); |
| 89 |
| 85 if (!UserGestureIndicator::utilizeUserGesture()) { | 90 if (!UserGestureIndicator::utilizeUserGesture()) { |
| 86 DOMException* error = DOMException::create(SecurityError, "Must be handl
ing a user gesture to perform a share request."); | 91 DOMException* error = DOMException::create(SecurityError, "Must be handl
ing a user gesture to perform a share request."); |
| 87 return ScriptPromise::rejectWithDOMException(scriptState, error); | 92 return ScriptPromise::rejectWithDOMException(scriptState, error); |
| 88 } | 93 } |
| 89 | 94 |
| 90 if (!m_service) { | 95 if (!m_service) { |
| 91 Document* doc = toDocument(scriptState->getExecutionContext()); | |
| 92 DCHECK(doc); | |
| 93 LocalFrame* frame = doc->frame(); | 96 LocalFrame* frame = doc->frame(); |
| 94 DCHECK(frame); | 97 DCHECK(frame); |
| 95 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_service)); | 98 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_service)); |
| 96 DCHECK(m_service); | 99 DCHECK(m_service); |
| 97 } | 100 } |
| 98 | 101 |
| 99 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 102 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 100 ShareClientImpl* client = new ShareClientImpl(this, resolver); | 103 ShareClientImpl* client = new ShareClientImpl(this, resolver); |
| 101 m_clients.add(client); | 104 m_clients.add(client); |
| 102 ScriptPromise promise = resolver->promise(); | 105 ScriptPromise promise = resolver->promise(); |
| 103 | 106 |
| 104 // TODO(sammc): Use shareData.url(). | 107 // TODO(sammc): Use shareData.url(). |
| 105 m_service->Share(shareData.hasTitle() ? shareData.title() : emptyString(), s
hareData.hasText() ? shareData.text() : emptyString(), convertToBaseCallback(WTF
::bind(&ShareClientImpl::callback, wrapPersistent(client)))); | 108 m_service->Share(shareData.hasTitle() ? shareData.title() : emptyString(), s
hareData.hasText() ? shareData.text() : emptyString(), convertToBaseCallback(WTF
::bind(&ShareClientImpl::callback, wrapPersistent(client)))); |
| 106 | 109 |
| 107 return promise; | 110 return promise; |
| 108 } | 111 } |
| 109 | 112 |
| 110 ScriptPromise NavigatorShare::share(ScriptState* scriptState, Navigator& navigat
or, const ShareData& shareData) | 113 ScriptPromise NavigatorShare::share(ScriptState* scriptState, Navigator& navigat
or, const ShareData& shareData) |
| 111 { | 114 { |
| 112 return from(navigator).share(scriptState, shareData); | 115 return from(navigator).share(scriptState, shareData); |
| 113 } | 116 } |
| 114 | 117 |
| 115 } // namespace blink | 118 } // namespace blink |
| OLD | NEW |