diff --git a/mozilla/toolkit/components/viewsource/content/viewPartialSource.js b/mozilla/toolkit/components/viewsource/content/viewPartialSource.js
index e4886a64296..5758b846671 100644
--- a/mozilla/toolkit/components/viewsource/content/viewPartialSource.js
+++ b/mozilla/toolkit/components/viewsource/content/viewPartialSource.js
@@ -56,7 +56,8 @@ const MARK_SELECTION_START = '\u200B\u200B\u200B\u200B\u200B';
const MARK_SELECTION_END = '\u200B\u200B\u200B\u200B\u200B';
function onLoadViewPartialSource()
-{
+{
+ gBrowser = document.getElementById("content");
// check the view_source.wrap_long_lines pref and set the menuitem's checked attribute accordingly
if (gPrefs) {
try {
@@ -66,6 +67,12 @@ function onLoadViewPartialSource()
gWrapLongLines = true;
}
} catch (e) { }
+ try {
+ document.getElementById("menu_highlightSyntax").setAttribute("checked", gPrefs.getBoolPref("view_source.syntax_highlight"));
+ } catch (e) {
+ }
+ } else {
+ document.getElementById("menu_highlightSyntax").setAttribute("hidden", "true");
}
// disable menu items that don't work since the selection is munged and
@@ -101,12 +108,20 @@ function viewPartialSourceForSelection(selection)
ancestorContainer.nodeType == Node.CDATA_SECTION_NODE)
ancestorContainer = ancestorContainer.parentNode;
+ // for selectAll, let's use the entire document, including ...
+ // @see DocumentViewerImpl::SelectAll() for how selectAll is implemented
+ try {
+ if (ancestorContainer == doc.body)
+ ancestorContainer = doc.documentElement;
+ } catch (e) { }
+
// each path is a "child sequence" (a.k.a. "tumbler") that
// descends from the ancestor down to the boundary point
var startPath = getPath(ancestorContainer, startContainer);
var endPath = getPath(ancestorContainer, endContainer);
// clone the fragment of interest and reset everything to be relative to it
+ // note: it is with the clone that we operate from now on
ancestorContainer = ancestorContainer.cloneNode(true);
startContainer = ancestorContainer;
endContainer = ancestorContainer;
@@ -130,7 +145,7 @@ function viewPartialSourceForSelection(selection)
// To get a neat output, the idea here is to remap the end point from:
// 1. ...]... to ...]...
// 2. ...]... to ...]...
- if ((endOffset > 0 && endOffset < endContainer.data.length-1) ||
+ if ((endOffset > 0 && endOffset < endContainer.data.length) ||
!endContainer.parentNode || !endContainer.parentNode.parentNode)
endContainer.insertData(endOffset, MARK_SELECTION_END);
else {
@@ -154,8 +169,9 @@ function viewPartialSourceForSelection(selection)
// To get a neat output, the idea here is to remap the start point from:
// 1. ...[... to ...[...
// 2. ...[... to ...[...
- if ((startOffset > 0 && startOffset < startContainer.data.length-1) ||
- !startContainer.parentNode || !startContainer.parentNode.parentNode)
+ if ((startOffset > 0 && startOffset < startContainer.data.length) ||
+ !startContainer.parentNode || !startContainer.parentNode.parentNode ||
+ startContainer != startContainer.parentNode.lastChild)
startContainer.insertData(startOffset, MARK_SELECTION_START);
else {
tmpNode = doc.createTextNode(MARK_SELECTION_START);
@@ -181,8 +197,8 @@ function viewPartialSourceForSelection(selection)
// all our content is held by the data:URI and URIs are internally stored as utf-8 (see nsIURI.idl)
var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
- getBrowser().webNavigation
- .loadURI("view-source:data:text/html;charset=utf-8," + escape(tmpNode.innerHTML),
+ gBrowser.webNavigation
+ .loadURI("view-source:data:text/html;charset=utf-8," + escape(tmpNode.innerHTML),
loadFlags, null, null, null);
}
@@ -213,7 +229,7 @@ function getPath(ancestor, node)
////////////////////////////////////////////////////////////////////////////////
// using special markers left in the serialized source, this helper makes the
-// underlying markup of the selected fragement to automatically appear as selected
+// underlying markup of the selected fragment to automatically appear as selected
// on the inflated view-source DOM
function drawSelection()
{
@@ -237,10 +253,10 @@ function drawSelection()
var replaceString = findService.replaceString;
// setup our find instance
- var findInst = getBrowser().webBrowserFind;
+ var findInst = gBrowser.webBrowserFind;
findInst.matchCase = true;
findInst.entireWord = false;
- findInst.wrapFind = false;
+ findInst.wrapFind = true;
findInst.findBackwards = false;
// ...lookup the start mark
@@ -248,7 +264,7 @@ function drawSelection()
var startLength = MARK_SELECTION_START.length;
findInst.findNext();
- var contentWindow = getBrowser().contentDocument.defaultView;
+ var contentWindow = gBrowser.contentDocument.defaultView;
var selection = contentWindow.getSelection();
var range = selection.getRangeAt(0);
@@ -279,11 +295,11 @@ function drawSelection()
// the selection, whereas in this situation, it is more user-friendly
// to scroll at the beginning. So we override the default behavior here
try {
- getBrowser().docShell
- .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
- .getInterface(Components.interfaces.nsISelectionDisplay)
- .QueryInterface(Components.interfaces.nsISelectionController)
- .scrollSelectionIntoView(Components.interfaces.nsISelectionController.SELECTION_NORMAL,
+ gBrowser.docShell
+ .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+ .getInterface(Components.interfaces.nsISelectionDisplay)
+ .QueryInterface(Components.interfaces.nsISelectionController)
+ .scrollSelectionIntoView(Components.interfaces.nsISelectionController.SELECTION_NORMAL,
Components.interfaces.nsISelectionController.SELECTION_ANCHOR_REGION,
true);
}
@@ -343,7 +359,7 @@ function viewPartialSourceForFragment(node, context)
; // end
// display
- var doc = getBrowser().contentDocument;
+ var doc = gBrowser.contentDocument;
doc.open("text/html", "replace");
doc.write(source);
doc.close();
@@ -442,39 +458,44 @@ function getOuterMarkup(node, indent) {
////////////////////////////////////////////////////////////////////////////////
function unicodeTOentity(text)
{
+ const charTable = {
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '"': '"'
+ };
+
+ function charTableLookup(letter) {
+ return charTable[letter];
+ }
+
+ function convertEntity(letter) {
+ try {
+ var unichar = gEntityConverter.ConvertToEntity(letter, entityVersion);
+ var entity = unichar.substring(1); // extract '&'
+ return '&' + entity + '';
+ } catch (ex) {
+ return letter;
+ }
+ }
+
if (!gEntityConverter) {
try {
- gEntityConverter = Components.classes["@mozilla.org/intl/entityconverter;1"]
- .createInstance(Components.interfaces.nsIEntityConverter);
+ gEntityConverter =
+ Components.classes["@mozilla.org/intl/entityconverter;1"]
+ .createInstance(Components.interfaces.nsIEntityConverter);
} catch(e) { }
}
- var entityVersion = Components.interfaces.nsIEntityConverter.html40
- + Components.interfaces.nsIEntityConverter.mathml20;
- var str = '';
- for (var i = 0; i < text.length; i++) {
- var c = text.charCodeAt(i);
- if ((c <= 0x7F) || !gEntityConverter) {
- if (text[i] == '<')
- str += '<';
- else if (text[i] == '>')
- str += '>';
- else if (text[i] == '&')
- str += '&';
- else
- str += text[i];
- }
- else {
- try {
- var unichar = gEntityConverter.ConvertToEntity(text[i], entityVersion);
- str += '&'
- + unichar.substring(1, unichar.length) // extract '&'
- + '';
- }
- catch(e) {
- str += text[i];
- }
- }
- }
+ const entityVersion = Components.interfaces.nsIEntityConverter.entityW3C;
+
+ var str = text;
+
+ // replace chars in our charTable
+ str = str.replace(/[<>&"]/g, charTableLookup);
+
+ // replace chars > 0x7f via nsIEntityConverter
+ str = str.replace(/[^\0-\u007f]/g, convertEntity);
+
return str;
}
diff --git a/mozilla/toolkit/components/viewsource/content/viewSource.js b/mozilla/toolkit/components/viewsource/content/viewSource.js
index eb2af2f4357..264fa98707a 100644
--- a/mozilla/toolkit/components/viewsource/content/viewSource.js
+++ b/mozilla/toolkit/components/viewsource/content/viewSource.js
@@ -23,7 +23,6 @@
const pageLoaderIface = Components.interfaces.nsIWebPageDescriptor;
var gBrowser = null;
-var appCore = null;
var gPrefs = null;
try {
@@ -35,15 +34,9 @@ try {
function onLoadViewSource()
{
+ gBrowser = document.getElementById("content");
viewSource(window.arguments[0]);
- window._content.focus();
-}
-
-function getBrowser()
-{
- if (!gBrowser)
- gBrowser = document.getElementById("content");
- return gBrowser;
+ document.commandDispatcher.focusedWindow = content;
}
function viewSource(url)
@@ -51,18 +44,6 @@ function viewSource(url)
if (!url)
return false; // throw Components.results.NS_ERROR_FAILURE;
- try {
- appCore = Components.classes["@mozilla.org/appshell/component/browser/instance;1"]
- .createInstance(Components.interfaces.nsIBrowserInstance);
-
- // Initialize browser instance..
- appCore.setWebShellWindow(window);
- } catch(ex) {
- // Give up.
- window.close();
- return false;
- }
-
var loadFromURL = true;
//
// Parse the 'arguments' supplied with the dialog.
@@ -99,7 +80,7 @@ function viewSource(url)
try {
if (typeof(arg) == "object" && arg != null) {
- var PageLoader = getBrowser().webNavigation.QueryInterface(pageLoaderIface);
+ var PageLoader = gBrowser.webNavigation.QueryInterface(pageLoaderIface);
//
// Load the page using the page descriptor rather than the URL.
@@ -123,7 +104,7 @@ function viewSource(url)
//
var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
var viewSrcUrl = "view-source:" + url;
- getBrowser().webNavigation.loadURI(viewSrcUrl, loadFlags, null, null, null);
+ gBrowser.webNavigation.loadURI(viewSrcUrl, loadFlags, null, null, null);
}
//check the view_source.wrap_long_lines pref and set the menuitem's checked attribute accordingly
@@ -136,11 +117,11 @@ function viewSource(url)
} catch (ex) {
}
try {
- document.getElementById("cmd_highlightSyntax").setAttribute("checked", gPrefs.getBoolPref("view_source.syntax_highlight"));
+ document.getElementById("menu_highlightSyntax").setAttribute("checked", gPrefs.getBoolPref("view_source.syntax_highlight"));
} catch (ex) {
}
} else {
- document.getElementById("cmd_highlightSyntax").setAttribute("hidden", "true");
+ document.getElementById("menu_highlightSyntax").setAttribute("hidden", "true");
}
window._content.focus();
@@ -200,20 +181,24 @@ function wrapLongLines()
//pref to persist the last state
function highlightSyntax()
{
- var highlightSyntaxCmd = document.getElementById("cmd_highlightSyntax");
- var highlightSyntax = highlightSyntaxCmd.getAttribute("checked") != "true";
- highlightSyntaxCmd.setAttribute("checked", highlightSyntax);
+ var highlightSyntaxMenu = document.getElementById("menu_highlightSyntax");
+ var highlightSyntax = (highlightSyntaxMenu.getAttribute("checked") == "true");
gPrefs.setBoolPref("view_source.syntax_highlight", highlightSyntax);
- var PageLoader = getBrowser().webNavigation.QueryInterface(pageLoaderIface);
+ var PageLoader = gBrowser.webNavigation.QueryInterface(pageLoaderIface);
PageLoader.LoadPage(PageLoader.currentDescriptor, pageLoaderIface.DISPLAY_NORMAL);
}
function BrowserSetForcedCharacterSet(aCharset)
{
- var docCharset = getBrowser().docShell.QueryInterface(
- Components.interfaces.nsIDocCharset);
+ var docCharset = gBrowser.docShell
+ .QueryInterface(Components.interfaces.nsIDocCharset);
docCharset.charset = aCharset;
- var PageLoader = getBrowser().webNavigation.QueryInterface(pageLoaderIface);
+ var PageLoader = gBrowser.webNavigation.QueryInterface(pageLoaderIface);
PageLoader.LoadPage(PageLoader.currentDescriptor, pageLoaderIface.DISPLAY_NORMAL);
}
+
+function BrowserFind()
+{
+ findInPage(gBrowser, window._content, window._content)
+}
diff --git a/mozilla/toolkit/components/viewsource/content/viewSource.xul b/mozilla/toolkit/components/viewsource/content/viewSource.xul
index 3f186de955f..4f12112c3ce 100644
--- a/mozilla/toolkit/components/viewsource/content/viewSource.xul
+++ b/mozilla/toolkit/components/viewsource/content/viewSource.xul
@@ -57,7 +57,6 @@
screenX="10" screenY="10"
persist="screenX screenY width height sizemode">
-
diff --git a/mozilla/toolkit/components/viewsource/content/viewSourceOverlay.xul b/mozilla/toolkit/components/viewsource/content/viewSourceOverlay.xul
index e35f69a7663..4d3cae8d0d4 100644
--- a/mozilla/toolkit/components/viewsource/content/viewSourceOverlay.xul
+++ b/mozilla/toolkit/components/viewsource/content/viewSourceOverlay.xul
@@ -53,9 +53,8 @@
-
-
+
@@ -144,9 +143,9 @@