зеркало из https://github.com/mozilla/pjs.git
bug #40867 (r=bzarsky@mit.edu, sr=jst@netscape.com, a=asa@mozilla.org) Add new caching API to allow view-source to load from the cache and not the network.
This commit is contained in:
Родитель
40071ccd06
Коммит
ea0b54acc7
|
@ -1001,7 +1001,7 @@ function BrowserLoadURL(aTriggeringEvent)
|
|||
{
|
||||
var url = gURLBar.value;
|
||||
if (url.match(/^view-source:/)) {
|
||||
BrowserViewSourceOfURL(url.replace(/^view-source:/, ""), null);
|
||||
BrowserViewSourceOfURL(url.replace(/^view-source:/, ""), null, null);
|
||||
} else {
|
||||
if (pref && pref.getBoolPref("browser.tabs.opentabfor.urlbar") &&
|
||||
getBrowser().localName == "tabbrowser" &&
|
||||
|
@ -1093,25 +1093,59 @@ function OpenAddressbook()
|
|||
"chrome,extrachrome,menubar,resizable,status,toolbar");
|
||||
}
|
||||
|
||||
function BrowserViewSource()
|
||||
function BrowserViewSourceOfDocument(aDocument)
|
||||
{
|
||||
var focusedWindow = document.commandDispatcher.focusedWindow;
|
||||
if (focusedWindow == window)
|
||||
focusedWindow = _content;
|
||||
var docCharset;
|
||||
var pageCookie;
|
||||
var webNav;
|
||||
|
||||
if (focusedWindow)
|
||||
var docCharset = "charset=" + focusedWindow.document.characterSet;
|
||||
// Get the document charset
|
||||
docCharset = "charset=" + aDocument.characterSet;
|
||||
|
||||
BrowserViewSourceOfURL(getWebNavigation().currentURI.spec, docCharset);
|
||||
// Get the nsIWebNavigation associated with the document
|
||||
try {
|
||||
var win;
|
||||
var ifRequestor;
|
||||
|
||||
// Get the DOMWindow for the requested document. If the DOMWindow
|
||||
// cannot be found, then just use the _content window...
|
||||
//
|
||||
// XXX: This is a bit of a hack...
|
||||
win = aDocument.defaultView;
|
||||
if (win == window) {
|
||||
win = _content;
|
||||
}
|
||||
ifRequestor = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
|
||||
|
||||
webNav = ifRequestor.getInterface(Components.interfaces.nsIWebNavigation);
|
||||
} catch(err) {
|
||||
// If nsIWebNavigation cannot be found, just get the one for the whole
|
||||
// window...
|
||||
webNav = getWebNavigation();
|
||||
}
|
||||
//
|
||||
// Get the 'PageDescriptor' for the current document. This allows the
|
||||
// view-source to access the cached copy of the content rather than
|
||||
// refetching it from the network...
|
||||
//
|
||||
try{
|
||||
var PageLoader = webNav.QueryInterface(Components.interfaces.nsIWebPageDescriptor);
|
||||
|
||||
pageCookie = PageLoader.currentDescriptor;
|
||||
} catch(err) {
|
||||
// If no page descriptor is available, just use the view-source URL...
|
||||
}
|
||||
|
||||
BrowserViewSourceOfURL(webNav.currentURI.spec, docCharset, pageCookie);
|
||||
}
|
||||
|
||||
function BrowserViewSourceOfURL(url, charset)
|
||||
function BrowserViewSourceOfURL(url, charset, pageCookie)
|
||||
{
|
||||
// try to open a view-source window while inheriting the charset (if any)
|
||||
openDialog("chrome://navigator/content/viewSource.xul",
|
||||
"_blank",
|
||||
"scrollbars,resizable,chrome,dialog=no",
|
||||
url, charset);
|
||||
url, charset, pageCookie);
|
||||
}
|
||||
|
||||
// doc=null for regular page info, doc=owner document for frame info.
|
||||
|
|
|
@ -133,7 +133,7 @@
|
|||
<command id="cmd_copyImageContents"/>
|
||||
|
||||
<!-- View Menu -->
|
||||
<command id="View:PageSource" oncommand="BrowserViewSource();"/>
|
||||
<command id="View:PageSource" oncommand="BrowserViewSourceOfDocument(_content.document);"/>
|
||||
<command id="View:PageInfo" oncommand="BrowserPageInfo();"/>
|
||||
<command id="View:FullScreen" oncommand="BrowserFullScreen();"/>
|
||||
|
||||
|
|
|
@ -61,22 +61,69 @@ function viewSource(url)
|
|||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if ("arguments" in window && window.arguments.length >= 2) {
|
||||
if (window.arguments[1].indexOf('charset=') != -1) {
|
||||
var arrayArgComponents = window.arguments[1].split('=');
|
||||
if (arrayArgComponents) {
|
||||
//we should "inherit" the charset menu setting in a new window
|
||||
getMarkupDocumentViewer().defaultCharacterSet = arrayArgComponents[1];
|
||||
}
|
||||
var loadFromURL = true;
|
||||
//
|
||||
// Parse the 'arguments' supplied with the dialog.
|
||||
// arg[0] - URL string.
|
||||
// arg[1] - Charset value in the form 'charset=xxx'.
|
||||
// arg[2] - Page descriptor used to load content from the cache.
|
||||
//
|
||||
if ("arguments" in window) {
|
||||
var arg;
|
||||
//
|
||||
// Set the charset of the viewsource window...
|
||||
//
|
||||
if (window.arguments.length >= 2) {
|
||||
arg = window.arguments[1];
|
||||
|
||||
try {
|
||||
if (typeof(arg) == "string" && arg.indexOf('charset=') != -1) {
|
||||
var arrayArgComponents = arg.split('=');
|
||||
if (arrayArgComponents) {
|
||||
//we should "inherit" the charset menu setting in a new window
|
||||
getMarkupDocumentViewer().defaultCharacterSet = arrayArgComponents[1];
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
// Ignore the failure and keep processing arguments...
|
||||
}
|
||||
}
|
||||
//
|
||||
// Use the page descriptor to load the content from the cache (if
|
||||
// available).
|
||||
//
|
||||
if (window.arguments.length >= 3) {
|
||||
arg = window.arguments[2];
|
||||
|
||||
try {
|
||||
if (typeof(arg) == "object" && arg != null) {
|
||||
var pageLoaderIface = Components.interfaces.nsIWebPageDescriptor;
|
||||
var PageLoader = getBrowser().webNavigation.QueryInterface(pageLoaderIface);
|
||||
|
||||
//
|
||||
// Load the page using the page descriptor rather than the URL.
|
||||
// This allows the content to be fetched from the cache (if
|
||||
// possible) rather than the network...
|
||||
//
|
||||
PageLoader.LoadPage(arg, pageLoaderIface.DISPLAY_AS_SOURCE);
|
||||
// The content was successfully loaded from the page cookie.
|
||||
loadFromURL = false;
|
||||
}
|
||||
} catch(ex) {
|
||||
// Ignore the failure. The content will be loaded via the URL
|
||||
// that was supplied in arg[0].
|
||||
}
|
||||
}
|
||||
} catch(ex) {
|
||||
}
|
||||
|
||||
var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
|
||||
var viewSrcUrl = "view-source:" + url;
|
||||
getBrowser().webNavigation.loadURI(viewSrcUrl, loadFlags, null, null, null);
|
||||
if (loadFromURL) {
|
||||
//
|
||||
// Currently, an exception is thrown if the URL load fails...
|
||||
//
|
||||
var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
|
||||
var viewSrcUrl = "view-source:" + url;
|
||||
getBrowser().webNavigation.loadURI(viewSrcUrl, loadFlags, null, null, null);
|
||||
}
|
||||
|
||||
//check the view_source.wrap_long_lines pref and set the menuitem's checked attribute accordingly
|
||||
if (gPrefs) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче