Mini Kabibi Habibi

Current Path : C:/Program Files/McAfee/WebAdvisor/MFW/packages_web_view/builtin/
Upload File :
Current File : C:/Program Files/McAfee/WebAdvisor/MFW/packages_web_view/builtin/wa-core.js

/* Core */
(function (wa) {
  var core = wa.Core = wa.Core || {},
    _settings = wa.Utils.Settings,
    _external = wa.Utils.External;

  //Component
  core.Component = function (name, status, key) {
    this.name = name;
    this.status = status;
    this.key = key;

    this.isIgnored = async function (key) {
      var isIgnored = false;
      var startIgnore = await this.settings.get("startIgnoreDate" + (key || this.key));
      var ignoreDuration = parseInt(await this.settings.get("ignoreDuration"));

      if (startIgnore && ignoreDuration) {
        var today = await this.settings.getToday();
        var startIgnoreDate = startIgnore.parseBasicDate();
        isIgnored = today >= startIgnoreDate && today <= startIgnoreDate.addDays(ignoreDuration);
      }

      return isIgnored;
    };

    this.isInFixGracePeriod = async function (key) {
      var inGracePeriod = false;
      var gracePeriodStart = await this.settings.get("fixGracePeriodStartDate" + (key || this.key));
      var gracePeriodDuration = parseInt(await this.settings.get("fixGracePeriodDuration"));
      if (gracePeriodStart && gracePeriodDuration) {
        var today = this.settings.getToday();
        var gracePeriodStartDate = gracePeriodStart.parseBasicDate();
        inGracePeriod = today >= gracePeriodStartDate && today <= gracePeriodStartDate.addHours(gracePeriodDuration);
      }

      return inGracePeriod;
    };

    this.isDisabled = function () {
      return this.status === "OFF";
    };

    this.isNone = function () {
      return this.status === "NONE";
    };
  };
  core.Component.prototype.settings = WebAdvisor.Utils.Settings;
  core.Component.fix = function (actions, key) {
    _external.actionEvent(actions, 3000);
    var todayString = _settings.getToday().getBasicDateString();
    var keys = key.split(",");
    for (var i = 0; i < keys.length; i++) {
      _settings.set("fixGracePeriodStartDate" + keys[i], todayString);
    }
  };
  core.Component.ignore = function (key) {
    var today = _settings.getToday();
    var basicDateString = today.getBasicDateString();
    var keys = key.split(",");
    for (var i = 0; i < keys.length; i++) {
      _settings.set("startIgnoreDate" + keys[i], basicDateString);
    }
  };
  core.Component.getState = async function () {
    var components = await this.getData();

    // The keys will not exist if there was an error determining the state on native side.
    if (!components.FW || !components.AV || !components.MCSUB) {
      return;
    }

    var firewall = new core.Firewall(components.FW);
    var antivirus = new core.AntiVirus(components.AV);
    var subscription = new core.Subscription(components.MCSUB);
    
    var fw_ignored = await firewall.isIgnored();
    var fw_in_grace_period = await firewall.isInFixGracePeriod();
    var aw_ignored = await antivirus.isIgnored();
    var aw_in_grace_period = await antivirus.isInFixGracePeriod();

    if ((firewall.isDisabled() && !fw_ignored && !fw_in_grace_period) &&
      (antivirus.isDisabled() && !aw_ignored && !aw_in_grace_period)) {
      return {
        key: this.key.FWAV,
        actions: subscription.getExpiryAction() || antivirus.key + "," + firewall.key,
        name: ["AVFW", "FW,AV"]
      };
    } else if (firewall.isDisabled() && !fw_ignored && !fw_in_grace_period) {
      return {
        key: this.key.FW,
        actions: subscription.getExpiryAction() || firewall.key,
        name: ["FW"]
      };
    } else if (antivirus.isDisabled() && !aw_ignored && !aw_in_grace_period) {
      return {
        key: this.key.AV,
        actions: subscription.getExpiryAction() || antivirus.key,
        name: ["AV"]
      };
    } else if (antivirus.isNone()) {
      return {
        key: this.key.AVNONE,
        actions: "AVN",
        name: ["AVN"]
      };
    }

  };
  core.Component.key = {
    FWAV: 1,
    FW: 2,
    AV: 3,
    AVNONE: 4
  };
  core.Component.getData = async function () {
    try {
      let checklist_data = await _external.getArgument("checklist_data");
      return JSON.parse(checklist_data);
    }
    catch (error) {
      chrome.webview.hostObjects.wa_external.log("core.Component.getData: exception " + error.message);
      return {}
    }
  };

  //Secure Search
  core.SecureSearch = {};
  core.SecureSearch.prototype = new core.Component();
  core.SecureSearch.key = "SS";
  core.SecureSearch.enable = function () {
    _external.actionEvent("EnableSecureSearch", 0);
  };
  core.SecureSearch.disable = function () {
    _external.actionEvent("IgnoreSecureSearch", 0);
  };
  core.SecureSearch.getMode = function () {
    var annotateSecureSearchOnly = _settings.get(this.ANNOTATE_SECURE_SEARCH),
      annotateAllSearchEngines = _settings.get(this.ICONS, "0");

    if (annotateSecureSearchOnly && annotateAllSearchEngines) {
      return ['ss'];
    } else if (annotateAllSearchEngines) {
      return ['all'];
    } else {
      return ['none'];
    }
  };
  core.SecureSearch.setMode = function (mode) {
    switch (mode) {
      case 'ss':
        this.annotateSecureSearchEngine();
        break;
      case 'all':
        this.annotateAllSearchEngines();
        break;
      case 'none':
        this.annotateNone();
        break;
    }
  };
  core.SecureSearch.setDefaultMode = function () {
    var isSuiteUser = _settings.get("*Suite"),
      isDefaultAnnotationOptionSet = _settings.get(this.DEFAULT_ANNOTATION_OPTION_SET),
      isUpdateFromSAToWA = _settings.get("*IsUpdateFromSAToWA"),
      isIconsSet = _settings.exists(this.ICONS, "0");

    if (isUpdateFromSAToWA === true &&
      isDefaultAnnotationOptionSet === false) {
      if (isSuiteUser === true) {
        this.showSecureSearchAnnotations(false);
      } else {
        if (isIconsSet === true) {
          this.showSecureSearchAnnotations(false);
        }
      }
      _settings.set(this.DEFAULT_ANNOTATION_OPTION_SET, true);
      this.notifySettingsChanged();
    }
  };
  core.SecureSearch.annotateSecureSearchEngine = function () {
    this.showSecureSearchAnnotations(true);
    this.showIcons(true);
    this.notifySettingsChanged();
  };
  core.SecureSearch.annotateAllSearchEngines = function () {
    this.showSecureSearchAnnotations(false);
    this.showIcons(true);
    this.notifySettingsChanged();
  };
  core.SecureSearch.annotateNone = function () {
    this.showSecureSearchAnnotations(false);
    this.showIcons(false);
    this.notifySettingsChanged();
  };
  core.SecureSearch.showSecureSearchAnnotations = function (show) {
    _settings.set(this.ANNOTATE_SECURE_SEARCH, show);
  };
  core.SecureSearch.showIcons = function (show) {
    _settings.set(this.ICONS, show, "0");
  };
  core.SecureSearch.notifySettingsChanged = function (show) {
    _settings.notify();
  };

  core.SecureSearch.DEFAULT_ANNOTATION_OPTION_SET = "*IsDefaultAnnotationOptionsSet";
  core.SecureSearch.ANNOTATE_SECURE_SEARCH = "*OnlyShowAnnotationsOnSecureSearch";
  core.SecureSearch.ICONS = "*Icons";
  core.SecureSearch.reset = function () {
    _settings.set("*SSDateStampShowedToast_ie", 0, "0");
    _settings.set("*SSDateStampShowedToast_ff", 0, "0");
    _settings.set("*SSDateStampShowedToast_ch", 0, "0");
    _settings.set("adblock_reenable_toast_ch", false, "0");
  };

  //Browser Protection
  core.BrowserProtection = function (item) {
    core.Component.call(this, item.name, item.status, core.BrowserProtection.key);
  };
  core.BrowserProtection.prototype = new core.Component();
  core.BrowserProtection.key = "BP";

  //Firewall
  core.Firewall = function (item) {
    core.Component.call(this, item.name, item.status, core.Firewall.key);
  };
  core.Firewall.prototype = new core.Component();
  core.Firewall.key = "FW";

  //AnitVirus
  core.AntiVirus = function (item) {
    core.Component.call(this, item.name, item.status, core.AntiVirus.key);
  };
  core.AntiVirus.prototype = new core.Component();
  core.AntiVirus.key = "AV";

  //How it works for Welcome checklist
  core.Welcome = {
    getHowItWorksUrl: function () {
      var url = _settings.get("HowItWorksUrl");
      if (url) {
        return url;
      }
      return "https://www.mcafee.com/consumer/v/wa-how.html";
    }
  };

  //Download Warning
  core.DownloadWarning = {
    allow: function () {
      _external.actionEvent("ALLOW_DOWNLOAD", 0);
    },
    uiDisplayed: function () {
      _external.setUIDisplayedEvent();
    },
    getFileName: async function () {
      var url = await this.getUrl();
      return JSON.parse(await _external.getArgument("template_args")).fileName || url.substring(url.lastIndexOf('/') + 1);
    },
    getDomain: async function () {
      var url = await this.getUrl(),
        matches = url.match(/^(?:[^\/?#]+\:\/\/)?([^\/?#]+)(?:[\/?#]|$)/i);
      return matches && matches[1];
    },
    getUrl: async function () {
      if (!this.url) {
        var json_args = await _external.getArgument("template_args")
        return JSON.parse(json_args).url;
      }
      return this.url;
    },
    url: "",
    key: "DW"
  };

  //Trusted Sites
  core.TrustedSites = {
    cleanUrl: function (url) {
      var domain = url.replace(/^\s*|\s*$/g, '');
      domain = domain.replace(/^http:\/\/|^https:\/\/|^ftp:\/\/|^gopher:\/\/|^nntp:\/\/|^wais:\/\/|^file:\/\/|^prospero:\/\//gi, '');
      domain = domain.replace(/(\/|:).*/g, '');
      return domain;
    },
    isValidUrl: function (url) {
      var invalidChars = /[^\x2D\x2E\x30-\x39\x41-\x5A\x61-\x7A]/g,
        invalidDots = /^\.|\.\.|\.$/g,
        validDot = /\./g,
        validStart = /^[a-zA-Z0-9]/g,
        MIN_URL_LENGTH = 5,
        MAX_URL_LENGTH = 255;

      return url.length !== 0 &&
        !/^\s+$/g.test(url) &&
        url.length >= MIN_URL_LENGTH &&
        url.length <= MAX_URL_LENGTH &&
        !invalidChars.test(url) &&
        !invalidDots.test(url) &&
        validDot.test(url) &&
        validStart.test(url);
    },
    getCurrentUrl: function () {
      return core.TrustedSites.cleanUrl(_external.getArgument("current_url"));
    },
    get: function () {
      return _settings.get(this.WHITE_LIST, "0");
    },
    set: function (trustedSites) {
      _settings.set(this.WHITE_LIST, trustedSites.join(";"), "0");
    },
    WHITE_LIST: "*WhiteList"
  };

  //Uninstaller
  core.Uninstaller = {
    close: _external.close,
    start: _external.startUninstall,
    complete: _external.isUninstallComplete,
    isUpdaterRunning: _external.isUpdaterRunning,
    isBrowserRunning: _external.isBrowserRunning,
    shutDownBrowsers: _external.shutDownBrowsers
  };

  //Stats
  core.Stats = {
    pagesScanned: function () { return _settings.get("*CounterPagesScanned"); },
    pagesBlocked: function () { return _settings.get("*CounterPagesBlocked"); },
    downloadsScanned: function () { return _settings.get("*CounterDownloadsScanned"); },
    downloadsBlocked: function () { return _settings.get("*CounterDownloadsBlocked"); },
    cryptoBlocked: function () { return _settings.get("*CounterCryptoJackingBlocked"); },

    getHtml: function (l) {

      var cryptoItem = "";
      var cryptoBlockedCount = this.cryptoBlocked();
      if (!_settings.get("CryptojackingDisabled") && cryptoBlockedCount > 0) {
        var attemp = cryptoBlockedCount > 1 ? l("ATTEMPTS") : l("ATTEMPT");
        var cryptoLink = "<span id='wa-crypto-blocked-link' style='color: #00AEEF; cursor: pointer'>" + l("CRYPTOJACKING") + "</span>";
        var cryptoStatText = l("CRYPTO_STAT").format(cryptoLink, attemp);
        cryptoItem = this.getCryptoItemHtml("crypto-blocked", cryptoBlockedCount, cryptoStatText);
      }

      return "<ul>" +
        this.getItemHtml("downloads-scanned", this.downloadsScanned(), l("DOWNLOADS_SCANNED")) +
        this.getItemHtml("downloads-blocked", this.downloadsBlocked(), l("DOWNLOADS_BLOCKED")) +
        this.getItemHtml("pages-scanned", this.pagesScanned(), l("PAGES_SCANNED")) +
        this.getItemHtml("pages-blocked", this.pagesBlocked(), l("PAGES_BLOCKED")) +
        cryptoItem +
        "</ul>";
    },

    getUninstallHtml: function (l) {
      var scannedDownloadCount = this.downloadsScanned();
      var downloadBlockCount = this.downloadsBlocked();
      var pageScannedCount = this.pagesScanned();
      var dangerousPageCount = this.pagesBlocked();
      var cryptoBlockCount = this.cryptoBlocked();

      if (scannedDownloadCount > 0 || downloadBlockCount > 0 || pageScannedCount > 0 ||
        dangerousPageCount > 0 || cryptoBlockCount > 0) {
        return "<ul>" +
          this.getItemHtmlWithPlural("downloads-scanned", scannedDownloadCount, l("WE_SCANNED"), scannedDownloadCount > 1 ? l("DOWNLOADS") : l("DOWNLOAD")) +
          this.getItemHtmlWithPlural("downloads-blocked", downloadBlockCount, l("BLOCKED_UNSAFE"), downloadBlockCount > 1 ? l("DOWNLOADS") : l("DOWNLOAD")) +
          this.getItemHtmlWithPlural("pages-scanned", pageScannedCount, l("WE_SCANNED"), pageScannedCount > 1 ? l("PAGES") : l("PAGE")) +
          this.getItemHtmlWithPlural("pages-blocked", dangerousPageCount, l("BLOCKED_DANGEROUS"), dangerousPageCount > 1 ? l("PAGES") : l("PAGE")) +
          this.getItemHtmlWithPlural("crypto-blocked", cryptoBlockCount, l("CRYPTO_BLOCKED"), cryptoBlockCount > 1 ? l("CRYPTOJACKERS") : l("CRYPTOJACKER")) +
          "</ul>";
      }

      return "<ul id='bulletpoints'>" +
        "<li><span>{0}</span></li>".format(l("BLOCKING_DOWNLOAD")) +
        "<li><span>{0}</span></li>".format(l("FLAGGING_SITES")) +
        "<li><span>{0}</span></li>".format(l("CHECKING_ANTIVIRUS")) +
        "<li><span>{0}</span></li>".format(l("BLOCKING_CRYPTO")) +
        "<li><span>{0}</span></li>".format(l("PEACE_OF_MIND")) +
        "</ul>";
    },

    getCryptoItemHtml: function (id, counter, text) {
      return (counter ? "<li><span id='" + id + "'>{0} {1}</span></li>".format(counter, text) : "");
    },

    getItemHtml: function (id, counter, text) {
      return (counter ? "<li><span id='" + id + "'>{0}</span></li>".format(text, counter) : "");
    },

    getItemHtmlWithPlural: function (id, counter, text, textPlural) {
      return (counter ? "<li><span id='" + id + "'>{0}</span></li>".format(text, counter, textPlural) : "");
    },
  };

  //Web Advisor
  core.WebAdvisor = {
    getProductName: function () {
      var lang = wa.Utils.Lang(wa.Utils.Lang.ResType.SHARED);
      return lang.get("PRODUCT_NAME_TRADEMARKED");
    },
    getProductLogoHtml: function (src) {
      var productNameHtml = this.getProductNameHtml(),
        imgSrc = src || "file:///[WA_FILES]/MFW/packages\\builtin\\mcafee-logo2.png";

      return "<div class='logo'><img src='" + imgSrc + "' align='middle'>" + productNameHtml + "</div>";
    },
    getProductNameHtml: function () {
      var className = "product-name",
        lang = wa.Utils.Lang(wa.Utils.Lang.ResType.SHARED);

      return "<span class='{0}'>".format(className) +
        lang.get("WEBADVISOR") +
        "</span>";
    },
    getProductLogoHtmlLegacy: function () {
      var style = "margin-left: 8px;color: #808080;";
      lang = wa.Utils.Lang(wa.Utils.Lang.ResType.SHARED);
      var productNameHtml = "<span class='{0}'>".format("product-name") + lang.get("COMPANY_NAME_TRADEMARKED") + "</span>";

      return "<img src='file:///[WA_FILES]/MFW/packages\\builtin\\icn_mshield.png' align='middle'>" +
        "<span style='{0}'>{1}</span>".format(style, productNameHtml);
    },
    isPremium: function () {
      return _settings.get("*Premium");
    },
    getVersion: _settings.getVersion,
    close: _external.close
  };

  //Window
  core.Window = {
    getWidth: _external.getWindowWidth,
    setHeight: _external.setWindowHeight,
    setWidth: _external.setWindowWidth,
    close: _external.close,
    show: _external.show,
    minimize: _external.minimize,
    isInitialized: _external.isInitialized,
    ready: function (success, error) {
      chrome.webview.hostObjects.wa_external.log("ready: start");
      if (typeof document === 'undefined' || document === null) {
        chrome.webview.hostObjects.wa_external.log("ready: document is invalid");
        if (error && typeof error === "function") {
          error();
        }
        else {
          chrome.webview.hostObjects.wa_external.log("ready: error handler is invalid");
        }
        return;
      }

      if (!success || typeof success !== "function") {
        chrome.webview.hostObjects.wa_external.log("ready: success handler is invalid");
        if (error && typeof error === "function") {
          error();
        }
      }

      if (document.readyState === 'complete' || (document.readyState !== 'loading' && !document.documentElement.doScroll)) {
        chrome.webview.hostObjects.wa_external.log("ready: document is good");
        success();
      }
      else {
        chrome.webview.hostObjects.wa_external.log("ready: adding listener");
        document.addEventListener('DOMContentLoaded', success);
      }
      chrome.webview.hostObjects.wa_external.log("ready: end");
    },
    getBrowserType: async function () {
      var type = await _external.getBrowserType();
      switch (type) {
        case 0:
          return "IE";
        case 1:
          return "FF";
        case 2:
          return "CH";
        case 3:
          return "ED";
      }
    }
  };

  core.Browser = {
    getType: function () {
      var type = _external.getBrowserType();
      switch (type) {
        case 0:
          return this.INTERNET_EXPLORER;
        case 1:
          return this.FIREFOX;
        case 2:
          return this.CHROME;
        case 3:
          return this.EDGE;
      }
    },
    INTERNET_EXPLORER: "IE",
    FIREFOX: "FF",
    CHROME: "CH",
    SAFER: "MSB",
    EDGE: "EDGE"
  };

  //CheckList
  core.CheckList = {
    shouldSupressThreat: function (state) {
      // Business Rule: We should not show security threats when the computer has booted
      // up in the last 3 minutes, as the information we read may not be accurate.
      var key = core.Component.key;
      if (state.key === key.FWAV || state.key === key.AV || state.key === key.FW) {

        var startupTickCount = _external.getTickCount();
        var noThreatTimer = _settings.get("*McAfeeNoThreatStartupTimer");

        // Perform a string-type number comparison startupTickCount < noThreatTimer
        // As the value we get from getTickCount may be larger
        // than javascript's number limit of +/- 2^53 depending on the call used
        if (typeof startupTickCount === 'string' && typeof noThreatTimer === 'string' &&
          (startupTickCount.length < noThreatTimer.length ||
            (startupTickCount.length === noThreatTimer.length && startupTickCount < noThreatTimer))) {
          return true;
        }
      }

      return false;
    },
    mapComponentsToItems: function (components, keys, lang) {
      var items = {};
      for (var i = 0; i < keys.length; i++) {
        var component = components[keys[i]];
        if (component.status === "ON") {
          switch (keys[i]) {
            case core.Firewall.key:
              component.name = lang("FIREWALL");
              break;
            case core.AntiVirus.key:
              component.name = lang("ANTIVIRUS");
              break;
            case core.BrowserProtection.key:
              component.name = lang("BROWSER_PROTECTION");
              break;
          }

          component.status = lang("ON");
          items[keys[i]] = component;
        }
      }
      return items;
    },
    getCommand: async function () {
      return JSON.parse(await _external.getArgument("template_args")).commandName;
    },
    disableWelcome: function (key, value) {
      _settings.set(this["DISABLE_{0}_WELCOME".format(key)], value);
    },
    reset: function () {
      _settings.set("startIgnoreDateAV", "");
      _settings.set("startIgnoreDateFW", "");
      _settings.set("ignoreDuration", "14");
      _settings.set("fixGracePeriodStartDateAV", "");
      _settings.set("fixGracePeriodStartDateFW", "");
      _settings.set("fixGracePeriodDuration", "24");
    }
  };

  //Subscription
  core.Subscription = function (item) {
    core.Component.call(this, item.name, item.status);
    this.isInLimitedExpiry = false;
    this.isInExtendedExpiry = false;

    initialize = function (subscription, that) {
      if (subscription && subscription.expiry) {
        var today = that.settings.getToday();
        var expiry = subscription.expiry.parseBasicDate();
        var expiryDays = parseInt(that.settings.get("expiryDays"));

        that.isInLimitedExpiry = today >= expiry && today < expiry.addDays(expiryDays);
        that.isInExtendedExpiry = today >= expiry.addDays(expiryDays);
      }
    }
      (item, this);

    this.getExpiryAction = function () {
      if (this.isInLimitedExpiry) {
        return "MCSUB";
      }
      if (this.isInExtendedExpiry) {
        return "DEFAULT";
      }
    };
  };
  core.Subscription.prototype = new core.Component();

  //Data
  core.data = {
    url: {
      helpNow: "https://service.mcafee.com/default.aspx",
      twitter: "https://twitter.com/McAfee_Home",
      facebook: "https://www.facebook.com/McAfee/",
      shared: "https://www.siteadvisor.com/final/index.html",
      survey: "https://www.siteadvisor.com/uninstall.html?client=ie&client_ver={0}"
    },
    image: {
      spinner: "file:///[WA_FILES]/MFW/packages\\builtin\\white_timer.png",
      spinnerLarge: "file:///[WA_FILES]/MFW/packages\\builtin\\spinner_large.gif",
      questionMark: "file:///[WA_FILES]/MFW/packages\\builtin\\white_questionmark.png",
      checkMark: "file:///[WA_FILES]/MFW/packages\\builtin\\white_check.png",
      exclamationMark: "file:///[WA_FILES]/MFW/packages\\builtin\\white_exclamation.gif",
      close: "file:///[WA_FILES]/MFW/packages\\builtin\\main_close.png",
      greenCheck: "file:///[WA_FILES]/MFW/packages\\builtin\\green_check.png",
      uninstallHeader: "file:///[WA_FILES]/MFW/packages\\builtin\\installer_background.png"
    }
  };
}(window.WebAdvisor = window.WebAdvisor || {}));

//FAF2F451CE52CE2A84509C0A0E0CD869791BF479F866C5094F457A73C89D53888DEFE57683B04EF2E2D17D2D3B529CC3EE0B85D03C4321AA2D8B7A463707FB95++