Bug 969671 - Warn about use of sync XHR in the main thread, r=sicking/ehsan

--HG--
extra : rebase_source : 4af00da28a4e8b6cc1209d9a5e098d9914286deb
This commit is contained in:
Olli Pettay 2014-02-10 20:35:25 +02:00
parent b9cfc63542
commit eb2b15d9d4
6 changed files with 45 additions and 0 deletions

View File

@ -38,3 +38,4 @@ DEPRECATED_OPERATION(UseOfReleaseEvents)
DEPRECATED_OPERATION(UseOfDOM3LoadMethod)
DEPRECATED_OPERATION(ShowModalDialog)
DEPRECATED_OPERATION(Window_Content)
DEPRECATED_OPERATION(SyncXMLHttpRequest)

View File

@ -273,6 +273,9 @@ nsXMLHttpRequestUpload::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
//
/////////////////////////////////////////////
bool
nsXMLHttpRequest::sDontWarnAboutSyncXHR = false;
nsXMLHttpRequest::nsXMLHttpRequest()
: mResponseBodyDecodedPos(0),
mResponseType(XML_HTTP_RESPONSE_TYPE_DEFAULT),
@ -1541,6 +1544,11 @@ nsXMLHttpRequest::Open(const nsACString& method, const nsACString& url,
{
NS_ENSURE_ARG(!method.IsEmpty());
if (!async && !DontWarnAboutSyncXHR() && GetOwner() &&
GetOwner()->GetExtantDoc()) {
GetOwner()->GetExtantDoc()->WarnOnceAbout(nsIDocument::eSyncXMLHttpRequest);
}
Telemetry::Accumulate(Telemetry::XMLHTTPREQUEST_ASYNC_OR_SYNC,
async ? 0 : 1);

View File

@ -533,6 +533,14 @@ public:
virtual void DisconnectFromOwner() MOZ_OVERRIDE;
static void SetDontWarnAboutSyncXHR(bool aVal)
{
sDontWarnAboutSyncXHR = aVal;
}
static bool DontWarnAboutSyncXHR()
{
return sDontWarnAboutSyncXHR;
}
protected:
nsresult DetectCharset();
nsresult AppendToResponseText(const char * aBuffer, uint32_t aBufferLen);
@ -736,6 +744,25 @@ protected:
// Helper object to manage our XPCOM scriptability bits
nsXMLHttpRequestXPCOMifier* mXPCOMifier;
static bool sDontWarnAboutSyncXHR;
};
class MOZ_STACK_CLASS AutoDontWarnAboutSyncXHR
{
public:
AutoDontWarnAboutSyncXHR() : mOldVal(nsXMLHttpRequest::DontWarnAboutSyncXHR())
{
nsXMLHttpRequest::SetDontWarnAboutSyncXHR(true);
}
~AutoDontWarnAboutSyncXHR()
{
nsXMLHttpRequest::SetDontWarnAboutSyncXHR(mOldVal);
}
private:
bool mOldVal;
};
// A shim class designed to expose the non-DOM interfaces of

View File

@ -144,4 +144,6 @@ UseOfDOM3LoadMethodWarning=Use of document.load() is deprecated. To upgrade your
ShowModalDialogWarning=Use of window.showModalDialog() is deprecated. Use window.open() instead. For more help https://developer.mozilla.org/en-US/docs/Web/API/Window.open
# LOCALIZATION NOTE: Do not translate "window._content" or "window.content"
Window_ContentWarning=window._content is deprecated. Please use window.content instead.
# LOCALIZATION NOTE: Do not translate "XMLHttpRequest"
SyncXMLHttpRequestWarning=Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/
ImplicitMetaViewportTagFallback=No meta-viewport tag found. Please explicitly specify one to prevent unexpected behavioural changes in future versions. For more help https://developer.mozilla.org/en/docs/Mozilla/Mobile/Viewport_meta_tag

View File

@ -115,6 +115,7 @@ static const char sPrintOptionsContractID[] =
#include "nsISHistoryInternal.h"
#include "nsIWebNavigation.h"
#include "nsEventDispatcher.h"
#include "nsXMLHttpRequest.h"
//paint forcing
#include <stdio.h>
@ -1071,6 +1072,8 @@ nsDocumentViewer::PermitUnloadInternal(bool aCallerClosesWindow,
bool *aShouldPrompt,
bool *aPermitUnload)
{
AutoDontWarnAboutSyncXHR disableSyncXHRWarning;
*aPermitUnload = true;
if (!mDocument
@ -1276,6 +1279,8 @@ nsDocumentViewer::ResetCloseWindow()
NS_IMETHODIMP
nsDocumentViewer::PageHide(bool aIsUnload)
{
AutoDontWarnAboutSyncXHR disableSyncXHRWarning;
mHidden = true;
if (!mDocument) {

View File

@ -144,3 +144,5 @@ UseOfDOM3LoadMethodWarning=Use of document.load() is deprecated. To upgrade your
ShowModalDialogWarning=Use of window.showModalDialog() is deprecated. Use window.open() instead. For more help https://developer.mozilla.org/en-US/docs/Web/API/Window.open
# LOCALIZATION NOTE: Do not translate "window._content" or "window.content"
Window_ContentWarning=window._content is deprecated. Please use window.content instead.
# LOCALIZATION NOTE: Do not translate "XMLHttpRequest"
SyncXMLHttpRequestWarning=Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/