From 218e91ac979b59d23af6585d8751fcf35a5728c2 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Tue, 4 Aug 2020 16:58:20 +0000 Subject: [PATCH] Bug 1653354 - Make the WebExtensions API tabs.saveAsPDF work via the Cocoa printing code on macOS. r=jwatt,extension-reviewers,zombie Differential Revision: https://phabricator.services.mozilla.com/D85891 --- browser/components/extensions/parent/ext-tabs.js | 5 ----- .../components/extensions/test/browser/browser.ini | 1 - widget/cocoa/nsPrintSettingsServiceX.mm | 6 +++++- widget/cocoa/nsPrintSettingsX.mm | 12 ++++++++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/browser/components/extensions/parent/ext-tabs.js b/browser/components/extensions/parent/ext-tabs.js index c14df61416eee..b455b0d9d0459 100644 --- a/browser/components/extensions/parent/ext-tabs.js +++ b/browser/components/extensions/parent/ext-tabs.js @@ -1292,11 +1292,6 @@ this.tabs = class extends ExtensionAPI { let title = strBundle.GetStringFromName( "saveaspdf.saveasdialog.title" ); - - if (AppConstants.platform === "macosx") { - return Promise.reject({ message: "Not supported on Mac OS X" }); - } - let filename; if ( pageSettings.toFileName !== null && diff --git a/browser/components/extensions/test/browser/browser.ini b/browser/components/extensions/test/browser/browser.ini index 7e0a42be26294..a0bb887e7acd3 100644 --- a/browser/components/extensions/test/browser/browser.ini +++ b/browser/components/extensions/test/browser/browser.ini @@ -264,7 +264,6 @@ skip-if = !e10s [browser_ext_tabs_reload.js] [browser_ext_tabs_reload_bypass_cache.js] [browser_ext_tabs_saveAsPDF.js] -skip-if = os == 'mac' # Save as PDF not supported on Mac OS X [browser_ext_tabs_sendMessage.js] [browser_ext_tabs_sharingState.js] [browser_ext_tabs_successors.js] diff --git a/widget/cocoa/nsPrintSettingsServiceX.mm b/widget/cocoa/nsPrintSettingsServiceX.mm index cbaa959e98a04..59d6b350c6e4b 100644 --- a/widget/cocoa/nsPrintSettingsServiceX.mm +++ b/widget/cocoa/nsPrintSettingsServiceX.mm @@ -65,7 +65,11 @@ NSURL* printToFileURL = [dict objectForKey:NSPrintJobSavingURL]; if (printToFileURL) { - nsCocoaUtils::GetStringForNSString([printToFileURL absoluteString], data -> toFileName()); + if ([printToFileURL isFileURL]) { + nsCocoaUtils::GetStringForNSString([printToFileURL path], data->toFileName()); + } else { + MOZ_ASSERT_UNREACHABLE("expected a file URL"); + } } NSDate* printTime = [dict objectForKey:NSPrintTime]; diff --git a/widget/cocoa/nsPrintSettingsX.mm b/widget/cocoa/nsPrintSettingsX.mm index 8323339e86600..60c5c6777fefc 100644 --- a/widget/cocoa/nsPrintSettingsX.mm +++ b/widget/cocoa/nsPrintSettingsX.mm @@ -235,8 +235,16 @@ NS_IMETHODIMP nsPrintSettingsX::GetEffectivePageSize(double* aWidth, double* aHeight) { - *aWidth = NS_INCHES_TO_TWIPS(mAdjustedPaperWidth / mWidthScale); - *aHeight = NS_INCHES_TO_TWIPS(mAdjustedPaperHeight / mHeightScale); + if (kPaperSizeInches == GetCocoaUnit(mPaperSizeUnit)) { + *aWidth = NS_INCHES_TO_TWIPS(mAdjustedPaperWidth / mWidthScale); + *aHeight = NS_INCHES_TO_TWIPS(mAdjustedPaperHeight / mHeightScale); + } else { + *aWidth = NS_MILLIMETERS_TO_TWIPS(mAdjustedPaperWidth / mWidthScale); + *aHeight = NS_MILLIMETERS_TO_TWIPS(mAdjustedPaperHeight / mHeightScale); + } + if (kLandscapeOrientation == mOrientation) { + std::swap(*aWidth, *aHeight); + } return NS_OK; }