Bug 961085 - Remove inline script / style in devtools netmonitor.xul. r=bgrins, r=vporof

This commit is contained in:
Aakash Bapna 2014-01-28 08:50:34 -05:00
parent 756f412a58
commit dcba1e123f
2 changed files with 108 additions and 39 deletions

View File

@ -71,6 +71,7 @@ let NetMonitorView = {
this.Toolbar.initialize();
this.RequestsMenu.initialize();
this.NetworkDetails.initialize();
this.CustomRequest.initialize();
},
/**
@ -80,6 +81,7 @@ let NetMonitorView = {
this.Toolbar.destroy();
this.RequestsMenu.destroy();
this.NetworkDetails.destroy();
this.CustomRequest.destroy();
this._destroyPanes();
},
@ -271,6 +273,30 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
this.widget.addEventListener("select", this._onSelect, false);
this._splitter.addEventListener("mousemove", this._onResize, false);
window.addEventListener("resize", this._onResize, false);
this.requestsMenuSortEvent = getKeyWithEvent(this.sortBy.bind(this));
this.requestsMenuFilterEvent = getKeyWithEvent(this.filterOn.bind(this));
this.clearEvent = this.clear.bind(this);
this._onContextShowing = this._onContextShowing.bind(this);
this._onContextNewTabCommand = this.openRequestInTab.bind(this);
this._onContextCopyUrlCommand = this.copyUrl.bind(this);
this._onContextResendCommand = this.cloneSelectedRequest.bind(this);
this.sendCustomRequestEvent = this.sendCustomRequest.bind(this);
this.closeCustomRequestEvent = this.closeCustomRequest.bind(this);
this.cloneSelectedRequestEvent = this.cloneSelectedRequest.bind(this);
$("#toolbar-labels").addEventListener("click", this.requestsMenuSortEvent, false);
$("#requests-menu-footer").addEventListener("click", this.requestsMenuFilterEvent, false);
$("#requests-menu-clear-button").addEventListener("click", this.clearEvent, false);
$("#network-request-popup").addEventListener("popupshowing", this._onContextShowing, false);
$("#request-menu-context-newtab").addEventListener("command", this._onContextNewTabCommand, false);
$("#request-menu-context-copy-url").addEventListener("command", this._onContextCopyUrlCommand, false);
$("#request-menu-context-resend").addEventListener("command", this._onContextResendCommand, false);
$("#custom-request-send-button").addEventListener("click", this.sendCustomRequestEvent, false);
$("#custom-request-close-button").addEventListener("click", this.closeCustomRequestEvent, false);
$("#headers-summary-resend").addEventListener("click", this.cloneSelectedRequestEvent, false);
},
/**
@ -282,6 +308,18 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
this.widget.removeEventListener("select", this._onSelect, false);
this._splitter.removeEventListener("mousemove", this._onResize, false);
window.removeEventListener("resize", this._onResize, false);
$("#toolbar-labels").removeEventListener("click", this.requestsMenuSortEvent, false);
$("#requests-menu-footer").removeEventListener("click", this.requestsMenuFilterEvent, false);
$("#requests-menu-clear-button").removeEventListener("click", this.clearEvent, false);
$("#network-request-popup").removeEventListener("popupshowing", this._onContextShowing, false);
$("#request-menu-context-newtab").removeEventListener("command", this._onContextNewTabCommand, false);
$("#request-menu-context-copy-url").removeEventListener("command", this._onContextCopyUrlCommand, false);
$("#request-menu-context-resend").removeEventListener("command", this._onContextResendCommand, false);
$("#custom-request-send-button").removeEventListener("click", this.sendCustomRequestEvent, false);
$("#custom-request-close-button").removeEventListener("click", this.closeCustomRequestEvent, false);
$("#headers-summary-resend").removeEventListener("click", this.cloneSelectedRequestEvent, false);
},
/**
@ -1435,6 +1473,26 @@ function CustomRequestView() {
}
CustomRequestView.prototype = {
/**
* Initialization function, called when the network monitor is started.
*/
initialize: function() {
dumpn("Initializing the CustomRequestView");
this.updateCustomRequestEvent = getKeyWithEvent(this.onUpdate.bind(this));
$("#custom-pane").addEventListener("input", this.updateCustomRequestEvent, false);
},
/**
* Destruction function, called when the network monitor is closed.
*/
destroy: function() {
dumpn("Destroying the CustomRequestView");
$("#custom-pane").removeEventListener("input", this.updateCustomRequestEvent, false);
},
/**
* Populates this view with the specified data.
*
@ -2237,6 +2295,23 @@ function writeQueryString(aParams) {
return [(name + "=" + value) for ({name, value} of aParams)].join("&");
}
/**
* Helper method to get a wrapped function which can be bound to as an event listener directly and is executed only when data-key is present in event.target.
*
* @param function callback
* Function to execute execute when data-key is present in event.target.
* @return function
* Wrapped function with the target data-key as the first argument.
*/
function getKeyWithEvent(callback) {
return function(event) {
var key = event.target.getAttribute("data-key");
if (key) {
callback.call(null, key);
}
};
}
/**
* Preliminary setup for the NetMonitorView object.
*/

View File

@ -21,20 +21,16 @@
<script type="text/javascript" src="netmonitor-view.js"/>
<popupset id="networkPopupSet">
<menupopup id="network-request-popup"
onpopupshowing="NetMonitorView.RequestsMenu._onContextShowing(event);">
<menupopup id="network-request-popup">
<menuitem id="request-menu-context-newtab"
label="&netmonitorUI.context.newTab;"
accesskey="&netmonitorUI.context.newTab.accesskey;"
oncommand="NetMonitorView.RequestsMenu.openRequestInTab();"/>
accesskey="&netmonitorUI.context.newTab.accesskey;"/>
<menuitem id="request-menu-context-copy-url"
label="&netmonitorUI.context.copyUrl;"
accesskey="&netmonitorUI.context.copyUrl.accesskey;"
oncommand="NetMonitorView.RequestsMenu.copyUrl();"/>
accesskey="&netmonitorUI.context.copyUrl.accesskey;"/>
<menuitem id="request-menu-context-resend"
label="&netmonitorUI.summary.editAndResend;"
accesskey="&netmonitorUI.summary.editAndResend.accesskey;"
oncommand="NetMonitorView.RequestsMenu.cloneSelectedRequest();"/>
accesskey="&netmonitorUI.summary.editAndResend.accesskey;"/>
</menupopup>
</popupset>
@ -51,12 +47,12 @@
align="center">
<button id="requests-menu-status-button"
class="requests-menu-header-button requests-menu-status"
onclick="NetMonitorView.RequestsMenu.sortBy('status')"
data-key="status"
label="&netmonitorUI.toolbar.status2;">
</button>
<button id="requests-menu-method-button"
class="requests-menu-header-button requests-menu-method"
onclick="NetMonitorView.RequestsMenu.sortBy('method')"
data-key="method"
label="&netmonitorUI.toolbar.method;"
flex="1">
</button>
@ -66,7 +62,7 @@
align="center">
<button id="requests-menu-file-button"
class="requests-menu-header-button requests-menu-file"
onclick="NetMonitorView.RequestsMenu.sortBy('file')"
data-key="file"
label="&netmonitorUI.toolbar.file;"
flex="1">
</button>
@ -76,7 +72,7 @@
align="center">
<button id="requests-menu-domain-button"
class="requests-menu-header-button requests-menu-domain"
onclick="NetMonitorView.RequestsMenu.sortBy('domain')"
data-key="domain"
label="&netmonitorUI.toolbar.domain;"
flex="1">
</button>
@ -86,7 +82,7 @@
align="center">
<button id="requests-menu-type-button"
class="requests-menu-header-button requests-menu-type"
onclick="NetMonitorView.RequestsMenu.sortBy('type')"
data-key="type"
label="&netmonitorUI.toolbar.type;"
flex="1">
</button>
@ -96,7 +92,7 @@
align="center">
<button id="requests-menu-size-button"
class="requests-menu-header-button requests-menu-size"
onclick="NetMonitorView.RequestsMenu.sortBy('size')"
data-key="size"
label="&netmonitorUI.toolbar.size;"
flex="1">
</button>
@ -107,7 +103,7 @@
flex="1">
<button id="requests-menu-waterfall-button"
class="requests-menu-header-button requests-menu-waterfall"
onclick="NetMonitorView.RequestsMenu.sortBy('waterfall')"
data-key="waterfall"
pack="start"
flex="1">
<label id="requests-menu-waterfall-label"
@ -160,47 +156,47 @@
<button id="requests-menu-filter-all-button"
class="requests-menu-footer-button"
checked="true"
onclick="NetMonitorView.RequestsMenu.filterOn('all')"
data-key="all"
label="&netmonitorUI.footer.filterAll;">
</button>
<button id="requests-menu-filter-html-button"
class="requests-menu-footer-button"
onclick="NetMonitorView.RequestsMenu.filterOn('html')"
data-key="html"
label="&netmonitorUI.footer.filterHTML;">
</button>
<button id="requests-menu-filter-css-button"
class="requests-menu-footer-button"
onclick="NetMonitorView.RequestsMenu.filterOn('css')"
data-key="css"
label="&netmonitorUI.footer.filterCSS;">
</button>
<button id="requests-menu-filter-js-button"
class="requests-menu-footer-button"
onclick="NetMonitorView.RequestsMenu.filterOn('js')"
data-key="js"
label="&netmonitorUI.footer.filterJS;">
</button>
<button id="requests-menu-filter-xhr-button"
class="requests-menu-footer-button"
onclick="NetMonitorView.RequestsMenu.filterOn('xhr')"
data-key="xhr"
label="&netmonitorUI.footer.filterXHR;">
</button>
<button id="requests-menu-filter-fonts-button"
class="requests-menu-footer-button"
onclick="NetMonitorView.RequestsMenu.filterOn('fonts')"
data-key="fonts"
label="&netmonitorUI.footer.filterFonts;">
</button>
<button id="requests-menu-filter-images-button"
class="requests-menu-footer-button"
onclick="NetMonitorView.RequestsMenu.filterOn('images')"
data-key="images"
label="&netmonitorUI.footer.filterImages;">
</button>
<button id="requests-menu-filter-media-button"
class="requests-menu-footer-button"
onclick="NetMonitorView.RequestsMenu.filterOn('media')"
data-key="media"
label="&netmonitorUI.footer.filterMedia;">
</button>
<button id="requests-menu-filter-flash-button"
class="requests-menu-footer-button"
onclick="NetMonitorView.RequestsMenu.filterOn('flash')"
data-key="flash"
label="&netmonitorUI.footer.filterFlash;">
</button>
<spacer id="requests-menu-spacer-end"
@ -212,7 +208,6 @@
crop="end"/>
<button id="requests-menu-clear-button"
class="requests-menu-footer-button"
onclick="NetMonitorView.RequestsMenu.clear()"
label="&netmonitorUI.footer.clear;">
</button>
</hbox>
@ -229,22 +224,22 @@
class="plain tabpanel-summary-label
custom-header"/>
<hbox flex="1" pack="end">
<button class="devtools-toolbarbutton"
label="&netmonitorUI.custom.send;"
onclick="NetMonitorView.RequestsMenu.sendCustomRequest();"/>
<button class="devtools-toolbarbutton"
label="&netmonitorUI.custom.cancel;"
onclick="NetMonitorView.RequestsMenu.closeCustomRequest();"/>
<button id="custom-request-send-button"
class="devtools-toolbarbutton"
label="&netmonitorUI.custom.send;"/>
<button id="custom-request-close-button"
class="devtools-toolbarbutton"
label="&netmonitorUI.custom.cancel;"/>
</hbox>
</hbox>
<hbox id="custom-method-and-url"
class="tabpanel-summary-container"
align="center">
<textbox id="custom-method-value"
oninput="NetMonitorView.CustomRequest.onUpdate('method');"/>
data-key="method"/>
<textbox id="custom-url-value"
flex="1"
oninput="NetMonitorView.CustomRequest.onUpdate('url');"/>
data-key="url"/>
</hbox>
<vbox id="custom-query"
class="tabpanel-summary-container custom-section">
@ -255,7 +250,7 @@
multiline="true"
rows="4"
wrap="off"
oninput="NetMonitorView.CustomRequest.onUpdate('query');"/>
data-key="query"/>
</vbox>
<vbox id="custom-headers"
class="tabpanel-summary-container custom-section">
@ -266,7 +261,7 @@
multiline="true"
rows="8"
wrap="off"
oninput="NetMonitorView.CustomRequest.onUpdate('headers');"/>
data-key="headers"/>
</vbox>
<vbox id="custom-postdata"
class="tabpanel-summary-container custom-section">
@ -277,7 +272,7 @@
multiline="true"
rows="6"
wrap="off"
oninput="NetMonitorView.CustomRequest.onUpdate('body');"/>
data-key="body"/>
</vbox>
</vbox>
<tabbox id="event-details-pane"
@ -326,9 +321,8 @@
crop="end"
flex="1"/>
<button id="headers-summary-resend"
label="&netmonitorUI.summary.editAndResend;"
class="devtools-toolbarbutton"
onclick="NetMonitorView.RequestsMenu.cloneSelectedRequest();"/>
label="&netmonitorUI.summary.editAndResend;"/>
</hbox>
<hbox id="headers-summary-version"
class="tabpanel-summary-container"