Backed out changeset bc3a104f8b20 (bug 1602410) for build bustages on nsGlobalWindowOuter.cpp . CLOSED TREE

This commit is contained in:
Narcis Beleuzu 2019-12-21 04:13:43 +02:00
Родитель 8b48782ea2
Коммит bd3cee1d8c
3 изменённых файлов: 58 добавлений и 61 удалений

Просмотреть файл

@ -25,7 +25,6 @@
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/dom/ContentFrameMessageManager.h"
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/JSWindowActorChild.h"
#include "mozilla/dom/LocalStorage.h"
#include "mozilla/dom/LSObject.h"
#include "mozilla/dom/Storage.h"
@ -4975,60 +4974,70 @@ void nsGlobalWindowOuter::PrintOuter(ErrorResult& aError) {
return;
}
nsCOMPtr<nsIPrintSettingsService> printSettingsService =
do_GetService("@mozilla.org/gfx/printsettings-service;1");
if (!printSettingsService) {
aError.Throw(NS_ERROR_NOT_AVAILABLE);
return;
}
nsCOMPtr<nsIWebBrowserPrint> webBrowserPrint;
if (NS_SUCCEEDED(GetInterface(NS_GET_IID(nsIWebBrowserPrint),
getter_AddRefs(webBrowserPrint)))) {
nsAutoSyncOperation sync(GetCurrentInnerWindowInternal()
? GetCurrentInnerWindowInternal()->mDoc.get()
: nullptr);
WindowGlobalChild* wgc = mInnerWindow->GetWindowGlobalChild();
if (!wgc) {
aError.Throw(NS_ERROR_NOT_AVAILABLE);
return;
}
nsCOMPtr<nsIPrintSettingsService> printSettingsService =
do_GetService("@mozilla.org/gfx/printsettings-service;1");
RefPtr<JSWindowActorChild> actor =
wgc->GetActor(NS_LITERAL_STRING("BrowserElement"), IgnoreErrors());
if (!actor) {
aError.Throw(NS_ERROR_NOT_AVAILABLE);
return;
}
nsCOMPtr<nsIPrintSettings> printSettings;
if (printSettingsService) {
bool printSettingsAreGlobal =
Preferences::GetBool("print.use_global_printsettings", false);
bool havePrintableSelection = false;
if (!mDoc->GetRootElement()->HasAttr(kNameSpaceID_None,
nsGkAtoms::mozdisallowselectionprint)) {
if (Selection* selection = GetSelectionOuter()) {
if (int32_t rangeCount = selection->RangeCount()) {
havePrintableSelection =
rangeCount > 1 ||
// check to make sure it isn't an insertion selection
(selection->GetRangeAt(0) && !selection->IsCollapsed());
if (printSettingsAreGlobal) {
printSettingsService->GetGlobalPrintSettings(
getter_AddRefs(printSettings));
nsAutoString printerName;
printSettings->GetPrinterName(printerName);
bool shouldGetDefaultPrinterName = printerName.IsEmpty();
# ifdef MOZ_X11
// In Linux, GTK backend does not support per printer settings.
// Calling GetDefaultPrinterName causes a sandbox violation (see Bug
// 1329216). The printer name is not needed anywhere else on Linux
// before it gets to the parent. In the parent, we will then query the
// default printer name if no name is set. Unless we are in the parent,
// we will skip this part.
if (!XRE_IsParentProcess()) {
shouldGetDefaultPrinterName = false;
}
# endif
if (shouldGetDefaultPrinterName) {
printSettingsService->GetDefaultPrinterName(printerName);
printSettings->SetPrinterName(printerName);
}
printSettingsService->InitPrintSettingsFromPrinter(printerName,
printSettings);
printSettingsService->InitPrintSettingsFromPrefs(
printSettings, true, nsIPrintSettings::kInitSaveAll);
} else {
printSettingsService->GetNewPrintSettings(
getter_AddRefs(printSettings));
}
EnterModalState();
webBrowserPrint->Print(printSettings, nullptr);
LeaveModalState();
bool savePrintSettings =
Preferences::GetBool("print.save_print_settings", false);
if (printSettingsAreGlobal && savePrintSettings) {
printSettingsService->SavePrintSettingsToPrefs(
printSettings, true, nsIPrintSettings::kInitSaveAll);
printSettingsService->SavePrintSettingsToPrefs(
printSettings, false, nsIPrintSettings::kInitSavePrinterName);
}
} else {
webBrowserPrint->GetGlobalPrintSettings(getter_AddRefs(printSettings));
webBrowserPrint->Print(printSettings, nullptr);
}
}
// We don't init the AutoJSAPI with ourselves because we don't want it
// reporting errors to our onerror handlers.
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
JSAutoRealm ar(cx, actor->GetParentObject()->GetGlobalJSObject());
// The frontend code doesn't yet make use of the `data` we send here, but it
// will do in future work in order to avoid a roundtrip to the content
// process.
// Note: if we want more complex detail, create something like
// DOMWindowResizeEventDetail.
JS::Rooted<JS::Value> msgData(cx, JS::NumberValue(havePrintableSelection));
IgnoredErrorResult res;
actor->SendAsyncMessage(cx, NS_LITERAL_STRING("ContentRequestedPrint"),
msgData, res);
if (res.Failed()) {
aError.Throw(NS_ERROR_NOT_AVAILABLE);
return;
}
#endif // NS_PRINTING
}

Просмотреть файл

@ -1,5 +1,4 @@
[print-microtask-after-navigate.html]
disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1569400#c22
expected:
if (os == "android") and not debug: ["ERROR", "OK"]
if (os == "android") and debug: ERROR

Просмотреть файл

@ -91,17 +91,6 @@ class BrowserElementParent extends JSWindowActorParent {
}
break;
}
case "ContentRequestedPrint": {
// Note: this is not yet fully Fission compatible. That requires
// further work to change the PrintUtils API and the underlying code
// that it uses.
let bc = this.manager.browsingContext;
let topWin = bc.top.embedderElement.ownerGlobal;
if (topWin.PrintUtils) {
topWin.PrintUtils.printWindow(bc);
}
break;
}
}
}
}