B2G/gecko/services/aitc/modules/main.js
// the initialSchedule function on the manager.
the initialSchedule function on the manager.
the initialSchedule function on the manager .
function _init() {
    let self = this;
    this._manager.initialSchedule(function queueDone(num) {
      if (num == -1) {
        self._log.debug("No initial upload was required");
        return;
      }
      self._log.debug(num + " initial apps queued successfully");
    });
    function dashboardLoaded(browser) {
      let win = browser.contentWindow;
      self._log.info("Dashboard was accessed " + win);
      if (win.document && win.document.readyState == "complete") {
        self._manager.userActive(win);
        return;
      }
      browser.contentWindow.addEventListener(
        "DOMContentLoaded",
        function _contentLoaded(event) {
          self._manager.userActive(win);
        },
        false
      );
    }
    function dashboardUnloaded() {
      self._log.info("Dashboard closed or in background");
      self._manager.userIdle();
    }
    let listener = {
      onLocationChange: function onLocationChange(browser, pr, req, loc, flag) {
        let win = Services.wm.getMostRecentWindow("navigator:browser");
        if (win.gBrowser.selectedBrowser == browser) {
          if (loc.prePath == self.DASHBOARD_ORIGIN) {
            dashboardLoaded(browser);
          }
        }
      }
    };
    function tabSelected(event) {
      let browser = event.target.linkedBrowser;
      if (browser.currentURI.prePath == self.DASHBOARD_ORIGIN) {
        dashboardLoaded(browser);
      } else {
        dashboardUnloaded();
      }
    }
    function winWatcher(subject, topic) {
      if (topic != "domwindowopened") {
        return;
      }
      subject.addEventListener("load", function winWatcherLoad() {
        subject.removeEventListener("load", winWatcherLoad, false);
        let doc = subject.document.documentElement;
        if (doc.getAttribute("windowtype") == "navigator:browser") {
          let browser = subject.gBrowser;
          browser.addTabsProgressListener(listener);
          browser.tabContainer.addEventListener("TabSelect", tabSelected);
        }
      }, false);
    }
    Services.ww.registerNotification(winWatcher);
    let enumerator = Services.wm.getEnumerator("navigator:browser");
    while (enumerator.hasMoreElements()) {
      let browser = enumerator.getNext().gBrowser;
      browser.addTabsProgressListener(listener);
      browser.tabContainer.addEventListener("TabSelect", tabSelected);
      if (browser.currentURI.prePath == this.DASHBOARD_ORIGIN) {
        dashboardLoaded(browser);
      }
    }
    Services.obs.addObserver(this, "webapps-sync-install", false);
    Services.obs.addObserver(this, "webapps-sync-uninstall", false);
    let idleSvc = Cc["@mozilla.org/widget/idleservice;1"].
                  getService(Ci.nsIIdleService);
    idleSvc.addIdleObserver(this,
                            Preferences.get("services.aitc.main.idleTime"));
  }
function _init ( ) { let self = this ; this . _manager . initialSchedule ( function queueDone ( num ) { if ( num == - 1 ) { self . _log . debug ( "No initial upload was required" ) ; return ; } self . _log . debug ( num + " initial apps queued successfully" ) ; } ) ; function dashboardLoaded ( browser ) { let win = browser . contentWindow ; self . _log . info ( "Dashboard was accessed " + win ) ; if ( win . document && win . document . readyState == "complete" ) { self . _manager . userActive ( win ) ; return ; } browser . contentWindow . addEventListener ( "DOMContentLoaded" , function _contentLoaded ( event ) { self . _manager . userActive ( win ) ; } , false ) ; } function dashboardUnloaded ( ) { self . _log . info ( "Dashboard closed or in background" ) ; self . _manager . userIdle ( ) ; } let listener = { onLocationChange : function onLocationChange ( browser , pr , req , loc , flag ) { let win = Services . wm . getMostRecentWindow ( "navigator:browser" ) ; if ( win . gBrowser . selectedBrowser == browser ) { if ( loc . prePath == self . DASHBOARD_ORIGIN ) { dashboardLoaded ( browser ) ; } } } } ; function tabSelected ( event ) { let browser = event . target . linkedBrowser ; if ( browser . currentURI . prePath == self . DASHBOARD_ORIGIN ) { dashboardLoaded ( browser ) ; } else { dashboardUnloaded ( ) ; } } function winWatcher ( subject , topic ) { if ( topic != "domwindowopened" ) { return ; } subject . addEventListener ( "load" , function winWatcherLoad ( ) { subject . removeEventListener ( "load" , winWatcherLoad , false ) ; let doc = subject . document . documentElement ; if ( doc . getAttribute ( "windowtype" ) == "navigator:browser" ) { let browser = subject . gBrowser ; browser . addTabsProgressListener ( listener ) ; browser . tabContainer . addEventListener ( "TabSelect" , tabSelected ) ; } } , false ) ; } Services . ww . registerNotification ( winWatcher ) ; let enumerator = Services . wm . getEnumerator ( "navigator:browser" ) ; while ( enumerator . hasMoreElements ( ) ) { let browser = enumerator . getNext ( ) . gBrowser ; browser . addTabsProgressListener ( listener ) ; browser . tabContainer . addEventListener ( "TabSelect" , tabSelected ) ; if ( browser . currentURI . prePath == this . DASHBOARD_ORIGIN ) { dashboardLoaded ( browser ) ; } } Services . obs . addObserver ( this , "webapps-sync-install" , false ) ; Services . obs . addObserver ( this , "webapps-sync-uninstall" , false ) ; let idleSvc = Cc [ "@mozilla.org/widget/idleservice;1" ] . getService ( Ci . nsIIdleService ) ; idleSvc . addIdleObserver ( this , Preferences . get ( "services.aitc.main.idleTime" ) ) ; }
the initialSchedule function on the manager.
the initialSchedule function on the manager .
// Do an initial upload. // This is called iff the user is currently looking the dashboard. // If page is ready to go, fire immediately. // Only fire event after the page fully loads. // This is called when the user's attention is elsewhere. // Called when a URI is loaded in any tab. We have to listen for this // because tabSelected is not called if I open a new tab which loads // about:home and then navigate to the dashboard, or navigation via // links on the currently open tab. // Called when the current tab selection changes. // Add listeners for all windows opened in the future. // Add listeners for all current open windows. // Also check the currently open URI. // Add listeners for app installs/uninstall. // Add listener for idle service.