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

Unified Diff: chrome/browser/extensions/extension_web_socket_proxy_private_api.cc

Issue 6683060: Private API for extensions like ssh-client that need access to TCP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed bugs + added apitest + rebased Created 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_web_socket_proxy_private_api.cc
diff --git a/chrome/browser/extensions/extension_web_socket_proxy_private_api.cc b/chrome/browser/extensions/extension_web_socket_proxy_private_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c3296f9a7254820907d4a87f153761dafd32f141
--- /dev/null
+++ b/chrome/browser/extensions/extension_web_socket_proxy_private_api.cc
@@ -0,0 +1,86 @@
+// Copyright (c) 2011 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 "chrome/browser/extensions/extension_web_socket_proxy_private_api.h"
+
+#include "base/logging.h"
+#include "base/values.h"
+#include "base/string_number_conversions.h"
+#include "chrome/browser/internal_auth.h"
+#include "chrome/common/extensions/extension.h"
+#include "content/common/notification_service.h"
+
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/web_socket_proxy_controller.h"
+#endif
+
+bool WebSocketProxyPrivateGetPassportForTCPFunction::CheckCredentials(
+ const std::string& hostname, int port) {
+ if (GetExtension() == NULL ||
+ GetExtension()->location() != Extension::COMPONENT) {
+ NOTREACHED();
+ return false;
+ }
+ return true;
+}
+
+bool WebSocketProxyPrivateGetPassportForTCPFunction::RunImpl() {
+ bool delay_response = false;
+ result_.reset(Value::CreateStringValue(""));
+
+#if defined(OS_CHROMEOS)
+ std::string hostname;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &hostname));
+ int port = -1;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &port));
+
+ if (CheckCredentials(hostname, port)) {
+ if (!chromeos::WebSocketProxyController::IsInitiated()) {
+ delay_response = true;
+ registrar_.Add(
+ this, NotificationType::WEB_SOCKET_PROXY_STARTED,
+ NotificationService::AllSources());
+ chromeos::WebSocketProxyController::Initiate();
+ }
+
+ std::map<std::string, std::string> map;
+ map["hostname"] = hostname;
+ map["port"] = base::IntToString(port);
+ map["extension_id"] = extension_id();
+ StringValue* passport = Value::CreateStringValue(
+ browser::InternalAuthGeneration::GeneratePassport(
+ "web_socket_proxy", map));
+ result_.reset(passport);
+ }
+#endif // defined(OS_CHROMEOS)
+
+ // TODO(dilmah): get idea why notification is not observed and timer callback
+ // is not called and remove this line.
+ delay_response = false;
Dmitry Polukhin 2011/05/16 09:41:39 It looks like some debug code.
+
+ if (delay_response) {
+ timer_.Start(base::TimeDelta::FromSeconds(3),
+ this, &WebSocketProxyPrivateGetPassportForTCPFunction::Finalize);
+ } else {
+ Finalize();
+ }
+ return true;
+}
+
+void WebSocketProxyPrivateGetPassportForTCPFunction::Observe(
+ NotificationType type, const NotificationSource& source,
+ const NotificationDetails& details) {
+#if defined(OS_CHROMEOS)
+ DCHECK(type.value == NotificationType::WEB_SOCKET_PROXY_STARTED);
+#else
+ NOTREACHED();
+#endif
+ timer_.Stop(); // Cancel timeout timer.
+ Finalize();
+}
+
+void WebSocketProxyPrivateGetPassportForTCPFunction::Finalize() {
+ SendResponse(true);
+}
+

Powered by Google App Engine
This is Rietveld 408576698