Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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/utf_string_conversions.h" | |
| 9 #include "base/values.h" | |
| 10 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 11 #include "extensions/common/error_utils.h" | |
| 12 | |
| 13 namespace keys = extension_manifest_keys; | |
| 14 namespace errors = extension_manifest_errors; | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 // Manifest keys. | |
| 19 const char kClientId[] = "client_id"; | |
| 20 const char kScopes[] = "scopes"; | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 namespace extensions { | |
| 25 | |
| 26 OAuth2Info::OAuth2Info() {} | |
| 27 OAuth2Info::~OAuth2Info() {} | |
| 28 | |
| 29 // static | |
| 30 const OAuth2Info& OAuth2Info::GetOAuth2Info(const Extension* extension) { | |
|
Devlin
2013/01/16 19:36:12
I interpreted Yoyo's comment as "if it's never goi
SanjoyPal
2013/01/16 20:11:28
Do you mean, we should return a default-constructe
Devlin
2013/01/16 20:26:39
Yes and no. If we return a const &, it should alwa
Yoyo Zhou
2013/01/16 21:06:12
Yes, that's what I meant. You should have an empty
SanjoyPal
2013/01/16 23:03:13
Done.
| |
| 31 OAuth2Info* info = static_cast<OAuth2Info*>( | |
| 32 extension->GetManifestData(keys::kOAuth2)); | |
| 33 CHECK(info); | |
| 34 return *info; | |
| 35 } | |
| 36 | |
| 37 OAuth2ManifestHandler::OAuth2ManifestHandler() { | |
| 38 } | |
| 39 | |
| 40 OAuth2ManifestHandler::~OAuth2ManifestHandler() { | |
| 41 } | |
| 42 | |
| 43 bool OAuth2ManifestHandler::Parse(const base::Value* value, | |
| 44 Extension* extension, string16* error) { | |
| 45 scoped_ptr<OAuth2Info> info(new OAuth2Info); | |
| 46 const DictionaryValue* dict = NULL; | |
| 47 if (!value->GetAsDictionary(&dict) || | |
| 48 !dict->GetString(kClientId, &info->client_id) || | |
| 49 info->client_id.empty()) { | |
| 50 *error = ASCIIToUTF16(errors::kInvalidOAuth2ClientId); | |
| 51 return false; | |
| 52 } | |
| 53 | |
| 54 const ListValue* list = NULL; | |
| 55 if (!dict->GetList(kScopes, &list)) { | |
| 56 *error = ASCIIToUTF16(errors::kInvalidOAuth2Scopes); | |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 for (size_t i = 0; i < list->GetSize(); ++i) { | |
| 61 std::string scope; | |
| 62 if (!list->GetString(i, &scope)) { | |
| 63 *error = ASCIIToUTF16(errors::kInvalidOAuth2Scopes); | |
| 64 return false; | |
| 65 } | |
| 66 info->scopes.push_back(scope); | |
| 67 } | |
| 68 | |
| 69 extension->SetManifestData(keys::kOAuth2, info.release()); | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 bool OAuth2ManifestHandler::HasNoKey(Extension* extension, string16* error) { | |
| 74 extension->SetManifestData(keys::kOAuth2, new OAuth2Info); | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 } // namespace extensions | |
| OLD | NEW |