content/html/document/src/VideoDocument.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial