2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-10-30 05:20:08 +00:00
|
|
|
|
2011-05-26 08:06:31 +00:00
|
|
|
#include "MediaDocument.h"
|
2008-10-30 05:20:08 +00:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
2013-03-19 12:23:54 +00:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2019-01-02 13:05:23 +00:00
|
|
|
#include "DocumentInlines.h"
|
2011-08-11 13:29:50 +00:00
|
|
|
#include "nsContentUtils.h"
|
2010-05-05 18:18:05 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-04-30 13:12:05 +00:00
|
|
|
|
2011-05-26 08:06:31 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2008-10-30 05:20:08 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class VideoDocument final : public MediaDocument {
|
2008-10-30 05:20:08 +00:00
|
|
|
public:
|
2018-07-19 11:36:20 +00:00
|
|
|
enum MediaDocumentKind MediaDocumentKind() const override {
|
|
|
|
return MediaDocumentKind::Video;
|
|
|
|
}
|
|
|
|
|
2008-10-30 05:20:08 +00:00
|
|
|
virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aReset = true,
|
2017-11-06 03:37:28 +00:00
|
|
|
nsIContentSink* aSink = nullptr) override;
|
|
|
|
virtual void SetScriptGlobalObject(
|
|
|
|
nsIScriptGlobalObject* aScriptGlobalObject) override;
|
2008-10-30 05:20:08 +00:00
|
|
|
|
2017-11-06 03:37:28 +00:00
|
|
|
virtual void Destroy() override {
|
2017-12-07 05:10:51 +00:00
|
|
|
if (mStreamListener) {
|
|
|
|
mStreamListener->DropDocumentRef();
|
|
|
|
}
|
|
|
|
MediaDocument::Destroy();
|
|
|
|
}
|
|
|
|
|
2019-05-14 04:27:49 +00:00
|
|
|
nsresult StartLayout() override;
|
|
|
|
|
2008-10-30 05:20:08 +00:00
|
|
|
protected:
|
2019-05-14 04:27:49 +00:00
|
|
|
nsresult CreateVideoElement();
|
2009-01-16 09:07:26 +00:00
|
|
|
// Sets document <title> to reflect the file name and description.
|
|
|
|
void UpdateTitle(nsIChannel* aChannel);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<MediaDocumentStreamListener> mStreamListener;
|
2008-10-30 05:20:08 +00:00
|
|
|
};
|
|
|
|
|
2011-05-26 08:06:31 +00:00
|
|
|
nsresult VideoDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
bool aReset, nsIContentSink* aSink) {
|
|
|
|
nsresult rv = MediaDocument::StartDocumentLoad(
|
|
|
|
aCommand, aChannel, aLoadGroup, aContainer, aDocListener, aReset, aSink);
|
2008-10-30 05:20:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-05-26 08:06:31 +00:00
|
|
|
mStreamListener = new MediaDocumentStreamListener(this);
|
2008-10-30 05:20:08 +00:00
|
|
|
NS_ADDREF(*aDocListener = mStreamListener);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-05-14 04:27:49 +00:00
|
|
|
nsresult VideoDocument::StartLayout() {
|
|
|
|
// Create video element, and begin loading the media resource. Note we
|
|
|
|
// delay creating the video element until now (we're called from
|
|
|
|
// MediaDocumentStreamListener::OnStartRequest) as the PresShell is likely
|
|
|
|
// to have been created by now, so the MediaDecoder will be able to tell
|
|
|
|
// what kind of compositor we have, so the video element knows whether
|
|
|
|
// it can create a hardware accelerated video decoder or not.
|
|
|
|
nsresult rv = CreateVideoElement();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = MediaDocument::StartLayout();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-08 02:43:48 +00:00
|
|
|
void VideoDocument::SetScriptGlobalObject(
|
|
|
|
nsIScriptGlobalObject* aScriptGlobalObject) {
|
|
|
|
// Set the script global object on the superclass before doing
|
|
|
|
// anything that might require it....
|
|
|
|
MediaDocument::SetScriptGlobalObject(aScriptGlobalObject);
|
|
|
|
|
2018-05-23 15:06:34 +00:00
|
|
|
if (aScriptGlobalObject && !InitialSetupHasBeenDone()) {
|
2019-05-14 04:27:49 +00:00
|
|
|
DebugOnly<nsresult> rv = CreateSyntheticDocument();
|
2018-08-15 16:28:32 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create synthetic video document");
|
2018-08-14 21:53:17 +00:00
|
|
|
|
2018-05-23 15:06:34 +00:00
|
|
|
if (!nsContentUtils::IsChildOfSameType(this)) {
|
2017-06-08 09:52:46 +00:00
|
|
|
LinkStylesheet(NS_LITERAL_STRING(
|
|
|
|
"resource://content-accessible/TopLevelVideoDocument.css"));
|
2012-10-05 21:44:11 +00:00
|
|
|
LinkStylesheet(NS_LITERAL_STRING(
|
|
|
|
"chrome://global/skin/media/TopLevelVideoDocument.css"));
|
2015-10-04 11:04:55 +00:00
|
|
|
LinkScript(NS_LITERAL_STRING(
|
|
|
|
"chrome://global/content/TopLevelVideoDocument.js"));
|
2012-07-27 13:35:09 +00:00
|
|
|
}
|
2018-05-23 15:06:34 +00:00
|
|
|
InitialSetupDone();
|
2012-01-08 02:43:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 04:27:49 +00:00
|
|
|
nsresult VideoDocument::CreateVideoElement() {
|
2019-08-06 13:43:01 +00:00
|
|
|
RefPtr<Element> body = GetBodyElement();
|
2008-10-30 05:20:08 +00:00
|
|
|
if (!body) {
|
|
|
|
NS_WARNING("no body on video document!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make content
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-07-30 14:20:58 +00:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(
|
|
|
|
nsGkAtoms::video, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<HTMLMediaElement> element = static_cast<HTMLMediaElement*>(
|
2013-03-19 12:23:54 +00:00
|
|
|
NS_NewHTMLVideoElement(nodeInfo.forget(), NOT_FROM_PARSER));
|
2008-10-30 05:20:08 +00:00
|
|
|
if (!element) return NS_ERROR_OUT_OF_MEMORY;
|
2018-02-15 05:22:38 +00:00
|
|
|
element->SetAutoplay(true, IgnoreErrors());
|
|
|
|
element->SetControls(true, IgnoreErrors());
|
2018-08-14 21:53:17 +00:00
|
|
|
element->LoadWithChannel(mChannel,
|
|
|
|
getter_AddRefs(mStreamListener->mNextStream));
|
|
|
|
UpdateTitle(mChannel);
|
2009-04-10 01:14:34 +00:00
|
|
|
|
2009-10-15 02:20:50 +00:00
|
|
|
if (nsContentUtils::IsChildOfSameType(this)) {
|
2009-04-10 01:14:34 +00:00
|
|
|
// Video documents that aren't toplevel should fill their frames and
|
|
|
|
// not have margins
|
|
|
|
element->SetAttr(
|
|
|
|
kNameSpaceID_None, nsGkAtoms::style,
|
|
|
|
NS_LITERAL_STRING(
|
|
|
|
"position:absolute; top:0; left:0; width:100%; height:100%"),
|
2011-10-17 14:59:28 +00:00
|
|
|
true);
|
2009-04-10 01:14:34 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return body->AppendChildTo(element, false);
|
2008-10-30 05:20:08 +00:00
|
|
|
}
|
|
|
|
|
2011-05-26 08:06:31 +00:00
|
|
|
void VideoDocument::UpdateTitle(nsIChannel* aChannel) {
|
2009-01-16 09:07:26 +00:00
|
|
|
if (!aChannel) return;
|
|
|
|
|
|
|
|
nsAutoString fileName;
|
2014-10-30 05:08:00 +00:00
|
|
|
GetFileName(fileName, aChannel);
|
2018-01-31 20:18:10 +00:00
|
|
|
IgnoredErrorResult ignored;
|
|
|
|
SetTitle(fileName, ignored);
|
2009-01-16 09:07:26 +00:00
|
|
|
}
|
|
|
|
|
2011-05-26 08:06:31 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2019-01-02 13:05:23 +00:00
|
|
|
nsresult NS_NewVideoDocument(mozilla::dom::Document** aResult) {
|
|
|
|
auto* doc = new mozilla::dom::VideoDocument();
|
2008-10-30 05:20:08 +00:00
|
|
|
|
|
|
|
NS_ADDREF(doc);
|
|
|
|
nsresult rv = doc->Init();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = doc;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|