summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryhirano@chromium.org <yhirano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-13 10:22:57 +0000
committeryhirano@chromium.org <yhirano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-13 10:22:57 +0000
commit7824cf82df8244b5f66a56e663ce6e121c25de88 (patch)
tree3a2908a3687bc00a80d2ca49b7324ce3cd71c088
parented8fd9152e0dff6c26f69f968e0d4aa4bd890d57 (diff)
downloadchromium_src-7824cf82df8244b5f66a56e663ce6e121c25de88.zip
chromium_src-7824cf82df8244b5f66a56e663ce6e121c25de88.tar.gz
chromium_src-7824cf82df8244b5f66a56e663ce6e121c25de88.tar.bz2
Introduce url::Origin to represent Web Origin.
Introduce url::Origin to represent a serialized Web Origin defined in RFC6455. This class wraps a string representation of blink-side SecurityOrigin object. BUG=339373 R=tyoshino@chromium.org, ricea@chromium.org Review URL: https://codereview.chromium.org/170843007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256789 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/renderer_host/websocket_dispatcher_host_unittest.cc5
-rw-r--r--content/browser/renderer_host/websocket_host.cc10
-rw-r--r--content/browser/renderer_host/websocket_host.h6
-rw-r--r--content/child/websocket_bridge.cc11
-rw-r--r--content/common/websocket_messages.h3
-rw-r--r--content/public/common/common_param_traits.cc23
-rw-r--r--content/public/common/common_param_traits.h11
-rw-r--r--net/websockets/websocket_channel.cc7
-rw-r--r--net/websockets/websocket_channel.h12
-rw-r--r--net/websockets/websocket_channel_test.cc13
-rw-r--r--net/websockets/websocket_stream.cc19
-rw-r--r--net/websockets/websocket_stream.h6
-rw-r--r--net/websockets/websocket_stream_test.cc73
-rw-r--r--net/websockets/websocket_test_util.h6
-rw-r--r--url/origin.cc19
-rw-r--r--url/origin.h33
-rw-r--r--url/origin_unittest.cc36
-rw-r--r--url/url.gyp1
-rw-r--r--url/url_srcs.gypi2
19 files changed, 223 insertions, 73 deletions
diff --git a/content/browser/renderer_host/websocket_dispatcher_host_unittest.cc b/content/browser/renderer_host/websocket_dispatcher_host_unittest.cc
index e771a2c..e1fc62b 100644
--- a/content/browser/renderer_host/websocket_dispatcher_host_unittest.cc
+++ b/content/browser/renderer_host/websocket_dispatcher_host_unittest.cc
@@ -15,6 +15,7 @@
#include "ipc/ipc_message.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
+#include "url/origin.h"
namespace content {
namespace {
@@ -87,7 +88,7 @@ TEST_F(WebSocketDispatcherHostTest, AddChannelRequest) {
GURL socket_url("ws://example.com/test");
std::vector<std::string> requested_protocols;
requested_protocols.push_back("hello");
- GURL origin("http://example.com/test");
+ url::Origin origin("http://example.com/test");
WebSocketHostMsg_AddChannelRequest message(
routing_id, socket_url, requested_protocols, origin);
@@ -122,7 +123,7 @@ TEST_F(WebSocketDispatcherHostTest, SendFrame) {
GURL socket_url("ws://example.com/test");
std::vector<std::string> requested_protocols;
requested_protocols.push_back("hello");
- GURL origin("http://example.com/test");
+ url::Origin origin("http://example.com/test");
WebSocketHostMsg_AddChannelRequest add_channel_message(
routing_id, socket_url, requested_protocols, origin);
diff --git a/content/browser/renderer_host/websocket_host.cc b/content/browser/renderer_host/websocket_host.cc
index b4a7cee..4346c4d 100644
--- a/content/browser/renderer_host/websocket_host.cc
+++ b/content/browser/renderer_host/websocket_host.cc
@@ -17,6 +17,7 @@
#include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode
#include "net/websockets/websocket_handshake_request_info.h"
#include "net/websockets/websocket_handshake_response_info.h"
+#include "url/origin.h"
namespace content {
@@ -240,14 +241,15 @@ bool WebSocketHost::OnMessageReceived(const IPC::Message& message,
void WebSocketHost::OnAddChannelRequest(
const GURL& socket_url,
const std::vector<std::string>& requested_protocols,
- const GURL& origin) {
+ const url::Origin& origin) {
DVLOG(3) << "WebSocketHost::OnAddChannelRequest"
<< " routing_id=" << routing_id_ << " socket_url=\"" << socket_url
<< "\" requested_protocols=\""
- << JoinString(requested_protocols, ", ") << "\" origin=\"" << origin
- << "\"";
+ << JoinString(requested_protocols, ", ") << "\" origin=\""
+ << origin.string() << "\"";
- channel_->SendAddChannelRequest(socket_url, requested_protocols, origin);
+ channel_->SendAddChannelRequest(
+ socket_url, requested_protocols, origin);
}
void WebSocketHost::OnSendFrame(bool fin,
diff --git a/content/browser/renderer_host/websocket_host.h b/content/browser/renderer_host/websocket_host.h
index ba10f1c..bfe6304 100644
--- a/content/browser/renderer_host/websocket_host.h
+++ b/content/browser/renderer_host/websocket_host.h
@@ -14,6 +14,10 @@
class GURL;
+namespace url {
+class Origin;
+} // namespace url
+
namespace net {
class WebSocketChannel;
class URLRequestContext;
@@ -47,7 +51,7 @@ class CONTENT_EXPORT WebSocketHost {
void OnAddChannelRequest(const GURL& socket_url,
const std::vector<std::string>& requested_protocols,
- const GURL& origin);
+ const url::Origin& origin);
void OnSendFrame(bool fin,
WebSocketMessageType type,
diff --git a/content/child/websocket_bridge.cc b/content/child/websocket_bridge.cc
index 15a92dc..8eaf2cc 100644
--- a/content/child/websocket_bridge.cc
+++ b/content/child/websocket_bridge.cc
@@ -17,7 +17,6 @@
#include "content/common/websocket_messages.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_message_macros.h"
-#include "url/gurl.h"
#include "third_party/WebKit/public/platform/WebSocketHandle.h"
#include "third_party/WebKit/public/platform/WebSocketHandleClient.h"
#include "third_party/WebKit/public/platform/WebSocketHandshakeRequestInfo.h"
@@ -25,6 +24,8 @@
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/platform/WebVector.h"
+#include "url/gurl.h"
+#include "url/origin.h"
using blink::WebSocketHandle;
using blink::WebSocketHandleClient;
@@ -216,11 +217,11 @@ void WebSocketBridge::connect(
std::vector<std::string> protocols_to_pass;
for (size_t i = 0; i < protocols.size(); ++i)
protocols_to_pass.push_back(protocols[i].utf8());
- GURL origin_to_pass(origin.utf8());
+ url::Origin origin_to_pass(origin.utf8());
- DVLOG(1) << "Bridge#" << channel_id_ << " Connect("
- << url << ", (" << JoinString(protocols_to_pass, ", ") << "), "
- << origin_to_pass << ")";
+ DVLOG(1) << "Bridge#" << channel_id_ << " Connect(" << url << ", ("
+ << JoinString(protocols_to_pass, ", ") << "), "
+ << origin_to_pass.string() << ")";
ChildThread::current()->Send(
new WebSocketHostMsg_AddChannelRequest(channel_id_,
diff --git a/content/common/websocket_messages.h b/content/common/websocket_messages.h
index 20fef1e..0ece66a 100644
--- a/content/common/websocket_messages.h
+++ b/content/common/websocket_messages.h
@@ -21,6 +21,7 @@
#include "content/common/websocket.h"
#include "ipc/ipc_message_macros.h"
#include "url/gurl.h"
+#include "url/origin.h"
#undef IPC_MESSAGE_EXPORT
#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
@@ -60,7 +61,7 @@ IPC_STRUCT_TRAITS_END()
IPC_MESSAGE_ROUTED3(WebSocketHostMsg_AddChannelRequest,
GURL /* socket_url */,
std::vector<std::string> /* requested_protocols */,
- GURL /* origin */)
+ url::Origin /* origin */)
// WebSocket messages sent from the browser to the renderer.
diff --git a/content/public/common/common_param_traits.cc b/content/public/common/common_param_traits.cc
index 474fb7a..956801a 100644
--- a/content/public/common/common_param_traits.cc
+++ b/content/public/common/common_param_traits.cc
@@ -4,6 +4,8 @@
#include "content/public/common/common_param_traits.h"
+#include <string>
+
#include "content/public/common/content_constants.h"
#include "content/public/common/page_state.h"
#include "content/public/common/referrer.h"
@@ -87,6 +89,27 @@ void ParamTraits<GURL>::Log(const GURL& p, std::string* l) {
l->append(p.spec());
}
+void ParamTraits<url::Origin>::Write(Message* m,
+ const url::Origin& p) {
+ m->WriteString(p.string());
+}
+
+bool ParamTraits<url::Origin>::Read(const Message* m,
+ PickleIterator* iter,
+ url::Origin* p) {
+ std::string s;
+ if (!m->ReadString(iter, &s)) {
+ *p = url::Origin();
+ return false;
+ }
+ *p = url::Origin(s);
+ return true;
+}
+
+void ParamTraits<url::Origin>::Log(const url::Origin& p, std::string* l) {
+ l->append(p.string());
+}
+
void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) {
WriteParam(m, p.host());
WriteParam(m, p.port());
diff --git a/content/public/common/common_param_traits.h b/content/public/common/common_param_traits.h
index 18a0ee0..8800fe1 100644
--- a/content/public/common/common_param_traits.h
+++ b/content/public/common/common_param_traits.h
@@ -14,6 +14,8 @@
#ifndef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_
#define CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_
+#include <string>
+
#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "content/public/common/common_param_traits_macros.h"
@@ -21,6 +23,7 @@
#include "ui/gfx/native_widget_types.h"
#include "ui/surface/transport_dib.h"
#include "url/gurl.h"
+#include "url/origin.h"
class SkBitmap;
@@ -51,6 +54,14 @@ struct CONTENT_EXPORT ParamTraits<GURL> {
static void Log(const param_type& p, std::string* l);
};
+template <>
+struct CONTENT_EXPORT ParamTraits<url::Origin> {
+ typedef url::Origin param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, PickleIterator* iter, param_type* p);
+ static void Log(const param_type& p, std::string* l);
+};
+
template<>
struct CONTENT_EXPORT ParamTraits<net::HostPortPair> {
typedef net::HostPortPair param_type;
diff --git a/net/websockets/websocket_channel.cc b/net/websockets/websocket_channel.cc
index ce1692d..953d4f7 100644
--- a/net/websockets/websocket_channel.cc
+++ b/net/websockets/websocket_channel.cc
@@ -28,6 +28,7 @@
#include "net/websockets/websocket_handshake_response_info.h"
#include "net/websockets/websocket_mux.h"
#include "net/websockets/websocket_stream.h"
+#include "url/origin.h"
namespace net {
@@ -279,7 +280,7 @@ WebSocketChannel::~WebSocketChannel() {
void WebSocketChannel::SendAddChannelRequest(
const GURL& socket_url,
const std::vector<std::string>& requested_subprotocols,
- const GURL& origin) {
+ const url::Origin& origin) {
// Delegate to the tested version.
SendAddChannelRequestWithSuppliedCreator(
socket_url,
@@ -406,7 +407,7 @@ void WebSocketChannel::StartClosingHandshake(uint16 code,
void WebSocketChannel::SendAddChannelRequestForTesting(
const GURL& socket_url,
const std::vector<std::string>& requested_subprotocols,
- const GURL& origin,
+ const url::Origin& origin,
const WebSocketStreamCreator& creator) {
SendAddChannelRequestWithSuppliedCreator(
socket_url, requested_subprotocols, origin, creator);
@@ -420,7 +421,7 @@ void WebSocketChannel::SetClosingHandshakeTimeoutForTesting(
void WebSocketChannel::SendAddChannelRequestWithSuppliedCreator(
const GURL& socket_url,
const std::vector<std::string>& requested_subprotocols,
- const GURL& origin,
+ const url::Origin& origin,
const WebSocketStreamCreator& creator) {
DCHECK_EQ(FRESHLY_CONSTRUCTED, state_);
if (!socket_url.SchemeIsWSOrWSS()) {
diff --git a/net/websockets/websocket_channel.h b/net/websockets/websocket_channel.h
index 40b76c9..fa7a133 100644
--- a/net/websockets/websocket_channel.h
+++ b/net/websockets/websocket_channel.h
@@ -22,6 +22,10 @@
#include "net/websockets/websocket_stream.h"
#include "url/gurl.h"
+namespace url {
+class Origin;
+} // namespace url
+
namespace net {
class BoundNetLog;
@@ -42,7 +46,7 @@ class NET_EXPORT WebSocketChannel {
typedef base::Callback<scoped_ptr<WebSocketStreamRequest>(
const GURL&,
const std::vector<std::string>&,
- const GURL&,
+ const url::Origin&,
URLRequestContext*,
const BoundNetLog&,
scoped_ptr<WebSocketStream::ConnectDelegate>)> WebSocketStreamCreator;
@@ -58,7 +62,7 @@ class NET_EXPORT WebSocketChannel {
void SendAddChannelRequest(
const GURL& socket_url,
const std::vector<std::string>& requested_protocols,
- const GURL& origin);
+ const url::Origin& origin);
// Sends a data frame to the remote side. The frame should usually be no
// larger than 32KB to prevent the time required to copy the buffers from from
@@ -96,7 +100,7 @@ class NET_EXPORT WebSocketChannel {
void SendAddChannelRequestForTesting(
const GURL& socket_url,
const std::vector<std::string>& requested_protocols,
- const GURL& origin,
+ const url::Origin& origin,
const WebSocketStreamCreator& creator);
// The default timout for the closing handshake is a sensible value (see
@@ -151,7 +155,7 @@ class NET_EXPORT WebSocketChannel {
void SendAddChannelRequestWithSuppliedCreator(
const GURL& socket_url,
const std::vector<std::string>& requested_protocols,
- const GURL& origin,
+ const url::Origin& origin,
const WebSocketStreamCreator& creator);
// Success callback from WebSocketStream::CreateAndConnectStream(). Reports
diff --git a/net/websockets/websocket_channel_test.cc b/net/websockets/websocket_channel_test.cc
index 03e2479..8d8686d 100644
--- a/net/websockets/websocket_channel_test.cc
+++ b/net/websockets/websocket_channel_test.cc
@@ -31,6 +31,7 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
+#include "url/origin.h"
// Hacky macros to construct the body of a Close message from a code and a
// string, while ensuring the result is a compile-time constant string.
@@ -680,7 +681,7 @@ struct ArgumentCopyingWebSocketStreamCreator {
scoped_ptr<WebSocketStreamRequest> Create(
const GURL& socket_url,
const std::vector<std::string>& requested_subprotocols,
- const GURL& origin,
+ const url::Origin& origin,
URLRequestContext* url_request_context,
const BoundNetLog& net_log,
scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
@@ -694,7 +695,7 @@ struct ArgumentCopyingWebSocketStreamCreator {
}
GURL socket_url;
- GURL origin;
+ url::Origin origin;
std::vector<std::string> requested_subprotocols;
URLRequestContext* url_request_context;
BoundNetLog net_log;
@@ -754,7 +755,7 @@ class WebSocketChannelTest : public ::testing::Test {
// A struct containing the data that will be used to connect the channel.
// Grouped for readability.
struct ConnectData {
- ConnectData() : socket_url("ws://ws/"), origin("http://ws/") {}
+ ConnectData() : socket_url("ws://ws/"), origin("http://ws") {}
// URLRequestContext object.
URLRequestContext url_request_context;
@@ -764,7 +765,7 @@ class WebSocketChannelTest : public ::testing::Test {
// Requested protocols for the request.
std::vector<std::string> requested_subprotocols;
// Origin of the request
- GURL origin;
+ url::Origin origin;
// A fake WebSocketStreamCreator that just records its arguments.
ArgumentCopyingWebSocketStreamCreator creator;
@@ -959,7 +960,7 @@ class WebSocketChannelReceiveUtf8Test : public WebSocketChannelStreamTest {
// passed to the creator function.
TEST_F(WebSocketChannelTest, EverythingIsPassedToTheCreatorFunction) {
connect_data_.socket_url = GURL("ws://example.com/test");
- connect_data_.origin = GURL("http://example.com/test");
+ connect_data_.origin = url::Origin("http://example.com");
connect_data_.requested_subprotocols.push_back("Sinbad");
CreateChannelAndConnect();
@@ -971,7 +972,7 @@ TEST_F(WebSocketChannelTest, EverythingIsPassedToTheCreatorFunction) {
EXPECT_EQ(connect_data_.socket_url, actual.socket_url);
EXPECT_EQ(connect_data_.requested_subprotocols,
actual.requested_subprotocols);
- EXPECT_EQ(connect_data_.origin, actual.origin);
+ EXPECT_EQ(connect_data_.origin.string(), actual.origin.string());
}
// Verify that calling SendFlowControl before the connection is established does
diff --git a/net/websockets/websocket_stream.cc b/net/websockets/websocket_stream.cc
index 558add2..48135d1 100644
--- a/net/websockets/websocket_stream.cc
+++ b/net/websockets/websocket_stream.cc
@@ -16,6 +16,7 @@
#include "net/websockets/websocket_handshake_stream_create_helper.h"
#include "net/websockets/websocket_test_util.h"
#include "url/gurl.h"
+#include "url/origin.h"
namespace net {
namespace {
@@ -146,7 +147,7 @@ void Delegate::OnReadCompleted(URLRequest* request, int bytes_read) {
scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamWithCreateHelper(
const GURL& socket_url,
scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper,
- const GURL& origin,
+ const url::Origin& origin,
URLRequestContext* url_request_context,
const BoundNetLog& net_log,
scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
@@ -158,7 +159,7 @@ scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamWithCreateHelper(
HttpRequestHeaders headers;
headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase);
headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade);
- headers.SetHeader(HttpRequestHeaders::kOrigin, origin.spec());
+ headers.SetHeader(HttpRequestHeaders::kOrigin, origin.string());
headers.SetHeader(websockets::kSecWebSocketVersion,
websockets::kSupportedVersion);
request->url_request()->SetExtraRequestHeaders(headers);
@@ -184,7 +185,7 @@ WebSocketStream::ConnectDelegate::~ConnectDelegate() {}
scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream(
const GURL& socket_url,
const std::vector<std::string>& requested_subprotocols,
- const GURL& origin,
+ const url::Origin& origin,
URLRequestContext* url_request_context,
const BoundNetLog& net_log,
scoped_ptr<ConnectDelegate> connect_delegate) {
@@ -201,12 +202,12 @@ scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream(
// This is declared in websocket_test_util.h.
scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamForTesting(
- const GURL& socket_url,
- scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper,
- const GURL& origin,
- URLRequestContext* url_request_context,
- const BoundNetLog& net_log,
- scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
+ const GURL& socket_url,
+ scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper,
+ const url::Origin& origin,
+ URLRequestContext* url_request_context,
+ const BoundNetLog& net_log,
+ scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
return CreateAndConnectStreamWithCreateHelper(socket_url,
create_helper.Pass(),
origin,
diff --git a/net/websockets/websocket_stream.h b/net/websockets/websocket_stream.h
index bcc8416..d881a37 100644
--- a/net/websockets/websocket_stream.h
+++ b/net/websockets/websocket_stream.h
@@ -19,6 +19,10 @@
class GURL;
+namespace url {
+class Origin;
+} // namespace url
+
namespace net {
class BoundNetLog;
@@ -87,7 +91,7 @@ class NET_EXPORT_PRIVATE WebSocketStream {
static scoped_ptr<WebSocketStreamRequest> CreateAndConnectStream(
const GURL& socket_url,
const std::vector<std::string>& requested_subprotocols,
- const GURL& origin,
+ const url::Origin& origin,
URLRequestContext* url_request_context,
const BoundNetLog& net_log,
scoped_ptr<ConnectDelegate> connect_delegate);
diff --git a/net/websockets/websocket_stream_test.cc b/net/websockets/websocket_stream_test.cc
index 904b1a0..8947d33 100644
--- a/net/websockets/websocket_stream_test.cc
+++ b/net/websockets/websocket_stream_test.cc
@@ -26,6 +26,7 @@
#include "net/websockets/websocket_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
+#include "url/origin.h"
namespace net {
namespace {
@@ -129,7 +130,7 @@ class WebSocketStreamCreateTest : public ::testing::Test {
scoped_ptr<WebSocketHandshakeStreamCreateHelper>(
new DeterministicKeyWebSocketHandshakeStreamCreateHelper(
delegate, sub_protocols)),
- GURL(origin),
+ url::Origin(origin),
url_request_context_host_.GetURLRequestContext(),
BoundNetLog(),
connect_delegate.Pass());
@@ -200,7 +201,7 @@ class WebSocketStreamCreateExtensionTest : public WebSocketStreamCreateTest {
"ws://localhost/testing_path",
"/testing_path",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
"Sec-WebSocket-Extensions: " + extensions_header_value + "\r\n");
RunUntilIdle();
@@ -210,7 +211,7 @@ class WebSocketStreamCreateExtensionTest : public WebSocketStreamCreateTest {
// Confirm that the basic case works as expected.
TEST_F(WebSocketStreamCreateTest, SimpleSuccess) {
CreateAndConnectStandard(
- "ws://localhost/", "/", NoSubProtocols(), "http://localhost/", "", "");
+ "ws://localhost/", "/", NoSubProtocols(), "http://localhost", "", "");
EXPECT_FALSE(request_info_);
EXPECT_FALSE(response_info_);
RunUntilIdle();
@@ -235,7 +236,7 @@ TEST_F(WebSocketStreamCreateTest, HandshakeInfo) {
"ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
kResponse);
EXPECT_FALSE(request_info_);
@@ -259,7 +260,7 @@ TEST_F(WebSocketStreamCreateTest, HandshakeInfo) {
EXPECT_EQ(HeaderKeyValuePair("Cache-Control", "no-cache"),
request_headers[3]);
EXPECT_EQ(HeaderKeyValuePair("Upgrade", "websocket"), request_headers[4]);
- EXPECT_EQ(HeaderKeyValuePair("Origin", "http://localhost/"),
+ EXPECT_EQ(HeaderKeyValuePair("Origin", "http://localhost"),
request_headers[5]);
EXPECT_EQ(HeaderKeyValuePair("Sec-WebSocket-Version", "13"),
request_headers[6]);
@@ -290,7 +291,7 @@ TEST_F(WebSocketStreamCreateTest, HandshakeInfo) {
// Confirm that the stream isn't established until the message loop runs.
TEST_F(WebSocketStreamCreateTest, NeedsToRunLoop) {
CreateAndConnectStandard(
- "ws://localhost/", "/", NoSubProtocols(), "http://localhost/", "", "");
+ "ws://localhost/", "/", NoSubProtocols(), "http://localhost", "", "");
EXPECT_FALSE(has_failed());
EXPECT_FALSE(stream_);
}
@@ -300,7 +301,7 @@ TEST_F(WebSocketStreamCreateTest, PathIsUsed) {
CreateAndConnectStandard("ws://localhost/testing_path",
"/testing_path",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
"");
RunUntilIdle();
@@ -313,7 +314,7 @@ TEST_F(WebSocketStreamCreateTest, OriginIsUsed) {
CreateAndConnectStandard("ws://localhost/testing_path",
"/testing_path",
NoSubProtocols(),
- "http://google.com/",
+ "http://google.com",
"",
"");
RunUntilIdle();
@@ -329,7 +330,7 @@ TEST_F(WebSocketStreamCreateTest, SubProtocolIsUsed) {
CreateAndConnectStandard("ws://localhost/testing_path",
"/testing_path",
sub_protocols,
- "http://google.com/",
+ "http://google.com",
"Sec-WebSocket-Protocol: chatv11.chromium.org, "
"chatv20.chromium.org\r\n",
"Sec-WebSocket-Protocol: chatv20.chromium.org\r\n");
@@ -344,7 +345,7 @@ TEST_F(WebSocketStreamCreateTest, UnsolicitedSubProtocol) {
CreateAndConnectStandard("ws://localhost/testing_path",
"/testing_path",
NoSubProtocols(),
- "http://google.com/",
+ "http://google.com",
"",
"Sec-WebSocket-Protocol: chatv20.chromium.org\r\n");
RunUntilIdle();
@@ -363,7 +364,7 @@ TEST_F(WebSocketStreamCreateTest, UnacceptedSubProtocol) {
CreateAndConnectStandard("ws://localhost/testing_path",
"/testing_path",
sub_protocols,
- "http://localhost/",
+ "http://localhost",
"Sec-WebSocket-Protocol: chat.example.com\r\n",
"");
RunUntilIdle();
@@ -383,7 +384,7 @@ TEST_F(WebSocketStreamCreateTest, MultipleSubProtocolsInResponse) {
CreateAndConnectStandard("ws://localhost/testing_path",
"/testing_path",
sub_protocols,
- "http://google.com/",
+ "http://google.com",
"Sec-WebSocket-Protocol: chatv11.chromium.org, "
"chatv20.chromium.org\r\n",
"Sec-WebSocket-Protocol: chatv11.chromium.org, "
@@ -405,7 +406,7 @@ TEST_F(WebSocketStreamCreateTest, UnmatchedSubProtocolInResponse) {
CreateAndConnectStandard("ws://localhost/testing_path",
"/testing_path",
sub_protocols,
- "http://google.com/",
+ "http://google.com",
"Sec-WebSocket-Protocol: chatv11.chromium.org, "
"chatv20.chromium.org\r\n",
"Sec-WebSocket-Protocol: chatv21.chromium.org\r\n");
@@ -442,7 +443,7 @@ TEST_F(WebSocketStreamCreateExtensionTest, PerMessageDeflateInflates) {
"ws://localhost/testing_path",
"/testing_path",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
WebSocketStandardResponse(
"Sec-WebSocket-Extensions: permessage-deflate\r\n") +
@@ -628,7 +629,7 @@ TEST_F(WebSocketStreamCreateTest, DoubleAccept) {
"ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
"Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n");
RunUntilIdle();
@@ -651,7 +652,7 @@ TEST_F(WebSocketStreamCreateTest, InvalidStatusCode) {
CreateAndConnectCustomResponse("ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
kInvalidStatusCodeResponse);
RunUntilIdle();
@@ -674,7 +675,7 @@ TEST_F(WebSocketStreamCreateTest, RedirectsRejected) {
CreateAndConnectCustomResponse("ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
kRedirectResponse);
RunUntilIdle();
@@ -698,7 +699,7 @@ TEST_F(WebSocketStreamCreateTest, MalformedResponse) {
CreateAndConnectCustomResponse("ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
kMalformedResponse);
RunUntilIdle();
@@ -717,7 +718,7 @@ TEST_F(WebSocketStreamCreateTest, MissingUpgradeHeader) {
CreateAndConnectCustomResponse("ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
kMissingUpgradeResponse);
RunUntilIdle();
@@ -732,7 +733,7 @@ TEST_F(WebSocketStreamCreateTest, DoubleUpgradeHeader) {
"ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"", "Upgrade: HTTP/2.0\r\n");
RunUntilIdle();
EXPECT_TRUE(has_failed());
@@ -752,7 +753,7 @@ TEST_F(WebSocketStreamCreateTest, IncorrectUpgradeHeader) {
CreateAndConnectCustomResponse("ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
kMissingUpgradeResponse);
RunUntilIdle();
@@ -772,7 +773,7 @@ TEST_F(WebSocketStreamCreateTest, MissingConnectionHeader) {
CreateAndConnectCustomResponse("ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
kMissingConnectionResponse);
RunUntilIdle();
@@ -793,7 +794,7 @@ TEST_F(WebSocketStreamCreateTest, IncorrectConnectionHeader) {
CreateAndConnectCustomResponse("ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
kMissingConnectionResponse);
RunUntilIdle();
@@ -814,7 +815,7 @@ TEST_F(WebSocketStreamCreateTest, AdditionalTokenInConnectionHeader) {
CreateAndConnectCustomResponse("ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
kAdditionalConnectionTokenResponse);
RunUntilIdle();
@@ -832,7 +833,7 @@ TEST_F(WebSocketStreamCreateTest, MissingSecWebSocketAccept) {
CreateAndConnectCustomResponse("ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
kMissingAcceptResponse);
RunUntilIdle();
@@ -853,7 +854,7 @@ TEST_F(WebSocketStreamCreateTest, WrongSecWebSocketAccept) {
CreateAndConnectCustomResponse("ws://localhost/",
"/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
"",
kIncorrectAcceptResponse);
RunUntilIdle();
@@ -866,7 +867,7 @@ TEST_F(WebSocketStreamCreateTest, WrongSecWebSocketAccept) {
// Cancellation works.
TEST_F(WebSocketStreamCreateTest, Cancellation) {
CreateAndConnectStandard(
- "ws://localhost/", "/", NoSubProtocols(), "http://localhost/", "", "");
+ "ws://localhost/", "/", NoSubProtocols(), "http://localhost", "", "");
stream_request_.reset();
RunUntilIdle();
EXPECT_FALSE(has_failed());
@@ -882,7 +883,7 @@ TEST_F(WebSocketStreamCreateTest, ConnectionFailure) {
socket_data->set_connect_data(
MockConnect(SYNCHRONOUS, ERR_CONNECTION_REFUSED));
CreateAndConnectRawExpectations("ws://localhost/", NoSubProtocols(),
- "http://localhost/", socket_data.Pass());
+ "http://localhost", socket_data.Pass());
RunUntilIdle();
EXPECT_TRUE(has_failed());
EXPECT_EQ("Error in connection establishment: net::ERR_CONNECTION_REFUSED",
@@ -898,7 +899,7 @@ TEST_F(WebSocketStreamCreateTest, ConnectionTimeout) {
socket_data->set_connect_data(
MockConnect(ASYNC, ERR_CONNECTION_TIMED_OUT));
CreateAndConnectRawExpectations("ws://localhost/", NoSubProtocols(),
- "http://localhost/", socket_data.Pass());
+ "http://localhost", socket_data.Pass());
RunUntilIdle();
EXPECT_TRUE(has_failed());
EXPECT_EQ("Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT",
@@ -912,7 +913,7 @@ TEST_F(WebSocketStreamCreateTest, CancellationDuringConnect) {
socket_data->set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING));
CreateAndConnectRawExpectations("ws://localhost/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
socket_data.Pass());
stream_request_.reset();
RunUntilIdle();
@@ -932,7 +933,7 @@ TEST_F(WebSocketStreamCreateTest, CancellationDuringWrite) {
socket_data->SetStop(1);
CreateAndConnectRawExpectations("ws://localhost/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
make_scoped_ptr(socket_data));
socket_data->Run();
stream_request_.reset();
@@ -945,7 +946,7 @@ TEST_F(WebSocketStreamCreateTest, CancellationDuringWrite) {
// Cancellation during read of the response headers works.
TEST_F(WebSocketStreamCreateTest, CancellationDuringRead) {
- std::string request = WebSocketStandardRequest("/", "http://localhost/", "");
+ std::string request = WebSocketStandardRequest("/", "http://localhost", "");
MockWrite writes[] = {MockWrite(ASYNC, 0, request.c_str())};
MockRead reads[] = {
MockRead(ASYNC, 1, "HTTP/1.1 101 Switching Protocols\r\nUpgr"),
@@ -956,7 +957,7 @@ TEST_F(WebSocketStreamCreateTest, CancellationDuringRead) {
socket_data->SetStop(1);
CreateAndConnectRawExpectations("ws://localhost/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
make_scoped_ptr(socket_data));
socket_data->Run();
stream_request_.reset();
@@ -978,7 +979,7 @@ TEST_F(WebSocketStreamCreateTest, VeryLargeResponseHeaders) {
base::StringPrintf("Set-Cookie: WK-websocket-test-flood-%d=1\r\n", i);
}
CreateAndConnectStandard("ws://localhost/", "/", NoSubProtocols(),
- "http://localhost/", "", set_cookie_headers);
+ "http://localhost", "", set_cookie_headers);
RunUntilIdle();
EXPECT_TRUE(has_failed());
EXPECT_FALSE(response_info_);
@@ -988,7 +989,7 @@ TEST_F(WebSocketStreamCreateTest, VeryLargeResponseHeaders) {
// log the console message "Connection closed before receiving a handshake
// response".
TEST_F(WebSocketStreamCreateTest, NoResponse) {
- std::string request = WebSocketStandardRequest("/", "http://localhost/", "");
+ std::string request = WebSocketStandardRequest("/", "http://localhost", "");
MockWrite writes[] = {MockWrite(ASYNC, request.data(), request.size(), 0)};
MockRead reads[] = {MockRead(ASYNC, 0, 1)};
DeterministicSocketData* socket_data(new DeterministicSocketData(
@@ -996,7 +997,7 @@ TEST_F(WebSocketStreamCreateTest, NoResponse) {
socket_data->set_connect_data(MockConnect(SYNCHRONOUS, OK));
CreateAndConnectRawExpectations("ws://localhost/",
NoSubProtocols(),
- "http://localhost/",
+ "http://localhost",
make_scoped_ptr(socket_data));
socket_data->RunFor(2);
EXPECT_TRUE(has_failed());
diff --git a/net/websockets/websocket_test_util.h b/net/websockets/websocket_test_util.h
index 71b2ce6..5dba6cd 100644
--- a/net/websockets/websocket_test_util.h
+++ b/net/websockets/websocket_test_util.h
@@ -14,6 +14,10 @@
class GURL;
+namespace url {
+class Origin;
+} // namespace url
+
namespace net {
class BoundNetLog;
@@ -38,7 +42,7 @@ NET_EXPORT_PRIVATE extern scoped_ptr<WebSocketStreamRequest>
CreateAndConnectStreamForTesting(
const GURL& socket_url,
scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper,
- const GURL& origin,
+ const url::Origin& origin,
URLRequestContext* url_request_context,
const BoundNetLog& net_log,
scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate);
diff --git a/url/origin.cc b/url/origin.cc
new file mode 100644
index 0000000..eb2cf14
--- /dev/null
+++ b/url/origin.cc
@@ -0,0 +1,19 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "url/origin.h"
+
+#include "base/strings/string_util.h"
+
+namespace url {
+
+Origin::Origin() : string_("null") {}
+
+Origin::Origin(const std::string& origin) : string_(origin) {
+ DCHECK(origin == "null" || MatchPattern(origin, "?*://?*"));
+ DCHECK_GT(origin.size(), 0u);
+ DCHECK_NE(origin[origin.size() - 1], '/');
+}
+
+} // namespace url
diff --git a/url/origin.h b/url/origin.h
new file mode 100644
index 0000000..777e4e1e
--- /dev/null
+++ b/url/origin.h
@@ -0,0 +1,33 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef URL_ORIGIN_H_
+#define URL_ORIGIN_H_
+
+#include <string>
+
+#include "url/url_export.h"
+
+namespace url {
+
+// Origin represents a Web Origin serialized to a string.
+// See RFC6454 for details.
+class URL_EXPORT Origin {
+ public:
+ Origin();
+ explicit Origin(const std::string& origin);
+
+ const std::string& string() const { return string_; }
+
+ bool IsSameAs(const Origin& that) const {
+ return string_ == that.string_;
+ }
+
+ private:
+ std::string string_;
+};
+
+} // namespace url
+
+#endif // URL_ORIGIN_H_
diff --git a/url/origin_unittest.cc b/url/origin_unittest.cc
new file mode 100644
index 0000000..d08342e
--- /dev/null
+++ b/url/origin_unittest.cc
@@ -0,0 +1,36 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/origin.h"
+
+namespace url {
+
+namespace {
+
+// Each test examines the Origin is constructed correctly without
+// violating DCHECKs.
+TEST(OriginTest, constructEmpty) {
+ Origin origin;
+ EXPECT_EQ("null", origin.string());
+}
+
+TEST(OriginTest, constructNull) {
+ Origin origin("null");
+ EXPECT_EQ("null", origin.string());
+}
+
+TEST(OriginTest, constructValidOrigin) {
+ Origin origin("http://example.com:8080");
+ EXPECT_EQ("http://example.com:8080", origin.string());
+}
+
+TEST(OriginTest, constructValidOriginWithoutPort) {
+ Origin origin("wss://example2.com");
+ EXPECT_EQ("wss://example2.com", origin.string());
+}
+
+} // namespace
+
+} // namespace url
diff --git a/url/url.gyp b/url/url.gyp
index bb617f1..93bbee2 100644
--- a/url/url.gyp
+++ b/url/url.gyp
@@ -48,6 +48,7 @@
],
'sources': [
'gurl_unittest.cc',
+ 'origin_unittest.cc',
'url_canon_unittest.cc',
'url_parse_unittest.cc',
'url_test_utils.h',
diff --git a/url/url_srcs.gypi b/url/url_srcs.gypi
index e26bd75..3114620 100644
--- a/url/url_srcs.gypi
+++ b/url/url_srcs.gypi
@@ -7,6 +7,8 @@
'gurl_sources': [
'gurl.cc',
'gurl.h',
+ 'origin.cc',
+ 'origin.h',
'third_party/mozilla/url_parse.cc',
'third_party/mozilla/url_parse.h',
'url_canon.h',