Add [EnabledAtRuntime] extended attribute support for global constructors

https://bugs.webkit.org/show_bug.cgi?id=116147

Reviewed by Geoffrey Garen.

Add [EnabledAtRuntime] extended attribute support for global constructors.
This patch adds [EnabledAtRuntime] extended attribute to SharedWorker and
WebSocket IDL interfaces so that their global constructors on the global
Window object can now be automatically generated.

The behavior on JavaScript side is unchanged. We simply leverage
RuntimeEnabledFeatures class and the new [EnabledAtRuntime] IDL extended
attribute to generate the code for global constructors getters instead
of using custom code.

No new tests, no behavior change for layout tests.

* GNUmakefile.list.am:
* Modules/websockets/WebSocket.cpp: Enable WebSockets at runtime by default.
* Modules/websockets/WebSocket.idl:
* Target.pri:
* UseJSC.cmake:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
* bindings/js/JSDOMWindowCustom.cpp:
(WebCore):
* bindings/js/JSDOMWindowWebSocketCustom.cpp: Removed.
* bindings/scripts/CodeGeneratorJS.pm:
(ToMethodName):
(GetRuntimeEnableFunctionName):
(GenerateImplementation):
* bindings/scripts/IDLAttributes.txt:
* page/DOMWindow.idl:
* workers/SharedWorker.idl:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@150276 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 868f0865
2013-05-17 Christophe Dumez <ch.dumez@sisa.samsung.com>
Add [EnabledAtRuntime] extended attribute support for global constructors
https://bugs.webkit.org/show_bug.cgi?id=116147
Reviewed by Geoffrey Garen.
Add [EnabledAtRuntime] extended attribute support for global constructors.
This patch adds [EnabledAtRuntime] extended attribute to SharedWorker and
WebSocket IDL interfaces so that their global constructors on the global
Window object can now be automatically generated.
The behavior on JavaScript side is unchanged. We simply leverage
RuntimeEnabledFeatures class and the new [EnabledAtRuntime] IDL extended
attribute to generate the code for global constructors getters instead
of using custom code.
No new tests, no behavior change for layout tests.
* GNUmakefile.list.am:
* Modules/websockets/WebSocket.cpp: Enable WebSockets at runtime by default.
* Modules/websockets/WebSocket.idl:
* Target.pri:
* UseJSC.cmake:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
* bindings/js/JSDOMWindowCustom.cpp:
(WebCore):
* bindings/js/JSDOMWindowWebSocketCustom.cpp: Removed.
* bindings/scripts/CodeGeneratorJS.pm:
(ToMethodName):
(GetRuntimeEnableFunctionName):
(GenerateImplementation):
* bindings/scripts/IDLAttributes.txt:
* page/DOMWindow.idl:
* workers/SharedWorker.idl:
2013-05-17 Darin Adler <darin@apple.com>
[EFL] Move EFL port off legacy clipboard
......
......@@ -2394,7 +2394,6 @@ webcore_sources += \
Source/WebCore/bindings/js/JSDOMWindowShell.cpp \
Source/WebCore/bindings/js/JSDOMWindowShell.h \
Source/WebCore/bindings/js/JSDOMWindowWebAudioCustom.cpp \
Source/WebCore/bindings/js/JSDOMWindowWebSocketCustom.cpp \
Source/WebCore/bindings/js/JSDOMWrapper.cpp \
Source/WebCore/bindings/js/JSDOMWrapper.h \
Source/WebCore/bindings/js/JSDataViewCustom.cpp \
......
......@@ -126,7 +126,7 @@ static unsigned long saturateAdd(unsigned long a, unsigned long b)
return a + b;
}
static bool webSocketsAvailable = false;
static bool webSocketsAvailable = true;
void WebSocket::setIsAvailable(bool available)
{
......
......@@ -30,7 +30,7 @@
*/
[
NoInterfaceObject,
EnabledAtRuntime,
Conditional=WEB_SOCKETS,
ActiveDOMObject,
Constructor(DOMString url),
......
......@@ -114,7 +114,6 @@ SOURCES += \
bindings/js/JSDOMWindowCustom.cpp \
bindings/js/JSDOMWindowShell.cpp \
bindings/js/JSDOMWindowWebAudioCustom.cpp \
bindings/js/JSDOMWindowWebSocketCustom.cpp \
bindings/js/JSDOMWrapper.cpp \
bindings/js/JSDataViewCustom.cpp \
bindings/js/JSDeviceMotionEventCustom.cpp \
......
......@@ -66,7 +66,6 @@ list(APPEND WebCore_SOURCES
bindings/js/JSDOMWindowCustom.cpp
bindings/js/JSDOMWindowShell.cpp
bindings/js/JSDOMWindowWebAudioCustom.cpp
bindings/js/JSDOMWindowWebSocketCustom.cpp
bindings/js/JSDOMWrapper.cpp
bindings/js/JSDeviceMotionEventCustom.cpp
bindings/js/JSDeviceOrientationEventCustom.cpp
......
......@@ -68293,58 +68293,6 @@
/>
</FileConfiguration>
</File>
<File
RelativePath="..\bindings\js\JSDOMWindowWebSocketCustom.cpp"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_Cairo_CFLite|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release_Cairo_CFLite|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_All|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Production|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\bindings\js\JSDOMWrapper.cpp"
>
......@@ -9437,14 +9437,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bindings\js\JSDOMWindowWebSocketCustom.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bindings\js\JSDOMWrapper.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
......@@ -5346,9 +5346,6 @@
<ClCompile Include="..\bindings\js\JSDOMWindowWebAudioCustom.cpp">
<Filter>bindings\js</Filter>
</ClCompile>
<ClCompile Include="..\bindings\js\JSDOMWindowWebSocketCustom.cpp">
<Filter>bindings\js</Filter>
</ClCompile>
<ClCompile Include="..\bindings\js\JSDOMWrapper.cpp">
<Filter>bindings\js</Filter>
</ClCompile>
......
......@@ -3494,7 +3494,6 @@
A7F5D9501384F02D00A29A87 /* NodeRenderingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = A7F5D94E1384F02D00A29A87 /* NodeRenderingContext.h */; };
A80A38FE0E50CC8200A25EBC /* PatternCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A80A38FD0E50CC8200A25EBC /* PatternCG.cpp */; };
A80A9423149F225E00989291 /* JSDOMWindowWebAudioCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A80A9422149F225E00989291 /* JSDOMWindowWebAudioCustom.cpp */; };
A80A9425149F227100989291 /* JSDOMWindowWebSocketCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A80A9424149F227100989291 /* JSDOMWindowWebSocketCustom.cpp */; };
A80D67080E9E9DEB00E420F0 /* GraphicsContextPlatformPrivateCG.h in Headers */ = {isa = PBXBuildFile; fileRef = A80D67070E9E9DEB00E420F0 /* GraphicsContextPlatformPrivateCG.h */; };
A80E6CE40A1989CA007FB8C5 /* CSSValueList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A80E6CBA0A1989CA007FB8C5 /* CSSValueList.cpp */; };
A80E6CE60A1989CA007FB8C5 /* CSSPrimitiveValue.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E6CBC0A1989CA007FB8C5 /* CSSPrimitiveValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
......@@ -9996,7 +9995,6 @@
A7F73EDA169AD7AA00CBAA4B /* DOMShadowRoot.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMShadowRoot.mm; sourceTree = "<group>"; };
A80A38FD0E50CC8200A25EBC /* PatternCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PatternCG.cpp; sourceTree = "<group>"; };
A80A9422149F225E00989291 /* JSDOMWindowWebAudioCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMWindowWebAudioCustom.cpp; sourceTree = "<group>"; };
A80A9424149F227100989291 /* JSDOMWindowWebSocketCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMWindowWebSocketCustom.cpp; sourceTree = "<group>"; };
A80D67070E9E9DEB00E420F0 /* GraphicsContextPlatformPrivateCG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextPlatformPrivateCG.h; sourceTree = "<group>"; };
A80E6CBA0A1989CA007FB8C5 /* CSSValueList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = CSSValueList.cpp; sourceTree = "<group>"; };
A80E6CBC0A1989CA007FB8C5 /* CSSPrimitiveValue.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CSSPrimitiveValue.h; sourceTree = "<group>"; };
......@@ -18888,7 +18886,6 @@
BCD9C25E0C17AA67005C90A2 /* JSDOMWindowCustom.cpp */,
652FBBBB0DE27CB60001D386 /* JSDOMWindowCustom.h */,
A80A9422149F225E00989291 /* JSDOMWindowWebAudioCustom.cpp */,
A80A9424149F227100989291 /* JSDOMWindowWebSocketCustom.cpp */,
BC2ED5540C6B9BD300920BFF /* JSElementCustom.cpp */,
BCEFAF4D0C317E6900FA81F6 /* JSEventCustom.cpp */,
2E7582ED12764F260062628B /* JSFileReaderCustom.cpp */,
......@@ -25525,7 +25522,6 @@
BCD9C2620C17AA67005C90A2 /* JSDOMWindowCustom.cpp in Sources */,
BCBFB53C0DCD29CF0019B3E5 /* JSDOMWindowShell.cpp in Sources */,
A80A9423149F225E00989291 /* JSDOMWindowWebAudioCustom.cpp in Sources */,
A80A9425149F227100989291 /* JSDOMWindowWebSocketCustom.cpp in Sources */,
CDDE691F171DFAD000A44D89 /* JSAudioBufferCustom.cpp in Sources */,
FD7868B9136B999200D403DF /* JSDynamicsCompressorNode.cpp in Sources */,
65DF31F909D1CC60000BE325 /* JSElement.cpp in Sources */,
......@@ -70,7 +70,6 @@
#include "JSDOMWindowCustom.cpp"
#include "JSDOMWindowShell.cpp"
#include "JSDOMWindowWebAudioCustom.cpp"
#include "JSDOMWindowWebSocketCustom.cpp"
#include "JSDOMWrapper.cpp"
#include "JSDataViewCustom.cpp"
#include "JSDedicatedWorkerContextCustom.cpp"
......
......@@ -547,15 +547,6 @@ JSValue JSDOMWindow::audio(ExecState* exec) const
}
#endif
#if ENABLE(SHARED_WORKERS)
JSValue JSDOMWindow::sharedWorker(ExecState* exec) const
{
if (SharedWorkerRepository::isAvailable())
return getDOMConstructor<JSSharedWorkerConstructor>(exec, this);
return jsUndefined();
}
#endif
// Custom functions
JSValue JSDOMWindow::open(ExecState* exec)
......
/*
* Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
* Copyright (C) 2011 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSDOMWindowCustom.h"
#if ENABLE(WEB_SOCKETS)
#include "Frame.h"
#include "JSWebSocket.h"
#include "Settings.h"
using namespace JSC;
namespace WebCore {
static Settings* settingsForWindowWebSocket(const JSDOMWindow* window)
{
ASSERT(window);
if (Frame* frame = window->impl()->frame())
return frame->settings();
return 0;
}
JSValue JSDOMWindow::webSocket(ExecState* exec) const
{
if (!settingsForWindowWebSocket(this))
return jsUndefined();
return getDOMConstructor<JSWebSocketConstructor>(exec, this);
}
} // namespace WebCore
#endif
......@@ -1510,6 +1510,37 @@ sub GetSkipVTableValidationForInterface
return $interface->extendedAttributes->{"SkipVTableValidation"};
}
# URL becomes url, but SetURL becomes setURL.
sub ToMethodName
{
my $param = shift;
my $ret = lcfirst($param);
$ret =~ s/hTML/html/ if $ret =~ /^hTML/;
$ret =~ s/uRL/url/ if $ret =~ /^uRL/;
$ret =~ s/jS/js/ if $ret =~ /^jS/;
$ret =~ s/xML/xml/ if $ret =~ /^xML/;
$ret =~ s/xSLT/xslt/ if $ret =~ /^xSLT/;
$ret =~ s/cSS/css/ if $ret =~ /^cSS/;
# For HTML5 FileSystem API Flags attributes.
# (create is widely used to instantiate an object and must be avoided.)
$ret =~ s/^create/isCreate/ if $ret =~ /^create$/;
$ret =~ s/^exclusive/isExclusive/ if $ret =~ /^exclusive$/;
return $ret;
}
# Returns the RuntimeEnabledFeatures function name that is hooked up to check if a method/attribute is enabled.
sub GetRuntimeEnableFunctionName
{
my $signature = shift;
# If a parameter is given (e.g. "EnabledAtRuntime=FeatureName") return the RuntimeEnabledFeatures::{FeatureName}Enabled() method.
return "RuntimeEnabledFeatures::" . ToMethodName($signature->extendedAttributes->{"EnabledAtRuntime"}) . "Enabled" if ($signature->extendedAttributes->{"EnabledAtRuntime"} && $signature->extendedAttributes->{"EnabledAtRuntime"} ne "VALUE_IS_MISSING");
# Otherwise return a function named RuntimeEnabledFeatures::{methodName}Enabled().
return "RuntimeEnabledFeatures::" . ToMethodName($signature->name) . "Enabled";
}
sub GenerateImplementation
{
......@@ -1947,6 +1978,14 @@ sub GenerateImplementation
push(@implContent, "JSValue ${getFunctionName}(ExecState* exec, JSValue slotBase, PropertyName)\n");
push(@implContent, "{\n");
# Global constructors can be disabled at runtime.
if ($attribute->signature->extendedAttributes->{"EnabledAtRuntime"} && $attribute->signature->type =~ /Constructor$/) {
AddToImplIncludes("RuntimeEnabledFeatures.h");
my $enable_function = GetRuntimeEnableFunctionName($attribute->signature);
push(@implContent, " if (!${enable_function}())\n");
push(@implContent, " return jsUndefined();\n");
}
if (!$attribute->isStatic || $attribute->signature->type =~ /Constructor$/) {
push(@implContent, " ${className}* castedThis = jsCast<$className*>(asObject(slotBase));\n");
} else {
......
......@@ -52,6 +52,7 @@ DoNotCheckConstants
DoNotCheckSecurity
DoNotCheckSecurityOnGetter
DoNotCheckSecurityOnSetter
EnabledAtRuntime=*
EnforceRange
EventTarget
ExtendsDOMGlobalObject
......
......@@ -326,8 +326,6 @@
attribute HTMLOptionElementConstructor HTMLOptionElement;
[CustomGetter, Conditional=VIDEO] attribute HTMLAudioElementConstructorConstructor Audio; // Usable with the new operator
[Conditional=VIDEO] attribute HTMLAudioElementConstructor HTMLAudioElement;
[Conditional=WEB_SOCKETS, CustomGetter] attribute WebSocketConstructor WebSocket;
[Conditional=SHARED_WORKERS, CustomGetter] attribute SharedWorkerConstructor SharedWorker; // Usable with the new operator
// Mozilla has a separate XMLDocument object for XML documents.
// We just use Document for this.
attribute DocumentConstructor XMLDocument;
......
......@@ -30,7 +30,7 @@
*/
[
NoInterfaceObject,
EnabledAtRuntime,
Conditional=SHARED_WORKERS,
CustomConstructor,
Constructor(DOMString scriptURL, [Default=NullString] optional DOMString name),
......
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