LCOV - code coverage report
Current view: top level - uriloader/prefetch - OfflineCacheUpdateParent.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 110 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 25 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "OfflineCacheUpdateParent.h"
       7             : 
       8             : #include "BackgroundUtils.h"
       9             : #include "mozilla/BasePrincipal.h"
      10             : #include "mozilla/dom/TabParent.h"
      11             : #include "mozilla/ipc/URIUtils.h"
      12             : #include "mozilla/Unused.h"
      13             : #include "nsContentUtils.h"
      14             : #include "nsOfflineCacheUpdate.h"
      15             : #include "nsIApplicationCache.h"
      16             : #include "nsIScriptSecurityManager.h"
      17             : #include "nsNetUtil.h"
      18             : 
      19             : using namespace mozilla::ipc;
      20             : using mozilla::BasePrincipal;
      21             : using mozilla::OriginAttributes;
      22             : using mozilla::dom::TabParent;
      23             : 
      24             : //
      25             : // To enable logging (see mozilla/Logging.h for full details):
      26             : //
      27             : //    set MOZ_LOG=nsOfflineCacheUpdate:5
      28             : //    set MOZ_LOG_FILE=offlineupdate.log
      29             : //
      30             : // this enables LogLevel::Debug level information and places all output in
      31             : // the file offlineupdate.log
      32             : //
      33             : extern mozilla::LazyLogModule gOfflineCacheUpdateLog;
      34             : 
      35             : #undef LOG
      36             : #define LOG(args) MOZ_LOG(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug, args)
      37             : 
      38             : #undef LOG_ENABLED
      39             : #define LOG_ENABLED() MOZ_LOG_TEST(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug)
      40             : 
      41             : namespace mozilla {
      42             : namespace docshell {
      43             : 
      44             : //-----------------------------------------------------------------------------
      45             : // OfflineCacheUpdateParent::nsISupports
      46             : //-----------------------------------------------------------------------------
      47             : 
      48           0 : NS_IMPL_ISUPPORTS(OfflineCacheUpdateParent,
      49             :                   nsIOfflineCacheUpdateObserver,
      50             :                   nsILoadContext)
      51             : 
      52             : //-----------------------------------------------------------------------------
      53             : // OfflineCacheUpdateParent <public>
      54             : //-----------------------------------------------------------------------------
      55             : 
      56             : 
      57           0 : OfflineCacheUpdateParent::OfflineCacheUpdateParent()
      58           0 :     : mIPCClosed(false)
      59             : {
      60             :     // Make sure the service has been initialized
      61           0 :     nsOfflineCacheUpdateService::EnsureService();
      62             : 
      63           0 :     LOG(("OfflineCacheUpdateParent::OfflineCacheUpdateParent [%p]", this));
      64           0 : }
      65             : 
      66           0 : OfflineCacheUpdateParent::~OfflineCacheUpdateParent()
      67             : {
      68           0 :     LOG(("OfflineCacheUpdateParent::~OfflineCacheUpdateParent [%p]", this));
      69           0 : }
      70             : 
      71             : void
      72           0 : OfflineCacheUpdateParent::ActorDestroy(ActorDestroyReason why)
      73             : {
      74           0 :     mIPCClosed = true;
      75           0 : }
      76             : 
      77             : nsresult
      78           0 : OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI,
      79             :                                    const URIParams& aDocumentURI,
      80             :                                    const PrincipalInfo& aLoadingPrincipalInfo,
      81             :                                    const bool& stickDocument)
      82             : {
      83           0 :     LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this));
      84             : 
      85             :     nsresult rv;
      86             : 
      87           0 :     RefPtr<nsOfflineCacheUpdate> update;
      88           0 :     nsCOMPtr<nsIURI> manifestURI = DeserializeURI(aManifestURI);
      89           0 :     if (!manifestURI)
      90           0 :         return NS_ERROR_FAILURE;
      91             : 
      92           0 :     mLoadingPrincipal = PrincipalInfoToPrincipal(aLoadingPrincipalInfo, &rv);
      93           0 :     NS_ENSURE_SUCCESS(rv, rv);
      94             : 
      95             :     nsOfflineCacheUpdateService* service =
      96           0 :         nsOfflineCacheUpdateService::EnsureService();
      97           0 :     if (!service)
      98           0 :         return NS_ERROR_FAILURE;
      99             : 
     100           0 :     bool offlinePermissionAllowed = false;
     101             : 
     102           0 :     rv = service->OfflineAppAllowed(
     103             :         mLoadingPrincipal, nullptr, &offlinePermissionAllowed);
     104           0 :     NS_ENSURE_SUCCESS(rv, rv);
     105             : 
     106           0 :     if (!offlinePermissionAllowed)
     107           0 :         return NS_ERROR_DOM_SECURITY_ERR;
     108             : 
     109           0 :     nsCOMPtr<nsIURI> documentURI = DeserializeURI(aDocumentURI);
     110           0 :     if (!documentURI)
     111           0 :         return NS_ERROR_FAILURE;
     112             : 
     113           0 :     if (!NS_SecurityCompareURIs(manifestURI, documentURI, false))
     114           0 :         return NS_ERROR_DOM_SECURITY_ERR;
     115             : 
     116           0 :     nsAutoCString originSuffix;
     117           0 :     rv = mLoadingPrincipal->GetOriginSuffix(originSuffix);
     118           0 :     NS_ENSURE_SUCCESS(rv, rv);
     119             : 
     120           0 :     service->FindUpdate(manifestURI,
     121             :                         originSuffix,
     122             :                         nullptr,
     123           0 :                         getter_AddRefs(update));
     124           0 :     if (!update) {
     125           0 :         update = new nsOfflineCacheUpdate();
     126             : 
     127             :         // Leave aDocument argument null. Only glues and children keep
     128             :         // document instances.
     129           0 :         rv = update->Init(manifestURI, documentURI, mLoadingPrincipal, nullptr, nullptr);
     130           0 :         NS_ENSURE_SUCCESS(rv, rv);
     131             : 
     132             :         // Must add before Schedule() call otherwise we would miss
     133             :         // oncheck event notification.
     134           0 :         update->AddObserver(this, false);
     135             : 
     136           0 :         rv = update->Schedule();
     137           0 :         NS_ENSURE_SUCCESS(rv, rv);
     138             :     } else {
     139           0 :         update->AddObserver(this, false);
     140             :     }
     141             : 
     142           0 :     if (stickDocument) {
     143           0 :         nsCOMPtr<nsIURI> stickURI;
     144           0 :         documentURI->Clone(getter_AddRefs(stickURI));
     145           0 :         update->StickDocument(stickURI);
     146             :     }
     147             : 
     148           0 :     return NS_OK;
     149             : }
     150             : 
     151             : NS_IMETHODIMP
     152           0 : OfflineCacheUpdateParent::UpdateStateChanged(nsIOfflineCacheUpdate* aUpdate, uint32_t state)
     153             : {
     154           0 :     if (mIPCClosed)
     155           0 :         return NS_ERROR_UNEXPECTED;
     156             : 
     157           0 :     LOG(("OfflineCacheUpdateParent::StateEvent [%p]", this));
     158             : 
     159             :     uint64_t byteProgress;
     160           0 :     aUpdate->GetByteProgress(&byteProgress);
     161           0 :     Unused << SendNotifyStateEvent(state, byteProgress);
     162             : 
     163           0 :     if (state == nsIOfflineCacheUpdateObserver::STATE_FINISHED) {
     164             :         // Tell the child the particulars after the update has finished.
     165             :         // Sending the Finish event will release the child side of the protocol
     166             :         // and notify "offline-cache-update-completed" on the child process.
     167             :         bool isUpgrade;
     168           0 :         aUpdate->GetIsUpgrade(&isUpgrade);
     169             :         bool succeeded;
     170           0 :         aUpdate->GetSucceeded(&succeeded);
     171             : 
     172           0 :         Unused << SendFinish(succeeded, isUpgrade);
     173             :     }
     174             : 
     175           0 :     return NS_OK;
     176             : }
     177             : 
     178             : NS_IMETHODIMP
     179           0 : OfflineCacheUpdateParent::ApplicationCacheAvailable(nsIApplicationCache* aApplicationCache)
     180             : {
     181           0 :     if (mIPCClosed)
     182           0 :         return NS_ERROR_UNEXPECTED;
     183             : 
     184           0 :     NS_ENSURE_ARG(aApplicationCache);
     185             : 
     186           0 :     nsCString cacheClientId;
     187           0 :     aApplicationCache->GetClientID(cacheClientId);
     188           0 :     nsCString cacheGroupId;
     189           0 :     aApplicationCache->GetGroupID(cacheGroupId);
     190             : 
     191           0 :     Unused << SendAssociateDocuments(cacheGroupId, cacheClientId);
     192           0 :     return NS_OK;
     193             : }
     194             : 
     195             : //-----------------------------------------------------------------------------
     196             : // OfflineCacheUpdateParent::nsILoadContext
     197             : //-----------------------------------------------------------------------------
     198             : 
     199             : NS_IMETHODIMP
     200           0 : OfflineCacheUpdateParent::GetAssociatedWindow(mozIDOMWindowProxy** aAssociatedWindow)
     201             : {
     202           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     203             : }
     204             : 
     205             : NS_IMETHODIMP
     206           0 : OfflineCacheUpdateParent::GetTopWindow(mozIDOMWindowProxy** aTopWindow)
     207             : {
     208           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     209             : }
     210             : 
     211             : NS_IMETHODIMP
     212           0 : OfflineCacheUpdateParent::GetTopFrameElement(nsIDOMElement** aElement)
     213             : {
     214           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     215             : }
     216             : 
     217             : NS_IMETHODIMP
     218           0 : OfflineCacheUpdateParent::GetNestedFrameId(uint64_t* aId)
     219             : {
     220           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     221             : }
     222             : 
     223             : NS_IMETHODIMP
     224           0 : OfflineCacheUpdateParent::GetIsContent(bool* aIsContent)
     225             : {
     226           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     227             : }
     228             : 
     229             : NS_IMETHODIMP
     230           0 : OfflineCacheUpdateParent::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)
     231             : {
     232           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     233             : }
     234             : NS_IMETHODIMP
     235           0 : OfflineCacheUpdateParent::SetUsePrivateBrowsing(bool aUsePrivateBrowsing)
     236             : {
     237           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     238             : }
     239             : 
     240             : NS_IMETHODIMP
     241           0 : OfflineCacheUpdateParent::SetPrivateBrowsing(bool aUsePrivateBrowsing)
     242             : {
     243           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     244             : }
     245             : 
     246             : NS_IMETHODIMP
     247           0 : OfflineCacheUpdateParent::GetUseRemoteTabs(bool* aUseRemoteTabs)
     248             : {
     249           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     250             : }
     251             : 
     252             : NS_IMETHODIMP
     253           0 : OfflineCacheUpdateParent::SetRemoteTabs(bool aUseRemoteTabs)
     254             : {
     255           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     256             : }
     257             : 
     258             : NS_IMETHODIMP
     259           0 : OfflineCacheUpdateParent::GetIsInIsolatedMozBrowserElement(bool* aIsInIsolatedMozBrowserElement)
     260             : {
     261           0 :     NS_ENSURE_TRUE(mLoadingPrincipal, NS_ERROR_UNEXPECTED);
     262           0 :     return mLoadingPrincipal->GetIsInIsolatedMozBrowserElement(aIsInIsolatedMozBrowserElement);
     263             : }
     264             : 
     265             : NS_IMETHODIMP
     266           0 : OfflineCacheUpdateParent::GetScriptableOriginAttributes(JS::MutableHandleValue aAttrs)
     267             : {
     268           0 :     NS_ENSURE_TRUE(mLoadingPrincipal, NS_ERROR_UNEXPECTED);
     269             : 
     270           0 :     JSContext* cx = nsContentUtils::GetCurrentJSContext();
     271           0 :     MOZ_ASSERT(cx);
     272             : 
     273           0 :     nsresult rv = mLoadingPrincipal->GetOriginAttributes(cx, aAttrs);
     274           0 :     NS_ENSURE_SUCCESS(rv, rv);
     275             : 
     276           0 :     return NS_OK;
     277             : }
     278             : 
     279             : NS_IMETHODIMP_(void)
     280           0 : OfflineCacheUpdateParent::GetOriginAttributes(mozilla::OriginAttributes& aAttrs)
     281             : {
     282           0 :     if (mLoadingPrincipal) {
     283           0 :         aAttrs = mLoadingPrincipal->OriginAttributesRef();
     284             :     }
     285           0 : }
     286             : 
     287             : NS_IMETHODIMP
     288           0 : OfflineCacheUpdateParent::GetUseTrackingProtection(bool* aUseTrackingProtection)
     289             : {
     290           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     291             : }
     292             : 
     293             : NS_IMETHODIMP
     294           0 : OfflineCacheUpdateParent::SetUseTrackingProtection(bool aUseTrackingProtection)
     295             : {
     296           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     297             : }
     298             : 
     299             : } // namespace docshell
     300             : } // namespace mozilla

Generated by: LCOV version 1.13