Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
2009-10-02 Pavel Feldman <pfeldman@chromium.org>
        Reviewed by Timothy Hatcher.

        Web Inspector: prepare InspectorController for being used from layout tests.
        This change adds evaluateForTestInFrontend method with the callback that
        allows evaluating arbitrary code in the frontend context.

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

        * WebCore.Inspector.exp:
        * WebCore.order:
        * inspector/InspectorBackend.cpp:
        (WebCore::InspectorBackend::didEvaluateForTestInFrontend):
        * inspector/InspectorBackend.h:
        * inspector/InspectorBackend.idl:
        * inspector/InspectorController.cpp:
        (WebCore::InspectorController::populateScriptObjects):
        (WebCore::InspectorController::evaluateForTestInFrontend):
        (WebCore::InspectorController::didEvaluateForTestInFrontend):
        * inspector/InspectorController.h:
        * inspector/InspectorFrontend.cpp:
        (WebCore::InspectorFrontend::evaluateForTestInFrontend):
        * inspector/InspectorFrontend.h:
        * inspector/front-end/inspector.js:
        (WebInspector.evaluateForTestInFrontend):


Canonical link: https://commits.webkit.org/40623@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@49064 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
pavelfeldman committed Oct 3, 2009
1 parent 4667d60 commit 2cf7fed
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 0 deletions.
27 changes: 27 additions & 0 deletions WebCore/ChangeLog
@@ -1,3 +1,30 @@
2009-10-02 Pavel Feldman <pfeldman@chromium.org>

Reviewed by Timothy Hatcher.

Web Inspector: prepare InspectorController for being used from layout tests.
This change adds evaluateForTestInFrontend method with the callback that
allows evaluating arbitrary code in the frontend context.

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

* WebCore.Inspector.exp:
* WebCore.order:
* inspector/InspectorBackend.cpp:
(WebCore::InspectorBackend::didEvaluateForTestInFrontend):
* inspector/InspectorBackend.h:
* inspector/InspectorBackend.idl:
* inspector/InspectorController.cpp:
(WebCore::InspectorController::populateScriptObjects):
(WebCore::InspectorController::evaluateForTestInFrontend):
(WebCore::InspectorController::didEvaluateForTestInFrontend):
* inspector/InspectorController.h:
* inspector/InspectorFrontend.cpp:
(WebCore::InspectorFrontend::evaluateForTestInFrontend):
* inspector/InspectorFrontend.h:
* inspector/front-end/inspector.js:
(WebInspector.evaluateForTestInFrontend):

2009-10-02 Pavel Feldman <pfeldman@chromium.org>

Reviewed by Timothy Hatcher.
Expand Down
1 change: 1 addition & 0 deletions WebCore/WebCore.Inspector.exp
Expand Up @@ -12,6 +12,7 @@ __ZN7WebCore19InspectorController4showEv
__ZN7WebCore19InspectorController5closeEv
__ZN7WebCore19InspectorController7inspectEPNS_4NodeE
__ZN7WebCore19InspectorController9showPanelENS0_13SpecialPanelsE
__ZN7WebCore19InspectorController25evaluateForTestInFrontendElRKNS_6StringE
__ZNK7WebCore19InspectorController17drawNodeHighlightERNS_15GraphicsContextE
__ZNK7WebCore19InspectorController7enabledEv
__ZNK7WebCore19InspectorController7settingERKNS_6StringE
1 change: 1 addition & 0 deletions WebCore/WebCore.order
Expand Up @@ -7851,6 +7851,7 @@ __ZN3WTF9HashTableIPN7WebCore4PageES3_NS_17IdentityExtractorIS3_EENS_7PtrHashIS3
__ZN3WTF9HashTableIPN7WebCore4PageES3_NS_17IdentityExtractorIS3_EENS_7PtrHashIS3_EENS_10HashTraitsIS3_EES9_E47removeAndInvalida
__ZN3WTF9HashTableIPN7WebCore4PageES3_NS_17IdentityExtractorIS3_EENS_7PtrHashIS3_EENS_10HashTraitsIS3_EES9_E6removeEPS3_
__ZN7WebCore19InspectorController22inspectedPageDestroyedEv
__ZN7WebCore19InspectorController25evaluateForTestInFrontendElRKNS_6StringE
__ZN7WebCore19InspectorController5closeEv
__ZN7WebCore15BackForwardList5closeEv
__ZN3WTF6VectorINS_6RefPtrIN7WebCore11HistoryItemEEELm0EE14shrinkCapacityEm
Expand Down
6 changes: 6 additions & 0 deletions WebCore/inspector/InspectorBackend.cpp
Expand Up @@ -543,6 +543,12 @@ void InspectorBackend::removeDOMStorageItem(long callId, long storageId, const S
}
#endif

void InspectorBackend::didEvaluateForTestInFrontend(long callId, const String& jsonResult)
{
if (m_inspectorController)
m_inspectorController->didEvaluateForTestInFrontend(callId, jsonResult);
}

InspectorDOMAgent* InspectorBackend::inspectorDOMAgent()
{
if (!m_inspectorController)
Expand Down
1 change: 1 addition & 0 deletions WebCore/inspector/InspectorBackend.h
Expand Up @@ -157,6 +157,7 @@ class InspectorBackend : public RefCounted<InspectorBackend>
void setDOMStorageItem(long callId, long storageId, const String& key, const String& value);
void removeDOMStorageItem(long callId, long storageId, const String& key);
#endif
void didEvaluateForTestInFrontend(long callId, const String& jsonResult);

private:
InspectorBackend(InspectorController* inspectorController, InspectorClient* client);
Expand Down
1 change: 1 addition & 0 deletions WebCore/inspector/InspectorBackend.idl
Expand Up @@ -127,5 +127,6 @@ module core {
void setDOMStorageItem(in long callId, in long storageId, in DOMString key, in DOMString value);
void removeDOMStorageItem(in long callId, in long storageId, in DOMString key);
#endif
void didEvaluateForTestInFrontend(in long callId, in DOMString jsonResult);
};
}
24 changes: 24 additions & 0 deletions WebCore/inspector/InspectorController.cpp
Expand Up @@ -673,6 +673,11 @@ void InspectorController::populateScriptObjects()
#endif

m_frontend->populateInterface();

// Dispatch pending frontend commands
for (Vector<pair<long, String> >::iterator it = m_pendingEvaluateTestCommands.begin(); it != m_pendingEvaluateTestCommands.end(); ++it)
m_frontend->evaluateForTestInFrontend((*it).first, (*it).second);
m_pendingEvaluateTestCommands.clear();
}

void InspectorController::resetScriptObjects()
Expand Down Expand Up @@ -1447,6 +1452,25 @@ void InspectorController::didContinue()

#endif

void InspectorController::evaluateForTestInFrontend(long callId, const String& script)
{
if (m_frontend && windowVisible())
m_frontend->evaluateForTestInFrontend(callId, script);
else
m_pendingEvaluateTestCommands.append(pair<long, String>(callId, script));
}

void InspectorController::didEvaluateForTestInFrontend(long callId, const String& jsonResult)
{
ScriptState* scriptState = scriptStateFromPage(m_inspectedPage);
ScriptObject window;
ScriptGlobalObject::get(scriptState, "window", window);
ScriptFunctionCall function(scriptState, window, "didEvaluateForTestInFrontend");
function.appendArgument(static_cast<int>(callId));
function.appendArgument(jsonResult);
function.call();
}

static Path quadToPath(const FloatQuad& quad)
{
Path quadPath;
Expand Down
5 changes: 5 additions & 0 deletions WebCore/inspector/InspectorController.h
Expand Up @@ -283,6 +283,8 @@ class InspectorController
virtual void didContinue();
#endif

void evaluateForTestInFrontend(long callId, const String& script);

private:
friend class InspectorBackend;
// Following are used from InspectorBackend and internally.
Expand Down Expand Up @@ -331,6 +333,8 @@ class InspectorController

SpecialPanels specialPanelForJSName(const String& panelName);

void didEvaluateForTestInFrontend(long callId, const String& jsonResult);

Page* m_inspectedPage;
InspectorClient* m_client;
OwnPtr<InspectorFrontend> m_frontend;
Expand Down Expand Up @@ -365,6 +369,7 @@ class InspectorController
RefPtr<InspectorBackend> m_inspectorBackend;
HashMap<String, ScriptValue> m_idToConsoleObject;
long m_lastBoundObjectId;
Vector<pair<long, String> > m_pendingEvaluateTestCommands;
#if ENABLE(JAVASCRIPT_DEBUGGER)
bool m_debuggerEnabled;
bool m_attachDebuggerWhenShown;
Expand Down
8 changes: 8 additions & 0 deletions WebCore/inspector/InspectorFrontend.cpp
Expand Up @@ -459,6 +459,14 @@ void InspectorFrontend::addNodesToSearchResult(const String& nodeIds)
function->call();
}

void InspectorFrontend::evaluateForTestInFrontend(int callId, const String& script)
{
OwnPtr<ScriptFunctionCall> function(newFunctionCall("evaluateForTestInFrontend"));
function->appendArgument(callId);
function->appendArgument(script);
function->call();
}

PassOwnPtr<ScriptFunctionCall> InspectorFrontend::newFunctionCall(const String& functionName)
{
ScriptFunctionCall* function = new ScriptFunctionCall(m_scriptState, m_webInspector, "dispatch");
Expand Down
1 change: 1 addition & 0 deletions WebCore/inspector/InspectorFrontend.h
Expand Up @@ -129,6 +129,7 @@ namespace WebCore {

ScriptState* scriptState() const { return m_scriptState; }

void evaluateForTestInFrontend(int callId, const String& script);
private:
PassOwnPtr<ScriptFunctionCall> newFunctionCall(const String& functionName);
void callSimpleFunction(const String& functionName);
Expand Down
5 changes: 5 additions & 0 deletions WebCore/inspector/front-end/inspector.js
Expand Up @@ -1615,6 +1615,11 @@ WebInspector._toolbarItemClicked = function(event)
this.currentPanel = toolbarItem.panel;
}

WebInspector.evaluateForTestInFrontend = function(callId, script)
{
InspectorController.didEvaluateForTestInFrontend(callId, JSON.stringify(window.eval(script)));
}

// This table maps MIME types to the Resource.Types which are valid for them.
// The following line:
// "text/html": {0: 1},
Expand Down

0 comments on commit 2cf7fed

Please sign in to comment.