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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/scripts/make_web_runtime_features.py
diff --git a/Source/core/scripts/make_web_runtime_features.py b/Source/core/scripts/make_web_runtime_features.py
new file mode 100755
index 0000000000000000000000000000000000000000..4036e08b0a47760d2a73fc7e17ef6c1863deaeb3
--- /dev/null
+++ b/Source/core/scripts/make_web_runtime_features.py
@@ -0,0 +1,140 @@
+#!/usr/bin/env python
+# Copyright (C) 2013 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import os.path
+import sys
+
+import in_generator
+import license
+import make_runtime_features
+
+
+HEADER_TEMPLATE = """%(license)s
+#ifndef %(class_name)s_h
+#define %(class_name)s_h
+
+#include "../../../Platform/chromium/public/WebCommon.h"
+
+namespace WebKit {
+
+// This class is used to enable runtime features of Blink.
+// All features are disabled by default.
+// Most clients should call enableStableFeatures() to enable
+// features Blink has made API commitments to.
+class %(class_name)s {
+public:
+%(feature_set_declarations)s
+
+%(feature_toggle_declarations)s
+
+private:
+ %(class_name)s() { }
+};
+
+} // namespace WebKit
+
+#endif // %(class_name)s_h
+"""
+
+IMPLEMENTATION_TEMPLATE = """%(license)s
+#include "config.h"
+#include "%(class_name)s.h"
+
+#include "RuntimeEnabledFeatures.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+%(feature_set_definitions)s
+
+%(feature_toggle_definitions)s
+
+} // namespace WebKit
+"""
+
+# We want exactly the same parsing as RuntimeFeatureWriter
+# but generate different files.
+class WebRuntimeFeaturesWriter(make_runtime_features.RuntimeFeatureWriter):
+ class_name = "WebRuntimeFeatures"
+ feature_sets = make_runtime_features.RuntimeFeatureWriter.valid_values['status']
+
+ def _feature_toggle_declaration(self, feature):
+ return """ WEBKIT_EXPORT static void enable%(name)s(bool);
+ WEBKIT_EXPORT static bool is%(name)sEnabled();
+""" % feature
+
+ def _feature_set_declaration(self, feature_set):
+ return " WEBKIT_EXPORT static void enable%sFeatures(bool);" % feature_set
+
+ def generate_header(self):
+ return HEADER_TEMPLATE % {
+ 'class_name' : self.class_name,
+ 'license' : license.license_for_generated_cpp(),
+ 'feature_set_declarations' : "\n".join(map(self._feature_set_declaration, map(str.capitalize, self.feature_sets))),
+ 'feature_toggle_declarations' : "\n".join(map(self._feature_toggle_declaration, self._non_custom_features)),
+ }
+
+ def _feature_toggle(self, feature):
+ return " enable%(name)s(enable);" % feature
+
+ def _feature_set_definition(self, feature_set):
+ features_in_set = filter(lambda feature: feature['status'] == feature_set, self._all_features)
+ return """void %(class_name)s::enable%(feature_set)sFeatures(bool enable)
+{
+%(feature_toggles)s
+}
+""" % {
+ 'class_name' : self.class_name,
+ 'feature_set' : feature_set.capitalize(),
+ 'feature_toggles' : "\n".join(map(self._feature_toggle, features_in_set))
+ }
+
+ def _feature_toggle_definition(self, feature):
+ return """void WebRuntimeFeatures::enable%(name)s(bool enable)
+{
+ RuntimeEnabledFeatures::set%(name)sEnabled(enable);
+}
+
+bool WebRuntimeFeatures::is%(name)sEnabled()
+{
+ return RuntimeEnabledFeatures::%(first_lowered_name)sEnabled();
+}
+""" % feature
+
+ def generate_implementation(self):
+ return IMPLEMENTATION_TEMPLATE % {
+ 'class_name' : self.class_name,
+ 'license' : license.license_for_generated_cpp(),
+ 'feature_set_definitions' : "\n".join(map(self._feature_set_definition, self.feature_sets)),
+ 'feature_toggle_definitions' : "\n".join(map(self._feature_toggle_definition, self._non_custom_features)),
+ }
+
+if __name__ == "__main__":
+ in_generator.Maker(WebRuntimeFeaturesWriter).main(sys.argv)
« 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