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

Side by Side Diff: third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp

Issue 2148643002: [Presentation API] Adds DOMString[] constructor to PresentationRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix LayoutTests Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/presentation/PresentationRequest.h" 5 #include "modules/presentation/PresentationRequest.h"
6 6
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" 7 #include "bindings/core/v8/CallbackPromiseAdapter.h"
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
11 #include "core/dom/Document.h" 11 #include "core/dom/Document.h"
12 #include "core/dom/ExecutionContext.h" 12 #include "core/dom/ExecutionContext.h"
13 #include "core/frame/Settings.h" 13 #include "core/frame/Settings.h"
14 #include "core/frame/UseCounter.h" 14 #include "core/frame/UseCounter.h"
15 #include "modules/EventTargetModules.h" 15 #include "modules/EventTargetModules.h"
16 #include "modules/presentation/PresentationAvailability.h" 16 #include "modules/presentation/PresentationAvailability.h"
17 #include "modules/presentation/PresentationAvailabilityCallbacks.h" 17 #include "modules/presentation/PresentationAvailabilityCallbacks.h"
18 #include "modules/presentation/PresentationConnection.h" 18 #include "modules/presentation/PresentationConnection.h"
19 #include "modules/presentation/PresentationConnectionCallbacks.h" 19 #include "modules/presentation/PresentationConnectionCallbacks.h"
20 #include "modules/presentation/PresentationController.h" 20 #include "modules/presentation/PresentationController.h"
21 #include "modules/presentation/PresentationError.h" 21 #include "modules/presentation/PresentationError.h"
22 #include "platform/UserGestureIndicator.h" 22 #include "platform/UserGestureIndicator.h"
23 #include "wtf/text/WTFString.h"
23 24
24 namespace blink { 25 namespace blink {
25 26
26 namespace { 27 namespace {
27 28
28 // TODO(mlamouri): refactor in one common place. 29 // TODO(mlamouri): refactor in one common place.
29 WebPresentationClient* presentationClient(ExecutionContext* executionContext) 30 WebPresentationClient* presentationClient(ExecutionContext* executionContext)
30 { 31 {
31 DCHECK(executionContext); 32 DCHECK(executionContext);
32 33
(...skipping 10 matching lines...) Expand all
43 44
44 Document* document = toDocument(executionContext); 45 Document* document = toDocument(executionContext);
45 return document->settings(); 46 return document->settings();
46 } 47 }
47 48
48 } // anonymous namespace 49 } // anonymous namespace
49 50
50 // static 51 // static
51 PresentationRequest* PresentationRequest::create(ExecutionContext* executionCont ext, const String& url, ExceptionState& exceptionState) 52 PresentationRequest* PresentationRequest::create(ExecutionContext* executionCont ext, const String& url, ExceptionState& exceptionState)
52 { 53 {
53 KURL parsedUrl = KURL(executionContext->url(), url); 54 WTF::Vector<String> urls(1);
54 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { 55 urls[0] = url;
55 exceptionState.throwTypeError("'" + url + "' can't be resolved to a vali d URL."); 56 return create(executionContext, urls, exceptionState);
56 return nullptr; 57 }
58
59 PresentationRequest* PresentationRequest::create(ExecutionContext* executionCont ext, const WTF::Vector<String>& urls, ExceptionState& exceptionState)
60 {
61 WTF::Vector<KURL> parsedUrls(urls.size());
62 for (size_t i = 0; i < urls.size(); ++i) {
63 const KURL& parsedUrl = KURL(executionContext->url(), urls[i]);
64 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) {
65 exceptionState.throwTypeError("'" + urls[i] + "' can't be resolved t o a valid URL.");
66 return nullptr;
67 }
68 parsedUrls[i] = parsedUrl;
57 } 69 }
58 70 PresentationRequest* request = new PresentationRequest(executionContext, par sedUrls);
59 PresentationRequest* request = new PresentationRequest(executionContext, par sedUrl);
60 request->suspendIfNeeded(); 71 request->suspendIfNeeded();
61 return request; 72 return request;
62 } 73 }
63 74
64 const AtomicString& PresentationRequest::interfaceName() const 75 const AtomicString& PresentationRequest::interfaceName() const
65 { 76 {
66 return EventTargetNames::PresentationRequest; 77 return EventTargetNames::PresentationRequest;
67 } 78 }
68 79
69 ExecutionContext* PresentationRequest::getExecutionContext() const 80 ExecutionContext* PresentationRequest::getExecutionContext() const
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) { 115 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) {
105 resolver->reject(DOMException::create(SecurityError, "The document is sa ndboxed and lacks the 'allow-presentation' flag.")); 116 resolver->reject(DOMException::create(SecurityError, "The document is sa ndboxed and lacks the 'allow-presentation' flag."));
106 return promise; 117 return promise;
107 } 118 }
108 119
109 WebPresentationClient* client = presentationClient(getExecutionContext()); 120 WebPresentationClient* client = presentationClient(getExecutionContext());
110 if (!client) { 121 if (!client) {
111 resolver->reject(DOMException::create(InvalidStateError, "The Presentati onRequest is no longer associated to a frame.")); 122 resolver->reject(DOMException::create(InvalidStateError, "The Presentati onRequest is no longer associated to a frame."));
112 return promise; 123 return promise;
113 } 124 }
114 client->startSession(m_url.getString(), new PresentationConnectionCallbacks( resolver, this)); 125 client->startSession(m_urls, new PresentationConnectionCallbacks(resolver, t his));
115 return promise; 126 return promise;
116 } 127 }
117 128
118 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, const Str ing& id) 129 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, const Str ing& id)
119 { 130 {
120 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 131 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
121 ScriptPromise promise = resolver->promise(); 132 ScriptPromise promise = resolver->promise();
122 133
123 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) { 134 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) {
124 resolver->reject(DOMException::create(SecurityError, "The document is sa ndboxed and lacks the 'allow-presentation' flag.")); 135 resolver->reject(DOMException::create(SecurityError, "The document is sa ndboxed and lacks the 'allow-presentation' flag."));
125 return promise; 136 return promise;
126 } 137 }
127 138
128 WebPresentationClient* client = presentationClient(getExecutionContext()); 139 WebPresentationClient* client = presentationClient(getExecutionContext());
129 if (!client) { 140 if (!client) {
130 resolver->reject(DOMException::create(InvalidStateError, "The Presentati onRequest is no longer associated to a frame.")); 141 resolver->reject(DOMException::create(InvalidStateError, "The Presentati onRequest is no longer associated to a frame."));
131 return promise; 142 return promise;
132 } 143 }
133 client->joinSession(m_url.getString(), id, new PresentationConnectionCallbac ks(resolver, this)); 144 client->joinSession(m_urls, id, new PresentationConnectionCallbacks(resolver , this));
134 return promise; 145 return promise;
135 } 146 }
136 147
137 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) 148 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState)
138 { 149 {
139 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 150 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
140 ScriptPromise promise = resolver->promise(); 151 ScriptPromise promise = resolver->promise();
141 152
142 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) { 153 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) {
143 resolver->reject(DOMException::create(SecurityError, "The document is sa ndboxed and lacks the 'allow-presentation' flag.")); 154 resolver->reject(DOMException::create(SecurityError, "The document is sa ndboxed and lacks the 'allow-presentation' flag."));
144 return promise; 155 return promise;
145 } 156 }
146 157
147 WebPresentationClient* client = presentationClient(getExecutionContext()); 158 WebPresentationClient* client = presentationClient(getExecutionContext());
148 if (!client) { 159 if (!client) {
149 resolver->reject(DOMException::create(InvalidStateError, "The object is no longer associated to a frame.")); 160 resolver->reject(DOMException::create(InvalidStateError, "The object is no longer associated to a frame."));
150 return promise; 161 return promise;
151 } 162 }
152 client->getAvailability(m_url.getString(), new PresentationAvailabilityCallb acks(resolver, m_url)); 163
164 client->getAvailability(m_urls, new PresentationAvailabilityCallbacks(resolv er, m_urls));
153 return promise; 165 return promise;
154 } 166 }
155 167
156 const KURL& PresentationRequest::url() const 168 const WTF::Vector<KURL>& PresentationRequest::urls() const
157 { 169 {
158 return m_url; 170 return m_urls;
159 } 171 }
160 172
161 DEFINE_TRACE(PresentationRequest) 173 DEFINE_TRACE(PresentationRequest)
162 { 174 {
163 EventTargetWithInlineData::trace(visitor); 175 EventTargetWithInlineData::trace(visitor);
164 ActiveDOMObject::trace(visitor); 176 ActiveDOMObject::trace(visitor);
165 } 177 }
166 178
167 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, con st KURL& url) 179 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, con st WTF::Vector<KURL>& urls)
168 : ActiveScriptWrappable(this) 180 : ActiveScriptWrappable(this)
169 , ActiveDOMObject(executionContext) 181 , ActiveDOMObject(executionContext)
170 , m_url(url) 182 , m_urls(urls)
171 { 183 {
172 } 184 }
173 185
174 } // namespace blink 186 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698