Bug 864098 - Add "Disable Cache" to options panel r=jwalker

--HG--
rename : browser/devtools/framework/test/browser_toolbox_options_disablejs.html => browser/devtools/framework/test/browser_toolbox_options_disable_js.html
rename : browser/devtools/framework/test/browser_toolbox_options_disablejs.js => browser/devtools/framework/test/browser_toolbox_options_disable_js.js
rename : browser/devtools/framework/test/browser_toolbox_options_disablejs_iframe.html => browser/devtools/framework/test/browser_toolbox_options_disable_js_iframe.html
This commit is contained in:
Michael Ratcliffe 2013-12-18 09:34:49 +00:00
Родитель dbd8549587
Коммит 8af158adc6
14 изменённых файлов: 388 добавлений и 55 удалений

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

@ -1065,7 +1065,7 @@ let RemoteDebugger = {
if ("nsIProfiler" in Ci) {
DebuggerServer.addActors("resource://gre/modules/devtools/server/actors/profiler.js");
}
DebuggerServer.registerModule("devtools/server/actors/inspector")
DebuggerServer.registerModule("devtools/server/actors/inspector");
DebuggerServer.registerModule("devtools/server/actors/styleeditor");
DebuggerServer.enableWebappsContentActor = true;
}

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

@ -1,7 +1,8 @@
[DEFAULT]
support-files =
browser_toolbox_options_disablejs.html
browser_toolbox_options_disablejs_iframe.html
browser_toolbox_options_disable_js.html
browser_toolbox_options_disable_js_iframe.html
browser_toolbox_options_disable_cache.sjs
head.js
[browser_devtools_api.js]
@ -13,7 +14,8 @@ support-files =
[browser_toolbox_highlight.js]
[browser_toolbox_hosts.js]
[browser_toolbox_options.js]
[browser_toolbox_options_disablejs.js]
[browser_toolbox_options_disable_cache.js]
[browser_toolbox_options_disable_js.js]
[browser_toolbox_raise.js]
skip-if = os == "win"
[browser_toolbox_ready.js]

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

@ -0,0 +1,113 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that disabling JavaScript for a tab works as it should.
const TEST_URI = "http://mochi.test:8888/browser/browser/devtools/framework/" +
"test/browser_toolbox_options_disable_cache.sjs";
let doc;
let toolbox;
function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
let target = TargetFactory.forTab(gBrowser.selectedTab);
gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) {
gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
doc = content.document;
gDevTools.showToolbox(target).then(testSelectTool);
}, true);
content.location = TEST_URI;
}
function testSelectTool(aToolbox) {
toolbox = aToolbox;
toolbox.once("options-selected", testCacheEnabled);
toolbox.selectTool("options");
}
function testCacheEnabled() {
let prevTimestamp = getGUID();
gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) {
gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
doc = content.document;
is(prevTimestamp, getGUID(), "GUID has not changed (page is cached)");
testCacheEnabled2();
}, true);
doc.location.reload(false);
}
function testCacheEnabled2() {
let prevTimestamp = getGUID();
gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) {
gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
doc = content.document;
is(prevTimestamp, getGUID(),
"GUID has not changed after page refresh (page is cached)");
testCacheDisabled();
}, true);
doc.location.reload(false);
}
function testCacheDisabled() {
let prevTimestamp = getGUID();
let panel = toolbox.getCurrentPanel();
let cbx = panel.panelDoc.getElementById("devtools-disable-cache");
let browser = gBrowser.selectedBrowser;
browser.addEventListener("load", function onLoad(evt) {
browser.removeEventListener(evt.type, onLoad, true);
doc = content.document;
isnot(prevTimestamp, getGUID(), "GUID has changed (page is not cached)");
testCacheDisabled2();
}, true);
info("disabling cache");
cbx.scrollIntoView();
// After uising scrollIntoView() we need to use executeSoon() to wait for the
// browser to scroll.
executeSoon(function() {
EventUtils.synthesizeMouseAtCenter(cbx, {}, panel.panelWin);
});
}
function testCacheDisabled2() {
let prevTimestamp = getGUID();
let browser = gBrowser.selectedBrowser;
browser.addEventListener("load", function onLoad(evt) {
browser.removeEventListener(evt.type, onLoad, true);
doc = content.document;
isnot(prevTimestamp, getGUID(),
"GUID has changed after page refresh (page is not cached)");
finishUp();
}, true);
doc.location.reload(false);
}
function getGUID() {
return doc.querySelector("h1").textContent;
}
function finishUp() {
toolbox.destroy().then(() => {
gBrowser.removeCurrentTab();
toolbox = doc = null;
finish();
}).then(null, console.error);
}

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

@ -0,0 +1,28 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function handleRequest(request, response) {
let Etag = '"4d881ab-b03-435f0a0f9ef00"';
let IfNoneMatch = request.hasHeader("If-None-Match")
? request.getHeader("If-None-Match")
: "";
let guid = 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
let r = Math.random() * 16 | 0;
let v = c === "x" ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
let page = "<!DOCTYPE html><html><body><h1>" + guid + "</h1></body></html>";
response.setHeader("Etag", Etag, false);
if (IfNoneMatch === Etag) {
response.setStatusLine(request.httpVersion, "304", "Not Modified");
} else {
response.setHeader("Content-Type", "text/html; charset=utf-8", false);
response.setHeader("Content-Length", page.length + "", false);
response.write(page);
}
}

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

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<title>browser_toolbox_options_disablejs.html</title>
@ -40,6 +41,6 @@
<br>
<div id="output">No output</div>
<h1>Test in iframe</h1>
<iframe src="browser_toolbox_options_disablejs_iframe.html"></iframe>
<iframe src="browser_toolbox_options_disable_js_iframe.html"></iframe>
</body>
</html>

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

@ -4,7 +4,7 @@
// Tests that disabling JavaScript for a tab works as it should.
const TEST_URI = "http://example.com/browser/browser/devtools/framework/" +
"test/browser_toolbox_options_disablejs.html";
"test/browser_toolbox_options_disable_js.html";
let doc;
let toolbox;
@ -123,6 +123,9 @@ function testJSDisabledIframe() {
}
function finishUp() {
doc = toolbox = null;
finish();
toolbox.destroy().then(function() {
gBrowser.removeCurrentTab();
toolbox = doc = null;
finish();
});
}

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

@ -20,8 +20,10 @@ function test() {
let nextIndex = index + 1;
if (nextIndex >= toolIds.length) {
toolbox.destroy();
finish();
toolbox.destroy().then(function() {
gBrowser.removeCurrentTab();
finish();
});
}
else {
open(nextIndex);

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

@ -41,7 +41,7 @@ function OptionsPanel(iframeWindow, toolbox) {
this.isReady = false;
EventEmitter.decorate(this);
};
}
OptionsPanel.prototype = {
@ -50,20 +50,35 @@ OptionsPanel.prototype = {
},
open: function() {
let deferred = promise.defer();
let targetPromise;
this.setupToolsList();
this.populatePreferences();
// For local debugging we need to make the target remote.
if (!this.target.isRemote) {
targetPromise = this.target.makeRemote();
} else {
targetPromise = promise.resolve(this.target);
}
this._disableJSClicked = this._disableJSClicked.bind(this);
return targetPromise.then(() => {
this.setupToolsList();
this.populatePreferences();
let disableJSNode = this.panelDoc.getElementById("devtools-disable-javascript");
disableJSNode.addEventListener("click", this._disableJSClicked, false);
this._disableJSClicked = this._disableJSClicked.bind(this);
this._disableCacheClicked = this._disableCacheClicked.bind(this);
this.isReady = true;
this.emit("ready");
deferred.resolve(this);
return deferred.promise;
let disableJSNode = this.panelDoc.getElementById("devtools-disable-javascript");
disableJSNode.addEventListener("click", this._disableJSClicked, false);
let disableCacheNode = this.panelDoc.getElementById("devtools-disable-cache");
disableCacheNode.addEventListener("click", this._disableCacheClicked, false);
}).then(() => {
this.isReady = true;
this.emit("ready");
return this;
}).then(null, function onError(aReason) {
Cu.reportError("OptionsPanel open failed. " +
aReason.error + ": " + aReason.message);
});
},
setupToolsList: function() {
@ -196,6 +211,24 @@ OptionsPanel.prototype = {
gDevTools.emit("pref-changed", data);
}.bind(menulist));
}
this.target.client.attachTab(this.target.client.activeTab._actor, (response) => {
this._origJavascriptEnabled = response.javascriptEnabled;
this._origCacheEnabled = response.cacheEnabled;
this._populateDisableJSCheckbox();
this._populateDisableCacheCheckbox();
});
},
_populateDisableJSCheckbox: function() {
let cbx = this.panelDoc.getElementById("devtools-disable-javascript");
cbx.checked = !this._origJavascriptEnabled;
},
_populateDisableCacheCheckbox: function() {
let cbx = this.panelDoc.getElementById("devtools-disable-cache");
cbx.checked = !this._origCacheEnabled;
},
/**
@ -210,22 +243,59 @@ OptionsPanel.prototype = {
*/
_disableJSClicked: function(event) {
let checked = event.target.checked;
let linkedBrowser = this.toolbox._host.hostTab.linkedBrowser;
let win = linkedBrowser.contentWindow;
let docShell = linkedBrowser.docShell;
if (typeof this.toolbox._origAllowJavascript == "undefined") {
this.toolbox._origAllowJavascript = docShell.allowJavascript;
}
let options = {
"javascriptEnabled": !checked
};
docShell.allowJavascript = !checked;
win.location.reload();
this.target.client.reconfigureTab(options);
},
destroy: function OP_destroy() {
/**
* Disables the cache for the currently loaded tab.
*
* @param {Event} event
* The event sent by checking / unchecking the disable cache checkbox.
*/
_disableCacheClicked: function(event) {
let checked = event.target.checked;
let options = {
"cacheEnabled": !checked
};
this.target.client.reconfigureTab(options);
},
destroy: function() {
if (this.destroyPromise) {
return this.destroyPromise;
}
let deferred = promise.defer();
this.destroyPromise = deferred.promise;
let disableJSNode = this.panelDoc.getElementById("devtools-disable-javascript");
disableJSNode.removeEventListener("click", this._disableJSClicked, false);
this.panelWin = this.panelDoc = this.toolbox = this._disableJSClicked = null;
let disableCacheNode = this.panelDoc.getElementById("devtools-disable-cache");
disableCacheNode.removeEventListener("click", this._disableCacheClicked, false);
this.panelWin = this.panelDoc = null;
this._disableJSClicked = this._disableCacheClicked = null;
// If the cache or JavaScript is disabled we need to revert them to their
// original values.
let options = {
"cacheEnabled": this._origCacheEnabled,
"javascriptEnabled": this._origJavascriptEnabled
};
this.target.client.reconfigureTab(options, () => {
this.toolbox = null;
deferred.resolve();
}, true);
return deferred.promise;
}
};

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

@ -69,13 +69,12 @@
</vbox>
<label value="&options.context.advancedSettings;"/>
<vbox id="context-options" class="options-groupbox">
<hbox>
<checkbox id="devtools-disable-javascript"
label="&options.disableJavaScript.label2;"
tooltiptext="&options.disableJavaScript.tooltip;"/>
<label class="options-citation-label theme-comment"
value="(&options.context.triggersPageRefresh2;)"/>
</hbox>
<checkbox id="devtools-disable-cache"
label="&options.disableCache.label;"
tooltiptext="&options.disableCache.tooltip;"/>
<checkbox id="devtools-disable-javascript"
label="&options.disableJavaScript.label;"
tooltiptext="&options.disableJavaScript.tooltip;"/>
<hbox class="hidden-labels-box">
<checkbox label="&options.enableChrome.label3;"
tooltiptext="&options.enableChrome.tooltip;"
@ -86,6 +85,8 @@
tooltiptext="&options.enableRemote.tooltip;"
data-pref="devtools.debugger.remote-enabled"/>
</hbox>
<label class="options-citation-label"
value="&options.context.triggersPageRefresh;"/>
</vbox>
</vbox>
</hbox>

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

@ -992,16 +992,7 @@ Toolbox.prototype = {
gDevTools.off("tool-registered", this._toolRegistered);
gDevTools.off("tool-unregistered", this._toolUnregistered);
// Revert docShell.allowJavascript back to its original value if it was
// changed via the Disable JS option.
if (typeof this._origAllowJavascript != "undefined") {
let docShell = this._host.hostTab.linkedBrowser.docShell;
docShell.allowJavascript = this._origAllowJavascript;
this._origAllowJavascript = undefined;
}
let outstanding = [];
for (let [id, panel] of this._toolPanels) {
try {
outstanding.push(panel.destroy());

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

@ -52,10 +52,10 @@
- -->
<!ENTITY options.defaultColorUnit.name "Color Names">
<!-- LOCALIZATION NOTE (options.context.triggersPageRefresh2): This is the
- triggers page refresh label next to the settings in the advanced settings
- group in the options panel which trigger page reload. -->
<!ENTITY options.context.triggersPageRefresh2 "Current session only, reloads the page">
<!-- LOCALIZATION NOTE (options.context.triggersPageRefresh): This is the
- triggers page refresh footnote under the advanced settings group in the
- options panel and is used for settings that trigger page reload. -->
<!ENTITY options.context.triggersPageRefresh "* Current session only, reloads the page">
<!-- LOCALIZATION NOTE (options.enableChrome.label3): This is the label for the
- checkbox that toggles chrome debugging, i.e. devtools.chrome.enabled
@ -69,12 +69,18 @@
<!ENTITY options.enableRemote.label3 "Enable remote debugging">
<!ENTITY options.enableRemote.tooltip "Turning this option on will allow the developer tools to debug remote Firefox instance like Firefox OS">
<!-- LOCALIZATION NOTE (options.disableJavaScript.label2,
<!-- LOCALIZATION NOTE (options.disableJavaScript.label,
- options.disableJavaScript.tooltip): This is the options panel label and
- tooltip for the checkbox that toggles JavaScript on or off. -->
<!ENTITY options.disableJavaScript.label2 "Disable JavaScript">
<!ENTITY options.disableJavaScript.label "Disable JavaScript *">
<!ENTITY options.disableJavaScript.tooltip "Turning this option on will disable JavaScript for the current tab. If the tab or the toolbox is closed then this setting will be forgotten.">
<!-- LOCALIZATION NOTE (options.disableCache.label,
- options.disableCache.tooltip): This is the options panel label and
- tooltip for the checkbox that toggles the cache on or off. -->
<!ENTITY options.disableCache.label "Disable Cache *">
<!ENTITY options.disableCache.tooltip "Turning this option on will disable the cache for the current tab. If the tab or the toolbox is closed then this setting will be forgotten.">
<!-- LOCALIZATION NOTE (options.selectDefaultTools.label): This is the label for
- the heading of group of checkboxes corresponding to the default developer
- tools. -->

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

@ -556,6 +556,23 @@ DebuggerClient.prototype = {
this.request(packet, aOnResponse);
},
/**
* Reconfigure a tab actor.
*
* @param object aOptions
* A dictionary object of the new options to use in the tab actor.
* @param function aOnResponse
* Called with the response packet.
*/
reconfigureTab: function(aOptions, aOnResponse) {
let packet = {
to: this.activeTab._actor,
type: "reconfigure",
options: aOptions
};
this.request(packet, aOnResponse);
},
/**
* Release an object actor.
*

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

@ -712,7 +712,12 @@ BrowserTabActor.prototype = {
this._attach();
return { type: "tabAttached", threadActor: this.threadActor.actorID };
return {
type: "tabAttached",
threadActor: this.threadActor.actorID,
cacheEnabled: this._getCacheEnabled(),
javascriptEnabled: this._getJavascriptEnabled()
};
},
onDetach: function BTA_onDetach(aRequest) {
@ -747,6 +752,99 @@ BrowserTabActor.prototype = {
return {};
},
/**
* Reconfigure options.
*/
onReconfigure: function (aRequest) {
let options = aRequest.options || {};
this._toggleJsOrCache(options);
return {};
},
/**
* Handle logic to enable/disable JS/cache.
*/
_toggleJsOrCache: function(options) {
// Wait a tick so that the response packet can be dispatched before the
// subsequent navigation event packet.
let reload = false;
if (typeof options.javascriptEnabled !== "undefined" &&
options.javascriptEnabled !== this._getJavascriptEnabled()) {
this._setJavascriptEnabled(options.javascriptEnabled);
reload = true;
}
if (typeof options.cacheEnabled !== "undefined" &&
options.cacheEnabled !== this._getCacheEnabled()) {
this._setCacheEnabled(options.cacheEnabled);
reload = true;
}
if (reload) {
this.onReload();
}
},
/**
* Disable or enable the cache via docShell.
*/
_setCacheEnabled: function(allow) {
let enable = Ci.nsIRequest.LOAD_NORMAL;
let disable = Ci.nsIRequest.LOAD_BYPASS_CACHE |
Ci.nsIRequest.INHIBIT_CACHING;
let docShell = this.window
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell);
docShell.defaultLoadFlags = allow ? enable : disable;
},
/**
* Disable or enable JS via docShell.
*/
_setJavascriptEnabled: function(allow) {
let docShell = this.window
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell);
docShell.allowJavascript = allow;
},
/**
* Return cache allowed status.
*/
_getCacheEnabled: function() {
if (!this.window) {
// The tab is already closed.
return null;
}
let disable = Ci.nsIRequest.LOAD_BYPASS_CACHE |
Ci.nsIRequest.INHIBIT_CACHING;
let docShell = this.window
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell);
return docShell.defaultLoadFlags !== disable;
},
/**
* Return JS allowed status.
*/
_getJavascriptEnabled: function() {
if (!this.window) {
// The tab is already closed.
return null;
}
let docShell = this.window
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell);
return docShell.allowJavascript;
},
/**
* Prepare to enter a nested event loop by disabling debuggee events.
*/
@ -838,7 +936,8 @@ BrowserTabActor.prototype.requestTypes = {
"attach": BrowserTabActor.prototype.onAttach,
"detach": BrowserTabActor.prototype.onDetach,
"reload": BrowserTabActor.prototype.onReload,
"navigateTo": BrowserTabActor.prototype.onNavigateTo
"navigateTo": BrowserTabActor.prototype.onNavigateTo,
"reconfigure": BrowserTabActor.prototype.onReconfigure
};
function BrowserAddonList(aConnection)