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

Unified Diff: webkit/child/websocket_handle_impl.cc

Issue 22815034: Introduce webkit_glue bridges for the new WebSocket Implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: webkit/child/websocket_handle_impl.cc
diff --git a/webkit/child/websocket_handle_impl.cc b/webkit/child/websocket_handle_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a8a828b942c67d048e048ab80e1dd13b7d277f72
--- /dev/null
+++ b/webkit/child/websocket_handle_impl.cc
@@ -0,0 +1,219 @@
+// Copyright (c) 2013 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 "webkit/child/websocket_handle_impl.h"
+
+#include <string>
+#include <vector>
+
+#include "base/compiler_specific.h"
+#include "base/logging.h"
tyoshino (SeeGerritForStatus) 2013/09/03 07:18:30 not used?
yhirano 2013/09/03 09:12:08 DCHECK is defined in the file.
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/string16.h"
+#include "third_party/WebKit/public/platform/WebData.h"
+#include "third_party/WebKit/public/platform/WebSocketHandle.h"
+#include "third_party/WebKit/public/platform/WebSocketHandleClient.h"
+#include "third_party/WebKit/public/platform/WebString.h"
+#include "third_party/WebKit/public/platform/WebURL.h"
+#include "webkit/child/webkitplatformsupport_impl.h"
+#include "webkit/child/websocket_handle_bridge.h"
+#include "webkit/child/websocket_handle_delegate.h"
+
+using WebKit::WebString;
+using WebKit::WebURL;
+using WebKit::WebVector;
+using WebKit::WebSocketHandle;
+using WebKit::WebSocketHandleClient;
+
+namespace webkit_glue {
+
+class WebSocketHandleImpl::Context
+ : public base::RefCounted<Context>,
+ public WebSocketHandleDelegate {
+ public:
+ explicit Context(WebSocketHandle* handle)
+ : is_active_(false),
+ handle_(handle),
+ client_(NULL) {}
+
+ void Connect(const GURL& url,
+ const std::vector<std::string>& protocols,
+ const GURL& origin,
+ WebSocketHandleClient* client);
+ void Send(bool fin,
+ WebSocketHandleBridge::MessageType type,
+ const char* data,
+ size_t size);
+ void FlowControl(int64_t quota);
+ void Close(unsigned short code, const std::string& reason);
+
+ // WebSocketHandleDelegate functions.
+ virtual void DidConnect(bool fail,
+ const std::string& protocol,
+ const std::string& extensions) OVERRIDE;
+ virtual void DidReceiveData(bool fin,
+ WebSocketHandleBridge::MessageType type,
+ const char* data,
+ size_t size) OVERRIDE;
+ virtual void DidReceiveFlowControl(int64_t quota) OVERRIDE;
+ virtual void DidClose(unsigned short code,
+ const std::string& reason) OVERRIDE;
+
+ private:
+ virtual ~Context();
+ friend class base::RefCounted<WebSocketHandleImpl::Context>;
+ bool is_active_;
+ WebSocketHandle* handle_;
+ WebSocketHandleClient* client_;
+ scoped_refptr<WebSocketHandleBridge> bridge_;
+};
+
+void WebSocketHandleImpl::Context::Connect(
+ const GURL& url,
+ const std::vector<std::string>& protocols,
+ const GURL& origin,
+ WebSocketHandleClient* client) {
+ DCHECK(!is_active_);
+ is_active_ = true;
+ client_ = client;
+ bridge_->Connect(url, protocols, origin, this);
tyoshino (SeeGerritForStatus) 2013/09/03 07:58:10 create bridge_. (told offline)
yhirano 2013/09/03 09:12:08 Done.
+}
+
+WebSocketHandleImpl::Context::~Context() {
+ if (bridge_) {
tyoshino (SeeGerritForStatus) 2013/09/03 07:18:30 Remove {}?
yhirano 2013/09/03 09:12:08 Done.
+ bridge_->Disconnect();
+ }
+}
+
+void WebSocketHandleImpl::Context::Send(bool fin,
+ WebSocketHandleBridge::MessageType type,
+ const char* data,
+ size_t size) {
+ if (!is_active_) {
tyoshino (SeeGerritForStatus) 2013/09/03 07:18:30 ditto
yhirano 2013/09/03 09:12:08 Done.
+ return;
+ }
+ bridge_->Send(fin, type, data, size);
+}
+
+void WebSocketHandleImpl::Context::FlowControl(int64_t quota) {
+ if (!is_active_) {
tyoshino (SeeGerritForStatus) 2013/09/03 07:18:30 ditto
yhirano 2013/09/03 09:12:08 Done.
+ return;
+ }
+ bridge_->FlowControl(quota);
+}
+
+void WebSocketHandleImpl::Context::Close(unsigned short code,
+ const std::string& reason) {
tyoshino (SeeGerritForStatus) 2013/09/03 07:18:30 indent
yhirano 2013/09/03 09:12:08 Done.
+ if (!is_active_) {
tyoshino (SeeGerritForStatus) 2013/09/03 07:18:30 ditto
yhirano 2013/09/03 09:12:08 Done.
+ return;
+ }
+ bridge_->Close(code, reason);
+}
+
+void WebSocketHandleImpl::Context::DidConnect(bool fail,
+ const std::string& protocol,
+ const std::string& extensions) {
+ if (!is_active_) {
tyoshino (SeeGerritForStatus) 2013/09/03 07:18:30 Remove {}?
yhirano 2013/09/03 09:12:08 Done.
+ return;
+ }
+ WebString protocol_to_pass = WebString::fromUTF8(protocol);
+ WebString extensions_to_pass = WebString::fromUTF8(extensions);
+ client_->didConnect(handle_, fail, protocol_to_pass, extensions_to_pass);
+}
+
+void WebSocketHandleImpl::Context::DidReceiveData(
+ bool fin,
+ WebSocketHandleBridge::MessageType type,
+ const char* data,
+ size_t size) {
+ if (!is_active_) {
tyoshino (SeeGerritForStatus) 2013/09/03 07:18:30 ditto
yhirano 2013/09/03 09:12:08 Done.
+ return;
+ }
+ WebSocketHandle::MessageType type_to_pass;
+ switch (type) {
+ case WebSocketHandleBridge::MESSAGE_TYPE_CONTINUATION:
+ type_to_pass = WebSocketHandle::MessageTypeContinuation;
+ break;
+ case WebSocketHandleBridge::MESSAGE_TYPE_TEXT:
+ type_to_pass = WebSocketHandle::MessageTypeText;
+ break;
+ case WebSocketHandleBridge::MESSAGE_TYPE_BINARY:
+ type_to_pass = WebSocketHandle::MessageTypeBinary;
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+
+ client_->didReceiveData(handle_, fin, type_to_pass, data, size);
+}
+
+void WebSocketHandleImpl::Context::DidReceiveFlowControl(int64_t quota) {
+ if (!is_active_) {
tyoshino (SeeGerritForStatus) 2013/09/03 07:18:30 ditto
yhirano 2013/09/03 09:12:08 Done.
+ return;
+ }
+ client_->didReceiveFlowControl(handle_, quota);
+}
+
+void WebSocketHandleImpl::Context::DidClose(unsigned short code,
+ const std::string& reason) {
+ if (!is_active_) {
tyoshino (SeeGerritForStatus) 2013/09/03 07:18:30 ditto
tyoshino (SeeGerritForStatus) 2013/09/03 07:58:10 unset is_active_? (told offline)
yhirano 2013/09/03 09:12:08 is_active_ can be replaced by (bridge_ != NULL) an
+ return;
+ }
+ WebString reason_to_pass = WebString::fromUTF8(reason);
+ client_->didClose(handle_, code, reason_to_pass);
+}
+
+WebSocketHandleImpl::WebSocketHandleImpl(WebKitPlatformSupportImpl* platform)
+ : context_(new Context(this)),
+ platform_(platform) {
+}
+
+WebSocketHandleImpl::~WebSocketHandleImpl() {}
+
+void WebSocketHandleImpl::connect(const WebURL& url,
+ const WebVector<WebString>& protocols,
+ const WebString& origin,
+ WebSocketHandleClient* client) {
+ std::vector<std::string> protocols_to_pass;
+ for (size_t i = 0; i < protocols.size(); ++i) {
tyoshino (SeeGerritForStatus) 2013/09/03 07:18:30 ditto
yhirano 2013/09/03 09:12:08 Done.
+ protocols_to_pass.push_back(protocols[i].utf8());
+ }
+ GURL origin_to_pass(origin.utf8());
tyoshino (SeeGerritForStatus) 2013/09/03 07:18:30 just use WebURL's operator GURL()?
tyoshino (SeeGerritForStatus) 2013/09/03 07:58:10 I was wrong. Never mind. (told offline)
+ context_->Connect(url, protocols_to_pass, origin_to_pass, client);
+}
+
+void WebSocketHandleImpl::send(bool fin,
+ WebSocketHandle::MessageType type,
+ const char* data,
+ size_t size) {
+ WebSocketHandleBridge::MessageType type_to_pass;
+ switch (type) {
+ case WebSocketHandle::MessageTypeContinuation:
+ type_to_pass = WebSocketHandleBridge::MESSAGE_TYPE_CONTINUATION;
+ break;
+ case WebSocketHandle::MessageTypeText:
+ type_to_pass = WebSocketHandleBridge::MESSAGE_TYPE_TEXT;
+ break;
+ case WebSocketHandle::MessageTypeBinary:
+ type_to_pass = WebSocketHandleBridge::MESSAGE_TYPE_BINARY;
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ context_->Send(fin, type_to_pass, data, size);
+}
+
+void WebSocketHandleImpl::flowControl(int64_t quota) {
+ context_->FlowControl(quota);
+}
+
+void WebSocketHandleImpl::close(unsigned short code, const WebString& reason) {
+ std::string reason_to_pass = reason.utf8();
+ context_->Close(code, reason_to_pass);
+}
+
+} // namespace webkit_glue

Powered by Google App Engine
This is Rietveld 408576698