110679 - minor performance optimizations in navigator. r=hewitt sr=ben

This commit is contained in:
blakeross%telocity.com 2001-11-18 18:41:24 +00:00
parent 8f49ae4dbe
commit 780cae7e50
5 changed files with 77 additions and 50 deletions

View File

@ -44,6 +44,7 @@ var gURLBar = null;
var gProxyButton = null;
var gProxyFavIcon = null;
var gProxyDeck = null;
var gBookmarksService = null;
var gNavigatorBundle;
var gBrandBundle;
var gNavigatorRegionBundle;
@ -62,6 +63,7 @@ var gBrowser = null;
// focused frame URL
var gFocusedURL = null;
var gFocusedDocument = null;
/**
* We can avoid adding multiple load event listeners and save some time by adding
@ -75,7 +77,6 @@ function loadEventHandlers(event)
UpdateBookmarksLastVisitedDate(event);
UpdateInternetSearchResults(event);
checkForDirectoryListing();
getContentAreaFrameCount();
postURLToNativeWidget();
}
}
@ -99,8 +100,7 @@ function contentAreaFrameFocus()
var focusedWindow = document.commandDispatcher.focusedWindow;
if (isDocumentFrame(focusedWindow)) {
gFocusedURL = focusedWindow.location.href;
var saveFrameItem = document.getElementById("savepage");
saveFrameItem.removeAttribute("hidden");
gFocusedDocument = focusedWindow.document;
}
}
@ -114,10 +114,11 @@ function UpdateBookmarksLastVisitedDate(event)
var url = _content.location.href;
if (url) {
// if the URL is bookmarked, update its "Last Visited" date
var bmks = Components.classes["@mozilla.org/browser/bookmarks-service;1"]
.getService(Components.interfaces.nsIBookmarksService);
if (!gBookmarksService)
gBookmarksService = Components.classes["@mozilla.org/browser/bookmarks-service;1"]
.getService(Components.interfaces.nsIBookmarksService);
bmks.UpdateBookmarkLastVisitedDate(url, _content.document.characterSet);
gBookmarksService.UpdateBookmarkLastVisitedDate(url, _content.document.characterSet);
}
}
@ -134,11 +135,11 @@ function UpdateInternetSearchResults(event)
if (autoOpenSearchPanel || isSearchPanelOpen())
{
var search = Components.
classes["@mozilla.org/rdf/datasource;1?name=internetsearch"].
getService(Components.interfaces.nsIInternetSearchService);
if (!gSearchService)
gSearchService = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
.getService(Components.interfaces.nsIInternetSearchService);
var searchInProgressFlag = search.FindInternetSearchResults(url);
var searchInProgressFlag = gSearchService.FindInternetSearchResults(url);
if (searchInProgressFlag) {
if (autoOpenSearchPanel)
@ -148,10 +149,10 @@ function UpdateInternetSearchResults(event)
} catch (ex) {
}
}
if (document.getElementById("main-window").getAttribute("fullScreen") == "true") {
BrowserFullScreenEnter();
}
}
function getBrowser()
@ -411,9 +412,10 @@ function Startup()
function LoadBookmarksCallback()
{
try {
var bmservice = Components.classes["@mozilla.org/browser/bookmarks-service;1"]
.getService(Components.interfaces.nsIBookmarksService);
bmservice.ReadBookmarks();
if (!gBookmarksService)
gBookmarksService = Components.classes["@mozilla.org/browser/bookmarks-service;1"]
.getService(Components.interfaces.nsIBookmarksService);
gBookmarksService.ReadBookmarks();
// tickle personal toolbar to load personal toolbar items
var personalToolbar = document.getElementById("innermostBox");
personalToolbar.builder.rebuild();
@ -1024,10 +1026,11 @@ function getShortcutOrURI(url)
{
// rjc: added support for URL shortcuts (3/30/1999)
try {
var bmks = Components.classes["@mozilla.org/browser/bookmarks-service;1"]
.getService(Components.interfaces.nsIBookmarksService);
if (!gBookmarksService)
gBookmarksService = Components.classes["@mozilla.org/browser/bookmarks-service;1"]
.getService(Components.interfaces.nsIBookmarksService);
var shortcutURL = bmks.FindShortcut(url);
var shortcutURL = gBookmarksService.FindShortcut(url);
if (!shortcutURL) {
// rjc: add support for string substitution with shortcuts (4/4/2000)
// (see bug # 29871 for details)
@ -1035,7 +1038,7 @@ function getShortcutOrURI(url)
if (aOffset > 0) {
var cmd = url.substr(0, aOffset);
var text = url.substr(aOffset+1);
shortcutURL = bmks.FindShortcut(cmd);
shortcutURL = gBookmarksService.FindShortcut(cmd);
if (shortcutURL && text) {
aOffset = shortcutURL.indexOf("%s");
if (aOffset >= 0)
@ -1120,7 +1123,6 @@ function BrowserFullScreenToggle()
next = next.nextSibling;
}
// toggle and save the fullScreen indicator
gFullScreen = !gFullScreen;
document.getElementById("main-window").setAttribute("fullScreen", gFullScreen?"true":"false");
@ -1146,7 +1148,6 @@ function BrowserViewSource()
if (focusedWindow == window)
focusedWindow = _content;
dump("focusedWindow = " + focusedWindow + "\n");
if (focusedWindow)
var docCharset = "charset=" + focusedWindow.document.characterSet;
@ -1424,7 +1425,7 @@ function stylesheetFillPopup(forDocument, menuPopup, itemNoOptStyles)
currentStyleSheets[currentStyleSheet.title] = menuItem;
} else {
if (currentStyleSheet.disabled)
lastWithSameTitle.setAttribute("checked", false);
lastWithSameTitle.removeAttribute("checked");
}
}
}
@ -1447,7 +1448,8 @@ function stylesheetSwitch(forDocument, title)
function applyTheme(themeName)
{
if (themeName.getAttribute("name") == "")
var name = themeName.getAttribute("name");
if (!name)
return;
var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
@ -1455,7 +1457,7 @@ function applyTheme(themeName)
var oldTheme = false;
try {
oldTheme = !chromeRegistry.checkThemeVersion(themeName.getAttribute("name"));
oldTheme = !chromeRegistry.checkThemeVersion(name);
}
catch(e) {
}

View File

@ -123,7 +123,6 @@ Contributor(s): ______________________________________. -->
<!-- tooltips -->
<popupset id="aTooltipSet"/>
</popupset>
<script type="application/x-javascript">
var gBookmarkPopup = null;
</script>
@ -138,7 +137,7 @@ Contributor(s): ______________________________________. -->
tbalign="stretch" tooltip="aTooltip">
<hbox id="nav-bar-buttons">
<toolbarbutton id="back-button" type="menu-button" class="toolbarbutton-1"
label="&backButton.label;" crop="right"
label="&backButton.label;"
oncommand="if (event.target==this) BrowserBack(); else gotoHistoryIndex(event);"
observes="canGoBack" context="backMenu"
tooltiptext="&backButton.tooltip;">
@ -146,7 +145,7 @@ Contributor(s): ______________________________________. -->
</toolbarbutton>
<toolbarbutton id="forward-button" type="menu-button" class="toolbarbutton-1"
label="&forwardButton.label;" crop="right"
label="&forwardButton.label;"
oncommand="if (event.target==this) BrowserForward(); else gotoHistoryIndex(event);"
observes="canGoForward" context="forwardMenu"
tooltiptext="&forwardButton.tooltip;">
@ -154,16 +153,16 @@ Contributor(s): ______________________________________. -->
</toolbarbutton>
<toolbarbutton id="reload-button" class="toolbarbutton-1"
label="&reloadButton.label;" crop="right"
label="&reloadButton.label;"
oncommand="if (event.shiftKey) BrowserReloadSkipCache(); else BrowserReload();"
tooltiptext="&reloadButton.tooltip;"/>
<toolbarbutton id="stop-button" class="toolbarbutton-1"
label="&stopButton.label;" crop="right"
label="&stopButton.label;"
oncommand="BrowserStop();" observes="canStop"
tooltiptext="&stopButton.tooltip;"/>
</hbox>
<hbox id="fullscreen-extra-buttons" hidden="true">
<toolbarbutton id="fullscreen-exit-button" class="toolbarbutton-1"
label="&exitFullScreenButton.label;" crop="right"
@ -219,7 +218,7 @@ Contributor(s): ______________________________________. -->
</hbox>
<toolbarbutton id="print-button" type="menu-button" class="toolbarbutton-1"
label="&printButton.label;" crop="right" persist="hidden"
label="&printButton.label;" persist="hidden"
oncommand="if (event.target==this) BrowserPrint();"
tooltiptext="&printButton.tooltip;">
<menupopup id="printMenu">
@ -254,7 +253,7 @@ Contributor(s): ______________________________________. -->
<!-- "Bookmarks" button on personal toolbar -->
<toolbarbutton type="menu" id="bookmarks-button" class="bookmark-item"
persist="hidden" label="&bookmarksButton.label;" hidden="false"
persist="hidden" label="&bookmarksButton.label;"
datasources="rdf:bookmarks rdf:files rdf:localsearch rdf:internetsearch"
ref="NC:BookmarksRoot" container="true" flags="dont-test-empty"
oncommand="OpenBookmarkURL(event.target,document.getElementById('BookmarksMenu').database)"

View File

@ -40,9 +40,6 @@
var DROP_BEFORE = -1;
var DROP_ON = 0;
var DROP_AFTER = 1;
var gRDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
function _RDF(aType)
{
return "http://www.w3.org/1999/02/22-rdf-syntax-ns#" + aType;
@ -55,7 +52,7 @@ function NC_RDF(aType)
var RDFUtils = {
getResource: function(aString)
{
return gRDFService.GetResource(aString, true);
return this.rdf.GetResource(aString, true);
},
getTarget: function(aDS, aSourceID, aPropertyID)
@ -69,7 +66,15 @@ var RDFUtils = {
{
aResource = aResource.QueryInterface(Components.interfaces.nsIRDFResource);
return aResource ? aResource.Value : null;
},
_rdf: null,
get rdf() {
if (!this._rdf) {
this._rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
}
return this._rdf;
}
};
function isBookmark(aURI)
@ -161,7 +166,7 @@ var personalToolbarObserver = {
var linkTitle;
// look it up in bookmarks
var bookmarksDS = gRDFService.GetDataSource("rdf:bookmarks");
var bookmarksDS = RDFUtils.rdf.GetDataSource("rdf:bookmarks");
var nameRes = RDFUtils.getResource(NC_RDF("Name"));
var nameFromBookmarks = bookmarksDS.GetTarget(elementRes, nameRes, true);
if (nameFromBookmarks)
@ -175,7 +180,7 @@ var personalToolbarObserver = {
{
// look up this URL's title in global history
var potentialTitle = null;
var historyDS = gRDFService.GetDataSource("rdf:history");
var historyDS = RDFUtils.rdf.GetDataSource("rdf:history");
var titlePropRes = RDFUtils.getResource(NC_RDF("Name"));
var titleFromHistory = historyDS.GetTarget(elementRes, titlePropRes, true);
if (titleFromHistory)
@ -542,7 +547,7 @@ var menuDNDObserver = {
var linkTitle;
// look it up in bookmarks
var bookmarksDS = gRDFService.GetDataSource("rdf:bookmarks");
var bookmarksDS = RDFUtils.rdf.GetDataSource("rdf:bookmarks");
var nameRes = RDFUtils.getResource(NC_RDF("Name"));
var nameFromBookmarks = bookmarksDS.GetTarget(elementRes, nameRes, true);
if (nameFromBookmarks)
@ -554,7 +559,7 @@ var menuDNDObserver = {
linkTitle = xferData[1]
else {
// look up this URL's title in global history
var historyDS = gRDFService.GetDataSource("rdf:history");
var historyDS = RDFUtils.rdf.GetDataSource("rdf:history");
var titlePropRes = RDFUtils.getResource(NC_RDF("Name"));
var titleFromHistory = historyDS.GetTarget(elementRes, titlePropRes, true);
if (titleFromHistory)

View File

@ -168,7 +168,7 @@
<!-- Menu -->
<menubar id="main-menubar" class="chromeclass-menubar">
<menu id="menu_File">
<menupopup id="menu_FilePopup">
<menupopup id="menu_FilePopup" onpopupshowing="getContentAreaFrameCount();">
<menuitem label="&browserCmd.label;" accesskey="&browserCmd.accesskey;" key="key_newNavigator" command="cmd_newNavigator"/>
<menu id="menu_New">
<menupopup id="menu_NewPopup">

View File

@ -39,11 +39,9 @@
* ***** END LICENSE BLOCK ***** */
const MAX_HISTORY_MENU_ITEMS = 15;
const MAX_HISTORY_ITEMS = 100;
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
var rdfc = Components.classes["@mozilla.org/rdf/container-utils;1"]
.getService(Components.interfaces.nsIRDFContainerUtils);
var localstore = rdf.GetDataSource("rdf:localstore");
var gRDF = null;
var gRDFC = null;
var gLocalStore = null;
function FillHistoryMenu(aParent, aMenu)
{
@ -112,8 +110,19 @@ function executeUrlBarHistoryCommand( aTarget )
function createUBHistoryMenu( aParent )
{
if (localstore) {
var entries = rdfc.MakeSeq(localstore, rdf.GetResource("nc:urlbar-history")).GetElements();
if (!gRDF)
gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
if (!gLocalStore)
gLocalStore = gRDF.GetDataSource("rdf:localstore");
if (gLocalStore) {
if (!gRDFC)
gRDFC = Components.classes["@mozilla.org/rdf/container-utils;1"]
.getService(Components.interfaces.nsIRDFContainerUtils);
var entries = gRDFC.MakeSeq(gLocalStore, gRDF.GetResource("nc:urlbar-history")).GetElements();
var i= MAX_HISTORY_MENU_ITEMS;
// Delete any old menu items only if there are legitimate
@ -150,8 +159,20 @@ function addToUrlbarHistory()
return;
if (urlToAdd.search(/[\x00-\x1F]/) != -1) // don't store bad URLs
return;
if (localstore) {
var entries = rdfc.MakeSeq(localstore, rdf.GetResource("nc:urlbar-history"));
if (!gRDF)
gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
if (!gLocalStore)
gLocalStore = gRDF.GetDataSource("rdf:localstore");
if (gLocalStore) {
if (!gRDFC)
gRDFC = Components.classes["@mozilla.org/rdf/container-utils;1"]
.getService(Components.interfaces.nsIRDFContainerUtils);
var entries = gRDFC.MakeSeq(gLocalStore, gRDF.GetResource("nc:urlbar-history"));
if (!entries)
return;
var elements = entries.GetElements();
@ -222,7 +243,7 @@ function addToUrlbarHistory()
}
} // while
var entry = rdf.GetLiteral(urlToAdd);
var entry = gRDF.GetLiteral(urlToAdd);
// Otherwise, we've got a new URL in town. Add it!
// Put the value as it was typed by the user in to RDF
// Insert it to the beginning of the list.