Skip to content

Commit

Permalink
Bug 1653354 - Make the WebExtensions API tabs.saveAsPDF work via the …
Browse files Browse the repository at this point in the history
…Cocoa printing code on macOS. r=jwatt,extension-reviewers,zombie

Differential Revision: https://phabricator.services.mozilla.com/D85891
  • Loading branch information
jfkthame committed Aug 4, 2020
1 parent 6b32e38 commit 218e91a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
5 changes: 0 additions & 5 deletions browser/components/extensions/parent/ext-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
1 change: 0 additions & 1 deletion browser/components/extensions/test/browser/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 5 additions & 1 deletion widget/cocoa/nsPrintSettingsServiceX.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
12 changes: 10 additions & 2 deletions widget/cocoa/nsPrintSettingsX.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 218e91a

Please sign in to comment.