{"size": 8322, "ext": "js", "max_stars_repo_path": "lib/kango-framework-latest/src/js/firefox/kango/browser.part.js", "max_stars_repo_name": "bachya/ynab-enhanced", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/kango-framework-latest/src/js/firefox/kango/browser.part.js", "max_issues_repo_name": "bachya/ynab-enhanced", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/kango-framework-latest/src/js/firefox/kango/browser.part.js", "max_forks_repo_name": "bachya/ynab-enhanced", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 8322.0, "max_line_length": 8322, "alphanum_fraction": 0.7924777698}
function WebProgressListener(e){this._callback=e}function BrowserTabs(){}function Browser(){BrowserBase.call(this),this.tabs=new BrowserTabs,this._tabs={},this._documentLoadListener=null,this.init()}function BrowserWindow(e){this._gBrowser=e.gBrowser,this._window=e}function BrowserTab(e,t){this._tabElem=e,this._id=t}var utils=require("kango/utils"),func=utils.func,array=utils.array,object=utils.object,chromeWindows=require("kango/chrome_windows"),io=require("kango/io"),core=require("kango/core");WebProgressListener.prototype={QueryInterface:function(e){if(e.equals(Ci.nsIWebProgressListener)||e.equals(Ci.nsISupportsWeakReference)||e.equals(Ci.nsISupports))return this;throw Cr.NS_NOINTERFACE},onProgressChange:function(){},onStatusChange:function(){},onSecurityChange:function(){},onLocationChange:function(){},onStateChange:function(e,t,n,r){var o=Ci.nsIWebProgressListener;if(n&o.STATE_START&&n&o.STATE_IS_DOCUMENT){var i=Ci.nsIChannel,s={url:t.QueryInterface(i).originalURI.spec,window:e.DOMWindow};this._callback(s)}}},BrowserTabs.prototype=object.extend(BrowserTabsBase,{getAll:function(e){for(var t=[],n=browser.getBrowsers(),r=0;r<n.length;r++)t=t.concat(browser.getTabs(n[r]));e(t)},getCurrent:function(e){browser.windows.getCurrent(function(t){t.getCurrentTab(function(t){e(t)})})},create:function(e){var t="undefined"==typeof e.focused||e.focused,n="undefined"!=typeof e.reuse&&e.reuse,r=chromeWindows.getMostRecentChromeWindow().gBrowser,o=null;if(n)for(var i=0;i<r.browsers.length;i++){var s=r.getBrowserAtIndex(i);if(s.currentURI.spec==e.url){o=r.tabContainer.childNodes[i];break}}null==o&&(o=r.addTab(e.url)),t&&(r.selectedTab=o)}}),Browser.prototype=object.extend(BrowserBase,{init:function(){array.forEach(chromeWindows.getLoadedChromeWindows(),function(e){this._listenChromeWindowEvents(e)},this),chromeWindows.addEventListener(chromeWindows.event.WINDOW_LOAD,func.bind(function(e){this._listenChromeWindowEvents(e.window)},this)),core.addEventListener("message",func.bind(function(e){"DocumentComplete"==e.name&&this._onPageLoad(e)},this))},dispose:function(){this.removeAllEventListeners(),this._tabs={}},_listenChromeWindowEvents:function(e){var t=new WebProgressListener(func.bind(this._onPageBeforeNavigate,this));e.gBrowser.addProgressListener(t),chromeWindows.registerContainerUnloader(function(){e.gBrowser.removeProgressListener(t)},e);var n=func.bind(this._onTabSelect,this);e.gBrowser.tabContainer.addEventListener("TabSelect",n,!0),chromeWindows.registerContainerUnloader(function(){e.gBrowser.tabContainer.removeEventListener("TabSelect",n,!0)},e);var r=func.bind(this._onTabOpen,this);e.gBrowser.tabContainer.addEventListener("TabOpen",r,!0),chromeWindows.registerContainerUnloader(function(){e.gBrowser.tabContainer.removeEventListener("TabOpen",r,!0)},e);var o=func.bind(this._onTabClose,this);e.gBrowser.tabContainer.addEventListener("TabClose",o,!0),chromeWindows.registerContainerUnloader(function(){e.gBrowser.tabContainer.removeEventListener("TabClose",o,!0)},e);var i=func.bind(this._onWindowActivate,this);e.addEventListener("activate",i,!0),chromeWindows.registerContainerUnloader(function(){e.removeEventListener("activate",i,!0)},e)},_onPageBeforeNavigate:function(e){var t=e.window;if(!t.frameElement){var n=t.top||t;this.fireEvent(this.event.BEFORE_NAVIGATE,{url:e.url,target:this.getTab(this.getTabFromWindow(n))})}},_onPageLoad:function(e){e.target.getId&&this.fireEvent(this.event.DOCUMENT_COMPLETE,{url:e.target.getUrl(),title:e.target.getTitle(),target:e.target})},_getTabId:function(e){return e.linkedPanel.toString().split("panel").pop()},_removeTab:function(e){return delete this._tabs[e]},_onTabSelect:function(e){var t=this.getTab(e.target);this.fireEvent(this.event.TAB_CHANGED,{url:t.getUrl(),title:t.getTitle(),target:t,tabId:t.getId()})},_onTabOpen:function(e){var t=this.getTab(e.target);this.fireEvent(this.event.TAB_CREATED,{target:t,tabId:t.getId()})},_onTabClose:function(e){var t=this._getTabId(e.target);this._removeTab(t),this.fireEvent(this.event.TAB_REMOVED,{tabId:t})},_onWindowActivate:function(e){var t=new BrowserWindow(e.target);this.fireEvent(this.event.WINDOW_CHANGED,{target:t,windowId:t.getId()})},getTabFromWindow:function(e){for(var t=e.top||e,n=this.getBrowsers(),r=0;r<n.length;r++){var o=n[r],i=o.getBrowserIndexForDocument(t.document);if(-1!=i)return o.tabContainer.childNodes[i]}return null},getTabFromBrowser:function(e){for(var t=this.getBrowsers(),n=0;n<t.length;n++)for(var r=t[n].tabContainer.childNodes,o=0;o<r.length;o++)if(r[o].linkedBrowser==e)return r[o]},getBrowsers:function(){return array.map(chromeWindows.getLoadedChromeWindows(),function(e){return e.gBrowser})},getTabs:function(e){return array.map(e.tabContainer.childNodes,function(e){return browser.getTab(e)})},getTab:function(e){var t=this._getTabId(e);if("undefined"==typeof this._tabs[t]){this._tabs[t]=new BrowserTab(e,t);var n=this._tabs[t].getChromeWindow();chromeWindows.registerContainerUnloader(func.bind(function(){this._removeTab(t)},this),n)}return this._tabs[t]},getName:function(){return"firefox"},cookies:{getCookies:function(e,t){var n=[],r=Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager),o=Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService),i=o.newURI(e,null,null);if(null!=i)for(var s=i.host,a=i.path||"/",c=r.enumerator;c.hasMoreElements();){var u=c.getNext().QueryInterface(Ci.nsICookie2);s.indexOf(u.host)+u.host.length==s.length&&0==a.indexOf(u.path)&&n.push({name:u.name,value:u.value,domain:u.host,hostOnly:u.isDomain,path:u.path,secure:u.isSecure,httpOnly:u.isHttpOnly,session:u.isSession,expires:u.expires})}t(n)},getCookie:function(e,t,n){this.getCookies(e,function(e){for(var r=0;r<e.length;r++)e[r].name==t&&n(e[r]);n(null)})},setCookie:function(e,t){var n=t.name,r=t.value,o=t.expires||null,i=t.secure||!1,s=t.httpOnly||!1,a=(t.session||!1,Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2)),c=Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService),u=c.newURI(e,null,null);if(null!=u){var g=u.host,d=u.path;a.add(g,d,n,r,i,s,i,o)}}},windows:{getAll:function(e){e(array.map(chromeWindows.getLoadedChromeWindows(),function(e){return new BrowserWindow(e)}))},getCurrent:function(e){e(new BrowserWindow(chromeWindows.getMostRecentChromeWindow()))},create:function(e){chromeWindows.getMostRecentChromeWindow().open(e.url)}}}),BrowserWindow.prototype={getTabs:function(e){e(browser.getTabs(this._gBrowser))},getCurrentTab:function(e){for(var t=this._gBrowser.tabContainer,n=null,r=0;r<t.childNodes.length&&(n=t.childNodes[r],!n.selected);r++);e(browser.getTab(n))},getId:function(){var e=this._window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);return e.outerWindowID},isActive:function(){return chromeWindows.getActiveWindow()==this._window}},BrowserTab.prototype={_getBrowserForTab:function(e){return e.linkedBrowser},_getBrowser:function(){return this._getBrowserForTab(this._tabElem)},_isWindowPrivate:function(e){try{return e.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsILoadContext).usePrivateBrowsing}catch(t){}try{return!!e.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing}catch(t){}return!1},_getMessageManager:function(){return this._getBrowser().messageManager},getChromeWindow:function(){return this._getBrowser().ownerDocument.defaultView},getId:function(){return this._id},getUrl:function(){return this._getBrowserForTab(this._tabElem).currentURI.spec},getTitle:function(){return this._getBrowserForTab(this._tabElem).contentTitle||this._tabElem.label||""},isActive:function(){return this._tabElem.selected},isPrivate:function(){return this._isWindowPrivate(this._getBrowserForTab(this._tabElem).ownerDocument.defaultView)},navigate:function(e){this._getBrowser().loadURI(e)},activate:function(){var e=this.getChromeWindow();e.gBrowser.selectedTab=this._tabElem,e.focus()},dispatchMessage:function(e,t){var n={name:e,data:null!=t?object.sanitize(t):t,origin:"background"},r=require("kango/messaging");this._getMessageManager().sendAsyncMessage(r.getMessageName(),n)},close:function(){this.getChromeWindow().gBrowser.removeTab(this._tabElem)}};var browser=module.exports=new Browser;module.exports.BrowserTab=BrowserTab,module.exports.getPublicApi=getPublicApi;