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

Side by Side Diff: Source/modules/websockets/MainThreadWebSocketChannel.cpp

Issue 14071008: WebSocket object should fire error event when WebSocket server can't be connected. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Add new layouttests into TestExceptions because it depends on chromium side patch Created 7 years, 8 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
« no previous file with comments | « Source/modules/websockets/MainThreadWebSocketChannel.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 namespace WebCore { 69 namespace WebCore {
70 70
71 const double TCPMaximumSegmentLifetime = 2 * 60.0; 71 const double TCPMaximumSegmentLifetime = 2 * 60.0;
72 72
73 MainThreadWebSocketChannel::MainThreadWebSocketChannel(Document* document, WebSo cketChannelClient* client) 73 MainThreadWebSocketChannel::MainThreadWebSocketChannel(Document* document, WebSo cketChannelClient* client)
74 : m_document(document) 74 : m_document(document)
75 , m_client(client) 75 , m_client(client)
76 , m_resumeTimer(this, &MainThreadWebSocketChannel::resumeTimerFired) 76 , m_resumeTimer(this, &MainThreadWebSocketChannel::resumeTimerFired)
77 , m_suspended(false) 77 , m_suspended(false)
78 , m_closing(false) 78 , m_closing(false)
79 , m_didFailOfClientAlreadyRun(false)
79 , m_receivedClosingHandshake(false) 80 , m_receivedClosingHandshake(false)
80 , m_closingTimer(this, &MainThreadWebSocketChannel::closingTimerFired) 81 , m_closingTimer(this, &MainThreadWebSocketChannel::closingTimerFired)
81 , m_closed(false) 82 , m_closed(false)
82 , m_shouldDiscardReceivedData(false) 83 , m_shouldDiscardReceivedData(false)
83 , m_unhandledBufferedAmount(0) 84 , m_unhandledBufferedAmount(0)
84 , m_identifier(0) 85 , m_identifier(0)
85 , m_hasContinuousFrame(false) 86 , m_hasContinuousFrame(false)
86 , m_closeEventCode(CloseEventCodeAbnormalClosure) 87 , m_closeEventCode(CloseEventCodeAbnormalClosure)
87 , m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen) 88 , m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen)
88 , m_blobLoaderStatus(BlobLoaderNotStarted) 89 , m_blobLoaderStatus(BlobLoaderNotStarted)
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 201
201 // Hybi-10 specification explicitly states we must not continue to handle in coming data 202 // Hybi-10 specification explicitly states we must not continue to handle in coming data
202 // once the WebSocket connection is failed (section 7.1.7). 203 // once the WebSocket connection is failed (section 7.1.7).
203 RefPtr<MainThreadWebSocketChannel> protect(this); // The client can close th e channel, potentially removing the last reference. 204 RefPtr<MainThreadWebSocketChannel> protect(this); // The client can close th e channel, potentially removing the last reference.
204 m_shouldDiscardReceivedData = true; 205 m_shouldDiscardReceivedData = true;
205 if (!m_buffer.isEmpty()) 206 if (!m_buffer.isEmpty())
206 skipBuffer(m_buffer.size()); // Save memory. 207 skipBuffer(m_buffer.size()); // Save memory.
207 m_deflateFramer.didFail(); 208 m_deflateFramer.didFail();
208 m_hasContinuousFrame = false; 209 m_hasContinuousFrame = false;
209 m_continuousFrameData.clear(); 210 m_continuousFrameData.clear();
210 m_client->didReceiveMessageError(); 211 if (!m_didFailOfClientAlreadyRun) {
211 212 m_didFailOfClientAlreadyRun = true;
213 if (m_client)
214 m_client->didReceiveMessageError();
215 }
212 if (m_handle && !m_closed) 216 if (m_handle && !m_closed)
213 m_handle->disconnect(); // Will call didClose(). 217 m_handle->disconnect(); // Will call didCloseSocketStream().
214 } 218 }
215 219
216 void MainThreadWebSocketChannel::disconnect() 220 void MainThreadWebSocketChannel::disconnect()
217 { 221 {
218 LOG(Network, "MainThreadWebSocketChannel %p disconnect()", this); 222 LOG(Network, "MainThreadWebSocketChannel %p disconnect()", this);
219 if (m_identifier && m_document) 223 if (m_identifier && m_document)
220 InspectorInstrumentation::didCloseWebSocket(m_document, m_identifier); 224 InspectorInstrumentation::didCloseWebSocket(m_document, m_identifier);
221 if (m_handshake) 225 if (m_handshake)
222 m_handshake->clearScriptExecutionContext(); 226 m_handshake->clearScriptExecutionContext();
223 m_client = 0; 227 m_client = 0;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 318
315 void MainThreadWebSocketChannel::didUpdateBufferedAmount(SocketStreamHandle*, si ze_t bufferedAmount) 319 void MainThreadWebSocketChannel::didUpdateBufferedAmount(SocketStreamHandle*, si ze_t bufferedAmount)
316 { 320 {
317 if (m_client) 321 if (m_client)
318 m_client->didUpdateBufferedAmount(bufferedAmount); 322 m_client->didUpdateBufferedAmount(bufferedAmount);
319 } 323 }
320 324
321 void MainThreadWebSocketChannel::didFailSocketStream(SocketStreamHandle* handle, const SocketStreamError& error) 325 void MainThreadWebSocketChannel::didFailSocketStream(SocketStreamHandle* handle, const SocketStreamError& error)
322 { 326 {
323 LOG(Network, "MainThreadWebSocketChannel %p didFailSocketStream()", this); 327 LOG(Network, "MainThreadWebSocketChannel %p didFailSocketStream()", this);
324 ASSERT(handle == m_handle || !m_handle); 328 ASSERT_UNUSED(handle, handle == m_handle || !m_handle);
325 if (m_document) { 329 m_shouldDiscardReceivedData = true;
326 String message; 330 String message;
327 if (error.isNull()) 331 if (error.isNull())
328 message = "WebSocket network error"; 332 message = "WebSocket network error";
329 else if (error.localizedDescription().isNull()) 333 else if (error.localizedDescription().isNull())
330 message = "WebSocket network error: error code " + String::number(er ror.errorCode()); 334 message = "WebSocket network error: error code " + String::number(error. errorCode());
331 else 335 else
332 message = "WebSocket network error: " + error.localizedDescription() ; 336 message = "WebSocket network error: error code " + String::number(error. errorCode()) + ", " + error.localizedDescription();
333 InspectorInstrumentation::didReceiveWebSocketFrameError(m_document, m_id entifier, message); 337 String failingURL = error.failingURL();
334 m_document->addConsoleMessage(NetworkMessageSource, ErrorMessageLevel, m essage); 338 ASSERT(failingURL.isNull() || m_handshake->url().string() == failingURL);
339 if (failingURL.isNull())
340 failingURL = m_handshake->url().string();
341 LOG(Network, "Error Message: '%s', FailURL: '%s'", message.utf8().data(), fa ilingURL.utf8().data());
342 RefPtr<WebSocketChannel> protect(this);
343 if (m_client && !m_didFailOfClientAlreadyRun) {
344 m_didFailOfClientAlreadyRun = true;
345 m_client->didReceiveMessageError();
335 } 346 }
336 m_shouldDiscardReceivedData = true; 347 if (m_handle && !m_closed)
337 handle->disconnect(); 348 m_handle->disconnect();
338 } 349 }
339 350
340 void MainThreadWebSocketChannel::didStartLoading() 351 void MainThreadWebSocketChannel::didStartLoading()
341 { 352 {
342 LOG(Network, "MainThreadWebSocketChannel %p didStartLoading()", this); 353 LOG(Network, "MainThreadWebSocketChannel %p didStartLoading()", this);
343 ASSERT(m_blobLoader); 354 ASSERT(m_blobLoader);
344 ASSERT(m_blobLoaderStatus == BlobLoaderStarted); 355 ASSERT(m_blobLoaderStatus == BlobLoaderStarted);
345 } 356 }
346 357
347 void MainThreadWebSocketChannel::didReceiveData() 358 void MainThreadWebSocketChannel::didReceiveData()
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 return false; 793 return false;
783 } 794 }
784 795
785 Vector<char> frameData; 796 Vector<char> frameData;
786 frame.makeFrameData(frameData); 797 frame.makeFrameData(frameData);
787 798
788 return m_handle->send(frameData.data(), frameData.size()); 799 return m_handle->send(frameData.data(), frameData.size());
789 } 800 }
790 801
791 } // namespace WebCore 802 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/websockets/MainThreadWebSocketChannel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698