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

Unified Diff: extensions/common/extension_api.cc

Issue 2254383002: Signal extension API schema corruption to the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 4 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/common/extension_api.cc
diff --git a/extensions/common/extension_api.cc b/extensions/common/extension_api.cc
index 4b49a83f8e5f70492f0aee34901739c1b85f1ce7..08f2a1504bea888966f2d1f6945b6e9e4eaa7152 100644
--- a/extensions/common/extension_api.cc
+++ b/extensions/common/extension_api.cc
@@ -55,15 +55,23 @@ std::unique_ptr<base::ListValue> LoadSchemaList(
NULL, // error code
&error_message));
- // Tracking down http://crbug.com/121424
- char buf[128];
- base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'",
- name.c_str(),
- result.get() ? result->GetType() : -1,
- error_message.c_str());
-
- CHECK(result.get()) << error_message << " for schema " << schema;
- CHECK(result->IsType(base::Value::TYPE_LIST)) << " for schema " << schema;
+#if DCHECK_IS_ON()
+ // |schema| comes from JSON hard-coded to the Chrome binary, so in principle
+ // failure to parse indicates we generated corrupted JSON, but in practice
+ // corruption of the Chrome binary (e.g. disk errors) can also break it.
+ // See http://crbug.com/121424.
+ if (!result || !result->IsType(base::Value::TYPE_LIST)) {
+ char buf[128];
+ base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", name.c_str(),
+ result.get() ? result->GetType() : -1,
+ error_message.c_str());
+
+ DCHECK(result);
+ DCHECK(result->IsType(base::Value::TYPE_LIST));
+ }
+#endif // DCHECK_IS_ON()
+
+ // From() returns null if passed a null or non-list value.
return base::ListValue::From(std::move(result));
}
@@ -214,6 +222,9 @@ ExtensionAPI::OverrideSharedInstanceForTest::~OverrideSharedInstanceForTest() {
void ExtensionAPI::LoadSchema(const std::string& name,
const base::StringPiece& schema) {
std::unique_ptr<base::ListValue> schema_list(LoadSchemaList(name, schema));
+ if (!schema_list)
+ return;
+
std::string schema_namespace;
extensions::ExtensionsClient* extensions_client =
extensions::ExtensionsClient::Get();
@@ -331,7 +342,12 @@ const base::DictionaryValue* ExtensionAPI::GetSchema(
}
maybe_schema = schemas_.find(api_name);
- CHECK(schemas_.end() != maybe_schema);
+ // If the schema failed to load then return null for it, rather than
+ // crashing, so that the browser can be notified of the problem.
+ // See http://crbug.com/121424.
+ if (schemas_.end() == maybe_schema)
+ return NULL;
+
result = maybe_schema->second.get();
}
@@ -341,6 +357,23 @@ const base::DictionaryValue* ExtensionAPI::GetSchema(
return result;
}
+void ExtensionAPI::LoadSchemaListOrDie(const std::string& api) {
+ std::string api_name = GetAPINameFromFullName(api, NULL);
+
+ extensions::ExtensionsClient* extensions_client =
+ extensions::ExtensionsClient::Get();
+ DCHECK(extensions_client);
+
+ UnloadedSchemaMap::iterator maybe_schema_resource =
+ unloaded_schemas_.find(api_name);
+ if (maybe_schema_resource != unloaded_schemas_.end()) {
+ CHECK(LoadSchemaList(api_name,
+ ReadFromResource(maybe_schema_resource->second)));
+ } else if (extensions_client->IsAPISchemaGenerated(api)) {
+ CHECK(LoadSchemaList(api_name, extensions_client->GetAPISchema(api_name)));
+ }
+}
+
Feature* ExtensionAPI::GetFeatureDependency(const std::string& full_name) {
std::string feature_type;
std::string feature_name;
@@ -390,7 +423,9 @@ std::string ExtensionAPI::GetAPINameFromFullName(const std::string& full_name,
api_name_candidate = api_name_candidate.substr(0, last_dot_index);
}
- *child_name = "";
+ if (child_name)
+ *child_name = "";
+
return std::string();
}

Powered by Google App Engine
This is Rietveld 408576698