diff --git a/src/sap.m/src/sap/m/PDFViewer.js b/src/sap.m/src/sap/m/PDFViewer.js index 7d15a58da118..443ee7751c52 100644 --- a/src/sap.m/src/sap/m/PDFViewer.js +++ b/src/sap.m/src/sap/m/PDFViewer.js @@ -129,10 +129,10 @@ sap.ui.define([ displayType: {type: "sap.m.PDFViewerDisplayType", group: "Misc", defaultValue: PDFViewerDisplayType.Auto}, /** * Parameter to determine if the given PDF is from a trusted source. If the source is valid this property can be set to true. - * If isTrustedSource is set to true, the PDFViewer opens with the displayType set to "Embedded" on desktop devices, which means that the PDF content is directly shown within the PDFViewer. Set this property to true only when the PDF is generated by the application or the PDF is scanned for viruses. - * If isTrustedSource is set to false, the PDFViewer opens with the displayType set to "Link" on desktop devices, which overrides any configuration that has been provided by the application for the property displayType. This means that the PDFViewer appears as a toolbar with a download button. + * If isTrustedSource is set to true, the PDFViewer opens with the displayType set to "Embedded" on desktop devices. This means that the PDF content is directly shown within the PDFViewer. Set this property to true only when the PDF is generated by the application or the PDF is scanned for viruses. + * If isTrustedSource is set to false, the PDFViewer opens with the displayType set to "Link" on desktop devices. This means that any configuration that has been provided by the application for the property displayType is overridden. In this case, the user would need to download the PDF to view its content. */ - isTrustedSource: {type: "boolean", group: "Misc", defaultValue: true} + isTrustedSource: {type: "boolean", group: "Misc", defaultValue: false} }, aggregations: { /** @@ -144,7 +144,12 @@ sap.ui.define([ * A multiple aggregation for buttons that can be added to the footer of the popup * dialog. Works only if the PDF viewer is set to open in a popup dialog. */ - popupButtons: {type: "sap.m.Button", multiple: true, singularName: "popupButton"} + popupButtons: {type: "sap.m.Button", multiple: true, singularName: "popupButton"}, + /** + * A message page is displayed when the property isTrustedSource = false + * @private + */ + _nonTrustedMessagePage: { type: "sap.m.MessagePage", multiple: false, visibility: "hidden" } }, events: { /** @@ -192,7 +197,7 @@ sap.ui.define([ this._initPopupControl(); this._initPopupDownloadButtonControl(); - this._initPlaceholderMessagePageControl(); + this._initErrorPlaceholderMessagePageControl(); this._initToolbarDownloadButtonControl(); this._initOverflowToolbarControl(); @@ -235,15 +240,11 @@ sap.ui.define([ }; PDFViewer.prototype.onBeforeRendering = function () { - // IE things + // IE things // because of the detecting error state in IE (double call of unload listener) // it is important to reset the flag before each render // otherwise it wrongly detects error state (the unload listener is called once even in valid use case) this._bOnBeforeUnloadFired = false; - if (!this.getIsTrustedSource() && !this._isDisplayTypeLink()) { - this.sInitialDisplayType = this.getDisplayType(); - this.setProperty("displayType", PDFViewerDisplayType.Link, true); - } }; /** @@ -252,9 +253,6 @@ sap.ui.define([ * @private */ PDFViewer.prototype.onAfterRendering = function () { - if (this.sInitialDisplayType) { - this.setProperty("displayType", this.sInitialDisplayType, true); - } var fnInitIframeElement = function () { // cant use attachBrowserEvent because it attach event to component root node (this.$()) // load event does not bubble so it has to be bind directly to iframe element @@ -520,9 +518,6 @@ sap.ui.define([ * @public */ PDFViewer.prototype.open = function () { - if (!this.getIsTrustedSource() && !this._isDisplayTypeLink()) { - this.setProperty("displayType", PDFViewerDisplayType.Link, true); - } if (!this._isSourceValidToDisplay()) { assert(false, "The PDF file cannot be opened with the given source. Given source: " + this.getSource()); return; @@ -530,7 +525,7 @@ sap.ui.define([ Log.warning("The PDF plug-in is not available on this device."); } - if (this._isEmbeddedModeAllowed()) { + if (this._isEmbeddedModeAllowed() && this.getIsTrustedSource()) { this._openOnDesktop(); } else { this._openOnMobile(); diff --git a/src/sap.m/src/sap/m/PDFViewerRenderManager.js b/src/sap.m/src/sap/m/PDFViewerRenderManager.js index 81bff0658d47..5608901c253e 100644 --- a/src/sap.m/src/sap/m/PDFViewerRenderManager.js +++ b/src/sap.m/src/sap/m/PDFViewerRenderManager.js @@ -116,9 +116,9 @@ sap.ui.define([ } }; - PDFViewer.prototype._initPlaceholderMessagePageControl = function () { + PDFViewer.prototype._initErrorPlaceholderMessagePageControl = function () { var that = this, - sPlaceholderMessagePageFactoryFunctionName = "getPlaceholderMessagePageControl"; + sPlaceholderMessagePageFactoryFunctionName = "getErrorPlaceholderMessagePageControl"; this._objectsRegister[sPlaceholderMessagePageFactoryFunctionName] = function () { var oMessagePage = new MessagePage({ @@ -129,7 +129,6 @@ sap.ui.define([ that._objectsRegister[sPlaceholderMessagePageFactoryFunctionName] = function () { oMessagePage.setText(that._getMessagePageErrorMessage()); - return oMessagePage; }; @@ -235,6 +234,23 @@ sap.ui.define([ }; }; + + PDFViewer.prototype._getNonTrustedSourceMessage = function () { + var oButtonContent = this._objectsRegister.getPopupDownloadButtonControl(), + oMessagePage = this.getAggregation("_nonTrustedMessagePage"); + + if (!oMessagePage) { + oMessagePage = new MessagePage({ + showHeader: false, + text: this._getLibraryResourceBundle().getText("PDF_VIEWER_NONTRUSTEDSOURCEMESSAGE_TITLE"), + icon: "sap-icon://download", + buttons: [oButtonContent], + description: "" + }); + this.setAggregation("_nonTrustedMessagePage", oMessagePage); + } + return oMessagePage; + }; } }; diff --git a/src/sap.m/src/sap/m/PDFViewerRenderer.js b/src/sap.m/src/sap/m/PDFViewerRenderer.js index 8ad883601dba..e728d1595ffb 100644 --- a/src/sap.m/src/sap/m/PDFViewerRenderer.js +++ b/src/sap.m/src/sap/m/PDFViewerRenderer.js @@ -99,14 +99,20 @@ sap.ui.define(['sap/ui/Device', "sap/base/Log"], } /** - * if displayType is not link and pdfPlugin is not enabled .. render error content. - * case: if "Always download pdf's" option is enabled in browser setting.. in that - * case display error content (to retain control behaviour) + * Case1: If display is in Embedded Mode, PDF Plugin is disabled and is Desktop Device, We render Error Content. + * Case2: If display is in Embedded Mode and PDF Plugin is enabled, We render PDF Content. + * Case3: If display is in Embedded Mode, PDF Plugin is enabled and isTrustedSource = false, We render NonTrustedSource Content. */ - if (!oControl._isDisplayTypeLink() && !this._isPdfPluginEnabled() && Device.system.desktop) { - this.renderErrorContent(oRm, oControl); - } else if (oControl._isEmbeddedModeAllowed() && this._isPdfPluginEnabled()) { - this.renderPdfContent(oRm, oControl); + var bRenderEmbededMode = (oControl._isDisplayTypeEmbedded() || oControl._isDisplayTypeAuto()) && Device.system.desktop; + + if (bRenderEmbededMode) { + if (!this._isPdfPluginEnabled()) { + this.renderErrorContent(oRm, oControl); + } else if (!oControl.getIsTrustedSource()) { + this.renderNonTrustedSourceContent(oRm, oControl); + } else { + this.renderPdfContent(oRm, oControl); + } } oRm.write(""); @@ -135,7 +141,7 @@ sap.ui.define(['sap/ui/Device', "sap/base/Log"], PDFViewerRenderer.renderErrorContent = function (oRm, oControl) { var oErrorContent = oControl.getErrorPlaceholder() ? oControl.getErrorPlaceholder() : - oControl._objectsRegister.getPlaceholderMessagePageControl(); + oControl._objectsRegister.getErrorPlaceholderMessagePageControl(); oRm.write("