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

Side by Side Diff: Source/core/scripts/make_web_runtime_features.py

Issue 15807002: WIP patch for autogenerating WebRuntimeFeatures.*, no plans to land this. Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (C) 2013 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 import os.path
31 import sys
32
33 import in_generator
34 import license
35 import make_runtime_features
36
37
38 HEADER_TEMPLATE = """%(license)s
39 #ifndef %(class_name)s_h
40 #define %(class_name)s_h
41
42 #include "../../../Platform/chromium/public/WebCommon.h"
43
44 namespace WebKit {
45
46 // This class is used to enable runtime features of Blink.
47 // All features are disabled by default.
48 // Most clients should call enableStableFeatures() to enable
49 // features Blink has made API commitments to.
50 class %(class_name)s {
51 public:
52 %(feature_set_declarations)s
53
54 %(feature_toggle_declarations)s
55
56 private:
57 %(class_name)s() { }
58 };
59
60 } // namespace WebKit
61
62 #endif // %(class_name)s_h
63 """
64
65 IMPLEMENTATION_TEMPLATE = """%(license)s
66 #include "config.h"
67 #include "%(class_name)s.h"
68
69 #include "RuntimeEnabledFeatures.h"
70
71 using namespace WebCore;
72
73 namespace WebKit {
74
75 %(feature_set_definitions)s
76
77 %(feature_toggle_definitions)s
78
79 } // namespace WebKit
80 """
81
82 # We want exactly the same parsing as RuntimeFeatureWriter
83 # but generate different files.
84 class WebRuntimeFeaturesWriter(make_runtime_features.RuntimeFeatureWriter):
85 class_name = "WebRuntimeFeatures"
86 feature_sets = make_runtime_features.RuntimeFeatureWriter.valid_values['stat us']
87
88 def _feature_toggle_declaration(self, feature):
89 return """ WEBKIT_EXPORT static void enable%(name)s(bool);
90 WEBKIT_EXPORT static bool is%(name)sEnabled();
91 """ % feature
92
93 def _feature_set_declaration(self, feature_set):
94 return " WEBKIT_EXPORT static void enable%sFeatures(bool);" % feature _set
95
96 def generate_header(self):
97 return HEADER_TEMPLATE % {
98 'class_name' : self.class_name,
99 'license' : license.license_for_generated_cpp(),
100 'feature_set_declarations' : "\n".join(map(self._feature_set_declara tion, map(str.capitalize, self.feature_sets))),
101 'feature_toggle_declarations' : "\n".join(map(self._feature_toggle_d eclaration, self._non_custom_features)),
102 }
103
104 def _feature_toggle(self, feature):
105 return " enable%(name)s(enable);" % feature
106
107 def _feature_set_definition(self, feature_set):
108 features_in_set = filter(lambda feature: feature['status'] == feature_se t, self._all_features)
109 return """void %(class_name)s::enable%(feature_set)sFeatures(bool enable )
110 {
111 %(feature_toggles)s
112 }
113 """ % {
114 'class_name' : self.class_name,
115 'feature_set' : feature_set.capitalize(),
116 'feature_toggles' : "\n".join(map(self._feature_toggle, features_in_set) )
117 }
118
119 def _feature_toggle_definition(self, feature):
120 return """void WebRuntimeFeatures::enable%(name)s(bool enable)
121 {
122 RuntimeEnabledFeatures::set%(name)sEnabled(enable);
123 }
124
125 bool WebRuntimeFeatures::is%(name)sEnabled()
126 {
127 return RuntimeEnabledFeatures::%(first_lowered_name)sEnabled();
128 }
129 """ % feature
130
131 def generate_implementation(self):
132 return IMPLEMENTATION_TEMPLATE % {
133 'class_name' : self.class_name,
134 'license' : license.license_for_generated_cpp(),
135 'feature_set_definitions' : "\n".join(map(self._feature_set_definiti on, self.feature_sets)),
136 'feature_toggle_definitions' : "\n".join(map(self._feature_toggle_de finition, self._non_custom_features)),
137 }
138
139 if __name__ == "__main__":
140 in_generator.Maker(WebRuntimeFeaturesWriter).main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698