Bug 1020186 - Patch 2: Make POfflineCacheUpdate be managed by PContent - v4. r=honzab

This commit is contained in:
Kershaw Chang 2014-11-13 01:31:00 +01:00
Родитель a5dd5a415d
Коммит b581824528
13 изменённых файлов: 157 добавлений и 139 удалений

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

@ -23,6 +23,7 @@
#include "mozilla/a11y/DocAccessibleChild.h"
#endif
#include "mozilla/Preferences.h"
#include "mozilla/docshell/OfflineCacheUpdateChild.h"
#include "mozilla/dom/ContentBridgeChild.h"
#include "mozilla/dom/ContentBridgeParent.h"
#include "mozilla/dom/DOMStorageIPC.h"
@ -2258,6 +2259,25 @@ ContentChild::RecvUnregisterSheet(const URIParams& aURI, const uint32_t& aType)
return true;
}
POfflineCacheUpdateChild*
ContentChild::AllocPOfflineCacheUpdateChild(const URIParams& manifestURI,
const URIParams& documentURI,
const bool& stickDocument,
const TabId& aTabId)
{
NS_RUNTIMEABORT("unused");
return nullptr;
}
bool
ContentChild::DeallocPOfflineCacheUpdateChild(POfflineCacheUpdateChild* actor)
{
OfflineCacheUpdateChild* offlineCacheUpdate =
static_cast<OfflineCacheUpdateChild*>(actor);
NS_RELEASE(offlineCacheUpdate);
return true;
}
#ifdef MOZ_NUWA_PROCESS
class CallNuwaSpawn : public nsRunnable
{

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

@ -404,6 +404,14 @@ public:
PBrowserOrId
GetBrowserOrId(TabChild* aTabChild);
virtual POfflineCacheUpdateChild* AllocPOfflineCacheUpdateChild(
const URIParams& manifestURI,
const URIParams& documentURI,
const bool& stickDocument,
const TabId& aTabId) MOZ_OVERRIDE;
virtual bool
DeallocPOfflineCacheUpdateChild(POfflineCacheUpdateChild* offlineCacheUpdate) MOZ_OVERRIDE;
private:
virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;

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

@ -35,6 +35,7 @@
#include "nsAccessibilityService.h"
#endif
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/docshell/OfflineCacheUpdateParent.h"
#include "mozilla/dom/DataStoreService.h"
#include "mozilla/dom/DOMStorageIPC.h"
#include "mozilla/dom/Element.h"
@ -84,6 +85,7 @@
#include "nsChromeRegistryChrome.h"
#include "nsConsoleMessage.h"
#include "nsConsoleService.h"
#include "nsContentUtils.h"
#include "nsDebugImpl.h"
#include "nsFrameMessageManager.h"
#include "nsGeolocationSettings.h"
@ -1487,6 +1489,14 @@ ContentParent::ShutDownProcess(bool aCloseWithError)
}
}
const InfallibleTArray<POfflineCacheUpdateParent*>& ocuParents =
ManagedPOfflineCacheUpdateParent();
for (uint32_t i = 0; i < ocuParents.Length(); ++i) {
nsRefPtr<mozilla::docshell::OfflineCacheUpdateParent> ocuParent =
static_cast<mozilla::docshell::OfflineCacheUpdateParent*>(ocuParents[i]);
ocuParent->StopSendingMessagesToChild();
}
// NB: must MarkAsDead() here so that this isn't accidentally
// returned from Get*() while in the midst of shutdown.
MarkAsDead();
@ -4317,6 +4327,62 @@ ContentParent::GetManagedTabContext()
GetTabContextByContentProcess(this->ChildID()));
}
mozilla::docshell::POfflineCacheUpdateParent*
ContentParent::AllocPOfflineCacheUpdateParent(const URIParams& aManifestURI,
const URIParams& aDocumentURI,
const bool& aStickDocument,
const TabId& aTabId)
{
TabContext tabContext;
if (!ContentProcessManager::GetSingleton()->
GetTabContextByProcessAndTabId(this->ChildID(), aTabId, &tabContext)) {
return nullptr;
}
nsRefPtr<mozilla::docshell::OfflineCacheUpdateParent> update =
new mozilla::docshell::OfflineCacheUpdateParent(
tabContext.OwnOrContainingAppId(),
tabContext.IsBrowserElement());
// Use this reference as the IPDL reference.
return update.forget().take();
}
bool
ContentParent::RecvPOfflineCacheUpdateConstructor(POfflineCacheUpdateParent* aActor,
const URIParams& aManifestURI,
const URIParams& aDocumentURI,
const bool& aStickDocument,
const TabId& aTabId)
{
MOZ_ASSERT(aActor);
nsRefPtr<mozilla::docshell::OfflineCacheUpdateParent> update =
static_cast<mozilla::docshell::OfflineCacheUpdateParent*>(aActor);
nsresult rv = update->Schedule(aManifestURI, aDocumentURI, aStickDocument);
if (NS_FAILED(rv) && IsAlive()) {
// Inform the child of failure.
unused << update->SendFinish(false, false);
}
return true;
}
bool
ContentParent::DeallocPOfflineCacheUpdateParent(POfflineCacheUpdateParent* aActor)
{
// Reclaim the IPDL reference.
nsRefPtr<mozilla::docshell::OfflineCacheUpdateParent> update =
dont_AddRef(static_cast<mozilla::docshell::OfflineCacheUpdateParent*>(aActor));
return true;
}
bool
ContentParent::RecvSetOfflinePermission(const Principal& aPrincipal)
{
nsIPrincipal* principal = aPrincipal;
nsContentUtils::MaybeAllowOfflineAppByDefault(principal, nullptr);
return true;
}
} // namespace dom
} // namespace mozilla

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

@ -311,6 +311,23 @@ public:
virtual bool RecvDeallocateTabId(const TabId& aTabId) MOZ_OVERRIDE;
nsTArray<TabContext> GetManagedTabContext();
virtual POfflineCacheUpdateParent*
AllocPOfflineCacheUpdateParent(const URIParams& aManifestURI,
const URIParams& aDocumentURI,
const bool& aStickDocument,
const TabId& aTabId) MOZ_OVERRIDE;
virtual bool
RecvPOfflineCacheUpdateConstructor(POfflineCacheUpdateParent* aActor,
const URIParams& aManifestURI,
const URIParams& aDocumentURI,
const bool& stickDocument,
const TabId& aTabId) MOZ_OVERRIDE;
virtual bool
DeallocPOfflineCacheUpdateParent(POfflineCacheUpdateParent* aActor) MOZ_OVERRIDE;
virtual bool RecvSetOfflinePermission(const IPC::Principal& principal) MOZ_OVERRIDE;
protected:
void OnChannelConnected(int32_t pid) MOZ_OVERRIDE;
virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;

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

@ -14,7 +14,6 @@ include protocol PContentPermissionRequest;
include protocol PFilePicker;
include protocol PIndexedDBPermissionRequest;
include protocol PRenderFrame;
include protocol POfflineCacheUpdate;
include protocol PPluginWidget;
include DOMTypes;
include JavaScriptTypes;
@ -80,7 +79,6 @@ prio(normal upto urgent) intr protocol PBrowser
manages PFilePicker;
manages PIndexedDBPermissionRequest;
manages PRenderFrame;
manages POfflineCacheUpdate;
manages PPluginWidget;
both:
@ -328,37 +326,6 @@ parent:
TextureFactoryIdentifier textureFactoryIdentifier, uint64_t layersId,
bool success);
/**
* Starts an offline application cache update.
* @param manifestURI
* URI of the manifest to fetch, the application cache group ID
* @param documentURI
* URI of the document that referred the manifest
* @param stickDocument
* True if the update was initiated by a document load that referred
* a manifest.
* False if the update was initiated by applicationCache.update() call.
*
* Tells the update to carry the documentURI to a potential separate
* update of implicit (master) items.
*
* Why this argument? If the document was not found in an offline cache
* before load and refers a manifest and this manifest itself has not
* been changed since the last fetch, we will not do the application
* cache group update. But we must cache the document (identified by the
* documentURI). This argument will ensure that a previously uncached
* document will get cached and that we don't re-cache a document that
* has already been cached (stickDocument=false).
*/
POfflineCacheUpdate(URIParams manifestURI, URIParams documentURI,
bool stickDocument);
/**
* Sets "offline-app" permission for the principal. Called when we hit
* a web app with the manifest attribute in <html> and
* offline-apps.allow_by_default is set to true.
*/
SetOfflinePermission(Principal principal);
/**
* window.open from inside <iframe mozbrowser> is special. When the child

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

@ -27,6 +27,7 @@ include protocol PMobileConnection;
include protocol PNecko;
include protocol PPluginModule;
include protocol PPrinting;
include protocol POfflineCacheUpdate;
include protocol PScreenManager;
include protocol PSharedBufferManager;
include protocol PSms;
@ -356,6 +357,7 @@ prio(normal upto urgent) intr protocol PContent
manages PMemoryReportRequest;
manages PMobileConnection;
manages PNecko;
manages POfflineCacheUpdate;
manages PPrinting;
manages PScreenManager;
manages PSms;
@ -787,6 +789,40 @@ parent:
returns (TabId tabId);
async DeallocateTabId(TabId tabId);
/**
* Starts an offline application cache update.
* @param manifestURI
* URI of the manifest to fetch, the application cache group ID
* @param documentURI
* URI of the document that referred the manifest
* @param stickDocument
* True if the update was initiated by a document load that referred
* a manifest.
* False if the update was initiated by applicationCache.update() call.
*
* Tells the update to carry the documentURI to a potential separate
* update of implicit (master) items.
*
* Why this argument? If the document was not found in an offline cache
* before load and refers a manifest and this manifest itself has not
* been changed since the last fetch, we will not do the application
* cache group update. But we must cache the document (identified by the
* documentURI). This argument will ensure that a previously uncached
* document will get cached and that we don't re-cache a document that
* has already been cached (stickDocument=false).
* @param tabId
* To identify which tab owns the app.
*/
POfflineCacheUpdate(URIParams manifestURI, URIParams documentURI,
bool stickDocument, TabId tabId);
/**
* Sets "offline-app" permission for the principal. Called when we hit
* a web app with the manifest attribute in <html> and
* offline-apps.allow_by_default is set to true.
*/
SetOfflinePermission(Principal principal);
both:
AsyncMessage(nsString aMessage, ClonedMessageData aData,
CpowEntry[] aCpows, Principal aPrincipal);

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

@ -15,7 +15,6 @@
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/IntentionalCrash.h"
#include "mozilla/docshell/OfflineCacheUpdateChild.h"
#include "mozilla/dom/indexedDB/PIndexedDBPermissionRequestChild.h"
#include "mozilla/plugins/PluginWidgetChild.h"
#include "mozilla/ipc/DocumentRendererChild.h"
@ -49,6 +48,7 @@
#include "nsIDocumentInlines.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIDOMChromeWindow.h"
#include "nsIDOMDocument.h"
#include "nsIDOMEvent.h"
#include "nsIDOMWindow.h"
#include "nsIDOMWindowUtils.h"
@ -2637,23 +2637,6 @@ TabChild::RecvActivateFrameEvent(const nsString& aType, const bool& capture)
return true;
}
POfflineCacheUpdateChild*
TabChild::AllocPOfflineCacheUpdateChild(const URIParams& manifestURI,
const URIParams& documentURI,
const bool& stickDocument)
{
NS_RUNTIMEABORT("unused");
return nullptr;
}
bool
TabChild::DeallocPOfflineCacheUpdateChild(POfflineCacheUpdateChild* actor)
{
OfflineCacheUpdateChild* offlineCacheUpdate = static_cast<OfflineCacheUpdateChild*>(actor);
NS_RELEASE(offlineCacheUpdate);
return true;
}
bool
TabChild::RecvLoadRemoteScript(const nsString& aURL, const bool& aRunInGlobalScope)
{

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

@ -409,13 +409,6 @@ public:
PIndexedDBPermissionRequestChild* aActor)
MOZ_OVERRIDE;
virtual POfflineCacheUpdateChild* AllocPOfflineCacheUpdateChild(
const URIParams& manifestURI,
const URIParams& documentURI,
const bool& stickDocument) MOZ_OVERRIDE;
virtual bool
DeallocPOfflineCacheUpdateChild(POfflineCacheUpdateChild* offlineCacheUpdate) MOZ_OVERRIDE;
virtual nsIWebNavigation* WebNavigation() MOZ_OVERRIDE { return mWebNav; }
virtual nsIWidget* WebWidget() MOZ_OVERRIDE { return mWidget; }

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

@ -11,7 +11,6 @@
#include "AppProcessChecker.h"
#include "mozIApplication.h"
#include "mozilla/BrowserElementParent.h"
#include "mozilla/docshell/OfflineCacheUpdateParent.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/PContentPermissionRequestParent.h"
#include "mozilla/dom/indexedDB/ActorsParent.h"
@ -302,14 +301,6 @@ TabParent::Destroy()
// destroy itself and send back __delete__().
unused << SendDestroy();
const InfallibleTArray<POfflineCacheUpdateParent*>& ocuParents =
ManagedPOfflineCacheUpdateParent();
for (uint32_t i = 0; i < ocuParents.Length(); ++i) {
nsRefPtr<mozilla::docshell::OfflineCacheUpdateParent> ocuParent =
static_cast<mozilla::docshell::OfflineCacheUpdateParent*>(ocuParents[i]);
ocuParent->StopSendingMessagesToChild();
}
if (RenderFrameParent* frame = GetRenderFrame()) {
frame->Destroy();
}
@ -1941,56 +1932,6 @@ TabParent::DeallocPRenderFrameParent(PRenderFrameParent* aFrame)
return true;
}
mozilla::docshell::POfflineCacheUpdateParent*
TabParent::AllocPOfflineCacheUpdateParent(const URIParams& aManifestURI,
const URIParams& aDocumentURI,
const bool& aStickDocument)
{
nsRefPtr<mozilla::docshell::OfflineCacheUpdateParent> update =
new mozilla::docshell::OfflineCacheUpdateParent(OwnOrContainingAppId(),
IsBrowserElement());
// Use this reference as the IPDL reference.
return update.forget().take();
}
bool
TabParent::RecvPOfflineCacheUpdateConstructor(POfflineCacheUpdateParent* aActor,
const URIParams& aManifestURI,
const URIParams& aDocumentURI,
const bool& aStickDocument)
{
MOZ_ASSERT(aActor);
nsRefPtr<mozilla::docshell::OfflineCacheUpdateParent> update =
static_cast<mozilla::docshell::OfflineCacheUpdateParent*>(aActor);
nsresult rv = update->Schedule(aManifestURI, aDocumentURI, aStickDocument);
if (NS_FAILED(rv) && !IsDestroyed()) {
// Inform the child of failure.
unused << update->SendFinish(false, false);
}
return true;
}
bool
TabParent::DeallocPOfflineCacheUpdateParent(POfflineCacheUpdateParent* aActor)
{
// Reclaim the IPDL reference.
nsRefPtr<mozilla::docshell::OfflineCacheUpdateParent> update =
dont_AddRef(
static_cast<mozilla::docshell::OfflineCacheUpdateParent*>(aActor));
return true;
}
bool
TabParent::RecvSetOfflinePermission(const IPC::Principal& aPrincipal)
{
nsIPrincipal* principal = aPrincipal;
nsContentUtils::MaybeAllowOfflineAppByDefault(principal, nullptr);
return true;
}
bool
TabParent::AllowContentIME()
{

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

@ -303,20 +303,6 @@ public:
PIndexedDBPermissionRequestParent* aActor)
MOZ_OVERRIDE;
virtual POfflineCacheUpdateParent*
AllocPOfflineCacheUpdateParent(const URIParams& aManifestURI,
const URIParams& aDocumentURI,
const bool& aStickDocument) MOZ_OVERRIDE;
virtual bool
RecvPOfflineCacheUpdateConstructor(POfflineCacheUpdateParent* aActor,
const URIParams& aManifestURI,
const URIParams& aDocumentURI,
const bool& stickDocument) MOZ_OVERRIDE;
virtual bool
DeallocPOfflineCacheUpdateParent(POfflineCacheUpdateParent* aActor) MOZ_OVERRIDE;
virtual bool RecvSetOfflinePermission(const IPC::Principal& principal) MOZ_OVERRIDE;
bool GetGlobalJSObject(JSContext* cx, JSObject** globalp);
NS_DECL_ISUPPORTS

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

@ -34,6 +34,7 @@
using namespace mozilla::ipc;
using namespace mozilla::net;
using mozilla::dom::TabChild;
using mozilla::dom::ContentChild;
#if defined(PR_LOGGING)
//
@ -433,10 +434,11 @@ OfflineCacheUpdateChild::Schedule()
// Need to addref ourself here, because the IPC stack doesn't hold
// a reference to us. Will be released in RecvFinish() that identifies
// the work has been done.
child->SendPOfflineCacheUpdateConstructor(this, manifestURI, documentURI,
stickDocument);
ContentChild::GetSingleton()->SendPOfflineCacheUpdateConstructor(
this, manifestURI, documentURI,
stickDocument, child->GetTabId());
// TabChild::DeallocPOfflineCacheUpdate will release this.
// ContentChild::DeallocPOfflineCacheUpdate will release this.
NS_ADDREF_THIS();
return NS_OK;

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

@ -5,7 +5,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBrowser;
include protocol PContent;
namespace mozilla {
namespace docshell {
@ -13,7 +13,7 @@ namespace docshell {
//-------------------------------------------------------------------
protocol POfflineCacheUpdate
{
manager PBrowser;
manager PContent;
parent:
__delete__();

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

@ -45,7 +45,7 @@
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeOwner.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "nsContentUtils.h"
#include "mozilla/unused.h"
@ -747,8 +747,7 @@ nsOfflineCacheUpdateService::AllowOfflineApp(nsIDOMWindow *aWindow,
nsresult rv;
if (GeckoProcessType_Default != XRE_GetProcessType()) {
TabChild* child = TabChild::GetFrom(aWindow);
NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
ContentChild* child = ContentChild::GetSingleton();
if (!child->SendSetOfflinePermission(IPC::Principal(aPrincipal))) {
return NS_ERROR_FAILURE;