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

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

Issue 222153002: Disallow connecting an insecure WebSocket from a secure page. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 7 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 | Annotate | Revision Log
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // called on the main thread, while all getters are called on the worker 59 // called on the main thread, while all getters are called on the worker
60 // thread. signalWorkerThread() must be called before any getters are called. 60 // thread. signalWorkerThread() must be called before any getters are called.
61 class ThreadableWebSocketChannelSyncHelper { 61 class ThreadableWebSocketChannelSyncHelper {
62 public: 62 public:
63 static PassOwnPtr<ThreadableWebSocketChannelSyncHelper> create(PassOwnPtr<bl ink::WebWaitableEvent> event) 63 static PassOwnPtr<ThreadableWebSocketChannelSyncHelper> create(PassOwnPtr<bl ink::WebWaitableEvent> event)
64 { 64 {
65 return adoptPtr(new ThreadableWebSocketChannelSyncHelper(event)); 65 return adoptPtr(new ThreadableWebSocketChannelSyncHelper(event));
66 } 66 }
67 67
68 // All setters are called on the main thread. 68 // All setters are called on the main thread.
69 void setConnectRequestResult(bool connectRequestResult)
70 {
71 m_connectRequestResult = connectRequestResult;
72 }
69 void setSendRequestResult(WebSocketChannel::SendResult sendRequestResult) 73 void setSendRequestResult(WebSocketChannel::SendResult sendRequestResult)
70 { 74 {
71 m_sendRequestResult = sendRequestResult; 75 m_sendRequestResult = sendRequestResult;
72 } 76 }
73 void setBufferedAmount(unsigned long bufferedAmount) 77 void setBufferedAmount(unsigned long bufferedAmount)
74 { 78 {
75 m_bufferedAmount = bufferedAmount; 79 m_bufferedAmount = bufferedAmount;
76 } 80 }
77 81
78 // All getter are called on the worker thread. 82 // All getter are called on the worker thread.
83 bool connectRequestResult() const
84 {
85 return m_connectRequestResult;
86 }
79 WebSocketChannel::SendResult sendRequestResult() const 87 WebSocketChannel::SendResult sendRequestResult() const
80 { 88 {
81 return m_sendRequestResult; 89 return m_sendRequestResult;
82 } 90 }
83 unsigned long bufferedAmount() const 91 unsigned long bufferedAmount() const
84 { 92 {
85 return m_bufferedAmount; 93 return m_bufferedAmount;
86 } 94 }
87 95
88 // This should be called after all setters are called and before any 96 // This should be called after all setters are called and before any
89 // getters are called. 97 // getters are called.
90 void signalWorkerThread() 98 void signalWorkerThread()
91 { 99 {
92 m_event->signal(); 100 m_event->signal();
93 } 101 }
94 102
95 blink::WebWaitableEvent* event() const 103 blink::WebWaitableEvent* event() const
96 { 104 {
97 return m_event.get(); 105 return m_event.get();
98 } 106 }
99 107
100 private: 108 private:
101 ThreadableWebSocketChannelSyncHelper(PassOwnPtr<blink::WebWaitableEvent> eve nt) 109 ThreadableWebSocketChannelSyncHelper(PassOwnPtr<blink::WebWaitableEvent> eve nt)
102 : m_event(event) 110 : m_event(event)
111 , m_connectRequestResult(false)
103 , m_sendRequestResult(WebSocketChannel::SendFail) 112 , m_sendRequestResult(WebSocketChannel::SendFail)
104 , m_bufferedAmount(0) 113 , m_bufferedAmount(0)
105 { 114 {
106 } 115 }
107 116
108 OwnPtr<blink::WebWaitableEvent> m_event; 117 OwnPtr<blink::WebWaitableEvent> m_event;
118 bool m_connectRequestResult;
109 WebSocketChannel::SendResult m_sendRequestResult; 119 WebSocketChannel::SendResult m_sendRequestResult;
110 unsigned long m_bufferedAmount; 120 unsigned long m_bufferedAmount;
111 }; 121 };
112 122
113 WorkerThreadableWebSocketChannel::WorkerThreadableWebSocketChannel(WorkerGlobalS cope& context, WebSocketChannelClient* client, const String& sourceURL, unsigned lineNumber) 123 WorkerThreadableWebSocketChannel::WorkerThreadableWebSocketChannel(WorkerGlobalS cope& context, WebSocketChannelClient* client, const String& sourceURL, unsigned lineNumber)
114 : m_workerGlobalScope(context) 124 : m_workerGlobalScope(context)
115 , m_workerClientWrapper(ThreadableWebSocketChannelClientWrapper::create(clie nt)) 125 , m_workerClientWrapper(ThreadableWebSocketChannelClientWrapper::create(clie nt))
116 , m_bridge(Bridge::create(m_workerClientWrapper, m_workerGlobalScope)) 126 , m_bridge(Bridge::create(m_workerClientWrapper, m_workerGlobalScope))
117 , m_sourceURLAtConnection(sourceURL) 127 , m_sourceURLAtConnection(sourceURL)
118 , m_lineNumberAtConnection(lineNumber) 128 , m_lineNumberAtConnection(lineNumber)
119 { 129 {
120 m_bridge->initialize(sourceURL, lineNumber); 130 m_bridge->initialize(sourceURL, lineNumber);
121 } 131 }
122 132
123 WorkerThreadableWebSocketChannel::~WorkerThreadableWebSocketChannel() 133 WorkerThreadableWebSocketChannel::~WorkerThreadableWebSocketChannel()
124 { 134 {
125 if (m_bridge) 135 if (m_bridge)
126 m_bridge->disconnect(); 136 m_bridge->disconnect();
127 } 137 }
128 138
129 void WorkerThreadableWebSocketChannel::connect(const KURL& url, const String& pr otocol) 139 bool WorkerThreadableWebSocketChannel::connect(const KURL& url, const String& pr otocol)
130 { 140 {
131 if (m_bridge) 141 if (m_bridge)
132 m_bridge->connect(url, protocol); 142 return m_bridge->connect(url, protocol);
143 return false;
133 } 144 }
134 145
135 String WorkerThreadableWebSocketChannel::subprotocol() 146 String WorkerThreadableWebSocketChannel::subprotocol()
136 { 147 {
137 ASSERT(m_workerClientWrapper); 148 ASSERT(m_workerClientWrapper);
138 return m_workerClientWrapper->subprotocol(); 149 return m_workerClientWrapper->subprotocol();
139 } 150 }
140 151
141 String WorkerThreadableWebSocketChannel::extensions() 152 String WorkerThreadableWebSocketChannel::extensions()
142 { 153 {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 263
253 void WorkerThreadableWebSocketChannel::Peer::destroy() 264 void WorkerThreadableWebSocketChannel::Peer::destroy()
254 { 265 {
255 ASSERT(isMainThread()); 266 ASSERT(isMainThread());
256 delete this; 267 delete this;
257 } 268 }
258 269
259 void WorkerThreadableWebSocketChannel::Peer::connect(const KURL& url, const Stri ng& protocol) 270 void WorkerThreadableWebSocketChannel::Peer::connect(const KURL& url, const Stri ng& protocol)
260 { 271 {
261 ASSERT(isMainThread()); 272 ASSERT(isMainThread());
262 if (!m_mainWebSocketChannel) 273 if (!m_mainWebSocketChannel || !m_workerClientWrapper) {
263 return; 274 m_syncHelper->setConnectRequestResult(false);
264 m_mainWebSocketChannel->connect(url, protocol); 275 } else {
276 bool connectRequestResult = m_mainWebSocketChannel->connect(url, protoco l);
277 m_syncHelper->setConnectRequestResult(connectRequestResult);
278 }
279 m_syncHelper->signalWorkerThread();
265 } 280 }
266 281
267 void WorkerThreadableWebSocketChannel::Peer::send(const String& message) 282 void WorkerThreadableWebSocketChannel::Peer::send(const String& message)
268 { 283 {
269 ASSERT(isMainThread()); 284 ASSERT(isMainThread());
270 if (!m_mainWebSocketChannel || !m_workerClientWrapper) { 285 if (!m_mainWebSocketChannel || !m_workerClientWrapper) {
271 m_syncHelper->setSendRequestResult(WebSocketChannel::SendFail); 286 m_syncHelper->setSendRequestResult(WebSocketChannel::SendFail);
272 } else { 287 } else {
273 WebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel- >send(message); 288 WebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel- >send(message);
274 m_syncHelper->setSendRequestResult(sendRequestResult); 289 m_syncHelper->setSendRequestResult(sendRequestResult);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 m_syncHelper = syncHelper.get(); 480 m_syncHelper = syncHelper.get();
466 481
467 RefPtr<Bridge> protect(this); 482 RefPtr<Bridge> protect(this);
468 m_loaderProxy.postTaskToLoader(createCallbackTask(&Peer::initialize, referen ce.release(), AllowCrossThreadAccess(&m_loaderProxy), m_workerClientWrapper, sou rceURL, lineNumber, syncHelper.release())); 483 m_loaderProxy.postTaskToLoader(createCallbackTask(&Peer::initialize, referen ce.release(), AllowCrossThreadAccess(&m_loaderProxy), m_workerClientWrapper, sou rceURL, lineNumber, syncHelper.release()));
469 if (!waitForMethodCompletion()) { 484 if (!waitForMethodCompletion()) {
470 // The worker thread has been signalled to shutdown before method comple tion. 485 // The worker thread has been signalled to shutdown before method comple tion.
471 terminatePeer(); 486 terminatePeer();
472 } 487 }
473 } 488 }
474 489
475 void WorkerThreadableWebSocketChannel::Bridge::connect(const KURL& url, const St ring& protocol) 490 bool WorkerThreadableWebSocketChannel::Bridge::connect(const KURL& url, const St ring& protocol)
476 { 491 {
477 ASSERT(m_workerClientWrapper); 492 ASSERT(m_workerClientWrapper);
478 m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::connect, m_peer, url.copy(), protocol.isolatedCopy()))); 493 m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::connect, m_peer, url.copy(), protocol.isolatedCopy())));
494 RefPtr<Bridge> protect(this);
495 waitForMethodCompletion();
496 return m_syncHelper->connectRequestResult();
479 } 497 }
480 498
481 WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(cons t String& message) 499 WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(cons t String& message)
482 { 500 {
483 if (!m_workerClientWrapper || !m_workerGlobalScope) 501 if (!m_workerClientWrapper || !m_workerGlobalScope)
484 return WebSocketChannel::SendFail; 502 return WebSocketChannel::SendFail;
485 ASSERT(m_syncHelper); 503 ASSERT(m_syncHelper);
486 m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::send, m_p eer, message.isolatedCopy()))); 504 m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::send, m_p eer, message.isolatedCopy())));
487 RefPtr<Bridge> protect(this); 505 RefPtr<Bridge> protect(this);
488 waitForMethodCompletion(); 506 waitForMethodCompletion();
489 return m_syncHelper->sendRequestResult(); 507 return m_syncHelper->sendRequestResult();
490 } 508 }
491 509
492 WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(cons t ArrayBuffer& binaryData, unsigned byteOffset, unsigned byteLength) 510 WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(cons t ArrayBuffer& binaryData, unsigned byteOffset, unsigned byteLength)
493 { 511 {
494 if (!m_workerClientWrapper || !m_workerGlobalScope) 512 if (!m_workerClientWrapper || !m_workerGlobalScope)
495 return WebSocketChannel::SendFail; 513 return WebSocketChannel::SendFail;
496 ASSERT(m_syncHelper); 514 ASSERT(m_syncHelper);
497 // ArrayBuffer isn't thread-safe, hence the content of ArrayBuffer is copied into Vector<char>. 515 // ArrayBuffer isn't thread-safe, hence the content of ArrayBuffer is copied into Vector<char>.
498 OwnPtr<Vector<char> > data = adoptPtr(new Vector<char>(byteLength)); 516 OwnPtr<Vector<char> > data = adoptPtr(new Vector<char>(byteLength));
499 if (binaryData.byteLength()) 517 if (binaryData.byteLength())
500 memcpy(data->data(), static_cast<const char*>(binaryData.data()) + byteO ffset, byteLength); 518 memcpy(data->data(), static_cast<const char*>(binaryData.data()) + byteO ffset, byteLength);
519
501 m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::sendArray Buffer, m_peer, data.release()))); 520 m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::sendArray Buffer, m_peer, data.release())));
502 RefPtr<Bridge> protect(this); 521 RefPtr<Bridge> protect(this);
503 waitForMethodCompletion(); 522 waitForMethodCompletion();
504 return m_syncHelper->sendRequestResult(); 523 return m_syncHelper->sendRequestResult();
505 } 524 }
506 525
507 WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(Pass RefPtr<BlobDataHandle> data) 526 WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(Pass RefPtr<BlobDataHandle> data)
508 { 527 {
509 if (!m_workerClientWrapper || !m_workerGlobalScope) 528 if (!m_workerClientWrapper || !m_workerGlobalScope)
510 return WebSocketChannel::SendFail; 529 return WebSocketChannel::SendFail;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 } 594 }
576 595
577 void WorkerThreadableWebSocketChannel::Bridge::terminatePeer() 596 void WorkerThreadableWebSocketChannel::Bridge::terminatePeer()
578 { 597 {
579 m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::destroy, m_peer))); 598 m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::destroy, m_peer)));
580 m_workerGlobalScope = nullptr; 599 m_workerGlobalScope = nullptr;
581 m_syncHelper = 0; 600 m_syncHelper = 0;
582 } 601 }
583 602
584 } // namespace WebCore 603 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/websockets/WorkerThreadableWebSocketChannel.h ('k') | Tools/Scripts/webkitpy/layout_tests/port/base.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698