Back to index

lightning-sunbird  0.9+nobinonly
nsContentSink.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is 
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _nsContentSink_h_
00039 #define _nsContentSink_h_
00040 
00041 // Base class for contentsink implementations.
00042 
00043 #include "nsICSSLoaderObserver.h"
00044 #include "nsIScriptLoaderObserver.h"
00045 #include "nsWeakReference.h"
00046 #include "nsCOMPtr.h"
00047 #include "nsCOMArray.h"
00048 #include "nsString.h"
00049 #include "nsAutoPtr.h"
00050 #include "nsHTMLAtoms.h"
00051 #include "nsTHashtable.h"
00052 #include "nsHashKeys.h"
00053 
00054 class nsIDocument;
00055 class nsIURI;
00056 class nsIChannel;
00057 class nsIDocShell;
00058 class nsICSSLoader;
00059 class nsIParser;
00060 class nsIAtom;
00061 class nsIChannel;
00062 class nsIContent;
00063 class nsIViewManager;
00064 class nsNodeInfoManager;
00065 
00066 class nsContentSink : public nsICSSLoaderObserver,
00067                       public nsIScriptLoaderObserver,
00068                       public nsSupportsWeakReference
00069 {
00070   NS_DECL_ISUPPORTS
00071   NS_DECL_NSISCRIPTLOADEROBSERVER
00072   
00073   // nsICSSLoaderObserver
00074   NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aNotify);
00075 
00076 protected:
00077   nsContentSink();
00078   virtual ~nsContentSink();
00079 
00080   nsresult Init(nsIDocument* aDoc, nsIURI* aURI,
00081                 nsISupports* aContainer, nsIChannel* aChannel);
00082 
00083   nsresult ProcessHTTPHeaders(nsIChannel* aChannel);
00084   nsresult ProcessHeaderData(nsIAtom* aHeader, const nsAString& aValue,
00085                              nsIContent* aContent = nsnull);
00086   nsresult ProcessLinkHeader(nsIContent* aElement,
00087                              const nsAString& aLinkData);
00088   nsresult ProcessLink(nsIContent* aElement, const nsSubstring& aHref,
00089                        const nsSubstring& aRel, const nsSubstring& aTitle,
00090                        const nsSubstring& aType, const nsSubstring& aMedia);
00091 
00092   virtual nsresult ProcessStyleLink(nsIContent* aElement,
00093                                     const nsSubstring& aHref,
00094                                     PRBool aAlternate,
00095                                     const nsSubstring& aTitle,
00096                                     const nsSubstring& aType,
00097                                     const nsSubstring& aMedia);
00098 
00099   nsresult ProcessMETATag(nsIContent* aContent);
00100 
00101   void PrefetchHref(const nsAString &aHref, PRBool aExplicit);
00102 
00103   PRBool ScrollToRef(PRBool aReallyScroll);
00104   nsresult RefreshIfEnabled(nsIViewManager* vm);
00105   void StartLayout(PRBool aIsFrameset);
00106 
00107   // Overridable hooks into script evaluation
00108   virtual void PreEvaluateScript()  {return;}
00109   virtual void PostEvaluateScript() {return;}
00110 
00111   nsCOMPtr<nsIDocument>         mDocument;
00112   nsCOMPtr<nsIParser>           mParser;
00113   nsCOMPtr<nsIURI>              mDocumentURI;
00114   nsCOMPtr<nsIURI>              mDocumentBaseURI;
00115   nsCOMPtr<nsIDocShell>         mDocShell;
00116   nsCOMPtr<nsICSSLoader>        mCSSLoader;
00117   nsRefPtr<nsNodeInfoManager>   mNodeInfoManager;
00118 
00119   nsCOMArray<nsIScriptElement> mScriptElements;
00120 
00121   nsCString mRef; // ScrollTo #ref
00122   PRBool mNeedToBlockParser;
00123 };
00124 
00125 // these two lists are used by the sanitizing fragment serializers
00126 static nsIAtom** const kDefaultAllowedTags [] = {
00127   &nsHTMLAtoms::a,
00128   &nsHTMLAtoms::abbr,
00129   &nsHTMLAtoms::acronym,
00130   &nsHTMLAtoms::address,
00131   &nsHTMLAtoms::area,
00132   &nsHTMLAtoms::b,
00133   &nsHTMLAtoms::big,
00134   &nsHTMLAtoms::blockquote,
00135   &nsHTMLAtoms::br,
00136   &nsHTMLAtoms::button,
00137   &nsHTMLAtoms::caption,
00138   &nsHTMLAtoms::center,
00139   &nsHTMLAtoms::cite,
00140   &nsHTMLAtoms::code,
00141   &nsHTMLAtoms::col,
00142   &nsHTMLAtoms::colgroup,
00143   &nsHTMLAtoms::dd,
00144   &nsHTMLAtoms::del,
00145   &nsHTMLAtoms::dfn,
00146   &nsHTMLAtoms::dir,
00147   &nsHTMLAtoms::div,
00148   &nsHTMLAtoms::dl,
00149   &nsHTMLAtoms::dt,
00150   &nsHTMLAtoms::em,
00151   &nsHTMLAtoms::fieldset,
00152   &nsHTMLAtoms::font,
00153   &nsHTMLAtoms::form,
00154   &nsHTMLAtoms::h1,
00155   &nsHTMLAtoms::h2,
00156   &nsHTMLAtoms::h3,
00157   &nsHTMLAtoms::h4,
00158   &nsHTMLAtoms::h5,
00159   &nsHTMLAtoms::h6,
00160   &nsHTMLAtoms::hr,
00161   &nsHTMLAtoms::i,
00162   &nsHTMLAtoms::img,
00163   &nsHTMLAtoms::input,
00164   &nsHTMLAtoms::ins,
00165   &nsHTMLAtoms::kbd,
00166   &nsHTMLAtoms::label,
00167   &nsHTMLAtoms::legend,
00168   &nsHTMLAtoms::li,
00169   &nsHTMLAtoms::map,
00170   &nsHTMLAtoms::menu,
00171   &nsHTMLAtoms::ol,
00172   &nsHTMLAtoms::optgroup,
00173   &nsHTMLAtoms::option,
00174   &nsHTMLAtoms::p,
00175   &nsHTMLAtoms::pre,
00176   &nsHTMLAtoms::q,
00177   &nsHTMLAtoms::s,
00178   &nsHTMLAtoms::samp,
00179   &nsHTMLAtoms::select,
00180   &nsHTMLAtoms::small,
00181   &nsHTMLAtoms::span,
00182   &nsHTMLAtoms::strike,
00183   &nsHTMLAtoms::strong,
00184   &nsHTMLAtoms::sub,
00185   &nsHTMLAtoms::sup,
00186   &nsHTMLAtoms::table,
00187   &nsHTMLAtoms::tbody,
00188   &nsHTMLAtoms::td,
00189   &nsHTMLAtoms::textarea,
00190   &nsHTMLAtoms::tfoot,
00191   &nsHTMLAtoms::th,
00192   &nsHTMLAtoms::thead,
00193   &nsHTMLAtoms::tr,
00194   &nsHTMLAtoms::tt,
00195   &nsHTMLAtoms::u,
00196   &nsHTMLAtoms::ul
00197 };
00198 
00199 static nsIAtom** const kDefaultAllowedAttributes [] = {
00200   &nsHTMLAtoms::accept,
00201   &nsHTMLAtoms::acceptcharset,
00202   &nsHTMLAtoms::accesskey,
00203   &nsHTMLAtoms::action,
00204   &nsHTMLAtoms::align,
00205   &nsHTMLAtoms::alt,
00206   &nsHTMLAtoms::axis,
00207   &nsHTMLAtoms::border,
00208   &nsHTMLAtoms::cellpadding,
00209   &nsHTMLAtoms::cellspacing,
00210   &nsHTMLAtoms::_char,
00211   &nsHTMLAtoms::charoff,
00212   &nsHTMLAtoms::charset,
00213   &nsHTMLAtoms::checked,
00214   &nsHTMLAtoms::cite,
00215   &nsHTMLAtoms::kClass,
00216   &nsHTMLAtoms::clear,
00217   &nsHTMLAtoms::cols,
00218   &nsHTMLAtoms::colspan,
00219   &nsHTMLAtoms::color,
00220   &nsHTMLAtoms::compact,
00221   &nsHTMLAtoms::coords,
00222   &nsHTMLAtoms::datetime,
00223   &nsHTMLAtoms::dir,
00224   &nsHTMLAtoms::disabled,
00225   &nsHTMLAtoms::enctype,
00226   &nsHTMLAtoms::_for,
00227   &nsHTMLAtoms::frame,
00228   &nsHTMLAtoms::headers,
00229   &nsHTMLAtoms::height,
00230   &nsHTMLAtoms::href,
00231   &nsHTMLAtoms::hreflang,
00232   &nsHTMLAtoms::hspace,
00233   &nsHTMLAtoms::id,
00234   &nsHTMLAtoms::ismap,
00235   &nsHTMLAtoms::label,
00236   &nsHTMLAtoms::lang,
00237   &nsHTMLAtoms::longdesc,
00238   &nsHTMLAtoms::maxlength,
00239   &nsHTMLAtoms::media,
00240   &nsHTMLAtoms::method,
00241   &nsHTMLAtoms::multiple,
00242   &nsHTMLAtoms::name,
00243   &nsHTMLAtoms::nohref,
00244   &nsHTMLAtoms::noshade,
00245   &nsHTMLAtoms::nowrap,
00246   &nsHTMLAtoms::prompt,
00247   &nsHTMLAtoms::readonly,
00248   &nsHTMLAtoms::rel,
00249   &nsHTMLAtoms::rev,
00250   &nsHTMLAtoms::rows,
00251   &nsHTMLAtoms::rowspan,
00252   &nsHTMLAtoms::rules,
00253   &nsHTMLAtoms::scope,
00254   &nsHTMLAtoms::selected,
00255   &nsHTMLAtoms::shape,
00256   &nsHTMLAtoms::size,
00257   &nsHTMLAtoms::span,
00258   &nsHTMLAtoms::src,
00259   &nsHTMLAtoms::start,
00260   &nsHTMLAtoms::summary,
00261   &nsHTMLAtoms::tabindex,
00262   &nsHTMLAtoms::target,
00263   &nsHTMLAtoms::title,
00264   &nsHTMLAtoms::type,
00265   &nsHTMLAtoms::usemap,
00266   &nsHTMLAtoms::valign,
00267   &nsHTMLAtoms::value,
00268   &nsHTMLAtoms::vspace,
00269   &nsHTMLAtoms::width
00270 };
00271 
00272 // URIs action, href, src, longdesc, usemap, cite
00273 static
00274 PRBool IsAttrURI(nsIAtom *aName)
00275 {
00276   return (aName == nsHTMLAtoms::action ||
00277           aName == nsHTMLAtoms::href ||
00278           aName == nsHTMLAtoms::src ||
00279           aName == nsHTMLAtoms::longdesc ||
00280           aName == nsHTMLAtoms::usemap ||
00281           aName == nsHTMLAtoms::cite);
00282 }
00283 #endif // _nsContentSink_h_