2008-10-29 22:20:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2008
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
#include "MediaDocument.h"
|
2008-10-29 22:20:08 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsHTMLMediaElement.h"
|
2009-04-09 18:14:34 -07:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "nsContentUtils.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-04-30 06:12:05 -07:00
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2008-10-29 22:20:08 -07:00
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
class VideoDocument : public MediaDocument
|
2008-10-29 22:20:08 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual nsresult StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aReset = true,
|
2008-10-29 22:20:08 -07:00
|
|
|
nsIContentSink* aSink = nsnull);
|
2012-01-07 18:43:48 -08:00
|
|
|
virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
|
2008-10-29 22:20:08 -07:00
|
|
|
|
|
|
|
protected:
|
2009-01-16 01:07:26 -08:00
|
|
|
|
|
|
|
// Sets document <title> to reflect the file name and description.
|
|
|
|
void UpdateTitle(nsIChannel* aChannel);
|
|
|
|
|
2008-10-29 22:20:08 -07:00
|
|
|
nsresult CreateSyntheticVideoDocument(nsIChannel* aChannel,
|
|
|
|
nsIStreamListener** aListener);
|
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
nsRefPtr<MediaDocumentStreamListener> mStreamListener;
|
2008-10-29 22:20:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
2011-05-26 01:06:31 -07:00
|
|
|
VideoDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aReset,
|
2011-05-26 01:06:31 -07:00
|
|
|
nsIContentSink* aSink)
|
2008-10-29 22:20:08 -07:00
|
|
|
{
|
|
|
|
nsresult rv =
|
2011-05-26 01:06:31 -07:00
|
|
|
MediaDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer,
|
|
|
|
aDocListener, aReset, aSink);
|
2008-10-29 22:20:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
mStreamListener = new MediaDocumentStreamListener(this);
|
2008-10-29 22:20:08 -07:00
|
|
|
|
|
|
|
// Create synthetic document
|
|
|
|
rv = CreateSyntheticVideoDocument(aChannel,
|
|
|
|
getter_AddRefs(mStreamListener->mNextStream));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_ADDREF(*aDocListener = mStreamListener);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-01-07 18:43:48 -08:00
|
|
|
void
|
|
|
|
VideoDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
|
|
|
|
{
|
|
|
|
// Set the script global object on the superclass before doing
|
|
|
|
// anything that might require it....
|
|
|
|
MediaDocument::SetScriptGlobalObject(aScriptGlobalObject);
|
|
|
|
|
|
|
|
if (aScriptGlobalObject && !nsContentUtils::IsChildOfSameType(this)) {
|
|
|
|
LinkStylesheet(NS_LITERAL_STRING("resource://gre/res/TopLevelVideoDocument.css"));
|
2012-04-10 16:03:41 -07:00
|
|
|
LinkStylesheet(NS_LITERAL_STRING("chrome://global/skin/TopLevelVideoDocument.css"));
|
2012-01-07 18:43:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-29 22:20:08 -07:00
|
|
|
nsresult
|
2011-05-26 01:06:31 -07:00
|
|
|
VideoDocument::CreateSyntheticVideoDocument(nsIChannel* aChannel,
|
|
|
|
nsIStreamListener** aListener)
|
2008-10-29 22:20:08 -07:00
|
|
|
{
|
|
|
|
// make our generic document
|
2011-05-26 01:06:31 -07:00
|
|
|
nsresult rv = MediaDocument::CreateSyntheticDocument();
|
2008-10-29 22:20:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-30 06:12:05 -07:00
|
|
|
Element* body = GetBodyElement();
|
2008-10-29 22:20:08 -07:00
|
|
|
if (!body) {
|
|
|
|
NS_WARNING("no body on video document!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make content
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::video, nsnull,
|
2011-06-14 00:56:49 -07:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2008-10-29 22:20:08 -07:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsRefPtr<nsHTMLMediaElement> element =
|
2010-07-23 02:49:57 -07:00
|
|
|
static_cast<nsHTMLMediaElement*>(NS_NewHTMLVideoElement(nodeInfo.forget(),
|
2010-10-25 05:17:38 -07:00
|
|
|
NOT_FROM_PARSER));
|
2008-10-29 22:20:08 -07:00
|
|
|
if (!element)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2011-10-17 07:59:28 -07:00
|
|
|
element->SetAutoplay(true);
|
|
|
|
element->SetControls(true);
|
2008-10-29 22:20:08 -07:00
|
|
|
element->LoadWithChannel(aChannel, aListener);
|
2009-01-16 01:07:26 -08:00
|
|
|
UpdateTitle(aChannel);
|
2009-04-09 18:14:34 -07:00
|
|
|
|
2009-10-14 19:20:50 -07:00
|
|
|
if (nsContentUtils::IsChildOfSameType(this)) {
|
2009-04-09 18:14:34 -07: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 07:59:28 -07:00
|
|
|
true);
|
2009-04-09 18:14:34 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return body->AppendChildTo(element, false);
|
2008-10-29 22:20:08 -07:00
|
|
|
}
|
|
|
|
|
2009-01-16 01:07:26 -08:00
|
|
|
void
|
2011-05-26 01:06:31 -07:00
|
|
|
VideoDocument::UpdateTitle(nsIChannel* aChannel)
|
2009-01-16 01:07:26 -08:00
|
|
|
{
|
|
|
|
if (!aChannel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoString fileName;
|
|
|
|
GetFileName(fileName);
|
|
|
|
SetTitle(fileName);
|
|
|
|
}
|
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2008-10-29 22:20:08 -07:00
|
|
|
nsresult
|
|
|
|
NS_NewVideoDocument(nsIDocument** aResult)
|
|
|
|
{
|
2011-05-26 01:06:31 -07:00
|
|
|
mozilla::dom::VideoDocument* doc = new mozilla::dom::VideoDocument();
|
2008-10-29 22:20:08 -07:00
|
|
|
|
|
|
|
NS_ADDREF(doc);
|
|
|
|
nsresult rv = doc->Init();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = doc;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|