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