Changeset 207384 in webkit
- Timestamp:
- Oct 15, 2016 4:23:33 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207381 r207384 1 2016-10-15 Darin Adler <darin@apple.com> 2 3 Move Web SQL database and WebSockets off legacy exceptions 4 https://bugs.webkit.org/show_bug.cgi?id=163284 5 6 Reviewed by Chris Dumez. 7 8 * Modules/webdatabase/DOMWindowWebDatabase.cpp: 9 (WebCore::DOMWindowWebDatabase::openDatabase): Use ExceptionOr. 10 * Modules/webdatabase/DOMWindowWebDatabase.h: Update for above. 11 * Modules/webdatabase/DOMWindowWebDatabase.idl: Ditto. 12 13 * Modules/webdatabase/SQLResultSet.cpp: 14 (WebCore::SQLResultSet::SQLResultSet): Move initialization of 15 many data members into the class definition. 16 (WebCore::SQLResultSet::insertId): Use ExceptionOr. 17 (WebCore::SQLResultSet::rowsAffected): Moved into class definition. 18 (WebCore::SQLResultSet::rows): Ditto. 19 (WebCore::SQLResultSet::setInsertId): Ditto. 20 (WebCore::SQLResultSet::setRowsAffected): Ditto. 21 22 * Modules/webdatabase/SQLResultSet.h: Updated for above. 23 24 * Modules/webdatabase/SQLResultSet.idl: Use non-legacy exceptions. 25 Added a FIXME about the mismatch between long and int64_t. 26 27 * Modules/webdatabase/SQLStatement.cpp: 28 (WebCore::SQLStatement::execute): Use reference instead of pointer. 29 30 * Modules/websockets/WebSocket.cpp: 31 (WebCore::isValidProtocolString): Use StringView. 32 (WebCore::WebSocket::subprotocolSeparator): Fixed capitalization and 33 spelling error in the name of this function. 34 (WebCore::WebSocket::WebSocket): Move initialization of many data 35 members into the class definition. 36 (WebCore::WebSocket::create): Use ExceptionOr. 37 (WebCore::WebSocket::connect): Ditto. 38 (WebCore::WebSocket::send): Ditto. 39 (WebCore::WebSocket::close): Ditto. 40 (WebCore::WebSocket::binaryType): Update to use enum class. 41 (WebCore::WebSocket::setBinaryType): Use ExecptionOr and update to 42 use enum class. 43 (WebCore::WebSocket::didReceiveBinaryData): Ditto. 44 45 * Modules/websockets/WebSocket.h: Updated for above. Changed the 46 BinaryType enum into an enum class. 47 48 * Modules/websockets/WebSocket.idl: Use non-legacy exceptions. 49 50 * Modules/websockets/WebSocketHandshake.cpp: 51 (WebCore::WebSocketHandshake::checkResponseHeaders): 52 Updated for name change to subprotocolSeparator. 53 54 * dom/ExceptionOr.h: Added a constructor for scalar types that does not 55 require an rvalue reference. We can refine this more later, but for now 56 this is sufficient to obviate the need for WTFMove where it otherwise would 57 have been needed in the code above. 58 59 * inspector/InspectorDatabaseAgent.cpp: Use reference instead of pointer. 60 61 * page/DOMWindow.idl: Touched this file to work around bugs in the dependency 62 analysis of the current CMake build system, since otherwise it doesn't process the 63 change to the partial interface WebSocket. Edited lots of comments, removed many 64 others, and tweaked formatting. 65 1 66 2016-10-14 Sam Weinig <sam@webkit.org> 2 67 -
trunk/Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.cpp
r200289 r207384 30 30 #include "DOMWindow.h" 31 31 #include "Database.h" 32 #include "DatabaseCallback.h"33 32 #include "DatabaseManager.h" 34 33 #include "Document.h" 35 #include "Frame.h"36 34 #include "SecurityOrigin.h" 37 35 38 36 namespace WebCore { 39 37 40 RefPtr<Database> DOMWindowWebDatabase::openDatabase(DOMWindow& window, const String& name, const String& version, const String& displayName, unsigned long estimatedSize, RefPtr<DatabaseCallback>&& creationCallback, ExceptionCode& ec)38 ExceptionOr<RefPtr<Database>> DOMWindowWebDatabase::openDatabase(DOMWindow& window, const String& name, const String& version, const String& displayName, unsigned estimatedSize, RefPtr<DatabaseCallback>&& creationCallback) 41 39 { 42 40 if (!window.isCurrentlyDisplayedInFrame()) 43 return nullptr; 44 45 RefPtr<Database> database; 46 DatabaseManager& dbManager = DatabaseManager::singleton(); 47 DatabaseError error = DatabaseError::None; 48 if (dbManager.isAvailable() && window.document()->securityOrigin()->canAccessDatabase(window.document()->topOrigin())) { 49 database = dbManager.openDatabase(window.document(), name, version, displayName, estimatedSize, WTFMove(creationCallback), error); 50 ASSERT(database || error != DatabaseError::None); 51 ec = DatabaseManager::exceptionCodeForDatabaseError(error); 52 } else 53 ec = SECURITY_ERR; 54 55 return database; 41 return RefPtr<Database> { nullptr }; 42 auto& manager = DatabaseManager::singleton(); 43 if (!manager.isAvailable()) 44 return Exception { SECURITY_ERR }; 45 auto* document = window.document(); 46 if (!document) 47 return Exception { SECURITY_ERR }; 48 auto* securityOrigin = document->securityOrigin(); 49 if (!securityOrigin) 50 return Exception { SECURITY_ERR }; 51 if (!securityOrigin->canAccessDatabase(document->topOrigin())) 52 return Exception { SECURITY_ERR }; 53 auto error = DatabaseError::None; 54 auto database = manager.openDatabase(window.document(), name, version, displayName, estimatedSize, WTFMove(creationCallback), error); 55 if (error != DatabaseError::None) 56 return Exception { DatabaseManager::exceptionCodeForDatabaseError(error) }; 57 ASSERT(database); 58 return WTFMove(database); 56 59 } 57 60 -
trunk/Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.h
r203146 r207384 25 25 */ 26 26 27 #ifndef DOMWindowWebDatabase_h 28 #define DOMWindowWebDatabase_h 27 #pragma once 29 28 30 #include "ExceptionCode.h" 31 #include <wtf/RefCounted.h> 32 #include <wtf/RefPtr.h> 33 #include <wtf/text/WTFString.h> 29 #include "ExceptionOr.h" 34 30 35 31 namespace WebCore { … … 38 34 class Database; 39 35 class DatabaseCallback; 40 class Frame;41 36 42 37 class DOMWindowWebDatabase { 43 38 public: 44 static RefPtr<Database> openDatabase(DOMWindow&, const String& name, const String& version, const String& displayName, unsigned long estimatedSize, RefPtr<DatabaseCallback>&& creationCallback, ExceptionCode&);39 static ExceptionOr<RefPtr<Database>> openDatabase(DOMWindow&, const String& name, const String& version, const String& displayName, unsigned estimatedSize, RefPtr<DatabaseCallback>&& creationCallback); 45 40 46 41 DOMWindowWebDatabase() = delete; … … 49 44 50 45 } // namespace WebCore 51 52 #endif // DOMWindowWebDatabase_h -
trunk/Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.idl
r206723 r207384 25 25 */ 26 26 27 [ 28 ] partial interface DOMWindow { 29 [MayThrowLegacyException] Database openDatabase(DOMString name, DOMString version, DOMString displayName, unsigned long estimatedSize, optional DatabaseCallback? creationCallback); 27 partial interface DOMWindow { 28 [MayThrowException] Database? openDatabase(DOMString name, DOMString version, DOMString displayName, unsigned long estimatedSize, optional DatabaseCallback? creationCallback); 30 29 }; 31 -
trunk/Source/WebCore/Modules/webdatabase/SQLResultSet.cpp
r178575 r207384 36 36 SQLResultSet::SQLResultSet() 37 37 : m_rows(SQLResultSetRowList::create()) 38 , m_insertId(0)39 , m_insertIdSet(false)40 , m_rowsAffected(0)41 38 { 42 39 } 43 40 44 int64_t SQLResultSet::insertId(ExceptionCode& e) const41 ExceptionOr<int64_t> SQLResultSet::insertId() const 45 42 { 46 43 // 4.11.4 - Return the id of the last row inserted as a result of the query 47 44 // If the query didn't result in any rows being added, raise an INVALID_ACCESS_ERR exception 48 if (m_insertIdSet) 49 return m_insertId; 50 51 e = INVALID_ACCESS_ERR; 52 return -1; 53 } 54 55 int SQLResultSet::rowsAffected() const 56 { 57 return m_rowsAffected; 58 } 59 60 SQLResultSetRowList* SQLResultSet::rows() const 61 { 62 return m_rows.get(); 63 } 64 65 void SQLResultSet::setInsertId(int64_t id) 66 { 67 ASSERT(!m_insertIdSet); 68 69 m_insertId = id; 70 m_insertIdSet = true; 71 } 72 73 void SQLResultSet::setRowsAffected(int count) 74 { 75 m_rowsAffected = count; 45 if (!m_insertId) 46 return Exception { INVALID_ACCESS_ERR }; 47 return m_insertId.value(); 76 48 } 77 49 -
trunk/Source/WebCore/Modules/webdatabase/SQLResultSet.h
r184709 r207384 27 27 */ 28 28 29 #ifndef SQLResultSet_h 30 #define SQLResultSet_h 29 #pragma once 31 30 32 #include " DatabaseBasicTypes.h"31 #include "ExceptionOr.h" 33 32 #include "SQLResultSetRowList.h" 34 33 #include <wtf/ThreadSafeRefCounted.h> … … 40 39 static Ref<SQLResultSet> create() { return adoptRef(*new SQLResultSet); } 41 40 42 SQLResultSetRowList * rows() const;41 SQLResultSetRowList& rows() { return m_rows.get(); } 43 42 44 int64_t insertId(ExceptionCode&) const;45 int rowsAffected() const ;43 ExceptionOr<int64_t> insertId() const; 44 int rowsAffected() const { return m_rowsAffected; } 46 45 47 // For internal (non-JS) use48 46 void setInsertId(int64_t); 49 47 void setRowsAffected(int); … … 52 50 SQLResultSet(); 53 51 54 RefPtr<SQLResultSetRowList> m_rows; 55 int64_t m_insertId; 56 bool m_insertIdSet; 57 int m_rowsAffected; 52 Ref<SQLResultSetRowList> m_rows; 53 Optional<int64_t> m_insertId; 54 int m_rowsAffected { 0 }; 58 55 }; 59 56 57 inline void SQLResultSet::setInsertId(int64_t id) 58 { 59 ASSERT(!m_insertId); 60 m_insertId = id; 61 } 62 63 inline void SQLResultSet::setRowsAffected(int count) 64 { 65 m_rowsAffected = count; 66 } 67 60 68 } // namespace WebCore 61 62 #endif // SQLResultSet_h -
trunk/Source/WebCore/Modules/webdatabase/SQLResultSet.idl
r206723 r207384 31 31 ] interface SQLResultSet { 32 32 readonly attribute SQLResultSetRowList rows; 33 [GetterMayThrow LegacyException] readonly attribute long insertId;33 [GetterMayThrowException] readonly attribute long insertId; 34 34 readonly attribute long rowsAffected; 35 35 }; -
trunk/Source/WebCore/Modules/webdatabase/SQLStatement.cpp
r203146 r207384 155 155 case SQLITE_ROW: { 156 156 int columnCount = statement.columnCount(); 157 SQLResultSetRowList*rows = resultSet->rows();157 auto& rows = resultSet->rows(); 158 158 159 159 for (int i = 0; i < columnCount; i++) 160 rows ->addColumn(statement.getColumnName(i));160 rows.addColumn(statement.getColumnName(i)); 161 161 162 162 do { 163 163 for (int i = 0; i < columnCount; i++) 164 rows ->addResult(statement.getColumnValue(i));164 rows.addResult(statement.getColumnValue(i)); 165 165 166 166 result = statement.step(); -
trunk/Source/WebCore/Modules/websockets/WebSocket.cpp
r206869 r207384 86 86 } 87 87 88 static bool isValidProtocolString( const String&protocol)88 static bool isValidProtocolString(StringView protocol) 89 89 { 90 90 if (protocol.isEmpty()) 91 91 return false; 92 for ( size_t i = 0; i < protocol.length(); ++i) {93 if (!isValidProtocolCharacter( protocol[i]))92 for (auto codeUnit : protocol.codeUnits()) { 93 if (!isValidProtocolCharacter(codeUnit)) 94 94 return false; 95 95 } … … 141 141 } 142 142 143 const char* WebSocket::sub ProtocolSeperator()143 const char* WebSocket::subprotocolSeparator() 144 144 { 145 145 return ", "; … … 148 148 WebSocket::WebSocket(ScriptExecutionContext& context) 149 149 : ActiveDOMObject(&context) 150 , m_state(CONNECTING)151 , m_bufferedAmount(0)152 , m_bufferedAmountAfterClose(0)153 , m_binaryType(BinaryTypeBlob)154 150 , m_subprotocol(emptyString()) 155 151 , m_extensions(emptyString()) … … 164 160 } 165 161 166 Ref<WebSocket> WebSocket::create(ScriptExecutionContext& context) 167 { 168 Ref<WebSocket> webSocket(adoptRef(*new WebSocket(context))); 169 webSocket->suspendIfNeeded(); 170 return webSocket; 171 } 172 173 RefPtr<WebSocket> WebSocket::create(ScriptExecutionContext& context, const String& url, ExceptionCode& ec) 174 { 175 Vector<String> protocols; 176 return WebSocket::create(context, url, protocols, ec); 177 } 178 179 RefPtr<WebSocket> WebSocket::create(ScriptExecutionContext& context, const String& url, const Vector<String>& protocols, ExceptionCode& ec) 180 { 181 if (url.isNull()) { 182 ec = SYNTAX_ERR; 183 return nullptr; 184 } 185 186 RefPtr<WebSocket> webSocket(adoptRef(*new WebSocket(context))); 187 webSocket->suspendIfNeeded(); 188 189 webSocket->connect(context.completeURL(url), protocols, ec); 190 if (ec) 191 return nullptr; 192 193 return webSocket; 194 } 195 196 RefPtr<WebSocket> WebSocket::create(ScriptExecutionContext& context, const String& url, const String& protocol, ExceptionCode& ec) 197 { 198 Vector<String> protocols; 199 protocols.append(protocol); 200 return WebSocket::create(context, url, protocols, ec); 201 } 202 203 void WebSocket::connect(const String& url, ExceptionCode& ec) 204 { 205 Vector<String> protocols; 206 connect(url, protocols, ec); 207 } 208 209 void WebSocket::connect(const String& url, const String& protocol, ExceptionCode& ec) 210 { 211 Vector<String> protocols; 212 protocols.append(protocol); 213 connect(url, protocols, ec); 214 } 215 216 void WebSocket::connect(const String& url, const Vector<String>& protocols, ExceptionCode& ec) 162 ExceptionOr<Ref<WebSocket>> WebSocket::create(ScriptExecutionContext& context, const String& url) 163 { 164 return create(context, url, Vector<String> { }); 165 } 166 167 ExceptionOr<Ref<WebSocket>> WebSocket::create(ScriptExecutionContext& context, const String& url, const Vector<String>& protocols) 168 { 169 if (url.isNull()) 170 return Exception { SYNTAX_ERR }; 171 172 auto socket = adoptRef(*new WebSocket(context)); 173 socket->suspendIfNeeded(); 174 175 auto result = socket->connect(context.completeURL(url), protocols); 176 if (result.hasException()) 177 return result.releaseException(); 178 179 return WTFMove(socket); 180 } 181 182 ExceptionOr<Ref<WebSocket>> WebSocket::create(ScriptExecutionContext& context, const String& url, const String& protocol) 183 { 184 return create(context, url, Vector<String> { 1, protocol }); 185 } 186 187 ExceptionOr<void> WebSocket::connect(const String& url) 188 { 189 return connect(url, Vector<String> { }); 190 } 191 192 ExceptionOr<void> WebSocket::connect(const String& url, const String& protocol) 193 { 194 return connect(url, Vector<String> { 1, protocol }); 195 } 196 197 ExceptionOr<void> WebSocket::connect(const String& url, const Vector<String>& protocols) 217 198 { 218 199 LOG(Network, "WebSocket %p connect() url='%s'", this, url.utf8().data()); … … 225 206 context.addConsoleMessage(MessageSource::JS, MessageLevel::Error, "Invalid url for WebSocket " + m_url.stringCenterEllipsizedToLength()); 226 207 m_state = CLOSED; 227 ec = SYNTAX_ERR; 228 return; 208 return Exception { SYNTAX_ERR }; 229 209 } 230 210 … … 232 212 context.addConsoleMessage(MessageSource::JS, MessageLevel::Error, "Wrong url scheme for WebSocket " + m_url.stringCenterEllipsizedToLength()); 233 213 m_state = CLOSED; 234 ec = SYNTAX_ERR; 235 return; 214 return Exception { SYNTAX_ERR }; 236 215 } 237 216 if (m_url.hasFragmentIdentifier()) { 238 217 context.addConsoleMessage(MessageSource::JS, MessageLevel::Error, "URL has fragment component " + m_url.stringCenterEllipsizedToLength()); 239 218 m_state = CLOSED; 240 ec = SYNTAX_ERR; 241 return; 219 return Exception { SYNTAX_ERR }; 242 220 } 243 221 … … 250 228 context.addConsoleMessage(MessageSource::JS, MessageLevel::Error, "WebSocket port " + String::number(m_url.port()) + " blocked"); 251 229 m_state = CLOSED; 252 ec = SECURITY_ERR; 253 return; 230 return Exception { SECURITY_ERR }; 254 231 } 255 232 … … 259 236 260 237 // FIXME: Should this be throwing an exception? 261 ec = SECURITY_ERR; 262 return; 238 return Exception { SECURITY_ERR }; 263 239 } 264 240 … … 280 256 context.addConsoleMessage(MessageSource::JS, MessageLevel::Error, "Wrong protocol for WebSocket '" + encodeProtocolString(protocol) + "'"); 281 257 m_state = CLOSED; 282 ec = SYNTAX_ERR; 283 return; 258 return Exception { SYNTAX_ERR }; 284 259 } 285 260 } … … 289 264 context.addConsoleMessage(MessageSource::JS, MessageLevel::Error, "WebSocket protocols contain duplicates: '" + encodeProtocolString(protocol) + "'"); 290 265 m_state = CLOSED; 291 ec = SYNTAX_ERR; 292 return; 266 return Exception { SYNTAX_ERR }; 293 267 } 294 268 } … … 319 293 }); 320 294 #endif 321 return ;295 return { }; 322 296 } else 323 297 ResourceLoadObserver::sharedObserver().logWebSocketLoading(document.frame(), m_url); … … 326 300 String protocolString; 327 301 if (!protocols.isEmpty()) 328 protocolString = joinStrings(protocols, sub ProtocolSeperator());302 protocolString = joinStrings(protocols, subprotocolSeparator()); 329 303 330 304 m_channel->connect(m_url, protocolString); 331 305 ActiveDOMObject::setPendingActivity(this); 332 } 333 334 void WebSocket::send(const String& message, ExceptionCode& ec) 306 307 return { }; 308 } 309 310 ExceptionOr<void> WebSocket::send(const String& message) 335 311 { 336 312 LOG(Network, "WebSocket %p send() Sending String '%s'", this, message.utf8().data()); 337 if (m_state == CONNECTING) { 338 ec = INVALID_STATE_ERR; 339 return; 340 } 313 if (m_state == CONNECTING) 314 return Exception { INVALID_STATE_ERR }; 341 315 // No exception is raised if the connection was once established but has subsequently been closed. 342 316 if (m_state == CLOSING || m_state == CLOSED) { … … 344 318 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, payloadSize); 345 319 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFramingOverhead(payloadSize)); 346 return ;320 return { }; 347 321 } 348 322 ASSERT(m_channel); 349 323 m_channel->send(message); 350 } 351 352 void WebSocket::send(ArrayBuffer& binaryData, ExceptionCode& ec) 324 return { }; 325 } 326 327 ExceptionOr<void> WebSocket::send(ArrayBuffer& binaryData) 353 328 { 354 329 LOG(Network, "WebSocket %p send() Sending ArrayBuffer %p", this, &binaryData); 355 if (m_state == CONNECTING) { 356 ec = INVALID_STATE_ERR; 357 return; 358 } 330 if (m_state == CONNECTING) 331 return Exception { INVALID_STATE_ERR }; 359 332 if (m_state == CLOSING || m_state == CLOSED) { 360 333 unsigned payloadSize = binaryData.byteLength(); 361 334 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, payloadSize); 362 335 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFramingOverhead(payloadSize)); 363 return ;336 return { }; 364 337 } 365 338 ASSERT(m_channel); 366 339 m_channel->send(binaryData, 0, binaryData.byteLength()); 367 } 368 369 void WebSocket::send(ArrayBufferView& arrayBufferView, ExceptionCode& ec) 340 return { }; 341 } 342 343 ExceptionOr<void> WebSocket::send(ArrayBufferView& arrayBufferView) 370 344 { 371 345 LOG(Network, "WebSocket %p send() Sending ArrayBufferView %p", this, &arrayBufferView); 372 346 373 if (m_state == CONNECTING) { 374 ec = INVALID_STATE_ERR; 375 return; 376 } 347 if (m_state == CONNECTING) 348 return Exception { INVALID_STATE_ERR }; 377 349 if (m_state == CLOSING || m_state == CLOSED) { 378 350 unsigned payloadSize = arrayBufferView.byteLength(); 379 351 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, payloadSize); 380 352 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFramingOverhead(payloadSize)); 381 return ;353 return { }; 382 354 } 383 355 ASSERT(m_channel); 384 356 m_channel->send(*arrayBufferView.buffer(), arrayBufferView.byteOffset(), arrayBufferView.byteLength()); 385 } 386 387 void WebSocket::send(Blob& binaryData, ExceptionCode& ec) 357 return { }; 358 } 359 360 ExceptionOr<void> WebSocket::send(Blob& binaryData) 388 361 { 389 362 LOG(Network, "WebSocket %p send() Sending Blob '%s'", this, binaryData.url().stringCenterEllipsizedToLength().utf8().data()); 390 if (m_state == CONNECTING) { 391 ec = INVALID_STATE_ERR; 392 return; 393 } 363 if (m_state == CONNECTING) 364 return Exception { INVALID_STATE_ERR }; 394 365 if (m_state == CLOSING || m_state == CLOSED) { 395 366 unsigned payloadSize = static_cast<unsigned>(binaryData.size()); 396 367 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, payloadSize); 397 368 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFramingOverhead(payloadSize)); 398 return ;369 return { }; 399 370 } 400 371 ASSERT(m_channel); 401 372 m_channel->send(binaryData); 402 } 403 404 void WebSocket::close(Optional<unsigned short> optionalCode, const String& reason, ExceptionCode& ec) 373 return { }; 374 } 375 376 ExceptionOr<void> WebSocket::close(Optional<unsigned short> optionalCode, const String& reason) 405 377 { 406 378 int code = optionalCode ? optionalCode.value() : static_cast<int>(WebSocketChannel::CloseEventCodeNotSpecified); … … 409 381 else { 410 382 LOG(Network, "WebSocket %p close() code=%d reason='%s'", this, code, reason.utf8().data()); 411 if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocketChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel::CloseEventCodeMaximumUserDefined))) { 412 ec = INVALID_ACCESS_ERR; 413 return; 414 } 383 if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocketChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel::CloseEventCodeMaximumUserDefined))) 384 return Exception { INVALID_ACCESS_ERR }; 415 385 CString utf8 = reason.utf8(StrictConversionReplacingUnpairedSurrogatesWithFFFD); 416 386 if (utf8.length() > maxReasonSizeInBytes) { 417 387 scriptExecutionContext()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("WebSocket close message is too long.")); 418 ec = SYNTAX_ERR; 419 return; 388 return Exception { SYNTAX_ERR }; 420 389 } 421 390 } 422 391 423 392 if (m_state == CLOSING || m_state == CLOSED) 424 return ;393 return { }; 425 394 if (m_state == CONNECTING) { 426 395 m_state = CLOSING; 427 396 m_channel->fail("WebSocket is closed before the connection is established."); 428 return ;397 return { }; 429 398 } 430 399 m_state = CLOSING; 431 400 if (m_channel) 432 401 m_channel->close(code, reason); 402 return { }; 433 403 } 434 404 … … 461 431 { 462 432 switch (m_binaryType) { 463 case BinaryType Blob:433 case BinaryType::Blob: 464 434 return ASCIILiteral("blob"); 465 case BinaryType ArrayBuffer:435 case BinaryType::ArrayBuffer: 466 436 return ASCIILiteral("arraybuffer"); 467 437 } … … 470 440 } 471 441 472 void WebSocket::setBinaryType(const String& binaryType, ExceptionCode& ec)442 ExceptionOr<void> WebSocket::setBinaryType(const String& binaryType) 473 443 { 474 444 if (binaryType == "blob") { 475 m_binaryType = BinaryType Blob;476 return ;445 m_binaryType = BinaryType::Blob; 446 return { }; 477 447 } 478 448 if (binaryType == "arraybuffer") { 479 m_binaryType = BinaryTypeArrayBuffer; 480 return; 481 } 482 ec = SYNTAX_ERR; 449 m_binaryType = BinaryType::ArrayBuffer; 450 return { }; 451 } 483 452 scriptExecutionContext()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, "'" + binaryType + "' is not a valid value for binaryType; binaryType remains unchanged."); 453 return Exception { SYNTAX_ERR }; 484 454 } 485 455 … … 592 562 LOG(Network, "WebSocket %p didReceiveBinaryData() %u byte binary message", this, static_cast<unsigned>(binaryData.size())); 593 563 switch (m_binaryType) { 594 case BinaryType Blob:564 case BinaryType::Blob: 595 565 // FIXME: We just received the data from NetworkProcess, and are sending it back. This is inefficient. 596 566 dispatchEvent(MessageEvent::create(Blob::create(WTFMove(binaryData), emptyString()), SecurityOrigin::create(m_url)->toString())); 597 567 break; 598 case BinaryType ArrayBuffer:568 case BinaryType::ArrayBuffer: 599 569 dispatchEvent(MessageEvent::create(ArrayBuffer::create(binaryData.data(), binaryData.size()), SecurityOrigin::create(m_url)->toString())); 600 570 break; -
trunk/Source/WebCore/Modules/websockets/WebSocket.h
r204127 r207384 29 29 */ 30 30 31 #ifndef WebSocket_h 32 #define WebSocket_h 31 #pragma once 33 32 34 33 #if ENABLE(WEB_SOCKETS) 35 34 36 35 #include "ActiveDOMObject.h" 37 #include "EventListener.h"38 36 #include "EventTarget.h" 37 #include "ExceptionOr.h" 38 #include "Timer.h" 39 39 #include "URL.h" 40 #include "WebSocketChannel.h"41 40 #include "WebSocketChannelClient.h" 42 #include <wtf/Forward.h> 43 #include <wtf/RefCounted.h> 44 #include <wtf/text/AtomicStringHash.h> 41 #include <wtf/Deque.h> 42 43 namespace JSC { 44 class ArrayBuffer; 45 class ArrayBufferView; 46 } 45 47 46 48 namespace WebCore { 47 49 48 50 class Blob; 49 class CloseEvent;50 51 class ThreadableWebSocketChannel; 51 52 52 class WebSocket final : public RefCounted<WebSocket>, public EventTargetWithInlineData, public ActiveDOMObject, p ublicWebSocketChannelClient {53 class WebSocket final : public RefCounted<WebSocket>, public EventTargetWithInlineData, public ActiveDOMObject, private WebSocketChannelClient { 53 54 public: 54 55 static void setIsAvailable(bool); 55 56 static bool isAvailable(); 56 static const char* subProtocolSeperator(); 57 static Ref<WebSocket> create(ScriptExecutionContext&); 58 static RefPtr<WebSocket> create(ScriptExecutionContext&, const String& url, ExceptionCode&); 59 static RefPtr<WebSocket> create(ScriptExecutionContext&, const String& url, const String& protocol, ExceptionCode&); 60 static RefPtr<WebSocket> create(ScriptExecutionContext&, const String& url, const Vector<String>& protocols, ExceptionCode&); 57 58 static const char* subprotocolSeparator(); 59 60 static ExceptionOr<Ref<WebSocket>> create(ScriptExecutionContext&, const String& url); 61 static ExceptionOr<Ref<WebSocket>> create(ScriptExecutionContext&, const String& url, const String& protocol); 62 static ExceptionOr<Ref<WebSocket>> create(ScriptExecutionContext&, const String& url, const Vector<String>& protocols); 61 63 virtual ~WebSocket(); 62 64 … … 68 70 }; 69 71 70 void connect(const String& url, ExceptionCode&);71 void connect(const String& url, const String& protocol, ExceptionCode&);72 void connect(const String& url, const Vector<String>& protocols, ExceptionCode&);72 ExceptionOr<void> connect(const String& url); 73 ExceptionOr<void> connect(const String& url, const String& protocol); 74 ExceptionOr<void> connect(const String& url, const Vector<String>& protocols); 73 75 74 void send(const String& message, ExceptionCode&);75 void send(JSC::ArrayBuffer&, ExceptionCode&);76 void send(JSC::ArrayBufferView&, ExceptionCode&);77 void send(Blob&, ExceptionCode&);76 ExceptionOr<void> send(const String& message); 77 ExceptionOr<void> send(JSC::ArrayBuffer&); 78 ExceptionOr<void> send(JSC::ArrayBufferView&); 79 ExceptionOr<void> send(Blob&); 78 80 79 void close(Optional<unsigned short> code, const String& reason, ExceptionCode&);81 ExceptionOr<void> close(Optional<unsigned short> code, const String& reason); 80 82 81 83 const URL& url() const; … … 87 89 88 90 String binaryType() const; 89 void setBinaryType(const String&, ExceptionCode&);91 ExceptionOr<void> setBinaryType(const String&); 90 92 91 // EventTarget functions. 92 EventTargetInterface eventTargetInterface() const override; 93 ScriptExecutionContext* scriptExecutionContext() const override; 93 using RefCounted::ref; 94 using RefCounted::deref; 94 95 95 using RefCounted<WebSocket>::ref; 96 using RefCounted<WebSocket>::deref;96 private: 97 explicit WebSocket(ScriptExecutionContext&); 97 98 98 // WebSocketChannelClient functions. 99 void resumeTimerFired(); 100 void dispatchOrQueueErrorEvent(); 101 void dispatchOrQueueEvent(Ref<Event>&&); 102 103 void contextDestroyed() final; 104 bool canSuspendForDocumentSuspension() const final; 105 void suspend(ReasonForSuspension) final; 106 void resume() final; 107 void stop() final; 108 const char* activeDOMObjectName() const final; 109 110 EventTargetInterface eventTargetInterface() const final; 111 ScriptExecutionContext* scriptExecutionContext() const final; 112 113 void refEventTarget() final { ref(); } 114 void derefEventTarget() final { deref(); } 115 99 116 void didConnect() final; 100 117 void didReceiveMessage(const String& message) final; … … 106 123 void didUpgradeURL() final; 107 124 108 private:109 explicit WebSocket(ScriptExecutionContext&);110 111 void resumeTimerFired();112 void dispatchOrQueueErrorEvent();113 void dispatchOrQueueEvent(Ref<Event>&&);114 115 // ActiveDOMObject API.116 void contextDestroyed() override;117 bool canSuspendForDocumentSuspension() const override;118 void suspend(ReasonForSuspension) override;119 void resume() override;120 void stop() override;121 const char* activeDOMObjectName() const override;122 123 void refEventTarget() override { ref(); }124 void derefEventTarget() override { deref(); }125 126 125 size_t getFramingOverhead(size_t payloadSize); 127 126 128 enum BinaryType { 129 BinaryTypeBlob, 130 BinaryTypeArrayBuffer 131 }; 127 enum class BinaryType { Blob, ArrayBuffer }; 132 128 133 129 RefPtr<ThreadableWebSocketChannel> m_channel; 134 130 135 State m_state ;131 State m_state { CONNECTING }; 136 132 URL m_url; 137 unsigned m_bufferedAmount ;138 unsigned m_bufferedAmountAfterClose ;139 BinaryType m_binaryType ;133 unsigned m_bufferedAmount { 0 }; 134 unsigned m_bufferedAmountAfterClose { 0 }; 135 BinaryType m_binaryType { BinaryType::Blob }; 140 136 String m_subprotocol; 141 137 String m_extensions; … … 150 146 151 147 #endif // ENABLE(WEB_SOCKETS) 152 153 #endif // WebSocket_h -
trunk/Source/WebCore/Modules/websockets/WebSocket.idl
r206723 r207384 35 35 Constructor(USVString url, optional sequence<DOMString> protocols = []), 36 36 Constructor(USVString url, DOMString protocol), 37 ConstructorMayThrow LegacyException,37 ConstructorMayThrowException, 38 38 ConstructorCallWith=ScriptExecutionContext, 39 39 EnabledAtRuntime, … … 43 43 readonly attribute USVString url; 44 44 45 // ready state46 45 const unsigned short CONNECTING = 0; 47 46 const unsigned short OPEN = 1; … … 52 51 readonly attribute unsigned long bufferedAmount; 53 52 54 // networking55 53 attribute EventHandler onopen; 56 54 attribute EventHandler onmessage; … … 61 59 readonly attribute DOMString? extensions; 62 60 63 [SetterMayThrow LegacyException] attribute DOMString binaryType;61 [SetterMayThrowException] attribute DOMString binaryType; 64 62 65 [MayThrow LegacyException] void send(ArrayBuffer data);66 [MayThrow LegacyException] void send(ArrayBufferView data);67 [MayThrow LegacyException] void send(Blob data);68 [MayThrow LegacyException] void send(USVString data);63 [MayThrowException] void send(ArrayBuffer data); 64 [MayThrowException] void send(ArrayBufferView data); 65 [MayThrowException] void send(Blob data); 66 [MayThrowException] void send(USVString data); 69 67 70 [MayThrow LegacyException] void close([Clamp] optional unsigned short code, optional DOMString reason);68 [MayThrowException] void close([Clamp] optional unsigned short code, optional DOMString reason); 71 69 }; -
trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp
r204702 r207384 606 606 } 607 607 Vector<String> result; 608 m_clientProtocol.split( String(WebSocket::subProtocolSeperator()), result);608 m_clientProtocol.split(WebSocket::subprotocolSeparator(), result); 609 609 if (!result.contains(serverWebSocketProtocol)) { 610 610 m_failureReason = ASCIILiteral("Error during WebSocket handshake: Sec-WebSocket-Protocol mismatch"); -
trunk/Source/WebCore/dom/ExceptionOr.h
r206960 r207384 37 37 ExceptionOr(Exception&&); 38 38 ExceptionOr(ReturnType&&); 39 template<typename OtherType> ExceptionOr(const OtherType&, typename std::enable_if<std::is_scalar<OtherType>::value && std::is_convertible<OtherType, ReturnType>::value>::type* = nullptr); 39 40 40 41 bool hasException() const; … … 65 66 template<typename ReturnType> inline ExceptionOr<ReturnType>::ExceptionOr(ReturnType&& returnValue) 66 67 : m_value(WTFMove(returnValue)) 68 { 69 } 70 71 template<typename ReturnType> template<typename OtherType> inline ExceptionOr<ReturnType>::ExceptionOr(const OtherType& returnValue, typename std::enable_if<std::is_scalar<OtherType>::value && std::is_convertible<OtherType, ReturnType>::value>::type*) 72 : m_value(static_cast<ReturnType>(returnValue)) 67 73 { 68 74 } -
trunk/Source/WebCore/inspector/InspectorDatabaseAgent.cpp
r199320 r207384 78 78 bool handleEvent(SQLTransaction*, SQLResultSet* resultSet) override 79 79 { 80 SQLResultSetRowList*rowList = resultSet->rows();80 auto& rowList = resultSet->rows(); 81 81 82 82 auto columnNames = Inspector::Protocol::Array<String>::create(); 83 for (auto& column : rowList ->columnNames())83 for (auto& column : rowList.columnNames()) 84 84 columnNames->addItem(column); 85 85 86 86 auto values = Inspector::Protocol::Array<InspectorValue>::create(); 87 for (auto& value : rowList ->values()) {87 for (auto& value : rowList.values()) { 88 88 RefPtr<InspectorValue> inspectorValue; 89 89 switch (value.type()) { -
trunk/Source/WebCore/page/DOMWindow.idl
r206877 r207384 1 1 /* 2 * Copyright (C) 2006 , 2007, 2008, 2009, 2013Apple Inc. All rights reserved.2 * Copyright (C) 2006-2016 Apple Inc. All rights reserved. 3 3 * Copyright (C) 2011 Google Inc. All rights reserved. 4 4 * … … 42 42 JSLegacyParent=JSDOMWindowBase, 43 43 ] interface DOMWindow : EventTarget { 44 // DOM Level 045 44 [Replaceable] readonly attribute Screen screen; 46 45 readonly attribute History history; … … 77 76 78 77 // FIXME: Using "undefined" as default parameter value is wrong. 79 boolean find(optional DOMString string = "undefined", 80 optional boolean caseSensitive = false, 81 optional boolean backwards = false, 82 optional boolean wrap = false, 83 optional boolean wholeWord = false, 84 optional boolean searchInFrames = false, 85 optional boolean showDialog = false); 78 boolean find(optional DOMString string = "undefined", optional boolean caseSensitive = false, optional boolean backwards = false, optional boolean wrap = false, optional boolean wholeWord = false, optional boolean searchInFrames = false, optional boolean showDialog = false); 86 79 87 80 [Replaceable] readonly attribute boolean offscreenBuffering; … … 109 102 [ImplementedAs=scrollTo] void scroll(optional ScrollToOptions options); 110 103 111 void moveBy(optional unrestricted float x = NaN, optional unrestricted float y = NaN); // FIXME: this should take longsnot floats.112 void moveTo(optional unrestricted float x = NaN, optional unrestricted float y = NaN); // FIXME: this should take longsnot floats.113 void resizeBy(optional unrestricted float x = NaN, optional unrestricted float y = NaN); // FIXME: this should take longsnot floats.114 void resizeTo(optional unrestricted float width = NaN, optional unrestricted float height = NaN); // FIXME: this should take longsnot floats.104 void moveBy(optional unrestricted float x = NaN, optional unrestricted float y = NaN); // FIXME: This should take longs, not floats. 105 void moveTo(optional unrestricted float x = NaN, optional unrestricted float y = NaN); // FIXME: This should take longs, not floats. 106 void resizeBy(optional unrestricted float x = NaN, optional unrestricted float y = NaN); // FIXME: This should take longs, not floats. 107 void resizeTo(optional unrestricted float width = NaN, optional unrestricted float height = NaN); // FIXME: This should take longs, not floats. 115 108 116 109 [DoNotCheckSecurity, ForwardDeclareInHeader] readonly attribute boolean closed; … … 122 115 attribute DOMString status; 123 116 attribute DOMString defaultStatus; 124 // This attribute is an alias of defaultStatus and is necessary for legacy uses. 125 [ImplementedAs=defaultStatus] attribute DOMString defaultstatus; 117 [ImplementedAs=defaultStatus] attribute DOMString defaultstatus; // For compatibility with legacy content. 126 118 127 // Self referential attributes128 119 [Replaceable, DoNotCheckSecurityOnGetter] readonly attribute DOMWindow self; 129 120 [DoNotCheckSecurity, Unforgeable] readonly attribute DOMWindow window; … … 134 125 [DoNotCheckSecurityOnGetter, Unforgeable] readonly attribute DOMWindow top; 135 126 136 // DOM Level 2 AbstractView Interface137 127 [Unforgeable] readonly attribute Document document; 138 128 139 // CSSOM View Module140 129 MediaQueryList matchMedia(DOMString query); 141 130 142 // styleMedia has been removed from the CSSOM View specification. 143 readonly attribute StyleMedia styleMedia; 131 readonly attribute StyleMedia styleMedia; // Keeping for now, but styleMedia has been removed from the CSSOM View specification. 144 132 145 // DOM Level 2 Style Interface146 133 [NewObject] CSSStyleDeclaration getComputedStyle(Element element, optional DOMString? pseudoElement = null); 147 // FIXME: Drop this overload once <rdar://problem/28016778> has been fixed. 134 135 // FIXME: Drop the following overload of getComputedStyle once <rdar://problem/28020681> has been fixed. 148 136 [NewObject, MayThrowLegacyException] CSSStyleDeclaration getComputedStyle(Document document, optional DOMString? pseudoElement = null); 149 137 150 // WebKit extensions151 138 CSSRuleList getMatchedCSSRules(optional Element? element = null, optional DOMString? pseudoElement = null); 152 139 153 140 [Replaceable] readonly attribute unrestricted double devicePixelRatio; 154 141 155 WebKitPoint webkitConvertPointFromPageToNode(optional Node? node = null, 156 optional WebKitPoint? p = null); 157 WebKitPoint webkitConvertPointFromNodeToPage(optional Node? node = null, 158 optional WebKitPoint? p = null); 142 WebKitPoint webkitConvertPointFromPageToNode(optional Node? node = null, optional WebKitPoint? p = null); 143 WebKitPoint webkitConvertPointFromNodeToPage(optional Node? node = null, optional WebKitPoint? p = null); 159 144 160 145 readonly attribute DOMApplicationCache applicationCache; … … 163 148 [GetterMayThrowLegacyException] readonly attribute Storage localStorage; 164 149 165 // This is the interface orientation in degrees. Some examples are: 166 // 0 is straight up; -90 is when the device is rotated 90 clockwise; 167 // 90 is when rotated counter clockwise. 150 // This is the interface orientation in degrees. Some examples: 151 // 0 when straight up; -90 when rotated 90 degrees clockwise; 90 counter clockwise. 168 152 [Conditional=ORIENTATION_EVENTS] readonly attribute long orientation; 169 153 170 // cross-document messaging171 154 [DoNotCheckSecurity, Custom, MayThrowLegacyException, ForwardDeclareInHeader] void postMessage(SerializedScriptValue message, USVString targetOrigin, optional Array messagePorts); 172 155 … … 179 162 [Conditional=REQUEST_ANIMATION_FRAME, ImplementedAs=cancelAnimationFrame] void webkitCancelRequestAnimationFrame(long id); // This is a deprecated alias for webkitCancelAnimationFrame(). Remove this when removing vendor prefix. 180 163 181 void captureEvents( /*in long eventFlags*/);182 void releaseEvents( /*in long eventFlags*/);164 void captureEvents(); // Not implemented. Also not in modern standards. Empty function may help compatibility with legacy content. 165 void releaseEvents(); // Not implemented. Also not in modern standards. Empty function may help compatibility with legacy content. 183 166 184 [CustomGetter, CustomConstructor] attribute HTMLImageElementNamedConstructor Image; // Usable with new operator167 [CustomGetter, CustomConstructor] attribute HTMLImageElementNamedConstructor Image; 185 168 attribute XMLDocumentConstructor SVGDocument; 186 169 187 attribute DOMURLConstructor webkitURL; // FIXME: deprecate this.188 attribute MutationObserverConstructor WebKitMutationObserver; // FIXME: Add metrics to determine when we can remove this.170 attribute DOMURLConstructor webkitURL; // FIXME: Deprecate this. 171 attribute MutationObserverConstructor WebKitMutationObserver; // FIXME: Remove once we prove it is not needed for compatibility with legacy content. 189 172 190 173 [Conditional=CUSTOM_ELEMENTS, EnabledAtRuntime=CustomElements, ImplementedAs=ensureCustomElementRegistry] readonly attribute CustomElementRegistry customElements; 191 174 192 // Event Handlers 193 194 // Unique to Element and DOMWindow 175 // Event handlers unique to Element and DOMWindow. 195 176 // FIXME: Should these be exposed on Document as well (and therefore moved to GlobalEventHandlers.idl)? 196 177 [NotEnumerable] attribute EventHandler onanimationend; … … 206 187 [NotEnumerable, Conditional=IOS_GESTURE_EVENTS] attribute EventHandler ongesturestart; 207 188 208 // Unique to DOMWindow189 // Event handlers unique to DOMWindow. 209 190 [NotEnumerable, Conditional=DEVICE_ORIENTATION] attribute EventHandler ondevicemotion; 210 191 [NotEnumerable, Conditional=DEVICE_ORIENTATION] attribute EventHandler ondeviceorientation;
Note: See TracChangeset
for help on using the changeset viewer.