Bug 887605 - Add "Copy URL" context menu item to Netmonitor; r=harth

This commit is contained in:
Minarto Margoliono 2013-07-10 18:50:16 -07:00
Родитель 1cb3ad3873
Коммит 2bab67852b
6 изменённых файлов: 68 добавлений и 7 удалений

Просмотреть файл

@ -22,6 +22,10 @@ XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
XPCOMUtils.defineLazyModuleGetter(this, "NetworkHelper",
"resource://gre/modules/devtools/NetworkHelper.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "clipboardHelper",
"@mozilla.org/widget/clipboardhelper;1",
"nsIClipboardHelper");
const NET_STRINGS_URI = "chrome://browser/locale/devtools/netmonitor.properties";
const LISTENERS = [ "NetworkActivity" ];
const NET_PREFS = { "NetworkMonitor.saveRequestAndResponseBodies": true };

Просмотреть файл

@ -362,6 +362,15 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
this.selectedItem = newItem;
},
/**
* Copy the request url from the currently selected item.
*/
copyUrl: function() {
let selected = this.selectedItem.attachment;
clipboardHelper.copyString(selected.url, this.document);
},
/**
* Send a new HTTP request using the data in the custom request form.
*/
@ -1162,8 +1171,11 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
* Handle the context menu opening. Hide items if no request is selected.
*/
_onContextShowing: function() {
let element = $("#request-menu-context-resend");
element.hidden = !this.selectedItem || this.selectedItem.attachment.isCustom;
let resendElement = $("#request-menu-context-resend");
resendElement.hidden = !this.selectedItem || this.selectedItem.attachment.isCustom;
let copyUrlElement = $("#request-menu-context-copy-url");
copyUrlElement.hidden = !this.selectedItem;
},
/**

Просмотреть файл

@ -20,6 +20,10 @@
<popupset id="networkPopupSet">
<menupopup id="network-request-popup"
onpopupshowing="NetMonitorView.RequestsMenu._onContextShowing(event);">
<menuitem id="request-menu-context-copy-url"
label="&netmonitorUI.context.copyUrl;"
accesskey="&netmonitorUI.context.copyUrl.accesskey;"
oncommand="NetMonitorView.RequestsMenu.copyUrl();"/>
<menuitem id="request-menu-context-resend"
label="&netmonitorUI.summary.resend;"
accesskey="&netmonitorUI.summary.resend.accesskey;"

Просмотреть файл

@ -44,6 +44,7 @@ MOCHITEST_BROWSER_TESTS = \
browser_net_footer-summary.js \
browser_net_resend.js \
browser_net_req-resp-bodies.js \
browser_net_copy_url.js \
head.js \
$(NULL)

Просмотреть файл

@ -0,0 +1,32 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests if copying a request's url works.
*/
function test() {
initNetMonitor(CUSTOM_GET_URL).then(([aTab, aDebuggee, aMonitor]) => {
info("Starting test... ");
let { NetMonitorView } = aMonitor.panelWin;
let { RequestsMenu } = NetMonitorView;
RequestsMenu.lazyUpdate = false;
waitForNetworkEvents(aMonitor, 1).then(() => {
let imageRequest = RequestsMenu.getItemAtIndex(0);
RequestsMenu.selectedItem = imageRequest;
waitForClipboard(RequestsMenu.selectedItem.attachment.url, function(){ RequestsMenu.copyUrl() } , cleanUp, cleanUp);
});
aDebuggee.performRequests(1);
function cleanUp(){
teardown(aMonitor);
finish();
}
});
}

Просмотреть файл

@ -169,12 +169,20 @@
- in a "receive" state. -->
<!ENTITY netmonitorUI.timings.receive "Receiving:">
<!-- LOCALIZATION NOTE (debuggerUI.custom.headers): This is the label displayed
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyUrl): This is the label displayed
- on the context menu that copies the selected request's url -->
<!ENTITY netmonitorUI.context.copyUrl "Copy URL">
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyUrl.accesskey): This is the access key
- for the Copy URL menu item displayed in the context menu for a request -->
<!ENTITY netmonitorUI.context.copyUrl.accesskey "C">
<!-- LOCALIZATION NOTE (debuggerUI.summary.resend): This is the label displayed
- on the button in the headers tab that opens a form to resend the currently
displayed request -->
<!ENTITY netmonitorUI.summary.resend "Resend">
<!-- LOCALIZATION NOTE (debuggerUI.custom.headers): This is the access key
<!-- LOCALIZATION NOTE (debuggerUI.summary.resend.accesskey): This is the access key
- for the Resend menu item displayed in the context menu for a request -->
<!ENTITY netmonitorUI.summary.resend.accesskey "R">
@ -190,14 +198,14 @@
- above the request headers entry in the custom request form -->
<!ENTITY netmonitorUI.custom.headers "Request Headers:">
<!-- LOCALIZATION NOTE (debuggerUI.custom.headers): This is the label displayed
<!-- LOCALIZATION NOTE (debuggerUI.custom.postData): This is the label displayed
- above the request body entry in the custom request form -->
<!ENTITY netmonitorUI.custom.postData "Request Body:">
<!-- LOCALIZATION NOTE (debuggerUI.custom.headers): This is the label displayed
<!-- LOCALIZATION NOTE (debuggerUI.custom.send): This is the label displayed
- on the button which sends the custom request -->
<!ENTITY netmonitorUI.custom.send "Send">
<!-- LOCALIZATION NOTE (debuggerUI.custom.headers): This is the label displayed
<!-- LOCALIZATION NOTE (debuggerUI.custom.cancel): This is the label displayed
- on the button which cancels and closes the custom request form -->
<!ENTITY netmonitorUI.custom.cancel "Cancel">