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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/api_custom_types.cc
diff --git a/extensions/renderer/api_custom_types.cc b/extensions/renderer/api_custom_types.cc
new file mode 100644
index 0000000000000000000000000000000000000000..36ce7c7d828b5940953388a9c200b10d8010cbdb
--- /dev/null
+++ b/extensions/renderer/api_custom_types.cc
@@ -0,0 +1,69 @@
+// Copyright 2017 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 "extensions/renderer/api_custom_types.h"
+
+#include <map>
+#include <memory>
+#include <string>
+
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "base/strings/stringprintf.h"
+#include "extensions/common/extension_api.h"
+#include "extensions/renderer/api_signature.h"
+
+namespace extensions {
+namespace api_custom_types {
+
+const APISignature& GetFunctionSchema(base::StringPiece api_name,
+ base::StringPiece type_name,
Devlin 2017/02/24 16:19:28 Cut and paste from storage_area.cc
+ base::StringPiece function_name) {
+ using SignatureMap = std::map<std::string, std::unique_ptr<APISignature>>;
+ 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
+
+ std::string full_name = base::StringPrintf(
+ "%s.%s.%s", api_name.data(), type_name.data(), function_name.data());
+ auto iter = signatures.find(full_name);
+ if (iter != signatures.end())
+ return *iter->second;
+
+ const base::DictionaryValue* full_schema =
+ ExtensionAPI::GetSharedInstance()->GetSchema(api_name.as_string());
+ const base::ListValue* types = nullptr;
+ CHECK(full_schema->GetList("types", &types));
+ const base::DictionaryValue* type_schema = nullptr;
+ for (const auto& type : *types) {
+ const base::DictionaryValue* type_dict = nullptr;
+ CHECK(type->GetAsDictionary(&type_dict));
+ std::string id;
+ CHECK(type_dict->GetString("id", &id));
+ if (id == type_name) {
+ type_schema = type_dict;
+ break;
+ }
+ }
+ CHECK(type_schema);
+ const base::ListValue* type_functions = nullptr;
+ CHECK(type_schema->GetList("functions", &type_functions));
+ const base::ListValue* parameters = nullptr;
+ for (const auto& function : *type_functions) {
+ const base::DictionaryValue* function_dict = nullptr;
+ CHECK(function->GetAsDictionary(&function_dict));
+ std::string name;
+ CHECK(function_dict->GetString("name", &name));
+ if (name == function_name) {
+ CHECK(function_dict->GetList("parameters", &parameters));
+ break;
+ }
+ }
+ CHECK(parameters);
+ auto signature = base::MakeUnique<APISignature>(*parameters);
+ auto raw_signature = signature.get();
+ signatures[full_name] = std::move(signature);
+ return *raw_signature;
+}
+
+} // namespace api_custom_types
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698