| Index: chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc
|
| diff --git a/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d5029cce0c50ea51ad8923ade97ebb2086ccf69d
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc
|
| @@ -0,0 +1,135 @@
|
| +// Copyright 2014 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/api/enterprise_platform_keys/enterprise_platform_keys_api.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "chrome/browser/extensions/api/enterprise_platform_keys/token_method_nss.h"
|
| +#include "chrome/common/extensions/api/enterprise_platform_keys.h"
|
| +#include "chrome/common/extensions/api/enterprise_platform_keys_internal.h"
|
| +
|
| +namespace {
|
| +const char kErrorInvalidToken[] = "Token is invalid.";
|
| +}
|
| +
|
| +namespace extensions {
|
| +
|
| +namespace enterprise_platform_keys {
|
| +
|
| +namespace impl = nss;
|
| +
|
| +namespace api_epk = api::enterprise_platform_keys;
|
| +namespace api_epki = api::enterprise_platform_keys_internal;
|
| +
|
| +const char kTokenIdUser[] = "user";
|
| +
|
| +TokenMethodExtensionFunction::TokenMethodExtensionFunction() {
|
| +}
|
| +
|
| +TokenMethodExtensionFunction::~TokenMethodExtensionFunction() {
|
| +}
|
| +
|
| +void TokenMethodExtensionFunction::SendResponse(bool success) {
|
| + ChromeAsyncExtensionFunction::SendResponse(success);
|
| +}
|
| +
|
| +void TokenMethodExtensionFunction::SetResults(
|
| + scoped_ptr<base::ListValue> results) {
|
| + results_ = results.Pass();
|
| +}
|
| +
|
| +bool TokenMethodExtensionFunction::ValidateToken(const std::string& token_id) {
|
| + // For now, the user token is the only valid one.
|
| + if (token_id != kTokenIdUser) {
|
| + SetError(kErrorInvalidToken);
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +Generate::Generate() {
|
| +}
|
| +Generate::~Generate() {
|
| +}
|
| +
|
| +bool Generate::RunImpl() {
|
| + scoped_ptr<api_epki::GenerateKey::Params> params(
|
| + api_epki::GenerateKey::Params::Create(*args_));
|
| + EXTENSION_FUNCTION_VALIDATE(params && ValidateToken(params->token_id));
|
| + impl::Generate(this, params.Pass());
|
| + return true;
|
| +}
|
| +
|
| +Sign::Sign() {
|
| +}
|
| +
|
| +Sign::~Sign() {
|
| +}
|
| +
|
| +bool Sign::RunImpl() {
|
| + scoped_ptr<api_epki::Sign::Params> params(
|
| + api_epki::Sign::Params::Create(*args_));
|
| + EXTENSION_FUNCTION_VALIDATE(params && ValidateToken(params->token_id));
|
| + impl::Sign(this, params.Pass());
|
| + return true;
|
| +}
|
| +
|
| +GetCerts::GetCerts() {
|
| +}
|
| +
|
| +GetCerts::~GetCerts() {
|
| +}
|
| +
|
| +bool GetCerts::RunImpl() {
|
| + scoped_ptr<api_epk::GetCertificates::Params> params(
|
| + api_epk::GetCertificates::Params::Create(*args_));
|
| + EXTENSION_FUNCTION_VALIDATE(params && ValidateToken(params->token_id));
|
| + impl::GetCerts(this, params.Pass());
|
| + return true;
|
| +}
|
| +
|
| +ImportCert::ImportCert() {
|
| +}
|
| +
|
| +ImportCert::~ImportCert() {
|
| +}
|
| +
|
| +bool ImportCert::RunImpl() {
|
| + scoped_ptr<api_epk::ImportCertificate::Params> params(
|
| + api_epk::ImportCertificate::Params::Create(*args_));
|
| + EXTENSION_FUNCTION_VALIDATE(params && ValidateToken(params->token_id));
|
| + impl::Import(this, params.Pass());
|
| + return true;
|
| +}
|
| +
|
| +RemoveCert::RemoveCert() {
|
| +}
|
| +
|
| +RemoveCert::~RemoveCert() {
|
| +}
|
| +
|
| +bool RemoveCert::RunImpl() {
|
| + scoped_ptr<api_epk::RemoveCertificate::Params> params(
|
| + api_epk::RemoveCertificate::Params::Create(*args_));
|
| + EXTENSION_FUNCTION_VALIDATE(params && ValidateToken(params->token_id));
|
| + impl::Remove(this, params.Pass());
|
| + return true;
|
| +}
|
| +
|
| +GetTokens::~GetTokens() {
|
| +}
|
| +
|
| +bool GetTokens::RunImpl() {
|
| + EXTENSION_FUNCTION_VALIDATE(args_->empty());
|
| +
|
| + std::vector<std::string> token_ids;
|
| + token_ids.push_back(kTokenIdUser);
|
| + results_ = api_epki::GetTokens::Results::Create(token_ids);
|
| + SendResponse(true);
|
| + return true;
|
| +}
|
| +
|
| +} // namespace enterprise_platform_keys
|
| +
|
| +} // namespace extensions
|
|
|