-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IDL compiler: Support context-{in,}dependence of runtime-enabled feat…
…ures Makes the IDL compiler processes runtime_enabled_features.json5 and makes Exposure aware of context-dependent and context- independent runtime enabled features. Bug: 839389 Change-Id: I2d46730f22866f6f677a96dbd7a72644253e4692 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1892973 Commit-Queue: Yuki Shiino <yukishiino@chromium.org> Reviewed-by: Hitoshi Yoshida <peria@chromium.org> Cr-Commit-Position: refs/heads/master@{#711998}
- Loading branch information
Showing
12 changed files
with
163 additions
and
7 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
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
23 changes: 23 additions & 0 deletions
23
third_party/blink/renderer/bindings/scripts/web_idl/runtime_enabled_features.json5
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,23 @@ | ||
// Copyright 2019 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. | ||
|
||
|
||
// This file is used only for testing purposes, and is never used for | ||
// production. For production purposes, see the following file: | ||
// //third_party/blink/renderer/platform/runtime_enabled_features.json5 | ||
// | ||
// This file is used to add runtime enabled features in order to test the Web | ||
// IDL compiler and bindings code generator. | ||
|
||
{ | ||
data: [ | ||
{ | ||
name: "TestFeature1", | ||
}, | ||
{ | ||
name: "TestFeature2", | ||
origin_trial_feature_name: "TestFeature2", | ||
}, | ||
] | ||
} |
44 changes: 44 additions & 0 deletions
44
third_party/blink/renderer/bindings/scripts/web_idl/runtime_enabled_features.py
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,44 @@ | ||
# Copyright 2019 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. | ||
|
||
import json5 | ||
|
||
|
||
class RuntimeEnabledFeatures(object): | ||
"""Represents a set of definitions of runtime enabled features.""" | ||
|
||
_REQUIRE_INIT_MESSAGE = ( | ||
"RuntimeEnabledFeatures.init must be called in advance.") | ||
|
||
@classmethod | ||
def init(cls, filepaths): | ||
""" | ||
Args: | ||
filepaths: Paths to the definition files of runtime-enabled features | ||
("runtime_enabled_features.json5"). | ||
""" | ||
assert isinstance(filepaths, list) | ||
assert all(isinstance(filepath, str) for filepath in filepaths) | ||
|
||
cls._features = {} | ||
|
||
for filepath in filepaths: | ||
with open(filepath) as file_obj: | ||
datastore = json5.load(file_obj) | ||
|
||
for entry in datastore["data"]: | ||
assert entry["name"] not in cls._features | ||
cls._features[entry["name"]] = entry | ||
|
||
cls._is_initialized = True | ||
|
||
@classmethod | ||
def is_context_dependent(cls, feature_name): | ||
"""Returns True if the feature may be enabled per-context.""" | ||
assert cls._is_initialized, _REQUIRE_INIT_MESSAGE | ||
assert isinstance(feature_name, str) | ||
assert feature_name in cls._features, ( | ||
"Unknown runtime-enabled feature: {}".format(feature_name)) | ||
return cls._features[feature_name].get( | ||
"origin_trial_feature_name") is not None |