Skip to content
Browse files

Some follow-up fixes to issue 5878

See issue 6056.

Patch by Florent FAYOLLE.
  • Loading branch information...
1 parent d386120 commit 4c5ad847a335b40956f2ba96cc388b234371ecee @simonlindholm simonlindholm committed Nov 4, 2012
Showing with 52 additions and 30 deletions.
  1. +44 −30 extension/content/firebug/console/commandLineInclude.js
  2. +8 −0 extension/locale/en-US/firebug.properties
View
74 extension/content/firebug/console/commandLineInclude.js
@@ -69,7 +69,7 @@ var CommandLineIncludeRep = domplate(FirebugReps.Table,
return FirebugReps.Table.getValueTag(object);
},
- getUrlTag: function(href, aliasName, context)
+ getUrlTag: function(href, aliasName)
{
var urlTag =
SPAN({style:"height:100%"},
@@ -123,9 +123,9 @@ var CommandLineIncludeRep = domplate(FirebugReps.Table,
var flags = prompts.BUTTON_POS_0 * prompts.BUTTON_TITLE_YES +
prompts.BUTTON_POS_1 * prompts.BUTTON_TITLE_NO;
- if (!prompts.confirmEx(context.chrome.window, Locale.$STR("Firebug"),
+ if (prompts.confirmEx(context.chrome.window, Locale.$STR("Firebug"),
Locale.$STR("commandline.include.confirmDelete"), flags, "", "", "",
- Locale.$STR("Do_not_show_this_message_again"), check) == 0)
+ Locale.$STR("Do_not_show_this_message_again"), check) > 0)
{
return;
}
@@ -298,12 +298,12 @@ function CommandLineIncludeObject()
var CommandLineInclude =
{
- onSuccess: function(aliases, newAlias, context, loadingMsgRow, xhr)
+ onSuccess: function(newAlias, context, loadingMsgRow, xhr)
{
var urlComponent = xhr.channel.URI.QueryInterface(Ci.nsIURL);
- var msg, filename = urlComponent.fileName, url = urlComponent.spec;
+ var filename = urlComponent.fileName, url = urlComponent.spec;
// clear the message saying "loading..."
- loadingMsgRow.parentNode.removeChild(loadingMsgRow);
+ this.clearLoadingMessage(loadingMsgRow);
if (newAlias)
{
@@ -315,22 +315,30 @@ var CommandLineInclude =
this.log("includeSuccess", [filename], [context, "info"]);
},
- onError: function(context, url)
+ onError: function(context, url, loadingMsgRow)
{
- loadingMsgRow.parentNode.removeChild(loadingMsgRow);
+ this.clearLoadingMessage(loadingMsgRow);
this.log("loadFail", [url], [context, "error"]);
},
+ clearLoadingMessage: function(loadingMsgRow)
+ {
+ if (loadingMsgRow && loadingMsgRow.parentNode)
+ loadingMsgRow.parentNode.removeChild(loadingMsgRow);
+ },
+
getStore: function()
{
if (!this.store)
this.store = storageScope.StorageService.getStorage("includeAliases.json");
return this.store;
},
- log: function(localeStr, localeArgs, logArgs)
+ log: function(localeStr, localeArgs, logArgs, noAutoPrefix)
{
- var msg = Locale.$STRF("commandline.include."+localeStr, localeArgs);
+ var prefixedLocaleStr = (noAutoPrefix ? localeStr : "commandline.include."+localeStr);
+
+ var msg = Locale.$STRF(prefixedLocaleStr, localeArgs);
logArgs.unshift([msg]);
return Firebug.Console.logFormatted.apply(Firebug.Console, logArgs);
},
@@ -341,17 +349,20 @@ var CommandLineInclude =
{
var reNotAlias = /[\.\/]/;
var urlIsAlias = url !== null && !reNotAlias.test(url);
- var aliases;
var returnValue = Firebug.Console.getDefaultReturnValue(context.window);
- var acceptedSchemes = ["http", "https"];
- var msg;
// checking arguments:
- if (newAlias !== undefined && typeof newAlias !== "string")
- throw "wrong alias argument; expected string";
+ if ((newAlias !== undefined && typeof newAlias !== "string") || newAlias === "")
+ {
+ this.log("wrongAliasArgument", [], [context, "error"]);
+ return returnValue;
+ }
- if (url !== null && typeof url !== "string")
- throw "wrong url argument; expected string or null";
+ if (url !== null && typeof url !== "string" || !url && !newAlias)
+ {
+ this.log("wrongUrlArgument", [], [context, "error"]);
+ return returnValue;
+ }
if (newAlias !== undefined)
newAlias = newAlias.toLowerCase();
@@ -394,44 +405,47 @@ var CommandLineInclude =
this.log("aliasRemoved", [newAlias], [context, "info"]);
return returnValue;
}
- var loadingMsg = Locale.$STR("Loading");
- var loadingMsgRow = Firebug.Console.logFormatted([loadingMsg], context, "loading", true);
- var onSuccess = this.onSuccess.bind(this, aliases, newAlias, context, loadingMsgRow);
- var onError = this.onError.bind(this, context, loadingMsgRow);
- this.evaluateRemoteScript(url, context, onSuccess, onError);
+ var loadingMsgRow = this.log("Loading", [], [context, "loading", true], true);
+ var onSuccess = this.onSuccess.bind(this, newAlias, context, loadingMsgRow);
+ var onError = Obj.bindFixed(this.onError, this, context, url, loadingMsgRow);
+ this.evaluateRemoteScript(url, context, onSuccess, onError, loadingMsgRow);
return returnValue;
},
- evaluateRemoteScript: function(url, context, successFunction, errorFunction)
+ evaluateRemoteScript: function(url, context, successFunction, errorFunction, loadingMsgRow)
{
var xhr = new XMLHttpRequest({ mozAnon: true, timeout:30});
var acceptedSchemes = ["http", "https"];
var absoluteURL = context.browser.currentURI.resolve(url);
xhr.onload = function()
{
- var contentType = xhr.getResponseHeader("Content-Type").split(";")[0];
var codeToEval = xhr.responseText;
- var headerMatch;
Firebug.CommandLine.evaluateInWebPage(codeToEval, context);
if (successFunction)
successFunction(xhr);
}
if (errorFunction)
{
- xhr.ontimeout = xhr.onerror = function()
- {
- errorFunction(url);
- }
+ xhr.ontimeout = xhr.onerror = errorFunction;
}
- xhr.open("GET", absoluteURL, true);
+ try
+ {
+ xhr.open("GET", absoluteURL, true);
+ }
+ catch(ex)
+ {
+ this.clearLoadingMessage(loadingMsgRow);
+ throw ex;
+ }
if (!~acceptedSchemes.indexOf(xhr.channel.URI.scheme))
{
this.log("invalidRequestProtocol", [], [context, "error"]);
+ this.clearLoadingMessage(loadingMsgRow);
return ;
}
View
8 extension/locale/en-US/firebug.properties
@@ -782,6 +782,14 @@ commandline.include.invalidAliasName=alias names must not contain any "." or "/"
# %S = the invalid alias name
commandline.include.tooLongAliasName=alias names must not contain more than 30 characters; invalid alias name: "%S"
+# LOCALIZATION NOTE (commandline.include.wrongAliasArgument): For the include() function. This message is displayed
+# in the Console panel if the provided alias name is invalid
+commandline.include.wrongAliasArgument=wrong alias argument; expected string
+
+# LOCALIZATION NOTE (commandline.include.wrongUrlArgument): For the include() function. This message is displayed
+# in the Console panel if the provided url argument is invalid
+commandline.include.wrongUrlArgument=wrong url argument; expected string or null
+
# LOCALIZATION NOTE (commandline.include.confirmDelete): For the include() function. This message is displayed
# in a confirmation dialog when the user wants to delete an alias
# %S = the name of the alias to delete

0 comments on commit 4c5ad84

Please sign in to comment.
Something went wrong with that request. Please try again.