summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorricea@chromium.org <ricea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-10 13:16:16 +0000
committerricea@chromium.org <ricea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-10 13:16:16 +0000
commit86ec5550eb81c98bdebe8f61dfe13c2ee24b2b96 (patch)
tree957b761793127c6395ee31534688dc998f664559 /net
parente802c0f7ebdf5984007bec3e4bb6512d124e993e (diff)
downloadchromium_src-86ec5550eb81c98bdebe8f61dfe13c2ee24b2b96.zip
chromium_src-86ec5550eb81c98bdebe8f61dfe13c2ee24b2b96.tar.gz
chromium_src-86ec5550eb81c98bdebe8f61dfe13c2ee24b2b96.tar.bz2
Pass was_clean from WebSocketChannel to renderer
Previously, the browser always set |was_clean| to true when it sent an OnDropChannel message to the renderer. Set the value correctly in WebSocketChannel and pass it through to WebSocketDispatcherHost. BUG=341343 Review URL: https://codereview.chromium.org/149793006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250082 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/websockets/websocket_channel.cc15
-rw-r--r--net/websockets/websocket_channel.h4
-rw-r--r--net/websockets/websocket_channel_test.cc41
-rw-r--r--net/websockets/websocket_event_interface.h6
4 files changed, 39 insertions, 27 deletions
diff --git a/net/websockets/websocket_channel.cc b/net/websockets/websocket_channel.cc
index 94baafd..6760849 100644
--- a/net/websockets/websocket_channel.cc
+++ b/net/websockets/websocket_channel.cc
@@ -321,7 +321,7 @@ void WebSocketChannel::StartClosingHandshake(uint16 code,
// Abort the in-progress handshake and drop the connection immediately.
stream_request_.reset();
state_ = CLOSED;
- AllowUnused(DoDropChannel(kWebSocketErrorAbnormalClosure, ""));
+ AllowUnused(DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""));
return;
}
if (state_ != CONNECTED) {
@@ -504,7 +504,7 @@ ChannelState WebSocketChannel::OnWriteDone(bool synchronous, int result) {
stream_->Close();
DCHECK_NE(CLOSED, state_);
state_ = CLOSED;
- return DoDropChannel(kWebSocketErrorAbnormalClosure, "");
+ return DoDropChannel(false, kWebSocketErrorAbnormalClosure, "");
}
}
@@ -568,11 +568,13 @@ ChannelState WebSocketChannel::OnReadDone(bool synchronous, int result) {
state_ = CLOSED;
uint16 code = kWebSocketErrorAbnormalClosure;
std::string reason = "";
+ bool was_clean = false;
if (closing_code_ != 0) {
code = closing_code_;
reason = closing_reason_;
+ was_clean = (result == ERR_CONNECTION_CLOSED);
}
- return DoDropChannel(code, reason);
+ return DoDropChannel(was_clean, code, reason);
}
}
@@ -859,19 +861,20 @@ bool WebSocketChannel::ParseClose(const scoped_refptr<IOBuffer>& buffer,
return parsed_ok;
}
-ChannelState WebSocketChannel::DoDropChannel(uint16 code,
+ChannelState WebSocketChannel::DoDropChannel(bool was_clean,
+ uint16 code,
const std::string& reason) {
if (CHANNEL_DELETED ==
notification_sender_->SendImmediately(event_interface_.get()))
return CHANNEL_DELETED;
- return event_interface_->OnDropChannel(code, reason);
+ return event_interface_->OnDropChannel(was_clean, code, reason);
}
void WebSocketChannel::CloseTimeout() {
stream_->Close();
DCHECK_NE(CLOSED, state_);
state_ = CLOSED;
- AllowUnused(DoDropChannel(kWebSocketErrorAbnormalClosure, ""));
+ AllowUnused(DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""));
// |this| has been deleted.
}
diff --git a/net/websockets/websocket_channel.h b/net/websockets/websocket_channel.h
index 64cf91d..423c48b 100644
--- a/net/websockets/websocket_channel.h
+++ b/net/websockets/websocket_channel.h
@@ -244,7 +244,9 @@ class NET_EXPORT WebSocketChannel {
// Drop this channel.
// If there are pending opening handshake notifications, notify them
// before dropping.
- ChannelState DoDropChannel(uint16 code, const std::string& reason);
+ ChannelState DoDropChannel(bool was_clean,
+ uint16 code,
+ const std::string& reason);
// Called if the closing handshake times out. Closes the connection and
// informs the |event_interface_| if appropriate.
diff --git a/net/websockets/websocket_channel_test.cc b/net/websockets/websocket_channel_test.cc
index ed309c7..e3ce416 100644
--- a/net/websockets/websocket_channel_test.cc
+++ b/net/websockets/websocket_channel_test.cc
@@ -152,8 +152,8 @@ class MockWebSocketEventInterface : public WebSocketEventInterface {
MOCK_METHOD1(OnFlowControl, ChannelState(int64)); // NOLINT
MOCK_METHOD0(OnClosingHandshake, ChannelState(void)); // NOLINT
MOCK_METHOD1(OnFailChannel, ChannelState(const std::string&)); // NOLINT
- MOCK_METHOD2(OnDropChannel,
- ChannelState(uint16, const std::string&)); // NOLINT
+ MOCK_METHOD3(OnDropChannel,
+ ChannelState(bool, uint16, const std::string&)); // NOLINT
// We can't use GMock with scoped_ptr.
ChannelState OnStartOpeningHandshake(
@@ -192,7 +192,8 @@ class FakeWebSocketEventInterface : public WebSocketEventInterface {
virtual ChannelState OnFailChannel(const std::string& message) OVERRIDE {
return CHANNEL_DELETED;
}
- virtual ChannelState OnDropChannel(uint16 code,
+ virtual ChannelState OnDropChannel(bool was_clean,
+ uint16 code,
const std::string& reason) OVERRIDE {
return CHANNEL_DELETED;
}
@@ -854,7 +855,8 @@ class ChannelDeletingFakeWebSocketEventInterface
return fixture_->DeleteIfDeleting(EVENT_ON_FAIL_CHANNEL);
}
- virtual ChannelState OnDropChannel(uint16 code,
+ virtual ChannelState OnDropChannel(bool was_clean,
+ uint16 code,
const std::string& reason) OVERRIDE {
return fixture_->DeleteIfDeleting(EVENT_ON_DROP_CHANNEL);
}
@@ -889,7 +891,7 @@ class WebSocketChannelEventInterfaceTest : public WebSocketChannelTest {
DefaultValue<ChannelState>::Set(CHANNEL_ALIVE);
ON_CALL(*event_interface_, OnAddChannelResponse(true, _, _))
.WillByDefault(Return(CHANNEL_DELETED));
- ON_CALL(*event_interface_, OnDropChannel(_, _))
+ ON_CALL(*event_interface_, OnDropChannel(_, _, _))
.WillByDefault(Return(CHANNEL_DELETED));
ON_CALL(*event_interface_, OnFailChannel(_))
.WillByDefault(Return(CHANNEL_DELETED));
@@ -1329,9 +1331,10 @@ TEST_F(WebSocketChannelEventInterfaceTest, CloseAfterHandshake) {
EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _));
EXPECT_CALL(*event_interface_, OnFlowControl(_));
EXPECT_CALL(*event_interface_, OnClosingHandshake());
- EXPECT_CALL(*event_interface_,
- OnDropChannel(kWebSocketErrorInternalServerError,
- "Internal Server Error"));
+ EXPECT_CALL(
+ *event_interface_,
+ OnDropChannel(
+ true, kWebSocketErrorInternalServerError, "Internal Server Error"));
}
CreateChannelAndConnectSuccessfully();
@@ -1350,7 +1353,7 @@ TEST_F(WebSocketChannelEventInterfaceTest, ConnectionCloseAfterHandshake) {
EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _));
EXPECT_CALL(*event_interface_, OnFlowControl(_));
EXPECT_CALL(*event_interface_,
- OnDropChannel(kWebSocketErrorAbnormalClosure, _));
+ OnDropChannel(false, kWebSocketErrorAbnormalClosure, _));
}
CreateChannelAndConnectSuccessfully();
@@ -1519,7 +1522,7 @@ TEST_F(WebSocketChannelEventInterfaceTest, AsyncAbnormalClosure) {
EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _));
EXPECT_CALL(*event_interface_, OnFlowControl(_));
EXPECT_CALL(*event_interface_,
- OnDropChannel(kWebSocketErrorAbnormalClosure, _));
+ OnDropChannel(false, kWebSocketErrorAbnormalClosure, _));
}
CreateChannelAndConnectSuccessfully();
@@ -1538,7 +1541,7 @@ TEST_F(WebSocketChannelEventInterfaceTest, ConnectionReset) {
EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _));
EXPECT_CALL(*event_interface_, OnFlowControl(_));
EXPECT_CALL(*event_interface_,
- OnDropChannel(kWebSocketErrorAbnormalClosure, _));
+ OnDropChannel(false, kWebSocketErrorAbnormalClosure, _));
}
CreateChannelAndConnectSuccessfully();
@@ -1762,7 +1765,7 @@ TEST_F(WebSocketChannelEventInterfaceTest, FailedWrite) {
EXPECT_CALL(*event_interface_, OnFlowControl(_));
EXPECT_CALL(checkpoint, Call(1));
EXPECT_CALL(*event_interface_,
- OnDropChannel(kWebSocketErrorAbnormalClosure, _));
+ OnDropChannel(false, kWebSocketErrorAbnormalClosure, _));
EXPECT_CALL(checkpoint, Call(2));
}
@@ -1781,7 +1784,7 @@ TEST_F(WebSocketChannelEventInterfaceTest, SendCloseDropsChannel) {
EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _));
EXPECT_CALL(*event_interface_, OnFlowControl(_));
EXPECT_CALL(*event_interface_,
- OnDropChannel(kWebSocketNormalClosure, "Fred"));
+ OnDropChannel(true, kWebSocketNormalClosure, "Fred"));
}
CreateChannelAndConnectSuccessfully();
@@ -1794,7 +1797,7 @@ TEST_F(WebSocketChannelEventInterfaceTest, SendCloseDropsChannel) {
// OnDropChannel.
TEST_F(WebSocketChannelEventInterfaceTest, CloseDuringConnection) {
EXPECT_CALL(*event_interface_,
- OnDropChannel(kWebSocketErrorAbnormalClosure, ""));
+ OnDropChannel(false, kWebSocketErrorAbnormalClosure, ""));
CreateChannelAndConnect();
channel_->StartClosingHandshake(kWebSocketNormalClosure, "Joe");
@@ -1808,7 +1811,7 @@ TEST_F(WebSocketChannelEventInterfaceTest, OnDropChannelCalledOnce) {
EXPECT_CALL(*event_interface_, OnFlowControl(_));
EXPECT_CALL(*event_interface_,
- OnDropChannel(kWebSocketErrorAbnormalClosure, ""))
+ OnDropChannel(false, kWebSocketErrorAbnormalClosure, ""))
.Times(1);
CreateChannelAndConnectSuccessfully();
@@ -1832,7 +1835,7 @@ TEST_F(WebSocketChannelEventInterfaceTest, CloseWithNoPayloadGivesStatus1005) {
EXPECT_CALL(*event_interface_, OnFlowControl(_));
EXPECT_CALL(*event_interface_, OnClosingHandshake());
EXPECT_CALL(*event_interface_,
- OnDropChannel(kWebSocketErrorNoStatusReceived, _));
+ OnDropChannel(true, kWebSocketErrorNoStatusReceived, _));
CreateChannelAndConnectSuccessfully();
}
@@ -1852,7 +1855,7 @@ TEST_F(WebSocketChannelEventInterfaceTest,
EXPECT_CALL(*event_interface_, OnFlowControl(_));
EXPECT_CALL(*event_interface_, OnClosingHandshake());
EXPECT_CALL(*event_interface_,
- OnDropChannel(kWebSocketErrorNoStatusReceived, _));
+ OnDropChannel(true, kWebSocketErrorNoStatusReceived, _));
CreateChannelAndConnectSuccessfully();
}
@@ -2063,7 +2066,7 @@ TEST_F(WebSocketChannelEventInterfaceTest,
InSequence s;
EXPECT_CALL(checkpoint, Call(1));
EXPECT_CALL(*event_interface_,
- OnDropChannel(kWebSocketErrorAbnormalClosure, _))
+ OnDropChannel(false, kWebSocketErrorAbnormalClosure, _))
.WillOnce(InvokeClosureReturnDeleted(completion.closure()));
}
CreateChannelAndConnectSuccessfully();
@@ -2097,7 +2100,7 @@ TEST_F(WebSocketChannelEventInterfaceTest,
EXPECT_CALL(checkpoint, Call(1));
EXPECT_CALL(*event_interface_, OnClosingHandshake());
EXPECT_CALL(*event_interface_,
- OnDropChannel(kWebSocketErrorAbnormalClosure, _))
+ OnDropChannel(false, kWebSocketErrorAbnormalClosure, _))
.WillOnce(InvokeClosureReturnDeleted(completion.closure()));
}
CreateChannelAndConnectSuccessfully();
diff --git a/net/websockets/websocket_event_interface.h b/net/websockets/websocket_event_interface.h
index c99376c..923581a 100644
--- a/net/websockets/websocket_event_interface.h
+++ b/net/websockets/websocket_event_interface.h
@@ -68,12 +68,16 @@ class NET_EXPORT WebSocketEventInterface {
// callers must take care not to provide details that could be useful to
// attackers attempting to use WebSockets to probe networks.
//
+ // |was_clean| should be true if the closing handshake completed successfully.
+ //
// The channel should not be used again after OnDropChannel() has been
// called.
//
// This method returns a ChannelState for consistency, but all implementations
// must delete the Channel and return CHANNEL_DELETED.
- virtual ChannelState OnDropChannel(uint16 code, const std::string& reason)
+ virtual ChannelState OnDropChannel(bool was_clean,
+ uint16 code,
+ const std::string& reason)
WARN_UNUSED_RESULT = 0;
// Called when the browser fails the channel, as specified in the spec.