/*************************************************************************
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2015 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by all applicable intellectual property laws,
* including trade secret and or copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
var $iframe,$newiframe,$fteIframe,disableKeyZoom,disableWheelZoom;const newIframeTop=150,docUrl=document.location.href;function GetChromeMenuDimensions(e,t){const i=t.version>SETTINGS.READER_VER,n=t.version==SETTINGS.READER_VER,o=t.panel_op,s={width:0,height:0};if("searchWidget"===e)switch(o){case"html_menu":case"status":case"test":i?(s.width=259,s.height=450):(s.width=294,s.height=624);break;case"pdf_menu":n?(s.width=294,s.height=350):i?(s.width=259,s.height=400):(s.width=294,s.height=160);break;case"load-frictionless":s.width=294,s.height=521}else"persistent"===e&&"pdf_menu"===o?(s.width=350,s.height=280):"fte"===e?(s.width=365,s.height=510):"downloadBanner"===e?(s.width="100%",s.height="100px"):"successToast"===e&&(s.width="450px",s.height="50px");return s}function GetEdgeMenuDimensions(e,t){const i=t.version>SETTINGS.READER_VER,n=t.version==SETTINGS.READER_VER,o=t.panel_op,s={width:0,height:0};if("searchWidget"===e)switch(o){case"html_menu":case"status":case"test":i?(s.width=259,s.height=450):(s.width=294,s.height=624);break;case"pdf_menu":n?(s.width=294,s.height=350):i?(s.width=294,s.height=400):(s.width=294,s.height=180);break;case"load-frictionless":s.width=294,s.height=550}else"persistent"===e&&"pdf_menu"===o?SETTINGS.IS_BETA||!i?(s.width=350,s.height=280):i&&(s.width=200,s.height=50):"fte"===e?(s.width=302,s.height=510):"downloadBanner"===e?(s.width="100%",s.height="100px"):"successToast"===e&&(s.width="450px",s.height="50px");return s}function GetMenuDimensions(e,t){return t.is_edge?GetEdgeMenuDimensions(e,t):GetChromeMenuDimensions(e,t)}function moveNewIframe(e,t){"dc-cv-fte-pdf-dmb"!==t&&($newiframe=$("#__acrobatNewDialog__")).length>0&&$newiframe.css({top:`${e}px`,transition:"top 0.5s ease 0s"})}function createAndInjectIframe(e){let t=e.base64PDF;delete e.base64PDF;let i="message="+encodeURIComponent(JSON.stringify(e));e.base64PDF=t;const n=GetMenuDimensions("searchWidget",e);if(n.width<=0||n.height<=0)return;let o="block";"hidden"===e.frame_visibility&&(o="none"),($iframe=$("<iframe>")).attr("id","__acrobatDialog__").css({border:"0px","z-index":2147483647,position:"fixed",top:"-5px",right:"80px",left:"unset",width:n.width+"px",height:n.height+"px",display:o,margin:"auto"}).attr("src",chrome.runtime.getURL("browser/js/frame.html")+"?"+i).appendTo("html"),$(document).on("keydown",disableKeyZoom),$(document).on("mousewheel",disableWheelZoom),$newiframe=$("#__acrobatNewDialog__");const{top:s}=$newiframe.offset()||{};if(n.height>s){moveNewIframe(s+(n.height-s),e.fteFeatureFlag)}}function injectFrame(e){"use strict";0===($iframe=$("#__acrobatDialog__")).length?createAndInjectIframe(e):"none"===$iframe.css("display")&&"visible"===e.frame_visibility&&$iframe.css({display:"block"})}function injectBannerInFrame(e){"use strict";const{height:t,width:i}=GetMenuDimensions(e.showToast?"successToast":"downloadBanner",e);if(0===($iframe=$("#__acrobatDialog__")).length){let n="block";"hidden"===e.frame_visibility&&(n="none"),($iframe=$("<iframe>")).attr("id","__acrobatDialog__").css({border:"0px","z-index":2147483647,position:"fixed",bottom:"0px",width:i,height:t,display:n,margin:"auto",background:"transparent","color-scheme":"auto",...e.showToast&&{bottom:"25px",right:"calc(50% - 200px)",left:"unset","border-radius":"4px"}}).attr("src",chrome.runtime.getURL(e.showToast?"browser/js/successToast.html":"browser/js/download-banner.html")).appendTo("html")}else"none"===$iframe.css("display")&&"visible"===e.frame_visibility&&$iframe.css({display:"block"})}function injectPersistFrame(e){if("application/pdf"!==document.contentType||e.url.startsWith("file://"))return;let t=e.base64PDF;delete e.base64PDF;let i="message="+encodeURIComponent(JSON.stringify(e));const n=GetMenuDimensions("persistent",e);n.width<=0||n.height<=0||(e.base64PDF=t,0===($newiframe=$("#__acrobatNewDialog__")).length&&("dc-cv-fte-pdf-dmb"===e.fteFeatureFlag&&$("embed")[0]&&($("embed")[0].style.top="48px",$("embed")[0].style.transition="top 1s ease 0s"),$newiframe=$("<iframe>").attr("id","__acrobatNewDialog__").css({border:"0px",position:"fixed",top:"150px",right:"15px",left:"unset",height:n.height+"px",width:n.width+"px",display:"block",margin:"auto",..."dc-cv-fte-pdf-dmb"===e.fteFeatureFlag&&{position:"absolute",top:"0px",right:"0px",left:"unset",height:"48px",width:"100%"}}).attr("src",chrome.runtime.getURL("browser/js/frameUI.html")+"?"+i).appendTo("html"),$(document).on("keydown",disableKeyZoom),$(document).on("mousewheel",disableWheelZoom)))}function errorOpeningPDF(e){e.panel_op="status",e.current_status="pdf_failure",e.main_op="open_in_acrobat",chrome.runtime.sendMessage(e)}function downloadAuthenticatedPDF(e){let t=new XMLHttpRequest;t.open("GET",e.url,!0),t.responseType="blob",t.onerror=function(t){errorOpeningPDF(e)},t.onload=function(i){let n;t.status<400&&(e.url===t.responseURL||"application/pdf"===t.response.type)?(n=new FileReader,n.onloadend=function(t){e.base64PDF=t.target.result,e.content_op="status",e.current_status="pdf_downloaded",e.main_op="open_in_acrobat",chrome.runtime.sendMessage(e)},n.readAsDataURL(t.response)):errorOpeningPDF(e)},t.send()}function handler(e,t,i){"use strict";if(!isInvalidContentScript()){if(!e.authenticatedPDF||1!=e.authenticatedPDF||"pdf_downloading"!==e.current_status){if("dismiss"===e.content_op)if(delete e.content_op,$iframe=$("#__acrobatDialog__"),1==e.fteUI){if(delete e.fteUI,$fteIframe)return $(document).off("keydown",disableKeyZoom),$(document).off("mousewheel",disableWheelZoom),$fteIframe.remove(),void($fteIframe=null)}else if(1==e.newUI){if(delete e.newUI,$newiframe)return $(document).off("keydown",disableKeyZoom),$(document).off("mousewheel",disableWheelZoom),$newiframe.remove(),"dc-cv-fte-pdf-dmb"===e.fteFeatureFlag&&$("embed")[0]&&($("embed")[0].style.top="0px"),void($newiframe=null)}else if(1==e.downloadBanner){if(delete e.downloadBanner,$iframe)return $iframe.remove(),void($iframe=null)}else if((null!=e.frictionless_workflow||e.forced_cancel)&&(delete e.frictionless_workflow,$iframe))return $(document).off("keydown",disableKeyZoom),$(document).off("mousewheel",disableWheelZoom),$iframe.remove(),void($iframe=null);return e.panel_op&&($fteIframe&&$fteIframe.remove(),"load-frictionless"===e.panel_op&&e.pdf_action?"resize_window"===e.content_op?(delete e.content_op,delete e.window_height):injectFrame(e):"load-downloadBanner"===e.panel_op?"update-height"===e?.content_op?$iframe.css({height:e.height}):injectBannerInFrame(e):1!=e.newUI&&1!=e.persist||(delete e.newUI,injectPersistFrame(e))),!1}downloadAuthenticatedPDF(e)}}isSupportedBrowserVersion()&&isGoogleQuery(docUrl)&&(async()=>{try{const e=await chrome.runtime.sendMessage({main_op:"frictionless-startup",url:docUrl,startup_time:Date.now()});e?.pdf_action&&("resize_window"===e.content_op?(delete e.content_op,delete e.window_height):injectFrame(e))}catch(e){}})(),disableKeyZoom=function(e){"use strict";e.ctrlKey&&-1!==[187,189,107,109].indexOf(e.keyCode)&&e.preventDefault()},disableWheelZoom=function(e){"use strict";e.ctrlKey&&e.preventDefault()},void 0!==chrome.runtime&&chrome.runtime.onMessage.addListener(handler),"application/pdf"===document.contentType&&chrome.runtime.sendMessage({main_op:"pdf-contentType-event"});