LCOV - code coverage report
Current view: top level - dom/html - VideoDocument.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 58 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "MediaDocument.h"
       8             : #include "nsGkAtoms.h"
       9             : #include "nsNodeInfoManager.h"
      10             : #include "nsContentCreatorFunctions.h"
      11             : #include "mozilla/dom/HTMLMediaElement.h"
      12             : #include "nsIDocumentInlines.h"
      13             : #include "nsContentUtils.h"
      14             : #include "mozilla/dom/Element.h"
      15             : 
      16             : namespace mozilla {
      17             : namespace dom {
      18             : 
      19           0 : class VideoDocument final : public MediaDocument
      20             : {
      21             : public:
      22             :   virtual nsresult StartDocumentLoad(const char*         aCommand,
      23             :                                      nsIChannel*         aChannel,
      24             :                                      nsILoadGroup*       aLoadGroup,
      25             :                                      nsISupports*        aContainer,
      26             :                                      nsIStreamListener** aDocListener,
      27             :                                      bool                aReset = true,
      28             :                                      nsIContentSink*     aSink = nullptr);
      29             :   virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
      30             : 
      31             : protected:
      32             : 
      33             :   // Sets document <title> to reflect the file name and description.
      34             :   void UpdateTitle(nsIChannel* aChannel);
      35             : 
      36             :   nsresult CreateSyntheticVideoDocument(nsIChannel* aChannel,
      37             :                                         nsIStreamListener** aListener);
      38             : 
      39             :   RefPtr<MediaDocumentStreamListener> mStreamListener;
      40             : };
      41             : 
      42             : nsresult
      43           0 : VideoDocument::StartDocumentLoad(const char*         aCommand,
      44             :                                  nsIChannel*         aChannel,
      45             :                                  nsILoadGroup*       aLoadGroup,
      46             :                                  nsISupports*        aContainer,
      47             :                                  nsIStreamListener** aDocListener,
      48             :                                  bool                aReset,
      49             :                                  nsIContentSink*     aSink)
      50             : {
      51             :   nsresult rv =
      52           0 :     MediaDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer,
      53           0 :                                      aDocListener, aReset, aSink);
      54           0 :   NS_ENSURE_SUCCESS(rv, rv);
      55             : 
      56           0 :   mStreamListener = new MediaDocumentStreamListener(this);
      57             : 
      58             :   // Create synthetic document
      59           0 :   rv = CreateSyntheticVideoDocument(aChannel,
      60           0 :       getter_AddRefs(mStreamListener->mNextStream));
      61           0 :   NS_ENSURE_SUCCESS(rv, rv);
      62             : 
      63           0 :   NS_ADDREF(*aDocListener = mStreamListener);
      64           0 :   return rv;
      65             : }
      66             : 
      67             : void
      68           0 : VideoDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
      69             : {
      70             :   // Set the script global object on the superclass before doing
      71             :   // anything that might require it....
      72           0 :   MediaDocument::SetScriptGlobalObject(aScriptGlobalObject);
      73             : 
      74           0 :   if (aScriptGlobalObject) {
      75           0 :     if (!nsContentUtils::IsChildOfSameType(this) &&
      76           0 :         GetReadyStateEnum() != nsIDocument::READYSTATE_COMPLETE) {
      77           0 :       LinkStylesheet(NS_LITERAL_STRING("resource://gre/res/TopLevelVideoDocument.css"));
      78           0 :       LinkStylesheet(NS_LITERAL_STRING("chrome://global/skin/media/TopLevelVideoDocument.css"));
      79           0 :       LinkScript(NS_LITERAL_STRING("chrome://global/content/TopLevelVideoDocument.js"));
      80             :     }
      81           0 :     BecomeInteractive();
      82             :   }
      83           0 : }
      84             : 
      85             : nsresult
      86           0 : VideoDocument::CreateSyntheticVideoDocument(nsIChannel* aChannel,
      87             :                                             nsIStreamListener** aListener)
      88             : {
      89             :   // make our generic document
      90           0 :   nsresult rv = MediaDocument::CreateSyntheticDocument();
      91           0 :   NS_ENSURE_SUCCESS(rv, rv);
      92             : 
      93           0 :   Element* body = GetBodyElement();
      94           0 :   if (!body) {
      95           0 :     NS_WARNING("no body on video document!");
      96           0 :     return NS_ERROR_FAILURE;
      97             :   }
      98             : 
      99             :   // make content
     100           0 :   RefPtr<mozilla::dom::NodeInfo> nodeInfo;
     101           0 :   nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::video, nullptr,
     102             :                                            kNameSpaceID_XHTML,
     103           0 :                                            nsIDOMNode::ELEMENT_NODE);
     104             : 
     105             :   RefPtr<HTMLMediaElement> element =
     106           0 :     static_cast<HTMLMediaElement*>(NS_NewHTMLVideoElement(nodeInfo.forget(),
     107           0 :                                                           NOT_FROM_PARSER));
     108           0 :   if (!element)
     109           0 :     return NS_ERROR_OUT_OF_MEMORY;
     110           0 :   element->SetAutoplay(true);
     111           0 :   element->SetControls(true);
     112           0 :   element->LoadWithChannel(aChannel, aListener);
     113           0 :   UpdateTitle(aChannel);
     114             : 
     115           0 :   if (nsContentUtils::IsChildOfSameType(this)) {
     116             :     // Video documents that aren't toplevel should fill their frames and
     117             :     // not have margins
     118           0 :     element->SetAttr(kNameSpaceID_None, nsGkAtoms::style,
     119           0 :         NS_LITERAL_STRING("position:absolute; top:0; left:0; width:100%; height:100%"),
     120           0 :         true);
     121             :   }
     122             : 
     123           0 :   return body->AppendChildTo(element, false);
     124             : }
     125             : 
     126             : void
     127           0 : VideoDocument::UpdateTitle(nsIChannel* aChannel)
     128             : {
     129           0 :   if (!aChannel)
     130           0 :     return;
     131             : 
     132           0 :   nsAutoString fileName;
     133           0 :   GetFileName(fileName, aChannel);
     134           0 :   SetTitle(fileName);
     135             : }
     136             : 
     137             : } // namespace dom
     138             : } // namespace mozilla
     139             : 
     140             : nsresult
     141           0 : NS_NewVideoDocument(nsIDocument** aResult)
     142             : {
     143           0 :   mozilla::dom::VideoDocument* doc = new mozilla::dom::VideoDocument();
     144             : 
     145           0 :   NS_ADDREF(doc);
     146           0 :   nsresult rv = doc->Init();
     147             : 
     148           0 :   if (NS_FAILED(rv)) {
     149           0 :     NS_RELEASE(doc);
     150             :   }
     151             : 
     152           0 :   *aResult = doc;
     153             : 
     154           0 :   return rv;
     155             : }

Generated by: LCOV version 1.13