This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4566cba
Showing
31 changed files
with
1,096 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.hg | ||
openinbrowser.kpf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
all: | ||
: | ||
|
||
NAME := openinbrowser | ||
VERSION := $(shell grep em:version install.rdf|sed 's@.*em:version>\([^<]*\)<.*@\1@') | ||
TARGET_XPI = $(NAME)-$(VERSION).xpi | ||
|
||
xpi: | ||
rm -rf ../tmp || : | ||
mkdir ../tmp | ||
cp -r ../$(NAME) ../tmp | ||
cd ../tmp/$(NAME)/chrome; \ | ||
zip -r $(NAME).jar *; \ | ||
rm -rf content locale | ||
rm -rf ../tmp/$(NAME)/.hg | ||
find ../tmp -name "*~" -exec rm {} \; | ||
rm ../tmp/$(NAME)/chrome.manifest | ||
mv ../tmp/$(NAME)/chrome.manifest_jar ../tmp/$(NAME)/chrome.manifest | ||
cd ../tmp/$(NAME); \ | ||
zip -r $(TARGET_XPI) * | ||
rm ../$(TARGET_XPI) || : | ||
mv ../tmp/$(NAME)/$(TARGET_XPI) .. | ||
rm -rf ../tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
content openinbrowser chrome/content/ | ||
locale openinbrowser de-DE chrome/locale/de-DE/ | ||
locale openinbrowser en-US chrome/locale/en-US/ | ||
locale openinbrowser fr chrome/locale/fr/ | ||
locale openinbrowser sv-SE chrome/locale/sv-SE/ | ||
|
||
overlay chrome://mozapps/content/downloads/unknownContentType.xul chrome://openinbrowser/content/unknownContentTypeOverlay.xul | ||
overlay chrome://browser/content/browser.xul chrome://openinbrowser/content/browserOverlay.xul | ||
overlay chrome://navigator/content/navigator.xul chrome://openinbrowser/content/browserOverlay.xul | ||
|
||
component {14aa9340-c449-4956-a5f9-a52fb32f933d} components/OpenInBrowser.js | ||
contract @spasche.net/openinbrowser;1 {14aa9340-c449-4956-a5f9-a52fb32f933d} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
content openinbrowser jar:chrome/openinbrowser.jar!/content/ | ||
locale openinbrowser de-DE jar:chrome/openinbrowser.jar!/locale/de-DE/ | ||
locale openinbrowser en-US jar:chrome/openinbrowser.jar!/locale/en-US/ | ||
locale openinbrowser fr jar:chrome/openinbrowser.jar!/locale/fr/ | ||
locale openinbrowser sv-SE jar:chrome/openinbrowser.jar!/locale/sv-SE/ | ||
|
||
overlay chrome://mozapps/content/downloads/unknownContentType.xul chrome://openinbrowser/content/unknownContentTypeOverlay.xul | ||
overlay chrome://browser/content/browser.xul chrome://openinbrowser/content/browserOverlay.xul | ||
overlay chrome://navigator/content/navigator.xul chrome://openinbrowser/content/browserOverlay.xul | ||
|
||
component {14aa9340-c449-4956-a5f9-a52fb32f933d} components/OpenInBrowser.js | ||
contract @spasche.net/openinbrowser;1 {14aa9340-c449-4956-a5f9-a52fb32f933d} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* ***** BEGIN LICENSE BLOCK ***** | ||
* Version: MPL 1.1 | ||
* | ||
* The contents of this file are subject to the Mozilla Public License Version | ||
* 1.1 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* http://www.mozilla.org/MPL/ | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
* for the specific language governing rights and limitations under the | ||
* License. | ||
* | ||
* The Original Code is the Open in Browser extension. | ||
* | ||
* The Initial Developer of the Original Code is | ||
* Sylvain Pasche <sylvain.pasche@gmail.com>. | ||
* Portions created by the Initial Developer are Copyright (C) 2009 | ||
* the Initial Developer. All Rights Reserved. | ||
* | ||
* Contributor(s): | ||
* | ||
* ***** END LICENSE BLOCK ***** */ | ||
|
||
var OIB_BrowserOverlay = { | ||
|
||
populateMimeTypesMenu: function OIBBO_popuplateViewAsMenu(event) { | ||
var popup = event.target; | ||
|
||
var uri = Application.activeWindow.activeTab.uri; | ||
OpenInBrowser.populateMenu(document.getElementById("mimeTypesPopup"), uri); | ||
}, | ||
|
||
onSetMimeCommand: function OIBBO_onSetMimeCommand(event) { | ||
var mime = event.target.mime; | ||
if (!mime) | ||
return; | ||
|
||
if (mime == OpenInBrowser.OTHER_MIME) { | ||
mime = prompt(OpenInBrowser.strings.getString("SelectMimeType")); | ||
|
||
if (!OpenInBrowser.validateMime(mime)) | ||
return; | ||
} | ||
|
||
OpenInBrowser.reloadWithMime(Application.activeWindow.activeTab.uri, mime) | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0"?> | ||
<!-- ***** BEGIN LICENSE BLOCK ***** | ||
- Version: MPL 1.1 | ||
- | ||
- The contents of this file are subject to the Mozilla Public License Version | ||
- 1.1 (the "License"); you may not use this file except in compliance with | ||
- the License. You may obtain a copy of the License at | ||
- http://www.mozilla.org/MPL/ | ||
- | ||
- Software distributed under the License is distributed on an "AS IS" basis, | ||
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
- for the specific language governing rights and limitations under the | ||
- License. | ||
- | ||
- The Original Code is the Open in Browser extension. | ||
- | ||
- The Initial Developer of the Original Code is | ||
- Sylvain Pasche <sylvain.pasche@gmail.com>. | ||
- Portions created by the Initial Developer are Copyright (C) 2009 | ||
- the Initial Developer. All Rights Reserved. | ||
- | ||
- Contributor(s): | ||
- | ||
- ***** END LICENSE BLOCK ***** --> | ||
|
||
<!DOCTYPE window [ | ||
<!ENTITY % openInBrowserDTD SYSTEM "chrome://openinbrowser/locale/openInBrowser.dtd"> | ||
%openInBrowserDTD; | ||
]> | ||
|
||
<overlay id="openInBrowserBrowserOverlay" | ||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> | ||
|
||
<script type="application/x-javascript" | ||
src="chrome://openinbrowser/content/openInBrowser.js"/> | ||
<script type="application/x-javascript" | ||
src="chrome://openinbrowser/content/browserOverlay.js"/> | ||
|
||
<stringbundleset id="stringbundleset"> | ||
<stringbundle id="strings_openInBrowser" src="chrome://openInBrowser/locale/openInBrowser.properties"/> | ||
</stringbundleset> | ||
|
||
<commandset id="mainCommandSet"> | ||
<command id="cmd_mimeTypeChange" oncommand="OIB_BrowserOverlay.onSetMimeCommand(event)"/> | ||
</commandset> | ||
|
||
<menupopup id="menu_viewPopup"> | ||
<menu id="viewAsMenu" insertafter="charsetMenu"/> | ||
</menupopup> | ||
|
||
<menupopup id="menu_View_Popup"> | ||
<menu id="viewAsMenu" insertafter="charsetMenu"/> | ||
</menupopup> | ||
|
||
<menu id="viewAsMenu" label="&viewAs.label;" accesskey="&viewAs.accesskey;"> | ||
<menupopup command="cmd_mimeTypeChange" id="mimeTypesPopup" | ||
onpopupshowing="OIB_BrowserOverlay.populateMimeTypesMenu(event)"/> | ||
</menu> | ||
|
||
</overlay> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* ***** BEGIN LICENSE BLOCK ***** | ||
* Version: MPL 1.1 | ||
* | ||
* The contents of this file are subject to the Mozilla Public License Version | ||
* 1.1 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* http://www.mozilla.org/MPL/ | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
* for the specific language governing rights and limitations under the | ||
* License. | ||
* | ||
* The Original Code is the Open in Browser extension. | ||
* | ||
* The Initial Developer of the Original Code is | ||
* Sylvain Pasche <sylvain.pasche@gmail.com>. | ||
* Portions created by the Initial Developer are Copyright (C) 2009 | ||
* the Initial Developer. All Rights Reserved. | ||
* | ||
* Contributor(s): | ||
* | ||
* ***** END LICENSE BLOCK ***** */ | ||
|
||
var Ci = Components.interfaces; | ||
var Cc = Components.classes; | ||
|
||
var OpenInBrowser = { | ||
SEPARATOR_ID: "oib_separator", | ||
OTHER_MIME: "other", | ||
|
||
MIMES_HTTP: [ | ||
"text/plain", | ||
"text/html", | ||
"view-source", | ||
"text/xml", | ||
// Note: | ||
// For image mime types, it relies on the fact that Gecko will correctly | ||
// display an image even if the server sent it with a mime type that does not | ||
// match the real image type. For instance, a PNG image sent with | ||
// image/jpeg Content-Type will still be displayed properly. | ||
"image/jpeg", | ||
"oib_separator", | ||
"other", | ||
], | ||
|
||
MIMES_NON_HTTP: [ | ||
"view-source" | ||
], | ||
|
||
ADDITIONAL_MIMES_PREF: "extensions.openinbrowser.additional_mimes", | ||
|
||
get _netutil() { | ||
delete this._netutil; | ||
return this._netutil = Cc["@mozilla.org/network/util;1"]. | ||
getService(Ci.nsINetUtil); | ||
}, | ||
|
||
get strings() { | ||
delete this.strings; | ||
return this.strings = document.getElementById("strings_openInBrowser"); | ||
}, | ||
|
||
populateMenu: function OIB_populateMenu(popup, uri) { | ||
var mimes; | ||
|
||
if (/^http/.test(uri.scheme)) { | ||
mimes = this.MIMES_HTTP; | ||
|
||
var additionalMimes = Application.prefs.getValue(this.ADDITIONAL_MIMES_PREF, null); | ||
if (additionalMimes) { | ||
mimes = mimes.slice(); | ||
for each (let m in additionalMimes.split("|")) { | ||
if (m) | ||
mimes.push(m); | ||
} | ||
} | ||
} else { | ||
mimes = this.MIMES_NON_HTTP; | ||
} | ||
|
||
while (popup.firstChild) | ||
popup.removeChild(popup.firstChild); | ||
|
||
for each (let mime in mimes) { | ||
var item; | ||
if (mime == this.SEPARATOR_ID) { | ||
item = document.createElement("menuseparator"); | ||
item.id = this.SEPARATOR_ID; | ||
popup.appendChild(item); | ||
continue; | ||
} | ||
item = document.createElement("menuitem"); | ||
item.mime = mime; | ||
// Id attribute is used for finding items with getElementById(). | ||
item.id = "mimeid_" + mime; | ||
|
||
var label = mime; | ||
|
||
// Use .stringBundle.GetStringFromName() instead of .getString() | ||
// to prevent dumping an exception if not found. | ||
try { | ||
label = this.strings.stringBundle.GetStringFromName(mime + ".label"); | ||
} catch(e) { } | ||
// Must use setAttribute, setting the label property doesn't work when | ||
// done on elements before they are added to the DOM. | ||
item.setAttribute("label", label); | ||
|
||
try { | ||
var accesskey = this.strings.stringBundle | ||
.GetStringFromName(mime + ".accesskey"); | ||
item.setAttribute("accesskey", accesskey); | ||
} catch(e) { } | ||
|
||
popup.appendChild(item); | ||
} | ||
}, | ||
|
||
validateMime: function OIB_validateMime(mime) { | ||
var type = this._netutil.parseContentType(mime, {}, {}); | ||
|
||
if (!type) { | ||
alert(this.strings.getFormattedString("InvalidMimeType", [mime])); | ||
return false; | ||
} | ||
return true; | ||
}, | ||
|
||
reloadWithMime: function OIB_reloadWithMime(uri, mime, doc) { | ||
if (mime == "view-source") { | ||
var iosvc = Cc["@mozilla.org/network/io-service;1"]. | ||
getService(Ci.nsIIOService); | ||
uri = iosvc.newURI("view-source:" + uri.spec, null, null); | ||
} else { | ||
var interceptor = Cc["@spasche.net/openinbrowser;1"]. | ||
getService().wrappedJSObject; | ||
interceptor.addInterceptInfo(uri.spec, mime); | ||
} | ||
var tab = Application.activeWindow.activeTab; | ||
if (doc) { | ||
var matchingTabs = []; | ||
Application.windows.forEach(function(window) { | ||
window.tabs.forEach(function(tab) { | ||
if (tab.document == doc) | ||
matchingTabs.push(tab); | ||
}) | ||
}) | ||
if (matchingTabs.length == 1) { | ||
tab = matchingTabs[0]; | ||
} | ||
} | ||
tab.load(uri); | ||
} | ||
} |
Oops, something went wrong.