Files
firefox/uriloader/prefetch/OfflineCacheUpdateParent.cpp
T
Gabriele Svelto f03cdb2b2d Bug 1600545 - Remove useless inclusions of header files generated from IDL files in modules/, netwerk/, parser/, security/, startupcache/, storage/, toolkit/, tools/, uriloader/, widget/, xpcom/ and xpfe/ r=Ehsan
The inclusions were removed with the following very crude script and the
resulting breakage was fixed up by hand. The manual fixups did either
revert the changes done by the script, replace a generic header with a more
specific one or replace a header with a forward declaration.

find . -name "*.idl" | grep -v web-platform | grep -v third_party | while read path; do
    interfaces=$(grep "^\(class\|interface\).*:.*" "$path" | cut -d' ' -f2)
    if [ -n "$interfaces" ]; then
        if [[ "$interfaces" == *$'\n'* ]]; then
          regexp="\("
          for i in $interfaces; do regexp="$regexp$i\|"; done
          regexp="${regexp%%\\\|}\)"
        else
          regexp="$interfaces"
        fi
        interface=$(basename "$path")
        rg -l "#include.*${interface%%.idl}.h" . | while read path2; do
            hits=$(grep -v "#include.*${interface%%.idl}.h" "$path2" | grep -c "$regexp" )
            if [ $hits -eq 0 ]; then
                echo "Removing ${interface} from ${path2}"
                grep -v "#include.*${interface%%.idl}.h" "$path2" > "$path2".tmp
                mv -f "$path2".tmp "$path2"
            fi
        done
    fi
done

Differential Revision: https://phabricator.services.mozilla.com/D55444
2019-12-06 09:17:57 +00:00

277 lines
8.0 KiB
C++

/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "OfflineCacheUpdateParent.h"
#include "BackgroundUtils.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/ipc/URIUtils.h"
#include "mozilla/Unused.h"
#include "nsContentUtils.h"
#include "nsOfflineCacheUpdate.h"
#include "nsIApplicationCache.h"
#include "nsNetUtil.h"
using namespace mozilla::ipc;
using mozilla::BasePrincipal;
using mozilla::OriginAttributes;
using mozilla::dom::BrowserParent;
//
// To enable logging (see mozilla/Logging.h for full details):
//
// set MOZ_LOG=nsOfflineCacheUpdate:5
// set MOZ_LOG_FILE=offlineupdate.log
//
// this enables LogLevel::Debug level information and places all output in
// the file offlineupdate.log
//
extern mozilla::LazyLogModule gOfflineCacheUpdateLog;
#undef LOG
#define LOG(args) \
MOZ_LOG(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug, args)
#undef LOG_ENABLED
#define LOG_ENABLED() \
MOZ_LOG_TEST(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug)
namespace mozilla {
namespace docshell {
//-----------------------------------------------------------------------------
// OfflineCacheUpdateParent::nsISupports
//-----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS(OfflineCacheUpdateParent, nsIOfflineCacheUpdateObserver,
nsILoadContext)
//-----------------------------------------------------------------------------
// OfflineCacheUpdateParent <public>
//-----------------------------------------------------------------------------
OfflineCacheUpdateParent::OfflineCacheUpdateParent() : mIPCClosed(false) {
// Make sure the service has been initialized
nsOfflineCacheUpdateService::EnsureService();
LOG(("OfflineCacheUpdateParent::OfflineCacheUpdateParent [%p]", this));
}
OfflineCacheUpdateParent::~OfflineCacheUpdateParent() {
LOG(("OfflineCacheUpdateParent::~OfflineCacheUpdateParent [%p]", this));
}
void OfflineCacheUpdateParent::ActorDestroy(ActorDestroyReason why) {
mIPCClosed = true;
}
nsresult OfflineCacheUpdateParent::Schedule(
const URIParams& aManifestURI, const URIParams& aDocumentURI,
const PrincipalInfo& aLoadingPrincipalInfo, const bool& stickDocument,
const CookieSettingsArgs& aCookieSettingsArgs) {
LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this));
nsresult rv;
RefPtr<nsOfflineCacheUpdate> update;
nsCOMPtr<nsIURI> manifestURI = DeserializeURI(aManifestURI);
if (!manifestURI) return NS_ERROR_FAILURE;
mLoadingPrincipal = PrincipalInfoToPrincipal(aLoadingPrincipalInfo, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsOfflineCacheUpdateService* service =
nsOfflineCacheUpdateService::EnsureService();
if (!service) return NS_ERROR_FAILURE;
bool offlinePermissionAllowed = false;
rv = service->OfflineAppAllowed(mLoadingPrincipal, &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;
nsAutoCString originSuffix;
rv = mLoadingPrincipal->GetOriginSuffix(originSuffix);
NS_ENSURE_SUCCESS(rv, rv);
service->FindUpdate(manifestURI, originSuffix, nullptr,
getter_AddRefs(update));
if (!update) {
update = new nsOfflineCacheUpdate();
// Leave aDocument argument null. Only glues and children keep
// document instances.
rv = update->Init(manifestURI, documentURI, mLoadingPrincipal, nullptr,
nullptr);
NS_ENSURE_SUCCESS(rv, rv);
update->SetCookieSettingsArgs(aCookieSettingsArgs);
// Must add before Schedule() call otherwise we would miss
// oncheck event notification.
update->AddObserver(this, false);
rv = update->Schedule();
NS_ENSURE_SUCCESS(rv, rv);
} else {
update->AddObserver(this, false);
}
if (stickDocument) {
update->StickDocument(documentURI);
}
return NS_OK;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::UpdateStateChanged(nsIOfflineCacheUpdate* aUpdate,
uint32_t state) {
if (mIPCClosed) return NS_ERROR_UNEXPECTED;
LOG(("OfflineCacheUpdateParent::StateEvent [%p]", this));
uint64_t byteProgress;
aUpdate->GetByteProgress(&byteProgress);
Unused << SendNotifyStateEvent(state, byteProgress);
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.
bool isUpgrade;
aUpdate->GetIsUpgrade(&isUpgrade);
bool succeeded;
aUpdate->GetSucceeded(&succeeded);
Unused << SendFinish(succeeded, isUpgrade);
}
return NS_OK;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::ApplicationCacheAvailable(
nsIApplicationCache* aApplicationCache) {
if (mIPCClosed) return NS_ERROR_UNEXPECTED;
NS_ENSURE_ARG(aApplicationCache);
nsCString cacheClientId;
aApplicationCache->GetClientID(cacheClientId);
nsCString cacheGroupId;
aApplicationCache->GetGroupID(cacheGroupId);
Unused << SendAssociateDocuments(cacheGroupId, cacheClientId);
return NS_OK;
}
//-----------------------------------------------------------------------------
// OfflineCacheUpdateParent::nsILoadContext
//-----------------------------------------------------------------------------
NS_IMETHODIMP
OfflineCacheUpdateParent::GetAssociatedWindow(
mozIDOMWindowProxy** aAssociatedWindow) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::GetTopWindow(mozIDOMWindowProxy** aTopWindow) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::GetTopFrameElement(dom::Element** aElement) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::GetNestedFrameId(uint64_t* aId) {
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;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::SetPrivateBrowsing(bool aUsePrivateBrowsing) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::GetUseRemoteTabs(bool* aUseRemoteTabs) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::SetRemoteTabs(bool aUseRemoteTabs) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::GetUseRemoteSubframes(bool* aUseRemoteSubframes) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::SetRemoteSubframes(bool aUseRemoteSubframes) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::GetScriptableOriginAttributes(
JSContext* aCx, JS::MutableHandleValue aAttrs) {
NS_ENSURE_TRUE(mLoadingPrincipal, NS_ERROR_UNEXPECTED);
nsresult rv = mLoadingPrincipal->GetOriginAttributes(aCx, aAttrs);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP_(void)
OfflineCacheUpdateParent::GetOriginAttributes(
mozilla::OriginAttributes& aAttrs) {
if (mLoadingPrincipal) {
aAttrs = mLoadingPrincipal->OriginAttributesRef();
}
}
NS_IMETHODIMP
OfflineCacheUpdateParent::GetUseTrackingProtection(
bool* aUseTrackingProtection) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::SetUseTrackingProtection(
bool aUseTrackingProtection) {
return NS_ERROR_NOT_IMPLEMENTED;
}
} // namespace docshell
} // namespace mozilla