1 # -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
15 # The Original Code is the Feed Writer.
17 # The Initial Developer of the Original Code is Google Inc.
18 # Portions created by the Initial Developer are Copyright (C) 2006
19 # the Initial Developer. All Rights Reserved.
22 # Ben Goodger <beng@google.com>
23 # Jeff Walden <jwalden+code@mit.edu>
24 # Asaf Romano <mano@mozilla.com>
25 # Robert Sayre <sayrer@gmail.com>
26 # Michael Ventnor <m.ventnor@gmail.com>
27 # Will Guaraldi <will.guaraldi@pculture.org>
29 # Alternatively, the contents of this file may be used under the terms of
30 # either the GNU General Public License Version 2 or later (the "GPL"), or
31 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32 # in which case the provisions of the GPL or the LGPL are applicable instead
33 # of those above. If you wish to allow use of your version of this file only
34 # under the terms of either the GPL or the LGPL, and not to allow others to
35 # use your version of this file under the terms of the MPL, indicate your
36 # decision by deleting the provisions above and replace them with the notice
37 # and other provisions required by the GPL or the LGPL. If you do not delete
38 # the provisions above, a recipient may use your version of this file under
39 # the terms of any one of the MPL, the GPL or the LGPL.
41 # ***** END LICENSE BLOCK ***** */
43 const Cc = Components.classes;
44 const Ci = Components.interfaces;
45 const Cr = Components.results;
46 const Cu = Components.utils;
48 Cu.import(
"resource://gre/modules/XPCOMUtils.jsm");
51 var prefB =
Cc[
"@mozilla.org/preferences-service;1"].
54 var shouldLog =
false;
56 shouldLog = prefB.getBoolPref(
"feeds.log");
62 dump(
"*** Feeds: " +
str +
"\n");
72 var
ios =
Cc[
"@mozilla.org/network/io-service;1"].
75 return ios.newURI(aURLSpec, aCharset,
null);
81 const XML_NS =
"http://www.w3.org/XML/1998/namespace"
82 const HTML_NS =
"http://www.w3.org/1999/xhtml";
83 const XUL_NS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
87 const URI_BUNDLE =
"chrome://browser/locale/feeds/subscribe.properties";
112 case Ci.nsIFeed.TYPE_VIDEO:
115 case Ci.nsIFeed.TYPE_AUDIO:
125 case Ci.nsIFeed.TYPE_VIDEO:
128 case Ci.nsIFeed.TYPE_AUDIO:
138 case Ci.nsIFeed.TYPE_VIDEO:
141 case Ci.nsIFeed.TYPE_AUDIO:
151 case Ci.nsIFeed.TYPE_VIDEO:
154 case Ci.nsIFeed.TYPE_AUDIO:
169 var units = [
"bytes",
"kilobyte",
"megabyte",
"gigabyte"];
174 while ((aBytes >= 999.5) && (unitIndex < units.length - 1)) {
181 aBytes = aBytes.toFixed((aBytes > 0) && (aBytes < 100) ? 1 : 0);
183 return [aBytes, units[unitIndex]];
188 _mimeSvc :
Cc[
"@mozilla.org/mime;1"].
191 _getPropertyAsBag:
function FW__getPropertyAsBag(container, property) {
192 return container.fields.getProperty(property).
196 _getPropertyAsString:
function FW__getPropertyAsString(container, property) {
198 return container.fields.getPropertyAsAString(property);
205 _setContentText:
function FW__setContentText(
id, text) {
206 this._contentSandbox.element = this.
_document.getElementById(
id);
207 this._contentSandbox.textNode = this.
_document.createTextNode(text);
209 "while (element.hasChildNodes()) " +
210 " element.removeChild(element.firstChild);" +
211 "element.appendChild(textNode);";
212 Cu.evalInSandbox(codeStr, this._contentSandbox);
213 this._contentSandbox.element =
null;
214 this._contentSandbox.textNode =
null;
227 _safeSetURIAttribute:
228 function FW__safeSetURIAttribute(
element, attribute,
uri) {
229 var
secman =
Cc[
"@mozilla.org/scriptsecuritymanager;1"].
231 const flags =
Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL;
243 this._contentSandbox.element =
element;
244 this._contentSandbox.uri =
uri;
245 var
codeStr =
"element.setAttribute('" + attribute +
"', uri);";
246 Cu.evalInSandbox(codeStr, this._contentSandbox);
254 get _contentSandbox() {
268 _safeDoCommand:
function FW___safeDoCommand(aElement) {
269 this._contentSandbox.element = aElement;
270 Cu.evalInSandbox(
"element.doCommand();", this._contentSandbox);
271 this._contentSandbox.element =
null;
275 get _faviconService() {
286 this.
__bundle =
Cc[
"@mozilla.org/intl/stringbundle;1"].
293 _getFormattedString:
function FW__getFormattedString(
key, params) {
294 return this._bundle.formatStringFromName(
key, params, params.length);
297 _getString:
function FW__getString(
key) {
298 return this._bundle.GetStringFromName(
key);
302 _getSelectedItemFromMenulist:
function FW__getSelectedItemFromList(aList) {
303 var
node = aList.firstChild.firstChild;
305 if (node.localName ==
"menuitem" && node.getAttribute(
"selected") ==
"true")
308 node = node.nextSibling;
314 _setCheckboxCheckedState:
function FW__setCheckboxCheckedState(aCheckbox,
aValue) {
316 this._contentSandbox.checkbox = aCheckbox;
318 var change = (
aValue != (aCheckbox.getAttribute(
'checked') ==
'true'));
320 codeStr =
"checkbox.setAttribute('checked', 'true'); ";
322 codeStr =
"checkbox.removeAttribute('checked'); ";
325 this._contentSandbox.document = this.
_document;
326 codeStr +=
"var event = document.createEvent('Events'); " +
327 "event.initEvent('CheckboxStateChange', true, true);" +
328 "checkbox.dispatchEvent(event);"
331 Cu.evalInSandbox(codeStr, this._contentSandbox);
340 _parseDate:
function FW__parseDate(dateString) {
342 dateObj =
new Date(dateString);
345 if (!dateObj.getTime())
348 var dateService =
Cc[
"@mozilla.org/intl/scriptabledateformat;1"].
350 return dateService.FormatDateTime(
"", dateService.dateFormatLong, dateService.timeFormatNoSeconds,
351 dateObj.getFullYear(), dateObj.getMonth()+1, dateObj.getDate(),
352 dateObj.getHours(), dateObj.getMinutes(), dateObj.getSeconds());
359 _getFeedType:
function FW__getFeedType() {
360 if (this.__feedType !=
null)
361 return this.__feedType;
365 var container = this._getContainer();
366 var feed = container.QueryInterface(
Ci.nsIFeed);
367 this.__feedType = feed.type;
371 return Ci.nsIFeed.TYPE_FEED;
377 _getMimeTypeForFeedType:
function FW__getMimeTypeForFeedType() {
378 switch (this._getFeedType()) {
379 case Ci.nsIFeed.TYPE_VIDEO:
382 case Ci.nsIFeed.TYPE_AUDIO:
396 if (container.title) {
397 var title = container.title.plainText();
398 this._setContentText(
TITLE_ID, title);
399 this._contentSandbox.document = this.
_document;
400 this._contentSandbox.title = title;
401 var
codeStr =
"document.title = title;"
402 Cu.evalInSandbox(codeStr, this._contentSandbox);
405 var feed = container.QueryInterface(
Ci.nsIFeed);
406 if (feed && feed.subtitle)
407 this._setContentText(
SUBTITLE_ID, container.subtitle.plainText());
417 var parts = container.image;
420 var feedTitleImage = this.
_document.getElementById(
"feedTitleImage");
421 this._safeSetURIAttribute(feedTitleImage,
"src",
422 parts.getPropertyAsAString(
"url"));
425 var feedTitleLink = this.
_document.getElementById(
"feedTitleLink");
427 var titleText = this._getFormattedString(
"linkTitleTextFormat",
428 [parts.getPropertyAsAString(
"title")]);
429 this._contentSandbox.feedTitleLink = feedTitleLink;
430 this._contentSandbox.titleText = titleText;
431 this._contentSandbox.feedTitleText = this.
_document.getElementById(
"feedTitleText");
432 this._contentSandbox.titleImageWidth = parseInt(parts.getPropertyAsAString(
"width")) + 15;
436 var
codeStr =
"feedTitleLink.setAttribute('title', titleText); " +
437 "feedTitleText.style.marginRight = titleImageWidth + 'px';";
438 Cu.evalInSandbox(codeStr, this._contentSandbox);
439 this._contentSandbox.feedTitleLink =
null;
440 this._contentSandbox.titleText =
null;
441 this._contentSandbox.feedTitleText =
null;
442 this._contentSandbox.titleImageWidth =
null;
444 this._safeSetURIAttribute(feedTitleLink,
"href",
445 parts.getPropertyAsAString(
"link"));
448 LOG(
"Failed to set Title Image (this is benign): " + e);
459 var feed = container.QueryInterface(
Ci.nsIFeed);
460 if (feed.items.length == 0)
463 this._contentSandbox.feedContent =
464 this.
_document.getElementById(
"feedContent");
466 for (var
i = 0;
i < feed.items.length; ++
i) {
467 var
entry = feed.items.queryElementAt(
i,
Ci.nsIFeedEntry);
468 entry.QueryInterface(
Ci.nsIFeedContainer);
470 var entryContainer = this.
_document.createElementNS(HTML_NS,
"div");
471 entryContainer.className =
"entry";
475 var a = this.
_document.createElementNS(HTML_NS,
"a");
476 a.appendChild(this.
_document.createTextNode(entry.title.plainText()));
480 this._safeSetURIAttribute(a,
"href", entry.link.spec);
482 var title = this.
_document.createElementNS(HTML_NS,
"h3");
483 title.appendChild(a);
485 var lastUpdated = this._parseDate(entry.updated);
487 var dateDiv = this.
_document.createElementNS(HTML_NS,
"div");
488 dateDiv.className =
"lastUpdated";
489 dateDiv.textContent = lastUpdated;
490 title.appendChild(dateDiv);
493 entryContainer.appendChild(title);
496 var body = this.
_document.createElementNS(HTML_NS,
"div");
497 var summary = entry.summary || entry.content;
498 var docFragment =
null;
501 body.setAttributeNS(
XML_NS,
"base", summary.base.spec);
504 docFragment = summary.createDocumentFragment(body);
506 body.appendChild(docFragment);
510 if (!entry.title && entry.link) {
511 var a = this.
_document.createElementNS(HTML_NS,
"a");
512 a.appendChild(this.
_document.createTextNode(
"#"));
513 this._safeSetURIAttribute(a,
"href", entry.link.spec);
514 body.appendChild(this.
_document.createTextNode(
" "));
519 body.className =
"feedEntryContent";
520 entryContainer.appendChild(body);
522 if (entry.enclosures && entry.enclosures.length > 0) {
523 var enclosuresDiv = this._buildEnclosureDiv(entry);
524 entryContainer.appendChild(enclosuresDiv);
527 this._contentSandbox.entryContainer = entryContainer;
528 this._contentSandbox.clearDiv =
529 this.
_document.createElementNS(HTML_NS,
"div");
530 this._contentSandbox.clearDiv.style.clear =
"both";
532 var
codeStr =
"feedContent.appendChild(entryContainer); " +
533 "feedContent.appendChild(clearDiv);"
534 Cu.evalInSandbox(codeStr, this._contentSandbox);
537 this._contentSandbox.feedContent =
null;
538 this._contentSandbox.entryContainer =
null;
539 this._contentSandbox.clearDiv =
null;
553 _getURLDisplayName:
function FW__getURLDisplayName(aURL) {
555 url.QueryInterface(
Ci.nsIURL);
556 if (url ==
null || url.fileName.length == 0)
559 return decodeURI(url.fileName);
569 _buildEnclosureDiv:
function FW__buildEnclosureDiv(
entry) {
570 var enclosuresDiv = this.
_document.createElementNS(HTML_NS,
"div");
571 enclosuresDiv.className =
"enclosures";
573 enclosuresDiv.appendChild(this.
_document.createTextNode(
this._getString(
"mediaLabel")));
575 var roundme =
function(n) {
576 return (Math.round(n * 100) / 100).toLocaleString();
579 for (var i_enc = 0; i_enc <
entry.enclosures.length; ++i_enc) {
580 var enc =
entry.enclosures.queryElementAt(i_enc,
Ci.nsIWritablePropertyBag2);
582 if (!(enc.hasKey(
"url")))
585 var enclosureDiv = this.
_document.createElementNS(HTML_NS,
"div");
586 enclosureDiv.setAttribute(
"class",
"enclosure");
588 var mozicon =
"moz-icon://.txt?size=16";
589 var type_text =
null;
590 var size_text =
null;
592 if (enc.hasKey(
"type")) {
593 type_text = enc.get(
"type");
595 var handlerInfoWrapper = this._mimeSvc.getFromTypeAndExtension(enc.get(
"type"),
null);
597 if (handlerInfoWrapper)
598 type_text = handlerInfoWrapper.description;
600 if (type_text && type_text.length > 0)
601 mozicon =
"moz-icon://goat?size=16&contentType=" + enc.get(
"type");
607 if (enc.hasKey(
"length") && /^[0-9]+$/.test(enc.get(
"length"))) {
610 var size_text = this._getFormattedString(
"enclosureSizeText",
611 [enc_size[0], this._getString(enc_size[1])]);
614 var iconimg = this.
_document.createElementNS(HTML_NS,
"img");
615 iconimg.setAttribute(
"src", mozicon);
616 iconimg.setAttribute(
"class",
"type-icon");
617 enclosureDiv.appendChild(iconimg);
619 enclosureDiv.appendChild(this.
_document.createTextNode(
" " ));
621 var enc_href = this.
_document.createElementNS(HTML_NS,
"a");
622 enc_href.appendChild(this.
_document.createTextNode(
this._getURLDisplayName(enc.get(
"url"))));
623 this._safeSetURIAttribute(enc_href,
"href", enc.get(
"url"));
624 enclosureDiv.appendChild(enc_href);
626 if (type_text && size_text)
627 enclosureDiv.appendChild(this.
_document.createTextNode(
" (" + type_text +
", " + size_text +
")"));
630 enclosureDiv.appendChild(this.
_document.createTextNode(
" (" + type_text +
")"))
633 enclosureDiv.appendChild(this.
_document.createTextNode(
" (" + size_text +
")"))
635 enclosuresDiv.appendChild(enclosureDiv);
638 return enclosuresDiv;
649 _getContainer:
function FW__getContainer(result) {
651 Cc[
"@mozilla.org/browser/feeds/result-service;1"].
656 feedService.getFeedResult(this._getOriginalURI(this.
_window));
659 LOG(
"Subscribe Preview: feed not available?!");
663 LOG(
"Subscribe Preview: feed result is bozo?!");
667 var container = result.doc;
670 LOG(
"Subscribe Preview: no result.doc? Why didn't the original reload?");
683 _getFileDisplayName:
function FW__getFileDisplayName(
file) {
685 if (
file instanceof
Ci.nsILocalFileWin) {
687 return file.getVersionInfoField(
"FileDescription");
694 var lfm =
file.QueryInterface(
Ci.nsILocalFileMac);
696 return lfm.bundleDisplayName;
703 Cc[
"@mozilla.org/network/io-service;1"].
705 var
url = ios.newFileURI(
file).QueryInterface(
Ci.nsIURL);
715 _getFileIconURL:
function FW__getFileIconURL(
file) {
716 var
ios =
Cc[
"@mozilla.org/network/io-service;1"].
717 getService(Components.interfaces.nsIIOService);
718 var fph = ios.getProtocolHandler(
"file")
719 .QueryInterface(
Ci.nsIFileProtocolHandler);
720 var urlSpec = fph.getURLSpecFromFile(
file);
721 return "moz-icon://" + urlSpec +
"?size=16";
733 this._contentSandbox.menuitem =
aMenuItem;
734 this._contentSandbox.label = this._getFileDisplayName(aFile);
735 this._contentSandbox.image = this._getFileIconURL(aFile);
736 var
codeStr =
"menuitem.setAttribute('label', label); " +
737 "menuitem.setAttribute('image', image);"
738 Cu.evalInSandbox(codeStr, this._contentSandbox);
745 _chooseClientApp:
function FW__chooseClientApp() {
747 var fp =
Cc[
"@mozilla.org/filepicker;1"].createInstance(
Ci.nsIFilePicker);
749 this._getString(
"chooseApplicationDialogTitle"),
750 Ci.nsIFilePicker.modeOpen);
751 fp.appendFilters(
Ci.nsIFilePicker.filterApps);
753 if (fp.show() ==
Ci.nsIFilePicker.returnOK) {
760 #expand if (fp.file.leafName != "__MOZ_APP_NAME__.exe") {
763 #expand if (fp.file.leafName != "__MOZ_APP_DISPLAYNAME__.app") {
765 #expand if (fp.file.leafName != "__MOZ_APP_NAME__-bin") {
772 var
codeStr =
"selectedAppMenuItem.hidden = false;" +
773 "selectedAppMenuItem.doCommand();"
774 Cu.evalInSandbox(codeStr, this._contentSandbox);
786 var checkbox = this.
_document.getElementById(
"alwaysUse");
788 var alwaysUse =
false;
790 var
prefs =
Cc[
"@mozilla.org/preferences-service;1"].
796 this._setCheckboxCheckedState(checkbox, alwaysUse);
801 var stringLabel =
"subscribeFeedUsing";
802 switch (this._getFeedType()) {
803 case Ci.nsIFeed.TYPE_VIDEO:
804 stringLabel =
"subscribeVideoPodcastUsing";
807 case Ci.nsIFeed.TYPE_AUDIO:
808 stringLabel =
"subscribeAudioPodcastUsing";
812 this._contentSandbox.subscribeUsing =
813 this.
_document.getElementById(
"subscribeUsingDescription");
814 this._contentSandbox.label = this._getString(stringLabel);
815 var
codeStr =
"subscribeUsing.setAttribute('value', label);"
816 Cu.evalInSandbox(codeStr, this._contentSandbox);
820 var checkbox = this.
_document.getElementById(
"alwaysUse");
823 if (handlersMenuList) {
824 var handlerName = this._getSelectedItemFromMenulist(handlersMenuList)
825 .getAttribute(
"label");
826 var stringLabel =
"alwaysUseForFeeds";
827 switch (this._getFeedType()) {
828 case Ci.nsIFeed.TYPE_VIDEO:
829 stringLabel =
"alwaysUseForVideoPodcasts";
832 case Ci.nsIFeed.TYPE_AUDIO:
833 stringLabel =
"alwaysUseForAudioPodcasts";
837 this._contentSandbox.checkbox = checkbox;
838 this._contentSandbox.label = this._getFormattedString(stringLabel, [handlerName]);
840 var codeStr =
"checkbox.setAttribute('label', label);";
841 Cu.evalInSandbox(codeStr, this._contentSandbox);
847 handleEvent:
function(
event) {
848 if (
event.target.ownerDocument !=
this._document) {
849 LOG(
"FeedWriter.handleEvent: Someone passed the feed writer as a listener to the events of another document!");
854 switch (
event.target.id) {
855 case "subscribeButton":
858 case "chooseApplicationMenuItem":
867 var popupbox = this.
_document.getElementById(
"handlersMenuList")
868 .firstChild.boxObject;
869 popupbox.QueryInterface(Components.interfaces.nsIPopupBoxObject);
870 if (popupbox.popupState ==
"hiding" && !
this._chooseClientApp()) {
884 Cc[
"@mozilla.org/preferences-service;1"].
896 if (handlersMenuList) {
899 handlersMenuList.getElementsByAttribute(
"webhandlerurl", url);
900 if (handlers.length == 0) {
901 LOG(
"FeedWriter._setSelectedHandler: selected web handler isn't in the menulist")
905 this._safeDoCommand(handlers[0]);
921 var codeStr =
"selectedAppMenuItem.hidden = false; " +
922 "selectedAppMenuItem.doCommand(); ";
926 if (this._defaultSystemReader) {
928 this._defaultSystemReader.path == this.
_selectedApp.path;
929 codeStr +=
"defaultHandlerMenuItem.hidden = " + shouldHide +
";"
931 Cu.evalInSandbox(codeStr, this._contentSandbox);
937 var liveBookmarksMenuItem = this.
_document.getElementById(
"liveBookmarksMenuItem");
938 if (liveBookmarksMenuItem)
939 this._safeDoCommand(liveBookmarksMenuItem);
946 if (!handlersMenuPopup)
954 this._contentSandbox.header =
header;
956 case Ci.nsIFeed.TYPE_VIDEO:
957 codeStr =
"header.className = 'videoPodcastBackground'; ";
960 case Ci.nsIFeed.TYPE_AUDIO:
961 codeStr =
"header.className = 'audioPodcastBackground'; ";
965 codeStr =
"header.className = 'feedBackground'; ";
971 menuItem.id =
"selectedAppMenuItem";
972 menuItem.className =
"menuitem-iconic";
973 menuItem.setAttribute(
"handlerType",
"client");
975 var prefs =
Cc[
"@mozilla.org/preferences-service;1"].
984 menuItem.setAttribute(
"hidden",
true);
989 menuItem.setAttribute(
"hidden",
true);
992 this._contentSandbox.selectedAppMenuItem =
menuItem;
994 codeStr +=
"handlersMenuPopup.appendChild(selectedAppMenuItem); ";
998 this._defaultSystemReader =
Cc[
"@mozilla.org/browser/shell-service;1"].
1002 menuItem.id =
"defaultHandlerMenuItem";
1003 menuItem.className =
"menuitem-iconic";
1004 menuItem.setAttribute(
"handlerType",
"client");
1011 this.
_selectedApp.path ==
this._defaultSystemReader.path)
1012 menuItem.hidden =
true;
1014 catch(ex) { menuItem =
null; }
1017 this._contentSandbox.defaultHandlerMenuItem =
menuItem;
1018 codeStr +=
"handlersMenuPopup.appendChild(defaultHandlerMenuItem); ";
1023 menuItem.id =
"chooseApplicationMenuItem";
1024 menuItem.className =
"menuitem-iconic";
1025 menuItem.setAttribute(
"label", this._getString(
"chooseApplicationMenuItem"));
1028 codeStr +=
"handlersMenuPopup.appendChild(chooseAppMenuItem); ";
1031 this._contentSandbox.chooseAppSep =
1033 codeStr +=
"handlersMenuPopup.appendChild(chooseAppSep); ";
1035 Cu.evalInSandbox(codeStr, this._contentSandbox);
1039 historySvc.addObserver(
this,
false);
1042 var
wccr =
Cc[
"@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"].
1044 var
handlers = wccr.getContentHandlers(this._getMimeTypeForFeedType(feedType), {});
1045 if (handlers.length != 0) {
1046 for (var
i = 0;
i < handlers.length; ++
i) {
1048 menuItem.className =
"menuitem-iconic";
1049 menuItem.setAttribute(
"label", handlers[
i].
name);
1050 menuItem.setAttribute(
"handlerType",
"web");
1051 menuItem.setAttribute(
"webhandlerurl", handlers[
i].
uri);
1052 this._contentSandbox.menuItem =
menuItem;
1053 codeStr =
"handlersMenuPopup.appendChild(menuItem);";
1054 Cu.evalInSandbox(codeStr, this._contentSandbox);
1058 var uri =
makeURI(handlers[
i].uri);
1059 if (!this._setFaviconForWebReader(uri, menuItem)) {
1060 if (uri && /^https?/.
test(uri.scheme)) {
1061 var iconURL =
makeURI(uri.prePath +
"/favicon.ico");
1062 this._faviconService.setAndLoadFaviconForPage(uri, iconURL,
true);
1066 this._contentSandbox.menuItem =
null;
1080 handlersMenuPopup.addEventListener(
"command",
this,
false);
1084 .getElementById(
"subscribeButton")
1085 .addEventListener(
"command",
this,
false);
1093 if (showFirstRunUI) {
1094 var textfeedinfo1, textfeedinfo2;
1096 case Ci.nsIFeed.TYPE_VIDEO:
1097 textfeedinfo1 =
"feedSubscriptionVideoPodcast1";
1098 textfeedinfo2 =
"feedSubscriptionVideoPodcast2";
1100 case Ci.nsIFeed.TYPE_AUDIO:
1101 textfeedinfo1 =
"feedSubscriptionAudioPodcast1";
1102 textfeedinfo2 =
"feedSubscriptionAudioPodcast2";
1105 textfeedinfo1 =
"feedSubscriptionFeed1";
1106 textfeedinfo2 =
"feedSubscriptionFeed2";
1109 this._contentSandbox.feedinfo1 =
1110 this.
_document.getElementById(
"feedSubscriptionInfo1");
1111 this._contentSandbox.feedinfo1Str = this._getString(textfeedinfo1);
1112 this._contentSandbox.feedinfo2 =
1113 this.
_document.getElementById(
"feedSubscriptionInfo2");
1114 this._contentSandbox.feedinfo2Str = this._getString(textfeedinfo2);
1115 this._contentSandbox.header =
header;
1116 codeStr =
"feedinfo1.textContent = feedinfo1Str; " +
1117 "feedinfo2.textContent = feedinfo2Str; " +
1118 "header.setAttribute('firstrun', 'true');"
1119 Cu.evalInSandbox(codeStr, this._contentSandbox);
1130 _getOriginalURI:
function FW__getOriginalURI(aWindow) {
1131 var chan = aWindow.QueryInterface(
Ci.nsIInterfaceRequestor).
1132 getInterface(
Ci.nsIWebNavigation).
1138 convertChromeURL(uri);
1140 if (resolvedURI.equals(chan.URI))
1141 return chan.originalURI;
1152 init:
function FW_init(aWindow) {
1154 this.
_feedURI = this._getOriginalURI(window);
1161 var
secman =
Cc[
"@mozilla.org/scriptsecuritymanager;1"].
1165 LOG(
"Subscribe Preview: feed uri = " + this.
_window.location.href);
1169 var prefs =
Cc[
"@mozilla.org/preferences-service;1"].
1186 writeContent:
function FW_writeContent() {
1192 var container = this._getContainer();
1205 close:
function FW_close() {
1207 .getElementById(
"handlersMenuPopup")
1208 .removeEventListener(
"command",
this,
false);
1210 .getElementById(
"subscribeButton")
1211 .removeEventListener(
"command",
this,
false);
1214 var prefs =
Cc[
"@mozilla.org/preferences-service;1"].
1236 var historySvc =
Cc[
"@mozilla.org/browser/nav-history-service;1"].
1238 historySvc.removeObserver(
this);
1243 var feedService =
Cc[
"@mozilla.org/browser/feeds/result-service;1"].
1245 feedService.removeFeedResult(this.
_feedURI);
1250 subscribe:
function FW_subscribe() {
1251 var feedType = this._getFeedType();
1254 var prefs =
Cc[
"@mozilla.org/preferences-service;1"].
1258 .getAttribute(
"checked");
1265 if (selectedItem.id ==
"chooseApplicationMenuItem") {
1266 if (!this._chooseClientApp())
1269 selectedItem = this._getSelectedItemFromMenulist(handlersMenuList);
1272 if (selectedItem.hasAttribute(
"webhandlerurl")) {
1273 var webURI = selectedItem.getAttribute(
"webhandlerurl");
1276 var supportsString =
Cc[
"@mozilla.org/supports-string;1"].
1278 supportsString.data = webURI;
1282 var wccr =
Cc[
"@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"].
1284 var handler = wccr.getWebContentHandlerByURI(this._getMimeTypeForFeedType(feedType), webURI);
1287 wccr.setAutoHandler(this._getMimeTypeForFeedType(feedType), handler);
1289 this.
_window.location.href = handler.getHandlerURI(this.
_window.location.href);
1293 switch (selectedItem.id) {
1294 case "selectedAppMenuItem":
1299 case "defaultHandlerMenuItem":
1301 this._defaultSystemReader);
1304 case "liveBookmarksMenuItem":
1305 defaultHandler =
"bookmarks";
1309 var feedService =
Cc[
"@mozilla.org/browser/feeds/result-service;1"].
1315 feedService.addToClientReader(this.
_window.location.href, feedTitle, feedSubtitle, feedType);
1336 var feedType = this._getFeedType();
1338 if (
topic ==
"nsPref:changed") {
1368 _setFaviconForWebReader:
1370 var faviconsSvc = this._faviconService;
1373 faviconURI = faviconsSvc.getFaviconForPage(aURI);
1378 var dataURL = faviconsSvc.getFaviconDataAsDataURL(faviconURI);
1380 this._contentSandbox.menuItem =
aMenuItem;
1381 this._contentSandbox.dataURL = dataURL;
1382 var codeStr =
"menuItem.setAttribute('image', dataURL);";
1383 Cu.evalInSandbox(codeStr, this._contentSandbox);
1384 this._contentSandbox.menuItem =
null;
1385 this._contentSandbox.dataURL =
null;
1396 if (
aWhat ==
Ci.nsINavHistoryObserver.ATTRIBUTE_FAVICON) {
1399 var spec = aURI.spec;
1400 var handlersMenulist = this.
_document.getElementById(
"handlersMenuList");
1401 var possibleHandlers = handlersMenulist.firstChild.childNodes;
1402 for (var
i=0;
i < possibleHandlers.length ;
i++) {
1403 if (possibleHandlers[
i].
getAttribute(
"webhandlerurl") == spec) {
1404 this._setFaviconForWebReader(aURI, possibleHandlers[
i]);
1423 countRef.value = interfaces.length;
1429 classID: Components.ID("{49bb6593-3aff-4eb3-a068-2712c28bd58e}
"),
1430 implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT,
1431 flags: Ci.nsIClassInfo.DOM_OBJECT,
1432 _xpcom_categories: [{ category: "JavaScript global
constructor",
1433 entry: "BrowserFeedWriter
"}],
1434 QueryInterface: XPCOMUtils.generateQI([Ci.nsIFeedWriter, Ci.nsIClassInfo,
1435 Ci.nsIDOMEventListener, Ci.nsIObserver,
1436 Ci.nsINavHistoryObserver])
1439 function NSGetModule(cm, file)
1440 XPCOMUtils.generateModule([FeedWriter]);
classDescription QueryInterface
this _writeFeedContent(container)
function convertByteUnits(aBytes)
getHelperForLanguage contractID
function getPrefWebForType(t)
const PREF_AUDIO_SELECTED_ACTION
onPageChanged onEndUpdateBatch
FeedWriter _setAlwaysUseCheckedState
const TYPE_MAYBE_VIDEO_FEED
const PREF_VIDEO_SELECTED_APP
function getPrefReaderForType(t)
onPageChanged onBeforeDeleteURI
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
const PREF_VIDEO_SELECTED_WEB
const PREF_AUDIO_SELECTED_READER
this _setSelectedHandler(feedType)
this _contentSandbox handlersMenuPopup
const PREF_AUDIO_SELECTED_APP
sbDeviceFirmwareAutoCheckForUpdate prototype getHelperForLanguage
const PREF_VIDEO_SELECTED_ACTION
getService(Ci.nsIPrefBranch)
this _setTitleText(container)
function makeURI(aURLSpec, aCharset)
this _setSubscribeUsingLabel()
onPageChanged onPageExpired
this _initSubscriptionUI()
DataRemote prototype constructor
this _setTitleImage(container)
this _setAlwaysUseLabel()
const PREF_SELECTED_READER
const PREF_SELECTED_ACTION
const PREF_SHOW_FIRST_RUN_UI
onPageChanged onBeginUpdateBatch
function getPrefAppForType(t)
onPageChanged onTitleChanged
onPageChanged getInterfaces
return aWindow document documentElement getAttribute(aAttribute)||dimension
this _removeFeedFromCache()
_setFaviconForWebReader aMenuItem
const PREF_AUDIO_SELECTED_WEB
onPageChanged onDeleteURI
function getPrefActionForType(t)
const PREF_VIDEO_SELECTED_READER
_getSelectedPageStyle s i
onPageChanged onClearHistory
this _initMenuItemWithFile(menuItem, this._defaultSystemReader)
const TYPE_MAYBE_AUDIO_FEED
sbDeviceFirmwareAutoCheckForUpdate prototype observe