-
Notifications
You must be signed in to change notification settings - Fork 20
/
protocolRedirect.html
119 lines (112 loc) · 3.25 KB
/
protocolRedirect.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE HTML>
<meta charset="utf-8" />
<title>Private Tab: Redirect…</title>
<div id="output"></div>
<div id="usage" style="display: none;">
Usage example: <a href="private:https://addons.mozilla.org/">private:https://addons.mozilla.org/</a>
</div>
<script>
window.onhashchange = function() {
location.reload(); // Allow open "Usage example" link in current tab
};
try {
Components.utils.import("resource://gre/modules/Services.jsm");
// Example: private:///#http://example.com/ (legacy) or private:http://example.com/
// Note: we use protocolRedirect.html#http://..., but we never (?) have it here
var spec = location.protocol == "private:"
? location.href.replace(/^\w+:\/*#?/, "")
: location.hash.substr(1);
try {
var dwu = Components.classes["@mozilla.org/inspector/dom-utils;1"]
.getService(Components.interfaces.inIDOMUtils);
var browser = dwu.getParentForNode(document, true);
if(
!(browser instanceof Components.interfaces.nsIDOMXULElement)
|| browser.localName.toLowerCase() != "browser"
)
throw new Error("Can't get XUL browser");
var doc = browser.ownerDocument;
var win = doc.defaultView;
var gBrowser = win.gBrowser;
// Link may be loaded in current tab, so we should send notification
var tab;
if("_getTabForBrowser" in gBrowser)
tab = gBrowser._getTabForBrowser(browser);
else { // SeaMonkey
for(var i = 0, tabs = gBrowser.tabs, l = tabs.length; i < l; ++i) {
if(tabs[i].linkedBrowser == browser) {
tab = tabs[i];
break;
}
}
}
if(
tab
&& !tab.hasAttribute("privateTab-isPrivate")
&& "PrivateBrowsingUtils" in win
&& win.PrivateBrowsingUtils.isWindowPrivate(window)
) {
tab.dispatchEvent(new win.UIEvent("PrivateTab:PrivateChanged", {
bubbles: true,
cancelable: false,
detail: 1,
view: win
}));
}
//win.setTimeout(function() {
// gBrowser.setTabTitleLoading(tab);
//}, 0);
var getString = function(id) {
try {
return gBrowser.mStringBundle.getString(id);
}
catch(e3) {
}
return undefined;
}
document.title = getString("tabs.connecting")
|| getString("tabs.loading") // SeaMonkey
|| spec;
}
catch(e2) {
document.title = spec;
Components.utils.reportError(e2);
}
if(!spec)
throw new Error("No URI");
if(!/^[^:]+:/.test(spec))
spec = "http://" + spec;
var uri = Services.io.newURI(spec, null, null); // We accept only valid URIs
try {
setFavicon(uri.scheme + "://" + uri.hostPort + "/favicon.ico");
}
catch(e2) {
}
location.replace(spec);
}
catch(e) {
document.title = "Private Tab: Can't redirect";
var out;
if(!("Services" in window)) // We can open this file directly using jar:file:///...
out = "Not enough permissions";
else {
setFavicon("chrome://global/skin/icons/warning-16.png");
if(!spec)
out = "Missing URI";
else if(!uri)
out = "Malformed URI: " + spec;
}
out && document.getElementById("output").appendChild(document.createTextNode(out));
document.getElementById("usage").style.display = "";
throw e;
}
function setFavicon(iconURL) {
var icon = "__icon" in setFavicon && setFavicon.__icon;
if(!icon) {
icon = document.createElement("link");
icon.rel = "shortcut icon";
document.documentElement.insertBefore(icon, document.documentElement.firstChild);
}
icon.href = iconURL;
}
</script>