Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/presentation/PresentationSession.h" | 6 #include "modules/presentation/PresentationSession.h" |
| 7 | 7 |
| 8 #include "core/dom/DOMArrayBuffer.h" | |
| 9 #include "core/dom/DOMArrayBufferView.h" | |
| 8 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| 11 #include "core/dom/ExceptionCode.h" | |
| 9 #include "core/events/Event.h" | 12 #include "core/events/Event.h" |
| 10 #include "core/frame/LocalFrame.h" | 13 #include "core/frame/LocalFrame.h" |
| 11 #include "modules/EventTargetModules.h" | 14 #include "modules/EventTargetModules.h" |
| 12 #include "modules/presentation/Presentation.h" | 15 #include "modules/presentation/Presentation.h" |
| 13 #include "modules/presentation/PresentationController.h" | 16 #include "modules/presentation/PresentationController.h" |
| 14 #include "public/platform/modules/presentation/WebPresentationSessionClient.h" | 17 #include "public/platform/modules/presentation/WebPresentationSessionClient.h" |
| 15 #include "wtf/Assertions.h" | 18 #include "wtf/Assertions.h" |
| 16 #include "wtf/OwnPtr.h" | 19 #include "wtf/OwnPtr.h" |
| 17 #include "wtf/text/AtomicString.h" | 20 #include "wtf/text/AtomicString.h" |
| 18 | 21 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 29 case WebPresentationSessionState::Connected: | 32 case WebPresentationSessionState::Connected: |
| 30 return connectedValue; | 33 return connectedValue; |
| 31 case WebPresentationSessionState::Disconnected: | 34 case WebPresentationSessionState::Disconnected: |
| 32 return disconnectedValue; | 35 return disconnectedValue; |
| 33 } | 36 } |
| 34 | 37 |
| 35 ASSERT_NOT_REACHED(); | 38 ASSERT_NOT_REACHED(); |
| 36 return disconnectedValue; | 39 return disconnectedValue; |
| 37 } | 40 } |
| 38 | 41 |
| 42 void throwPresentationDisconnectedError(ExceptionState& exceptionState) | |
| 43 { | |
| 44 exceptionState.throwDOMException(InvalidStateError, "Presentation session is disconnected."); | |
| 45 } | |
| 46 | |
| 39 } // namespace | 47 } // namespace |
| 40 | 48 |
| 41 PresentationSession::PresentationSession(LocalFrame* frame, const String& id, co nst String& url) | 49 PresentationSession::PresentationSession(LocalFrame* frame, const String& id, co nst String& url) |
| 42 : DOMWindowProperty(frame) | 50 : DOMWindowProperty(frame) |
| 43 , m_id(id) | 51 , m_id(id) |
| 44 , m_url(url) | 52 , m_url(url) |
| 45 , m_state(WebPresentationSessionState::Disconnected) | 53 , m_state(WebPresentationSessionState::Disconnected) |
| 46 { | 54 { |
| 47 } | 55 } |
| 48 | 56 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 { | 91 { |
| 84 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationSession>::tr ace(visitor); | 92 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationSession>::tr ace(visitor); |
| 85 DOMWindowProperty::trace(visitor); | 93 DOMWindowProperty::trace(visitor); |
| 86 } | 94 } |
| 87 | 95 |
| 88 const AtomicString& PresentationSession::state() const | 96 const AtomicString& PresentationSession::state() const |
| 89 { | 97 { |
| 90 return SessionStateToString(m_state); | 98 return SessionStateToString(m_state); |
| 91 } | 99 } |
| 92 | 100 |
| 93 void PresentationSession::postMessage(const String& message) | 101 void PresentationSession::send(const String& message, ExceptionState& exceptionS tate) |
| 94 { | 102 { |
| 103 if (m_state != WebPresentationSessionState::Connected) { | |
| 104 throwPresentationDisconnectedError(exceptionState); | |
| 105 return; | |
| 106 } | |
| 107 PresentationController* controller = presentationController(); | |
| 108 if (controller) | |
| 109 controller->send(m_url, m_id, message); | |
| 110 } | |
| 111 | |
| 112 void PresentationSession::send(Blob* data, ExceptionState& exceptionState) | |
| 113 { | |
| 114 // TODO(): To be implemented. | |
|
mark a. foltz
2015/04/08 23:14:35
Throw a DOMException here for an unimplemented fea
mark a. foltz
2015/04/08 23:14:35
Please put your @chromium.org login here and in ot
USE s.singapati at gmail.com
2015/04/09 04:36:13
I do not have username at @chromium.org yet, but @
USE s.singapati at gmail.com
2015/04/09 14:37:11
Done. yes, i think DOMException is ok for now.
| |
| 115 } | |
| 116 | |
| 117 void PresentationSession::send(PassRefPtr<DOMArrayBuffer> data, ExceptionState& exceptionState) | |
| 118 { | |
| 119 if (m_state != WebPresentationSessionState::Connected) { | |
| 120 throwPresentationDisconnectedError(exceptionState); | |
| 121 return; | |
| 122 } | |
| 123 // TODO(): DOM exception Or ASSERT(data && data->buffer())? | |
| 124 if (!data) { | |
| 125 exceptionState.throwDOMException( | |
| 126 SyntaxError, | |
| 127 "invalid ArrayBuffer for PresentationSession message."); | |
| 128 return; | |
| 129 } | |
| 130 if (!data->byteLength()) | |
| 131 return; | |
| 132 | |
| 133 PresentationController* controller = presentationController(); | |
| 134 if (controller) | |
| 135 controller->send(m_url, m_id, static_cast<const char*>(data->data()), da ta->byteLength()); | |
| 136 } | |
| 137 | |
| 138 void PresentationSession::send(PassRefPtr<DOMArrayBufferView> data, ExceptionSta te& exceptionState) | |
| 139 { | |
| 140 if (m_state != WebPresentationSessionState::Connected) { | |
| 141 throwPresentationDisconnectedError(exceptionState); | |
| 142 return; | |
| 143 } | |
| 144 // TODO(): DOM exception Or ASSERT(data)? | |
|
mark a. foltz
2015/04/08 23:14:35
I think you should be guaranteed to get a live and
USE s.singapati at gmail.com
2015/04/09 14:37:11
Done. It is tested that data is valid. and atleast
| |
| 145 if (!data) { | |
| 146 exceptionState.throwDOMException( | |
| 147 SyntaxError, | |
| 148 "invalid ArrayBufferView for PresentationSession message."); | |
| 149 return; | |
| 150 } | |
| 151 if (!data->byteLength()) | |
| 152 return; | |
| 153 | |
| 154 PresentationController* controller = presentationController(); | |
| 155 if (controller) | |
| 156 controller->send(m_url, m_id, static_cast<const char*>(data->baseAddress ()), data->byteLength()); | |
| 95 } | 157 } |
| 96 | 158 |
| 97 void PresentationSession::close() | 159 void PresentationSession::close() |
| 98 { | 160 { |
| 99 if (m_state != WebPresentationSessionState::Connected) | 161 if (m_state != WebPresentationSessionState::Connected) |
| 100 return; | 162 return; |
| 101 PresentationController* controller = presentationController(); | 163 PresentationController* controller = presentationController(); |
| 102 if (controller) | 164 if (controller) |
| 103 controller->closeSession(m_url, m_id); | 165 controller->closeSession(m_url, m_id); |
| 104 } | 166 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 118 } | 180 } |
| 119 | 181 |
| 120 PresentationController* PresentationSession::presentationController() | 182 PresentationController* PresentationSession::presentationController() |
| 121 { | 183 { |
| 122 if (!frame()) | 184 if (!frame()) |
| 123 return nullptr; | 185 return nullptr; |
| 124 return PresentationController::from(*frame()); | 186 return PresentationController::from(*frame()); |
| 125 } | 187 } |
| 126 | 188 |
| 127 } // namespace blink | 189 } // namespace blink |
| OLD | NEW |