forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Extensions Bindings] Add support for DeclarativeEvents
A small number of APIs have declarative events - events that support "rules" rather than listeners. These events take a list of conditions and actions to perform when those conditions are met. For instance, declarativeContent.onPageChanged allows extensions to register an action to make the extension's page action visible when a set of conditions, like the page having a certain url, are met. Create a DeclarativeEvent class in the native bindings, and wire it up for use, and add tests for the same. Some complications arise because each event can have a somewhat different "rule" schema, since the actions and conditions for that event can be unique. The way we specify these in the JSON schema files is pretty convoluted, by specifying "any" object in the events.json file, then listing "actions" and "conditions" in the specific API file, and finally using the custom JS event bindings to validate them. Unfortunately, this creates complexity in the native side as well, since we cannot simply look up the schema directly. BUG=653596 Review-Url: https://codereview.chromium.org/2754073002 Cr-Commit-Position: refs/heads/master@{#459176}
- Loading branch information
Showing
17 changed files
with
761 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
chrome/test/data/extensions/api_test/native_bindings/declarative_content/background.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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. | ||
|
||
// Register a rule to show the page action whenever we see a page with 'example' | ||
// in the host. Send messages after registration of the rule is complete and | ||
// when the page action is clicked. | ||
|
||
const kRuleId = 'rule1'; | ||
|
||
var rule = { | ||
conditions: [ | ||
new chrome.declarativeContent.PageStateMatcher( | ||
{pageUrl: {hostPrefix: 'example'}}), | ||
], actions: [ | ||
new chrome.declarativeContent.ShowPageAction(), | ||
], | ||
id: kRuleId, | ||
}; | ||
|
||
chrome.pageAction.onClicked.addListener(function() { | ||
chrome.declarativeContent.onPageChanged.removeRules([kRuleId], function() { | ||
chrome.declarativeContent.onPageChanged.getRules(function(rules) { | ||
chrome.test.assertEq(0, rules.length); | ||
chrome.test.sendMessage('clicked and removed'); | ||
}); | ||
}); | ||
}); | ||
|
||
chrome.declarativeContent.onPageChanged.addRules([rule], function() { | ||
chrome.declarativeContent.onPageChanged.getRules(function(rules) { | ||
chrome.test.assertEq(1, rules.length); | ||
chrome.test.assertEq(kRuleId, rules[0].id); | ||
chrome.test.sendMessage('ready'); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
chrome/test/data/extensions/api_test/native_bindings/declarative_content/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "Test declarative content", | ||
"description": "Test declarative content with native bindings", | ||
"version": "0.1", | ||
"manifest_version": 2, | ||
"permissions": ["declarativeContent"], | ||
"page_action": {}, | ||
"background": { | ||
"peristent": false, | ||
"scripts": ["background.js"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.