Changeset 56841 in webkit


Ignore:
Timestamp:
Mar 31, 2010 8:24:19 AM (14 years ago)
Author:
yurys@chromium.org
Message:

2010-03-31 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Pavel Feldman.

Check that injected script can still access inspected window object when wrapping console object. When the window cannot be access serialize objects as strings. Also don't call InjectedScript.dispatch if the window cannot be accessed (due to frame navigation).

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

  • bindings/js/JSInjectedScriptHostCustom.cpp: (WebCore::InjectedScriptHost::canAccessInspectedWindow):
  • bindings/v8/custom/V8InjectedScriptHostCustom.cpp: (WebCore::InjectedScriptHost::canAccessInspectedWindow):
  • inspector/InjectedScript.cpp: (WebCore::InjectedScript::wrapForConsole):
  • inspector/InjectedScriptHost.h:
  • inspector/front-end/InjectedScript.js: (injectedScriptConstructor):

2010-03-30 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: get rid of "Unsafe JavaScript attempt..." message when inspecting frames whose content has changed.

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

  • http/tests/inspector-enabled/console-log-before-frame-navigation-expected.txt:
  • http/tests/inspector-enabled/resources/console-log-frame-before-navigation.html:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r56839 r56841  
     12010-03-30  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: get rid of "Unsafe JavaScript attempt..." message when inspecting frames whose content has changed.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=36828
     8
     9        * http/tests/inspector-enabled/console-log-before-frame-navigation-expected.txt:
     10        * http/tests/inspector-enabled/resources/console-log-frame-before-navigation.html:
     11
    1122010-03-31  Nikolas Zimmermann  <nzimmermann@rim.com>
    213
  • trunk/LayoutTests/http/tests/inspector-enabled/console-log-before-frame-navigation-expected.txt

    r56708 r56841  
    11CONSOLE MESSAGE: line 5: 2010
    2 CONSOLE MESSAGE: line 1: Unsafe JavaScript attempt to access frame with URL http://localhost:8000/inspector-enabled/resources/console-log-frame-after-navigation.html from frame with URL http://127.0.0.1:8000/inspector-enabled/resources/console-log-frame-before-navigation.html. Domains, protocols and ports must match.
    3 
    42Tests that Web Inspector won't crash if there are messages written to console from a frame which has already navigated to a page from a different domain.
    53
     
    86Received console messages:
    97Message[0]:
    10 URL:
    11 Message: Unsafe JavaScript attempt to access frame with URL http://localhost:8000/inspector-enabled/resources/console-log-frame-after-navigation.html from frame with URL http://127.0.0.1:8000/inspector-enabled/resources/console-log-frame-before-navigation.html. Domains, protocols and ports must match.
    12 
    13 Message[1]:
    148URL: http://127.0.0.1:8000/inspector-enabled/resources/console-log-frame-before-navigation.html
    15 Message: 2010
     9Message: 2010 [object HTMLHtmlElement]
    1610TEST COMPLETE.
    1711
  • trunk/LayoutTests/http/tests/inspector-enabled/resources/console-log-frame-before-navigation.html

    r56708 r56841  
    33<script>
    44function handleLoad() {
    5   console.log(2010);
     5  console.log(2010, document.documentElement);
    66
    77  setTimeout(function() {
  • trunk/WebCore/ChangeLog

    r56840 r56841  
     12010-03-31  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Check that injected script can still access inspected window object when wrapping console object. When the window cannot be access serialize objects as strings. Also don't call InjectedScript.dispatch if the window cannot be accessed (due to frame navigation).
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=36828
     8
     9        * bindings/js/JSInjectedScriptHostCustom.cpp:
     10        (WebCore::InjectedScriptHost::canAccessInspectedWindow):
     11        * bindings/v8/custom/V8InjectedScriptHostCustom.cpp:
     12        (WebCore::InjectedScriptHost::canAccessInspectedWindow):
     13        * inspector/InjectedScript.cpp:
     14        (WebCore::InjectedScript::wrapForConsole):
     15        * inspector/InjectedScriptHost.h:
     16        * inspector/front-end/InjectedScript.js:
     17        (injectedScriptConstructor):
     18
    1192010-03-31  Mattias Nissler  <mnissler@google.com>
    220
  • trunk/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp

    r55771 r56841  
    4949#include "InspectorResource.h"
    5050#include "JSDOMWindow.h"
     51#include "JSDOMWindowCustom.h"
    5152#include "JSNode.h"
    5253#include "JSRange.h"
     
    230231}
    231232
     233bool InjectedScriptHost::canAccessInspectedWindow(ScriptState* scriptState)
     234{
     235    JSLock lock(SilenceAssertionsOnly);
     236    JSDOMWindow* inspectedWindow = toJSDOMWindow(scriptState->lexicalGlobalObject());
     237    if (!inspectedWindow)
     238        return false;
     239    return inspectedWindow->allowsAccessFromNoErrorMessage(scriptState);
     240}
     241
    232242} // namespace WebCore
    233243
  • trunk/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp

    r55798 r56841  
    4343
    4444#include "V8Binding.h"
     45#include "V8BindingState.h"
     46#include "V8DOMWindow.h"
    4547#include "V8Database.h"
    4648#include "V8Node.h"
     
    247249}
    248250
     251bool InjectedScriptHost::canAccessInspectedWindow(ScriptState* scriptState)
     252{
     253    v8::Local<v8::Context> context = scriptState->context();
     254    v8::Local<v8::Object> global = context->Global();
     255    if (global.IsEmpty())
     256        return false;
     257    v8::Handle<v8::Object> holder = V8DOMWrapper::lookupDOMWrapper(V8DOMWindow::GetTemplate(), global);
     258    if (holder.IsEmpty())
     259        return false;
     260    Frame* frame = V8DOMWindow::toNative(holder)->frame();
     261
     262    v8::Context::Scope contextScope(context);
     263    return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), frame, false);
     264}
     265
    249266} // namespace WebCore
  • trunk/WebCore/inspector/InjectedScript.cpp

    r56532 r56841  
    4848{
    4949    ASSERT(!hasNoValue());
     50    if (!canAccessInspectedWindow()) {
     51        *hadException = true;
     52        return;
     53    }
     54
    5055    ScriptFunctionCall function(m_injectedScriptObject, "dispatch");
    5156    function.appendArgument(methodName);
     
    7277{
    7378    ASSERT(!hasNoValue());
    74     ScriptFunctionCall wrapFunction(m_injectedScriptObject, "wrapObject");
     79    ScriptFunctionCall wrapFunction(m_injectedScriptObject, "wrapObjectForConsole");
    7580    wrapFunction.appendArgument(value);
    76     wrapFunction.appendArgument("console");
     81    wrapFunction.appendArgument(canAccessInspectedWindow());
    7782    bool hadException = false;
    7883    ScriptValue r = wrapFunction.call(hadException);
     
    8994    releaseFunction.call();
    9095}
     96bool InjectedScript::canAccessInspectedWindow()
     97{
     98    return InjectedScriptHost::canAccessInspectedWindow(m_injectedScriptObject.scriptState());
     99}
    91100
    92101} // namespace WebCore
  • trunk/WebCore/inspector/InjectedScript.h

    r54421 r56841  
    5959    friend InjectedScript InjectedScriptHost::injectedScriptFor(ScriptState*);
    6060    explicit InjectedScript(ScriptObject);
     61    bool canAccessInspectedWindow();
    6162    ScriptObject m_injectedScriptObject;
    6263};
  • trunk/WebCore/inspector/InjectedScriptHost.h

    r56404 r56841  
    9494    void releaseWrapperObjectGroup(long injectedScriptId, const String& objectGroup);
    9595
     96    static bool canAccessInspectedWindow(ScriptState*);
     97
    9698private:
    9799    InjectedScriptHost(InspectorController* inspectorController);
  • trunk/WebCore/inspector/front-end/InjectedScript.js

    r56708 r56841  
    3434InjectedScript.idToWrappedObject = {};
    3535InjectedScript.objectGroups = {};
     36
     37InjectedScript.wrapObjectForConsole = function(object, canAccessInspectedWindow)
     38{
     39    if (canAccessInspectedWindow)
     40        return InjectedScript.wrapObject(object, "console");
     41    var result = {};
     42    result.type = typeof object;
     43    result.description = InjectedScript._toString(object);
     44    return result;
     45}
     46
    3647InjectedScript.wrapObject = function(object, objectGroupName)
    3748{
Note: See TracChangeset for help on using the changeset viewer.