Commit 325aa652 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions Bindings] Remove some unused custom bindings

Most of the JS-based DeclarativeContentCustomBindings are no longer
necessary with native bindings (only the setIcon handling still is).
Remove the majority of the JS bindings, as well as the CssNativeHandler
class (which was only used by the DeclarativeContent JS bindings).

Bug: 938998
TBR=halliwell@chromium.org (removing unused include)

Change-Id: Ie9bf12f4a050b7b79cd55ef2ff361f19ab913cf3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1879947
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709232}
parent bac52e20
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "extensions/common/permissions/permission_set.h" #include "extensions/common/permissions/permission_set.h"
#include "extensions/common/switches.h" #include "extensions/common/switches.h"
#include "extensions/renderer/bindings/api_bindings_system.h" #include "extensions/renderer/bindings/api_bindings_system.h"
#include "extensions/renderer/css_native_handler.h"
#include "extensions/renderer/dispatcher.h" #include "extensions/renderer/dispatcher.h"
#include "extensions/renderer/lazy_background_page_native_handler.h" #include "extensions/renderer/lazy_background_page_native_handler.h"
#include "extensions/renderer/native_extension_bindings_system.h" #include "extensions/renderer/native_extension_bindings_system.h"
...@@ -104,9 +103,6 @@ void ChromeExtensionsDispatcherDelegate::RegisterNativeHandlers( ...@@ -104,9 +103,6 @@ void ChromeExtensionsDispatcherDelegate::RegisterNativeHandlers(
"lazy_background_page", "lazy_background_page",
std::unique_ptr<NativeHandler>( std::unique_ptr<NativeHandler>(
new extensions::LazyBackgroundPageNativeHandler(context))); new extensions::LazyBackgroundPageNativeHandler(context)));
module_system->RegisterNativeHandler(
"css_natives", std::unique_ptr<NativeHandler>(
new extensions::CssNativeHandler(context)));
} }
void ChromeExtensionsDispatcherDelegate::PopulateSourceMap( void ChromeExtensionsDispatcherDelegate::PopulateSourceMap(
......
...@@ -4,99 +4,30 @@ ...@@ -4,99 +4,30 @@
// Custom binding for the declarativeContent API. // Custom binding for the declarativeContent API.
if (!apiBridge) {
var utils = require('utils');
var validate = require('schemaUtils').validate;
var canonicalizeCompoundSelector =
requireNative('css_natives').CanonicalizeCompoundSelector;
}
var setIcon = require('setIcon').setIcon; var setIcon = require('setIcon').setIcon;
apiBridge.registerCustomHook(function(api) { apiBridge.registerCustomHook(function(api) {
var declarativeContent = api.compiledApi; var declarativeContent = api.compiledApi;
if (apiBridge) { // Validation for most types is done in the native C++ with native bindings,
// Validation for most types is done in the native C++ with native bindings, // but setIcon is funny (and sadly broken). Ideally, we can move this
// but setIcon is funny (and sadly broken). Ideally, we can move this // validation entirely into the native code, and this whole file can go
// validation entirely into the native code, and this whole file can go // away.
// away. var nativeSetIcon = declarativeContent.SetIcon;
var nativeSetIcon = declarativeContent.SetIcon;
declarativeContent.SetIcon = function(parameters) {
// TODO(devlin): This is very, very wrong. setIcon() is potentially
// asynchronous (in the case of a path being specified), which means this
// becomes an "asynchronous constructor". Errors can be thrown *after* the
// `new declarativeContent.SetIcon(...)` call, and in the async cases,
// this wouldn't work when we immediately add the action via an API call
// (e.g.,
// chrome.declarativeContent.onPageChange.addRules(
// [{conditions: ..., actions: [ new SetIcon(...) ]}]);
// ). Some of this is tracked in http://crbug.com/415315.
setIcon(parameters, $Function.bind(function(data) {
// Fake calling the original function as a constructor.
$Object.setPrototypeOf(this, nativeSetIcon.prototype);
$Function.apply(nativeSetIcon, this, [data]);
}, this));
};
return;
}
// Returns the schema definition of type |typeId| defined in |namespace|.
function getSchema(typeId) {
return utils.lookup(api.schema.types,
'id',
'declarativeContent.' + typeId);
}
// Helper function for the constructor of concrete datatypes of the
// declarative content API.
// Makes sure that |this| contains the union of parameters and
// {'instanceType': 'declarativeContent.' + typeId} and validates the
// generated union dictionary against the schema for |typeId|.
function setupInstance(instance, parameters, typeId) {
for (var key in parameters) {
if ($Object.hasOwnProperty(parameters, key)) {
instance[key] = parameters[key];
}
}
instance.instanceType = 'declarativeContent.' + typeId;
var schema = getSchema(typeId);
validate([instance], [schema]);
}
function canonicalizeCssSelectors(selectors) {
for (var i = 0; i < selectors.length; i++) {
var canonicalizedSelector = canonicalizeCompoundSelector(selectors[i]);
if (canonicalizedSelector == '') {
throw new Error(
'Element of \'css\' array must be a ' +
'list of valid compound selectors: ' +
selectors[i]);
}
selectors[i] = canonicalizedSelector;
}
}
// Setup all data types for the declarative content API.
declarativeContent.PageStateMatcher = function(parameters) {
setupInstance(this, parameters, 'PageStateMatcher');
if ($Object.hasOwnProperty(this, 'css')) {
canonicalizeCssSelectors(this.css);
}
};
declarativeContent.ShowAction = function(parameters) {
setupInstance(this, parameters, 'ShowAction');
};
declarativeContent.ShowPageAction = declarativeContent.ShowAction;
declarativeContent.RequestContentScript = function(parameters) {
setupInstance(this, parameters, 'RequestContentScript');
};
// TODO(rockot): Do not expose this in M39 stable. Making this restriction
// possible will take some extra work. See http://crbug.com/415315
// Note: See also the SetIcon wrapper above for more issues.
declarativeContent.SetIcon = function(parameters) { declarativeContent.SetIcon = function(parameters) {
// TODO(devlin): This is very, very wrong. setIcon() is potentially
// asynchronous (in the case of a path being specified), which means this
// becomes an "asynchronous constructor". Errors can be thrown *after* the
// `new declarativeContent.SetIcon(...)` call, and in the async cases,
// this wouldn't work when we immediately add the action via an API call
// (e.g.,
// chrome.declarativeContent.onPageChange.addRules(
// [{conditions: ..., actions: [ new SetIcon(...) ]}]);
// ). Some of this is tracked in http://crbug.com/415315.
setIcon(parameters, $Function.bind(function(data) { setIcon(parameters, $Function.bind(function(data) {
setupInstance(this, data, 'SetIcon'); // Fake calling the original function as a constructor.
$Object.setPrototypeOf(this, nativeSetIcon.prototype);
$Function.apply(nativeSetIcon, this, [data]);
}, this)); }, this));
}; };
}); });
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "extensions/common/switches.h" #include "extensions/common/switches.h"
#include "extensions/renderer/bindings/api_binding_hooks.h" #include "extensions/renderer/bindings/api_binding_hooks.h"
#include "extensions/renderer/bindings/api_bindings_system.h" #include "extensions/renderer/bindings/api_bindings_system.h"
#include "extensions/renderer/css_native_handler.h"
#include "extensions/renderer/dispatcher.h" #include "extensions/renderer/dispatcher.h"
#include "extensions/renderer/lazy_background_page_native_handler.h" #include "extensions/renderer/lazy_background_page_native_handler.h"
#include "extensions/renderer/native_extension_bindings_system.h" #include "extensions/renderer/native_extension_bindings_system.h"
......
...@@ -87,8 +87,6 @@ jumbo_source_set("renderer") { ...@@ -87,8 +87,6 @@ jumbo_source_set("renderer") {
"content_watcher.h", "content_watcher.h",
"context_menus_custom_bindings.cc", "context_menus_custom_bindings.cc",
"context_menus_custom_bindings.h", "context_menus_custom_bindings.h",
"css_native_handler.cc",
"css_native_handler.h",
"declarative_content_hooks_delegate.cc", "declarative_content_hooks_delegate.cc",
"declarative_content_hooks_delegate.h", "declarative_content_hooks_delegate.h",
"dispatcher.cc", "dispatcher.cc",
......
// Copyright 2014 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/css_native_handler.h"
#include "base/bind.h"
#include "extensions/renderer/script_context.h"
#include "extensions/renderer/v8_helpers.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/web/web_selector.h"
namespace extensions {
using blink::WebString;
CssNativeHandler::CssNativeHandler(ScriptContext* context)
: ObjectBackedNativeHandler(context) {}
void CssNativeHandler::AddRoutes() {
RouteHandlerFunction(
"CanonicalizeCompoundSelector", "declarativeContent",
base::BindRepeating(&CssNativeHandler::CanonicalizeCompoundSelector,
base::Unretained(this)));
}
void CssNativeHandler::CanonicalizeCompoundSelector(
const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK_EQ(args.Length(), 1);
CHECK(args[0]->IsString());
v8::Isolate* isolate = args.GetIsolate();
std::string input_selector = *v8::String::Utf8Value(isolate, args[0]);
// TODO(esprehn): This API shouldn't exist, the extension code should be
// moved into blink.
WebString output_selector = blink::CanonicalizeSelector(
WebString::FromUTF8(input_selector), blink::kWebSelectorTypeCompound);
args.GetReturnValue().Set(
v8_helpers::ToV8StringUnsafe(isolate, output_selector.Utf8().c_str()));
}
} // namespace extensions
// Copyright 2014 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.
#ifndef EXTENSIONS_RENDERER_CSS_NATIVE_HANDLER_H_
#define EXTENSIONS_RENDERER_CSS_NATIVE_HANDLER_H_
#include "extensions/renderer/object_backed_native_handler.h"
namespace extensions {
class ScriptContext;
class CssNativeHandler : public ObjectBackedNativeHandler {
public:
explicit CssNativeHandler(ScriptContext* context);
// ObjectBackedNativeHandler:
void AddRoutes() override;
private:
// Expects one string argument that's a comma-separated list of compound CSS
// selectors (http://dev.w3.org/csswg/selectors4/#compound), and returns its
// Blink-canonicalized form. If the selector is invalid, returns an empty
// string.
void CanonicalizeCompoundSelector(
const v8::FunctionCallbackInfo<v8::Value>& args);
};
} // namespace extensions
#endif // EXTENSIONS_RENDERER_CSS_NATIVE_HANDLER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment