| OLD | NEW |
| 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" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 PresentationRequest* request = new PresentationRequest(executionContext, par
sedUrl); | 59 PresentationRequest* request = new PresentationRequest(executionContext, par
sedUrl); |
| 60 request->suspendIfNeeded(); | 60 request->suspendIfNeeded(); |
| 61 return request; | 61 return request; |
| 62 } | 62 } |
| 63 | 63 |
| 64 const AtomicString& PresentationRequest::interfaceName() const | 64 const AtomicString& PresentationRequest::interfaceName() const |
| 65 { | 65 { |
| 66 return EventTargetNames::PresentationRequest; | 66 return EventTargetNames::PresentationRequest; |
| 67 } | 67 } |
| 68 | 68 |
| 69 ExecutionContext* PresentationRequest::executionContext() const | 69 ExecutionContext* PresentationRequest::getExecutionContext() const |
| 70 { | 70 { |
| 71 return ActiveDOMObject::executionContext(); | 71 return ActiveDOMObject::getExecutionContext(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool PresentationRequest::addEventListenerInternal(const AtomicString& eventType
, PassRefPtrWillBeRawPtr<EventListener> listener, const EventListenerOptions& op
tions) | 74 bool PresentationRequest::addEventListenerInternal(const AtomicString& eventType
, PassRefPtrWillBeRawPtr<EventListener> listener, const EventListenerOptions& op
tions) |
| 75 { | 75 { |
| 76 if (eventType == EventTypeNames::connectionavailable) | 76 if (eventType == EventTypeNames::connectionavailable) |
| 77 UseCounter::count(executionContext(), UseCounter::PresentationRequestCon
nectionAvailableEventListener); | 77 UseCounter::count(getExecutionContext(), UseCounter::PresentationRequest
ConnectionAvailableEventListener); |
| 78 | 78 |
| 79 return EventTarget::addEventListenerInternal(eventType, listener, options); | 79 return EventTarget::addEventListenerInternal(eventType, listener, options); |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool PresentationRequest::hasPendingActivity() const | 82 bool PresentationRequest::hasPendingActivity() const |
| 83 { | 83 { |
| 84 if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) | 84 if (!getExecutionContext() || getExecutionContext()->activeDOMObjectsAreStop
ped()) |
| 85 return false; | 85 return false; |
| 86 | 86 |
| 87 // Prevents garbage collecting of this object when not hold by another | 87 // Prevents garbage collecting of this object when not hold by another |
| 88 // object but still has listeners registered. | 88 // object but still has listeners registered. |
| 89 return hasEventListeners(); | 89 return hasEventListeners(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 ScriptPromise PresentationRequest::start(ScriptState* scriptState) | 92 ScriptPromise PresentationRequest::start(ScriptState* scriptState) |
| 93 { | 93 { |
| 94 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 94 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 95 ScriptPromise promise = resolver->promise(); | 95 ScriptPromise promise = resolver->promise(); |
| 96 | 96 |
| 97 Settings* contextSettings = settings(executionContext()); | 97 Settings* contextSettings = settings(getExecutionContext()); |
| 98 bool isUserGestureRequired = !contextSettings || contextSettings->presentati
onRequiresUserGesture(); | 98 bool isUserGestureRequired = !contextSettings || contextSettings->presentati
onRequiresUserGesture(); |
| 99 | 99 |
| 100 if (isUserGestureRequired && !UserGestureIndicator::processingUserGesture())
{ | 100 if (isUserGestureRequired && !UserGestureIndicator::processingUserGesture())
{ |
| 101 resolver->reject(DOMException::create(InvalidAccessError, "PresentationR
equest::start() requires user gesture.")); | 101 resolver->reject(DOMException::create(InvalidAccessError, "PresentationR
equest::start() requires user gesture.")); |
| 102 return promise; | 102 return promise; |
| 103 } | 103 } |
| 104 | 104 |
| 105 WebPresentationClient* client = presentationClient(executionContext()); | 105 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 106 if (!client) { | 106 if (!client) { |
| 107 resolver->reject(DOMException::create(InvalidStateError, "The Presentati
onRequest is no longer associated to a frame.")); | 107 resolver->reject(DOMException::create(InvalidStateError, "The Presentati
onRequest is no longer associated to a frame.")); |
| 108 return promise; | 108 return promise; |
| 109 } | 109 } |
| 110 client->startSession(m_url.getString(), new PresentationConnectionCallbacks(
resolver, this)); | 110 client->startSession(m_url.getString(), new PresentationConnectionCallbacks(
resolver, this)); |
| 111 | 111 |
| 112 return promise; | 112 return promise; |
| 113 } | 113 } |
| 114 | 114 |
| 115 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, const Str
ing& id) | 115 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, const Str
ing& id) |
| 116 { | 116 { |
| 117 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 117 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 118 ScriptPromise promise = resolver->promise(); | 118 ScriptPromise promise = resolver->promise(); |
| 119 | 119 |
| 120 WebPresentationClient* client = presentationClient(executionContext()); | 120 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 121 if (!client) { | 121 if (!client) { |
| 122 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.")); |
| 123 return promise; | 123 return promise; |
| 124 } | 124 } |
| 125 client->joinSession(m_url.getString(), id, new PresentationConnectionCallbac
ks(resolver, this)); | 125 client->joinSession(m_url.getString(), id, new PresentationConnectionCallbac
ks(resolver, this)); |
| 126 | 126 |
| 127 return promise; | 127 return promise; |
| 128 } | 128 } |
| 129 | 129 |
| 130 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) | 130 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) |
| 131 { | 131 { |
| 132 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 132 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 133 ScriptPromise promise = resolver->promise(); | 133 ScriptPromise promise = resolver->promise(); |
| 134 | 134 |
| 135 WebPresentationClient* client = presentationClient(executionContext()); | 135 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 136 if (!client) { | 136 if (!client) { |
| 137 resolver->reject(DOMException::create(InvalidStateError, "The object is
no longer associated to a frame.")); | 137 resolver->reject(DOMException::create(InvalidStateError, "The object is
no longer associated to a frame.")); |
| 138 return promise; | 138 return promise; |
| 139 } | 139 } |
| 140 client->getAvailability(m_url.getString(), new PresentationAvailabilityCallb
acks(resolver, m_url)); | 140 client->getAvailability(m_url.getString(), new PresentationAvailabilityCallb
acks(resolver, m_url)); |
| 141 return promise; | 141 return promise; |
| 142 } | 142 } |
| 143 | 143 |
| 144 const KURL& PresentationRequest::url() const | 144 const KURL& PresentationRequest::url() const |
| 145 { | 145 { |
| 146 return m_url; | 146 return m_url; |
| 147 } | 147 } |
| 148 | 148 |
| 149 DEFINE_TRACE(PresentationRequest) | 149 DEFINE_TRACE(PresentationRequest) |
| 150 { | 150 { |
| 151 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationRequest>::tr
ace(visitor); | 151 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationRequest>::tr
ace(visitor); |
| 152 ActiveDOMObject::trace(visitor); | 152 ActiveDOMObject::trace(visitor); |
| 153 } | 153 } |
| 154 | 154 |
| 155 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, con
st KURL& url) | 155 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, con
st KURL& url) |
| 156 : ActiveDOMObject(executionContext) | 156 : ActiveDOMObject(executionContext) |
| 157 , m_url(url) | 157 , m_url(url) |
| 158 { | 158 { |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace blink | 161 } // namespace blink |
| OLD | NEW |