Changeset 106657 in webkit


Ignore:
Timestamp:
Feb 3, 2012 6:47:31 AM (12 years ago)
Author:
yurys@chromium.org
Message:

Web Inspector: console evaluation doesn't work on breakpoint in pages with CSP
https://bugs.webkit.org/show_bug.cgi?id=77203

Inspector console evaluation now works when debugger is paused in a page with
content-security-policy prohibiting evals.

Reviewed by Pavel Feldman.

Source/WebCore:

Test: inspector/debugger/eval-on-pause-blocked.html

  • bindings/js/JSInjectedScriptHostCustom.cpp:
  • bindings/js/ScriptState.cpp:

(WebCore::evalEnabled):
(WebCore):
(WebCore::setEvalEnabled):

  • bindings/js/ScriptState.h:

(WebCore):

  • bindings/v8/ScriptObject.h:

(WebCore::ScriptObject::ScriptObject):

  • bindings/v8/ScriptState.cpp:

(WebCore::evalEnabled):
(WebCore):
(WebCore::setEvalEnabled):

  • bindings/v8/ScriptState.h:

(WebCore):

  • bindings/v8/custom/V8InjectedScriptHostCustom.cpp:
  • inspector/InjectedScript.cpp:

(WebCore::InjectedScript::makeCall):

  • inspector/InjectedScriptHost.idl:
  • inspector/InjectedScriptSource.js:

(.):

LayoutTests:

  • inspector/debugger/eval-on-pause-blocked-expected.txt: Added.
  • inspector/debugger/eval-on-pause-blocked.html: Added.
Location:
trunk
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r106654 r106657  
     12012-01-27  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Web Inspector: console evaluation doesn't work on breakpoint in pages with CSP
     4        https://bugs.webkit.org/show_bug.cgi?id=77203
     5
     6        Inspector console evaluation now works when debugger is paused in a page with
     7        content-security-policy prohibiting evals.
     8
     9        Reviewed by Pavel Feldman.
     10
     11        * inspector/debugger/eval-on-pause-blocked-expected.txt: Added.
     12        * inspector/debugger/eval-on-pause-blocked.html: Added.
     13
    1142012-02-03  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r106655 r106657  
     12012-01-27  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Web Inspector: console evaluation doesn't work on breakpoint in pages with CSP
     4        https://bugs.webkit.org/show_bug.cgi?id=77203
     5
     6        Inspector console evaluation now works when debugger is paused in a page with
     7        content-security-policy prohibiting evals.
     8
     9        Reviewed by Pavel Feldman.
     10
     11        Test: inspector/debugger/eval-on-pause-blocked.html
     12
     13        * bindings/js/JSInjectedScriptHostCustom.cpp:
     14        * bindings/js/ScriptState.cpp:
     15        (WebCore::evalEnabled):
     16        (WebCore):
     17        (WebCore::setEvalEnabled):
     18        * bindings/js/ScriptState.h:
     19        (WebCore):
     20        * bindings/v8/ScriptObject.h:
     21        (WebCore::ScriptObject::ScriptObject):
     22        * bindings/v8/ScriptState.cpp:
     23        (WebCore::evalEnabled):
     24        (WebCore):
     25        (WebCore::setEvalEnabled):
     26        * bindings/v8/ScriptState.h:
     27        (WebCore):
     28        * bindings/v8/custom/V8InjectedScriptHostCustom.cpp:
     29        * inspector/InjectedScript.cpp:
     30        (WebCore::InjectedScript::makeCall):
     31        * inspector/InjectedScriptHost.idl:
     32        * inspector/InjectedScriptSource.js:
     33        (.):
     34
    1352012-02-03  Rob Buis  <rbuis@rim.com>
    236
  • trunk/Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp

    r106101 r106657  
    7777}
    7878
    79 JSValue JSInjectedScriptHost::evaluate(ExecState* exec)
    80 {
    81     JSValue expression = exec->argument(0);
    82     if (!expression.isString())
    83         return throwError(exec, createError(exec, "String argument expected."));
    84     JSGlobalObject* globalObject = exec->lexicalGlobalObject();
    85     JSFunction* evalFunction = globalObject->evalFunction();
    86     CallData callData;
    87     CallType callType = evalFunction->methodTable()->getCallData(evalFunction, callData);
    88     if (callType == CallTypeNone)
    89         return jsUndefined();
    90     MarkedArgumentBuffer args;
    91     args.append(expression);
    92 
    93     bool wasEvalEnabled = globalObject->evalEnabled();
    94     globalObject->setEvalEnabled(true);
    95     JSValue result = JSC::call(exec, evalFunction, callType, callData, exec->globalThisValue(), args);
    96     globalObject->setEvalEnabled(wasEvalEnabled);
    97 
    98     return result;
    99 }
    100 
    10179JSValue JSInjectedScriptHost::inspectedNode(ExecState* exec)
    10280{
  • trunk/Source/WebCore/bindings/js/ScriptState.cpp

    r96465 r106657  
    7272}
    7373
     74bool evalEnabled(ScriptState* scriptState)
     75{
     76    JSC::JSGlobalObject* globalObject = scriptState->lexicalGlobalObject();
     77    return globalObject->evalEnabled();
     78}
     79
     80void setEvalEnabled(ScriptState* scriptState, bool enabled)
     81{
     82    JSC::JSGlobalObject* globalObject = scriptState->lexicalGlobalObject();
     83    return globalObject->setEvalEnabled(enabled);
     84}
     85
    7486ScriptState* mainWorldScriptState(Frame* frame)
    7587{
  • trunk/Source/WebCore/bindings/js/ScriptState.h

    r95901 r106657  
    6767DOMWindow* domWindowFromScriptState(ScriptState*);
    6868
     69bool evalEnabled(ScriptState*);
     70void setEvalEnabled(ScriptState*, bool);
     71
    6972ScriptState* mainWorldScriptState(Frame*);
    7073
  • trunk/Source/WebCore/bindings/v8/ScriptObject.h

    r95901 r106657  
    4444    public:
    4545        ScriptObject(ScriptState*, v8::Handle<v8::Object>);
    46         ScriptObject() {};
     46        ScriptObject() : m_scriptState(0) { };
    4747        virtual ~ScriptObject() {}
    4848
  • trunk/Source/WebCore/bindings/v8/ScriptState.cpp

    r97258 r106657  
    110110}
    111111
     112bool evalEnabled(ScriptState* scriptState)
     113{
     114    v8::HandleScope handleScope;
     115    return scriptState->context()->IsCodeGenerationFromStringsAllowed();
     116}
     117
     118void setEvalEnabled(ScriptState* scriptState, bool enabled)
     119{
     120    v8::HandleScope handleScope;
     121    return scriptState->context()->AllowCodeGenerationFromStrings(enabled);
     122}
     123
    112124ScriptState* mainWorldScriptState(Frame* frame)
    113125{
  • trunk/Source/WebCore/bindings/v8/ScriptState.h

    r95901 r106657  
    110110DOMWindow* domWindowFromScriptState(ScriptState*);
    111111
     112bool evalEnabled(ScriptState*);
     113void setEvalEnabled(ScriptState*, bool);
     114
    112115ScriptState* mainWorldScriptState(Frame*);
    113116
  • trunk/Source/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp

    r106101 r106657  
    6767}
    6868
    69 v8::Handle<v8::Value> V8InjectedScriptHost::evaluateCallback(const v8::Arguments& args)
    70 {
    71     INC_STATS("InjectedScriptHost.evaluate()");
    72     if (args.Length() < 1)
    73         return v8::ThrowException(v8::Exception::Error(v8::String::New("One argument expected.")));
    74 
    75     v8::Handle<v8::String> expression = args[0]->ToString();
    76     if (expression.IsEmpty())
    77         return v8::ThrowException(v8::Exception::Error(v8::String::New("The argument must be a string.")));
    78 
    79     v8::Handle<v8::Script> script = v8::Script::Compile(expression);
    80     if (script.IsEmpty()) // Return immediately in case of exception to let the caller handle it.
    81         return v8::Handle<v8::Value>();
    82     return script->Run();
    83 }
    84 
    8569v8::Handle<v8::Value> V8InjectedScriptHost::inspectedNodeCallback(const v8::Arguments& args)
    8670{
  • trunk/Source/WebCore/inspector/InjectedScript.cpp

    r106101 r106657  
    209209    InspectorInstrumentationCookie cookie = domWindow && domWindow->frame() ? InspectorInstrumentation::willCallFunction(domWindow->frame()->page(), "InjectedScript", 1) : InspectorInstrumentationCookie();
    210210    bool hadException = false;
     211
     212    ScriptState* scriptState = m_injectedScriptObject.scriptState();
     213    bool evalIsDisabled = false;
     214    if (scriptState) {
     215        evalIsDisabled = !evalEnabled(scriptState);
     216        // Temporarily enable allow evals for inspector.
     217        if (evalIsDisabled)
     218            setEvalEnabled(scriptState, true);
     219    }
     220
    211221    ScriptValue resultValue = function.call(hadException);
     222
     223    if (evalIsDisabled)
     224        setEvalEnabled(scriptState, false);
     225
    212226    InspectorInstrumentation::didCallFunction(cookie);
    213227
  • trunk/Source/WebCore/inspector/InjectedScriptHost.idl

    r106101 r106657  
    3737        void clearConsoleMessages();
    3838
    39         [Custom] DOMObject evaluate(in DOMString text);
    40 
    4139        void copyText(in DOMString text);
    4240        [Custom] void inspect(in DOMObject objectId, in DOMObject hints);
  • trunk/Source/WebCore/inspector/InjectedScriptSource.js

    r106101 r106657  
    142142    _parseObjectId: function(objectId)
    143143    {
    144         return InjectedScriptHost.evaluate("(" + objectId + ")");
     144        return eval("(" + objectId + ")");
    145145    },
    146146
     
    157157    dispatch: function(methodName, args)
    158158    {
    159         var argsArray = InjectedScriptHost.evaluate("(" + args + ")");
     159        var argsArray = eval("(" + args + ")");
    160160        var result = this[methodName].apply(this, argsArray);
    161161        if (typeof result === "undefined") {
     
    260260    evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByValue)
    261261    {
    262         return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue);
     262        return this._evaluateAndWrap(inspectedWindow.eval, inspectedWindow, expression, objectGroup, false, injectCommandLineAPI, returnByValue);
    263263    },
    264264
     
    272272        if (args) {
    273273            var resolvedArgs = [];
    274             args = InjectedScriptHost.evaluate(args);
     274            args = eval(args);
    275275            for (var i = 0; i < args.length; ++i) {
    276276                var objectId = args[i].objectId;
     
    294294        try {
    295295            var objectGroup = this._idToObjectGroupName[parsedObjectId.id];
    296             var func = InjectedScriptHost.evaluate("(" + expression + ")");
     296            var func = eval("(" + expression + ")");
    297297            if (typeof func !== "function")
    298298                return "Given expression does not evaluate to a function";
     
    367367    _callFrameForId: function(topCallFrame, callFrameId)
    368368    {
    369         var parsedCallFrameId = InjectedScriptHost.evaluate("(" + callFrameId + ")");
     369        var parsedCallFrameId = eval("(" + callFrameId + ")");
    370370        var ordinal = parsedCallFrameId.ordinal;
    371371        var callFrame = topCallFrame;
Note: See TracChangeset for help on using the changeset viewer.