My favorites | Sign in
Project Home Wiki Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions

Issue 5878 attachment: include_progress.patch (8.4 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
diff --git a/extension/content/firebug/console/commandLine.js b/extension/content/firebug/console/commandLine.js
index 35a697c..4412f70 100644
--- a/extension/content/firebug/console/commandLine.js
+++ b/extension/content/firebug/console/commandLine.js
@@ -349,23 +349,6 @@ Firebug.CommandLine = Obj.extend(Firebug.Module,
return win.postMessage(expr, "*");
},

- evaluateInWebPage: function(expr, context, targetWindow)
- {
- var win = targetWindow || context.window;
- var element = Dom.addScript(win.document, "_firebugInWebPage", expr);
- if (!element)
- return;
-
- setTimeout(function delayRemoveScriptTag()
- {
- // we don't need the script element, result is in DOM object
- if (element.parentNode)
- element.parentNode.removeChild(element);
- });
-
- return "true";
- },
-
// isSandbox(context) true, => context.global is a Sandbox
evaluateInSandbox: function(expr, context, thisValue, targetWindow, successConsoleFunction,
exceptionFunction)
@@ -1081,14 +1064,14 @@ function FirebugCommandLineAPI(context)
case "node":
XPathResultType = XPathResult.FIRST_ORDERED_NODE_TYPE;
break;
-
+
case "nodes":
XPathResultType = XPathResult.UNORDERED_NODE_ITERATOR_TYPE;
break;
}

var doc = Wrapper.unwrapObject(context.baseWindow.document);
-
+
return Xpath.evaluateXPath(doc, xpath, contextNode, XPathResultType);
};

@@ -1235,6 +1218,85 @@ function FirebugCommandLineAPI(context)
return Firebug.Console.getDefaultReturnValue(context.window);
};

+ // include([newAlias, ]url)
+ // includes a remote script
+ this.include = function()
+ {
+ // xxxFlorent: shouldn't we place the content of this function in CommandLine ?
+ var xhr = new XMLHttpRequest();
+ var url = arguments[ arguments.length - 1 ];
+ var urlIsAlias = (url !== null && url[0] === ':');
+ var newAlias = arguments.length > 1 ? arguments[0].toLowerCase() : undefined;
+ var aliases, predefAliases;
+ var reAcceptedRequests = /^(https?|spdy)/;
+ var returnValue = Firebug.Console.getDefaultReturnValue(context.window);
+ // checking arguments:
+ if (newAlias !== undefined && (typeof newAlias !== "string" || newAlias[0] !== ':') )
+ {
+ var msg = 'aliases must begin with a colon (ex.: ":myalias") ; invalid alias name: "'+
+ newAlias + '"';
+ Firebug.Console.log(msg, context, "error", FirebugReps.Text);
+ return returnValue;
+ }
+
+ // we get the predefined aliases
+ if (newAlias === undefined && url !== null)
+ predefAliases = JSON.parse( PrefLoader.getPref("consoleAliases.predefined") ) || {};
+
+ // we get the custom aliases
+ if (newAlias !== undefined || urlIsAlias)
+ aliases = JSON.parse( PrefLoader.getPref("consoleAliases") ) || {};
+
+ if (newAlias === undefined && urlIsAlias)
+ {
+ var key = url.substr(1).toLowerCase();
+ url = aliases[key] || predefAliases[key] ;
+ }
+
+ // if the URL is null, we delete the alias
+ if (newAlias !== undefined && url === null)
+ {
+ delete aliases[newAlias];
+ PrefLoader.setPref("consoleAliases", JSON.stringify(aliases));
+ Firebug.Console.log("alias deleted", context, "info", FirebugReps.Text);
+ return returnValue;
+ }
+
+ xhr.mozAnon = true;
+
+ xhr.onload = function()
+ {
+ if (~xhr.getResponseHeader("Content-Type").search(/(application|text)\/javascript/i))
+ {
+ var codeToEval = xhr.responseText;
+ var headerMatch;
+ Firebug.CommandLine.evaluate(codeToEval, context);
+ if (newAlias)
+ {
+ aliases[ newAlias.substr(1) ] = url;
+ PrefLoader.setPref("consoleAliases", JSON.stringify(aliases));
+ }
+ logIncludedScriptInfo(url, context);
+ }
+ else
+ {
+ // TODO: error
+ }
+ };
+
+ xhr.open("GET", url, true);
+
+ if (!reAcceptedRequests.test(xhr.channel.URI.scheme.toString()))
+ {
+ // TODO: do as if the request were aborted
+ return returnValue;
+ }
+
+ xhr.send(null);
+ // show XHR progress
+ return returnValue;
+ };
+
// xxxHonza: removed from 1.10 (issue 5599)
/*this.memoryProfile = function(title)
{
@@ -1249,6 +1311,49 @@ function FirebugCommandLineAPI(context)
};*/
}

+function logIncludedScriptInfo(url, context)
+{
+ var fmtMatch = url.match(/^https?:\/\/ajax\.googleapis\.com\/ajax\/libs\/([^\/]+)/);
+ if (fmtMatch !== null)
+ {
+ var version, fmtName, logMessage;
+ var win = Wrapper.unwrapObject(context.window);
+ try{
+ switch (fmtMatch[1])
+ {
+ case "jquery":
+ fmtName = "jQuery";
+ version = win.jQuery.fn.jquery;
+ break;
+ case "prototype":
+ fmtName = "Prototype";
+ version = win.Prototype.Version;
+ break;
+ case "dojo":
+ fmtName = "Dojo Toolkit";
+ version = win.dojo.version.toString();
+ break;
+ case "mootools":
+ fmtName = "MooTools";
+ version = win.MooTools.version;
+ break;
+ case "ext":
+ fmtName = "Ext Core";
+ version = win.Ext.version;
+ break;
+ }
+ if (fmtName)
+ logMessage = fmtName + " (" + version + ") loaded";
+ }
+ catch(ex){}
+ }
+ // default log message
+ if (!logMessage)
+ logMessage = "script loaded";
+
+ Firebug.Console.log(logMessage, context, "info", FirebugReps.Text);
+}
+
// ********************************************************************************************* //
// CommandLine Injector

@@ -1455,6 +1560,7 @@ function getNoScript()
return this.noscript;
}

+
// ********************************************************************************************* //
// Registration

diff --git a/extension/content/firebug/console/commandLineExposed.js b/extension/content/firebug/console/commandLineExposed.js
index 865ed28..868cc97 100644
--- a/extension/content/firebug/console/commandLineExposed.js
+++ b/extension/content/firebug/console/commandLineExposed.js
@@ -14,7 +14,7 @@ function(Firebug, Wrapper, Events) {
var commands = ["$", "$$", "$x", "$n", "cd", "clear", "inspect", "keys",
"values", "debug", "undebug", "monitor", "unmonitor", "traceCalls", "untraceCalls",
"traceAll", "untraceAll", "monitorEvents", "unmonitorEvents", "profile", "profileEnd",
- "copy" /*, "memoryProfile", "memoryProfileEnd"*/];
+ "copy", "include" /*, "memoryProfile", "memoryProfileEnd"*/];

// List of shortcuts for some console methods
var consoleShortcuts = ["dir", "dirxml", "table"];
diff --git a/extension/defaults/preferences/firebug.js b/extension/defaults/preferences/firebug.js
index ecf0d48..8795dc7 100644
--- a/extension/defaults/preferences/firebug.js
+++ b/extension/defaults/preferences/firebug.js
@@ -59,6 +59,14 @@ pref("extensions.firebug.console.enableSites", false);
pref("extensions.firebug.tabularLogMaxHeight", 200);
pref("extensions.firebug.consoleFilterTypes", "all");
pref("extensions.firebug.preferJSDSourceLinks", false);
+pref("extensions.firebug.consoleAliases", "{}");
+pref("extensions.firebug.consoleAliases.predefined", '{'+
+ '"jquery":"https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js",'+
+ '"prototype": "https://ajax.googleapis.com/ajax/libs/prototype/1/prototype.js",'+
+ '"mootools":"https://ajax.googleapis.com/ajax/libs/mootools/1/mootools-yui-compressed.js",'+
+ '"dojo":"https://ajax.googleapis.com/ajax/libs/dojo/1/dojo/dojo.js",'+
+ '"ext":"https://ajax.googleapis.com/ajax/libs/ext-core/3/ext-core.js"'+
+ '}');

// HTML
pref("extensions.firebug.showCommentNodes", false);
Powered by Google Project Hosting