2010-10-20 10:12:32 -07:00
|
|
|
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2010-10-20 10:12:32 -07:00
|
|
|
|
|
|
|
#include "OfflineCacheUpdateParent.h"
|
2012-08-23 12:33:46 -07:00
|
|
|
|
2012-12-29 01:02:16 -08:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2012-08-23 12:33:46 -07:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2010-10-20 10:12:32 -07:00
|
|
|
#include "nsOfflineCacheUpdate.h"
|
|
|
|
#include "nsIApplicationCache.h"
|
2012-09-27 12:35:07 -07:00
|
|
|
#include "nsNetUtil.h"
|
2010-10-20 10:12:32 -07:00
|
|
|
|
2012-08-23 12:33:46 -07:00
|
|
|
using namespace mozilla::ipc;
|
2012-12-29 01:02:16 -08:00
|
|
|
using mozilla::dom::TabParent;
|
2012-08-23 12:33:46 -07:00
|
|
|
|
2010-10-20 10:12:32 -07:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
//
|
|
|
|
// To enable logging (see prlog.h for full details):
|
|
|
|
//
|
|
|
|
// set NSPR_LOG_MODULES=nsOfflineCacheUpdate:5
|
|
|
|
// set NSPR_LOG_FILE=offlineupdate.log
|
|
|
|
//
|
|
|
|
// this enables PR_LOG_ALWAYS level information and places all output in
|
|
|
|
// the file offlineupdate.log
|
|
|
|
//
|
|
|
|
extern PRLogModuleInfo *gOfflineCacheUpdateLog;
|
|
|
|
#endif
|
2012-07-30 23:36:00 -07:00
|
|
|
#undef LOG
|
2010-10-20 10:12:32 -07:00
|
|
|
#define LOG(args) PR_LOG(gOfflineCacheUpdateLog, 4, args)
|
|
|
|
#define LOG_ENABLED() PR_LOG_TEST(gOfflineCacheUpdateLog, 4)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace docshell {
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// OfflineCacheUpdateParent::nsISupports
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-07-30 23:36:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS2(OfflineCacheUpdateParent,
|
|
|
|
nsIOfflineCacheUpdateObserver,
|
|
|
|
nsILoadContext)
|
2010-10-20 10:12:32 -07:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// OfflineCacheUpdateParent <public>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-12-29 01:02:16 -08:00
|
|
|
OfflineCacheUpdateParent::OfflineCacheUpdateParent(uint32_t aAppId,
|
|
|
|
bool aIsInBrowser)
|
2010-12-22 07:44:27 -08:00
|
|
|
: mIPCClosed(false)
|
2012-12-29 01:02:16 -08:00
|
|
|
, mIsInBrowserElement(aIsInBrowser)
|
|
|
|
, mAppId(aAppId)
|
2010-10-20 10:12:32 -07:00
|
|
|
{
|
|
|
|
// Make sure the service has been initialized
|
|
|
|
nsOfflineCacheUpdateService* service =
|
|
|
|
nsOfflineCacheUpdateService::EnsureService();
|
|
|
|
if (!service)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LOG(("OfflineCacheUpdateParent::OfflineCacheUpdateParent [%p]", this));
|
|
|
|
}
|
|
|
|
|
|
|
|
OfflineCacheUpdateParent::~OfflineCacheUpdateParent()
|
|
|
|
{
|
|
|
|
LOG(("OfflineCacheUpdateParent::~OfflineCacheUpdateParent [%p]", this));
|
|
|
|
}
|
|
|
|
|
2010-12-22 07:44:27 -08:00
|
|
|
void
|
|
|
|
OfflineCacheUpdateParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
mIPCClosed = true;
|
|
|
|
}
|
|
|
|
|
2010-10-20 10:12:32 -07:00
|
|
|
nsresult
|
2012-08-23 12:33:46 -07:00
|
|
|
OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI,
|
|
|
|
const URIParams& aDocumentURI,
|
2010-10-20 10:12:32 -07:00
|
|
|
const bool& stickDocument)
|
|
|
|
{
|
|
|
|
LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this));
|
|
|
|
|
|
|
|
nsRefPtr<nsOfflineCacheUpdate> update;
|
2012-08-23 12:33:46 -07:00
|
|
|
nsCOMPtr<nsIURI> manifestURI = DeserializeURI(aManifestURI);
|
|
|
|
if (!manifestURI)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-10-20 10:12:32 -07:00
|
|
|
nsOfflineCacheUpdateService* service =
|
|
|
|
nsOfflineCacheUpdateService::EnsureService();
|
|
|
|
if (!service)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-09-27 12:35:07 -07:00
|
|
|
bool offlinePermissionAllowed = false;
|
|
|
|
nsresult rv = service->OfflineAppAllowedForURI(
|
|
|
|
manifestURI, nullptr, &offlinePermissionAllowed);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!offlinePermissionAllowed)
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> documentURI = DeserializeURI(aDocumentURI);
|
|
|
|
if (!documentURI)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (!NS_SecurityCompareURIs(manifestURI, documentURI, false))
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
|
2012-12-29 01:02:16 -08:00
|
|
|
service->FindUpdate(manifestURI, mAppId, mIsInBrowserElement,
|
2012-10-26 04:02:47 -07:00
|
|
|
getter_AddRefs(update));
|
2010-10-20 10:12:32 -07:00
|
|
|
if (!update) {
|
|
|
|
update = new nsOfflineCacheUpdate();
|
|
|
|
|
|
|
|
// Leave aDocument argument null. Only glues and children keep
|
|
|
|
// document instances.
|
2012-10-26 04:02:47 -07:00
|
|
|
rv = update->Init(manifestURI, documentURI, nullptr, nullptr,
|
2012-12-29 01:02:16 -08:00
|
|
|
mAppId, mIsInBrowserElement);
|
2010-10-20 10:12:32 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = update->Schedule();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
update->AddObserver(this, false);
|
2010-10-20 10:12:32 -07:00
|
|
|
|
|
|
|
if (stickDocument) {
|
2010-12-22 07:44:27 -08:00
|
|
|
nsCOMPtr<nsIURI> stickURI;
|
|
|
|
documentURI->Clone(getter_AddRefs(stickURI));
|
|
|
|
update->StickDocument(stickURI);
|
2010-10-20 10:12:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
OfflineCacheUpdateParent::UpdateStateChanged(nsIOfflineCacheUpdate *aUpdate, uint32_t state)
|
2010-10-20 10:12:32 -07:00
|
|
|
{
|
2010-12-22 07:44:27 -08:00
|
|
|
if (mIPCClosed)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2010-10-20 10:12:32 -07:00
|
|
|
LOG(("OfflineCacheUpdateParent::StateEvent [%p]", this));
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t byteProgress;
|
2012-05-22 13:12:40 -07:00
|
|
|
aUpdate->GetByteProgress(&byteProgress);
|
|
|
|
SendNotifyStateEvent(state, byteProgress);
|
2010-10-20 10:12:32 -07:00
|
|
|
|
|
|
|
if (state == nsIOfflineCacheUpdateObserver::STATE_FINISHED) {
|
|
|
|
// Tell the child the particulars after the update has finished.
|
|
|
|
// Sending the Finish event will release the child side of the protocol
|
|
|
|
// and notify "offline-cache-update-completed" on the child process.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isUpgrade;
|
2010-10-20 10:12:32 -07:00
|
|
|
aUpdate->GetIsUpgrade(&isUpgrade);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool succeeded;
|
2010-10-20 10:12:32 -07:00
|
|
|
aUpdate->GetSucceeded(&succeeded);
|
|
|
|
|
2012-05-11 20:15:47 -07:00
|
|
|
SendFinish(succeeded, isUpgrade);
|
2010-10-20 10:12:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::ApplicationCacheAvailable(nsIApplicationCache *aApplicationCache)
|
|
|
|
{
|
2010-12-22 07:44:27 -08:00
|
|
|
if (mIPCClosed)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2010-10-20 10:12:32 -07:00
|
|
|
NS_ENSURE_ARG(aApplicationCache);
|
|
|
|
|
|
|
|
nsCString cacheClientId;
|
|
|
|
aApplicationCache->GetClientID(cacheClientId);
|
|
|
|
nsCString cacheGroupId;
|
|
|
|
aApplicationCache->GetGroupID(cacheGroupId);
|
|
|
|
|
2012-05-11 20:15:47 -07:00
|
|
|
SendAssociateDocuments(cacheGroupId, cacheClientId);
|
2010-10-20 10:12:32 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 23:36:00 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// OfflineCacheUpdateParent::nsILoadContext
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::GetAssociatedWindow(nsIDOMWindow * *aAssociatedWindow)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::GetTopWindow(nsIDOMWindow * *aTopWindow)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::GetTopFrameElement(nsIDOMElement** aElement)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::IsAppOfType(uint32_t appType, bool *_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::GetIsContent(bool *aIsContent)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::GetUsePrivateBrowsing(bool *aUsePrivateBrowsing)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::SetUsePrivateBrowsing(bool aUsePrivateBrowsing)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-10-30 21:15:24 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::SetPrivateBrowsing(bool aUsePrivateBrowsing)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-07-30 23:36:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::GetIsInBrowserElement(bool *aIsInBrowserElement)
|
|
|
|
{
|
|
|
|
*aIsInBrowserElement = mIsInBrowserElement;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::GetAppId(uint32_t *aAppId)
|
|
|
|
{
|
|
|
|
*aAppId = mAppId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-20 10:12:32 -07:00
|
|
|
} // docshell
|
2011-04-19 16:28:21 -07:00
|
|
|
} // mozilla
|