LCOV - code coverage report
Current view: directory - content/html/document/src - VideoDocument.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 49 0 0.0 %
Date: 2012-06-02 Functions: 8 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       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/
       9                 :  *
      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
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Mozilla Foundation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2008
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #include "MediaDocument.h"
      39                 : #include "nsGkAtoms.h"
      40                 : #include "nsNodeInfoManager.h"
      41                 : #include "nsContentCreatorFunctions.h"
      42                 : #include "nsHTMLMediaElement.h"
      43                 : #include "nsIDocShellTreeItem.h"
      44                 : #include "nsContentUtils.h"
      45                 : #include "mozilla/dom/Element.h"
      46                 : 
      47                 : namespace mozilla {
      48                 : namespace dom {
      49                 : 
      50                 : class VideoDocument : public MediaDocument
      51               0 : {
      52                 : public:
      53                 :   virtual nsresult StartDocumentLoad(const char*         aCommand,
      54                 :                                      nsIChannel*         aChannel,
      55                 :                                      nsILoadGroup*       aLoadGroup,
      56                 :                                      nsISupports*        aContainer,
      57                 :                                      nsIStreamListener** aDocListener,
      58                 :                                      bool                aReset = true,
      59                 :                                      nsIContentSink*     aSink = nsnull);
      60                 :   virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
      61                 : 
      62                 : protected:
      63                 : 
      64                 :   // Sets document <title> to reflect the file name and description.
      65                 :   void UpdateTitle(nsIChannel* aChannel);
      66                 : 
      67                 :   nsresult CreateSyntheticVideoDocument(nsIChannel* aChannel,
      68                 :                                         nsIStreamListener** aListener);
      69                 : 
      70                 :   nsRefPtr<MediaDocumentStreamListener> mStreamListener;
      71                 : };
      72                 : 
      73                 : nsresult
      74               0 : VideoDocument::StartDocumentLoad(const char*         aCommand,
      75                 :                                  nsIChannel*         aChannel,
      76                 :                                  nsILoadGroup*       aLoadGroup,
      77                 :                                  nsISupports*        aContainer,
      78                 :                                  nsIStreamListener** aDocListener,
      79                 :                                  bool                aReset,
      80                 :                                  nsIContentSink*     aSink)
      81                 : {
      82                 :   nsresult rv =
      83                 :     MediaDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer,
      84               0 :                                      aDocListener, aReset, aSink);
      85               0 :   NS_ENSURE_SUCCESS(rv, rv);
      86                 : 
      87               0 :   mStreamListener = new MediaDocumentStreamListener(this);
      88                 : 
      89                 :   // Create synthetic document
      90                 :   rv = CreateSyntheticVideoDocument(aChannel,
      91               0 :       getter_AddRefs(mStreamListener->mNextStream));
      92               0 :   NS_ENSURE_SUCCESS(rv, rv);
      93                 : 
      94               0 :   NS_ADDREF(*aDocListener = mStreamListener);
      95               0 :   return rv;
      96                 : }
      97                 : 
      98                 : void
      99               0 : VideoDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
     100                 : {
     101                 :   // Set the script global object on the superclass before doing
     102                 :   // anything that might require it....
     103               0 :   MediaDocument::SetScriptGlobalObject(aScriptGlobalObject);
     104                 : 
     105               0 :   if (aScriptGlobalObject && !nsContentUtils::IsChildOfSameType(this)) {
     106               0 :     LinkStylesheet(NS_LITERAL_STRING("resource://gre/res/TopLevelVideoDocument.css"));
     107                 :   }
     108               0 : }
     109                 : 
     110                 : nsresult
     111               0 : VideoDocument::CreateSyntheticVideoDocument(nsIChannel* aChannel,
     112                 :                                             nsIStreamListener** aListener)
     113                 : {
     114                 :   // make our generic document
     115               0 :   nsresult rv = MediaDocument::CreateSyntheticDocument();
     116               0 :   NS_ENSURE_SUCCESS(rv, rv);
     117                 : 
     118               0 :   Element* body = GetBodyElement();
     119               0 :   if (!body) {
     120               0 :     NS_WARNING("no body on video document!");
     121               0 :     return NS_ERROR_FAILURE;
     122                 :   }
     123                 : 
     124                 :   // make content
     125               0 :   nsCOMPtr<nsINodeInfo> nodeInfo;
     126                 :   nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::video, nsnull,
     127                 :                                            kNameSpaceID_XHTML,
     128               0 :                                            nsIDOMNode::ELEMENT_NODE);
     129               0 :   NS_ENSURE_TRUE(nodeInfo, NS_ERROR_FAILURE);
     130                 : 
     131                 :   nsRefPtr<nsHTMLMediaElement> element =
     132                 :     static_cast<nsHTMLMediaElement*>(NS_NewHTMLVideoElement(nodeInfo.forget(),
     133               0 :                                                             NOT_FROM_PARSER));
     134               0 :   if (!element)
     135               0 :     return NS_ERROR_OUT_OF_MEMORY;
     136               0 :   element->SetAutoplay(true);
     137               0 :   element->SetControls(true);
     138               0 :   element->LoadWithChannel(aChannel, aListener);
     139               0 :   UpdateTitle(aChannel);
     140                 : 
     141               0 :   if (nsContentUtils::IsChildOfSameType(this)) {
     142                 :     // Video documents that aren't toplevel should fill their frames and
     143                 :     // not have margins
     144                 :     element->SetAttr(kNameSpaceID_None, nsGkAtoms::style,
     145               0 :         NS_LITERAL_STRING("position:absolute; top:0; left:0; width:100%; height:100%"),
     146               0 :         true);
     147                 :   }
     148                 : 
     149               0 :   return body->AppendChildTo(element, false);
     150                 : }
     151                 : 
     152                 : void
     153               0 : VideoDocument::UpdateTitle(nsIChannel* aChannel)
     154                 : {
     155               0 :   if (!aChannel)
     156               0 :     return;
     157                 : 
     158               0 :   nsAutoString fileName;
     159               0 :   GetFileName(fileName);
     160               0 :   SetTitle(fileName);
     161                 : }
     162                 : 
     163                 : } // namespace dom
     164                 : } // namespace mozilla
     165                 : 
     166                 : nsresult
     167               0 : NS_NewVideoDocument(nsIDocument** aResult)
     168                 : {
     169               0 :   mozilla::dom::VideoDocument* doc = new mozilla::dom::VideoDocument();
     170                 : 
     171               0 :   NS_ADDREF(doc);
     172               0 :   nsresult rv = doc->Init();
     173                 : 
     174               0 :   if (NS_FAILED(rv)) {
     175               0 :     NS_RELEASE(doc);
     176                 :   }
     177                 : 
     178               0 :   *aResult = doc;
     179                 : 
     180               0 :   return rv;
     181                 : }

Generated by: LCOV version 1.7