tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WebBrowserPersistResourcesParent.cpp (3179B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 *
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "WebBrowserPersistResourcesParent.h"
      8 
      9 #include "mozilla/dom/BrowserParent.h"
     10 #include "mozilla/dom/CanonicalBrowsingContext.h"
     11 #include "mozilla/dom/ContentParent.h"
     12 #include "mozilla/dom/WindowGlobalParent.h"
     13 #include "nsThreadUtils.h"
     14 
     15 namespace mozilla {
     16 
     17 NS_IMPL_ISUPPORTS(WebBrowserPersistResourcesParent,
     18                  nsIWebBrowserPersistDocumentReceiver)
     19 
     20 WebBrowserPersistResourcesParent::WebBrowserPersistResourcesParent(
     21    nsIWebBrowserPersistDocument* aDocument,
     22    nsIWebBrowserPersistResourceVisitor* aVisitor)
     23    : mDocument(aDocument), mVisitor(aVisitor) {
     24  MOZ_ASSERT(aDocument);
     25  MOZ_ASSERT(aVisitor);
     26 }
     27 
     28 WebBrowserPersistResourcesParent::~WebBrowserPersistResourcesParent() = default;
     29 
     30 void WebBrowserPersistResourcesParent::ActorDestroy(ActorDestroyReason aWhy) {
     31  if (aWhy != Deletion && mVisitor) {
     32    // See comment in WebBrowserPersistDocumentParent::ActorDestroy
     33    // (or bug 1202887) for why this is deferred.
     34    nsCOMPtr<nsIRunnable> errorLater =
     35        NewRunnableMethod<nsCOMPtr<nsIWebBrowserPersistDocument>, nsresult>(
     36            "nsIWebBrowserPersistResourceVisitor::EndVisit", mVisitor,
     37            &nsIWebBrowserPersistResourceVisitor::EndVisit, mDocument,
     38            NS_ERROR_FAILURE);
     39    NS_DispatchToCurrentThread(errorLater);
     40  }
     41  mVisitor = nullptr;
     42 }
     43 
     44 mozilla::ipc::IPCResult WebBrowserPersistResourcesParent::Recv__delete__(
     45    const nsresult& aStatus) {
     46  mVisitor->EndVisit(mDocument, aStatus);
     47  mVisitor = nullptr;
     48  return IPC_OK();
     49 }
     50 
     51 mozilla::ipc::IPCResult WebBrowserPersistResourcesParent::RecvVisitResource(
     52    const nsACString& aURI, const nsContentPolicyType& aContentPolicyType) {
     53  mVisitor->VisitResource(mDocument, aURI, aContentPolicyType);
     54  return IPC_OK();
     55 }
     56 
     57 mozilla::ipc::IPCResult WebBrowserPersistResourcesParent::RecvVisitDocument(
     58    NotNull<PWebBrowserPersistDocumentParent*> aSubDocument) {
     59  // Don't expose the subdocument to the visitor until it's ready
     60  // (until the actor isn't in START state).
     61  static_cast<WebBrowserPersistDocumentParent*>(aSubDocument.get())
     62      ->SetOnReady(this);
     63  return IPC_OK();
     64 }
     65 
     66 mozilla::ipc::IPCResult
     67 WebBrowserPersistResourcesParent::RecvVisitBrowsingContext(
     68    const dom::MaybeDiscarded<dom::BrowsingContext>& aContext) {
     69  if (aContext.IsNullOrDiscarded()) {
     70    // Nothing useful to do but ignore the discarded context.
     71    return IPC_OK();
     72  }
     73 
     74  mVisitor->VisitBrowsingContext(mDocument, aContext.get());
     75  return IPC_OK();
     76 }
     77 
     78 NS_IMETHODIMP
     79 WebBrowserPersistResourcesParent::OnDocumentReady(
     80    nsIWebBrowserPersistDocument* aSubDocument) {
     81  if (!mVisitor) {
     82    return NS_ERROR_FAILURE;
     83  }
     84  mVisitor->VisitDocument(mDocument, aSubDocument);
     85  return NS_OK;
     86 }
     87 
     88 NS_IMETHODIMP
     89 WebBrowserPersistResourcesParent::OnError(nsresult aFailure) {
     90  // Nothing useful to do but ignore the failed document.
     91  return NS_OK;
     92 }
     93 
     94 }  // namespace mozilla