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 Stream Converter.
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 # Will Guaraldi <will.guaraldi@pculture.org>
26 # Alternatively, the contents of this file may be used under the terms of
27 # either the GNU General Public License Version 2 or later (the "GPL"), or
28 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 # in which case the provisions of the GPL or the LGPL are applicable instead
30 # of those above. If you wish to allow use of your version of this file only
31 # under the terms of either the GPL or the LGPL, and not to allow others to
32 # use your version of this file under the terms of the MPL, indicate your
33 # decision by deleting the provisions above and replace them with the notice
34 # and other provisions required by the GPL or the LGPL. If you do not delete
35 # the provisions above, a recipient may use your version of this file under
36 # the terms of any one of the MPL, the GPL or the LGPL.
38 # ***** END LICENSE BLOCK ***** */
40 const Cc = Components.classes;
41 const Ci = Components.interfaces;
42 const Cr = Components.results;
45 dump(
"*** " +
str +
"\n");
48 const FC_CLASSID = Components.ID(
"{229fa115-9412-4d32-baf3-2fc407f76fb1}");
50 const FS_CLASSID = Components.ID(
"{2376201c-bbc6-472f-9b62-7548040a61c6}");
54 const FPH_CLASSID = Components.ID(
"{4f91ef2e-57ba-472e-ab7a-b4999e42d6c0}");
57 const PCPH_CLASSID = Components.ID(
"{1c31ed79-accd-4b94-b517-06e0c81999d5}");
84 case Ci.nsIFeed.TYPE_VIDEO:
87 case Ci.nsIFeed.TYPE_AUDIO:
97 case Ci.nsIFeed.TYPE_VIDEO:
100 case Ci.nsIFeed.TYPE_AUDIO:
110 case Ci.nsIFeed.TYPE_VIDEO:
113 case Ci.nsIFeed.TYPE_AUDIO:
123 case Ci.nsIFeed.TYPE_VIDEO:
126 case Ci.nsIFeed.TYPE_AUDIO:
136 Cc[
"@mozilla.org/preferences-service;1"].
139 return prefs.getCharPref(
pref);
168 convert:
function FC_convert(sourceStream, sourceType, destinationType,
170 throw Cr.NS_ERROR_NOT_IMPLEMENTED;
176 asyncConvertData:
function FC_asyncConvertData(sourceType, destinationType,
184 _forcePreviewPage:
false,
189 _releaseHandles:
function FC__releaseHandles() {
190 this._listener =
null;
191 this._request =
null;
192 this._processor =
null;
198 handleResult:
function FC_handleResult(result) {
231 Cc[
"@mozilla.org/browser/feeds/result-service;1"].
233 if (!this._forcePreviewPage && result.doc) {
234 var feed = result.doc.QueryInterface(
Ci.nsIFeed);
237 if (handler !=
"ask") {
238 if (handler ==
"reader")
243 Cc[
"@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"].
245 if ((feed.type ==
Ci.nsIFeed.TYPE_FEED &&
247 (feed.type ==
Ci.nsIFeed.TYPE_VIDEO &&
249 (feed.type ==
Ci.nsIFeed.TYPE_AUDIO &&
251 wccr.loadPreferredHandler(this._request);
257 LOG(
"unexpected handler: " + handler);
262 var title = feed.title ? feed.title.plainText() :
"";
263 var desc = feed.subtitle ? feed.subtitle.plainText() :
"";
264 feedService.addToClientReader(result.uri.spec, title, desc, feed.type);
272 Cc[
"@mozilla.org/network/io-service;1"].
283 feedService.addFeedResult(result);
287 chromeChannel = ios.newChannelFromURI(chromeURI,
null);
288 chromeChannel.originalURI = result.uri;
291 chromeChannel = ios.newChannelFromURI(result.uri,
null);
293 chromeChannel.loadGroup = this._request.loadGroup;
294 chromeChannel.asyncOpen(this._listener,
null);
297 this._releaseHandles();
304 onDataAvailable:
function FC_onDataAvailable(request, context, inputStream,
305 sourceOffset,
count) {
307 this._processor.onDataAvailable(request, context, inputStream,
308 sourceOffset,
count);
314 onStartRequest:
function FC_onStartRequest(request, context) {
315 var channel = request.QueryInterface(
Ci.nsIChannel);
320 var httpChannel = channel.QueryInterface(
Ci.nsIHttpChannel);
321 var noSniff = httpChannel.getResponseHeader(
"X-Moz-Is-Feed");
324 this._sniffed =
true;
327 this._request = request;
332 Cc[
"@mozilla.org/browser/feeds/result-service;1"].
334 this._forcePreviewPage = feedService.forcePreviewPage;
335 feedService.forcePreviewPage =
false;
339 Cc[
"@mozilla.org/feed-processor;1"].
341 this._processor.listener =
this;
342 this._processor.parseAsync(
null, channel.URI);
344 this._processor.onStartRequest(request, context);
350 onStopRequest:
function FC_onStopRequest(request, context, status) {
352 this._processor.onStopRequest(request, context, status);
359 if (iid.equals(
Ci.nsIFeedResultListener) ||
360 iid.equals(
Ci.nsIStreamConverter) ||
361 iid.equals(
Ci.nsIStreamListener) ||
362 iid.equals(
Ci.nsIRequestObserver)||
363 iid.equals(
Ci.nsISupports))
365 throw Cr.NS_ERROR_NO_INTERFACE;
372 throw Cr.NS_ERROR_NO_AGGREGATION;
377 if (iid.equals(
Ci.nsIFactory) ||
378 iid.equals(
Ci.nsISupports))
380 throw Cr.NS_ERROR_NO_INTERFACE;
399 forcePreviewPage:
false,
406 Cc[
"@mozilla.org/preferences-service;1"].
410 if (handler ==
"ask" || handler ==
"reader")
425 Cc[
"@mozilla.org/network/io-service;1"].
427 var feedURI = ios.newURI(spec,
null,
null);
428 if (feedURI.schemeIs(
"http")) {
429 feedURI.scheme =
"feed";
433 spec =
"feed:" + spec;
439 Cc[
"@mozilla.org/browser/shell-service;1"].
441 ss.openApplicationWithURI(clientApp, spec);
446 Cc[
"@mozilla.org/process/util;1"].
449 p.run(
false, [spec], 1);
455 LOG(
"unexpected handler: " + handler);
459 Cc[
"@mozilla.org/appshell/window-mediator;1"].
461 var topWindow = wm.getMostRecentWindow(
"navigator:browser");
462 topWindow.PlacesCommandHook.addLiveBookmark(spec, title, subtitle);
470 addFeedResult:
function FRS_addFeedResult(feedResult) {
473 var spec = feedResult.uri.spec;
474 if(!this._results[spec])
475 this._results[spec] = [];
476 this._results[spec].push(feedResult);
482 getFeedResult:
function RFS_getFeedResult(
uri) {
484 var resultList = this._results[
uri.spec];
485 for (var
i in resultList) {
487 return resultList[
i];
497 var resultList = this._results[
uri.spec];
501 for (var
i = 0;
i < resultList.length; ++
i) {
502 if (resultList[
i].
uri ==
uri) {
503 delete resultList[
i];
511 resultList.splice(resultList.length - deletions, deletions);
512 if (resultList.length == 0)
513 delete this._results[
uri.spec];
518 throw Cr.NS_ERROR_NO_AGGREGATION;
523 if (iid.equals(
Ci.nsIFeedResultService) ||
524 iid.equals(
Ci.nsIFactory) ||
525 iid.equals(
Ci.nsISupports))
527 throw Cr.NS_ERROR_NOT_IMPLEMENTED;
536 this._scheme = scheme;
538 Cc[
"@mozilla.org/network/io-service;1"].
540 this._http = ios.getProtocolHandler(
"http");
548 get protocolFlags() {
549 return this._http.protocolFlags;
553 return this._http.defaultPort;
556 allowPort:
function FPH_allowPort(port, scheme) {
557 return this._http.allowPort(port, scheme);
560 newURI:
function FPH_newURI(spec, originalCharset, baseURI) {
568 const feedSlashes =
"feed://";
569 const feedHttpSlashes =
"feed:http://";
570 const feedHttpsSlashes =
"feed:https://";
573 if (spec.substr(0, feedSlashes.length) != feedSlashes &&
574 spec.substr(0, feedHttpSlashes.length) != feedHttpSlashes &&
575 spec.substr(0, feedHttpsSlashes.length) != feedHttpsSlashes)
579 Cc[
"@mozilla.org/network/standard-url;1"].
581 uri.init(
Ci.nsIStandardURL.URLTYPE_STANDARD, 80, spec, originalCharset,
586 newChannel:
function FPH_newChannel(aUri) {
588 Cc[
"@mozilla.org/network/io-service;1"].
592 var feedSpec = aUri.spec;
593 const httpsChunk =
"feed://https//";
594 const httpChunk =
"feed://http//";
595 if (feedSpec.substr(0, httpsChunk.length) == httpsChunk)
596 feedSpec =
"https://" + feedSpec.substr(httpsChunk.length);
597 else if (feedSpec.substr(0, httpChunk.length) == httpChunk)
598 feedSpec =
"http://" + feedSpec.substr(httpChunk.length);
600 feedSpec = feedSpec.replace(/^feed/,
"http");
602 var uri = ios.newURI(feedSpec, aUri.originCharset,
null);
604 ios.newChannelFromURI(uri,
null).QueryInterface(
Ci.nsIHttpChannel);
606 channel.setRequestHeader(
"X-Moz-Is-Feed",
"1",
false);
607 channel.originalURI = aUri;
612 if (iid.equals(
Ci.nsIProtocolHandler) ||
613 iid.equals(
Ci.nsISupports))
615 throw Cr.NS_ERROR_NO_INTERFACE;
621 if (iid.equals(
Ci.nsIModule) ||
622 iid.equals(
Ci.nsISupports))
624 throw Cr.NS_ERROR_NO_INTERFACE;
628 if (!iid.equals(
Ci.nsIFactory))
629 throw Cr.NS_ERROR_NOT_IMPLEMENTED;
632 return FeedResultService;
640 throw Cr.NS_ERROR_NO_INTERFACE;
644 var
cr =
cm.QueryInterface(
Ci.nsIComponentRegistrar);
647 file, location, type);
649 file, location, type);
651 file, location, type);
655 const converterPrefix =
"@mozilla.org/streamconv;1?from=";
656 var converterContractID =
659 file, location, type);
661 converterContractID =
664 file, location, type);
666 converterContractID =
669 file, location, type);
672 unregisterSelf:
function M_unregisterSelf(
cm, location, type) {
673 var
cr =
cm.QueryInterface(
Ci.nsIComponentRegistrar);
674 cr.unregisterFactoryLocation(
FPH_CLASSID, location);
678 canUnload:
function M_canUnload(
cm) {
687 #include ../../../../toolkit/content/debug.js
688 #include GenericFactory.js
feedService removeFeedResult(this._feedURI)
const TYPE_MAYBE_VIDEO_FEED
function getPrefAppForType(t)
const PREF_SELECTED_READER
const TYPE_MAYBE_AUDIO_FEED
function getPrefActionForType(t)
function FeedProtocolHandler(scheme)
SafebrowsingApplicationMod prototype registerSelf
const PREF_VIDEO_SELECTED_ACTION
const PREF_AUDIO_SELECTED_READER
const PREF_AUDIO_SELECTED_WEB
sbOSDControlService prototype QueryInterface
const NS_ERROR_MALFORMED_URI
feedService addToClientReader(this._window.location.href, feedTitle, feedSubtitle, feedType)
function safeGetCharPref(pref, defaultValue)
function GenericComponentFactory(ctor, params)
function getPrefReaderForType(t)
getService(Ci.sbIFaceplateManager)
const PREF_SELECTED_ACTION
SafebrowsingApplicationMod prototype getClassObject
const PREF_AUDIO_SELECTED_APP
const PREF_VIDEO_SELECTED_READER
function NSGetModule(cm, file)
function newURI(aURLString)
function NS_ASSERT(cond, msg)
function getPrefWebForType(t)
_getSelectedPageStyle s i
const PREF_AUDIO_SELECTED_ACTION
const PREF_VIDEO_SELECTED_APP
const PREF_VIDEO_SELECTED_WEB