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

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
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 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(SecurityError, "Must be handling a user gesture to perform a share reques t."));
Matt Giuca 2016/08/08 08:00:06 nit: Maybe split this into a temp variable, for li
Sam McNally 2016/08/08 09:08:44 Done.
87
84 if (!m_service) { 88 if (!m_service) {
85 Document* doc = toDocument(scriptState->getExecutionContext()); 89 Document* doc = toDocument(scriptState->getExecutionContext());
86 DCHECK(doc); 90 DCHECK(doc);
87 LocalFrame* frame = doc->frame(); 91 LocalFrame* frame = doc->frame();
88 DCHECK(frame); 92 DCHECK(frame);
89 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_service)); 93 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_service));
90 DCHECK(m_service); 94 DCHECK(m_service);
91 } 95 }
92 96
93 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 97 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
94 ShareClientImpl* client = new ShareClientImpl(this, resolver); 98 ShareClientImpl* client = new ShareClientImpl(this, resolver);
95 m_clients.add(client); 99 m_clients.add(client);
96 ScriptPromise promise = resolver->promise(); 100 ScriptPromise promise = resolver->promise();
97 101
98 // TODO(sammc): Use shareData.url(). 102 // 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)))); 103 m_service->Share(shareData.hasTitle() ? shareData.title() : emptyString(), s hareData.hasText() ? shareData.text() : emptyString(), convertToBaseCallback(WTF ::bind(&ShareClientImpl::callback, wrapPersistent(client))));
100 104
101 return promise; 105 return promise;
102 } 106 }
103 107
104 ScriptPromise NavigatorShare::share(ScriptState* scriptState, Navigator& navigat or, const ShareData& shareData) 108 ScriptPromise NavigatorShare::share(ScriptState* scriptState, Navigator& navigat or, const ShareData& shareData)
105 { 109 {
106 return from(navigator).share(scriptState, shareData); 110 return from(navigator).share(scriptState, shareData);
107 } 111 }
108 112
109 } // namespace blink 113 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698