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

Unified Diff: chrome/renderer/extensions/dispatcher.cc

Issue 14494013: Allow API functions and events to have entries in _api_features.json (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix browser_tests, Stubs now inspects _api_features.json Created 7 years, 8 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: chrome/renderer/extensions/dispatcher.cc
diff --git a/chrome/renderer/extensions/dispatcher.cc b/chrome/renderer/extensions/dispatcher.cc
index 8da074ce0c68621cf28033ef757625135aa0c87d..da3c357050889a65d05e7ca315bcf0fc60221ccd 100644
--- a/chrome/renderer/extensions/dispatcher.cc
+++ b/chrome/renderer/extensions/dispatcher.cc
@@ -7,6 +7,8 @@
#include "base/callback.h"
#include "base/command_line.h"
#include "base/debug/alias.h"
+#include "base/json/json_reader.h"
+#include "base/json/json_writer.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
#include "base/strings/string_piece.h"
@@ -65,6 +67,7 @@
#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
#include "extensions/common/view_type.h"
+#include "grit/common_resources.h"
#include "grit/renderer_resources.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h"
@@ -113,6 +116,27 @@ static v8::Handle<v8::Object> GetOrCreateChrome(
return chrome->ToObject();
}
+class TestFeaturesNativeHandler : public ObjectBackedNativeHandler {
+ public:
+ explicit TestFeaturesNativeHandler(v8::Handle<v8::Context> context)
+ : ObjectBackedNativeHandler(context) {
+ RouteFunction("GetAPIFeatures",
+ base::Bind(&TestFeaturesNativeHandler::GetAPIFeatures,
+ base::Unretained(this)));
+ }
+
+ private:
+ v8::Handle<v8::Value> GetAPIFeatures(const v8::Arguments& args) {
+ // Read the JSON and write it back out to remove comments.
+ base::Value* value = base::JSONReader::Read(
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_EXTENSION_API_FEATURES).as_string());
not at google - send to devlin 2013/05/03 04:58:14 do you need to write it back to a string again? yo
cduvall 2013/05/07 23:44:29 Done.
+ std::string json_str;
+ base::JSONWriter::Write(value, &json_str);
+ return v8::String::New(json_str.c_str());
+ }
+};
+
class SchemaRegistryNativeHandler : public ObjectBackedNativeHandler {
public:
SchemaRegistryNativeHandler(V8SchemaRegistry* registry,
@@ -699,7 +723,7 @@ void Dispatcher::RegisterSchemaGeneratedBindings(
for (std::set<std::string>::iterator it = apis.begin();
it != apis.end(); ++it) {
const std::string& api_name = *it;
- if (!context->GetAvailabilityForContext(api_name).is_available())
+ if (!context->IsAnyFeatureAvailableToContext(api_name))
continue;
Feature* feature =
@@ -1014,6 +1038,8 @@ void Dispatcher::DidCreateScriptContext(
new SchemaRegistryNativeHandler(v8_schema_registry(), v8_context)));
module_system->RegisterNativeHandler("v8_context",
scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context, this)));
+ module_system->RegisterNativeHandler("test_features",
+ scoped_ptr<NativeHandler>(new TestFeaturesNativeHandler(v8_context)));
int manifest_version = extension ? extension->manifest_version() : 1;
bool send_request_disabled =

Powered by Google App Engine
This is Rietveld 408576698