Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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/common/extensions/api/identity/oauth2_manifest_handler.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #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.
| |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "base/values.h" | |
| 11 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 12 #include "extensions/common/error_utils.h" | |
| 13 #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.
| |
| 14 | |
| 15 namespace keys = extension_manifest_keys; | |
| 16 namespace errors = extension_manifest_errors; | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 // Manifest keys. | |
| 21 const char kClientId[] = "client_id"; | |
| 22 const char kScopes[] = "scopes"; | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 namespace extensions { | |
| 27 | |
| 28 OAuth2Info::OAuth2Info() {} | |
| 29 OAuth2Info::~OAuth2Info() {} | |
| 30 | |
| 31 // static | |
| 32 const OAuth2Info* OAuth2Info::GetOAuth2Info(const Extension* extension) { | |
| 33 OAuth2Info* info = static_cast<OAuth2Info*>( | |
| 34 extension->GetManifestData(keys::kOAuth2)); | |
| 35 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.
| |
| 36 return info; | |
| 37 } | |
| 38 | |
| 39 OAuth2ManifestHandler::OAuth2ManifestHandler() { | |
| 40 } | |
| 41 | |
| 42 OAuth2ManifestHandler::~OAuth2ManifestHandler() { | |
| 43 } | |
| 44 | |
| 45 bool OAuth2ManifestHandler::Parse(const base::Value* value, | |
| 46 Extension* extension, string16* error) { | |
| 47 scoped_ptr<OAuth2Info> info(new OAuth2Info); | |
| 48 const DictionaryValue* dict = NULL; | |
| 49 if (!value->GetAsDictionary(&dict) || | |
| 50 !dict->GetString(kClientId, &info->client_id) || | |
| 51 info->client_id.empty()) { | |
| 52 *error = ASCIIToUTF16(errors::kInvalidOAuth2ClientId); | |
| 53 return false; | |
| 54 } | |
| 55 | |
| 56 const ListValue* list = NULL; | |
| 57 if (!dict->GetList(kScopes, &list)) { | |
| 58 *error = ASCIIToUTF16(errors::kInvalidOAuth2Scopes); | |
| 59 return false; | |
| 60 } | |
| 61 | |
| 62 for (size_t i = 0; i < list->GetSize(); ++i) { | |
| 63 std::string scope; | |
| 64 if (!list->GetString(i, &scope)) { | |
| 65 *error = ASCIIToUTF16(errors::kInvalidOAuth2Scopes); | |
| 66 return false; | |
| 67 } | |
| 68 info->scopes.push_back(scope); | |
| 69 } | |
| 70 | |
| 71 extension->SetManifestData(keys::kOAuth2, info.release()); | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 bool OAuth2ManifestHandler::HasNoKey(Extension* extension, string16* error) { | |
| 76 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.
| |
| 77 extension->SetManifestData(keys::kOAuth2, info.release()); | |
| 78 return true; | |
| 79 } | |
| 80 | |
| 81 } // namespace extensions | |
| OLD | NEW |