From 612e652d4a9feac5331c0262bbe6d234df3542e7 Mon Sep 17 00:00:00 2001 From: Einar Egilsson Date: Sat, 9 May 2009 20:46:48 +0000 Subject: 1.7 start git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@209 119bf307-c92d-0410-89bd-8f53e6181181 --- Redirector.csproj | 81 +++++++ Redirector.sln | 20 ++ chrome/content/overlay.js | 181 +++------------- chrome/content/overlay.xul | 5 +- chrome/content/redirect.js | 24 ++- chrome/content/redirect.xul | 6 - chrome/content/redirectList.js | 50 ++++- chrome/content/redirectList.xul | 62 +++--- chrome/content/redirector.js | 312 --------------------------- chrome/content/redirector.tws | Bin 783 -> 0 bytes chrome/content/redirlib.js | 229 -------------------- chrome/locale/en-US/redirect.dtd | 1 - chrome/locale/en-US/redirector.properties | 2 +- components/redirector.js | 338 ++++++++++++++++++++++++++++++ defaults/preferences/redirector.js | 6 +- install.rdf | 6 +- make.bat | 11 - 17 files changed, 568 insertions(+), 766 deletions(-) create mode 100644 Redirector.csproj create mode 100644 Redirector.sln delete mode 100644 chrome/content/redirector.js delete mode 100644 chrome/content/redirector.tws delete mode 100644 chrome/content/redirlib.js create mode 100644 components/redirector.js delete mode 100644 make.bat diff --git a/Redirector.csproj b/Redirector.csproj new file mode 100644 index 0000000..493850f --- /dev/null +++ b/Redirector.csproj @@ -0,0 +1,81 @@ + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {1C962CCA-74DC-4F72-8C83-7617F2275D1A} + Exe + Properties + Redirector + Redirector + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Redirector.sln b/Redirector.sln new file mode 100644 index 0000000..a61c861 --- /dev/null +++ b/Redirector.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Redirector", "Redirector.csproj", "{1C962CCA-74DC-4F72-8C83-7617F2275D1A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1C962CCA-74DC-4F72-8C83-7617F2275D1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1C962CCA-74DC-4F72-8C83-7617F2275D1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1C962CCA-74DC-4F72-8C83-7617F2275D1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1C962CCA-74DC-4F72-8C83-7617F2275D1A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index f1d2241..46f69cc 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -1,5 +1,10 @@ //// $Id$ +var Redirector = Components.classes["@einaregilsson.com/redirector;1"].getService(Components.interfaces.nsISupports).wrappedJSObject; + +function $(id) { + return document.getElementById(id); +} var RedirectorOverlay = { @@ -12,172 +17,35 @@ var RedirectorOverlay = { try { // initialization code - RedirLib.initialize(this); - RedirLib.debug("Initializing..."); + Redirector.debug("Initializing..."); $('contentAreaContextMenu') .addEventListener("popupshowing", function(e) { RedirectorOverlay.showContextMenu(e); }, false); - this.ffversion = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo).version; - - if (!RedirLib.getBoolPref('showContextMenu')) { + if (!Redirector.getBoolPref('showContextMenu')) { $('redirector-context').hidden = true; } - if (!RedirLib.getBoolPref('showStatusBarIcon')) { + if (!Redirector.getBoolPref('showStatusBarIcon')) { $('redirector-status').hidden = true; } - Redirector.init(); - this.overrideOnStateChange(); - this.overrideOpenNewWindowWith(); - this.overrideOpenNewTabWith(); this.strings = document.getElementById("redirector-strings"); - Redirector.strings = this.strings; this.prefObserver.register(); this.setStatusBarImg(); - RedirLib.debug("Finished initialization"); + Redirector.debug("Finished initialization"); this.initialized = true; } catch(e) { - //Don't use RedirLib because it's initialization might have failed. if (this.strings) { - alert(this.strings.getString("initError")._(this.name) + "\n\n" + e); + alert(this.strings.getFormattedString("initError", [this.name]) + "\n\n" + e); } else { alert(e); } } }, - isVersion3 : function() { - return this.ffversion.toString().charAt(0) == '3'; - }, - - overrideOnStateChange : function() { - var origOnStateChange = nsBrowserStatusHandler.prototype.onStateChange; - - nsBrowserStatusHandler.prototype.onStateChange = function(aWebProgress, aRequest, aStateFlags, aStatus) { - if(aStateFlags & Ci.nsIWebProgressListener.STATE_START - && aStateFlags| Ci.nsIWebProgressListener.STATE_IS_NETWORK - && aStateFlags| Ci.nsIWebProgressListener.STATE_IS_REQUEST - && aRequest && aWebProgress.DOMWindow) { - - //If it's not a GET request we'll always do a slow redirect so the web will continue - //to work in the way you'd expect - try { - var oHttp = aRequest.QueryInterface(Ci.nsIHttpChannel); - var method = oHttp.requestMethod; - - if (method != "GET") { - origOnStateChange.apply(this, arguments); - return; - } - - } catch(ex) { - origOnStateChange.apply(this, arguments); - return; - } - - var uri = aRequest.QueryInterface(Ci.nsIChannel).URI.spec; - - RedirLib.debug('Checking url %1 for instant redirect'._(uri)); - var redirectUrl = Redirector.getRedirectUrlForInstantRedirect(uri); - if (redirectUrl.url && oHttp.notificationCallbacks) { - const NS_BINDING_ABORTED = 0x804b0002; - aRequest.cancel(NS_BINDING_ABORTED); - var newStateFlags = Ci.nsIWebProgressListener.STATE_STOP | Ci.nsIWebProgressListener.STATE_IS_NETWORK | Ci.nsIWebProgressListener.STATE_IS_REQUEST; - origOnStateChange.call(this, aWebProgress, aRequest, newStateFlags, ""); - var interfaceRequestor = oHttp.notificationCallbacks.QueryInterface(Ci.nsIInterfaceRequestor); - var targetDoc = interfaceRequestor.getInterface(Ci.nsIDOMWindow).document; - var gotoUrl = Redirector.makeAbsoluteUrl(uri, redirectUrl.url); - Redirector.goto(gotoUrl, redirectUrl.pattern, uri, targetDoc); - } else { - origOnStateChange.apply(this, arguments); - } - - } else { - origOnStateChange.apply(this, arguments); - } - - }; - }, - - overrideOpenNewWindowWith: function() { - - window.__openNewWindowWith = window.openNewWindowWith; - - - if (this.isVersion3()) { - - window.openNewWindowWith = function (aUrl, aDocument, aPostData, aAllowThirdPartyFixup, aReferrer) { - var redirectUrl = Redirector.getRedirectUrlForInstantRedirect(aUrl); - if (redirectUrl.url) { - __openNewWindowWith(redirectUrl.url, aDocument, aPostData, aAllowThirdPartyFixup, aUrl); - } else { - __openNewWindowWith(aUrl, aDocument, aPostData, aAllowThirdPartyFixup, aReferrer); - } - }; - - } else { //version 2.* - - window.openNewWindowWith = function (href, sourceURL, postData, allowThirdPartyFixup) { - var redirectUrl = Redirector.getRedirectUrlForInstantRedirect(href); - if (redirectUrl.url) { - __openNewWindowWith(redirectUrl.url, href, postData, allowThirdPartyFixup); - } else { - __openNewWindowWith(href, sourceURL, postData, allowThirdPartyFixup); - } - }; - } - }, - - - overrideOpenNewTabWith: function() { - - window.__openNewTabWith = window.openNewTabWith; - if (this.isVersion3()) { - window.openNewTabWith = function (aUrl, aDocument, aPostData, aEvent, aAllowThirdPartyFixup, aReferrer) { - var redirectUrl = Redirector.getRedirectUrlForInstantRedirect(aUrl); - if (redirectUrl.url) { - __openNewTabWith(redirectUrl.url, aDocument, aPostData, aEvent, aAllowThirdPartyFixup, aUrl); - } else { - __openNewTabWith(aUrl, aDocument, aPostData, aEvent, aAllowThirdPartyFixup, aReferrer); - } - - }; - - } else { //version 2.* - window.openNewTabWith = function (href, sourceURL, postData, event, allowThirdPartyFixup) { - var redirectUrl = Redirector.getRedirectUrlForInstantRedirect(href); - if (redirectUrl.url) { - __openNewTabWith(redirectUrl.url, href, postData, event, allowThirdPartyFixup); - } else { - __openNewTabWith(href, sourceURL, postData, event, allowThirdPartyFixup); - } - - }; - - } - }, - - - onDOMContentLoaded : function(event) { - var redirect, link, links, url; - - if (event.target.toString().indexOf('HTMLDocument') == -1) { - return; - } - - url = event.target.location.href; - - RedirLib.debug('Processing url %1'._(url)); - Redirector.processUrl(url, event.target); - }, - - onUnload : function(event) { RedirectorOverlay.prefObserver.unregister(); - Redirector.prefObserver.unregister(); - //Clean up here - RedirLib.debug("Finished cleanup"); + Redirector.debug("Finished cleanup"); }, showContextMenu : function(event) { @@ -202,24 +70,37 @@ var RedirectorOverlay = { if (item.saved) { Redirector.addRedirect(item); } - }, onMenuItemCommand: function(event) { - Redirector.openSettings(); + this.openSettings(); }, toggleEnabled : function(event) { - RedirLib.setBoolPref('enabled', !RedirLib.getBoolPref('enabled')); + Redirector.setEnabled(!Redirector.enabled); }, + openSettings : function() { + var windowName = "redirectorSettings"; + var windowsMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); + var win = windowsMediator.getMostRecentWindow(windowName); + if (win) { + win.focus(); + } else { + window.openDialog("chrome://redirector/content/redirectList.xul", + windowName, + "chrome,dialog,resizable=no,centerscreen", this); + } + + }, + statusBarClick : function(event) { var LEFT = 0, RIGHT = 2; if (event.button == LEFT) { RedirectorOverlay.toggleEnabled(); } else if (event.button == RIGHT) { - Redirector.openSettings(); + this.openSettings(); //$('redirector-status-popup').showPopup(); } }, @@ -227,16 +108,16 @@ var RedirectorOverlay = { setStatusBarImg : function() { var statusImg = $('redirector-statusbar-img'); - if (RedirLib.getBoolPref('enabled')) { + if (Redirector.enabled) { statusImg.src = 'chrome://redirector/content/statusactive.PNG' statusImg.setAttribute('tooltiptext', this.strings.getString('enabledTooltip')); - Redirector.enabled = true; } else { statusImg.src = 'chrome://redirector/content/statusinactive.PNG' statusImg.setAttribute('tooltiptext', this.strings.getString('disabledTooltip')); - Redirector.enabled = false; } }, + + prefObserver : { diff --git a/chrome/content/overlay.xul b/chrome/content/overlay.xul index 5bd827f..f46bfcf 100644 --- a/chrome/content/overlay.xul +++ b/chrome/content/overlay.xul @@ -4,9 +4,6 @@ - -