Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/extensions/extension_web_socket_proxy_private_api.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/values.h" | |
| 9 #include "base/string_number_conversions.h" | |
| 10 #include "chrome/browser/internal_auth.h" | |
| 11 #include "chrome/common/extensions/extension.h" | |
| 12 #include "content/common/notification_service.h" | |
| 13 | |
| 14 #if defined(OS_CHROMEOS) | |
| 15 #include "chrome/browser/chromeos/web_socket_proxy_controller.h" | |
| 16 #endif | |
| 17 | |
| 18 bool WebSocketProxyPrivateGetPassportForTCPFunction::CheckCredentials( | |
| 19 const std::string& hostname, int port) { | |
| 20 if (GetExtension() == NULL || | |
| 21 GetExtension()->location() != Extension::COMPONENT) { | |
| 22 NOTREACHED(); | |
| 23 return false; | |
| 24 } | |
| 25 return true; | |
| 26 } | |
| 27 | |
| 28 bool WebSocketProxyPrivateGetPassportForTCPFunction::RunImpl() { | |
| 29 bool delay_response = false; | |
| 30 result_.reset(Value::CreateStringValue("")); | |
| 31 | |
| 32 #if defined(OS_CHROMEOS) | |
| 33 std::string hostname; | |
| 34 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &hostname)); | |
| 35 int port = -1; | |
| 36 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &port)); | |
| 37 | |
| 38 if (CheckCredentials(hostname, port)) { | |
| 39 if (!chromeos::WebSocketProxyController::IsInitiated()) { | |
| 40 delay_response = true; | |
| 41 registrar_.Add( | |
| 42 this, NotificationType::WEB_SOCKET_PROXY_STARTED, | |
| 43 NotificationService::AllSources()); | |
| 44 chromeos::WebSocketProxyController::Initiate(); | |
| 45 } | |
| 46 | |
| 47 std::map<std::string, std::string> map; | |
| 48 map["hostname"] = hostname; | |
| 49 map["port"] = base::IntToString(port); | |
| 50 map["extension_id"] = extension_id(); | |
| 51 StringValue* passport = Value::CreateStringValue( | |
| 52 browser::InternalAuthGeneration::GeneratePassport( | |
| 53 "web_socket_proxy", map)); | |
| 54 result_.reset(passport); | |
| 55 } | |
| 56 #endif // defined(OS_CHROMEOS) | |
| 57 | |
| 58 // TODO(dilmah): get idea why notification is not observed and timer callback | |
| 59 // is not called and remove this line. | |
| 60 delay_response = false; | |
|
Dmitry Polukhin
2011/05/16 09:41:39
It looks like some debug code.
| |
| 61 | |
| 62 if (delay_response) { | |
| 63 timer_.Start(base::TimeDelta::FromSeconds(3), | |
| 64 this, &WebSocketProxyPrivateGetPassportForTCPFunction::Finalize); | |
| 65 } else { | |
| 66 Finalize(); | |
| 67 } | |
| 68 return true; | |
| 69 } | |
| 70 | |
| 71 void WebSocketProxyPrivateGetPassportForTCPFunction::Observe( | |
| 72 NotificationType type, const NotificationSource& source, | |
| 73 const NotificationDetails& details) { | |
| 74 #if defined(OS_CHROMEOS) | |
| 75 DCHECK(type.value == NotificationType::WEB_SOCKET_PROXY_STARTED); | |
| 76 #else | |
| 77 NOTREACHED(); | |
| 78 #endif | |
| 79 timer_.Stop(); // Cancel timeout timer. | |
| 80 Finalize(); | |
| 81 } | |
| 82 | |
| 83 void WebSocketProxyPrivateGetPassportForTCPFunction::Finalize() { | |
| 84 SendResponse(true); | |
| 85 } | |
| 86 | |
| OLD | NEW |