Skip to content

Commit

Permalink
Bug 794663 - Allow downloading appcache for a specific appid/browserf…
Browse files Browse the repository at this point in the history
…lag. r=jduell, a=blocking-basecamp
  • Loading branch information
mayhemer committed Oct 26, 2012
1 parent ba05b20 commit aab53fd
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 47 deletions.
18 changes: 7 additions & 11 deletions uriloader/prefetch/OfflineCacheUpdateChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ OfflineCacheUpdateChild::OfflineCacheUpdateChild(nsIDOMWindow* aWindow)
: mState(STATE_UNINITIALIZED)
, mIsUpgrade(false)
, mIPCActivated(false)
, mInBrowser(false)
, mAppID(NECKO_NO_APP_ID)
, mWindow(aWindow)
, mByteProgress(0)
{
Expand Down Expand Up @@ -182,7 +184,8 @@ OfflineCacheUpdateChild::Init(nsIURI *aManifestURI,
nsIURI *aDocumentURI,
nsIDOMDocument *aDocument,
nsIFile *aCustomProfileDir,
nsILoadContext *aLoadContext)
uint32_t aAppID,
bool aInBrowser)
{
nsresult rv;

Expand Down Expand Up @@ -223,7 +226,8 @@ OfflineCacheUpdateChild::Init(nsIURI *aManifestURI,
if (aDocument)
SetDocument(aDocument);

mLoadContext = aLoadContext;
mAppID = aAppID;
mInBrowser = aInBrowser;

return NS_OK;
}
Expand Down Expand Up @@ -426,19 +430,11 @@ OfflineCacheUpdateChild::Schedule()
// See also nsOfflineCacheUpdate::ScheduleImplicit.
bool stickDocument = mDocument != nullptr;

// Carry load context to the parent
bool isInBrowserElement = false;
uint32_t appId = NECKO_NO_APP_ID;
if (mLoadContext) {
mLoadContext->GetIsInBrowserElement(&isInBrowserElement);
mLoadContext->GetAppId(&appId);
}

// 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,
isInBrowserElement, appId,
mInBrowser, mAppID,
stickDocument);

mIPCActivated = true;
Expand Down
4 changes: 3 additions & 1 deletion uriloader/prefetch/OfflineCacheUpdateChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class OfflineCacheUpdateChild : public nsIOfflineCacheUpdate
nsCOMPtr<nsIURI> mDocumentURI;

nsCOMPtr<nsIObserverService> mObserverService;
nsCOMPtr<nsILoadContext> mLoadContext;

uint32_t mAppID;
bool mInBrowser;

/* Clients watching this update for changes */
nsCOMArray<nsIWeakReference> mWeakObservers;
Expand Down
5 changes: 3 additions & 2 deletions uriloader/prefetch/OfflineCacheUpdateGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ OfflineCacheUpdateGlue::Init(nsIURI *aManifestURI,
nsIURI *aDocumentURI,
nsIDOMDocument *aDocument,
nsIFile *aCustomProfileDir,
nsILoadContext *aLoadContext)
uint32_t aAppID,
bool aInBrowser)
{
if (!EnsureUpdate())
return NS_ERROR_NULL_POINTER;
Expand All @@ -103,7 +104,7 @@ OfflineCacheUpdateGlue::Init(nsIURI *aManifestURI,
if (aDocument)
SetDocument(aDocument);

return mUpdate->Init(aManifestURI, aDocumentURI, nullptr, aCustomProfileDir, aLoadContext);
return mUpdate->Init(aManifestURI, aDocumentURI, nullptr, aCustomProfileDir, aAppID, aInBrowser);
}

void
Expand Down
3 changes: 2 additions & 1 deletion uriloader/prefetch/OfflineCacheUpdateGlue.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class OfflineCacheUpdateGlue MOZ_FINAL : public nsSupportsWeakReference
nsIURI *aDocumentURI,
nsIDOMDocument *aDocument,
nsIFile *aCustomProfileDir,
nsILoadContext *aLoadContext);
uint32_t aAppID,
bool aInBrowser);

NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER

Expand Down
10 changes: 4 additions & 6 deletions uriloader/prefetch/OfflineCacheUpdateParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI,
{
LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this));

// Load context members
mIsInBrowserElement = isInBrowserElement;
mAppId = appId;

nsRefPtr<nsOfflineCacheUpdate> update;
nsCOMPtr<nsIURI> manifestURI = DeserializeURI(aManifestURI);
if (!manifestURI)
Expand All @@ -104,13 +100,15 @@ OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI,
if (!NS_SecurityCompareURIs(manifestURI, documentURI, false))
return NS_ERROR_DOM_SECURITY_ERR;

service->FindUpdate(manifestURI, this, getter_AddRefs(update));
service->FindUpdate(manifestURI, appId, isInBrowserElement,
getter_AddRefs(update));
if (!update) {
update = new nsOfflineCacheUpdate();

// Leave aDocument argument null. Only glues and children keep
// document instances.
rv = update->Init(manifestURI, documentURI, nullptr, nullptr, this);
rv = update->Init(manifestURI, documentURI, nullptr, nullptr,
appId, isInBrowserElement);
NS_ENSURE_SUCCESS(rv, rv);

rv = update->Schedule();
Expand Down
19 changes: 15 additions & 4 deletions uriloader/prefetch/nsIOfflineCacheUpdate.idl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ interface nsIPrincipal;
interface nsIPrefBranch;
interface nsIApplicationCache;
interface nsIFile;
interface nsILoadContext;
interface nsIObserver;

[scriptable, uuid(47360d57-8ef4-4a5d-8865-1a27a739ad1a)]
Expand Down Expand Up @@ -64,7 +63,7 @@ interface nsIOfflineCacheUpdateObserver : nsISupports {
* load its items one by one, sending itemCompleted() to any registered
* observers.
*/
[scriptable, uuid(91d356fa-4eaf-4de2-9870-bb92854cccfe)]
[scriptable, uuid(91b94446-5d91-4089-bed7-edfab25824a7)]
interface nsIOfflineCacheUpdate : nsISupports {
/**
* Fetch the status of the running update. This will return a value
Expand Down Expand Up @@ -110,7 +109,8 @@ interface nsIOfflineCacheUpdate : nsISupports {
*/
void init(in nsIURI aManifestURI, in nsIURI aDocumentURI, in nsIDOMDocument aDocument,
[optional] in nsIFile aCustomProfileDir,
[optional] in nsILoadContext aLoadContext);
[optional] in unsigned long aAppId,
[optional] in boolean aInBrowser);

/**
* Initialize the update for partial processing.
Expand Down Expand Up @@ -190,7 +190,7 @@ interface nsIOfflineCacheUpdate : nsISupports {
readonly attribute uint64_t byteProgress;
};

[scriptable, uuid(9ff7f81f-114a-4876-ad1b-f3910418e4a6)]
[scriptable, uuid(cf362a31-4166-4994-8443-b68704ecdcc0)]
interface nsIOfflineCacheUpdateService : nsISupports {
/**
* Constants for the offline-app permission.
Expand Down Expand Up @@ -229,6 +229,17 @@ interface nsIOfflineCacheUpdateService : nsISupports {
in nsIURI aDocumentURI,
in nsIFile aProfileDir);

/**
* Schedule a cache update for a given offline manifest using app cache
* bound to the given appID+inBrowser flag. If an existing update is
* scheduled or running, that update will be returned. Otherwise a new
* update will be scheduled.
*/
nsIOfflineCacheUpdate scheduleAppUpdate(in nsIURI aManifestURI,
in nsIURI aDocumentURI,
in unsigned long aAppID,
in boolean aInBrowser);

/**
* Schedule a cache update for a manifest when the document finishes
* loading.
Expand Down
16 changes: 10 additions & 6 deletions uriloader/prefetch/nsOfflineCacheUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,8 @@ nsOfflineCacheUpdate::nsOfflineCacheUpdate()
, mOnlyCheckUpdate(false)
, mSucceeded(true)
, mObsolete(false)
, mAppID(NECKO_NO_APP_ID)
, mInBrowser(false)
, mItemsInProgress(0)
, mRescheduleCount(0)
, mPinnedEntryRetriesCount(0)
Expand Down Expand Up @@ -1215,7 +1217,8 @@ nsOfflineCacheUpdate::Init(nsIURI *aManifestURI,
nsIURI *aDocumentURI,
nsIDOMDocument *aDocument,
nsIFile *aCustomProfileDir,
nsILoadContext *aLoadContext)
uint32_t aAppID,
bool aInBrowser)
{
nsresult rv;

Expand Down Expand Up @@ -1257,9 +1260,9 @@ nsOfflineCacheUpdate::Init(nsIURI *aManifestURI,
mCustomProfileDir = aCustomProfileDir;
}
else {
rv = cacheService->BuildGroupID(aManifestURI,
aLoadContext,
mGroupID);
rv = cacheService->BuildGroupIDForApp(aManifestURI,
aAppID, aInBrowser,
mGroupID);
NS_ENSURE_SUCCESS(rv, rv);

rv = cacheService->GetActiveCache(mGroupID,
Expand All @@ -1276,7 +1279,8 @@ nsOfflineCacheUpdate::Init(nsIURI *aManifestURI,
&mPinned);
NS_ENSURE_SUCCESS(rv, rv);

mLoadContext = aLoadContext;
mAppID = aAppID;
mInBrowser = aInBrowser;

mState = STATE_INITIALIZED;
return NS_OK;
Expand Down Expand Up @@ -1681,7 +1685,7 @@ nsOfflineCacheUpdate::ManifestCheckCompleted(nsresult aStatus,
// Leave aDocument argument null. Only glues and children keep
// document instances.
newUpdate->Init(mManifestURI, mDocumentURI, nullptr,
mCustomProfileDir, mLoadContext);
mCustomProfileDir, mAppID, mInBrowser);

// In a rare case the manifest will not be modified on the next refetch
// transfer all master document URIs to the new update to ensure that
Expand Down
11 changes: 9 additions & 2 deletions uriloader/prefetch/nsOfflineCacheUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class nsOfflineCacheUpdate;

class nsICacheEntryDescriptor;
class nsIUTF8StringEnumerator;
class nsILoadContext;

class nsOfflineCacheUpdateItem : public nsIDOMLoadStatus
, public nsIStreamListener
Expand Down Expand Up @@ -264,7 +265,10 @@ class nsOfflineCacheUpdate MOZ_FINAL : public nsIOfflineCacheUpdate
nsCOMPtr<nsIURI> mManifestURI;
nsCOMPtr<nsIURI> mDocumentURI;
nsCOMPtr<nsIFile> mCustomProfileDir;
nsCOMPtr<nsILoadContext> mLoadContext;

uint32_t mAppID;
bool mInBrowser;

nsCOMPtr<nsIObserver> mUpdateAvailableObserver;

nsCOMPtr<nsIApplicationCache> mApplicationCache;
Expand Down Expand Up @@ -317,14 +321,17 @@ class nsOfflineCacheUpdateService MOZ_FINAL : public nsIOfflineCacheUpdateServic

nsresult ScheduleUpdate(nsOfflineCacheUpdate *aUpdate);
nsresult FindUpdate(nsIURI *aManifestURI,
nsILoadContext *aLoadContext,
uint32_t aAppID,
bool aInBrowser,
nsOfflineCacheUpdate **aUpdate);

nsresult Schedule(nsIURI *aManifestURI,
nsIURI *aDocumentURI,
nsIDOMDocument *aDocument,
nsIDOMWindow* aWindow,
nsIFile* aCustomProfileDir,
uint32_t aAppID,
bool aInBrowser,
nsIOfflineCacheUpdate **aUpdate);

virtual nsresult UpdateFinished(nsOfflineCacheUpdate *aUpdate);
Expand Down
Loading

0 comments on commit aab53fd

Please sign in to comment.