@@ -306,9 +306,10 @@ static void DecreasePrivateDocShellCount() {
306306 }
307307}
308308
309- nsDocShell::nsDocShell (BrowsingContext* aBrowsingContext)
309+ nsDocShell::nsDocShell (BrowsingContext* aBrowsingContext,
310+ uint64_t aContentWindowID)
310311 : nsDocLoader(),
311- mContentWindowID(nsContentUtils::GenerateWindowId() ),
312+ mContentWindowID(aContentWindowID ),
312313 mBrowsingContext(aBrowsingContext),
313314 mForcedCharset(nullptr ),
314315 mParentCharset(nullptr ),
@@ -394,6 +395,11 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext)
394395
395396 nsContentUtils::GenerateUUIDInPlace (mHistoryID );
396397
398+ // If no outer window ID was provided, generate a new one.
399+ if (aContentWindowID == 0 ) {
400+ mContentWindowID = nsContentUtils::GenerateWindowId ();
401+ }
402+
397403 if (gDocShellCount ++ == 0 ) {
398404 NS_ASSERTION (sURIFixup == nullptr ,
399405 " Huh, sURIFixup not null in first nsDocShell ctor!" );
@@ -460,11 +466,11 @@ nsDocShell::~nsDocShell() {
460466
461467/* static */
462468already_AddRefed<nsDocShell> nsDocShell::Create (
463- BrowsingContext* aBrowsingContext) {
469+ BrowsingContext* aBrowsingContext, uint64_t aContentWindowID ) {
464470 MOZ_ASSERT (aBrowsingContext, " DocShell without a BrowsingContext!" );
465471
466472 nsresult rv;
467- RefPtr<nsDocShell> ds = new nsDocShell (aBrowsingContext);
473+ RefPtr<nsDocShell> ds = new nsDocShell (aBrowsingContext, aContentWindowID );
468474
469475 // Initialize the underlying nsDocLoader.
470476 rv = ds->nsDocLoader ::Init ();
@@ -518,6 +524,7 @@ already_AddRefed<nsDocShell> nsDocShell::Create(
518524
519525 // Make |ds| the primary DocShell for the given context.
520526 aBrowsingContext->SetDocShell (ds);
527+
521528 return ds.forget ();
522529}
523530
@@ -6243,12 +6250,13 @@ nsresult nsDocShell::RefreshURIFromQueue() {
62436250 return NS_OK ;
62446251}
62456252
6246- nsresult nsDocShell::Embed (nsIContentViewer* aContentViewer) {
6253+ nsresult nsDocShell::Embed (nsIContentViewer* aContentViewer,
6254+ WindowGlobalChild* aWindowActor) {
62476255 // Save the LayoutHistoryState of the previous document, before
62486256 // setting up new document
62496257 PersistLayoutHistoryState ();
62506258
6251- nsresult rv = SetupNewViewer (aContentViewer);
6259+ nsresult rv = SetupNewViewer (aContentViewer, aWindowActor );
62526260 NS_ENSURE_SUCCESS (rv, rv);
62536261
62546262 // XXX What if SetupNewViewer fails?
@@ -6884,6 +6892,7 @@ nsresult nsDocShell::EnsureContentViewer() {
68846892 nsCOMPtr<nsIURI> baseURI;
68856893 nsIPrincipal* principal = GetInheritedPrincipal (false );
68866894 nsIPrincipal* storagePrincipal = GetInheritedPrincipal (false , true );
6895+
68876896 nsCOMPtr<nsIDocShellTreeItem> parentItem;
68886897 GetInProcessSameTypeParent (getter_AddRefs (parentItem));
68896898 if (parentItem) {
@@ -6925,11 +6934,14 @@ nsresult nsDocShell::EnsureContentViewer() {
69256934nsresult nsDocShell::CreateAboutBlankContentViewer (
69266935 nsIPrincipal* aPrincipal, nsIPrincipal* aStoragePrincipal,
69276936 nsIContentSecurityPolicy* aCSP, nsIURI* aBaseURI,
6928- bool aTryToSaveOldPresentation, bool aCheckPermitUnload) {
6937+ bool aTryToSaveOldPresentation, bool aCheckPermitUnload,
6938+ WindowGlobalChild* aActor) {
69296939 RefPtr<Document> blankDoc;
69306940 nsCOMPtr<nsIContentViewer> viewer;
69316941 nsresult rv = NS_ERROR_FAILURE ;
69326942
6943+ MOZ_ASSERT_IF (aActor, aActor->DocumentPrincipal () == aPrincipal);
6944+
69336945 /* mCreatingDocument should never be true at this point. However, it's
69346946 a theoretical possibility. We want to know about it and make it stop,
69356947 and this sounds like a job for an assertion. */
@@ -7058,7 +7070,7 @@ nsresult nsDocShell::CreateAboutBlankContentViewer(
70587070 // hook 'em up
70597071 if (viewer) {
70607072 viewer->SetContainer (this );
7061- rv = Embed (viewer);
7073+ rv = Embed (viewer, aActor );
70627074 NS_ENSURE_SUCCESS (rv, rv);
70637075
70647076 SetCurrentURI (blankDoc->GetDocumentURI (), nullptr , true , 0 );
@@ -7088,6 +7100,32 @@ nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,
70887100 nullptr );
70897101}
70907102
7103+ nsresult nsDocShell::CreateContentViewerForActor (
7104+ WindowGlobalChild* aWindowActor) {
7105+ MOZ_ASSERT (aWindowActor);
7106+
7107+ // FIXME: WindowGlobalChild should provide the StoragePrincipal.
7108+ nsresult rv = CreateAboutBlankContentViewer (
7109+ aWindowActor->DocumentPrincipal (), aWindowActor->DocumentPrincipal (),
7110+ /* aCsp */ nullptr ,
7111+ /* aBaseURI */ nullptr ,
7112+ /* aTryToSaveOldPresentation */ true ,
7113+ /* aCheckPermitUnload */ true , aWindowActor);
7114+ if (NS_SUCCEEDED (rv)) {
7115+ RefPtr<Document> doc (GetDocument ());
7116+ MOZ_ASSERT (
7117+ doc,
7118+ " Should have a document if CreateAboutBlankContentViewer succeeded" );
7119+ MOZ_ASSERT (doc->GetOwnerGlobal () == aWindowActor->WindowGlobal (),
7120+ " New document should be in the same global as our actor" );
7121+
7122+ // FIXME: We may want to support non-initial documents here.
7123+ doc->SetIsInitialDocument (true );
7124+ }
7125+
7126+ return rv;
7127+ }
7128+
70917129bool nsDocShell::CanSavePresentation (uint32_t aLoadType,
70927130 nsIRequest* aNewRequest,
70937131 Document* aNewDocument) {
@@ -8293,7 +8331,8 @@ nsresult nsDocShell::NewContentViewerObj(const nsACString& aContentType,
82938331 return NS_OK ;
82948332}
82958333
8296- nsresult nsDocShell::SetupNewViewer (nsIContentViewer* aNewViewer) {
8334+ nsresult nsDocShell::SetupNewViewer (nsIContentViewer* aNewViewer,
8335+ WindowGlobalChild* aWindowActor) {
82978336 MOZ_ASSERT (!mIsBeingDestroyed );
82988337
82998338 //
@@ -8417,7 +8456,7 @@ nsresult nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer) {
84178456
84188457 mContentViewer ->SetNavigationTiming (mTiming );
84198458
8420- if (NS_FAILED (mContentViewer ->Init (widget, bounds))) {
8459+ if (NS_FAILED (mContentViewer ->Init (widget, bounds, aWindowActor ))) {
84218460 mContentViewer = nullptr ;
84228461 NS_WARNING (" ContentViewer Initialization failed" );
84238462 return NS_ERROR_FAILURE ;
0 commit comments