WebBrowserPersistResourcesChild.cpp (2659B)
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 "WebBrowserPersistResourcesChild.h" 8 9 #include "WebBrowserPersistDocumentChild.h" 10 #include "mozilla/dom/PContentChild.h" 11 12 namespace mozilla { 13 14 NS_IMPL_ISUPPORTS(WebBrowserPersistResourcesChild, 15 nsIWebBrowserPersistResourceVisitor) 16 17 WebBrowserPersistResourcesChild::WebBrowserPersistResourcesChild() = default; 18 19 WebBrowserPersistResourcesChild::~WebBrowserPersistResourcesChild() = default; 20 21 NS_IMETHODIMP 22 WebBrowserPersistResourcesChild::VisitResource( 23 nsIWebBrowserPersistDocument* aDocument, const nsACString& aURI, 24 nsContentPolicyType aContentPolicyType) { 25 nsCString copiedURI(aURI); // Yay, XPIDL/IPDL mismatch. 26 SendVisitResource(copiedURI, aContentPolicyType); 27 return NS_OK; 28 } 29 30 NS_IMETHODIMP 31 WebBrowserPersistResourcesChild::VisitDocument( 32 nsIWebBrowserPersistDocument* aDocument, 33 nsIWebBrowserPersistDocument* aSubDocument) { 34 RefPtr<WebBrowserPersistDocumentChild> subActor = 35 new WebBrowserPersistDocumentChild(); 36 // As a consequence of how PWebBrowserPersistDocumentConstructor 37 // can be sent by both the parent and the child, we must pass the 38 // aBrowser and outerWindowID arguments here, but the values are 39 // ignored by the parent. In particular, the BrowserChild in which 40 // persistence started does not necessarily exist at this point; 41 // see bug 1203602. 42 if (!Manager()->Manager()->SendPWebBrowserPersistDocumentConstructor( 43 subActor, nullptr, nullptr)) { 44 return NS_ERROR_FAILURE; 45 } 46 47 // The order of these two messages will be preserved, because 48 // they're the same toplevel protocol and priority. 49 // 50 // With this ordering, it's always the transition out of START 51 // state that causes a document's parent actor to be exposed to 52 // XPCOM (for both parent->child and child->parent construction), 53 // which simplifies the lifetime management. 54 SendVisitDocument(WrapNotNull(subActor)); 55 subActor->Start(aSubDocument); 56 return NS_OK; 57 } 58 59 NS_IMETHODIMP 60 WebBrowserPersistResourcesChild::VisitBrowsingContext( 61 nsIWebBrowserPersistDocument* aDocument, 62 dom::BrowsingContext* aBrowsingContext) { 63 SendVisitBrowsingContext(aBrowsingContext); 64 return NS_OK; 65 } 66 67 NS_IMETHODIMP 68 WebBrowserPersistResourcesChild::EndVisit( 69 nsIWebBrowserPersistDocument* aDocument, nsresult aStatus) { 70 Send__delete__(this, aStatus); 71 return NS_OK; 72 } 73 74 } // namespace mozilla