/*************************************************************************
* 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.
**************************************************************************/
(()=>{const e="-shared",t="acrobatDisconnectContentScriptStart",n="acrobatContentScriptDisconnectEnd",o="acrobat-touch-point",i="acrobat-fte-tooltip-container",r="acrobat-gdrive-fte-state";let a,s,c,l,d,u,p,m,g,h,v,w=!1,f=!1,b=!1,E=!1;const T=()=>!chrome.runtime?.id,D=()=>window.location.pathname.includes("/file"),C=e=>{m?.sendAnalytics(e)},y=t=>{if(w||t){const t=document.getElementsByClassName(o);if(t?.length>0){const e=t[0].getElementsByClassName(i);e?.length>0&&C(["DCBrowserExt:GdriveFTE:NativeView:Dismissed"]),t[0].remove()}const n=document.getElementsByClassName(o+e);n?.length>0&&n[0].remove();const r=document.getElementById("acrobat-touch-point");r?.remove();const a=document.getElementsByClassName("acrobat-prompt");a?.length>0&&a[0].remove();const s=document.getElementsByClassName("acrobat-prompt-shared");s?.length>0&&s[0].remove();const c=document.getElementById("acrobat-prompt");c?.remove(),w=!1}},S=()=>((e,t)=>{if(e){const n=u?.config?.selectors,o=n&&n[t];for(let t=0;t<o?.length;t++){let n=e.querySelector(o[t]);if(n)return n}}return null})(document,"fileDetails"),F=e=>{if("Enter"===e.key||32===e.keyCode||"click"===e.type){if(T())return void y();const{acrobatTouchPointClicked:t,getAcrobatTouchPointFteEligibility:n}=p;t(r),u.fteToolTip.touchPointClicked=!0;const o=S(),i=m?.getFileDetails(o);let a="DCBrowserExt:Gdrive:OpenInExtension:Clicked";"Enter"===e.type&&(a="DCBrowserExt:Gdrive:OpenInExtension:EnterKeyDown"),32===e.keyCode&&(a="DCBrowserExt:Gdrive:OpenInExtension:SpaceKeyDown"),C([[a,{gsuiteFte:n(u?.config?.enableFteToolTip)}]]),chrome.runtime.sendMessage({main_op:"akamai-ping"});let s=m?.buildAcrobatPromotionSource("gdrive_chrome","native_view");!1!==u?.addOnStatus?.isAddOnDefault&&(s=m?.buildAcrobatPromotionSource("gdrive_chrome","native_view","NDV"));const c=chrome.runtime.getURL("viewer.html")+"?pdfurl="+encodeURIComponent(`https://drive.usercontent.google.com/download?id=${i.id}&authuser=${u?.userId}&acrobatPromotionSource=${s}`)+"&pdffilename="+encodeURIComponent(i.title);window.open(c,"_blank")}},L=()=>D()?o+e:o,x=()=>{const e=document.createElement("div"),t=(()=>{const e=D()?"acrobat-icon-shared":"acrobat-icon";return m?.createAcrobatIconElement(e,"browser/images/acrobat_dc_appicon_128.png")})(),n=(()=>{const e=document.createElement("span"),t=D()?"acrobat-touch-point-text-shared":"acrobat-touch-point-text";return e.setAttribute("class",t),e.textContent=u?.config?.acrobatPromptText||"Edit with Acrobat",e})(),o=(()=>{const e=document.createElement("div"),t=D()?"acrobat-touch-point-tooltip":"acrobat-touch-point-tooltip-shared";return e.setAttribute("class",t),e.textContent=u?.config?.acrobatPromptText||"Open in Acrobat",e})(),i=L();return e.setAttribute("class",i),e.appendChild(t),e.appendChild(o),e.appendChild(n),e.tabIndex=0,e.addEventListener("keydown",e=>{F(e)},{signal:u?.eventControllerSignal}),e.addEventListener("click",e=>{F(e)},{signal:u?.eventControllerSignal}),e},A=()=>{let e;for(let t=0;t<u?.config?.selectors?.promptParentElement.length&&(e=document.querySelector(u?.config?.selectors?.promptParentElement[t]),!e);t++);return e},_=async()=>{[p,s,m,h,c,g,v]=await Promise.all([import(chrome.runtime.getURL("content_scripts/utils/fte-utils.js")),import(chrome.runtime.getURL("content_scripts/gdrive/touchpoint-service.js")),import(chrome.runtime.getURL("content_scripts/utils/util.js")),import(chrome.runtime.getURL("content_scripts/gdrive/search-handler.js")),import(chrome.runtime.getURL("content_scripts/gdrive/default-viewership-service.js")),import(chrome.runtime.getURL("content_scripts/gdrive/api-parsing-util.js")),import(chrome.runtime.getURL("content_scripts/utils/implicit-toast-service.js"))])},k=async()=>{l=(await import(chrome.runtime.getURL("content_scripts/express/gdrive/express-gdrive-touchpoint-service.js")))?.expressGdriveTouchpointService},I=e=>{const t=document.getElementsByClassName(i);"Enter"!==e.key&&"ArrowLeft"!==e.key&&"ArrowRight"!==e.key&&"click"!==e.type||t?.length>0&&(t[0]?.contains(e.target)||(t[0].remove(),C(["DCBrowserExt:GdriveFTE:NativeView:Dismissed"]),document.removeEventListener("click",I),document.removeEventListener("keydown",I)))},V=e=>{gdriveAcrobatFteCoachmark?.setEligibility(!0,()=>{const{createFteTooltip:t}=p,n=t(!1===u?.addOnStatus?.isAddOnDefault?u?.config?.fteToolTipStrings:u?.config?.fteToolTipStringsForNativeViewNonDV,"gdriveNativeView");(e=>{e.querySelector(".acrobat-fte-tooltip-button").addEventListener("click",()=>{e.remove(),C(["DCBrowserExt:GdriveFTE:NativeView:Clicked"]),document.removeEventListener("click",I),document.removeEventListener("keydown",I)})})(n),document.addEventListener("click",I,{signal:u?.eventControllerSignal}),document.addEventListener("keydown",I,{signal:u?.eventControllerSignal}),e.appendChild(n),C(["DCBrowserExt:GdriveFTE:NativeView:Shown"]);const{updateFteToolTipCoolDown:o}=p;o(u?.config?.fteConfig?.tooltip,r).then(e=>{u.fteToolTip={...u?.fteToolTip,...e}})}),chrome.runtime.sendMessage({main_op:"reRenderShowOneChild"})},P=(e,t)=>{if(window.innerWidth>1080){const n={gsuiteFte:p?.getAcrobatTouchPointFteEligibility(u?.config?.enableFteToolTip),source:t};C([["DCBrowserExt:Gdrive:OpenInExtension:Shown",n]]);const{shouldShowFteTooltip:o}=p,i=u?.config?.fteConfig?.tooltip;o(i,u?.fteToolTip,u?.config?.enableFteToolTip).then(t=>{(e=>!u?.implicitToastShownInSession&&e)(t)&&setTimeout(()=>V(e),1e3)})}},G=(e,t)=>{const n=t.getBoundingClientRect(),o=e.getBoundingClientRect();e.style.top=n.top+n.height/2-o.height/2+"px",e.style.right=window.innerWidth-n.left+"px"},B=()=>{const e=S();if(e){const t=m?.getFileDetails(e);"application/pdf"===t?.mimeType?m?.getElementFromParent(u?.config?.selectors?.updatedViewerElement,document)?t?.title&&t.title.length<=u?.config?.selectors?.updatedViewerMaxFileNameLength?((()=>{try{if(w)return;const e=A(),t=L();if(e&&0===e.getElementsByClassName(t)?.length){const t=x();t.classList.add("acrobat-touch-point-updated-viewer"),document.body.appendChild(t),G(t,e),t.style.visibility="visible",w=!0,P(t,"updated_viewer")}else y()}catch(e){y()}})(),(()=>{if(!w)return;const e=L(),t=m?.getElementFromParent([e],document),n=A();t&&n&&G(t,n)})()):y():(()=>{try{if(w)return;const e=x(),t=A(),n=L();t&&0===t?.getElementsByClassName(n)?.length?(t.prepend(e),w=!0,P(e,"regular_viewer")):y()}catch(e){y()}})():y()}else y()},R=()=>{if(b)try{B(),u?.config?.enableGDriveSearchBarAnalytics&&h?.checkForSearchBarDiv(),(u?.config?.enableGDriveSearchBarAnalytics||c?.isDefaultViewer())&&h?.checkForSearchResultsTable(),u?.pageLoaded&&s?.processForTouchPoint()}catch(e){}},N=()=>{E&&l?.addExpressNativeViewerTouchpoint()},M=()=>{if(document?.body)try{const e={childList:!0,subtree:!0,attributes:!0,attributeFilter:["style"]};d=new MutationObserver(function(){d.takeRecords(),T()?(d.disconnect(),O(),u?.disconnectEventListeners()):(R(),N())}),d.observe(document?.body,e)}catch(e){}else setTimeout(M,500)},O=()=>{y(!0),s?.removeAllTouchPoints(),l?.removeExpressTouchpoints()},U=()=>{T()&&(d&&d.disconnect(),y(),u?.disconnectEventListeners(),window.dispatchEvent(new CustomEvent(n,{detail:{state:u.createStateTransferObject()}})))},j=()=>{window.addEventListener(n,e=>(e=>{T()||u.updateStateFromTransferObject(e?.detail?.state)})(e),{signal:u?.eventControllerSignal}),window.dispatchEvent(new Event("orphanContentScript")),window.dispatchEvent(new Event(t)),window.addEventListener(t,U,{signal:u?.eventControllerSignal})},q=()=>{Promise.all([chrome.runtime.sendMessage({main_op:"gdrive-init"}),chrome.runtime.sendMessage({main_op:"gdrive-express-init"}),chrome.runtime.sendMessage({main_op:"implicit-default-viewership-init",surfaceId:"gdrive"})]).then(async([e,t,n])=>{if(e?.acrobatTouchPointEnabled||e?.enableDefaultViewershipFeatureForGoogleDrive||n?.enableImplicitDefaultViewershipFeature||t?.enableGdriveNativeViewerExpressMenu){W(e);const o=((e,t)=>t?.enableImplicitDefaultViewershipFeature?{...e,fteToolTipStrings:t.fteToolTipStrings}:e)(e,n);await((e,t,n)=>{const o=chrome.runtime.getURL("content_scripts/gdrive/state.js");return import(o).then(o=>{u=o.default,u.config=e,u.expressConfig=t,u.gdriveImplicitDefaultViewershipConfig=n,u.acrobatIconPath="browser/images/acrobat_dc_trefoil_24_white.svg"})})(o,t,n),j(),b=(e?.acrobatTouchPointEnabled||e?.isAcrobatDefaultForSurface||n?.isAcrobatDefaultForSurface)&&(e?.enableOpenInExtension||window.location?.search?.includes("enableAcrobatPromptInGSuite")),E=t?.enableGdriveNativeViewerExpressMenu,(b||E)&&Promise.all([_(),k()]).then(()=>{m.addFontToDocument(u),K(),b&&(((e,t)=>{u.isAcrobatDefaultForGDrivePDFs=e?.isAcrobatDefaultForSurface||t?.isAcrobatDefaultForSurface})(e,n),m?.sendAnalyticsOncePerMonth("DCBrowserExt:Gdrive:OpenInExtension:Enable"),(e?.enableFteToolTip||e?.enableFteToolTipForListGridView)&&m?.sendAnalyticsOncePerMonth("DCBrowserExt:GdriveFTE:Enable"),(()=>{if(window?.document?.location?.pathname.includes("/u/"))return void(u.userId=window.document.location.pathname.split("/")[3]);const e=document.createElement("script");document.addEventListener("acrobat-auth-user-id",t=>{u.userId=t?.detail?.authuser,e.remove()}),e.type="text/javascript",e.src=chrome.runtime.getURL("content_scripts/gdrive/get-auth-user.js"),document.head.appendChild(e)})(),a=chrome.runtime.getURL("browser/images/acrobat_dc_appicon_128.png"),(async()=>{const e=(new Date).getTime();let t={count:0,nextDate:e};t=(await chrome.storage.local.get(r))?.[r]||t;const n=u?.config?.fteConfig?.tooltip;((e,t)=>-1!==e?.resetDay&&t>e?.resetDay)(n,e)&&(t.count=0,t.nextDate=e),u.fteToolTip={...t},t={[r]:t},chrome.storage.local.set(t)})(),O(),$(),v?.shouldShowImplicitDefaultViewerToast("gdrive",u)&&setTimeout(()=>{v?.showImplicitDefaultViewershipToast("gdrive",u?.gdriveImplicitDefaultViewershipConfig?.toastMessage)},1e3),R()),E&&N(),M()})}})},$=()=>{u?.config?.enableGDriveTripleDotMenuAnalytics&&(document.addEventListener("click",e=>{s?.handleAnalyticsForTripleDotMenu(e),s?.handleAnalyticsForTopMenu(e)},{signal:u?.eventControllerSignal}),document.addEventListener("contextmenu",e=>{s?.handleAnalyticsForRightClickMenu(e)},{signal:u?.eventControllerSignal}))},K=()=>{window.addEventListener("load",()=>{setTimeout(()=>{u.pageLoaded=!0},500)})},W=e=>{if(!f&&(f=!0,e?.enableGDriveGridViewTouchPoint||e?.enableGDriveListViewTouchPoint)){const e=document.createElement("script");e.setAttribute("id","acrobat-response-interceptor"),e.src=chrome.runtime.getURL("content_scripts/gdrive/gdrive-inject.js"),e.onload=function(){this.remove()},(document.head||document.documentElement).appendChild(e)}};document.addEventListener("acrobat-addon-status-data",e=>{setTimeout(()=>{g?.handleGDriveInstalledAppResponse(e)},0)},{signal:u?.eventControllerSignal}),document.addEventListener("gdrive-search-bar-api-response",e=>{c?.isDefaultViewer()&&e?.detail?.searchResponse&&g?.processSearchApiResponse(e)},{signal:u?.eventControllerSignal}),chrome.runtime.onMessage.addListener(function(e){switch(e.content_op){case"acrobatGdriveFteStateUpdated":(e=>{u.fteToolTip={...u?.fteToolTip,...e?.fteState}})(e);break;case"acrobatTouchPointsDisabled":u?.isAcrobatDefaultForGDrivePDFs||e.acrobatShortcutSurfaceId&&"gdrive"!==e.acrobatShortcutSurfaceId||(d?.disconnect(),O());break;case"changeDefaultViewershipForSurface":"gdrive"===e?.surfaceId&&chrome.runtime.id&&(e?.isDefault?c?.takeDefaultViewerShip():c?.resetDefaultViewership());break;case"show-implicit-dv-toast":v?.shouldShowImplicitDefaultViewerToast("gdrive",u)&&v?.showImplicitDefaultViewershipToast("gdrive",u?.gdriveImplicitDefaultViewershipConfig?.toastMessage)}}),(async()=>{"drive.google.com"===window?.document?.location?.host&&window.top===window.self&&0===window?.document?.location?.ancestorOrigins.length&&q()})()})();