2010-10-20 21:12:32 +04:00
|
|
|
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04: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 21:12:32 +04:00
|
|
|
|
|
|
|
#include "OfflineCacheUpdateParent.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2015-10-02 19:13:52 +03:00
|
|
|
#include "BackgroundUtils.h"
|
2015-08-17 12:03:19 +03:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2012-12-29 13:02:16 +04:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2013-01-24 01:07:23 +04:00
|
|
|
#include "mozilla/unused.h"
|
2010-10-20 21:12:32 +04:00
|
|
|
#include "nsOfflineCacheUpdate.h"
|
|
|
|
#include "nsIApplicationCache.h"
|
2013-12-23 06:31:15 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2012-09-27 23:35:07 +04:00
|
|
|
#include "nsNetUtil.h"
|
2010-10-20 21:12:32 +04:00
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
using namespace mozilla::ipc;
|
2015-08-17 12:03:19 +03:00
|
|
|
using mozilla::BasePrincipal;
|
|
|
|
using mozilla::OriginAttributes;
|
2012-12-29 13:02:16 +04:00
|
|
|
using mozilla::dom::TabParent;
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2010-10-20 21:12:32 +04:00
|
|
|
//
|
|
|
|
// To enable logging (see prlog.h for full details):
|
|
|
|
//
|
|
|
|
// set NSPR_LOG_MODULES=nsOfflineCacheUpdate:5
|
|
|
|
// set NSPR_LOG_FILE=offlineupdate.log
|
|
|
|
//
|
2015-06-04 01:25:57 +03:00
|
|
|
// this enables LogLevel::Debug level information and places all output in
|
2010-10-20 21:12:32 +04:00
|
|
|
// the file offlineupdate.log
|
|
|
|
//
|
|
|
|
extern PRLogModuleInfo *gOfflineCacheUpdateLog;
|
2013-11-19 11:50:59 +04:00
|
|
|
|
2012-07-31 10:36:00 +04:00
|
|
|
#undef LOG
|
2015-06-04 01:25:57 +03:00
|
|
|
#define LOG(args) MOZ_LOG(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug, args)
|
2013-11-19 11:50:59 +04:00
|
|
|
|
|
|
|
#undef LOG_ENABLED
|
2015-06-04 01:25:57 +03:00
|
|
|
#define LOG_ENABLED() MOZ_LOG_TEST(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug)
|
2010-10-20 21:12:32 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace docshell {
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// OfflineCacheUpdateParent::nsISupports
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(OfflineCacheUpdateParent,
|
|
|
|
nsIOfflineCacheUpdateObserver,
|
|
|
|
nsILoadContext)
|
2010-10-20 21:12:32 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// OfflineCacheUpdateParent <public>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-11-03 13:53:41 +03:00
|
|
|
OfflineCacheUpdateParent::OfflineCacheUpdateParent(const OriginAttributes& aAttrs)
|
2010-12-22 18:44:27 +03:00
|
|
|
: mIPCClosed(false)
|
2015-11-03 13:53:41 +03:00
|
|
|
, mOriginAttributes(aAttrs)
|
2010-10-20 21:12:32 +04:00
|
|
|
{
|
|
|
|
// Make sure the service has been initialized
|
2014-01-16 00:20:33 +04:00
|
|
|
nsOfflineCacheUpdateService::EnsureService();
|
2010-10-20 21:12:32 +04:00
|
|
|
|
|
|
|
LOG(("OfflineCacheUpdateParent::OfflineCacheUpdateParent [%p]", this));
|
|
|
|
}
|
|
|
|
|
|
|
|
OfflineCacheUpdateParent::~OfflineCacheUpdateParent()
|
|
|
|
{
|
|
|
|
LOG(("OfflineCacheUpdateParent::~OfflineCacheUpdateParent [%p]", this));
|
|
|
|
}
|
|
|
|
|
2010-12-22 18:44:27 +03:00
|
|
|
void
|
|
|
|
OfflineCacheUpdateParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
mIPCClosed = true;
|
|
|
|
}
|
|
|
|
|
2010-10-20 21:12:32 +04:00
|
|
|
nsresult
|
2012-08-23 23:33:46 +04:00
|
|
|
OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI,
|
|
|
|
const URIParams& aDocumentURI,
|
2015-10-02 19:13:52 +03:00
|
|
|
const PrincipalInfo& aLoadingPrincipalInfo,
|
2010-10-20 21:12:32 +04:00
|
|
|
const bool& stickDocument)
|
|
|
|
{
|
|
|
|
LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this));
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsOfflineCacheUpdate> update;
|
2012-08-23 23:33:46 +04:00
|
|
|
nsCOMPtr<nsIURI> manifestURI = DeserializeURI(aManifestURI);
|
|
|
|
if (!manifestURI)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-10-20 21:12:32 +04:00
|
|
|
nsOfflineCacheUpdateService* service =
|
|
|
|
nsOfflineCacheUpdateService::EnsureService();
|
|
|
|
if (!service)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-09-27 23:35:07 +04:00
|
|
|
bool offlinePermissionAllowed = false;
|
2013-12-23 06:31:15 +04:00
|
|
|
|
2015-08-17 12:03:19 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principal =
|
2015-09-23 11:10:21 +03:00
|
|
|
BasePrincipal::CreateCodebasePrincipal(manifestURI, mOriginAttributes);
|
2013-12-23 06:31:15 +04:00
|
|
|
|
|
|
|
nsresult rv = service->OfflineAppAllowed(
|
|
|
|
principal, nullptr, &offlinePermissionAllowed);
|
2012-09-27 23:35:07 +04:00
|
|
|
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;
|
|
|
|
|
2015-09-23 11:10:21 +03:00
|
|
|
// TODO: Bug 1197093 - add originAttributes to nsIOfflineCacheUpdate
|
|
|
|
service->FindUpdate(manifestURI,
|
|
|
|
mOriginAttributes.mAppId,
|
|
|
|
mOriginAttributes.mInBrowser,
|
|
|
|
nullptr,
|
2012-10-26 15:02:47 +04:00
|
|
|
getter_AddRefs(update));
|
2010-10-20 21:12:32 +04:00
|
|
|
if (!update) {
|
|
|
|
update = new nsOfflineCacheUpdate();
|
|
|
|
|
2015-10-02 19:13:52 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> loadingPrincipal =
|
|
|
|
PrincipalInfoToPrincipal(aLoadingPrincipalInfo, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-10-20 21:12:32 +04:00
|
|
|
// Leave aDocument argument null. Only glues and children keep
|
|
|
|
// document instances.
|
2015-10-02 19:13:52 +03:00
|
|
|
rv = update->Init(manifestURI, documentURI, loadingPrincipal, nullptr, nullptr,
|
2015-09-23 11:10:21 +03:00
|
|
|
mOriginAttributes.mAppId, mOriginAttributes.mInBrowser);
|
2010-10-20 21:12:32 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = update->Schedule();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
update->AddObserver(this, false);
|
2010-10-20 21:12:32 +04:00
|
|
|
|
|
|
|
if (stickDocument) {
|
2010-12-22 18:44:27 +03:00
|
|
|
nsCOMPtr<nsIURI> stickURI;
|
|
|
|
documentURI->Clone(getter_AddRefs(stickURI));
|
|
|
|
update->StickDocument(stickURI);
|
2010-10-20 21:12:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
OfflineCacheUpdateParent::UpdateStateChanged(nsIOfflineCacheUpdate *aUpdate, uint32_t state)
|
2010-10-20 21:12:32 +04:00
|
|
|
{
|
2010-12-22 18:44:27 +03:00
|
|
|
if (mIPCClosed)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2010-10-20 21:12:32 +04:00
|
|
|
LOG(("OfflineCacheUpdateParent::StateEvent [%p]", this));
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t byteProgress;
|
2012-05-23 00:12:40 +04:00
|
|
|
aUpdate->GetByteProgress(&byteProgress);
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << SendNotifyStateEvent(state, byteProgress);
|
2010-10-20 21:12:32 +04: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-29 10:19:26 +04:00
|
|
|
bool isUpgrade;
|
2010-10-20 21:12:32 +04:00
|
|
|
aUpdate->GetIsUpgrade(&isUpgrade);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool succeeded;
|
2010-10-20 21:12:32 +04:00
|
|
|
aUpdate->GetSucceeded(&succeeded);
|
|
|
|
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << SendFinish(succeeded, isUpgrade);
|
2010-10-20 21:12:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::ApplicationCacheAvailable(nsIApplicationCache *aApplicationCache)
|
|
|
|
{
|
2010-12-22 18:44:27 +03:00
|
|
|
if (mIPCClosed)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2010-10-20 21:12:32 +04:00
|
|
|
NS_ENSURE_ARG(aApplicationCache);
|
|
|
|
|
|
|
|
nsCString cacheClientId;
|
|
|
|
aApplicationCache->GetClientID(cacheClientId);
|
|
|
|
nsCString cacheGroupId;
|
|
|
|
aApplicationCache->GetGroupID(cacheGroupId);
|
|
|
|
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << SendAssociateDocuments(cacheGroupId, cacheClientId);
|
2010-10-20 21:12:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-31 10:36:00 +04: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;
|
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:36 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::GetNestedFrameId(uint64_t* aId)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-07-31 10:36:00 +04:00
|
|
|
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-31 08:15:24 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::SetPrivateBrowsing(bool aUsePrivateBrowsing)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2014-02-11 21:00:54 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::GetUseRemoteTabs(bool *aUseRemoteTabs)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::SetRemoteTabs(bool aUseRemoteTabs)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-07-31 10:36:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::GetIsInBrowserElement(bool *aIsInBrowserElement)
|
|
|
|
{
|
2015-09-23 11:10:21 +03:00
|
|
|
*aIsInBrowserElement = mOriginAttributes.mInBrowser;
|
2012-07-31 10:36:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::GetAppId(uint32_t *aAppId)
|
|
|
|
{
|
2015-09-23 11:10:21 +03:00
|
|
|
*aAppId = mOriginAttributes.mAppId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::GetOriginAttributes(JS::MutableHandleValue aAttrs)
|
|
|
|
{
|
|
|
|
JSContext* cx = nsContentUtils::GetCurrentJSContext();
|
|
|
|
MOZ_ASSERT(cx);
|
|
|
|
|
|
|
|
bool ok = ToJSValue(cx, mOriginAttributes, aAttrs);
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
|
2012-07-31 10:36:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace docshell
|
|
|
|
} // namespace mozilla
|