зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1569077 - Part 2: Add --autoclose argument to the layout debugger. r=dbaron
Differential Revision: https://phabricator.services.mozilla.com/D39468 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
7ce6716163
Коммит
712f284101
|
@ -62,6 +62,27 @@ static nsresult HandleFlagWithOptionalArgument(nsICommandLine* aCmdLine,
|
|||
return aCmdLine->RemoveArguments(idx, idx + argPresent);
|
||||
}
|
||||
|
||||
static nsresult HandleFlagWithOptionalArgument(nsICommandLine* aCmdLine,
|
||||
const nsAString& aName,
|
||||
double aDefaultValue,
|
||||
double& aValue,
|
||||
bool& aFlagPresent) {
|
||||
nsresult rv;
|
||||
nsString s;
|
||||
|
||||
rv = HandleFlagWithOptionalArgument(aCmdLine, aName, NS_LITERAL_STRING("0"),
|
||||
s, aFlagPresent);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!aFlagPresent) {
|
||||
aValue = 0.0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
aValue = s.ToDouble(&rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static nsresult AppendArg(nsIMutableArray* aArray, const nsAString& aString) {
|
||||
nsCOMPtr<nsISupportsString> s =
|
||||
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
|
||||
|
@ -76,6 +97,8 @@ nsLayoutDebugCLH::Handle(nsICommandLine* aCmdLine) {
|
|||
bool flagPresent;
|
||||
|
||||
nsString url;
|
||||
bool autoclose = false;
|
||||
double delay = 0.0;
|
||||
|
||||
rv =
|
||||
HandleFlagWithOptionalArgument(aCmdLine, NS_LITERAL_STRING("layoutdebug"),
|
||||
|
@ -86,6 +109,10 @@ nsLayoutDebugCLH::Handle(nsICommandLine* aCmdLine) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
rv = HandleFlagWithOptionalArgument(aCmdLine, NS_LITERAL_STRING("autoclose"),
|
||||
0.0, delay, autoclose);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIMutableArray> argsArray = nsArray::Create();
|
||||
|
||||
if (!url.IsEmpty()) {
|
||||
|
@ -102,6 +129,14 @@ nsLayoutDebugCLH::Handle(nsICommandLine* aCmdLine) {
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
if (autoclose) {
|
||||
nsString arg;
|
||||
arg.AppendPrintf("autoclose=%f", delay);
|
||||
|
||||
rv = AppendArg(argsArray, arg);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWindowWatcher> wwatch =
|
||||
do_GetService(NS_WINDOWWATCHER_CONTRACTID);
|
||||
NS_ENSURE_TRUE(wwatch, NS_ERROR_FAILURE);
|
||||
|
@ -115,6 +150,10 @@ nsLayoutDebugCLH::Handle(nsICommandLine* aCmdLine) {
|
|||
|
||||
NS_IMETHODIMP
|
||||
nsLayoutDebugCLH::GetHelpInfo(nsACString& aResult) {
|
||||
aResult.AssignLiteral(" --layoutdebug [<url>] Start with Layout Debugger\n");
|
||||
aResult.AssignLiteral(
|
||||
" --layoutdebug [<url>] Start with Layout Debugger\n"
|
||||
" --autoclose [<seconds>] Automatically close the Layout Debugger once\n"
|
||||
" the page has loaded, after delaying the specified\n"
|
||||
" number of seconds (which defaults to 0).\n");
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
var gArgs;
|
||||
var gBrowser;
|
||||
var gURLBar;
|
||||
var gDebugger;
|
||||
|
@ -170,6 +171,17 @@ nsLDBBrowserContentListener.prototype = {
|
|||
this.setButtonEnabled(this.mStopButton, false);
|
||||
this.mStatusText.value = gURLBar.value + " loaded";
|
||||
this.mLoading = false;
|
||||
if (gArgs.autoclose && gBrowser.currentURI.spec != "about:blank") {
|
||||
// We check for about:blank just to avoid one or two STATE_STOP
|
||||
// notifications that occur before the loadURI() call completes.
|
||||
// This does mean that --autoclose doesn't work when the URL on
|
||||
// the command line is about:blank (or not specified), but that's
|
||||
// not a big deal.
|
||||
setTimeout(
|
||||
() => Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit),
|
||||
gArgs.delay * 1000
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -213,6 +225,26 @@ nsLDBBrowserContentListener.prototype = {
|
|||
mLoading: false,
|
||||
};
|
||||
|
||||
function parseArguments() {
|
||||
let args = {
|
||||
url: null,
|
||||
autoclose: false,
|
||||
delay: 0,
|
||||
};
|
||||
if (window.arguments) {
|
||||
args.url = window.arguments[0];
|
||||
for (let i = 1; i < window.arguments.length; ++i) {
|
||||
if (/^autoclose=(.*)$/.test(window.arguments[i])) {
|
||||
args.autoclose = true;
|
||||
args.delay = +RegExp.$1;
|
||||
} else {
|
||||
throw `Unknown option ${window.arguments[i]}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
function OnLDBLoad() {
|
||||
gBrowser = document.getElementById("browser");
|
||||
gURLBar = document.getElementById("urlbar");
|
||||
|
@ -229,8 +261,9 @@ function OnLDBLoad() {
|
|||
return null;
|
||||
};
|
||||
|
||||
if (window.arguments && window.arguments[0]) {
|
||||
loadURI(window.arguments[0]);
|
||||
gArgs = parseArguments();
|
||||
if (gArgs.url) {
|
||||
loadURI(gArgs.url);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче