2015-05-03 22:32:37 +03: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 15:12:37 +04: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/. */
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
#include "MediaDocument.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2003-03-22 05:22:03 +03:00
|
|
|
#include "nsRect.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2003-03-22 05:22:03 +03:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIScrollable.h"
|
2013-01-05 07:12:24 +04:00
|
|
|
#include "nsViewManager.h"
|
2003-04-13 04:40:26 +04:00
|
|
|
#include "nsITextToSubURI.h"
|
|
|
|
#include "nsIURL.h"
|
2003-07-26 09:17:26 +04:00
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIDocShell.h"
|
2012-03-22 18:42:42 +04:00
|
|
|
#include "nsCharsetSource.h" // kCharsetFrom* macro definition
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
2011-12-15 19:10:36 +04:00
|
|
|
#include "nsContentUtils.h"
|
2013-03-17 11:55:12 +04:00
|
|
|
#include "nsDocElementCreatedNotificationRunner.h"
|
2013-06-11 04:18:29 +04:00
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-10-16 05:46:10 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2014-07-30 02:23:22 +04:00
|
|
|
#include "nsIMultiPartChannel.h"
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
MediaDocumentStreamListener::MediaDocumentStreamListener(MediaDocument *aDocument)
|
2003-03-22 05:22:03 +03:00
|
|
|
{
|
|
|
|
mDocument = aDocument;
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocumentStreamListener::~MediaDocumentStreamListener()
|
2003-03-22 05:22:03 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(MediaDocumentStreamListener,
|
|
|
|
nsIRequestObserver,
|
|
|
|
nsIStreamListener)
|
2003-03-22 05:22:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocumentStreamListener::SetStreamListener(nsIStreamListener *aListener)
|
2003-03-22 05:22:03 +03:00
|
|
|
{
|
|
|
|
mNextStream = aListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocumentStreamListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
|
2003-03-22 05:22:03 +03:00
|
|
|
{
|
2003-04-04 04:26:33 +04:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
|
|
|
|
|
2003-03-22 05:22:03 +03:00
|
|
|
mDocument->StartLayout();
|
|
|
|
|
|
|
|
if (mNextStream) {
|
|
|
|
return mNextStream->OnStartRequest(request, ctxt);
|
|
|
|
}
|
|
|
|
|
2015-10-27 23:25:14 +03:00
|
|
|
return NS_ERROR_PARSED_DATA_CACHED;
|
2003-03-22 05:22:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocumentStreamListener::OnStopRequest(nsIRequest* request,
|
|
|
|
nsISupports *ctxt,
|
|
|
|
nsresult status)
|
2003-03-22 05:22:03 +03:00
|
|
|
{
|
2003-04-04 04:26:33 +04:00
|
|
|
nsresult rv = NS_OK;
|
2003-03-22 05:22:03 +03:00
|
|
|
if (mNextStream) {
|
2003-04-04 04:26:33 +04:00
|
|
|
rv = mNextStream->OnStopRequest(request, ctxt, status);
|
2003-03-22 05:22:03 +03:00
|
|
|
}
|
|
|
|
|
2014-07-30 02:23:22 +04:00
|
|
|
// Don't release mDocument here if we're in the middle of a multipart response.
|
|
|
|
bool lastPart = true;
|
|
|
|
nsCOMPtr<nsIMultiPartChannel> mpchan(do_QueryInterface(request));
|
|
|
|
if (mpchan) {
|
|
|
|
mpchan->GetIsLastPart(&lastPart);
|
|
|
|
}
|
2003-04-04 04:26:33 +04:00
|
|
|
|
2014-07-30 02:23:22 +04:00
|
|
|
if (lastPart) {
|
|
|
|
mDocument = nullptr;
|
|
|
|
}
|
2003-04-04 04:26:33 +04:00
|
|
|
return rv;
|
2003-03-22 05:22:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocumentStreamListener::OnDataAvailable(nsIRequest* request,
|
|
|
|
nsISupports *ctxt,
|
|
|
|
nsIInputStream *inStr,
|
2012-09-06 06:41:02 +04:00
|
|
|
uint64_t sourceOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count)
|
2003-03-22 05:22:03 +03:00
|
|
|
{
|
|
|
|
if (mNextStream) {
|
|
|
|
return mNextStream->OnDataAvailable(request, ctxt, inStr, sourceOffset, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
// default format names for MediaDocument.
|
|
|
|
const char* const MediaDocument::sFormatNames[4] =
|
2003-04-13 04:40:26 +04:00
|
|
|
{
|
|
|
|
"MediaTitleWithNoInfo", // eWithNoInfo
|
|
|
|
"MediaTitleWithFile", // eWithFile
|
|
|
|
"", // eWithDim
|
|
|
|
"" // eWithDimAndFile
|
|
|
|
};
|
|
|
|
|
2013-05-06 17:42:00 +04:00
|
|
|
MediaDocument::MediaDocument()
|
|
|
|
: nsHTMLDocument(),
|
2012-12-12 06:45:36 +04:00
|
|
|
mDocumentElementInserted(false)
|
2003-03-22 05:22:03 +03:00
|
|
|
{
|
|
|
|
}
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocument::~MediaDocument()
|
2003-03-22 05:22:03 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-04-13 04:40:26 +04:00
|
|
|
nsresult
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocument::Init()
|
2003-04-13 04:40:26 +04:00
|
|
|
{
|
|
|
|
nsresult rv = nsHTMLDocument::Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Create a bundle for the localization
|
2010-05-14 13:24:41 +04:00
|
|
|
nsCOMPtr<nsIStringBundleService> stringService =
|
|
|
|
mozilla::services::GetStringBundleService();
|
2003-04-13 04:40:26 +04:00
|
|
|
if (stringService) {
|
|
|
|
stringService->CreateBundle(NSMEDIADOCUMENT_PROPERTIES_URI,
|
|
|
|
getter_AddRefs(mStringBundle));
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsSyntheticDocument = true;
|
2011-08-09 16:35:00 +04:00
|
|
|
|
2003-04-13 04:40:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aReset,
|
2011-05-26 12:06:31 +04:00
|
|
|
nsIContentSink* aSink)
|
2003-03-22 05:22:03 +03:00
|
|
|
{
|
|
|
|
nsresult rv = nsDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup,
|
|
|
|
aContainer, aDocListener, aReset,
|
|
|
|
aSink);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-07-26 09:17:26 +04:00
|
|
|
// We try to set the charset of the current document to that of the
|
|
|
|
// 'genuine' (as opposed to an intervening 'chrome') parent document
|
|
|
|
// that may be in a different window/tab. Even if we fail here,
|
|
|
|
// we just return NS_OK because another attempt is made in
|
|
|
|
// |UpdateTitleAndCharset| and the worst thing possible is a mangled
|
|
|
|
// filename in the titlebar and the file picker.
|
|
|
|
|
2013-10-16 05:46:10 +04:00
|
|
|
// Note that we
|
2003-07-26 09:17:26 +04:00
|
|
|
// exclude UTF-8 as 'invalid' because UTF-8 is likely to be the charset
|
|
|
|
// of a chrome document that has nothing to do with the actual content
|
|
|
|
// whose charset we want to know. Even if "the actual content" is indeed
|
|
|
|
// in UTF-8, we don't lose anything because the default empty value is
|
|
|
|
// considered synonymous with UTF-8.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
|
2003-07-26 09:54:42 +04:00
|
|
|
|
|
|
|
// not being able to set the charset is not critical.
|
2003-07-26 09:17:26 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_OK);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString charset;
|
2013-10-16 05:46:10 +04:00
|
|
|
int32_t source;
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
2013-05-25 18:09:30 +04:00
|
|
|
// opening in a new tab
|
2013-10-16 05:46:10 +04:00
|
|
|
docShell->GetParentCharset(charset, &source, getter_AddRefs(principal));
|
2003-07-26 09:17:26 +04:00
|
|
|
|
2013-10-16 05:46:10 +04:00
|
|
|
if (!charset.IsEmpty() &&
|
2014-05-22 07:48:51 +04:00
|
|
|
!charset.EqualsLiteral("UTF-8") &&
|
2013-10-16 05:46:10 +04:00
|
|
|
NodePrincipal()->Equals(principal)) {
|
|
|
|
SetDocumentCharacterSetSource(source);
|
2003-07-26 09:17:26 +04:00
|
|
|
SetDocumentCharacterSet(charset);
|
|
|
|
}
|
|
|
|
|
2003-03-22 05:22:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-27 17:35:09 +04:00
|
|
|
void
|
|
|
|
MediaDocument::BecomeInteractive()
|
|
|
|
{
|
|
|
|
// In principle, if we knew the readyState code to work, we could infer
|
|
|
|
// restoration from GetReadyStateEnum() == nsIDocument::READYSTATE_COMPLETE.
|
|
|
|
bool restoring = false;
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsPIDOMWindowOuter* window = GetWindow()) {
|
2012-07-27 17:35:09 +04:00
|
|
|
nsIDocShell* docShell = window->GetDocShell();
|
|
|
|
if (docShell) {
|
|
|
|
docShell->GetRestoringDocument(&restoring);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!restoring) {
|
|
|
|
MOZ_ASSERT(GetReadyStateEnum() == nsIDocument::READYSTATE_LOADING,
|
|
|
|
"Bad readyState");
|
|
|
|
SetReadyStateInternal(nsIDocument::READYSTATE_INTERACTIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-22 05:22:03 +03:00
|
|
|
nsresult
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocument::CreateSyntheticDocument()
|
2003-03-22 05:22:03 +03:00
|
|
|
{
|
|
|
|
// Synthesize an empty html document
|
|
|
|
nsresult rv;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-07-30 18:20:58 +04:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::html, nullptr,
|
2011-06-14 11:56:49 +04:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> root = NS_NewHTMLHtmlElement(nodeInfo.forget());
|
2011-11-11 03:08:07 +04:00
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_OUT_OF_MEMORY);
|
2005-04-15 05:30:14 +04:00
|
|
|
|
2006-01-19 06:34:18 +03:00
|
|
|
NS_ASSERTION(GetChildCount() == 0, "Shouldn't have any kids");
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = AppendChildTo(root, false);
|
2005-04-15 05:30:14 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::head, nullptr,
|
2011-06-14 11:56:49 +04:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2008-08-18 06:10:28 +04:00
|
|
|
|
|
|
|
// Create a <head> so our title has somewhere to live
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> head = NS_NewHTMLHeadElement(nodeInfo.forget());
|
2011-11-11 03:08:07 +04:00
|
|
|
NS_ENSURE_TRUE(head, NS_ERROR_OUT_OF_MEMORY);
|
2008-08-18 06:10:28 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::meta, nullptr,
|
2011-11-11 03:08:07 +04:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2011-09-02 01:16:13 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> metaContent = NS_NewHTMLMetaElement(nodeInfo.forget());
|
2011-11-11 03:08:07 +04:00
|
|
|
NS_ENSURE_TRUE(metaContent, NS_ERROR_OUT_OF_MEMORY);
|
2011-09-02 01:16:13 +04:00
|
|
|
metaContent->SetAttr(kNameSpaceID_None, nsGkAtoms::name,
|
|
|
|
NS_LITERAL_STRING("viewport"),
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2011-09-02 01:16:13 +04:00
|
|
|
|
|
|
|
metaContent->SetAttr(kNameSpaceID_None, nsGkAtoms::content,
|
|
|
|
NS_LITERAL_STRING("width=device-width; height=device-height;"),
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
|
|
|
head->AppendChildTo(metaContent, false);
|
2011-09-02 01:16:13 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
root->AppendChildTo(head, false);
|
2008-08-18 06:10:28 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::body, nullptr,
|
2011-06-14 11:56:49 +04:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> body = NS_NewHTMLBodyElement(nodeInfo.forget());
|
2011-11-11 03:08:07 +04:00
|
|
|
NS_ENSURE_TRUE(body, NS_ERROR_OUT_OF_MEMORY);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
root->AppendChildTo(body, false);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocument::StartLayout()
|
2003-03-22 05:22:03 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mMayStartLayout = true;
|
2010-06-25 17:59:57 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell = GetShell();
|
2010-01-07 13:36:11 +03:00
|
|
|
// Don't mess with the presshell if someone has already handled
|
|
|
|
// its initial reflow.
|
2012-09-07 08:16:09 +04:00
|
|
|
if (shell && !shell->DidInitialize()) {
|
2004-08-21 00:34:37 +04:00
|
|
|
nsRect visibleArea = shell->GetPresContext()->GetVisibleArea();
|
2012-09-07 08:16:09 +04:00
|
|
|
nsresult rv = shell->Initialize(visibleArea.width, visibleArea.height);
|
2006-05-15 21:51:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-03-22 05:22:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-04-13 04:40:26 +04:00
|
|
|
|
2009-01-16 12:07:26 +03:00
|
|
|
void
|
2014-10-30 08:08:00 +03:00
|
|
|
MediaDocument::GetFileName(nsAString& aResult, nsIChannel* aChannel)
|
2009-01-16 12:07:26 +03:00
|
|
|
{
|
|
|
|
aResult.Truncate();
|
|
|
|
|
2014-10-30 08:08:00 +03:00
|
|
|
if (aChannel) {
|
|
|
|
aChannel->GetContentDispositionFilename(aResult);
|
|
|
|
if (!aResult.IsEmpty())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-16 12:07:26 +03:00
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(mDocumentURI);
|
|
|
|
if (!url)
|
|
|
|
return;
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString fileName;
|
2009-01-16 12:07:26 +03:00
|
|
|
url->GetFileName(fileName);
|
|
|
|
if (fileName.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString docCharset;
|
2009-01-16 12:07:26 +03:00
|
|
|
// Now that the charset is set in |StartDocumentLoad| to the charset of
|
|
|
|
// the document viewer instead of a bogus value ("ISO-8859-1" set in
|
|
|
|
// |nsDocument|'s ctor), the priority is given to the current charset.
|
|
|
|
// This is necessary to deal with a media document being opened in a new
|
|
|
|
// window or a new tab, in which case |originCharset| of |nsIURI| is not
|
|
|
|
// reliable.
|
|
|
|
if (mCharacterSetSource != kCharsetUninitialized) {
|
|
|
|
docCharset = mCharacterSet;
|
|
|
|
} else {
|
|
|
|
// resort to |originCharset|
|
|
|
|
url->GetOriginCharset(docCharset);
|
|
|
|
SetDocumentCharacterSet(docCharset);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsITextToSubURI> textToSubURI =
|
|
|
|
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// UnEscapeURIForUI always succeeds
|
|
|
|
textToSubURI->UnEscapeURIForUI(docCharset, fileName, aResult);
|
|
|
|
} else {
|
|
|
|
CopyUTF8toUTF16(fileName, aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-11 03:08:07 +04:00
|
|
|
nsresult
|
|
|
|
MediaDocument::LinkStylesheet(const nsAString& aStylesheet)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-07-30 18:20:58 +04:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::link, nullptr,
|
2011-11-11 03:08:07 +04:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> link = NS_NewHTMLLinkElement(nodeInfo.forget());
|
2011-11-11 03:08:07 +04:00
|
|
|
NS_ENSURE_TRUE(link, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
link->SetAttr(kNameSpaceID_None, nsGkAtoms::rel,
|
|
|
|
NS_LITERAL_STRING("stylesheet"), true);
|
|
|
|
|
|
|
|
link->SetAttr(kNameSpaceID_None, nsGkAtoms::href, aStylesheet, true);
|
|
|
|
|
|
|
|
Element* head = GetHeadElement();
|
|
|
|
return head->AppendChildTo(link, false);
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:04:55 +03:00
|
|
|
nsresult
|
|
|
|
MediaDocument::LinkScript(const nsAString& aScript)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2015-10-04 14:04:55 +03:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::script, nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> script = NS_NewHTMLScriptElement(nodeInfo.forget());
|
2015-10-04 14:04:55 +03:00
|
|
|
NS_ENSURE_TRUE(script, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
script->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
NS_LITERAL_STRING("text/javascript;version=1.8"), true);
|
|
|
|
|
|
|
|
script->SetAttr(kNameSpaceID_None, nsGkAtoms::src, aScript, true);
|
|
|
|
|
|
|
|
Element* head = GetHeadElement();
|
|
|
|
return head->AppendChildTo(script, false);
|
|
|
|
}
|
|
|
|
|
2003-04-13 04:40:26 +04:00
|
|
|
void
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
|
2014-10-30 08:08:00 +03:00
|
|
|
nsIChannel* aChannel,
|
2011-05-26 12:06:31 +04:00
|
|
|
const char* const* aFormatNames,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aWidth, int32_t aHeight,
|
2011-05-26 12:06:31 +04:00
|
|
|
const nsAString& aStatus)
|
2003-04-13 04:40:26 +04:00
|
|
|
{
|
|
|
|
nsXPIDLString fileStr;
|
2014-10-30 08:08:00 +03:00
|
|
|
GetFileName(fileStr, aChannel);
|
2003-04-13 04:40:26 +04:00
|
|
|
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertASCIItoUTF16 typeStr(aTypeStr);
|
2003-04-13 04:40:26 +04:00
|
|
|
nsXPIDLString title;
|
|
|
|
|
|
|
|
if (mStringBundle) {
|
|
|
|
// if we got a valid size (not all media have a size)
|
|
|
|
if (aWidth != 0 && aHeight != 0) {
|
|
|
|
nsAutoString widthStr;
|
|
|
|
nsAutoString heightStr;
|
|
|
|
widthStr.AppendInt(aWidth);
|
|
|
|
heightStr.AppendInt(aHeight);
|
|
|
|
// If we got a filename, display it
|
|
|
|
if (!fileStr.IsEmpty()) {
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *formatStrings[4] = {fileStr.get(), typeStr.get(),
|
2003-04-13 04:40:26 +04:00
|
|
|
widthStr.get(), heightStr.get()};
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertASCIItoUTF16 fmtName(aFormatNames[eWithDimAndFile]);
|
2003-04-22 02:45:28 +04:00
|
|
|
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 4,
|
2003-04-13 04:40:26 +04:00
|
|
|
getter_Copies(title));
|
|
|
|
}
|
|
|
|
else {
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *formatStrings[3] = {typeStr.get(), widthStr.get(),
|
2003-04-13 04:40:26 +04:00
|
|
|
heightStr.get()};
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertASCIItoUTF16 fmtName(aFormatNames[eWithDim]);
|
2003-04-22 02:45:28 +04:00
|
|
|
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 3,
|
2003-04-13 04:40:26 +04:00
|
|
|
getter_Copies(title));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If we got a filename, display it
|
|
|
|
if (!fileStr.IsEmpty()) {
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *formatStrings[2] = {fileStr.get(), typeStr.get()};
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertASCIItoUTF16 fmtName(aFormatNames[eWithFile]);
|
2003-04-22 02:45:28 +04:00
|
|
|
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 2,
|
2003-04-13 04:40:26 +04:00
|
|
|
getter_Copies(title));
|
2003-04-22 02:45:28 +04:00
|
|
|
}
|
2003-04-13 04:40:26 +04:00
|
|
|
else {
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *formatStrings[1] = {typeStr.get()};
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertASCIItoUTF16 fmtName(aFormatNames[eWithNoInfo]);
|
2003-04-22 02:45:28 +04:00
|
|
|
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 1,
|
2003-04-13 04:40:26 +04:00
|
|
|
getter_Copies(title));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set it on the document
|
2003-04-22 02:45:28 +04:00
|
|
|
if (aStatus.IsEmpty()) {
|
|
|
|
SetTitle(title);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsXPIDLString titleWithStatus;
|
|
|
|
const nsPromiseFlatString& status = PromiseFlatString(aStatus);
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *formatStrings[2] = {title.get(), status.get()};
|
2003-04-22 02:45:28 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(fmtName, "TitleWithStatus");
|
|
|
|
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 2,
|
|
|
|
getter_Copies(titleWithStatus));
|
|
|
|
SetTitle(titleWithStatus);
|
|
|
|
}
|
2003-04-13 04:40:26 +04:00
|
|
|
}
|
2011-05-26 12:06:31 +04:00
|
|
|
|
2011-12-15 19:10:36 +04:00
|
|
|
void
|
|
|
|
MediaDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject)
|
|
|
|
{
|
|
|
|
nsHTMLDocument::SetScriptGlobalObject(aGlobalObject);
|
|
|
|
if (!mDocumentElementInserted && aGlobalObject) {
|
|
|
|
mDocumentElementInserted = true;
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new nsDocElementCreatedNotificationRunner(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|