Bug 786419 - Part 6 - Disable HTMLDNSPrefetches for offline apps r=jduell

This commit is contained in:
Valentin Gosu 2014-08-23 02:17:18 +03:00
parent 831b1f1158
commit 1f8399dee4
6 changed files with 37 additions and 0 deletions

View File

@ -94,6 +94,10 @@ nsHTMLDNSPrefetch::Shutdown()
bool
nsHTMLDNSPrefetch::IsAllowed (nsIDocument *aDocument)
{
if (NS_IsAppOffline(aDocument->NodePrincipal())) {
return false;
}
// There is no need to do prefetch on non UI scenarios such as XMLHttpRequest.
return aDocument->IsDNSPrefetchAllowed() && aDocument->GetWindow();
}

View File

@ -539,6 +539,11 @@ child:
*/
UIResolutionChanged();
/**
* Tell the child of an app's offline status
*/
AppOfflineStatus(uint32_t id, bool offline);
/*
* FIXME: write protocol!

View File

@ -80,6 +80,7 @@
#include "UnitTransforms.h"
#include "ClientLayerManager.h"
#include "LayersLogging.h"
#include "nsIOService.h"
#include "nsColorPickerProxy.h"
@ -2572,6 +2573,18 @@ TabChild::RecvAsyncMessage(const nsString& aMessage,
return true;
}
bool
TabChild::RecvAppOfflineStatus(const uint32_t& aId, const bool& aOffline)
{
// Instantiate the service to make sure gIOService is initialized
nsCOMPtr<nsIIOService> ioService = mozilla::services::GetIOService();
if (gIOService && ioService) {
gIOService->SetAppOfflineInternal(aId, aOffline ?
nsIAppOfflineInfo::OFFLINE : nsIAppOfflineInfo::ONLINE);
}
return true;
}
class UnloadScriptEvent : public nsRunnable
{
public:

View File

@ -374,6 +374,8 @@ public:
const InfallibleTArray<CpowEntry>& aCpows,
const IPC::Principal& aPrincipal) MOZ_OVERRIDE;
virtual bool RecvAppOfflineStatus(const uint32_t& aId, const bool& aOffline) MOZ_OVERRIDE;
virtual PDocumentRendererChild*
AllocPDocumentRendererChild(const nsRect& documentRect, const gfx::Matrix& transform,
const nsString& bgcolor,

View File

@ -240,6 +240,7 @@ TabParent::TabParent(nsIContentParent* aManager, const TabContext& aContext, uin
, mMarkedDestroying(false)
, mIsDestroyed(false)
, mAppPackageFileDescriptorSent(false)
, mSendOfflineStatus(true)
, mChromeFlags(aChromeFlags)
{
MOZ_ASSERT(aManager);
@ -499,6 +500,14 @@ TabParent::LoadURL(nsIURI* aURI)
return;
}
uint32_t appId = OwnOrContainingAppId();
if (mSendOfflineStatus && NS_IsAppOffline(appId)) {
// If the app is offline in the parent process
// pass that state to the child process as well
unused << SendAppOfflineStatus(appId, true);
}
mSendOfflineStatus = false;
unused << SendLoadURL(spec);
// If this app is a packaged app then we can speed startup by sending over

View File

@ -428,6 +428,10 @@ private:
// Whether we have already sent a FileDescriptor for the app package.
bool mAppPackageFileDescriptorSent;
// Whether we need to send the offline status to the TabChild
// This is true, until the first call of LoadURL
bool mSendOfflineStatus;
uint32_t mChromeFlags;
nsCOMPtr<nsILoadContext> mLoadContext;