B2G/gaia/apps/browser/js/browser.js
// Each browser gets their own listener
Each browser gets their own listener
Each browser gets their own listener
function browser_handleBrowserEvent(tab) {
    return (function(evt) {
      var isCurrentTab = this.currentTab.id === tab.id;
      switch (evt.type) {
      case 'mozbrowserloadstart':
        if (!tab.url || tab.crashed) {
          return;
        }
        if (this.addressBarState === this.HIDDEN) {
          this.showAddressBar();
        }
        tab.loading = true;
        if (isCurrentTab && this.currentScreen === this.PAGE_SCREEN) {
          this.throbber.classList.add('loading');
          this.setUrlButtonMode(this.STOP);
        }
        tab.title = null;
        tab.iconUrl = null;
        break;
      case 'mozbrowserloadend':
        if (!tab.loading) {
          return;
        }
        tab.loading = false;
        if (isCurrentTab && this.currentScreen === this.PAGE_SCREEN) {
          this.throbber.classList.remove('loading');
          this.setUrlBar(tab.title || tab.url);
          this.setUrlButtonMode(this.REFRESH);
        }
        if (tab.dom.getScreenshot) {
          tab.dom.getScreenshot(this.MAX_THUMBNAIL_WIDTH * this.DEVICE_RATIO,
            this.MAX_THUMBNAIL_HEIGHT * this.DEVICE_RATIO).onsuccess =
          (function(e) {
            tab.screenshot = e.target.result;
            if (this.currentScreen === this.TABS_SCREEN) {
              this.showTabScreen();
            }
            Places.updateScreenshot(tab.url, tab.screenshot);
          }).bind(this);
        }
        if (!tab.iconUrl) {
          var a = document.createElement('a');
          a.href = tab.url;
          var iconUrl = a.protocol + '//' + a.hostname + '/' + 'favicon.ico';
          Places.setAndLoadIconForPage(tab.url, iconUrl);
        }
        break;
      case 'mozbrowserlocationchange':
        if (evt.detail === 'about:blank') {
          return;
        }
        tab.url = evt.detail;
        this.updateHistory(evt.detail);
        if (isCurrentTab) {
          if (this.currentScreen === this.PAGE_SCREEN) {
            this.setUrlBar(tab.url);
          }
        }
        break;
      case 'mozbrowsertitlechange':
        if (evt.detail) {
          tab.title = evt.detail;
          Places.setPageTitle(tab.url, tab.title);
          if (isCurrentTab && !tab.loading &&
              this.currentScreen === this.PAGE_SCREEN) {
            this.setUrlBar(tab.title);
          }
          if (this.currentScreen === this.TABS_SCREEN) {
            this.showTabScreen();
          }
        }
        break;
      case 'mozbrowsericonchange':
        if (evt.detail && evt.detail != tab.iconUrl) {
          tab.iconUrl = evt.detail;
          Places.setAndLoadIconForPage(tab.url, tab.iconUrl);
        }
        break;
      case 'mozbrowsercontextmenu':
        this.showContextMenu(evt);
        break;
      case 'mozbrowsersecuritychange':
        tab.security = evt.detail;
        if (isCurrentTab) {
          this.updateSecurityIcon();
        }
        break;
      case 'mozbrowseropenwindow':
        this.handleWindowOpen(evt);
        break;
      case 'mozbrowserclose':
        this.handleWindowClose(tab.id);
        this.setTabVisibility(this.currentTab, true);
        this.updateTabsCount();
        if (tab.id === ModalDialog.currentOrigin) {
          ModalDialog.hide();
        } else if (tab.id === AuthenticationDialog.currentOrigin) {
          AuthenticationDialog.hide();
        }
        break;
      case 'mozbrowserusernameandpasswordrequired':
        if (!isCurrentTab) {
          this.hideCurrentTab();
          this.selectTab(tab.id);
        }
        if (this.currentScreen !== this.PAGE_SCREEN) {
          this.showPageScreen();
        }
        AuthenticationDialog.handleEvent(evt, tab.id);
        break;
      case 'mozbrowsershowmodalprompt':
        if (!isCurrentTab) {
          this.hideCurrentTab();
          this.selectTab(tab.id);
        }
        if (this.currentScreen !== this.PAGE_SCREEN) {
          this.showPageScreen();
        }
        ModalDialog.handleEvent(evt, tab.id);
        break;
      case 'mozbrowsererror':
        if (evt.detail.type === 'fatal')
          this.handleCrashedTab(tab);
        break;
      case 'mozbrowserasyncscroll':
        this.handleScroll(evt);
        break;
      }
    }).bind(this);
  }
function browser_handleBrowserEvent ( tab ) { return ( function ( evt ) { var isCurrentTab = this . currentTab . id === tab . id ; switch ( evt . type ) { case 'mozbrowserloadstart' : if ( ! tab . url || tab . crashed ) { return ; } if ( this . addressBarState === this . HIDDEN ) { this . showAddressBar ( ) ; } tab . loading = true ; if ( isCurrentTab && this . currentScreen === this . PAGE_SCREEN ) { this . throbber . classList . add ( 'loading' ) ; this . setUrlButtonMode ( this . STOP ) ; } tab . title = null ; tab . iconUrl = null ; break ; case 'mozbrowserloadend' : if ( ! tab . loading ) { return ; } tab . loading = false ; if ( isCurrentTab && this . currentScreen === this . PAGE_SCREEN ) { this . throbber . classList . remove ( 'loading' ) ; this . setUrlBar ( tab . title || tab . url ) ; this . setUrlButtonMode ( this . REFRESH ) ; } if ( tab . dom . getScreenshot ) { tab . dom . getScreenshot ( this . MAX_THUMBNAIL_WIDTH * this . DEVICE_RATIO , this . MAX_THUMBNAIL_HEIGHT * this . DEVICE_RATIO ) . onsuccess = ( function ( e ) { tab . screenshot = e . target . result ; if ( this . currentScreen === this . TABS_SCREEN ) { this . showTabScreen ( ) ; } Places . updateScreenshot ( tab . url , tab . screenshot ) ; } ) . bind ( this ) ; } if ( ! tab . iconUrl ) { var a = document . createElement ( 'a' ) ; a . href = tab . url ; var iconUrl = a . protocol + '//' + a . hostname + '/' + 'favicon.ico' ; Places . setAndLoadIconForPage ( tab . url , iconUrl ) ; } break ; case 'mozbrowserlocationchange' : if ( evt . detail === 'about:blank' ) { return ; } tab . url = evt . detail ; this . updateHistory ( evt . detail ) ; if ( isCurrentTab ) { if ( this . currentScreen === this . PAGE_SCREEN ) { this . setUrlBar ( tab . url ) ; } } break ; case 'mozbrowsertitlechange' : if ( evt . detail ) { tab . title = evt . detail ; Places . setPageTitle ( tab . url , tab . title ) ; if ( isCurrentTab && ! tab . loading && this . currentScreen === this . PAGE_SCREEN ) { this . setUrlBar ( tab . title ) ; } if ( this . currentScreen === this . TABS_SCREEN ) { this . showTabScreen ( ) ; } } break ; case 'mozbrowsericonchange' : if ( evt . detail && evt . detail != tab . iconUrl ) { tab . iconUrl = evt . detail ; Places . setAndLoadIconForPage ( tab . url , tab . iconUrl ) ; } break ; case 'mozbrowsercontextmenu' : this . showContextMenu ( evt ) ; break ; case 'mozbrowsersecuritychange' : tab . security = evt . detail ; if ( isCurrentTab ) { this . updateSecurityIcon ( ) ; } break ; case 'mozbrowseropenwindow' : this . handleWindowOpen ( evt ) ; break ; case 'mozbrowserclose' : this . handleWindowClose ( tab . id ) ; this . setTabVisibility ( this . currentTab , true ) ; this . updateTabsCount ( ) ; if ( tab . id === ModalDialog . currentOrigin ) { ModalDialog . hide ( ) ; } else if ( tab . id === AuthenticationDialog . currentOrigin ) { AuthenticationDialog . hide ( ) ; } break ; case 'mozbrowserusernameandpasswordrequired' : if ( ! isCurrentTab ) { this . hideCurrentTab ( ) ; this . selectTab ( tab . id ) ; } if ( this . currentScreen !== this . PAGE_SCREEN ) { this . showPageScreen ( ) ; } AuthenticationDialog . handleEvent ( evt , tab . id ) ; break ; case 'mozbrowsershowmodalprompt' : if ( ! isCurrentTab ) { this . hideCurrentTab ( ) ; this . selectTab ( tab . id ) ; } if ( this . currentScreen !== this . PAGE_SCREEN ) { this . showPageScreen ( ) ; } ModalDialog . handleEvent ( evt , tab . id ) ; break ; case 'mozbrowsererror' : if ( evt . detail . type === 'fatal' ) this . handleCrashedTab ( tab ) ; break ; case 'mozbrowserasyncscroll' : this . handleScroll ( evt ) ; break ; } } ) . bind ( this ) ; }
Each browser gets their own listener
Each browser gets their own listener
// iframe will call loadstart on creation, ignore // If address bar is hidden then show it // Capture screenshot for tab thumbnail // If no icon URL found yet, try loading from default location // Refresh the tab screen if we are currently viewing it, for dynamic // or not yet loaded titles