Commit 194cc74e authored by akling@apple.com's avatar akling@apple.com

Move BindingSecurity stuff under JSDOMBinding umbrella.

<https://webkit.org/b/124099>

We are hitting shouldAllowAccessToDOMWindow() pretty hard on the
demo here: <http://www.jasondavies.com/maps/rotate/>

Putting it together with the rest of the JSDOMBinding code takes
CPU time spent in there from 8.7% to 6.5%. The abstraction was
only used to support alternate JS engines in the past.

Reviewed by Antti Koivisto.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@158997 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a8052e1f
......@@ -969,7 +969,6 @@ set(WebCore_SOURCES
accessibility/AccessibilityTableRow.cpp
bindings/generic/ActiveDOMCallback.cpp
bindings/generic/BindingSecurity.cpp
bindings/generic/RuntimeEnabledFeatures.cpp
css/BasicShapeFunctions.cpp
......
2013-11-09 Andreas Kling <akling@apple.com>
Move BindingSecurity stuff under JSDOMBinding umbrella.
<https://webkit.org/b/124099>
We are hitting shouldAllowAccessToDOMWindow() pretty hard on the
demo here: <http://www.jasondavies.com/maps/rotate/>
Putting it together with the rest of the JSDOMBinding code takes
CPU time spent in there from 8.7% to 6.5%. The abstraction was
only used to support alternate JS engines in the past.
Reviewed by Antti Koivisto.
2013-11-08 Brady Eidson <beidson@apple.com>
Merge IDBDatabaseBackendInterface and IDBDatabaseBackendImpl
......
......@@ -2237,8 +2237,6 @@ webcore_sources += \
Source/WebCore/accessibility/AXObjectCache.h \
Source/WebCore/bindings/generic/ActiveDOMCallback.cpp \
Source/WebCore/bindings/generic/ActiveDOMCallback.h \
Source/WebCore/bindings/generic/BindingSecurity.cpp \
Source/WebCore/bindings/generic/BindingSecurity.h \
Source/WebCore/bindings/generic/RuntimeEnabledFeatures.cpp \
Source/WebCore/bindings/generic/RuntimeEnabledFeatures.h \
Source/WebCore/bindings/js/ArrayValue.cpp \
......
......@@ -15506,7 +15506,6 @@
<ClCompile Include="..\html\track\WebVTTParser.cpp" />
<ClCompile Include="..\html\track\WebVTTTokenizer.cpp" />
<ClCompile Include="..\bindings\generic\ActiveDOMCallback.cpp" />
<ClCompile Include="..\bindings\generic\BindingSecurity.cpp" />
<ClCompile Include="..\bindings\generic\RuntimeEnabledFeatures.cpp" />
<ClCompile Include="..\bindings\js\ArrayValue.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
......@@ -20317,7 +20316,6 @@
<ClInclude Include="..\html\track\WebVTTToken.h" />
<ClInclude Include="..\html\track\WebVTTTokenizer.h" />
<ClInclude Include="..\bindings\generic\ActiveDOMCallback.h" />
<ClInclude Include="..\bindings\generic\BindingSecurity.h" />
<ClInclude Include="..\bindings\generic\RuntimeEnabledFeatures.h" />
<ClInclude Include="..\bindings\js\ArrayValue.h" />
<ClInclude Include="..\bindings\js\BreakpointID.h" />
......@@ -4248,9 +4248,6 @@
<ClCompile Include="..\bindings\generic\ActiveDOMCallback.cpp">
<Filter>bindings\generic</Filter>
</ClCompile>
<ClCompile Include="..\bindings\generic\BindingSecurity.cpp">
<Filter>bindings\generic</Filter>
</ClCompile>
<ClCompile Include="..\bindings\generic\RuntimeEnabledFeatures.cpp">
<Filter>bindings\generic</Filter>
</ClCompile>
......@@ -11322,9 +11319,6 @@
<ClInclude Include="..\bindings\generic\ActiveDOMCallback.h">
<Filter>bindings\generic</Filter>
</ClInclude>
<ClInclude Include="..\bindings\generic\BindingSecurity.h">
<Filter>bindings\generic</Filter>
</ClInclude>
<ClInclude Include="..\bindings\generic\RuntimeEnabledFeatures.h">
<Filter>bindings\generic</Filter>
</ClInclude>
......
......@@ -3177,8 +3177,6 @@
9728C3141268E4390041E89B /* MarkupAccumulator.h in Headers */ = {isa = PBXBuildFile; fileRef = 9728C3121268E4390041E89B /* MarkupAccumulator.h */; };
973889A0116EA9DC00ADF313 /* DocumentWriter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9738899E116EA9DC00ADF313 /* DocumentWriter.cpp */; };
973889A1116EA9DC00ADF313 /* DocumentWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = 9738899F116EA9DC00ADF313 /* DocumentWriter.h */; settings = {ATTRIBUTES = (Private, ); }; };
973AA3F915D0891B00E38A85 /* BindingSecurity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 973AA3F715D0891B00E38A85 /* BindingSecurity.cpp */; };
973AA3FA15D0891B00E38A85 /* BindingSecurity.h in Headers */ = {isa = PBXBuildFile; fileRef = 973AA3F815D0891B00E38A85 /* BindingSecurity.h */; };
973DC63F145A9409002842C2 /* ExceptionCodeDescription.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 973DC63D145A9409002842C2 /* ExceptionCodeDescription.cpp */; };
973DC640145A9409002842C2 /* ExceptionCodeDescription.h in Headers */ = {isa = PBXBuildFile; fileRef = 973DC63E145A9409002842C2 /* ExceptionCodeDescription.h */; settings = {ATTRIBUTES = (Private, ); }; };
973E325610883B7C005BC493 /* ResourceLoadNotifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 973E325410883B7C005BC493 /* ResourceLoadNotifier.cpp */; };
......@@ -9894,8 +9892,6 @@
9728C3121268E4390041E89B /* MarkupAccumulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MarkupAccumulator.h; sourceTree = "<group>"; };
9738899E116EA9DC00ADF313 /* DocumentWriter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentWriter.cpp; sourceTree = "<group>"; };
9738899F116EA9DC00ADF313 /* DocumentWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentWriter.h; sourceTree = "<group>"; };
973AA3F715D0891B00E38A85 /* BindingSecurity.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BindingSecurity.cpp; path = generic/BindingSecurity.cpp; sourceTree = "<group>"; };
973AA3F815D0891B00E38A85 /* BindingSecurity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BindingSecurity.h; path = generic/BindingSecurity.h; sourceTree = "<group>"; };
973DC63D145A9409002842C2 /* ExceptionCodeDescription.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExceptionCodeDescription.cpp; sourceTree = "<group>"; };
973DC63E145A9409002842C2 /* ExceptionCodeDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExceptionCodeDescription.h; sourceTree = "<group>"; };
973E325410883B7C005BC493 /* ResourceLoadNotifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceLoadNotifier.cpp; sourceTree = "<group>"; };
......@@ -19396,8 +19392,6 @@
children = (
B5D31DF811CF610B009F22B4 /* ActiveDOMCallback.cpp */,
B5D31DF911CF610B009F22B4 /* ActiveDOMCallback.h */,
973AA3F715D0891B00E38A85 /* BindingSecurity.cpp */,
973AA3F815D0891B00E38A85 /* BindingSecurity.h */,
);
name = generic;
sourceTree = "<group>";
......@@ -22016,7 +22010,6 @@
B2C3DA250D006C1D00EF6F26 /* BidiResolver.h in Headers */,
BCE789861120E7A60060ECE5 /* BidiRun.h in Headers */,
A8C402931348B2220063F1E5 /* BidiRunList.h in Headers */,
973AA3FA15D0891B00E38A85 /* BindingSecurity.h in Headers */,
F35AE5AC14925F5B004D5776 /* BindingVisitors.h in Headers */,
FD31608D12B026F700C1A359 /* Biquad.h in Headers */,
FD31602512B0267600C1A359 /* BiquadDSPKernel.h in Headers */,
......@@ -25540,7 +25533,6 @@
85031B3C0A44EFC700F992E0 /* BeforeUnloadEvent.cpp in Sources */,
B2C3DA230D006C1D00EF6F26 /* BidiContext.cpp in Sources */,
BCE7898B1120E8020060ECE5 /* BidiRun.cpp in Sources */,
973AA3F915D0891B00E38A85 /* BindingSecurity.cpp in Sources */,
FD31608C12B026F700C1A359 /* Biquad.cpp in Sources */,
FD31602412B0267600C1A359 /* BiquadDSPKernel.cpp in Sources */,
FDC54F041399B0DA008D9117 /* BiquadFilterNode.cpp in Sources */,
/*
* Copyright (C) 2009 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.
*/
#include "config.h"
#include "BindingSecurity.h"
#include "DOMWindow.h"
#include "Document.h"
#include "Frame.h"
#include "HTMLFrameElementBase.h"
#include "HTMLParserIdioms.h"
#include "JSDOMBinding.h"
#include "SecurityOrigin.h"
#include "Settings.h"
namespace WebCore {
static bool canAccessDocument(JSC::ExecState* state, Document* targetDocument, SecurityReportingOption reportingOption = ReportSecurityError)
{
if (!targetDocument)
return false;
DOMWindow& active = activeDOMWindow(state);
if (active.document()->securityOrigin()->canAccess(targetDocument->securityOrigin()))
return true;
if (reportingOption == ReportSecurityError)
printErrorMessageForFrame(targetDocument->frame(), targetDocument->domWindow()->crossDomainAccessErrorMessage(active));
return false;
}
bool BindingSecurity::shouldAllowAccessToDOMWindow(JSC::ExecState* state, DOMWindow& target, SecurityReportingOption reportingOption)
{
return canAccessDocument(state, target.document(), reportingOption);
}
bool BindingSecurity::shouldAllowAccessToFrame(JSC::ExecState* state, Frame* target, SecurityReportingOption reportingOption)
{
return target && canAccessDocument(state, target->document(), reportingOption);
}
bool BindingSecurity::shouldAllowAccessToNode(JSC::ExecState* state, Node* target)
{
return target && canAccessDocument(state, &target->document());
}
bool BindingSecurity::allowSettingFrameSrcToJavascriptUrl(JSC::ExecState* state, HTMLFrameElementBase* frame, const String& value)
{
return !protocolIsJavaScript(stripLeadingAndTrailingHTMLSpaces(value)) || canAccessDocument(state, frame->contentDocument());
}
}
/*
* Copyright (C) 2009 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.
*/
#ifndef BindingSecurity_h
#define BindingSecurity_h
#include <wtf/text/WTFString.h>
namespace JSC {
class ExecState;
}
namespace WebCore {
class DOMWindow;
class Frame;
class HTMLFrameElementBase;
class Node;
enum SecurityReportingOption {
DoNotReportSecurityError,
ReportSecurityError,
};
class BindingSecurity {
public:
static bool shouldAllowAccessToNode(JSC::ExecState*, Node*);
static bool shouldAllowAccessToDOMWindow(JSC::ExecState*, DOMWindow&, SecurityReportingOption = ReportSecurityError);
static bool shouldAllowAccessToFrame(JSC::ExecState*, Frame*, SecurityReportingOption = ReportSecurityError);
static bool allowSettingFrameSrcToJavascriptUrl(JSC::ExecState*, HTMLFrameElementBase*, const String& value);
};
}
#endif
......@@ -22,7 +22,6 @@
#include "config.h"
#include "JSDOMBinding.h"
#include "BindingSecurity.h"
#include "CachedScript.h"
#include "DOMConstructorWithDocument.h"
#include "DOMObjectHashTableMap.h"
......@@ -31,8 +30,10 @@
#include "ExceptionHeaders.h"
#include "ExceptionInterfaces.h"
#include "Frame.h"
#include "HTMLParserIdioms.h"
#include "JSDOMWindowCustom.h"
#include "JSExceptionBase.h"
#include "SecurityOrigin.h"
#include "ScriptCallStack.h"
#include "ScriptCallStackFactory.h"
#include <interpreter/Interpreter.h>
......@@ -496,4 +497,35 @@ DOMWindow& firstDOMWindow(ExecState* exec)
return asJSDOMWindow(exec->dynamicGlobalObject())->impl();
}
static inline bool canAccessDocument(JSC::ExecState* state, Document* targetDocument, SecurityReportingOption reportingOption = ReportSecurityError)
{
if (!targetDocument)
return false;
DOMWindow& active = activeDOMWindow(state);
if (active.document()->securityOrigin()->canAccess(targetDocument->securityOrigin()))
return true;
if (reportingOption == ReportSecurityError)
printErrorMessageForFrame(targetDocument->frame(), targetDocument->domWindow()->crossDomainAccessErrorMessage(active));
return false;
}
bool BindingSecurity::shouldAllowAccessToDOMWindow(JSC::ExecState* state, DOMWindow& target, SecurityReportingOption reportingOption)
{
return canAccessDocument(state, target.document(), reportingOption);
}
bool BindingSecurity::shouldAllowAccessToFrame(JSC::ExecState* state, Frame* target, SecurityReportingOption reportingOption)
{
return target && canAccessDocument(state, target->document(), reportingOption);
}
bool BindingSecurity::shouldAllowAccessToNode(JSC::ExecState* state, Node* target)
{
return target && canAccessDocument(state, &target->document());
}
} // namespace WebCore
......@@ -645,6 +645,18 @@ template <typename T> struct ReportMemoryCost<T, false> {
}
};
enum SecurityReportingOption {
DoNotReportSecurityError,
ReportSecurityError,
};
class BindingSecurity {
public:
static bool shouldAllowAccessToNode(JSC::ExecState*, Node*);
static bool shouldAllowAccessToDOMWindow(JSC::ExecState*, DOMWindow&, SecurityReportingOption = ReportSecurityError);
static bool shouldAllowAccessToFrame(JSC::ExecState*, Frame*, SecurityReportingOption = ReportSecurityError);
};
} // namespace WebCore
#endif // JSDOMBinding_h
......@@ -23,7 +23,6 @@
#include "config.h"
#include "JSDOMWindowBase.h"
#include "BindingSecurity.h"
#include "Chrome.h"
#include "Console.h"
#include "DOMWindow.h"
......
......@@ -21,7 +21,6 @@
#include "config.h"
#include "JSDOMWindowCustom.h"
#include "BindingSecurity.h"
#include "Frame.h"
#include "HTMLCollection.h"
#include "HTMLDocument.h"
......
......@@ -36,7 +36,6 @@
#include "InjectedScriptManager.h"
#include "BindingSecurity.h"
#include "ExceptionCode.h"
#include "JSDOMWindow.h"
#include "JSDOMWindowCustom.h"
......
......@@ -26,7 +26,6 @@
#import "config.h"
#import "WebScriptObjectPrivate.h"
#import "BindingSecurity.h"
#import "BridgeJSC.h"
#import "Console.h"
#import "DOMInternal.h"
......
......@@ -1908,7 +1908,6 @@ sub GenerateImplementation
if ($interface->extendedAttributes->{"CheckSecurity"} &&
!$attribute->signature->extendedAttributes->{"DoNotCheckSecurity"} &&
!$attribute->signature->extendedAttributes->{"DoNotCheckSecurityOnGetter"}) {
$implIncludes{"BindingSecurity.h"} = 1;
push(@implContent, " if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, castedThis->impl()))\n");
push(@implContent, " return jsUndefined();\n");
}
......@@ -2047,7 +2046,6 @@ sub GenerateImplementation
push(@implContent, " ${className}* domObject = jsCast<$className*>(asObject(slotBase));\n");
if ($interface->extendedAttributes->{"CheckSecurity"}) {
$implIncludes{"BindingSecurity.h"} = 1;
push(@implContent, " if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, domObject->impl()))\n");
push(@implContent, " return jsUndefined();\n");
}
......@@ -2138,7 +2136,6 @@ sub GenerateImplementation
if ($interface->extendedAttributes->{"CheckSecurity"} && !$attribute->signature->extendedAttributes->{"DoNotCheckSecurity"}) {
if ($interfaceName eq "DOMWindow") {
$implIncludes{"BindingSecurity.h"} = 1;
push(@implContent, " if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, jsCast<$className*>(thisObject)->impl()))\n");
} else {
push(@implContent, " if (!shouldAllowAccessToFrame(exec, jsCast<$className*>(thisObject)->impl().frame()))\n");
......@@ -2285,7 +2282,6 @@ sub GenerateImplementation
push(@implContent, "{\n");
if ($interface->extendedAttributes->{"CheckSecurity"}) {
if ($interfaceName eq "DOMWindow") {
$implIncludes{"BindingSecurity.h"} = 1;
push(@implContent, " if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, jsCast<$className*>(thisObject)->impl()))\n");
} else {
push(@implContent, " if (!shouldAllowAccessToFrame(exec, jsCast<$className*>(thisObject)->impl().frame()))\n");
......@@ -2395,7 +2391,6 @@ sub GenerateImplementation
if ($interface->extendedAttributes->{"CheckSecurity"} and
!$function->signature->extendedAttributes->{"DoNotCheckSecurity"}) {
$implIncludes{"BindingSecurity.h"} = 1;
push(@implContent, " if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, castedThis->impl()))\n");
push(@implContent, " return JSValue::encode(jsUndefined());\n");
}
......
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