diff --git a/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/remote-experiment-loader.js b/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/remote-experiment-loader.js index b736dad1ebf..0599d4a0a02 100644 --- a/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/remote-experiment-loader.js +++ b/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/remote-experiment-loader.js @@ -132,7 +132,7 @@ function downloadFile(url, cb, lastModified) { console.info("Using binary mode to download jar file."); req.overrideMimeType('text/plain; charset=x-user-defined'); } - req.onreadystatechange = function(aEvt) { + req.addEventListener("readystatechange", function(aEvt) { if (req.readyState == 4) { if (req.status == 200) { // check security channel: @@ -154,7 +154,7 @@ function downloadFile(url, cb, lastModified) { cb(null); } } - }; + }, false); req.send(); } diff --git a/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js b/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js index cb6775ac388..684948a41bd 100644 --- a/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js +++ b/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js @@ -846,7 +846,7 @@ TestPilotExperiment.prototype = { req.setRequestHeader("Content-type", "application/json"); req.setRequestHeader("Content-length", dataString.length); req.setRequestHeader("Connection", "close"); - req.onreadystatechange = function(aEvt) { + req.addEventListener("readystatechange", function(aEvt) { if (req.readyState == 4) { if (req.status == 200 || req.status == 201 || req.status == 202) { let location = req.getResponseHeader("Location"); @@ -887,7 +887,7 @@ TestPilotExperiment.prototype = { callback(false); } } - }; + }, false); req.send(dataString); }); }, @@ -919,7 +919,7 @@ TestPilotExperiment.prototype = { req.setRequestHeader("Content-type", "application/json"); req.setRequestHeader("Content-length", dataString.length); req.setRequestHeader("Connection", "close"); - req.onreadystatechange = function(aEvt) { + req.addEventListener("readystatechange", function(aEvt) { if (req.readyState == 4) { if (req.status == 200 || req.status == 201 || req.status == 202) { logger.info("Quit reason posted successfully " + req.responseText); @@ -933,7 +933,7 @@ TestPilotExperiment.prototype = { } } } - }; + }, false); logger.trace("Sending quit reason."); req.send(dataString); } else { @@ -1069,7 +1069,7 @@ TestPilotBuiltinSurvey.prototype = { req.setRequestHeader("Content-type", "application/json"); req.setRequestHeader("Content-length", params.length); req.setRequestHeader("Connection", "close"); - req.onreadystatechange = function(aEvt) { + req.addEventListener("readystatechange", function(aEvt) { if (req.readyState == 4) { if (req.status == 200 || req.status == 201 || req.status == 202) { @@ -1099,7 +1099,7 @@ TestPilotBuiltinSurvey.prototype = { callback(false); } } - }; + }, false); req.send(params); }); } diff --git a/build/win32/crashinject.cpp b/build/win32/crashinject.cpp index 10e64273016..cc089735383 100644 --- a/build/win32/crashinject.cpp +++ b/build/win32/crashinject.cpp @@ -71,7 +71,7 @@ int main(int argc, char** argv) wcscpy(slash, L"crashinjectdll.dll"); // now find our target process - HANDLE targetProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, + HANDLE targetProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION, FALSE, pid); if (targetProc == NULL) { diff --git a/content/base/public/nsDOMEventTargetWrapperCache.h b/content/base/public/nsDOMEventTargetWrapperCache.h index 00bbd68c504..7749fc2cfde 100644 --- a/content/base/public/nsDOMEventTargetWrapperCache.h +++ b/content/base/public/nsDOMEventTargetWrapperCache.h @@ -86,9 +86,60 @@ public: return static_cast(target); } + void Init(JSContext* aCx = nsnull); + protected: nsDOMEventTargetWrapperCache() : nsDOMEventTargetHelper(), nsWrapperCache() {} virtual ~nsDOMEventTargetWrapperCache(); }; +#define NS_DECL_EVENT_HANDLER(_event) \ + public: \ + NS_IMETHOD GetOn##_event(JSContext *cx, jsval *vp); \ + NS_IMETHOD SetOn##_event(JSContext *cx, const jsval &vp); + +#define NS_DECL_AND_IMPL_EVENT_HANDLER(_event) \ + public: \ + NS_IMPL_EVENT_HANDLER(_class, _event) + +#define NS_IMPL_EVENT_HANDLER(_class, _event) \ + NS_IMETHODIMP \ + _class::GetOn##_event(JSContext *cx, jsval *vp) \ + { \ + nsEventListenerManager* elm = GetListenerManager(PR_FALSE); \ + if (elm) { \ + elm->GetJSEventListener(nsGkAtoms::on##_event, vp); \ + } else { \ + *vp = JSVAL_NULL; \ + } \ + return NS_OK; \ + } \ + NS_IMETHODIMP \ + _class::SetOn##_event(JSContext *cx, const jsval &vp) \ + { \ + nsEventListenerManager* elm = GetListenerManager(PR_TRUE); \ + if (!elm) { \ + return NS_ERROR_OUT_OF_MEMORY; \ + } \ + \ + JSObject *obj = GetWrapper(); \ + if (!obj) { \ + /* Just silently do nothing */ \ + return NS_OK; \ + } \ + return elm->SetJSEventListenerToJsval(nsGkAtoms::on##_event, cx, obj, vp);\ + } + +#define NS_IMPL_FORWARD_EVENT_HANDLER(_class, _event, _baseclass) \ + NS_IMETHODIMP \ + _class::GetOn##_event(JSContext *cx, jsval *vp) \ + { \ + return _baseclass::GetOn##_event(cx, vp); \ + } \ + NS_IMETHODIMP \ + _class::SetOn##_event(JSContext *cx, const jsval &vp) \ + { \ + return _baseclass::SetOn##_event(cx, vp); \ + } + #endif // nsDOMEventTargetWrapperCache_h__ diff --git a/content/base/public/nsIDOMFileReader.idl b/content/base/public/nsIDOMFileReader.idl index d7b20a75ead..7ce2447972a 100644 --- a/content/base/public/nsIDOMFileReader.idl +++ b/content/base/public/nsIDOMFileReader.idl @@ -41,8 +41,8 @@ interface nsIDOMEventListener; interface nsIDOMBlob; interface nsIDOMFileError; -[scriptable, uuid(3d77e784-1459-4206-b8a2-0855d826f569)] -interface nsIDOMFileReader : nsISupports +[scriptable, builtinclass, uuid(57d68e17-85fa-4509-bf71-ffac1b22a174)] +interface nsIDOMFileReader : nsIDOMEventTarget { [implicit_jscontext] void readAsArrayBuffer(in nsIDOMBlob filedata); @@ -60,6 +60,13 @@ interface nsIDOMFileReader : nsISupports [implicit_jscontext] readonly attribute jsval result; readonly attribute nsIDOMFileError error; + + [implicit_jscontext] attribute jsval onloadstart; + [implicit_jscontext] attribute jsval onprogress; + [implicit_jscontext] attribute jsval onload; + [implicit_jscontext] attribute jsval onabort; + [implicit_jscontext] attribute jsval onerror; + [implicit_jscontext] attribute jsval onloadend; }; %{ C++ diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index e41d1c4f3ae..75e1288f2bd 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -527,13 +527,8 @@ public: /** * Return the root element for this document. */ - Element *GetRootElement() const - { - return (mCachedRootElement && - mCachedRootElement->GetNodeParent() == this) ? - reinterpret_cast(mCachedRootElement.get()) : - GetRootElementInternal(); - } + Element *GetRootElement() const; + protected: virtual Element *GetRootElementInternal() const = 0; @@ -1644,9 +1639,7 @@ protected: nsIDocument* mParentDocument; // A reference to the element last returned from GetRootElement(). - // This should be an Element, but that would force us to pull in - // Element.h and therefore nsIContent.h. - nsCOMPtr mCachedRootElement; + mozilla::dom::Element* mCachedRootElement; // We'd like these to be nsRefPtrs, but that'd require us to include // additional headers that we don't want to expose. diff --git a/content/base/public/nsIEventSource.idl b/content/base/public/nsIEventSource.idl index c9512c30209..72287a67b8e 100644 --- a/content/base/public/nsIEventSource.idl +++ b/content/base/public/nsIEventSource.idl @@ -51,7 +51,7 @@ interface nsIPrincipal; interface nsIScriptContext; interface nsPIDOMWindow; -[scriptable, uuid(755e2d2d-a836-4539-83f4-16b51156341f)] +[scriptable, uuid(741374e9-39ed-4712-a380-93e023b271f8)] interface nsIEventSource : nsISupports { readonly attribute DOMString url; @@ -63,9 +63,9 @@ interface nsIEventSource : nsISupports readonly attribute long readyState; // event handler attributes - attribute nsIDOMEventListener onopen; - attribute nsIDOMEventListener onmessage; - attribute nsIDOMEventListener onerror; + [implicit_jscontext] attribute jsval onopen; + [implicit_jscontext] attribute jsval onmessage; + [implicit_jscontext] attribute jsval onerror; /** * Close the connection, if any, and set the readyState attribute to CLOSED. diff --git a/content/base/public/nsIXMLHttpRequest.idl b/content/base/public/nsIXMLHttpRequest.idl index cf4bfebba2c..c390a3b6400 100644 --- a/content/base/public/nsIXMLHttpRequest.idl +++ b/content/base/public/nsIXMLHttpRequest.idl @@ -53,18 +53,18 @@ interface nsIDOMBlob; #include "jsapi.h" %} -[scriptable, builtinclass, uuid(dea238a1-240f-45f4-9f07-7769bc69eb76)] +[scriptable, builtinclass, uuid(8bc1357c-fe70-4741-a170-8fa50b6d23be)] interface nsIXMLHttpRequestEventTarget : nsIDOMEventTarget { // event handler attributes - attribute nsIDOMEventListener onabort; - attribute nsIDOMEventListener onerror; - attribute nsIDOMEventListener onload; - attribute nsIDOMEventListener onloadstart; - attribute nsIDOMEventListener onprogress; - attribute nsIDOMEventListener onloadend; + [implicit_jscontext] attribute jsval onabort; + [implicit_jscontext] attribute jsval onerror; + [implicit_jscontext] attribute jsval onload; + [implicit_jscontext] attribute jsval onloadstart; + [implicit_jscontext] attribute jsval onprogress; + [implicit_jscontext] attribute jsval onloadend; }; -[scriptable, builtinclass, uuid(09ff3682-7759-4441-a765-f70e1a1fabcf)] +[scriptable, builtinclass, uuid(cfa2d9fc-1871-444c-aaf9-8fc7fc7261d8)] interface nsIXMLHttpRequestUpload : nsIXMLHttpRequestEventTarget { // for future use }; @@ -110,7 +110,7 @@ interface nsIXMLHttpRequestUpload : nsIXMLHttpRequestEventTarget { * you're aware of all the security implications. And then think twice about * it. */ -[scriptable, uuid(5cf8d518-51d0-4cd6-a69a-c3674c2de599)] +[scriptable, uuid(10d4701f-6351-4e9b-addd-ffdba05bd425)] interface nsIXMLHttpRequest : nsISupports { /** @@ -374,7 +374,7 @@ interface nsIXMLHttpRequest : nsISupports * * Call open() before setting an onreadystatechange listener. */ - attribute nsIDOMEventListener onreadystatechange; + [implicit_jscontext] attribute jsval onreadystatechange; }; [scriptable, uuid(840d0d00-e83e-4a29-b3c7-67e96e90a499)] @@ -387,7 +387,7 @@ interface nsIXHRSendable : nsISupports { /** * @deprecated */ -[deprecated, scriptable, uuid(423fdd3d-41c9-4149-8fe5-b14a1d3912a0)] +[deprecated, scriptable, uuid(58d2c633-2efd-45be-80ed-511dcd0407cc)] interface nsIJSXMLHttpRequest : nsISupports { /** * Meant to be a script-only mechanism for setting an upload progress event @@ -402,7 +402,7 @@ interface nsIJSXMLHttpRequest : nsISupports { * * Mozilla only. */ - attribute nsIDOMEventListener onuploadprogress; + [implicit_jscontext] attribute jsval onuploadprogress; }; %{ C++ diff --git a/content/base/src/FileIOObject.cpp b/content/base/src/FileIOObject.cpp new file mode 100644 index 00000000000..cceed6a9935 --- /dev/null +++ b/content/base/src/FileIOObject.cpp @@ -0,0 +1,300 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozila.org code. + * + * The Initial Developer of the Original Code is the Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Kyle Huey + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "FileIOObject.h" +#include "nsDOMFile.h" +#include "nsDOMError.h" +#include "nsIPrivateDOMEvent.h" +#include "nsIDOMEvent.h" +#include "nsIDOMProgressEvent.h" +#include "nsComponentManagerUtils.h" +#include "nsEventDispatcher.h" +#include "nsGkAtoms.h" +#include "xpcprivate.h" + +#define ERROR_STR "error" +#define ABORT_STR "abort" +#define PROGRESS_STR "progress" + +namespace mozilla { +namespace dom { + +const PRUint64 kUnknownSize = PRUint64(-1); + +NS_IMPL_ADDREF_INHERITED(FileIOObject, nsDOMEventTargetWrapperCache) +NS_IMPL_RELEASE_INHERITED(FileIOObject, nsDOMEventTargetWrapperCache) + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FileIOObject) + NS_INTERFACE_MAP_ENTRY(nsITimerCallback) + NS_INTERFACE_MAP_ENTRY(nsIStreamListener) + NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) +NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetWrapperCache) + +NS_IMPL_CYCLE_COLLECTION_CLASS(FileIOObject) + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(FileIOObject, + nsDOMEventTargetWrapperCache) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mProgressNotifier) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(FileIOObject, + nsDOMEventTargetWrapperCache) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mProgressNotifier) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_EVENT_HANDLER(FileIOObject, abort) +NS_IMPL_EVENT_HANDLER(FileIOObject, error) +NS_IMPL_EVENT_HANDLER(FileIOObject, progress) + +FileIOObject::FileIOObject() + : mProgressEventWasDelayed(PR_FALSE), + mTimerIsActive(PR_FALSE), + mReadyState(0), + mTotal(0), mTransferred(0) +{} + +FileIOObject::~FileIOObject() +{ + if (mListenerManager) + mListenerManager->Disconnect(); +} + +void +FileIOObject::StartProgressEventTimer() +{ + if (!mProgressNotifier) { + mProgressNotifier = do_CreateInstance(NS_TIMER_CONTRACTID); + } + if (mProgressNotifier) { + mProgressEventWasDelayed = PR_FALSE; + mTimerIsActive = PR_TRUE; + mProgressNotifier->Cancel(); + mProgressNotifier->InitWithCallback(this, NS_PROGRESS_EVENT_INTERVAL, + nsITimer::TYPE_ONE_SHOT); + } +} + +void +FileIOObject::ClearProgressEventTimer() +{ + mProgressEventWasDelayed = PR_FALSE; + mTimerIsActive = PR_FALSE; + if (mProgressNotifier) { + mProgressNotifier->Cancel(); + } +} + +void +FileIOObject::DispatchError(nsresult rv, nsAString& finalEvent) +{ + // Set the status attribute, and dispatch the error event + switch (rv) { + case NS_ERROR_FILE_NOT_FOUND: + mError = new nsDOMFileError(nsIDOMFileError::NOT_FOUND_ERR); + break; + case NS_ERROR_FILE_ACCESS_DENIED: + mError = new nsDOMFileError(nsIDOMFileError::SECURITY_ERR); + break; + default: + mError = new nsDOMFileError(nsIDOMFileError::NOT_READABLE_ERR); + break; + } + + // Dispatch error event to signify load failure + DispatchProgressEvent(NS_LITERAL_STRING(ERROR_STR)); + DispatchProgressEvent(finalEvent); +} + +nsresult +FileIOObject::DispatchProgressEvent(const nsAString& aType) +{ + nsCOMPtr event; + nsresult rv = nsEventDispatcher::CreateEvent(nsnull, nsnull, + NS_LITERAL_STRING("ProgressEvent"), + getter_AddRefs(event)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr privevent(do_QueryInterface(event)); + NS_ENSURE_TRUE(privevent, NS_ERROR_UNEXPECTED); + + privevent->SetTrusted(PR_TRUE); + nsCOMPtr progress = do_QueryInterface(event); + NS_ENSURE_TRUE(progress, NS_ERROR_UNEXPECTED); + + bool known; + PRUint64 size; + if (mTotal != kUnknownSize) { + known = PR_TRUE; + size = mTotal; + } else { + known = PR_FALSE; + size = 0; + } + rv = progress->InitProgressEvent(aType, PR_FALSE, PR_FALSE, known, + mTransferred, size); + NS_ENSURE_SUCCESS(rv, rv); + + return DispatchDOMEvent(nsnull, event, nsnull, nsnull); +} + +// nsITimerCallback +NS_IMETHODIMP +FileIOObject::Notify(nsITimer* aTimer) +{ + nsresult rv; + mTimerIsActive = PR_FALSE; + + if (mProgressEventWasDelayed) { + rv = DispatchProgressEvent(NS_LITERAL_STRING("progress")); + NS_ENSURE_SUCCESS(rv, rv); + + StartProgressEventTimer(); + } + + return NS_OK; +} + +// nsIStreamListener +NS_IMETHODIMP +FileIOObject::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext) +{ + return DoOnStartRequest(aRequest, aContext); +} + +NS_IMETHODIMP +FileIOObject::DoOnStartRequest(nsIRequest *request, nsISupports *ctxt) +{ + return NS_OK; +} + +NS_IMETHODIMP +FileIOObject::OnDataAvailable(nsIRequest *aRequest, + nsISupports *aContext, + nsIInputStream *aInputStream, + PRUint32 aOffset, + PRUint32 aCount) +{ + nsresult rv; + rv = DoOnDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount); + NS_ENSURE_SUCCESS(rv, rv); + + mTransferred += aCount; + + //Notify the timer is the appropriate timeframe has passed + if (mTimerIsActive) { + mProgressEventWasDelayed = PR_TRUE; + } else { + rv = DispatchProgressEvent(NS_LITERAL_STRING(PROGRESS_STR)); + NS_ENSURE_SUCCESS(rv, rv); + + StartProgressEventTimer(); + } + + return NS_OK; +} + +NS_IMETHODIMP +FileIOObject::OnStopRequest(nsIRequest* aRequest, nsISupports* aContext, + nsresult aStatus) +{ + // If we're here as a result of a call from Abort(), + // simply ignore the request. + if (aRequest != mChannel) + return NS_OK; + + // Cancel the progress event timer + ClearProgressEventTimer(); + + // FileIOObject must be in DONE stage after an operation + mReadyState = 2; + + nsString successEvent, termEvent; + nsresult rv = DoOnStopRequest(aRequest, aContext, aStatus, + successEvent, termEvent); + NS_ENSURE_SUCCESS(rv, rv); + + // Set the status field as appropriate + if (NS_FAILED(aStatus)) { + DispatchError(aStatus, termEvent); + return NS_OK; + } + + // Dispatch event to signify end of a successful operation + DispatchProgressEvent(successEvent); + DispatchProgressEvent(termEvent); + + return NS_OK; +} + +NS_IMETHODIMP +FileIOObject::Abort() +{ + if (mReadyState != 1) + return NS_ERROR_DOM_FILE_ABORT_ERR; + + ClearProgressEventTimer(); + + mReadyState = 2; // There are DONE constants on multiple interfaces, + // but they all have value 2. + mError = new nsDOMFileError(nsIDOMFileError::ABORT_ERR); + + nsString finalEvent; + nsresult rv = DoAbort(finalEvent); + + // Dispatch the events + DispatchProgressEvent(NS_LITERAL_STRING(ABORT_STR)); + DispatchProgressEvent(finalEvent); + + return rv; +} + +NS_IMETHODIMP +FileIOObject::GetReadyState(PRUint16 *aReadyState) +{ + *aReadyState = mReadyState; + return NS_OK; +} + +NS_IMETHODIMP +FileIOObject::GetError(nsIDOMFileError** aError) +{ + NS_IF_ADDREF(*aError = mError); + return NS_OK; +} + +} // namespace dom +} // namespace mozilla diff --git a/content/base/src/FileIOObject.h b/content/base/src/FileIOObject.h new file mode 100644 index 00000000000..13e75af27f7 --- /dev/null +++ b/content/base/src/FileIOObject.h @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozila.org code. + * + * The Initial Developer of the Original Code is the Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Kyle Huey + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef FileIOObject_h__ +#define FileIOObject_h__ + +#include "nsIDOMEventTarget.h" +#include "nsDOMEventTargetWrapperCache.h" +#include "nsIChannel.h" +#include "nsIFile.h" +#include "nsIDOMFile.h" +#include "nsIStreamListener.h" +#include "nsITimer.h" + +#include "nsCOMPtr.h" + +#define NS_PROGRESS_EVENT_INTERVAL 50 + +namespace mozilla { +namespace dom { + +extern const PRUint64 kUnknownSize; + +// A common base class for FileReader and FileSaver + +class FileIOObject : public nsDOMEventTargetWrapperCache, + public nsIStreamListener, + public nsITimerCallback +{ +public: + FileIOObject(); + ~FileIOObject(); + + NS_DECL_ISUPPORTS_INHERITED + + // Common methods + NS_METHOD Abort(); + NS_METHOD GetReadyState(PRUint16* aReadyState); + NS_METHOD GetError(nsIDOMFileError** aError); + + NS_DECL_EVENT_HANDLER(abort); + NS_DECL_EVENT_HANDLER(error); + NS_DECL_EVENT_HANDLER(progress); + + NS_DECL_NSITIMERCALLBACK + + NS_DECL_NSISTREAMLISTENER + + NS_DECL_NSIREQUESTOBSERVER + + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileIOObject, + nsDOMEventTargetWrapperCache) + +protected: + // Implemented by the derived class to do whatever it needs to do for abort + NS_IMETHOD DoAbort(nsAString& aEvent) = 0; + // for onStartRequest (this has a default impl since FileReader doesn't need + // special handling + NS_IMETHOD DoOnStartRequest(nsIRequest *aRequest, nsISupports *aContext); + // for onStopRequest + NS_IMETHOD DoOnStopRequest(nsIRequest *aRequest, nsISupports *aContext, + nsresult aStatus, nsAString& aSuccessEvent, + nsAString& aTerminationEvent) = 0; + // and for onDataAvailable + NS_IMETHOD DoOnDataAvailable(nsIRequest *aRequest, nsISupports *aContext, + nsIInputStream *aInputStream, PRUint32 aOffset, + PRUint32 aCount) = 0; + + void StartProgressEventTimer(); + void ClearProgressEventTimer(); + void DispatchError(nsresult rv, nsAString& finalEvent); + nsresult DispatchProgressEvent(const nsAString& aType); + + nsCOMPtr mProgressNotifier; + bool mProgressEventWasDelayed; + bool mTimerIsActive; + + nsCOMPtr mError; + nsCOMPtr mChannel; + + PRUint16 mReadyState; + + PRUint64 mTotal; + PRUint64 mTransferred; +}; + +} // namespace dom +} // namespace mozilla + +#endif diff --git a/content/base/src/Makefile.in b/content/base/src/Makefile.in index 127b2ae70bb..850f3c6951d 100644 --- a/content/base/src/Makefile.in +++ b/content/base/src/Makefile.in @@ -155,6 +155,7 @@ CPPSRCS = \ nsInProcessTabChildGlobal.cpp \ ThirdPartyUtil.cpp \ nsEventSource.cpp \ + FileIOObject.cpp \ $(NULL) # Are we targeting x86-32 or x86-64? If so, we want to include SSE2 code for diff --git a/content/base/src/nsDOMEventTargetWrapperCache.cpp b/content/base/src/nsDOMEventTargetWrapperCache.cpp index 94834eb783b..3290c22cab0 100644 --- a/content/base/src/nsDOMEventTargetWrapperCache.cpp +++ b/content/base/src/nsDOMEventTargetWrapperCache.cpp @@ -40,6 +40,9 @@ #include "nsContentUtils.h" #include "nsDOMEventTargetWrapperCache.h" #include "nsIDocument.h" +#include "nsIJSContextStack.h" +#include "nsServiceManagerUtils.h" +#include "nsDOMJSUtils.h" nsDOMEventTargetWrapperCache::~nsDOMEventTargetWrapperCache() { @@ -69,3 +72,29 @@ NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper) NS_IMPL_ADDREF_INHERITED(nsDOMEventTargetWrapperCache, nsDOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(nsDOMEventTargetWrapperCache, nsDOMEventTargetHelper) + +void +nsDOMEventTargetWrapperCache::Init(JSContext* aCx) +{ + // Set the original mScriptContext and mPrincipal, if available + JSContext* cx = aCx; + if (!cx) { + nsIJSContextStack* stack = nsContentUtils::ThreadJSContextStack(); + + if (!stack) + return; + + if (NS_FAILED(stack->Peek(&cx)) || !cx) + return; + } + + NS_ASSERTION(cx, "Should have returned earlier ..."); + nsIScriptContext* context = GetScriptContextFromJSContext(cx); + if (context) { + mScriptContext = context; + nsCOMPtr window = + do_QueryInterface(context->GetGlobalObject()); + if (window) + mOwner = window->GetCurrentInnerWindow(); + } +} diff --git a/content/base/src/nsDOMFileReader.cpp b/content/base/src/nsDOMFileReader.cpp index 5584bc421b0..149fb8afcdc 100644 --- a/content/base/src/nsDOMFileReader.cpp +++ b/content/base/src/nsDOMFileReader.cpp @@ -72,51 +72,43 @@ #include "nsIDOMClassInfo.h" #include "nsCExternalHandlerService.h" #include "nsIStreamConverterService.h" -#include "nsEventDispatcher.h" #include "nsCycleCollectionParticipant.h" #include "nsLayoutStatics.h" #include "nsIScriptObjectPrincipal.h" #include "nsFileDataProtocolHandler.h" #include "mozilla/Preferences.h" -#include "xpcprivate.h" +#include "xpcprivate.h" +#include "xpcpublic.h" #include "xpcquickstubs.h" #include "jstypedarray.h" using namespace mozilla; #define LOAD_STR "load" -#define ERROR_STR "error" -#define ABORT_STR "abort" #define LOADSTART_STR "loadstart" -#define PROGRESS_STR "progress" -#define UPLOADPROGRESS_STR "uploadprogress" #define LOADEND_STR "loadend" -#define NS_PROGRESS_EVENT_INTERVAL 50 -const PRUint64 kUnknownSize = PRUint64(-1); +using mozilla::dom::FileIOObject; NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMFileReader) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMFileReader, - nsXHREventTarget) + FileIOObject) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFile) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mProgressNotifier) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPrincipal) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChannel) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMFileReader, - nsXHREventTarget) + FileIOObject) tmp->mResultArrayBuffer = nsnull; NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFile) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mProgressNotifier) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPrincipal) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mChannel) NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(nsDOMFileReader, - nsXHREventTarget) + nsDOMEventTargetWrapperCache) if(tmp->mResultArrayBuffer) { NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->mResultArrayBuffer, "mResultArrayBuffer") @@ -127,17 +119,15 @@ DOMCI_DATA(FileReader, nsDOMFileReader) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMFileReader) NS_INTERFACE_MAP_ENTRY(nsIDOMFileReader) - NS_INTERFACE_MAP_ENTRY(nsIStreamListener) NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer) - NS_INTERFACE_MAP_ENTRY(nsITimerCallback) NS_INTERFACE_MAP_ENTRY(nsICharsetDetectionObserver) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(FileReader) -NS_INTERFACE_MAP_END_INHERITING(nsXHREventTarget) +NS_INTERFACE_MAP_END_INHERITING(FileIOObject) -NS_IMPL_ADDREF_INHERITED(nsDOMFileReader, nsXHREventTarget) -NS_IMPL_RELEASE_INHERITED(nsDOMFileReader, nsXHREventTarget) +NS_IMPL_ADDREF_INHERITED(nsDOMFileReader, FileIOObject) +NS_IMPL_RELEASE_INHERITED(nsDOMFileReader, FileIOObject) void nsDOMFileReader::RootResultArrayBuffer() @@ -161,10 +151,6 @@ nsDOMFileReader::Notify(const char *aCharset, nsDetectionConfident aConf) nsDOMFileReader::nsDOMFileReader() : mFileData(nsnull), mDataLen(0), mDataFormat(FILE_AS_BINARY), - mReadyState(nsIDOMFileReader::EMPTY), - mProgressEventWasDelayed(PR_FALSE), - mTimerIsActive(PR_FALSE), - mReadTotal(0), mReadTransferred(0), mResultArrayBuffer(nsnull) { nsLayoutStatics::AddRef(); @@ -173,9 +159,6 @@ nsDOMFileReader::nsDOMFileReader() nsDOMFileReader::~nsDOMFileReader() { - if (mListenerManager) - mListenerManager->Disconnect(); - FreeFileData(); nsLayoutStatics::Release(); @@ -184,20 +167,7 @@ nsDOMFileReader::~nsDOMFileReader() nsresult nsDOMFileReader::Init() { - // Set the original mScriptContext and mPrincipal, if available. - // Get JSContext from stack. - nsCOMPtr stack = - do_GetService("@mozilla.org/js/xpc/ContextStack;1"); - - if (!stack) { - return NS_OK; - } - - JSContext *cx; - - if (NS_FAILED(stack->Peek(&cx)) || !cx) { - return NS_OK; - } + nsDOMEventTargetWrapperCache::Init(); nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager(); nsCOMPtr subjectPrincipal; @@ -206,21 +176,18 @@ nsDOMFileReader::Init() NS_ENSURE_SUCCESS(rv, rv); } NS_ENSURE_STATE(subjectPrincipal); - mPrincipal = subjectPrincipal; - - nsIScriptContext* context = GetScriptContextFromJSContext(cx); - if (context) { - mScriptContext = context; - nsCOMPtr window = - do_QueryInterface(context->GetGlobalObject()); - if (window) { - mOwner = window->GetCurrentInnerWindow(); - } - } + mPrincipal.swap(subjectPrincipal); return NS_OK; } +NS_IMPL_EVENT_HANDLER(nsDOMFileReader, load) +NS_IMPL_EVENT_HANDLER(nsDOMFileReader, loadstart) +NS_IMPL_EVENT_HANDLER(nsDOMFileReader, loadend) +NS_IMPL_FORWARD_EVENT_HANDLER(nsDOMFileReader, abort, FileIOObject) +NS_IMPL_FORWARD_EVENT_HANDLER(nsDOMFileReader, progress, FileIOObject) +NS_IMPL_FORWARD_EVENT_HANDLER(nsDOMFileReader, error, FileIOObject) + NS_IMETHODIMP nsDOMFileReader::Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj, PRUint32 argc, jsval *argv) @@ -257,8 +224,7 @@ nsDOMFileReader::GetInterface(const nsIID & aIID, void **aResult) NS_IMETHODIMP nsDOMFileReader::GetReadyState(PRUint16 *aReadyState) { - *aReadyState = mReadyState; - return NS_OK; + return FileIOObject::GetReadyState(aReadyState); } NS_IMETHODIMP @@ -284,8 +250,7 @@ nsDOMFileReader::GetResult(JSContext* aCx, jsval* aResult) NS_IMETHODIMP nsDOMFileReader::GetError(nsIDOMFileError** aError) { - NS_IF_ADDREF(*aError = mError); - return NS_OK; + return FileIOObject::GetError(aError); } NS_IMETHODIMP @@ -316,25 +281,19 @@ nsDOMFileReader::ReadAsDataURL(nsIDOMBlob* aFile) NS_IMETHODIMP nsDOMFileReader::Abort() { - if (mReadyState != nsIDOMFileReader::LOADING) - return NS_ERROR_DOM_FILE_ABORT_ERR; + return FileIOObject::Abort(); +} - //Clear progress and file data - mProgressEventWasDelayed = PR_FALSE; - mTimerIsActive = PR_FALSE; - if (mProgressNotifier) { - mProgressNotifier->Cancel(); - } - - //Revert status, result and readystate attributes +nsresult +nsDOMFileReader::DoAbort(nsAString& aEvent) +{ + // Revert status and result attributes SetDOMStringToNull(mResult); mResultArrayBuffer = nsnull; - mReadyState = nsIDOMFileReader::DONE; - mError = new nsDOMFileError(nsIDOMFileError::ABORT_ERR); - //Non-null channel indicates a read is currently active + // Non-null channel indicates a read is currently active if (mChannel) { - //Cancel request requires an error status + // Cancel request requires an error status mChannel->Cancel(NS_ERROR_FAILURE); mChannel = nsnull; } @@ -343,48 +302,8 @@ nsDOMFileReader::Abort() //Clean up memory buffer FreeFileData(); - //Dispatch the abort event - DispatchProgressEvent(NS_LITERAL_STRING(ABORT_STR)); - DispatchProgressEvent(NS_LITERAL_STRING(LOADEND_STR)); - - mReadyState = nsIDOMFileReader::EMPTY; - - return NS_OK; -} - -// nsITimerCallback -NS_IMETHODIMP -nsDOMFileReader::Notify(nsITimer* aTimer) -{ - mTimerIsActive = PR_FALSE; - if (mProgressEventWasDelayed) { - DispatchProgressEvent(NS_LITERAL_STRING(PROGRESS_STR)); - StartProgressEventTimer(); - } - - return NS_OK; -} - -void -nsDOMFileReader::StartProgressEventTimer() -{ - if (!mProgressNotifier) { - mProgressNotifier = do_CreateInstance(NS_TIMER_CONTRACTID); - } - if (mProgressNotifier) { - mProgressEventWasDelayed = PR_FALSE; - mTimerIsActive = PR_TRUE; - mProgressNotifier->Cancel(); - mProgressNotifier->InitWithCallback(this, NS_PROGRESS_EVENT_INTERVAL, - nsITimer::TYPE_ONE_SHOT); - } -} - -// nsIStreamListener - -NS_IMETHODIMP -nsDOMFileReader::OnStartRequest(nsIRequest *request, nsISupports *ctxt) -{ + // Tell the base class which event to dispatch + aEvent = NS_LITERAL_STRING(LOADEND_STR); return NS_OK; } @@ -410,12 +329,12 @@ ReadFuncBinaryString(nsIInputStream* in, return NS_OK; } -NS_IMETHODIMP -nsDOMFileReader::OnDataAvailable(nsIRequest *aRequest, - nsISupports *aContext, - nsIInputStream *aInputStream, - PRUint32 aOffset, - PRUint32 aCount) +nsresult +nsDOMFileReader::DoOnDataAvailable(nsIRequest *aRequest, + nsISupports *aContext, + nsIInputStream *aInputStream, + PRUint32 aOffset, + PRUint32 aCount) { if (mDataFormat == FILE_AS_BINARY) { //Continuously update our binary string as data comes in @@ -451,44 +370,22 @@ nsDOMFileReader::OnDataAvailable(nsIRequest *aRequest, mDataLen += aCount; } - mReadTransferred += aCount; - - //Notify the timer is the appropriate timeframe has passed - if (mTimerIsActive) { - mProgressEventWasDelayed = PR_TRUE; - } - else { - DispatchProgressEvent(NS_LITERAL_STRING(PROGRESS_STR)); - StartProgressEventTimer(); - } - return NS_OK; } -NS_IMETHODIMP -nsDOMFileReader::OnStopRequest(nsIRequest *aRequest, - nsISupports *aContext, - nsresult aStatus) +nsresult +nsDOMFileReader::DoOnStopRequest(nsIRequest *aRequest, + nsISupports *aContext, + nsresult aStatus, + nsAString& aSuccessEvent, + nsAString& aTerminationEvent) { - //If we're here as a result of a call from Abort(), - //simply ignore the request. - if (aRequest != mChannel) - return NS_OK; + aSuccessEvent = NS_LITERAL_STRING(LOAD_STR); + aTerminationEvent = NS_LITERAL_STRING(LOADEND_STR); - //Cancel the progress event timer - mProgressEventWasDelayed = PR_FALSE; - mTimerIsActive = PR_FALSE; - if (mProgressNotifier) { - mProgressNotifier->Cancel(); - } - - //FileReader must be in DONE stage after a load - mReadyState = nsIDOMFileReader::DONE; - - //Set the status field as appropriate + // Clear out the data if necessary if (NS_FAILED(aStatus)) { FreeFileData(); - DispatchError(aStatus); return NS_OK; } @@ -510,16 +407,7 @@ nsDOMFileReader::OnStopRequest(nsIRequest *aRequest, FreeFileData(); - if (NS_FAILED(rv)) { - DispatchError(rv); - return NS_OK; - } - - //Dispatch load event to signify end of a successful load - DispatchProgressEvent(NS_LITERAL_STRING(LOAD_STR)); - DispatchProgressEvent(NS_LITERAL_STRING(LOADEND_STR)); - - return NS_OK; + return rv; } // Helper methods @@ -537,8 +425,8 @@ nsDOMFileReader::ReadFileContent(JSContext* aCx, Abort(); mError = nsnull; SetDOMStringToNull(mResult); - mReadTransferred = 0; - mReadTotal = 0; + mTransferred = 0; + mTotal = 0; mReadyState = nsIDOMFileReader::EMPTY; FreeFileData(); @@ -562,8 +450,8 @@ nsDOMFileReader::ReadFileContent(JSContext* aCx, } //Obtain the total size of the file before reading - mReadTotal = kUnknownSize; - mFile->GetSize(&mReadTotal); + mTotal = mozilla::dom::kUnknownSize; + mFile->GetSize(&mTotal); rv = mChannel->AsyncOpen(this, nsnull); NS_ENSURE_SUCCESS(rv, rv); @@ -574,7 +462,7 @@ nsDOMFileReader::ReadFileContent(JSContext* aCx, if (mDataFormat == FILE_AS_ARRAYBUFFER) { RootResultArrayBuffer(); - mResultArrayBuffer = js_CreateArrayBuffer(aCx, mReadTotal); + mResultArrayBuffer = js_CreateArrayBuffer(aCx, mTotal); if (!mResultArrayBuffer) { NS_WARNING("Failed to create JS array buffer"); return NS_ERROR_FAILURE; @@ -584,64 +472,6 @@ nsDOMFileReader::ReadFileContent(JSContext* aCx, return NS_OK; } -void -nsDOMFileReader::DispatchError(nsresult rv) -{ - //Set the status attribute, and dispatch the error event - switch (rv) { - case NS_ERROR_FILE_NOT_FOUND: - mError = new nsDOMFileError(nsIDOMFileError::NOT_FOUND_ERR); - break; - case NS_ERROR_FILE_ACCESS_DENIED: - mError = new nsDOMFileError(nsIDOMFileError::SECURITY_ERR); - break; - default: - mError = new nsDOMFileError(nsIDOMFileError::NOT_READABLE_ERR); - break; - } - - //Dispatch error event to signify load failure - DispatchProgressEvent(NS_LITERAL_STRING(ERROR_STR)); - DispatchProgressEvent(NS_LITERAL_STRING(LOADEND_STR)); -} - -void -nsDOMFileReader::DispatchProgressEvent(const nsAString& aType) -{ - nsCOMPtr event; - nsresult rv = nsEventDispatcher::CreateEvent(nsnull, nsnull, - NS_LITERAL_STRING("ProgressEvent"), - getter_AddRefs(event)); - if (NS_FAILED(rv)) - return; - - nsCOMPtr privevent(do_QueryInterface(event)); - - if (!privevent) - return; - - privevent->SetTrusted(PR_TRUE); - - nsCOMPtr progress = do_QueryInterface(event); - - if (!progress) - return; - - bool known; - PRUint64 size; - if (mReadTotal != kUnknownSize) { - known = PR_TRUE; - size = mReadTotal; - } else { - known = PR_FALSE; - size = 0; - } - progress->InitProgressEvent(aType, PR_FALSE, PR_FALSE, known, - mReadTransferred, size); - - this->DispatchDOMEvent(nsnull, event, nsnull, nsnull); -} - nsresult nsDOMFileReader::GetAsText(const nsACString &aCharset, const char *aFileData, diff --git a/content/base/src/nsDOMFileReader.h b/content/base/src/nsDOMFileReader.h index deb289d4296..5fb0062f75e 100644 --- a/content/base/src/nsDOMFileReader.h +++ b/content/base/src/nsDOMFileReader.h @@ -39,16 +39,15 @@ #define nsDOMFileReader_h__ #include "nsISupportsUtils.h" -#include "nsString.h" +#include "nsString.h" +#include "nsWeakReference.h" #include "nsIStreamListener.h" -#include "nsIScriptContext.h" #include "nsIInterfaceRequestor.h" #include "nsJSUtils.h" #include "nsTArray.h" #include "nsIJSNativeInitializer.h" #include "prtime.h" #include "nsITimer.h" -#include "nsDOMEventTargetHelper.h" #include "nsICharsetDetector.h" #include "nsICharsetDetectionObserver.h" @@ -62,15 +61,13 @@ #include "nsIChannel.h" #include "prmem.h" -#include "nsXMLHttpRequest.h" +#include "FileIOObject.h" -class nsDOMFileReader : public nsXHREventTarget, +class nsDOMFileReader : public mozilla::dom::FileIOObject, public nsIDOMFileReader, - public nsIStreamListener, public nsIInterfaceRequestor, public nsSupportsWeakReference, public nsIJSNativeInitializer, - public nsITimerCallback, public nsICharsetDetectionObserver { public: @@ -81,35 +78,31 @@ public: NS_DECL_NSIDOMFILEREADER - NS_FORWARD_NSIXMLHTTPREQUESTEVENTTARGET(nsXHREventTarget::); - - // nsIStreamListener - NS_DECL_NSISTREAMLISTENER - - // nsIRequestObserver - NS_DECL_NSIREQUESTOBSERVER - + NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::) + // nsIInterfaceRequestor NS_DECL_NSIINTERFACEREQUESTOR - // nsITimerCallback - NS_DECL_NSITIMERCALLBACK - // nsIJSNativeInitializer NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj, PRUint32 argc, jsval* argv); - NS_FORWARD_NSIDOMEVENTTARGET(nsXHREventTarget::) - // nsICharsetDetectionObserver NS_IMETHOD Notify(const char *aCharset, nsDetectionConfident aConf); - void DispatchProgressEvent(const nsAString& aType); + // FileIOObject overrides + NS_IMETHOD DoAbort(nsAString& aEvent); + NS_IMETHOD DoOnStopRequest(nsIRequest* aRequest, nsISupports* aContext, + nsresult aStatus, nsAString& aSuccessEvent, + nsAString& aTerminationEvent); + NS_IMETHOD DoOnDataAvailable(nsIRequest* aRequest, nsISupports* aContext, + nsIInputStream* aInputStream, PRUint32 aOffset, + PRUint32 aCount); nsresult Init(); NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsDOMFileReader, - nsXHREventTarget) + FileIOObject) void RootResultArrayBuffer(); protected: @@ -126,8 +119,6 @@ protected: nsresult GetAsDataURL(nsIDOMBlob *aFile, const char *aFileData, PRUint32 aDataLen, nsAString &aResult); nsresult GuessCharset(const char *aFileData, PRUint32 aDataLen, nsACString &aCharset); nsresult ConvertStream(const char *aFileData, PRUint32 aDataLen, const char *aCharset, nsAString &aResult); - void DispatchError(nsresult rv); - void StartProgressEventTimer(); void FreeFileData() { PR_Free(mFileData); @@ -143,18 +134,7 @@ protected: eDataFormat mDataFormat; nsString mResult; - PRUint16 mReadyState; - - bool mProgressEventWasDelayed; - bool mTimerIsActive; - nsCOMPtr mError; - - nsCOMPtr mProgressNotifier; nsCOMPtr mPrincipal; - nsCOMPtr mChannel; - - PRUint64 mReadTotal; - PRUint64 mReadTransferred; JSObject* mResultArrayBuffer; }; diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index bc6d242df1d..59fb5191553 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -1825,7 +1825,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument) } // Traverse all nsIDocument pointer members. - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCachedRootElement) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSecurityInfo) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDisplayDocument) @@ -1906,7 +1905,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument) tmp->mFirstChild = nsnull; NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mXPathEvaluatorTearoff) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCachedRootElement) + tmp->mCachedRootElement = nsnull; // Avoid a dangling pointer NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDisplayDocument) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstBaseNodeWithHref) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDOMImplementation) @@ -3396,6 +3395,13 @@ nsDocument::NodeName(nsAString& aNodeName) aNodeName.AssignLiteral("#document"); } +Element* +nsIDocument::GetRootElement() const +{ + return (mCachedRootElement && mCachedRootElement->GetNodeParent() == this) ? + mCachedRootElement : GetRootElementInternal(); +} + Element* nsDocument::GetRootElementInternal() const { @@ -3405,7 +3411,7 @@ nsDocument::GetRootElementInternal() const for (i = mChildren.ChildCount(); i > 0; --i) { nsIContent* child = mChildren.ChildAt(i - 1); if (child->IsElement()) { - const_cast(this)->mCachedRootElement = child; + const_cast(this)->mCachedRootElement = child->AsElement(); return child->AsElement(); } } diff --git a/content/base/src/nsEventSource.cpp b/content/base/src/nsEventSource.cpp index 7bcb5d3aaa9..a77870e87fd 100644 --- a/content/base/src/nsEventSource.cpp +++ b/content/base/src/nsEventSource.cpp @@ -59,6 +59,7 @@ #include "nsIContentSecurityPolicy.h" #include "nsContentUtils.h" #include "mozilla/Preferences.h" +#include "xpcpublic.h" using namespace mozilla; @@ -113,17 +114,11 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsEventSource, NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChannelEventSink) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mHttpChannel) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTimer) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnOpenListener) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnMessageListener) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnErrorListener) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mUnicodeDecoder) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsEventSource, nsDOMEventTargetWrapperCache) tmp->Close(); - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnOpenListener) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnMessageListener) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnErrorListener) NS_IMPL_CYCLE_COLLECTION_UNLINK_END DOMCI_DATA(EventSource, nsEventSource) @@ -162,23 +157,9 @@ nsEventSource::GetReadyState(PRInt32 *aReadyState) return NS_OK; } -#define NS_EVENTSRC_IMPL_DOMEVENTLISTENER(_eventlistenername, _eventlistener) \ - NS_IMETHODIMP \ - nsEventSource::GetOn##_eventlistenername(nsIDOMEventListener * *aListener) \ - { \ - return GetInnerEventListener(_eventlistener, aListener); \ - } \ - \ - NS_IMETHODIMP \ - nsEventSource::SetOn##_eventlistenername(nsIDOMEventListener * aListener) \ - { \ - return RemoveAddEventListener(NS_LITERAL_STRING(#_eventlistenername), \ - _eventlistener, aListener); \ - } - -NS_EVENTSRC_IMPL_DOMEVENTLISTENER(open, mOnOpenListener) -NS_EVENTSRC_IMPL_DOMEVENTLISTENER(error, mOnErrorListener) -NS_EVENTSRC_IMPL_DOMEVENTLISTENER(message, mOnMessageListener) +NS_IMPL_EVENT_HANDLER(nsEventSource, open) +NS_IMPL_EVENT_HANDLER(nsEventSource, error) +NS_IMPL_EVENT_HANDLER(nsEventSource, message) NS_IMETHODIMP nsEventSource::Close() diff --git a/content/base/src/nsEventSource.h b/content/base/src/nsEventSource.h index a28bb2cb5ed..e23a67f5703 100644 --- a/content/base/src/nsEventSource.h +++ b/content/base/src/nsEventSource.h @@ -222,10 +222,6 @@ protected: nsString mLastFieldName; nsString mLastFieldValue; - nsRefPtr mOnOpenListener; - nsRefPtr mOnErrorListener; - nsRefPtr mOnMessageListener; - nsCOMPtr mLoadGroup; /** diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index 03004056183..d065429a9f0 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -1790,7 +1790,9 @@ GK_ATOM(svgTSpanFrame, "SVGTSpanFrame") GK_ATOM(svgUseFrame, "SVGUseFrame") GK_ATOM(HTMLVideoFrame, "VideoFrame") GK_ATOM(onloadstart, "onloadstart") +GK_ATOM(onloadend, "onloadend") GK_ATOM(onprogress, "onprogress") +GK_ATOM(onuploadprogress, "onuploadprogress") GK_ATOM(onsuspend, "onsuspend") GK_ATOM(onemptied, "onemptied") GK_ATOM(onstalled, "onstalled") diff --git a/content/base/src/nsWebSocket.cpp b/content/base/src/nsWebSocket.cpp index 12ab15edc9a..7268c138f12 100644 --- a/content/base/src/nsWebSocket.cpp +++ b/content/base/src/nsWebSocket.cpp @@ -78,6 +78,7 @@ #include "nsIRequest.h" #include "mozilla/Preferences.h" #include "nsDOMLists.h" +#include "xpcpublic.h" using namespace mozilla; diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index 2a512ac8a21..b8509ae1062 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -288,24 +288,15 @@ nsMultipartProxyListener::OnDataAvailable(nsIRequest *aRequest, NS_IMPL_CYCLE_COLLECTION_CLASS(nsXHREventTarget) +// nsXHREventTarget's CC participant doesn't actually do anything anymore +// but these are left here as placeholders in case it needs to do something +// in the future. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXHREventTarget, nsDOMEventTargetWrapperCache) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnLoadListener) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnErrorListener) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnAbortListener) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnLoadStartListener) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnProgressListener) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnLoadendListener) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsXHREventTarget, nsDOMEventTargetWrapperCache) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnLoadListener) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnErrorListener) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnAbortListener) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnLoadStartListener) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnProgressListener) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnLoadendListener) NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsXHREventTarget) @@ -315,83 +306,12 @@ NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetWrapperCache) NS_IMPL_ADDREF_INHERITED(nsXHREventTarget, nsDOMEventTargetWrapperCache) NS_IMPL_RELEASE_INHERITED(nsXHREventTarget, nsDOMEventTargetWrapperCache) -NS_IMETHODIMP -nsXHREventTarget::GetOnload(nsIDOMEventListener** aOnLoad) -{ - return GetInnerEventListener(mOnLoadListener, aOnLoad); -} - -NS_IMETHODIMP -nsXHREventTarget::SetOnload(nsIDOMEventListener* aOnLoad) -{ - return RemoveAddEventListener(NS_LITERAL_STRING(LOAD_STR), - mOnLoadListener, aOnLoad); -} - -NS_IMETHODIMP -nsXHREventTarget::GetOnerror(nsIDOMEventListener** aOnerror) -{ - return GetInnerEventListener(mOnErrorListener, aOnerror); -} - -NS_IMETHODIMP -nsXHREventTarget::SetOnerror(nsIDOMEventListener* aOnerror) -{ - return RemoveAddEventListener(NS_LITERAL_STRING(ERROR_STR), - mOnErrorListener, aOnerror); -} - -NS_IMETHODIMP -nsXHREventTarget::GetOnabort(nsIDOMEventListener** aOnabort) -{ - return GetInnerEventListener(mOnAbortListener, aOnabort); -} - -NS_IMETHODIMP -nsXHREventTarget::SetOnabort(nsIDOMEventListener* aOnabort) -{ - return RemoveAddEventListener(NS_LITERAL_STRING(ABORT_STR), - mOnAbortListener, aOnabort); -} - -NS_IMETHODIMP -nsXHREventTarget::GetOnloadstart(nsIDOMEventListener** aOnloadstart) -{ - return GetInnerEventListener(mOnLoadStartListener, aOnloadstart); -} - -NS_IMETHODIMP -nsXHREventTarget::SetOnloadstart(nsIDOMEventListener* aOnloadstart) -{ - return RemoveAddEventListener(NS_LITERAL_STRING(LOADSTART_STR), - mOnLoadStartListener, aOnloadstart); -} - -NS_IMETHODIMP -nsXHREventTarget::GetOnprogress(nsIDOMEventListener** aOnprogress) -{ - return GetInnerEventListener(mOnProgressListener, aOnprogress); -} - -NS_IMETHODIMP -nsXHREventTarget::SetOnprogress(nsIDOMEventListener* aOnprogress) -{ - return RemoveAddEventListener(NS_LITERAL_STRING(PROGRESS_STR), - mOnProgressListener, aOnprogress); -} - -NS_IMETHODIMP -nsXHREventTarget::GetOnloadend(nsIDOMEventListener** aOnLoadend) -{ - return GetInnerEventListener(mOnLoadendListener, aOnLoadend); -} - -NS_IMETHODIMP -nsXHREventTarget::SetOnloadend(nsIDOMEventListener* aOnLoadend) -{ - return RemoveAddEventListener(NS_LITERAL_STRING(LOADEND_STR), - mOnLoadendListener, aOnLoadend); -} +NS_IMPL_EVENT_HANDLER(nsXHREventTarget, load) +NS_IMPL_EVENT_HANDLER(nsXHREventTarget, error) +NS_IMPL_EVENT_HANDLER(nsXHREventTarget, abort) +NS_IMPL_EVENT_HANDLER(nsXHREventTarget, loadstart) +NS_IMPL_EVENT_HANDLER(nsXHREventTarget, progress) +NS_IMPL_EVENT_HANDLER(nsXHREventTarget, loadend) ///////////////////////////////////////////// @@ -585,9 +505,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLHttpRequest, NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mResponseXML) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCORSPreflightChannel) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnUploadProgressListener) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnReadystatechangeListener) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mXMLParserStreamListener) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChannelEventSink) @@ -607,9 +524,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsXMLHttpRequest, NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mResponseXML) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCORSPreflightChannel) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnUploadProgressListener) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnReadystatechangeListener) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mXMLParserStreamListener) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mChannelEventSink) @@ -650,39 +564,8 @@ NS_INTERFACE_MAP_END_INHERITING(nsXHREventTarget) NS_IMPL_ADDREF_INHERITED(nsXMLHttpRequest, nsXHREventTarget) NS_IMPL_RELEASE_INHERITED(nsXMLHttpRequest, nsXHREventTarget) -NS_IMETHODIMP -nsXMLHttpRequest::GetOnreadystatechange(nsIDOMEventListener * *aOnreadystatechange) -{ - return - nsXHREventTarget::GetInnerEventListener(mOnReadystatechangeListener, - aOnreadystatechange); -} - -NS_IMETHODIMP -nsXMLHttpRequest::SetOnreadystatechange(nsIDOMEventListener * aOnreadystatechange) -{ - return - nsXHREventTarget::RemoveAddEventListener(NS_LITERAL_STRING(READYSTATE_STR), - mOnReadystatechangeListener, - aOnreadystatechange); -} - -NS_IMETHODIMP -nsXMLHttpRequest::GetOnuploadprogress(nsIDOMEventListener * *aOnuploadprogress) -{ - return - nsXHREventTarget::GetInnerEventListener(mOnUploadProgressListener, - aOnuploadprogress); -} - -NS_IMETHODIMP -nsXMLHttpRequest::SetOnuploadprogress(nsIDOMEventListener * aOnuploadprogress) -{ - return - nsXHREventTarget::RemoveAddEventListener(NS_LITERAL_STRING(UPLOADPROGRESS_STR), - mOnUploadProgressListener, - aOnuploadprogress); -} +NS_IMPL_EVENT_HANDLER(nsXMLHttpRequest, readystatechange) +NS_IMPL_EVENT_HANDLER(nsXMLHttpRequest, uploadprogress) /* readonly attribute nsIChannel channel; */ NS_IMETHODIMP diff --git a/content/base/src/nsXMLHttpRequest.h b/content/base/src/nsXMLHttpRequest.h index afb82206a4b..00703284a12 100644 --- a/content/base/src/nsXMLHttpRequest.h +++ b/content/base/src/nsXMLHttpRequest.h @@ -80,14 +80,6 @@ public: nsDOMEventTargetWrapperCache) NS_DECL_NSIXMLHTTPREQUESTEVENTTARGET NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::) - -protected: - nsRefPtr mOnLoadListener; - nsRefPtr mOnErrorListener; - nsRefPtr mOnAbortListener; - nsRefPtr mOnLoadStartListener; - nsRefPtr mOnProgressListener; - nsRefPtr mOnLoadendListener; }; class nsXMLHttpRequestUpload : public nsXHREventTarget, @@ -133,8 +125,7 @@ public: NS_DECL_NSIXMLHTTPREQUEST // nsIJSXMLHttpRequest - NS_IMETHOD GetOnuploadprogress(nsIDOMEventListener** aOnuploadprogress); - NS_IMETHOD SetOnuploadprogress(nsIDOMEventListener* aOnuploadprogress); + NS_DECL_NSIJSXMLHTTPREQUEST NS_FORWARD_NSIXMLHTTPREQUESTEVENTTARGET(nsXHREventTarget::) @@ -257,9 +248,6 @@ protected: nsCOMPtr mCORSPreflightChannel; nsTArray mCORSUnsafeHeaders; - nsRefPtr mOnUploadProgressListener; - nsRefPtr mOnReadystatechangeListener; - nsCOMPtr mXMLParserStreamListener; // used to implement getAllResponseHeaders() diff --git a/content/base/test/unit/test_bug553888.js b/content/base/test/unit/test_bug553888.js index 9433f7a8aba..60cdf77d386 100644 --- a/content/base/test/unit/test_bug553888.js +++ b/content/base/test/unit/test_bug553888.js @@ -79,12 +79,12 @@ function run_test() { .createInstance(Components.interfaces.nsIXMLHttpRequest); request.open("GET", redirectURL, true); request.setRequestHeader("X-Custom-Header", "present"); - request.onreadystatechange = function() { + request.addEventListener("readystatechange", function() { if (request.readyState == 4) { do_check_eq(request.status, 200); server.stop(do_test_finished); } - }; + }, false); request.send(); try { request.setRequestHeader("X-Unwanted-Header", "present"); diff --git a/content/base/test/unit/test_error_codes.js b/content/base/test/unit/test_error_codes.js index 35528bb1a39..c8e2da29459 100644 --- a/content/base/test/unit/test_error_codes.js +++ b/content/base/test/unit/test_error_codes.js @@ -46,7 +46,7 @@ var asyncXHR = { request.open("GET", "http://localhost:4444/test_error_code.xml", true); var self = this; - request.onerror = function(event) { self.onError(event); }; + request.addEventListener("error", function(event) { self.onError(event); }, false); request.send(null); }, onError: function doAsyncRequest_onError(event) { diff --git a/content/canvas/src/WebGLContext.h b/content/canvas/src/WebGLContext.h index 68b798bde2d..48d506bc6d1 100644 --- a/content/canvas/src/WebGLContext.h +++ b/content/canvas/src/WebGLContext.h @@ -588,17 +588,6 @@ protected: return target == LOCAL_GL_TEXTURE_2D ? mGLMaxTextureSize : mGLMaxCubeMapTextureSize; } - // bug 684882 comment 37. On Mac OS (confirmed on 10.7.1), Intel driver, rendering to a face of a cube map - // copies random video memory into it. - // In particular, since glGenerateMipmap does that, it must be avoided. - bool WorkAroundCubeMapBug684882() const { - #ifdef XP_MACOSX - return gl->Vendor() == gl::GLContext::VendorIntel; - #else - return false; - #endif - } - /** like glBufferData but if the call may change the buffer size, checks any GL error generated * by this glBufferData call and returns it */ GLenum CheckedBufferData(GLenum target, @@ -1165,7 +1154,6 @@ public: mWrapT = aWrapT; SetDontKnowIfNeedFakeBlack(); } - WebGLenum MinFilter() const { return mMinFilter; } bool DoesMinFilterRequireMipmap() const { diff --git a/content/canvas/src/WebGLContextGL.cpp b/content/canvas/src/WebGLContextGL.cpp index b9dadf81465..9c524b28e86 100644 --- a/content/canvas/src/WebGLContextGL.cpp +++ b/content/canvas/src/WebGLContextGL.cpp @@ -1696,17 +1696,10 @@ WebGLContext::FramebufferTexture2D(WebGLenum target, nsIWebGLTexture *tobj, WebGLint level) { - if (!mBoundFramebuffer) + if (mBoundFramebuffer) + return mBoundFramebuffer->FramebufferTexture2D(target, attachment, textarget, tobj, level); + else return ErrorInvalidOperation("framebufferTexture2D: cannot modify framebuffer 0"); - - if (textarget != LOCAL_GL_TEXTURE_2D && WorkAroundCubeMapBug684882()) { - return ErrorInvalidOperation("framebufferTexture2D: Attaching a face of a cube map to a framebuffer is disabled " - "on Mac OS X on Intel GPUs to protect you from a bug causing random " - "video memory to be copied into cube maps attached to framebuffers " - "(Mozilla bug 684882, Apple bug 9129398)"); - } - - return mBoundFramebuffer->FramebufferTexture2D(target, attachment, textarget, tobj, level); } GL_SAME_METHOD_0(Flush, Flush) @@ -1784,18 +1777,7 @@ WebGLContext::GenerateMipmap(WebGLenum target) tex->SetGeneratedMipmap(); MakeContextCurrent(); - - if (WorkAroundCubeMapBug684882()) { - if (target == LOCAL_GL_TEXTURE_2D) { - gl->fGenerateMipmap(target); - } else { - // do nothing! Accordingly we must make sure to never actually set texture parameters to something that requires mipmaps, - // or else we'll fail to render. - } - } else { - gl->fGenerateMipmap(target); - } - + gl->fGenerateMipmap(target); return NS_OK; } @@ -2527,33 +2509,12 @@ nsresult WebGLContext::TexParameter_base(WebGLenum target, WebGLenum pname, return ErrorInvalidEnum("texParameterf: pname %x and floating-point param %e are mutually incompatible", pname, floatParam); } - - WebGLint intParamForGL = intParam; - WebGLfloat floatParamForGL = floatParam; - - if (WorkAroundCubeMapBug684882()) { - // bug 684882 - we skip mipmap generation in this case to work around a Mac GL bug, so we have - // to tweak the minification filter to avoid requiring a mipmap - if (pname == LOCAL_GL_TEXTURE_MIN_FILTER) { - if (intParam == LOCAL_GL_NEAREST_MIPMAP_NEAREST || - intParam == LOCAL_GL_NEAREST_MIPMAP_LINEAR) - { - intParamForGL = LOCAL_GL_NEAREST; - floatParamForGL = WebGLfloat(intParamForGL); - } else if (intParam == LOCAL_GL_LINEAR_MIPMAP_NEAREST || - intParam == LOCAL_GL_LINEAR_MIPMAP_LINEAR) - { - intParamForGL = LOCAL_GL_LINEAR; - floatParamForGL = WebGLfloat(intParamForGL); - } - } - } MakeContextCurrent(); if (intParamPtr) - gl->fTexParameteri(target, pname, intParamForGL); + gl->fTexParameteri(target, pname, intParam); else - gl->fTexParameterf(target, pname, floatParamForGL); + gl->fTexParameterf(target, pname, floatParam); return NS_OK; } @@ -2579,29 +2540,23 @@ WebGLContext::GetTexParameter(WebGLenum target, WebGLenum pname, nsIVariant **re if (!ValidateTextureTargetEnum(target, "getTexParameter: target")) return NS_OK; - - WebGLTexture *tex = activeBoundTextureForTarget(target); - if (!tex) + if (!activeBoundTextureForTarget(target)) return ErrorInvalidOperation("getTexParameter: no texture bound"); nsCOMPtr wrval = do_CreateInstance("@mozilla.org/variant;1"); NS_ENSURE_TRUE(wrval, NS_ERROR_FAILURE); switch (pname) { - // note that because of bug 684882, the minification filter for OpenGL is sometimes spoofed. - // here we want to return our own value, not OpenGL's value case LOCAL_GL_TEXTURE_MIN_FILTER: - wrval->SetAsInt32(tex->mMinFilter); - break; case LOCAL_GL_TEXTURE_MAG_FILTER: - wrval->SetAsInt32(tex->mMagFilter); - break; case LOCAL_GL_TEXTURE_WRAP_S: - wrval->SetAsInt32(tex->mWrapS); - break; case LOCAL_GL_TEXTURE_WRAP_T: - wrval->SetAsInt32(tex->mWrapT); + { + GLint i = 0; + gl->fGetTexParameteriv(target, pname, &i); + wrval->SetAsInt32(i); + } break; default: diff --git a/content/canvas/src/WebGLContextValidate.cpp b/content/canvas/src/WebGLContextValidate.cpp index 6f660ae7ac2..c75340802e2 100644 --- a/content/canvas/src/WebGLContextValidate.cpp +++ b/content/canvas/src/WebGLContextValidate.cpp @@ -555,6 +555,14 @@ WebGLContext::InitAndValidateGL() gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &mGLMaxTextureSize); gl->fGetIntegerv(LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE, &mGLMaxCubeMapTextureSize); + +#ifdef XP_MACOSX + if (gl->Vendor() == gl::GLContext::VendorIntel) { + // bug 684882, corruption in large cube maps on Intel Mac driver. + // Is reported to only affect Mac OS < 10.7.2 but don't want to rely on that yet. + mGLMaxCubeMapTextureSize = NS_MIN(mGLMaxCubeMapTextureSize, 512); + } +#endif gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_IMAGE_UNITS, &mGLMaxTextureImageUnits); gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mGLMaxVertexTextureImageUnits); diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index a442c90e9be..96af8fb6143 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -3823,8 +3823,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_BEGIN(FileReader, nsIDOMFileReader) DOM_CLASSINFO_MAP_ENTRY(nsIDOMFileReader) - DOM_CLASSINFO_MAP_ENTRY(nsIXMLHttpRequestEventTarget) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) DOM_CLASSINFO_MAP_ENTRY(nsIInterfaceRequestor) DOM_CLASSINFO_MAP_END diff --git a/dom/system/NetworkGeolocationProvider.js b/dom/system/NetworkGeolocationProvider.js index 14c919b09ef..9c0361c3a4b 100755 --- a/dom/system/NetworkGeolocationProvider.js +++ b/dom/system/NetworkGeolocationProvider.js @@ -239,10 +239,10 @@ WifiGeoPositionProvider.prototype = { xhr.mozBackgroundRequest = true; xhr.open("GET", providerUrl, false); xhr.channel.loadFlags = Ci.nsIChannel.LOAD_ANONYMOUS; - xhr.onerror = function(req) { + xhr.addEventListener("error", function(req) { LOG("onerror: " + req); - }; - xhr.onload = function (req) { + }, false); + xhr.addEventListener("load", function (req) { LOG("service returned: " + req.target.responseText); response = JSON.parse(req.target.responseText); /* @@ -288,7 +288,7 @@ WifiGeoPositionProvider.prototype = { } } } - }; + }, false); LOG("************************************* ------>>>> sending."); xhr.send(null); diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index d354750d508..b85bd45babe 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -390,8 +390,8 @@ protected: void AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, eFontPrefLang aCharLang, eFontPrefLang aPageLang); - bool mAllowDownloadableFonts; - bool mDownloadableFontsSanitize; + PRInt8 mAllowDownloadableFonts; + PRInt8 mDownloadableFontsSanitize; // which scripts should be shaped with harfbuzz PRInt32 mUseHarfBuzzScripts; diff --git a/gfx/thebes/gfxWindowsPlatform.h b/gfx/thebes/gfxWindowsPlatform.h index d2fcac72745..7eada23872b 100644 --- a/gfx/thebes/gfxWindowsPlatform.h +++ b/gfx/thebes/gfxWindowsPlatform.h @@ -256,8 +256,8 @@ public: protected: RenderMode mRenderMode; - bool mUseClearTypeForDownloadableFonts; - bool mUseClearTypeAlways; + PRInt8 mUseClearTypeForDownloadableFonts; + PRInt8 mUseClearTypeAlways; HDC mScreenDC; private: diff --git a/js/src/xpconnect/tests/chrome/test_doublewrappedcompartments.xul b/js/src/xpconnect/tests/chrome/test_doublewrappedcompartments.xul index 6917344af6c..3cece3a3981 100644 --- a/js/src/xpconnect/tests/chrome/test_doublewrappedcompartments.xul +++ b/js/src/xpconnect/tests/chrome/test_doublewrappedcompartments.xul @@ -30,12 +30,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=533596 var wrappedWin = $('ifr').contentWindow; var unwrapped = wrappedWin.wrappedJSObject; - var readystatechange = unwrapped.xhr.onreadystatechange; - is(utils.getClassName(readystatechange), 'Proxy', 'properly wrapped'); - is(typeof readystatechange.QueryInterface, 'function', 'double wrapped'); + var filter = unwrapped.filter; + is(utils.getClassName(filter), 'Proxy', 'properly wrapped'); + is(typeof filter.QueryInterface, 'function', 'double wrapped'); - ok(unwrapped.testme(readystatechange), - 'content didn\'t get a proxy, but another double wrapped object'); + ok(unwrapped.testme(filter), + "content didn't get a proxy, but another double wrapped object"); SimpleTest.finish(); } diff --git a/js/src/xpconnect/tests/mochitest/file_doublewrappedcompartments.html b/js/src/xpconnect/tests/mochitest/file_doublewrappedcompartments.html index b983bf86326..a3ebd681912 100644 --- a/js/src/xpconnect/tests/mochitest/file_doublewrappedcompartments.html +++ b/js/src/xpconnect/tests/mochitest/file_doublewrappedcompartments.html @@ -1,9 +1,9 @@ diff --git a/js/src/xpconnect/tests/mochitest/test_bug505915.html b/js/src/xpconnect/tests/mochitest/test_bug505915.html index 158a95f3d7b..3f4c7f87eb9 100644 --- a/js/src/xpconnect/tests/mochitest/test_bug505915.html +++ b/js/src/xpconnect/tests/mochitest/test_bug505915.html @@ -38,16 +38,6 @@ function go() { "threw a security exception instead of an invalid child exception"); } - var xhr = new XMLHttpRequest(); - - try { - xhr.onreadystatechange = ifr.contentWindow; - ok(false, "weird behavior"); - } catch (e) { - ok(/NS_ERROR_XPC_SECURITY_MANAGER_VETO/.test(e), - "threw a security exception instead of an invalid child exception"); - } - // Location is always wrapped, so test it separately. ifr.onload = null; diff --git a/mobile/modules/LocaleRepository.jsm b/mobile/modules/LocaleRepository.jsm index c3ba1316d4b..e7d63a1a491 100644 --- a/mobile/modules/LocaleRepository.jsm +++ b/mobile/modules/LocaleRepository.jsm @@ -105,7 +105,7 @@ var LocaleRepository = { request.overrideMimeType("text/xml"); let self = this; - request.onreadystatechange = function () { + request.addEventListener("readystatechange", function () { if (request.readyState == 4) { if (request.status == 200) { self.log("---- got response") @@ -122,7 +122,7 @@ var LocaleRepository = { Cu.reportError("Locale Repository: Error getting locale from AMO [" + request.status + "]"); } } - }; + }, false); request.send(null); }, diff --git a/netwerk/test/unit/test_xmlhttprequest.js b/netwerk/test/unit/test_xmlhttprequest.js index 273316ad590..9a59b88b93d 100644 --- a/netwerk/test/unit/test_xmlhttprequest.js +++ b/netwerk/test/unit/test_xmlhttprequest.js @@ -38,10 +38,10 @@ function run_test() // Test async XHR sending let async = createXHR(true); - async.onreadystatechange = function(event) { + async.addEventListener("readystatechange", function(event) { if (checkResults(async)) httpserver.stop(do_test_finished); - }; + }, false); async.send(null); do_test_pending(); } diff --git a/testing/mozmill/Makefile.in b/testing/mozmill/Makefile.in index 63351ef4237..2bad70912ab 100644 --- a/testing/mozmill/Makefile.in +++ b/testing/mozmill/Makefile.in @@ -95,6 +95,7 @@ install-develop: mozmill-dir endif # Rules for staging the necessary harness bits for a test package -stage-package: PKG_STAGE = $(DIST)/test-package-stage stage-package: install + +PKG_STAGE = $(DIST)/test-package-stage diff --git a/toolkit/components/telemetry/TelemetryPing.js b/toolkit/components/telemetry/TelemetryPing.js index 01db8b20d30..5b047de7695 100644 --- a/toolkit/components/telemetry/TelemetryPing.js +++ b/toolkit/components/telemetry/TelemetryPing.js @@ -320,8 +320,8 @@ TelemetryPing.prototype = { if (isTestPing) Services.obs.notifyObservers(null, "telemetry-test-xhr-complete", null); } - request.onerror = function(aEvent) finishRequest(request.channel); - request.onload = function(aEvent) finishRequest(request.channel); + request.addEventListener("error", function(aEvent) finishRequest(request.channel), false); + request.addEventListener("load", function(aEvent) finishRequest(request.channel), false); request.send(JSON.stringify(payload)); }, diff --git a/toolkit/components/url-classifier/content/xml-fetcher.js b/toolkit/components/url-classifier/content/xml-fetcher.js index 6e52e5a0cbe..1edad3470af 100644 --- a/toolkit/components/url-classifier/content/xml-fetcher.js +++ b/toolkit/components/url-classifier/content/xml-fetcher.js @@ -103,15 +103,14 @@ PROT_XMLFetcher.prototype = { // Create a closure var self = this; - this._request.onreadystatechange = function() { + this._request.addEventListener("readystatechange", function() { self.readyStateChange(self); - } + }, false); this._request.send(null); }, cancel: function() { - this._request.onreadystatechange = null; this._request.abort(); this._request = null; }, diff --git a/toolkit/crashreporter/CrashSubmit.jsm b/toolkit/crashreporter/CrashSubmit.jsm index d1a52d789e4..6d60e539861 100644 --- a/toolkit/crashreporter/CrashSubmit.jsm +++ b/toolkit/crashreporter/CrashSubmit.jsm @@ -257,7 +257,7 @@ Submitter.prototype = { // add the minidump formData.append("upload_file_minidump", File(this.dump.path)); let self = this; - xhr.onreadystatechange = function (aEvt) { + xhr.addEventListener("readystatechange", function (aEvt) { if (xhr.readyState == 4) { if (xhr.status != 200) { self.notifyStatus(FAILED); @@ -267,7 +267,7 @@ Submitter.prototype = { self.submitSuccess(ret); } } - }; + }, false); xhr.send(formData); return true; diff --git a/toolkit/mozapps/extensions/AddonRepository.jsm b/toolkit/mozapps/extensions/AddonRepository.jsm index 7ebea12f42d..36a7cf92f95 100644 --- a/toolkit/mozapps/extensions/AddonRepository.jsm +++ b/toolkit/mozapps/extensions/AddonRepository.jsm @@ -1176,8 +1176,10 @@ var AddonRepository = { this._request.overrideMimeType("text/xml"); let self = this; - this._request.onerror = function(aEvent) { self._reportFailure(); }; - this._request.onload = function(aEvent) { + this._request.addEventListener("error", function(aEvent) { + self._reportFailure(); + }, false); + this._request.addEventListener("load", function(aEvent) { let request = aEvent.target; let responseXML = request.responseXML; @@ -1196,7 +1198,7 @@ var AddonRepository = { totalResults = parsedTotalResults; aHandleResults(elements, totalResults); - }; + }, false); this._request.send(null); }, diff --git a/toolkit/mozapps/extensions/AddonUpdateChecker.jsm b/toolkit/mozapps/extensions/AddonUpdateChecker.jsm index 7aa1bb2539f..163b279dc8f 100644 --- a/toolkit/mozapps/extensions/AddonUpdateChecker.jsm +++ b/toolkit/mozapps/extensions/AddonUpdateChecker.jsm @@ -451,8 +451,8 @@ function UpdateParser(aId, aType, aUpdateKey, aUrl, aObserver) { this.request.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE; this.request.overrideMimeType("text/xml"); var self = this; - this.request.onload = function(event) { self.onLoad() }; - this.request.onerror = function(event) { self.onError() }; + this.request.addEventListener("load", function(event) { self.onLoad() }, false); + this.request.addEventListener("error", function(event) { self.onError() }, false); this.request.send(null); } catch (e) { diff --git a/toolkit/mozapps/extensions/LightweightThemeManager.jsm b/toolkit/mozapps/extensions/LightweightThemeManager.jsm index e9d0a2cfcce..63ac4db2363 100644 --- a/toolkit/mozapps/extensions/LightweightThemeManager.jsm +++ b/toolkit/mozapps/extensions/LightweightThemeManager.jsm @@ -227,7 +227,7 @@ var LightweightThemeManager = { req.open("GET", theme.updateURL, true); var self = this; - req.onload = function () { + req.addEventListener("load", function () { if (req.status != 200) return; @@ -240,7 +240,7 @@ var LightweightThemeManager = { var currentTheme = self.currentTheme; if (currentTheme && currentTheme.id == theme.id) self.currentTheme = newData; - }; + }, false); req.send(null); }, diff --git a/toolkit/mozapps/extensions/nsBlocklistService.js b/toolkit/mozapps/extensions/nsBlocklistService.js index 7efc0ee8ad1..23cd11a75a5 100644 --- a/toolkit/mozapps/extensions/nsBlocklistService.js +++ b/toolkit/mozapps/extensions/nsBlocklistService.js @@ -546,8 +546,8 @@ Blocklist.prototype = { request.QueryInterface(Components.interfaces.nsIJSXMLHttpRequest); var self = this; - request.onerror = function(event) { self.onXMLError(event); }; - request.onload = function(event) { self.onXMLLoad(event); }; + request.addEventListener("error", function(event) { self.onXMLError(event); }, false); + request.addEventListener("load", function(event) { self.onXMLLoad(event); }, false); request.send(null); // When the blocklist loads we need to compare it to the current copy so diff --git a/toolkit/mozapps/update/nsUpdateService.js b/toolkit/mozapps/update/nsUpdateService.js index b856c81f33b..8f365e56df1 100644 --- a/toolkit/mozapps/update/nsUpdateService.js +++ b/toolkit/mozapps/update/nsUpdateService.js @@ -2155,9 +2155,9 @@ Checker.prototype = { this._request.setRequestHeader("Cache-Control", "no-cache"); var self = this; - this._request.onerror = function(event) { self.onError(event); }; - this._request.onload = function(event) { self.onLoad(event); }; - this._request.onprogress = function(event) { self.onProgress(event); }; + this._request.addEventListener("error", function(event) { self.onError(event); } ,false); + this._request.addEventListener("load", function(event) { self.onLoad(event); }, false); + this._request.addEventListener("progress", function(event) { self.onProgress(event); }, false); LOG("Checker:checkForUpdates - sending request to: " + url); this._request.send(null); diff --git a/toolkit/mozapps/update/test/unit/head_update.js.in b/toolkit/mozapps/update/test/unit/head_update.js.in index e1d475e0a82..b7195d7f90b 100644 --- a/toolkit/mozapps/update/test/unit/head_update.js.in +++ b/toolkit/mozapps/update/test/unit/head_update.js.in @@ -1007,6 +1007,9 @@ xhr.prototype = { _onload: null, set onload(val) { gXHR._onload = makeHandler(val); }, get onload() { return gXHR._onload; }, + addEventListener: function(event, val, capturing) { + eval("gXHR._on" + event + " = val"); + }, flags: AUS_Ci.nsIClassInfo.SINGLETON, implementationLanguage: AUS_Ci.nsIProgrammingLanguage.JAVASCRIPT, getHelperForLanguage: function(language) null, diff --git a/toolkit/mozapps/update/test/unit/test_0020_general.js b/toolkit/mozapps/update/test/unit/test_0020_general.js index 4b8c4be4b59..c24a7e6f8da 100644 --- a/toolkit/mozapps/update/test/unit/test_0020_general.js +++ b/toolkit/mozapps/update/test/unit/test_0020_general.js @@ -87,7 +87,7 @@ function callHandleEvent() { gXHR.responseXML = null; } var e = { target: gXHR }; - gXHR.onload.handleEvent(e); + gXHR.onload(e); } // update xml not found diff --git a/toolkit/mozapps/update/test/unit/test_0030_general.js b/toolkit/mozapps/update/test/unit/test_0030_general.js index 3fcab51e433..e7f0ced92ee 100644 --- a/toolkit/mozapps/update/test/unit/test_0030_general.js +++ b/toolkit/mozapps/update/test/unit/test_0030_general.js @@ -77,7 +77,7 @@ function callHandleEvent() { catch(e) { } var e = { target: gXHR }; - gXHR.onload.handleEvent(e); + gXHR.onload(e); } // Helper function for testing mar downloads that have the correct size diff --git a/toolkit/mozapps/update/test/unit/test_0040_general.js b/toolkit/mozapps/update/test/unit/test_0040_general.js index b6d02efae83..8c8e5500ea5 100644 --- a/toolkit/mozapps/update/test/unit/test_0040_general.js +++ b/toolkit/mozapps/update/test/unit/test_0040_general.js @@ -63,7 +63,7 @@ function end_test() { // call the nsIDOMEventListener's handleEvent method for onload. function callHandleEvent() { var e = { target: gXHR }; - gXHR.onload.handleEvent(e); + gXHR.onload(e); } // Helper function for parsing the result from the contructed url diff --git a/toolkit/mozapps/update/test/unit/test_0050_general.js b/toolkit/mozapps/update/test/unit/test_0050_general.js index a707559ca87..6542a404958 100644 --- a/toolkit/mozapps/update/test/unit/test_0050_general.js +++ b/toolkit/mozapps/update/test/unit/test_0050_general.js @@ -68,7 +68,7 @@ function end_test() { function callHandleEvent() { gXHR.status = gExpectedStatusCode; var e = { target: gXHR }; - gXHR.onload.handleEvent(e); + gXHR.onload(e); } // Helper functions for testing nsIUpdateCheckListener statusText diff --git a/toolkit/mozapps/webapps/OpenWebapps.js b/toolkit/mozapps/webapps/OpenWebapps.js index 938b2966095..8a2a06b7ec8 100644 --- a/toolkit/mozapps/webapps/OpenWebapps.js +++ b/toolkit/mozapps/webapps/OpenWebapps.js @@ -166,7 +166,7 @@ OpenWebapps.prototype = { let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest); xhr.open("GET", aURL, true); - xhr.onload = function() { + xhr.addEventListener("load", function() { if (xhr.status == 200) { try { let manifest = JSON.parse(xhr.responseText); @@ -185,12 +185,12 @@ OpenWebapps.prototype = { else if (aError) { aError.handle({ code: "networkError", message: "Unable to retrieve manifest" }); } - } + }, false); - xhr.onerror = function() { + xhr.addEventListener("error", function() { if (aError) aError.handle({ code: "networkError", message: "Unable to retrieve manifest" }); - } + }, false); xhr.send(null); },