/*************************************************************************
* 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.
**************************************************************************/
import{dcLocalStorage as e}from"./common/local-storage.js";import{hydrateWithStorage as o}from"./sw_modules/hydrate.js";import{communicate as s}from"./sw_modules/communicate.js";import{tempUrlBufferClean as t}from"./sw_modules/temp-url-buffer-cleanup.js";import{onMessageListener as r}from"./sw_modules/common.js";import{externalClients as n}from"./sw_modules/externalClients.js";import{feat as a}from"./sw_modules/feat.js";import{session as i}from"./sw_modules/session.js";import{acroweb2pdf as m}from"./sw_modules/acro-web2pdf.js";import{userSubscriptionAlarmHandler as d}from"./sw_modules/user-subscription.js";import{whatsNewAlarmHandler as c}from"./sw_modules/whats-new-handler.js";import{startQAWithWebpage as l}from"./sw_modules/ch-context-menu.js";import{openPreferences as p}from"./common/navigation-helper.js";import"./sw_modules/acro-gstate.js";import{authProvider as u}from"./sw_modules/auth-provider.js";import{initSiteVisitAnalytics as h}from"./sw_modules/site-visit-analytics.js";import{startup as f,registerActions as w,onWelcomeTabRemoved as b,contextMenuOnClickHandler as g,updateAnalyticsOptInAdmin as _,refocusLocalFteWindow as L,onLocalFileClosed as I,onLocalFteWindowClosed as y,onDownloadChanged as j}from"./sw_modules/ch-context-menu.js";import{processRequest as x,honorRequest as v,onTabsUpdated as S,onTabActivated as C,logWebpageDomain as A,handlePrefetchValidation as R,detectAndStorePrefetch as T,cleanupPrefetchForTab as M,onWindowFocusChanged as k}from"./sw_modules/viewer-module.js";import{indexedDBScript as P}from"./common/indexDB.js";import{offscreenActions as D}from"./sw_modules/offscreen-actions.js";import{analytics as B}from"./common/analytics.js";import{expressModalTabCloseListener as U}from"./sw_modules/express.js";import{sidepanelState as F}from"./sw_modules/SidepanelState.js";import{loggingApi as q}from"./common/loggingApi.js";import E from"./sw_modules/ExplicitBlocklist.js";import{checkAndOpenWhatsNewPage as O}from"./sw_modules/whats-new-handler.js";import{removeCoiTab as N,trackCoiHeaders as H,clearOptionPageSource as G}from"./common/util.js";import{storageAnalyzer as V}from"./sw_modules/storage-analyzer.js";const W=["http","https","ftp","file","blob","data","filesystem","drive"];try{const D=chrome.runtime.getURL("/");chrome.runtime.onConnect.addListener(o=>{const[s,t,r]=o.name?.split("_")??[];"sidepanel"===s&&(o.onMessage.addListener(()=>{}),chrome.tabs.sendMessage(parseInt(t),{action:"sidepanel_opened"}),F.setIsOpen(parseInt(t),!0),o.onDisconnect.addListener(async()=>{chrome.tabs.sendMessage(parseInt(t),{action:"sidepanel_closed",initTimeStamp:r}),F.setIsOpen(parseInt(t),!1);const o=Date.now(),{version:s}=chrome.runtime.getManifest();await e.init(),q.info({message:"DC Acrobat Extn: Sidepanel closed",timestamp:o,duration:Math.round((o-r)/100)/10,durationInMs:o-r,adobeInternal:"true"===e.getItem("adobeInternal"),extensionVersion:s})}))}),chrome.management.getSelf(o(f)),chrome.runtime.onInstalled.addListener(o(w)),h(),chrome.cookies?.onChanged?.addListener(e=>{const{name:o,domain:s}=e?.cookie||{};s?.includes("services.adobe.com")&&("ims_sid"===o?u.resetSignInStatusCooldown():"gds"===o&&e?.removed&&["explicit","expired"].includes(e?.cause)&&chrome.runtime.sendMessage({content_op:"removeAnonGenAIProvisionResponse"}))}),chrome.runtime.onStartup.addListener(o(()=>{e.removeItem("loadedTabsInfo"),O("browserStartup")})),chrome.contextMenus.onClicked.addListener(o(g)),chrome.runtime.onMessageExternal.addListener(o(a,n)),chrome.action.onUserSettingsChanged?.addListener(o(async o=>{const s=e.getItem("pinToolbarSettingsWindowId");if(s&&o.isOnToolbar)try{await chrome.windows.remove(s)}catch(e){}})),chrome.webRequest.onHeadersReceived.addListener(e=>{o(e=>{R(e)||(x(e,!1),A(e),H(e))})(e)},{urls:["http://*/*","https://*/*"],types:["main_frame","sub_frame"]},["responseHeaders"]),chrome.webRequest.onBeforeRequest.addListener(e=>{o(x)(e,!0)},{urls:["file://*/*.pdf","file://*/*.PDF"],types:["main_frame","sub_frame"]}),chrome.webRequest.onBeforeSendHeaders.addListener(e=>{o(T)(e)},{urls:["http://*/*","https://*/*"],types:["main_frame"]},["requestHeaders"]),chrome.webRequest.onBeforeRequest.addListener(o(v),{urls:W.map(e=>D+e+"*"),types:["main_frame"]}),chrome.webNavigation.onBeforeNavigate.addListener(o(s.handlerTabs),{frameType:"outermost_frame"}),chrome.runtime.onMessage.addListener((...t)=>{const[n,a,i]=t;switch(n?.type){case"getWindowType":a?.tab?.windowId?chrome.windows.get(a.tab.windowId).then(e=>{const o="popup"===e.type,s="app"===e.type;i({isPopup:o,isApp:s})}):i({isPopup:!1,isApp:!1});break;case"open_side_panel":l(n,a.tab||n.tab);break;case"open_options_page":p({preferenceTabId:n.preferenceTabId,controlId:n.controlId,accordionId:n.accordionId,sectionClassNames:n.highlightSection});break;case"send_to_sidepanel":chrome.runtime.sendMessage({...n,tabId:a.tab?.id});break;case"get_sidepanel_state":i({isOpen:F.getIsOpen(a.tab?.id)});break;case"get_explicit_blocklist":"true"===e.getItem("enableGenAIFab")?E.getExplicitBlocklist().then(e=>i(e)).catch(()=>i([])):i([])}return o(r,s.proxy(s.handler))(...t),!0}),chrome.tabs.onRemoved.addListener(o(s.proxy(s.close),i.proxy(i.onSessionTabRemoved),b,(...o)=>{e.getItem("LocalFileAccessTouchpointsFromViewer")||P.deleteDataFromIndexedDB(...o)},I,s.proxy(s.getCurrentTabInfoAndUpdateLoadedTabs),U,N,e=>F.clear(e),M,u.clearImsConsciousTab,G)),chrome.tabs.onUpdated.addListener(o(S)),chrome.storage.managed.onChanged.addListener(o(_)),chrome.extension.isAllowedFileSchemeAccess(o(s.proxy(s.setIsAllowedLocalFileAccess))),chrome.tabs.onActivated.addListener(async(...e)=>{o(C,s.proxy(s.active),L,u.recheckSignInStatus)(...e)}),chrome.tabs.onReplaced.addListener(o(s.proxy(s.tabReplace))),chrome.tabs.onMoved.addListener(o(s.proxy(s.getCurrentTabInfoAndUpdateLoadedTabs))),m.setNcPort(chrome.runtime.connectNative("com.adobe.acrobat.chrome_webcapture")),m.ncPort.onMessage.addListener(m.proxy(m.nativeMessageCallback)),m.ncPort.onDisconnect.addListener(m.proxy(m.nativeOnDisconnect)),chrome.alarms.onAlarm.addListener(o(e=>{d(e),c(e)})),chrome.alarms.onAlarm.addListener(t.deleteTempURLBufferEntries),chrome.windows.onRemoved.addListener(o(y)),chrome.downloads.onChanged.addListener(o(j)),chrome.downloads.onCreated.addListener(e=>{(e?.finalUrl&&new URL(e?.finalUrl)?.searchParams?.has("acrobatPromotionSource")||e?.url&&new URL(e?.url)?.searchParams?.get("acrobatPromotionSource"))&&(chrome.downloads.cancel(e?.id),B.event("DCBrowserExt:PromotionSource:Download:Cancel"))}),chrome.windows.onFocusChanged.addListener(o(k))}catch(e){console.log(e)}