Backed out changeset 786d44e03d8b (bug 957592) for static rooting hazard bustage on a CLOSED TREE

This commit is contained in:
Carsten "Tomcat" Book 2014-01-23 14:22:24 +01:00
parent 2a23bd8b96
commit 051714c230
9 changed files with 42 additions and 92 deletions

View File

@ -864,6 +864,9 @@ pref("media.webspeech.synth.enabled", true);
pref("dom.mozDownloads.enabled", true);
pref("dom.downloads.max_retention_days", 7);
// Downloads API
pref("dom.mozDownloads.enabled", true);
// Inactivity time in milliseconds after which we shut down the OS.File worker.
pref("osfile.reset_worker_delay", 5000);

View File

@ -1539,6 +1539,13 @@ Navigator::DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObject,
}
}
if (name.EqualsLiteral("mozDownloadManager")) {
if (!CheckPermission("downloads")) {
FillPropertyDescriptor(aDesc, aObject, JS::NullValue(), false);
return true;
}
}
domObject = construct(aCx, naviObj);
if (!domObject) {
return Throw(aCx, NS_ERROR_FAILURE);
@ -1907,23 +1914,6 @@ Navigator::HasDataStoreSupport(JSContext* cx, JSObject* aGlobal)
return status == nsIPrincipal::APP_STATUS_CERTIFIED;
}
/* static */
bool
Navigator::HasDownloadsSupport(JSContext* aCx, JSObject* aGlobal)
{
// Because of the way this API must be implemented, it will interact with
// objects attached to a chrome window. We always want to allow this.
if (ThreadsafeCheckIsChrome(aCx, aGlobal)) {
return true;
}
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
return win &&
CheckPermission(win, "downloads") &&
Preferences::GetBool("dom.mozDownloads.enabled");
}
/* static */
already_AddRefed<nsPIDOMWindow>
Navigator::GetWindowFromGlobal(JSObject* aGlobal)

View File

@ -290,8 +290,6 @@ public:
static bool HasDataStoreSupport(JSContext* cx, JSObject* aGlobal);
static bool HasDownloadsSupport(JSContext* aCx, JSObject* aGlobal);
nsPIDOMWindow* GetParentObject() const
{
return GetWindow();

View File

@ -206,12 +206,12 @@ function DOMDownloadImpl() {
this.currentBytes = 0;
this.url = null;
this.path = null;
this.state = "stopped";
this.contentType = null;
/* fields that require getters/setters */
this._error = null;
this._startTime = new Date();
this._state = "stopped";
/* private fields */
this.id = null;
@ -270,25 +270,6 @@ DOMDownloadImpl.prototype = {
}
},
get state() {
return this._state;
},
// We require a setter here to simplify the internals of the Download Manager
// since we actually pass dummy JSON objects to the child process and update
// them. This is the case for all other setters for read-only attributes
// implemented in this object.
set state(aState) {
// We need to ensure that XPCOM consumers of this API respect the enum
// values as well.
if (["downloading",
"stopped",
"succeeded",
"finalized"].indexOf(aState) != -1) {
this._state = aState;
}
},
_init: function(aWindow, aDownload) {
this._window = aWindow;
this.id = aDownload.id;

View File

@ -9,6 +9,9 @@ function getQuery(request) {
return query;
}
// Timer used to handle the request response.
var timer = null;
function handleResponse() {
// Is this a rate limited response?
if (this.state.rate > 0) {
@ -23,24 +26,7 @@ function handleResponse() {
(bytesToWrite > this.state.rate) ? this.state.rate : bytesToWrite;
for (let i = 0; i < bytesToWrite; i++) {
try {
this.response.bodyOutputStream.write("0", 1);
} catch (e) {
// Connection was closed by client.
if (e == Components.results.NS_ERROR_NOT_AVAILABLE) {
// There's no harm in calling this multiple times.
this.response.finish();
// It's possible that our timer wasn't cancelled in time
// and we'll be called again.
if (this.timer) {
this.timer.cancel();
this.timer = null;
}
return;
}
}
this.response.write("0");
}
// Update the number of bytes we've sent to the client.
@ -61,19 +47,12 @@ function handleResponse() {
this.response.finish();
// All done sending, go ahead and cancel our repeating timer.
this.timer.cancel();
// Clear the timer.
this.timer = null;
timer.cancel();
}
function handleRequest(request, response) {
var query = getQuery(request);
// sending at a specific rate requires our response to be asynchronous so
// we handle all requests asynchronously. See handleResponse().
response.processAsync();
// Default status when responding.
var version = "1.1";
var statusCode = 200;
@ -141,17 +120,20 @@ function handleRequest(request, response) {
totalBytes: size,
sentBytes: 0,
rate: rate
},
timer: null
}
};
// The notify implementation for the timer.
context.notify = handleResponse.bind(context);
context.timer =
timer =
Components.classes["@mozilla.org/timer;1"]
.createInstance(Components.interfaces.nsITimer);
// sending at a specific rate requires our response to be asynchronous so
// we handle all requests asynchronously. See handleResponse().
response.processAsync();
// generate the content.
response.setStatusLine(version, statusCode, description);
response.setHeader("Content-Type", contentType, false);
@ -161,10 +143,8 @@ function handleRequest(request, response) {
response.setHeader("Content-Length", size.toString(), false);
// initialize the timer and start writing out the response.
context.timer.initWithCallback(
context,
1000,
Components.interfaces.nsITimer.TYPE_REPEATING_SLACK
);
timer.initWithCallback(context,
1000,
Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
}

View File

@ -48,7 +48,7 @@ var steps = [
SpecialPowers.pushPermissions([
{type: "downloads", allow: 0, context: document}
], function() {
ise(frames[0].navigator.mozDownloadManager, undefined, "navigator.mozDownloadManager is undefined when the page doesn't have permissions");
ise(frames[0].navigator.mozDownloadManager, null, "navigator.mozDownloadManager is null when the page doesn't have permissions");
next();
});
},

View File

@ -326,6 +326,12 @@ var interfaceNamesInGlobalScope =
"DOMTokenList",
// IMPORTANT: Do not change this list without review from a DOM peer!
"DOMTransactionEvent",
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "DOMDownload", b2g: true, pref: "dom.mozDownloads.enabled"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "DOMDownloadManager", b2g: true, pref: "dom.mozDownloads.enabled"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "DownloadEvent", b2g: true, pref: "dom.mozDownloads.enabled"},
// IMPORTANT: Do not change this list without review from a DOM peer!
"DragEvent",
// IMPORTANT: Do not change this list without review from a DOM peer!

View File

@ -5,7 +5,7 @@
*/
[Constructor(DOMString type, optional DownloadEventInit eventInitDict),
Func="Navigator::HasDownloadsSupport"]
Pref="dom.mozDownloads.enabled"]
interface DownloadEvent : Event
{
readonly attribute DOMDownload? download;

View File

@ -4,22 +4,9 @@
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Represents the state of a download.
// "downloading": The resource is actively transfering.
// "stopped" : No network tranfer is happening.
// "succeeded" : The resource has been downloaded successfully.
// "finalized" : We won't try to download this resource, but the DOM
// object is still alive.
enum DownloadState {
"downloading",
"stopped",
"succeeded",
"finalized"
};
[NavigatorProperty="mozDownloadManager",
JSImplementation="@mozilla.org/downloads/manager;1",
Func="Navigator::HasDownloadsSupport"]
Pref="dom.mozDownloads.enabled"]
interface DOMDownloadManager : EventTarget {
// This promise returns an array of downloads with all the current
// download objects.
@ -37,7 +24,7 @@ interface DOMDownloadManager : EventTarget {
};
[JSImplementation="@mozilla.org/downloads/download;1",
Func="Navigator::HasDownloadsSupport"]
Pref="dom.mozDownloads.enabled"]
interface DOMDownload : EventTarget {
// The full size of the resource.
readonly attribute long totalBytes;
@ -52,8 +39,13 @@ interface DOMDownload : EventTarget {
// is complete.
readonly attribute DOMString path;
// The state of the download.
readonly attribute DownloadState state;
// The state of the download. Can be any of:
// "downloading": The resource is actively transfering.
// "stopped" : No network tranfer is happening.
// "succeeded" : The resource has been downloaded successfully.
// "finalized" : We won't try to download this resource, but the DOM
// object is still alive.
readonly attribute DOMString state;
// The mime type for this resource.
readonly attribute DOMString contentType;