Chromium Code Reviews| Index: chrome/common/extensions/api/identity/oauth2_manifest_handler.cc |
| =================================================================== |
| --- chrome/common/extensions/api/identity/oauth2_manifest_handler.cc (revision 0) |
| +++ chrome/common/extensions/api/identity/oauth2_manifest_handler.cc (revision 0) |
| @@ -0,0 +1,81 @@ |
| +// Copyright (c) 2012 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/common/extensions/api/identity/oauth2_manifest_handler.h" |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/string_number_conversions.h" |
|
Devlin
2013/01/14 20:18:34
Where is this used?
SanjoyPal
2013/01/16 19:10:52
Done.
|
| +#include "base/utf_string_conversions.h" |
| +#include "base/values.h" |
| +#include "chrome/common/extensions/extension_manifest_constants.h" |
| +#include "extensions/common/error_utils.h" |
| +#include "ui/base/l10n/l10n_util.h" |
|
Devlin
2013/01/14 20:18:34
Where is this used?
SanjoyPal
2013/01/16 19:10:52
Done.
|
| + |
| +namespace keys = extension_manifest_keys; |
| +namespace errors = extension_manifest_errors; |
| + |
| +namespace { |
| + |
| +// Manifest keys. |
| +const char kClientId[] = "client_id"; |
| +const char kScopes[] = "scopes"; |
| + |
| +} // namespace |
| + |
| +namespace extensions { |
| + |
| +OAuth2Info::OAuth2Info() {} |
| +OAuth2Info::~OAuth2Info() {} |
| + |
| +// static |
| +const OAuth2Info* OAuth2Info::GetOAuth2Info(const Extension* extension) { |
| + OAuth2Info* info = static_cast<OAuth2Info*>( |
| + extension->GetManifestData(keys::kOAuth2)); |
| + DCHECK(info); |
|
Devlin
2013/01/14 20:18:34
This should be a CHECK, not a DCHECK (since any ac
SanjoyPal
2013/01/16 19:10:52
Done.
|
| + return info; |
| +} |
| + |
| +OAuth2ManifestHandler::OAuth2ManifestHandler() { |
| +} |
| + |
| +OAuth2ManifestHandler::~OAuth2ManifestHandler() { |
| +} |
| + |
| +bool OAuth2ManifestHandler::Parse(const base::Value* value, |
| + Extension* extension, string16* error) { |
| + scoped_ptr<OAuth2Info> info(new OAuth2Info); |
| + const DictionaryValue* dict = NULL; |
| + if (!value->GetAsDictionary(&dict) || |
| + !dict->GetString(kClientId, &info->client_id) || |
| + info->client_id.empty()) { |
| + *error = ASCIIToUTF16(errors::kInvalidOAuth2ClientId); |
| + return false; |
| + } |
| + |
| + const ListValue* list = NULL; |
| + if (!dict->GetList(kScopes, &list)) { |
| + *error = ASCIIToUTF16(errors::kInvalidOAuth2Scopes); |
| + return false; |
| + } |
| + |
| + for (size_t i = 0; i < list->GetSize(); ++i) { |
| + std::string scope; |
| + if (!list->GetString(i, &scope)) { |
| + *error = ASCIIToUTF16(errors::kInvalidOAuth2Scopes); |
| + return false; |
| + } |
| + info->scopes.push_back(scope); |
| + } |
| + |
| + extension->SetManifestData(keys::kOAuth2, info.release()); |
| + return true; |
| +} |
| + |
| +bool OAuth2ManifestHandler::HasNoKey(Extension* extension, string16* error) { |
| + scoped_ptr<OAuth2Info> info(new OAuth2Info); |
|
Devlin
2013/01/14 20:18:34
This can be simplified to
extension->SetManifestDa
SanjoyPal
2013/01/16 19:10:52
Done.
|
| + extension->SetManifestData(keys::kOAuth2, info.release()); |
| + return true; |
| +} |
| + |
| +} // namespace extensions |