How is gBrowser and xpcom used? Can you talk about it too?
gBrowser
gBrowser is the name of the component in a Firefox browser window that manages tabs, and the underlying infrastructure for switching tabs, adding tabs, knowing about tab switches, etc.
gBrowser is a window-global instance of a component called tabbrowser
gBrowser is a pretty bad name for what it is. Could maybe be called gTabsManager or gBrowsersManager
, is similar to an
g is for global, a is for argument, m is for method, s is for static, k is for global constant, ALL_CAPS for global constant
Firefox used to not have tabs! At some point in its lineage, Firefox didn’t have tabs. It was one per window. gBrowser.
They kept the same name when adding tabs! I think this was to make it easier to support XUL add-ons that relied on touching gBrowser. The new gBrowser variable had the same interface as the old one but would forward calls to the currently selected .
It’s a very old Mozilla technology modeled after COM from Microsoft
Infrastructure for defining interfaces for components that are implementation-language agnostic
This means a component written in language A can in theory talk to a component written in language B by way of an interface defined in an (XP)IDL file (.idl)
The dream was that Mozilla-backed applications could be written in whatever language you wanted so long as it “supported XPCOM/XPConnect”.
XPCOM components these days are written in C++, JavaScript or Rust
Registry of XPCOM components, and XPCOM component singletons (“services”)
Cc (Components.classes), Ci (Components.interfaces)
let referrerInfo = Cc[“@mozilla.org/referrer-info;1”].createInstance(Ci.nsIReferrerInfo);