summaryrefslogtreecommitdiffstats
path: root/dom/base/nsGlobalWindowOuter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/base/nsGlobalWindowOuter.cpp')
-rw-r--r--dom/base/nsGlobalWindowOuter.cpp83
1 files changed, 70 insertions, 13 deletions
diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp
index e28dcdb092..c678a0a941 100644
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -2414,6 +2414,11 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,
MOZ_RELEASE_ASSERT(newInnerWindow->mDoc == aDocument);
+ if (mBrowsingContext->IsTopContent()) {
+ net::CookieJarSettings::Cast(aDocument->CookieJarSettings())
+ ->SetTopLevelWindowContextId(aDocument->InnerWindowID());
+ }
+
newInnerWindow->RefreshReduceTimerPrecisionCallerType();
if (!aState) {
@@ -3468,9 +3473,17 @@ nsresult nsGlobalWindowOuter::GetInnerSize(CSSSize& aSize) {
aSize = CSSPixel::FromAppUnits(viewportSize);
- if (StaticPrefs::dom_innerSize_rounded()) {
- aSize.width = std::roundf(aSize.width);
- aSize.height = std::roundf(aSize.height);
+ switch (StaticPrefs::dom_innerSize_rounding()) {
+ case 1:
+ aSize.width = std::roundf(aSize.width);
+ aSize.height = std::roundf(aSize.height);
+ break;
+ case 2:
+ aSize.width = std::truncf(aSize.width);
+ aSize.height = std::truncf(aSize.height);
+ break;
+ default:
+ break;
}
return NS_OK;
@@ -4993,7 +5006,7 @@ void nsGlobalWindowOuter::PrintOuter(ErrorResult& aError) {
const bool forPreview = !StaticPrefs::print_always_print_silent();
Print(nullptr, nullptr, nullptr, nullptr, IsPreview(forPreview),
- IsForWindowDotPrint::Yes, nullptr, aError);
+ IsForWindowDotPrint::Yes, nullptr, nullptr, aError);
#endif
}
@@ -5015,7 +5028,8 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
nsIPrintSettings* aPrintSettings, RemotePrintJobChild* aRemotePrintJob,
nsIWebProgressListener* aListener, nsIDocShell* aDocShellToCloneInto,
IsPreview aIsPreview, IsForWindowDotPrint aForWindowDotPrint,
- PrintPreviewResolver&& aPrintPreviewCallback, ErrorResult& aError) {
+ PrintPreviewResolver&& aPrintPreviewCallback,
+ RefPtr<BrowsingContext>* aCachedBrowsingContext, ErrorResult& aError) {
#ifdef NS_PRINTING
nsCOMPtr<nsIPrintSettingsService> printSettingsService =
do_GetService("@mozilla.org/gfx/printsettings-service;1");
@@ -5051,16 +5065,36 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
nsCOMPtr<nsIDocumentViewer> viewer;
RefPtr<BrowsingContext> bc;
bool hasPrintCallbacks = false;
- if (docToPrint->IsStaticDocument()) {
+ bool wasStaticDocument = docToPrint->IsStaticDocument();
+ bool usingCachedBrowsingContext = false;
+ if (aCachedBrowsingContext && *aCachedBrowsingContext) {
+ MOZ_ASSERT(!wasStaticDocument,
+ "Why pass in non-empty aCachedBrowsingContext if original "
+ "document is already static?");
+ if (!wasStaticDocument) {
+ // The passed in document is not a static clone and the caller passed in a
+ // static clone to reuse, so swap it in.
+ docToPrint = (*aCachedBrowsingContext)->GetDocument();
+ MOZ_ASSERT(docToPrint);
+ MOZ_ASSERT(docToPrint->IsStaticDocument());
+ wasStaticDocument = true;
+ usingCachedBrowsingContext = true;
+ }
+ }
+ if (wasStaticDocument) {
if (aForWindowDotPrint == IsForWindowDotPrint::Yes) {
aError.ThrowNotSupportedError(
"Calling print() from a print preview is unsupported, did you intend "
"to call printPreview() instead?");
return nullptr;
}
- // We're already a print preview window, just reuse our browsing context /
- // content viewer.
- bc = sourceBC;
+ if (usingCachedBrowsingContext) {
+ bc = docToPrint->GetBrowsingContext();
+ } else {
+ // We're already a print preview window, just reuse our browsing context /
+ // content viewer.
+ bc = sourceBC;
+ }
nsCOMPtr<nsIDocShell> docShell = bc->GetDocShell();
if (!docShell) {
aError.ThrowNotSupportedError("No docshell");
@@ -5102,6 +5136,10 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
if (NS_WARN_IF(aError.Failed())) {
return nullptr;
}
+ if (aCachedBrowsingContext) {
+ MOZ_ASSERT(!*aCachedBrowsingContext);
+ *aCachedBrowsingContext = bc;
+ }
}
if (!bc) {
aError.ThrowNotAllowedError("No browsing context");
@@ -5157,6 +5195,24 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
"Content viewer didn't implement nsIWebBrowserPrint");
return nullptr;
}
+ bool closeWindowAfterPrint;
+ if (wasStaticDocument) {
+ // Here the document was a static clone to begin with that this code did not
+ // create, so we should not clean it up.
+ // The exception is if we're using the passed-in aCachedBrowsingContext, in
+ // which case this is the second print with this static document clone that
+ // we created the first time through, and we are responsible for cleaning it
+ // up.
+ closeWindowAfterPrint = usingCachedBrowsingContext;
+ } else {
+ // In this case the document was not a static clone, so we made a static
+ // clone for printing purposes and must clean it up after the print is done.
+ // The exception is if aCachedBrowsingContext is non-NULL, meaning the
+ // caller is intending to print this document again, so we need to defer the
+ // cleanup until after the second print.
+ closeWindowAfterPrint = !aCachedBrowsingContext;
+ }
+ webBrowserPrint->SetCloseWindowAfterPrint(closeWindowAfterPrint);
// For window.print(), we postpone making these calls until the round-trip to
// the parent process (triggered by the OpenInternal call above) calls us
@@ -5953,10 +6009,11 @@ void nsGlobalWindowOuter::CloseOuter(bool aTrustedCaller) {
if (!allowClose) {
// We're blocking the close operation
// report localized error msg in JS console
- nsContentUtils::ReportToConsole(
- nsIScriptError::warningFlag, "DOM Window"_ns,
- mDoc, // Better name for the category?
- nsContentUtils::eDOM_PROPERTIES, "WindowCloseBlockedWarning");
+ nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
+ "DOM Window"_ns,
+ mDoc, // Better name for the category?
+ nsContentUtils::eDOM_PROPERTIES,
+ "WindowCloseByScriptBlockedWarning");
return;
}