Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: third_party/WebKit/Source/modules/webshare/NavigatorShare.cpp

Issue 2219383002: Require a user gesture to use navigator.share. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webshare-dictionary
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/webshare/share-without-user-gesture.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "modules/webshare/ShareData.h" 12 #include "modules/webshare/ShareData.h"
13 #include "platform/UserGestureIndicator.h"
13 #include "platform/mojo/MojoHelper.h" 14 #include "platform/mojo/MojoHelper.h"
14 #include "public/platform/InterfaceProvider.h" 15 #include "public/platform/InterfaceProvider.h"
15 #include "public/platform/Platform.h" 16 #include "public/platform/Platform.h"
16 17
17 namespace blink { 18 namespace blink {
18 19
19 class NavigatorShare::ShareClientImpl final : public GarbageCollected<ShareClien tImpl> { 20 class NavigatorShare::ShareClientImpl final : public GarbageCollected<ShareClien tImpl> {
20 public: 21 public:
21 ShareClientImpl(NavigatorShare*, ScriptPromiseResolver*); 22 ShareClientImpl(NavigatorShare*, ScriptPromiseResolver*);
22 23
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 { 75 {
75 } 76 }
76 77
77 const char* NavigatorShare::supplementName() 78 const char* NavigatorShare::supplementName()
78 { 79 {
79 return "NavigatorShare"; 80 return "NavigatorShare";
80 } 81 }
81 82
82 ScriptPromise NavigatorShare::share(ScriptState* scriptState, const ShareData& s hareData) 83 ScriptPromise NavigatorShare::share(ScriptState* scriptState, const ShareData& s hareData)
83 { 84 {
85 if (!UserGestureIndicator::utilizeUserGesture()) {
86 DOMException* error = DOMException::create(SecurityError, "Must be handl ing a user gesture to perform a share request.");
87 return ScriptPromise::rejectWithDOMException(scriptState, error);
88 }
89
84 if (!m_service) { 90 if (!m_service) {
85 Document* doc = toDocument(scriptState->getExecutionContext()); 91 Document* doc = toDocument(scriptState->getExecutionContext());
86 DCHECK(doc); 92 DCHECK(doc);
87 LocalFrame* frame = doc->frame(); 93 LocalFrame* frame = doc->frame();
88 DCHECK(frame); 94 DCHECK(frame);
89 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_service)); 95 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_service));
90 DCHECK(m_service); 96 DCHECK(m_service);
91 } 97 }
92 98
93 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 99 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
94 ShareClientImpl* client = new ShareClientImpl(this, resolver); 100 ShareClientImpl* client = new ShareClientImpl(this, resolver);
95 m_clients.add(client); 101 m_clients.add(client);
96 ScriptPromise promise = resolver->promise(); 102 ScriptPromise promise = resolver->promise();
97 103
98 // TODO(sammc): Use shareData.url(). 104 // TODO(sammc): Use shareData.url().
99 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))));
100 106
101 return promise; 107 return promise;
102 } 108 }
103 109
104 ScriptPromise NavigatorShare::share(ScriptState* scriptState, Navigator& navigat or, const ShareData& shareData) 110 ScriptPromise NavigatorShare::share(ScriptState* scriptState, Navigator& navigat or, const ShareData& shareData)
105 { 111 {
106 return from(navigator).share(scriptState, shareData); 112 return from(navigator).share(scriptState, shareData);
107 } 113 }
108 114
109 } // namespace blink 115 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/webshare/share-without-user-gesture.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698