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/lazy_instance.h" | |
8 #include "base/memory/scoped_ptr.h" | |
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 | |
14 namespace keys = extension_manifest_keys; | |
15 namespace errors = extension_manifest_errors; | |
16 | |
17 namespace { | |
18 | |
19 // Manifest keys. | |
20 const char kClientId[] = "client_id"; | |
21 const char kScopes[] = "scopes"; | |
22 | |
23 } // namespace | |
24 | |
25 namespace extensions { | |
26 | |
27 OAuth2Info::OAuth2Info() {} | |
28 OAuth2Info::~OAuth2Info() {} | |
29 | |
30 static base::LazyInstance<OAuth2Info> g_empty_oauth2_info = | |
31 LAZY_INSTANCE_INITIALIZER; | |
32 | |
33 // static | |
34 const OAuth2Info& OAuth2Info::GetOAuth2Info(const Extension* extension) { | |
35 OAuth2Info* info = static_cast<OAuth2Info*>( | |
36 extension->GetManifestData(keys::kOAuth2)); | |
37 return info ? *info : g_empty_oauth2_info.Get(); | |
38 } | |
39 | |
40 OAuth2ManifestHandler::OAuth2ManifestHandler() { | |
41 } | |
42 | |
43 OAuth2ManifestHandler::~OAuth2ManifestHandler() { | |
44 } | |
45 | |
46 bool OAuth2ManifestHandler::Parse(const base::Value* value, | |
47 Extension* extension, string16* error) { | |
48 scoped_ptr<OAuth2Info> info(new OAuth2Info); | |
49 const DictionaryValue* dict = NULL; | |
50 if (!value->GetAsDictionary(&dict) || | |
51 !dict->GetString(kClientId, &info->client_id) || | |
52 info->client_id.empty()) { | |
53 *error = ASCIIToUTF16(errors::kInvalidOAuth2ClientId); | |
54 return false; | |
55 } | |
56 | |
57 const ListValue* list = NULL; | |
58 if (!dict->GetList(kScopes, &list)) { | |
59 *error = ASCIIToUTF16(errors::kInvalidOAuth2Scopes); | |
60 return false; | |
61 } | |
62 | |
63 for (size_t i = 0; i < list->GetSize(); ++i) { | |
64 std::string scope; | |
65 if (!list->GetString(i, &scope)) { | |
66 *error = ASCIIToUTF16(errors::kInvalidOAuth2Scopes); | |
67 return false; | |
68 } | |
69 info->scopes.push_back(scope); | |
70 } | |
71 | |
72 extension->SetManifestData(keys::kOAuth2, info.release()); | |
73 return true; | |
74 } | |
75 | |
76 bool OAuth2ManifestHandler::HasNoKey(Extension* extension, string16* error) { | |
Devlin
2013/01/16 23:25:40
This is no longer needed (if the extension doesn't
SanjoyPal
2013/01/17 00:11:13
Done.
| |
77 extension->SetManifestData(keys::kOAuth2, new OAuth2Info); | |
78 return true; | |
79 } | |
80 | |
81 } // namespace extensions | |
OLD | NEW |