text: function dependOn(){"use strict";return[require("communicate"),require("proxy"),require("common"),require("util"),require("analytics")]}var def;require=function(t){"use strict";return t},def=window.define?window.define:function(t,e){"use strict";return e.apply(null,[{ajax:$.ajax.bind($)}])};var exports=acom_analytics={};def(dependOn(),function(h,t,e,c,l){"use strict";var i,o,s=null,a=!1,T=2,g=13,u=[0,1,T,g,14],d=[T=2,11,12,g=13];for(i in o=function(){return h.getModule("acro-gstate")},s||(s=new function(){var n=[];function r(t){var e;for(e=0;e<n.length;e+=1)if(n[e].tabId===t)return n[e];return null}function s(t){return(t=t||chrome.i18n.getMessage("web2pdfUntitledFileName")).replace(/[<>?:|\*"\/\\'&\.]/g,"")}this.proxy=t.proxy.bind(this),this.LOG=e.LOG,this.UNSET=0,this.OPEN_IN_ACROBAT=1,this.APPEND=2,this.CONVERT_PAGE=4,this.CONVERT_LINK=8,this.CONVERT_SELECTION=16,this.PRINT=32,this.EMAIL=64,this.CALLER_TOOLBAR=128,this.CLEAN_FILE_ON_FAILURE=256,this.STATUS_WAITING=1e4,this.STATUS_DOWNLOADING=10001,this.STATUS_CONVERTING=10002,this.STATUS_SUCCESS=10003,this.STATUS_ERROR=10004,this.STATUS_NOINSTANCE=10005,this.STATUS_FILELOCKED=10006,this.STATUS_NOACROBAT=10007,this.STATUS_CANCELLED=10008,this.STATUS_FILE_OPENED=10100,this.STATUS_FILE_OPEN_FAILED=10101,this.imagePromise=null,this.errorHandler=function(){try{if(0===n.length)return;this.Done(n[0].tabId,this.STATUS_ERROR,null,c.getTranslation("web2pdfHTMLJSError"))}catch(t){}},t.handlers(this.errorHandler.bind(this)),this.Done=function(t,e,i,s){if(-1===t){if(0===n.length)return;t=n[0].tabId}this.setStatus(t,e,i,s),this.nextConversion(t)},this.nextConversion=function(t){var e;for(e=0;e<n.length;e+=1)n[e].tabId===t&&n.splice(e,1);0<n.length&&n[0].start.resolve(n[0]),this.exitShim()},this.cancelConversion=function(t){var e;for(e=0;e<n.length;e+=1)n[e].tabId===t&&(n[e].start&&n[e].start.reject(),n.splice(e,1))},this.addConversion=function(t,e){return t.start=c.Deferred(),n.push(t),1===n.length?t.start.resolve(t):e&&e(),t.start},this.setStatus=function(t,e,i,s){var n,o=r(t)||this.openPDFRequest,a=new Date;c.consoleLog("setStatus: "+t+" status: "+e),o?(o.timing||(o.timing=[]),e===this.STATUS_WAITING?(n="waiting",l.event(l.e.TREFOIL_HTML_CONVERT_WAITING),o.timing.push({stage:"WAIT",start_time:a.getTime()})):e===this.STATUS_DOWNLOADING?(l.event(l.e.TREFOIL_HTML_CONVERT_DOWNLOADING),n="downloading",this.logTiming(o.timing,"WAIT")):e===this.STATUS_CONVERTING?(l.event(l.e.TREFOIL_HTML_CONVERT_IN_PROGRESS),n="in_progress",this.logTiming(o.timing,"USER_PROMPT"),o.timing.push({stage:"CONVERT",start_time:a.getTime()})):e===this.STATUS_SUCCESS?(l.event(l.e.TREFOIL_HTML_CONVERT_COMPLETE),n="complete",this.logTiming(o.timing,"CONVERT")):e===this.STATUS_ERROR?(l.event(l.e.TREFOIL_HTML_CONVERT_FAILED),n="failure"):e===this.STATUS_CANCELLED?(l.event(l.e.TREFOIL_HTML_CONVERT_CANCELLED),n="cancelled",this.logTiming(o.timing,"USER_PROMPT")):n=e===this.STATUS_NOACROBAT?(l.event(l.e.TREFOIL_HTML_CONVERT_NO_ACROBAT),"noacrobat"):e===this.STATUS_FILELOCKED?"filelocked":e===this.STATUS_FILE_OPENED?(o.version===SETTINGS.READER_VER?o.newUI?l.event(l.e.PERSIST_PDF_DOWNLOAD_OPENED_READER):l.event(l.e.TREFOIL_PDF_DOWNLOAD_OPENED_READER):o.newUI?l.event(l.e.PERSIST_PDF_DOWNLOAD_OPENED):l.event(l.e.TREFOIL_PDF_DOWNLOAD_OPENED),"pdf_opened"):e===this.STATUS_FILE_OPEN_FAILED?(o.version===SETTINGS.READER_VER?l.event(l.e.TREFOIL_PDF_DOWNLOAD_OPEN_FAILED_READER):l.event(l.e.TREFOIL_PDF_DOWNLOAD_OPEN_FAILED),"pdf_open_failed"):(c.consoleLog("Unexpected status: "+e),"unknown"),o.panel_op="status",o.current_status=n,i&&(o.file_path=i),s&&(o.message=s),h.deferMessage(o)):c.consoleLog("failed to find conversion for tabId: "+t)},this.nativeMessageCallback=function(t){var e;"setStateCallback"===t.messageType?this.setStatus(+t.conversionID,+t.state):"doneCallback"===t.messageType?(t.filePath&&(e=c.atob16(t.filePath)),this.Done(+t.conversionID,+t.state,e)):"getMessageCallback"===t.messageType?this.sendMessageToNative({message:function(t){return chrome.i18n.getMessage(t)||chrome.i18n.getMessage("web2pdfStatusError")}(t.msgIDStr)}):"saveSuccessCallback"===t.messageType?(e=c.atob16(t.path),this.imagePromise.resolve(e)):"saveFailureCallback"===t.messageType?(c.consoleLogDir("failed to save image"),this.imagePromise.reject()):"shimVersionInfo"===t.messageType?this.versionCallback&&(this.versionCallback(t),delete this.versionCallback):"fileOpenCallback"===t.messageType&&(0==+t.state?this.setStatus(0,this.STATUS_FILE_OPENED):this.setStatus(0,this.STATUS_FILE_OPEN_FAILED),this.openPDFRequest&&(this.nextConversion(this.openPDFRequest.tabId),delete this.openPDFRequest))},this.init=function(){this.m_NativeConnectionPort=chrome.runtime.connectNative("com.adobe.acrobat.chrome_webcapture"),this.m_NativeConnectionPort.onMessage.addListener(this.proxy(this.nativeMessageCallback)),this.m_NativeConnectionPort.onDisconnect.addListener(this.proxy(function(){var t=this.STATUS_ERROR;"Specified native messaging host not found."===chrome.runtime.lastError.message&&(this.versionCallback&&(this.versionCallback({messageType:"shimVersionInfo",majorVersion:"0",minorVersion:"0"}),delete this.versionCallback),t=this.STATUS_NOACROBAT),"Native host has exited"===chrome.runtime.lastError.message&&(t=this.STATUS_ERROR),this.m_NativeConnectionPort=null,this.Done(-1,t)}))},this.sendMessageToNative=function(t){h.legacyShim()&&t.task&&-1===u.indexOf(t.task)?c.consoleLog("Skipping task: "+t.task+" in legacy shim"):(this.m_NativeConnectionPort||this.init(),this.m_NativeConnectionPort.postMessage(t),-1!==d.indexOf(t.task)&&setTimeout(this.proxy(function(){this.exitShim()}),1e3))},this.exitShim=function(){0===n.length&&this.sendMessageToNative({task:14})},this.getVersion=function(t){this.versionCallback=t,this.sendMessageToNative({task:g})},this.openInAcrobat=function(t){t.newUI&&h.resetPersistPrefCount(),this.addConversion(t).then(this.proxy(function(t){this.openPDFRequest=t,this.sendMessageToNative({task:12,pdfData:t.base64PDF.split(",")[1],fileName:t.filename}),l.checkAndLogPDFSize(t.base64PDF.length/1048576),delete t.base64PDF}))},this.openFile=function(t){0===n.length&&this.sendMessageToNative({task:11,filePath:t.file_path})},this.SendForConversion=function(t,e){try{var i,s=new Date;i=0!=(t.conversionSettings&this.APPEND)?1:0,e.timing||(e.timing=[]),e.timing.push({stage:"USER_PROMPT",start_time:s.getTime()}),e.outputPath?0===e.action?this.sendMessageToNative({task:3,conversionID:e.tabId,domData:t.domData,conversionSettings:t.conversionSettings,charset:t.charset,url:t.url,docTitle:t.domtitle,outputPath:e.outputPath}):1===e.action&&this.sendMessageToNative({task:4,conversionID:e.tabId,domData:t.domData,conversionSettings:t.conversionSettings,charset:t.charset,url:t.url,docTitle:t.domtitle,outputPath:e.outputPath}):this.sendMessageToNative({task:i,conversionID:e.tabId,domData:t.domData,conversionSettings:t.conversionSettings,charset:t.charset,url:t.url,docTitle:t.domtitle})}catch(t){this.Done(e.tabId,this.STATUS_ERROR)}},this.showConversionSettingsDialog=function(){0===n.length&&this.sendMessageToNative({task:T})},this.convertToPDF=function(t,e){t.conversionSettings=this.UNSET,o().getViewResultsPreferenceState()&&(t.conversionSettings|=this.OPEN_IN_ACROBAT),t.action===o().web2pdfAction.APPEND?t.conversionSettings|=this.APPEND:t.conversionSettings|=this.CLEAN_FILE_ON_FAILURE,t.context===o().web2pdfContext.PAGE&&(t.conversionSettings|=this.CONVERT_PAGE),t.caller===o().web2pdfCaller.TOOLBAR?t.conversionSettings|=this.CALLER_TOOLBAR:t.context===o().web2pdfContext.LINK&&(t.conversionSettings|=this.CONVERT_LINK),this.SendForConversion(t,e)},this.processImages=function(t,e,i){var s=t.blob.refs[e],n=new Date;return t.timing||(t.timing=[]),t.imagesComplete||(t.imagesComplete=c.Deferred()),this.imagePromise=c.Deferred(),e>=t.blob.refs.length?(this.imagePromise.resolve(),t.imagesComplete.resolve()):(s.data&&"data:"!==s.data?"image"===s.type?(a||(t.timing.push({stage:"SEND_IMAGES",start_time:n.getTime()}),a=!0),t.blob.refs.splice(e,1),this.sendMessageToNative({task:10,imagedata:s.data.split(",")[1],conversionID:t.tabId}),this.imagePromise.then(this.proxy(function(t){i.push("<AcroexchangeDownloadSeprator AcroexchangeDownloadUrl="+s.placeholder+"><FILEPATH>"+t+"</FILEPATH></AcroexchangeDownloadSeprator>")}),function(){})):(this.imagePromise.resolve(),e+=1):(t.blob.refs.splice(e,1),this.imagePromise.resolve()),this.imagePromise.done(this.proxy(function(){this.processImages(t,e,i)}))),this.imagePromise},this.acro_html=function(t,e){var i,s,n;t.error?(c.consoleError(t.error),l.logError(t.error_analytics),this.Done(t.tabId,this.STATUS_ERROR,null,c.getTranslation(t.error))):(l.checkAndLogHTMLBlobSize(t.blob.currentSize/1048576),l.logContents(t),t.analytics&&l.setParamsAndLogAnalytics(t.analytics,l.e.HTML_SOURCE_CONTENT,"content"),l.setArg("stage","CLONE"),l.checkAndLogTimingRange(t.cloneTiming),(n=r(t.tabId)).blob=t.blob,a=!(s=[]),this.processImages(n,0,s),n.imagesComplete.then(this.proxy(function(){for(delete n.imagesComplete,this.logTiming(n.timing,"SEND_IMAGES"),s.push("<AcroexchangeDownloadSeprator AcroexchangeDownloadUrl="+e.tab.url+">"+n.blob.html+"</AcroexchangeDownloadSeprator>"),i=0;i<n.blob.refs.length;i+=1)s.push("<AcroexchangeDownloadSeprator AcroexchangeDownloadUrl="+n.blob.refs[i].placeholder+">"+n.blob.refs[i].data+"</AcroexchangeDownloadSeprator>");delete n.blob,this.convertToPDF({caller:n.caller,action:n.action,context:o().web2pdfContext.PAGE,domData:s.join("\n"),charset:"UTF-8",domtitle:n.domtitle,url:n.url},n)})))},this.logTiming=function(t,e){var i,s=new Date;t.forEach(function(t){t.stage===e&&(i=s.getTime()-t.start_time,l.setArg("stage",e),l.checkAndLogTimingRange(i/100))})},this.handleConversionRequest=function(t){if(SETTINGS.IS_ACROBAT){var e,i=this.proxy(function(){this.setStatus(t.tabId,this.STATUS_WAITING)});h.legacyShim()||t.context!==o().web2pdfContext.PAGE?!h.legacyShim()&&t.context!==o().web2pdfContext.LINK||this.addConversion(t,i).then(this.proxy(function(t){this.convertToPDF({caller:t.caller,action:t.action,context:t.context,domData:"",charset:"UTF-8",domtitle:t.domtitle,url:t.url},t)})):this.addConversion(t,i).then(this.proxy(function(t){delete t.start,this.setStatus(t.tabId,this.STATUS_DOWNLOADING),l.logSiteAndProtocolAnalytics(t.url),e="var maxSize = "+SETTINGS.MAX_HTML_SIZE+", DEBUG = "+SETTINGS.DEBUG_MODE+", TABID = "+t.tabId+", OP = 'acro-html', EXCLUDE = ['font', 'svg_image'];",chrome.tabs.executeScript(t.tabId,{code:e,runAt:"document_start"},this.proxy(function(){if(chrome.runtime.lastError)throw new Error(chrome.runtime.lastError.message);chrome.tabs.executeScript(t.tabId,{file:"data/js/get-html.js"})}))}))}},this.convertToPDFPopupMenu=function(t,e){var i={tabId:e.tab.id,caller:o().web2pdfCaller.TOOLBAR,action:o().web2pdfAction.CONVERT,context:o().web2pdfContext.PAGE,url:e.tab.url,domtitle:s(e.tab.title)};t.outputPath&&(i.outputPath=t.outputPath),this.handleConversionRequest(i)},this.appendToExistingPDFPopupMenu=function(t,e){var i={tabId:e.tab.id,caller:o().web2pdfCaller.TOOLBAR,action:o().web2pdfAction.APPEND,context:o().web2pdfContext.PAGE,url:e.tab.url,domtitle:s(e.tab.title)};t.outputPath&&(i.outputPath=t.outputPath),this.handleConversionRequest(i)}},h.registerModule("acro-web2pdf",s),SETTINGS.IS_ACROBAT&&h.registerHandlers({"acro-html":s.proxy(s.acro_html),appendToExistingPDFPopupMenu:s.proxy(s.appendToExistingPDFPopupMenu),convertToPDFPopupMenu:s.proxy(s.convertToPDFPopupMenu),showConversionSettingsDialog:s.proxy(s.showConversionSettingsDialog)})),s)s.hasOwnProperty(i)&&("function"==typeof s[i]?exports[i]=s[i].bind(s):exports[i]=s[i]);return s});