Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: extensions/renderer/api_custom_types.cc

Issue 2718543004: [Extensions Bindings] Add ChromeSetting custom type (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 "extensions/renderer/api_custom_types.h"
6
7 #include <map>
8 #include <memory>
9 #include <string>
10
11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
13 #include "base/strings/stringprintf.h"
14 #include "extensions/common/extension_api.h"
15 #include "extensions/renderer/api_signature.h"
16
17 namespace extensions {
18 namespace api_custom_types {
19
20 const APISignature& GetFunctionSchema(base::StringPiece api_name,
21 base::StringPiece type_name,
Devlin 2017/02/24 16:19:28 Cut and paste from storage_area.cc
22 base::StringPiece function_name) {
23 using SignatureMap = std::map<std::string, std::unique_ptr<APISignature>>;
24 CR_DEFINE_STATIC_LOCAL(SignatureMap, signatures, ());
jbroman 2017/02/24 18:08:45 Danger, Will Robinson! IIUC, this could be called
Devlin 2017/02/24 20:12:28 Ah, right, forgot that with workers this can be ca
25
26 std::string full_name = base::StringPrintf(
27 "%s.%s.%s", api_name.data(), type_name.data(), function_name.data());
28 auto iter = signatures.find(full_name);
29 if (iter != signatures.end())
30 return *iter->second;
31
32 const base::DictionaryValue* full_schema =
33 ExtensionAPI::GetSharedInstance()->GetSchema(api_name.as_string());
34 const base::ListValue* types = nullptr;
35 CHECK(full_schema->GetList("types", &types));
36 const base::DictionaryValue* type_schema = nullptr;
37 for (const auto& type : *types) {
38 const base::DictionaryValue* type_dict = nullptr;
39 CHECK(type->GetAsDictionary(&type_dict));
40 std::string id;
41 CHECK(type_dict->GetString("id", &id));
42 if (id == type_name) {
43 type_schema = type_dict;
44 break;
45 }
46 }
47 CHECK(type_schema);
48 const base::ListValue* type_functions = nullptr;
49 CHECK(type_schema->GetList("functions", &type_functions));
50 const base::ListValue* parameters = nullptr;
51 for (const auto& function : *type_functions) {
52 const base::DictionaryValue* function_dict = nullptr;
53 CHECK(function->GetAsDictionary(&function_dict));
54 std::string name;
55 CHECK(function_dict->GetString("name", &name));
56 if (name == function_name) {
57 CHECK(function_dict->GetList("parameters", &parameters));
58 break;
59 }
60 }
61 CHECK(parameters);
62 auto signature = base::MakeUnique<APISignature>(*parameters);
63 auto raw_signature = signature.get();
64 signatures[full_name] = std::move(signature);
65 return *raw_signature;
66 }
67
68 } // namespace api_custom_types
69 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698