mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
797c29b92e
--HG-- rename : browser/devtools/commandline/Commands.jsm => browser/devtools/commandline/GcliCommands.jsm rename : browser/devtools/commandline/CmdCookie.jsm => browser/devtools/commandline/GcliCookieCommands.jsm rename : browser/devtools/tilt/CmdTilt.jsm => browser/devtools/commandline/GcliTiltCommands.jsm rename : browser/devtools/commandline/commandline.css => browser/devtools/commandline/gcli.css rename : browser/devtools/commandline/commandlineoutput.xhtml => browser/devtools/commandline/gclioutput.xhtml rename : browser/devtools/commandline/commandlinetooltip.xhtml => browser/devtools/commandline/gclitooltip.xhtml rename : browser/devtools/commandline/test/browser_cmd_addon.js => browser/devtools/commandline/test/browser_gcli_addon.js rename : browser/devtools/commandline/test/browser_dbg_cmd_break.html => browser/devtools/commandline/test/browser_gcli_break.html rename : browser/devtools/commandline/test/browser_dbg_cmd_break.js => browser/devtools/commandline/test/browser_gcli_break.js rename : browser/devtools/commandline/test/browser_cmd_calllog.js => browser/devtools/commandline/test/browser_gcli_calllog.js rename : browser/devtools/commandline/test/browser_cmd_commands.js => browser/devtools/commandline/test/browser_gcli_commands.js rename : browser/devtools/commandline/test/browser_cmd_cookie.js => browser/devtools/commandline/test/browser_gcli_cookie.js rename : browser/devtools/commandline/test/browser_dbg_cmd.js => browser/devtools/commandline/test/browser_gcli_dbg.js rename : browser/devtools/styleeditor/test/browser_styleeditor_cmd_edit.js => browser/devtools/commandline/test/browser_gcli_edit.js rename : browser/devtools/commandline/test/browser_cmd_pagemod_export.html => browser/devtools/commandline/test/browser_gcli_inspect.html rename : browser/devtools/highlighter/test/browser_inspector_cmd_inspect.js => browser/devtools/commandline/test/browser_gcli_inspect.js rename : browser/devtools/commandline/test/browser_cmd_integrate.js => browser/devtools/commandline/test/browser_gcli_integrate.js rename : browser/devtools/commandline/test/browser_cmd_jsb.js => browser/devtools/commandline/test/browser_gcli_jsb.js rename : browser/devtools/commandline/test/browser_cmd_pagemod_export.js => browser/devtools/commandline/test/browser_gcli_pagemod_export.js rename : browser/devtools/commandline/test/browser_cmd_pref.js => browser/devtools/commandline/test/browser_gcli_pref.js rename : browser/devtools/responsivedesign/test/browser_responsive_cmd.js => browser/devtools/commandline/test/browser_gcli_responsivemode.js rename : browser/devtools/commandline/test/browser_cmd_restart.js => browser/devtools/commandline/test/browser_gcli_restart.js rename : browser/devtools/commandline/test/browser_cmd_settings.js => browser/devtools/commandline/test/browser_gcli_settings.js rename : browser/devtools/styleeditor/test/browser_styleeditor_cmd_edit.html => browser/devtools/commandline/test/resources.html rename : browser/devtools/commandline/test/browser_dbg_cmd.html => browser/devtools/commandline/test/resources_dbg.html rename : browser/devtools/styleeditor/test/resources_inpage.jsi => browser/devtools/commandline/test/resources_inpage.js rename : browser/devtools/styleeditor/test/resources_inpage1.css => browser/devtools/commandline/test/resources_inpage1.css rename : browser/devtools/styleeditor/test/resources_inpage2.css => browser/devtools/commandline/test/resources_inpage2.css rename : browser/devtools/commandline/test/browser_cmd_jsb_script.jsi => browser/devtools/commandline/test/resources_jsb_script.js rename : browser/themes/gnomestripe/devtools/commandline.css => browser/themes/gnomestripe/devtools/gcli.css rename : browser/themes/pinstripe/devtools/commandline.css => browser/themes/pinstripe/devtools/gcli.css rename : browser/themes/winstripe/devtools/commandline.css => browser/themes/winstripe/devtools/gcli.css
208 lines
5.9 KiB
JavaScript
208 lines
5.9 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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/. */
|
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
|
|
|
let EXPORTED_SYMBOLS = [ ];
|
|
|
|
Cu.import("resource:///modules/devtools/gcli.jsm");
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "console",
|
|
"resource:///modules/devtools/Console.jsm");
|
|
|
|
// We should really be using nsICookieManager so we can read more than just the
|
|
// key/value of cookies. The difficulty is filtering the cookies that are
|
|
// relevant to the current page. See
|
|
// https://github.com/firebug/firebug/blob/master/extension/content/firebug/cookies/cookieObserver.js#L123
|
|
// For details on how this is done with Firebug
|
|
|
|
/**
|
|
* 'cookie' command
|
|
*/
|
|
gcli.addCommand({
|
|
name: "cookie",
|
|
description: gcli.lookup("cookieDesc"),
|
|
manual: gcli.lookup("cookieManual")
|
|
});
|
|
|
|
/**
|
|
* The template for the 'cookie list' command.
|
|
*/
|
|
var cookieListHtml = "" +
|
|
"<table>" +
|
|
" <tr>" +
|
|
" <th>" + gcli.lookup("cookieListOutKey") + "</th>" +
|
|
" <th>" + gcli.lookup("cookieListOutValue") + "</th>" +
|
|
" <th>" + gcli.lookup("cookieListOutActions") + "</th>" +
|
|
" </tr>" +
|
|
" <tr foreach='cookie in ${cookies}'>" +
|
|
" <td>${cookie.key}</td>" +
|
|
" <td>${cookie.value}</td>" +
|
|
" <td>" +
|
|
" <span class='gcli-out-shortcut' onclick='${onclick}'" +
|
|
" data-command='cookie set ${cookie.key} '" +
|
|
" >" + gcli.lookup("cookieListOutEdit") + "</span>" +
|
|
" <span class='gcli-out-shortcut'" +
|
|
" onclick='${onclick}' ondblclick='${ondblclick}'" +
|
|
" data-command='cookie remove ${cookie.key}'" +
|
|
" >" + gcli.lookup("cookieListOutRemove") + "</span>" +
|
|
" </td>" +
|
|
" </tr>" +
|
|
"</table>" +
|
|
"";
|
|
|
|
/**
|
|
* 'cookie list' command
|
|
*/
|
|
gcli.addCommand({
|
|
name: "cookie list",
|
|
description: gcli.lookup("cookieListDesc"),
|
|
manual: gcli.lookup("cookieListManual"),
|
|
returnType: "string",
|
|
exec: function Command_cookieList(args, context) {
|
|
// Parse out an array of { key:..., value:... } objects for each cookie
|
|
var doc = context.environment.contentDocument;
|
|
var cookies = doc.cookie.split("; ").map(function(cookieStr) {
|
|
var equalsPos = cookieStr.indexOf("=");
|
|
return {
|
|
key: cookieStr.substring(0, equalsPos),
|
|
value: cookieStr.substring(equalsPos + 1)
|
|
};
|
|
});
|
|
|
|
return context.createView({
|
|
html: cookieListHtml,
|
|
data: {
|
|
cookies: cookies,
|
|
onclick: createUpdateHandler(context),
|
|
ondblclick: createExecuteHandler(context),
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
/**
|
|
* 'cookie remove' command
|
|
*/
|
|
gcli.addCommand({
|
|
name: "cookie remove",
|
|
description: gcli.lookup("cookieRemoveDesc"),
|
|
manual: gcli.lookup("cookieRemoveManual"),
|
|
params: [
|
|
{
|
|
name: "key",
|
|
type: "string",
|
|
description: gcli.lookup("cookieRemoveKeyDesc"),
|
|
}
|
|
],
|
|
exec: function Command_cookieRemove(args, context) {
|
|
let document = context.environment.contentDocument;
|
|
let expDate = new Date();
|
|
expDate.setDate(expDate.getDate() - 1);
|
|
document.cookie = escape(args.key) + "=; expires=" + expDate.toGMTString();
|
|
}
|
|
});
|
|
|
|
/**
|
|
* 'cookie set' command
|
|
*/
|
|
gcli.addCommand({
|
|
name: "cookie set",
|
|
description: gcli.lookup("cookieSetDesc"),
|
|
manual: gcli.lookup("cookieSetManual"),
|
|
params: [
|
|
{
|
|
name: "key",
|
|
type: "string",
|
|
description: gcli.lookup("cookieSetKeyDesc")
|
|
},
|
|
{
|
|
name: "value",
|
|
type: "string",
|
|
description: gcli.lookup("cookieSetValueDesc")
|
|
},
|
|
{
|
|
group: gcli.lookup("cookieSetOptionsDesc"),
|
|
params: [
|
|
{
|
|
name: "path",
|
|
type: "string",
|
|
defaultValue: "/",
|
|
description: gcli.lookup("cookieSetPathDesc")
|
|
},
|
|
{
|
|
name: "domain",
|
|
type: "string",
|
|
defaultValue: null,
|
|
description: gcli.lookup("cookieSetDomainDesc")
|
|
},
|
|
{
|
|
name: "secure",
|
|
type: "boolean",
|
|
description: gcli.lookup("cookieSetSecureDesc")
|
|
}
|
|
]
|
|
}
|
|
],
|
|
exec: function Command_cookieSet(args, context) {
|
|
let document = context.environment.contentDocument;
|
|
|
|
document.cookie = escape(args.key) + "=" + escape(args.value) +
|
|
(args.domain ? "; domain=" + args.domain : "") +
|
|
(args.path ? "; path=" + args.path : "") +
|
|
(args.secure ? "; secure" : "");
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Helper to find the 'data-command' attribute and call some action on it.
|
|
* @see |updateCommand()| and |executeCommand()|
|
|
*/
|
|
function withCommand(element, action) {
|
|
var command = element.getAttribute("data-command");
|
|
if (!command) {
|
|
command = element.querySelector("*[data-command]")
|
|
.getAttribute("data-command");
|
|
}
|
|
|
|
if (command) {
|
|
action(command);
|
|
}
|
|
else {
|
|
console.warn("Missing data-command for " + util.findCssSelector(element));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create a handler to update the requisition to contain the text held in the
|
|
* first matching data-command attribute under the currentTarget of the event.
|
|
* @param context Either a Requisition or an ExecutionContext or another object
|
|
* that contains an |update()| function that follows a similar contract.
|
|
*/
|
|
function createUpdateHandler(context) {
|
|
return function(ev) {
|
|
withCommand(ev.currentTarget, function(command) {
|
|
context.update(command);
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create a handler to execute the text held in the data-command attribute
|
|
* under the currentTarget of the event.
|
|
* @param context Either a Requisition or an ExecutionContext or another object
|
|
* that contains an |update()| function that follows a similar contract.
|
|
*/
|
|
function createExecuteHandler(context) {
|
|
return function(ev) {
|
|
withCommand(ev.currentTarget, function(command) {
|
|
context.exec({
|
|
visible: true,
|
|
typed: command
|
|
});
|
|
});
|
|
}
|
|
}
|