summaryrefslogtreecommitdiffstats
path: root/WebCore/inspector/front-end/InjectedScript.js
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/inspector/front-end/InjectedScript.js')
-rw-r--r--WebCore/inspector/front-end/InjectedScript.js216
1 files changed, 120 insertions, 96 deletions
diff --git a/WebCore/inspector/front-end/InjectedScript.js b/WebCore/inspector/front-end/InjectedScript.js
index 3bed8da..209e99f 100644
--- a/WebCore/inspector/front-end/InjectedScript.js
+++ b/WebCore/inspector/front-end/InjectedScript.js
@@ -59,7 +59,8 @@ InjectedScript.getStyles = function(nodeId, authorOnly)
var node = InjectedScript._nodeForId(nodeId);
if (!node)
return false;
- var matchedRules = InjectedScript._window().getMatchedCSSRules(node, "", authorOnly);
+ var defaultView = node.ownerDocument.defaultView;
+ var matchedRules = defaultView.getMatchedCSSRules(node, "", authorOnly);
var matchedCSSRules = [];
for (var i = 0; matchedRules && i < matchedRules.length; ++i)
matchedCSSRules.push(InjectedScript._serializeRule(matchedRules[i]));
@@ -72,7 +73,7 @@ InjectedScript.getStyles = function(nodeId, authorOnly)
}
var result = {};
result.inlineStyle = InjectedScript._serializeStyle(node.style, true);
- result.computedStyle = InjectedScript._serializeStyle(InjectedScript._window().getComputedStyle(node));
+ result.computedStyle = InjectedScript._serializeStyle(defaultView.getComputedStyle(node));
result.matchedCSSRules = matchedCSSRules;
result.styleAttributes = styleAttributes;
return result;
@@ -83,7 +84,7 @@ InjectedScript.getComputedStyle = function(nodeId)
var node = InjectedScript._nodeForId(nodeId);
if (!node)
return false;
- return InjectedScript._serializeStyle(InjectedScript._window().getComputedStyle(node));
+ return InjectedScript._serializeStyle(node.ownerDocument.defaultView.getComputedStyle(node));
}
InjectedScript.getInlineStyle = function(nodeId)
@@ -230,15 +231,19 @@ InjectedScript.applyStyleRuleText = function(ruleId, newContent, selectedNodeId)
InjectedScript.addStyleSelector = function(newContent, selectedNodeId)
{
- var stylesheet = InjectedScript.stylesheet;
+ var selectedNode = InjectedScript._nodeForId(selectedNodeId);
+ if (!selectedNode)
+ return false;
+ var ownerDocument = selectedNode.ownerDocument;
+
+ var stylesheet = ownerDocument.__stylesheet;
if (!stylesheet) {
- var inspectedDocument = InjectedScript._window().document;
- var head = inspectedDocument.getElementsByTagName("head")[0];
- var styleElement = inspectedDocument.createElement("style");
+ var head = ownerDocument.head;
+ var styleElement = ownerDocument.createElement("style");
styleElement.type = "text/css";
head.appendChild(styleElement);
- stylesheet = inspectedDocument.styleSheets[inspectedDocument.styleSheets.length - 1];
- InjectedScript.stylesheet = stylesheet;
+ stylesheet = ownerDocument.styleSheets[ownerDocument.styleSheets.length - 1];
+ ownerDocument.__stylesheet = stylesheet;
}
try {
@@ -248,7 +253,6 @@ InjectedScript.addStyleSelector = function(newContent, selectedNodeId)
return false;
}
- var selectedNode = InjectedScript._nodeForId(selectedNodeId);
var rule = stylesheet.cssRules[stylesheet.cssRules.length - 1];
rule.__isViaInspector = true;
@@ -557,7 +561,7 @@ InjectedScript._evaluateAndWrap = function(evalFunction, object, expression, obj
{
var result = {};
try {
- result.value = InspectorController.wrapObject(InjectedScript._evaluateOn(evalFunction, object, expression), objectGroup);
+ result.value = InjectedScriptHost.wrapObject(InjectedScript._evaluateOn(evalFunction, object, expression), objectGroup);
// Handle error that might have happened while describing result.
if (result.value.errorText) {
result.value = result.value.errorText;
@@ -575,7 +579,7 @@ InjectedScript._evaluateOn = function(evalFunction, object, expression)
InjectedScript._ensureCommandLineAPIInstalled(evalFunction, object);
// Surround the expression in with statements to inject our command line API so that
// the window object properties still take more precedent than our API functions.
- expression = "with (window.console._inspectorCommandLineAPI) { with (window) { " + expression + " } }";
+ expression = "with (window.console._inspectorCommandLineAPI) { with (window) {\n" + expression + "\n} }";
var value = evalFunction.call(object, expression);
// When evaluating on call frame error is not thrown, but returned as a value.
@@ -642,10 +646,10 @@ InjectedScript.performSearch = function(whitespaceTrimmedQuery)
node[searchResultsProperty] = true;
InjectedScript._searchResults.push(node);
- var nodeId = InspectorController.pushNodePathToFrontend(node, false);
+ var nodeId = InjectedScriptHost.pushNodePathToFrontend(node, false);
nodeIds.push(nodeId);
}
- InspectorController.addNodesToSearchResult(nodeIds.join(","));
+ InjectedScriptHost.addNodesToSearchResult(nodeIds.join(","));
}
function matchExactItems(doc)
@@ -844,7 +848,7 @@ InjectedScript.openInInspectedWindow = function(url)
InjectedScript.getCallFrames = function()
{
- var callFrame = InspectorController.currentCallFrame();
+ var callFrame = InjectedScriptHost.currentCallFrame();
if (!callFrame)
return false;
@@ -867,7 +871,7 @@ InjectedScript.evaluateInCallFrame = function(callFrameId, code, objectGroup)
InjectedScript._callFrameForId = function(id)
{
- var callFrame = InspectorController.currentCallFrame();
+ var callFrame = InjectedScriptHost.currentCallFrame();
while (--id >= 0 && callFrame)
callFrame = callFrame.caller;
return callFrame;
@@ -875,7 +879,7 @@ InjectedScript._callFrameForId = function(id)
InjectedScript._clearConsoleMessages = function()
{
- InspectorController.clearMessages(true);
+ InjectedScriptHost.clearMessages(true);
}
InjectedScript._inspectObject = function(o)
@@ -886,90 +890,105 @@ InjectedScript._inspectObject = function(o)
var inspectedWindow = InjectedScript._window();
inspectedWindow.console.log(o);
if (Object.type(o) === "node") {
- InspectorController.pushNodePathToFrontend(o, true);
+ InjectedScriptHost.pushNodePathToFrontend(o, true);
} else {
switch (Object.describe(o)) {
case "Database":
- InspectorController.selectDatabase(o);
+ InjectedScriptHost.selectDatabase(o);
break;
case "Storage":
- InspectorController.selectDOMStorage(o);
+ InjectedScriptHost.selectDOMStorage(o);
break;
}
}
}
+InjectedScript._copy = function(o)
+{
+ if (Object.type(o) === "node") {
+ var nodeId = InjectedScriptHost.pushNodePathToFrontend(o, false);
+ InjectedScriptHost.copyNode(nodeId);
+ } else {
+ InjectedScriptHost.copyText(o);
+ }
+}
+
InjectedScript._ensureCommandLineAPIInstalled = function(evalFunction, evalObject)
{
if (evalFunction.call(evalObject, "window.console._inspectorCommandLineAPI"))
return;
- var inspectorCommandLineAPI = evalFunction.call(evalObject, "window.console._inspectorCommandLineAPI = { \
- $: function() { return document.getElementById.apply(document, arguments) }, \
- $$: function() { return document.querySelectorAll.apply(document, arguments) }, \
- $x: function(xpath, context) { \
- var nodes = []; \
- try { \
- var doc = context || document; \
- var results = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null); \
- var node; \
- while (node = results.iterateNext()) nodes.push(node); \
- } catch (e) {} \
- return nodes; \
- }, \
- dir: function() { return console.dir.apply(console, arguments) }, \
- dirxml: function() { return console.dirxml.apply(console, arguments) }, \
- keys: function(o) { var a = []; for (var k in o) a.push(k); return a; }, \
- values: function(o) { var a = []; for (var k in o) a.push(o[k]); return a; }, \
- profile: function() { return console.profile.apply(console, arguments) }, \
- profileEnd: function() { return console.profileEnd.apply(console, arguments) }, \
- _logEvent: function _inspectorCommandLineAPI_logEvent(e) { console.log(e.type, e); }, \
- _allEventTypes: [\"mouse\", \"key\", \"load\", \"unload\", \"abort\", \"error\", \
- \"select\", \"change\", \"submit\", \"reset\", \"focus\", \"blur\", \
- \"resize\", \"scroll\"], \
- _normalizeEventTypes: function(t) { \
- if (typeof t === \"undefined\") \
- t = _inspectorCommandLineAPI._allEventTypes; \
- else if (typeof t === \"string\") \
- t = [t]; \
- var i, te = []; \
- for (i = 0; i < t.length; i++) { \
- if (t[i] === \"mouse\") \
- te.splice(0, 0, \"mousedown\", \"mouseup\", \"click\", \"dblclick\", \
- \"mousemove\", \"mouseover\", \"mouseout\"); \
- else if (t[i] === \"key\") \
- te.splice(0, 0, \"keydown\", \"keyup\", \"keypress\"); \
- else \
- te.push(t[i]); \
- } \
- return te; \
- }, \
- monitorEvent: function(o, t) { \
- if (!o || !o.addEventListener || !o.removeEventListener) \
- return; \
- t = _inspectorCommandLineAPI._normalizeEventTypes(t); \
- for (i = 0; i < t.length; i++) { \
- o.removeEventListener(t[i], _inspectorCommandLineAPI._logEvent, false); \
- o.addEventListener(t[i], _inspectorCommandLineAPI._logEvent, false); \
- } \
- }, \
- unmonitorEvent: function(o, t) { \
- if (!o || !o.removeEventListener) \
- return; \
- t = _inspectorCommandLineAPI._normalizeEventTypes(t); \
- for (i = 0; i < t.length; i++) { \
- o.removeEventListener(t[i], _inspectorCommandLineAPI._logEvent, false); \
- } \
- }, \
- _inspectedNodes: [], \
- get $0() { return console._inspectorCommandLineAPI._inspectedNodes[0] }, \
- get $1() { return console._inspectorCommandLineAPI._inspectedNodes[1] }, \
- get $2() { return console._inspectorCommandLineAPI._inspectedNodes[2] }, \
- get $3() { return console._inspectorCommandLineAPI._inspectedNodes[3] }, \
- get $4() { return console._inspectorCommandLineAPI._inspectedNodes[4] } \
+ var inspectorCommandLineAPI = evalFunction.call(evalObject, "window.console._inspectorCommandLineAPI = { \n\
+ $: function() { return document.getElementById.apply(document, arguments) }, \n\
+ $$: function() { return document.querySelectorAll.apply(document, arguments) }, \n\
+ $x: function(xpath, context) \n\
+ { \n\
+ var nodes = []; \n\
+ try { \n\
+ var doc = context || document; \n\
+ var results = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null); \n\
+ var node; \n\
+ while (node = results.iterateNext()) nodes.push(node); \n\
+ } catch (e) {} \n\
+ return nodes; \n\
+ }, \n\
+ dir: function() { return console.dir.apply(console, arguments) }, \n\
+ dirxml: function() { return console.dirxml.apply(console, arguments) }, \n\
+ keys: function(o) { var a = []; for (var k in o) a.push(k); return a; }, \n\
+ values: function(o) { var a = []; for (var k in o) a.push(o[k]); return a; }, \n\
+ profile: function() { return console.profile.apply(console, arguments) }, \n\
+ profileEnd: function() { return console.profileEnd.apply(console, arguments) }, \n\
+ _logEvent: function _inspectorCommandLineAPI_logEvent(e) { console.log(e.type, e); }, \n\
+ _allEventTypes: [\"mouse\", \"key\", \"load\", \"unload\", \"abort\", \"error\", \n\
+ \"select\", \"change\", \"submit\", \"reset\", \"focus\", \"blur\", \n\
+ \"resize\", \"scroll\"], \n\
+ _normalizeEventTypes: function(t) \n\
+ { \n\
+ if (typeof t === \"undefined\") \n\
+ t = console._inspectorCommandLineAPI._allEventTypes; \n\
+ else if (typeof t === \"string\") \n\
+ t = [t]; \n\
+ var i, te = []; \n\
+ for (i = 0; i < t.length; i++) { \n\
+ if (t[i] === \"mouse\") \n\
+ te.splice(0, 0, \"mousedown\", \"mouseup\", \"click\", \"dblclick\", \n\
+ \"mousemove\", \"mouseover\", \"mouseout\"); \n\
+ else if (t[i] === \"key\") \n\
+ te.splice(0, 0, \"keydown\", \"keyup\", \"keypress\"); \n\
+ else \n\
+ te.push(t[i]); \n\
+ } \n\
+ return te; \n\
+ }, \n\
+ monitorEvents: function(o, t) \n\
+ { \n\
+ if (!o || !o.addEventListener || !o.removeEventListener) \n\
+ return; \n\
+ t = console._inspectorCommandLineAPI._normalizeEventTypes(t); \n\
+ for (i = 0; i < t.length; i++) { \n\
+ o.removeEventListener(t[i], console._inspectorCommandLineAPI._logEvent, false); \n\
+ o.addEventListener(t[i], console._inspectorCommandLineAPI._logEvent, false); \n\
+ } \n\
+ }, \n\
+ unmonitorEvents: function(o, t) \n\
+ { \n\
+ if (!o || !o.removeEventListener) \n\
+ return; \n\
+ t = console._inspectorCommandLineAPI._normalizeEventTypes(t); \n\
+ for (i = 0; i < t.length; i++) { \n\
+ o.removeEventListener(t[i], console._inspectorCommandLineAPI._logEvent, false); \n\
+ } \n\
+ }, \n\
+ _inspectedNodes: [], \n\
+ get $0() { return console._inspectorCommandLineAPI._inspectedNodes[0] }, \n\
+ get $1() { return console._inspectorCommandLineAPI._inspectedNodes[1] }, \n\
+ get $2() { return console._inspectorCommandLineAPI._inspectedNodes[2] }, \n\
+ get $3() { return console._inspectorCommandLineAPI._inspectedNodes[3] }, \n\
+ get $4() { return console._inspectorCommandLineAPI._inspectedNodes[4] }, \n\
};");
- inspectorCommandLineAPI.clear = InspectorController.wrapCallback(InjectedScript._clearConsoleMessages);
- inspectorCommandLineAPI.inspect = InspectorController.wrapCallback(InjectedScript._inspectObject);
+ inspectorCommandLineAPI.clear = InjectedScriptHost.wrapCallback(InjectedScript._clearConsoleMessages);
+ inspectorCommandLineAPI.inspect = InjectedScriptHost.wrapCallback(InjectedScript._inspectObject);
+ inspectorCommandLineAPI.copy = InjectedScriptHost.wrapCallback(InjectedScript._copy);
}
InjectedScript._resolveObject = function(objectProxy)
@@ -993,14 +1012,14 @@ InjectedScript._window = function()
{
// TODO: replace with 'return window;' once this script is injected into
// the page's context.
- return InspectorController.inspectedWindow();
+ return InjectedScriptHost.inspectedWindow();
}
InjectedScript._nodeForId = function(nodeId)
{
if (!nodeId)
return null;
- return InspectorController.nodeForId(nodeId);
+ return InjectedScriptHost.nodeForId(nodeId);
}
InjectedScript._objectForId = function(objectId)
@@ -1012,7 +1031,7 @@ InjectedScript._objectForId = function(objectId)
if (typeof objectId === "number") {
return InjectedScript._nodeForId(objectId);
} else if (typeof objectId === "string") {
- return InspectorController.unwrapObject(objectId);
+ return InjectedScriptHost.unwrapObject(objectId);
} else if (typeof objectId === "object") {
var callFrame = InjectedScript._callFrameForId(objectId.callFrame);
if (objectId.thisObject)
@@ -1028,7 +1047,14 @@ InjectedScript.pushNodeToFrontend = function(objectProxy)
var object = InjectedScript._resolveObject(objectProxy);
if (!object || Object.type(object) !== "node")
return false;
- return InspectorController.pushNodePathToFrontend(object, false);
+ return InjectedScriptHost.pushNodePathToFrontend(object, false);
+}
+
+InjectedScript.nodeByPath = function(path)
+{
+ // We make this call through the injected script only to get a nice
+ // callback for it.
+ return InjectedScriptHost.pushNodeByPathToFrontend(path.join(","));
}
// Called from within InspectorController on the 'inspected page' side.
@@ -1111,23 +1137,23 @@ InjectedScript.executeSql = function(callId, databaseId, query)
data[columnIdentifier] = String(text);
}
}
- InspectorController.reportDidDispatchOnInjectedScript(callId, JSON.stringify(result), false);
+ InjectedScriptHost.reportDidDispatchOnInjectedScript(callId, JSON.stringify(result), false);
}
function errorCallback(tx, error)
{
- InspectorController.reportDidDispatchOnInjectedScript(callId, JSON.stringify(error), false);
+ InjectedScriptHost.reportDidDispatchOnInjectedScript(callId, JSON.stringify(error), false);
}
function queryTransaction(tx)
{
- tx.executeSql(query, null, InspectorController.wrapCallback(successCallback), InspectorController.wrapCallback(errorCallback));
+ tx.executeSql(query, null, InjectedScriptHost.wrapCallback(successCallback), InjectedScriptHost.wrapCallback(errorCallback));
}
- var database = InspectorController.databaseForId(databaseId);
+ var database = InjectedScriptHost.databaseForId(databaseId);
if (!database)
errorCallback(null, { code : 2 }); // Return as unexpected version.
- database.transaction(InspectorController.wrapCallback(queryTransaction), InspectorController.wrapCallback(errorCallback));
+ database.transaction(InjectedScriptHost.wrapCallback(queryTransaction), InjectedScriptHost.wrapCallback(errorCallback));
return true;
}
@@ -1197,8 +1223,6 @@ Object.describe = function(obj, abbreviated)
else if (abbreviated)
objectText = /.*/.exec(obj)[0].replace(/ +$/g, "");
return objectText;
- case "regexp":
- return String(obj).replace(/([\\\/])/g, "\\$1").replace(/\\(\/[gim]*)$/, "$1").substring(1);
default:
return String(obj);
}