Index: chrome/browser/extensions/extension_internal_auth_api.cc |
diff --git a/chrome/browser/extensions/extension_internal_auth_api.cc b/chrome/browser/extensions/extension_internal_auth_api.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7633ed34fe2cd61ac53ca9d27732ac9390cd9f30 |
--- /dev/null |
+++ b/chrome/browser/extensions/extension_internal_auth_api.cc |
@@ -0,0 +1,55 @@ |
+// 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_internal_auth_api.h" |
+ |
+#include "base/logging.h" |
+#include "base/values.h" |
+#include "chrome/browser/internal_auth.h" |
+ |
+namespace { |
+ |
+// Checks credentials and in case of positive check fills var=value map. |
+bool CheckCredentials( |
+ const std::string& extension_id, |
+ const std::vector<std::string>& arg_list, |
+ std::map<std::string, std::string>* out) { |
+ DCHECK(out); |
+ out->clear(); |
+ |
+ char k90ttyExtensionId[] = "cigbjabahnfnnmplhmjeolnhobhfjggp"; |
+ if (extension_id != k90ttyExtensionId) |
+ return false; |
+ |
+ std::map<std::string, std::string> map; |
+ if (!browser::ConvertArgListToVarValueMap(arg_list, &map)) |
+ return false; |
+ if (map.size() != 2 || |
+ map["port"] != "22" || |
+ map["hostname"].empty()) { |
+ return false; |
+ } |
+ out->swap(map); |
+ return true; |
+} |
+ |
+} // namespace |
+ |
+bool InternalAuthGetTokenFunction::RunImpl() { |
+ std::vector<std::string> arg_list; |
zel
2011/03/29 05:31:34
why string array here? aren't you just passing hos
Denis Lagno
2011/04/04 18:18:02
Done.
|
+ for (size_t i = 0; i < args_->GetSize(); ++i) { |
+ arg_list.push_back(std::string()); |
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(i, &arg_list.back())); |
+ } |
+ |
+ std::map<std::string, std::string> map; |
+ std::string id = extension_id(); |
+ if (CheckCredentials(id, arg_list, &map)) { |
+ StringValue* token = Value::CreateStringValue( |
+ browser::InternalAuthGeneration::GenerateToken(id, map)); |
+ result_.reset(token); |
+ } |
+ return true; |
+} |
+ |