Title: [173333] trunk
Revision
173333
Author
commit-qu...@webkit.org
Date
2014-09-05 14:08:14 -0700 (Fri, 05 Sep 2014)

Log Message

Web Inspector: breakpoint actions should work regardless of Content Security Policy
https://bugs.webkit.org/show_bug.cgi?id=136542

Patch by Matt Baker <mattba...@apple.com> on 2014-09-05
Reviewed by Mark Lam.

Source/_javascript_Core:

Added JSC::DebuggerEvalEnabler, an RAII object which enables eval on a
JSGlobalObject for the duration of a scope, returning the eval enabled state to its
original value when the scope exits. Used by JSC::DebuggerCallFrame::evaluate
to allow breakpoint actions to execute JS in pages with a Content Security Policy
that would normally prohibit this (such as Inspector's Main.html).

Refactored Inspector::InjectedScriptBase to use the RAII object instead of manually
setting eval enabled and then resetting the original eval enabled state.

NOTE: The JS::DebuggerEvalEnabler constructor checks the passed in ExecState pointer
for null to be equivalent with the original code in Inspector::InjectedScriptBase.
InjectedScriptBase is getting the ExecState from ScriptObject::scriptState(), which
can currently be null.

* _javascript_Core.vcxproj/_javascript_Core.vcxproj:
* _javascript_Core.vcxproj/_javascript_Core.vcxproj.filters:
* _javascript_Core.xcodeproj/project.pbxproj:
* debugger/DebuggerCallFrame.cpp:
(JSC::DebuggerCallFrame::evaluate):
* debugger/DebuggerEvalEnabler.h: Added.
(JSC::DebuggerEvalEnabler::DebuggerEvalEnabler):
(JSC::DebuggerEvalEnabler::~DebuggerEvalEnabler):
* inspector/InjectedScriptBase.cpp:
(Inspector::InjectedScriptBase::callFunctionWithEvalEnabled):

LayoutTests:

Added test for "Evaluate _javascript_" breakpoint actions for breakpoints set on
pages with a CSP that does not allow 'unsafe-eval'.

* inspector/debugger/breakpoint-action-eval-expected.txt: Added.
* inspector/debugger/breakpoint-action-eval.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (173332 => 173333)


--- trunk/LayoutTests/ChangeLog	2014-09-05 20:57:55 UTC (rev 173332)
+++ trunk/LayoutTests/ChangeLog	2014-09-05 21:08:14 UTC (rev 173333)
@@ -1,3 +1,16 @@
+2014-09-05  Matt Baker  <mattba...@apple.com>
+
+        Web Inspector: breakpoint actions should work regardless of Content Security Policy
+        https://bugs.webkit.org/show_bug.cgi?id=136542
+
+        Reviewed by Mark Lam.
+
+        Added test for "Evaluate _javascript_" breakpoint actions for breakpoints set on
+        pages with a CSP that does not allow 'unsafe-eval'.
+
+        * inspector/debugger/breakpoint-action-eval-expected.txt: Added.
+        * inspector/debugger/breakpoint-action-eval.html: Added.
+
 2014-09-05  Carlos Alberto Lopez Perez  <clo...@igalia.com>
 
         [SOUP] Implement ResourceResponse::platformSuggestedFilename() when USE(SOUP) is enabled.

Added: trunk/LayoutTests/inspector/debugger/breakpoint-action-eval-expected.txt (0 => 173333)


--- trunk/LayoutTests/inspector/debugger/breakpoint-action-eval-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/debugger/breakpoint-action-eval-expected.txt	2014-09-05 21:08:14 UTC (rev 173333)
@@ -0,0 +1,5 @@
+Testing that "Evaluate _javascript_" breakpoint actions work correctly in the presense of a Content Security Policy that doesn't include 'unsafe-eval'.
+
+inside breakpointActions a:(42) b:([object Object])
+Breakpoint action evaluated. a:(42) b:([object Object])
+

Added: trunk/LayoutTests/inspector/debugger/breakpoint-action-eval.html (0 => 173333)


--- trunk/LayoutTests/inspector/debugger/breakpoint-action-eval.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/debugger/breakpoint-action-eval.html	2014-09-05 21:08:14 UTC (rev 173333)
@@ -0,0 +1,46 @@
+<!doctype html>
+<html>
+<head>
+<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'">
+<script type="text/_javascript_" src=""
+<script type="text/_javascript_" src=""
+<script type="text/_javascript_" src=""
+<script>
+function runBreakpointActions()
+{
+    setTimeout(function() { breakpointActions(42, {x:220, y:284}); }, 0);
+}
+
+function action(a, b)
+{
+    InspectorTestProxy.addResult("Breakpoint action evaluated. a:(" + a + ") b:(" + b + ")");
+    InspectorTestProxy.completeTest();
+}
+
+function test()
+{
+    WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, function(event) {
+        var scriptObject = event.data.script;
+
+        if (!/breakpoint\.js$/.test(scriptObject.url))
+            return;
+
+        var location = scriptObject.createSourceCodeLocation(4, 0);
+        // Create the breakpoint and its actions before sending anything to the backend.
+        var breakpoint = new WebInspector.Breakpoint(location);
+        breakpoint.autoContinue = true;
+        breakpoint.createAction(WebInspector.BreakpointAction.Type.Evaluate, null, "action(a, b)");
+
+        WebInspector.debuggerManager.addBreakpoint(breakpoint);
+
+        InspectorTest.evaluateInPage("runBreakpointActions()");
+    });
+
+    InspectorTest.reloadPage();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+    <p>Testing that "Evaluate _javascript_" breakpoint actions work correctly in the presense of a Content Security Policy that doesn't include 'unsafe-eval'.</p>
+</body>
+</html>

Modified: trunk/Source/_javascript_Core/ChangeLog (173332 => 173333)


--- trunk/Source/_javascript_Core/ChangeLog	2014-09-05 20:57:55 UTC (rev 173332)
+++ trunk/Source/_javascript_Core/ChangeLog	2014-09-05 21:08:14 UTC (rev 173333)
@@ -1,3 +1,35 @@
+2014-09-05  Matt Baker  <mattba...@apple.com>
+
+        Web Inspector: breakpoint actions should work regardless of Content Security Policy
+        https://bugs.webkit.org/show_bug.cgi?id=136542
+
+        Reviewed by Mark Lam.
+
+        Added JSC::DebuggerEvalEnabler, an RAII object which enables eval on a 
+        JSGlobalObject for the duration of a scope, returning the eval enabled state to its
+        original value when the scope exits. Used by JSC::DebuggerCallFrame::evaluate 
+        to allow breakpoint actions to execute JS in pages with a Content Security Policy
+        that would normally prohibit this (such as Inspector's Main.html).
+
+        Refactored Inspector::InjectedScriptBase to use the RAII object instead of manually
+        setting eval enabled and then resetting the original eval enabled state.
+
+        NOTE: The JS::DebuggerEvalEnabler constructor checks the passed in ExecState pointer
+        for null to be equivalent with the original code in Inspector::InjectedScriptBase.
+        InjectedScriptBase is getting the ExecState from ScriptObject::scriptState(), which
+        can currently be null.
+
+        * _javascript_Core.vcxproj/_javascript_Core.vcxproj:
+        * _javascript_Core.vcxproj/_javascript_Core.vcxproj.filters:
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        * debugger/DebuggerCallFrame.cpp:
+        (JSC::DebuggerCallFrame::evaluate):
+        * debugger/DebuggerEvalEnabler.h: Added.
+        (JSC::DebuggerEvalEnabler::DebuggerEvalEnabler):
+        (JSC::DebuggerEvalEnabler::~DebuggerEvalEnabler):
+        * inspector/InjectedScriptBase.cpp:
+        (Inspector::InjectedScriptBase::callFunctionWithEvalEnabled):
+
 2014-09-05  pe...@outlook.com  <pe...@outlook.com>
 
         [WinCairo] jsc.exe won't run.

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj (173332 => 173333)


--- trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj	2014-09-05 20:57:55 UTC (rev 173332)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj	2014-09-05 21:08:14 UTC (rev 173333)
@@ -974,6 +974,7 @@
     <ClInclude Include="..\debugger\Breakpoint.h" />
     <ClInclude Include="..\debugger\Debugger.h" />
     <ClInclude Include="..\debugger\DebuggerCallFrame.h" />
+    <ClInclude Include="..\debugger\DebuggerEvalEnabler.h" />
     <ClInclude Include="..\debugger\DebuggerPrimitives.h" />
     <ClInclude Include="..\debugger\DebuggerScope.h" />
     <ClInclude Include="..\dfg\DFGAbstractHeap.h" />

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj.filters (173332 => 173333)


--- trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj.filters	2014-09-05 20:57:55 UTC (rev 173332)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj.filters	2014-09-05 21:08:14 UTC (rev 173333)
@@ -1958,6 +1958,9 @@
     <ClInclude Include="..\debugger\DebuggerCallFrame.h">
       <Filter>debugger</Filter>
     </ClInclude>
+    <ClInclude Include="..\debugger\DebuggerEvalEnabler.h">
+      <Filter>debugger</Filter>
+    </ClInclude>
     <ClInclude Include="..\debugger\DebuggerPrimitives.h">
       <Filter>debugger</Filter>
     </ClInclude>

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (173332 => 173333)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2014-09-05 20:57:55 UTC (rev 173332)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2014-09-05 21:08:14 UTC (rev 173333)
@@ -1172,6 +1172,7 @@
 		65C0285C1717966800351E35 /* ARMv7DOpcode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65C0285A1717966800351E35 /* ARMv7DOpcode.cpp */; };
 		65C0285D1717966800351E35 /* ARMv7DOpcode.h in Headers */ = {isa = PBXBuildFile; fileRef = 65C0285B1717966800351E35 /* ARMv7DOpcode.h */; };
 		65FB5117184EEE7000C12B70 /* ProtoCallFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65FB5116184EE9BC00C12B70 /* ProtoCallFrame.cpp */; };
+		6AD2CB4D19B9140100065719 /* DebuggerEvalEnabler.h in Headers */ = {isa = PBXBuildFile; fileRef = 6AD2CB4C19B9140100065719 /* DebuggerEvalEnabler.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7C008CD2186F8A9300955C24 /* JSPromiseFunctions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C008CD0186F8A9300955C24 /* JSPromiseFunctions.cpp */; };
 		7C008CD3186F8A9300955C24 /* JSPromiseFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C008CD1186F8A9300955C24 /* JSPromiseFunctions.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7C008CDA187124BB00955C24 /* JSPromiseDeferred.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C008CD8187124BB00955C24 /* JSPromiseDeferred.cpp */; };
@@ -2811,6 +2812,7 @@
 		65EA73630BAE35D1001BB560 /* CommonIdentifiers.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CommonIdentifiers.h; sourceTree = "<group>"; };
 		65FB5115184EE8F800C12B70 /* ProtoCallFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProtoCallFrame.h; sourceTree = "<group>"; };
 		65FB5116184EE9BC00C12B70 /* ProtoCallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProtoCallFrame.cpp; sourceTree = "<group>"; };
+		6AD2CB4C19B9140100065719 /* DebuggerEvalEnabler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebuggerEvalEnabler.h; sourceTree = "<group>"; };
 		704FD35305697E6D003DBED9 /* BooleanObject.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = BooleanObject.h; sourceTree = "<group>"; tabWidth = 8; };
 		7C008CD0186F8A9300955C24 /* JSPromiseFunctions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = JSPromiseFunctions.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
 		7C008CD1186F8A9300955C24 /* JSPromiseFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPromiseFunctions.h; sourceTree = "<group>"; };
@@ -4216,6 +4218,7 @@
 				F692A8590255597D01FF60F7 /* Debugger.h */,
 				149559ED0DDCDDF700648087 /* DebuggerCallFrame.cpp */,
 				1480DB9B0DDC227F003CFDF2 /* DebuggerCallFrame.h */,
+				6AD2CB4C19B9140100065719 /* DebuggerEvalEnabler.h */,
 				FEA0861F182B7A0400F6D851 /* DebuggerPrimitives.h */,
 				0F2D4DDB19832D34007D4B19 /* DebuggerScope.cpp */,
 				0F2D4DDC19832D34007D4B19 /* DebuggerScope.h */,
@@ -5752,6 +5755,7 @@
 				A1A009C11831A26E00CF8711 /* ARM64Assembler.h in Headers */,
 				86D3B2C410156BDE002865E7 /* ARMAssembler.h in Headers */,
 				C49FE4AB19AAC86100F40CE9 /* generate_protocol_types_header.py in Headers */,
+				6AD2CB4D19B9140100065719 /* DebuggerEvalEnabler.h in Headers */,
 				C49FE4AC19AAC86100F40CE9 /* generate_protocol_types_implementation.py in Headers */,
 				658D3A5619638268003C45D6 /* VMEntryRecord.h in Headers */,
 				2AD2EDFB19799E38004D6478 /* EnumerationMode.h in Headers */,

Modified: trunk/Source/_javascript_Core/debugger/DebuggerCallFrame.cpp (173332 => 173333)


--- trunk/Source/_javascript_Core/debugger/DebuggerCallFrame.cpp	2014-09-05 20:57:55 UTC (rev 173332)
+++ trunk/Source/_javascript_Core/debugger/DebuggerCallFrame.cpp	2014-09-05 21:08:14 UTC (rev 173333)
@@ -30,6 +30,7 @@
 #include "DebuggerCallFrame.h"
 
 #include "CodeBlock.h"
+#include "DebuggerEvalEnabler.h"
 #include "DebuggerScope.h"
 #include "Interpreter.h"
 #include "JSActivation.h"
@@ -186,6 +187,7 @@
     if (!callFrame->codeBlock())
         return JSValue();
     
+    DebuggerEvalEnabler evalEnabler(callFrame);
     VM& vm = callFrame->vm();
     EvalExecutable* eval = EvalExecutable::create(callFrame, makeSource(script), callFrame->codeBlock()->isStrictMode());
     if (vm.exception()) {

Added: trunk/Source/_javascript_Core/debugger/DebuggerEvalEnabler.h (0 => 173333)


--- trunk/Source/_javascript_Core/debugger/DebuggerEvalEnabler.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/debugger/DebuggerEvalEnabler.h	2014-09-05 21:08:14 UTC (rev 173333)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2014 Apple 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 APPLE INC. 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 DebuggerEvalEnabler_h
+#define DebuggerEvalEnabler_h
+
+#include "CallFrame.h"
+#include "JSGlobalObject.h"
+
+namespace JSC {
+
+class DebuggerEvalEnabler {
+public:
+    explicit DebuggerEvalEnabler(const ExecState* exec)
+        : m_exec(exec)
+        , m_evalWasDisabled(false)
+    {
+        if (exec) {
+            JSGlobalObject* globalObject = exec->lexicalGlobalObject();
+            m_evalWasDisabled = !globalObject->evalEnabled();
+            if (m_evalWasDisabled)
+                globalObject->setEvalEnabled(true, globalObject->evalDisabledErrorMessage());
+        }
+    }
+
+    ~DebuggerEvalEnabler()
+    {
+        if (m_evalWasDisabled) {
+            JSGlobalObject* globalObject = m_exec->lexicalGlobalObject();
+            globalObject->setEvalEnabled(false, globalObject->evalDisabledErrorMessage());
+        }
+    }
+
+private:
+    const ExecState* m_exec;
+    bool m_evalWasDisabled;
+};
+
+} // namespace JSC
+
+#endif // DebuggerEvalEnabler_h

Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptBase.cpp (173332 => 173333)


--- trunk/Source/_javascript_Core/inspector/InjectedScriptBase.cpp	2014-09-05 20:57:55 UTC (rev 173332)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptBase.cpp	2014-09-05 21:08:14 UTC (rev 173333)
@@ -34,6 +34,7 @@
 
 #if ENABLE(INSPECTOR)
 
+#include "DebuggerEvalEnabler.h"
 #include "InspectorValues.h"
 #include "JSCInlines.h"
 #include "JSGlobalObject.h"
@@ -81,19 +82,13 @@
         m_environment->willCallInjectedScriptFunction(m_injectedScriptObject.scriptState(), name(), 1);
 
     JSC::ExecState* scriptState = m_injectedScriptObject.scriptState();
-    bool evalIsDisabled = false;
-    if (scriptState) {
-        evalIsDisabled = !scriptState->lexicalGlobalObject()->evalEnabled();
-        // Temporarily enable allow evals for inspector.
-        if (evalIsDisabled)
-            scriptState->lexicalGlobalObject()->setEvalEnabled(true);
+    Deprecated::ScriptValue resultValue;
+
+    {
+        JSC::DebuggerEvalEnabler evalEnabler(scriptState);
+        resultValue = function.call(hadException);
     }
 
-    Deprecated::ScriptValue resultValue = function.call(hadException);
-
-    if (evalIsDisabled)
-        scriptState->lexicalGlobalObject()->setEvalEnabled(false);
-
     if (m_environment)
         m_environment->didCallInjectedScriptFunction(m_injectedScriptObject.scriptState());
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to