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 "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"
|
2019-03-29 18:12:47 +03:00
|
|
|
#include "mozilla/PresShell.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"
|
2018-06-28 21:07:27 +03:00
|
|
|
#include "nsProxyRelease.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)
|
2018-06-28 21:07:27 +03:00
|
|
|
: mDocument(aDocument) {}
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocumentStreamListener::~MediaDocumentStreamListener() {
|
2018-06-28 21:07:27 +03:00
|
|
|
if (mDocument && !NS_IsMainThread()) {
|
|
|
|
nsCOMPtr<nsIEventTarget> mainTarget(do_GetMainThread());
|
|
|
|
NS_ProxyRelease("MediaDocumentStreamListener::mDocument", mainTarget,
|
|
|
|
mDocument.forget());
|
|
|
|
}
|
2003-03-22 05:22:03 +03:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(MediaDocumentStreamListener, nsIRequestObserver,
|
2018-06-28 21:07:27 +03:00
|
|
|
nsIStreamListener, nsIThreadRetargetableStreamListener)
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
void MediaDocumentStreamListener::SetStreamListener(
|
|
|
|
nsIStreamListener* aListener) {
|
2003-03-22 05:22:03 +03:00
|
|
|
mNextStream = aListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-02-28 02:41:04 +03:00
|
|
|
MediaDocumentStreamListener::OnStartRequest(nsIRequest* request) {
|
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) {
|
2019-02-28 02:41:04 +03:00
|
|
|
return mNextStream->OnStartRequest(request);
|
2003-03-22 05:22:03 +03:00
|
|
|
}
|
|
|
|
|
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,
|
2019-02-28 02:41:31 +03:00
|
|
|
nsresult status) {
|
2003-04-04 04:26:33 +04:00
|
|
|
nsresult rv = NS_OK;
|
2003-03-22 05:22:03 +03:00
|
|
|
if (mNextStream) {
|
2019-02-28 02:41:31 +03:00
|
|
|
rv = mNextStream->OnStopRequest(request, 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,
|
|
|
|
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) {
|
2019-02-28 02:42:27 +03:00
|
|
|
return mNextStream->OnDataAvailable(request, inStr, sourceOffset, count);
|
2003-03-22 05:22:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-06-28 21:07:27 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MediaDocumentStreamListener::CheckListenerChain() {
|
|
|
|
nsCOMPtr<nsIThreadRetargetableStreamListener> retargetable =
|
|
|
|
do_QueryInterface(mNextStream);
|
|
|
|
if (retargetable) {
|
|
|
|
return retargetable->CheckListenerChain();
|
|
|
|
}
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03: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()
|
2018-05-23 18:06:34 +03:00
|
|
|
: nsHTMLDocument(), mDidInitialDocumentSetup(false) {}
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocument::~MediaDocument() {}
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
nsresult 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;
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
nsresult MediaDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
bool aReset, nsIContentSink* aSink) {
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult rv = Document::StartDocumentLoad(
|
2003-03-22 05:22:03 +03:00
|
|
|
aCommand, aChannel, aLoadGroup, aContainer, aDocListener, aReset, aSink);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
// We try to set the charset of the current document to that of the
|
|
|
|
// 'genuine' (as opposed to an intervening 'chrome') parent document
|
2003-07-26 09:17:26 +04:00
|
|
|
// that may be in a different window/tab. Even if we fail here,
|
2017-07-06 15:00:35 +03:00
|
|
|
// we just return NS_OK because another attempt is made in
|
|
|
|
// |UpdateTitleAndCharset| and the worst thing possible is a mangled
|
2003-07-26 09:17:26 +04:00
|
|
|
// filename in the titlebar and the file picker.
|
|
|
|
|
2013-10-16 05:46:10 +04:00
|
|
|
// Note that we
|
2017-07-06 15:00:35 +03: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.
|
|
|
|
|
2003-07-26 09:17:26 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
|
2003-07-26 09:54:42 +04:00
|
|
|
|
|
|
|
// not being able to set the charset is not critical.
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_OK);
|
2003-07-26 09:17:26 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
const Encoding* encoding;
|
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
|
2017-06-18 14:37:50 +03:00
|
|
|
docShell->GetParentCharset(encoding, &source, getter_AddRefs(principal));
|
2003-07-26 09:17:26 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
if (encoding && encoding != UTF_8_ENCODING &&
|
2013-10-16 05:46:10 +04:00
|
|
|
NodePrincipal()->Equals(principal)) {
|
|
|
|
SetDocumentCharacterSetSource(source);
|
2017-06-18 14:37:50 +03:00
|
|
|
SetDocumentCharacterSet(WrapNotNull(encoding));
|
2003-07-26 09:17:26 +04:00
|
|
|
}
|
|
|
|
|
2003-03-22 05:22:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-23 18:06:34 +03:00
|
|
|
void MediaDocument::InitialSetupDone() {
|
2019-01-02 16:05:23 +03:00
|
|
|
MOZ_ASSERT(GetReadyStateEnum() == Document::READYSTATE_LOADING,
|
2018-05-23 18:06:34 +03:00
|
|
|
"Bad readyState: we should still be doing our initial load");
|
|
|
|
mDidInitialDocumentSetup = true;
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new nsDocElementCreatedNotificationRunner(this));
|
2019-01-02 16:05:23 +03:00
|
|
|
SetReadyStateInternal(Document::READYSTATE_INTERACTIVE);
|
2012-07-27 17:35:09 +04:00
|
|
|
}
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
nsresult MediaDocument::CreateSyntheticDocument() {
|
2018-05-23 18:06:34 +03:00
|
|
|
MOZ_ASSERT(!InitialSetupHasBeenDone());
|
|
|
|
|
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, kNameSpaceID_XHTML, nsINode::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, kNameSpaceID_XHTML, nsINode::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, kNameSpaceID_XHTML, nsINode::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"), true);
|
|
|
|
|
|
|
|
metaContent->SetAttr(
|
|
|
|
kNameSpaceID_None, nsGkAtoms::content,
|
|
|
|
NS_LITERAL_STRING("width=device-width; height=device-height;"), true);
|
2011-10-17 18:59:28 +04:00
|
|
|
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, kNameSpaceID_XHTML, nsINode::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;
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
nsresult MediaDocument::StartLayout() {
|
2011-10-17 18:59:28 +04:00
|
|
|
mMayStartLayout = true;
|
2019-03-29 18:12:47 +03:00
|
|
|
RefPtr<PresShell> presShell = GetPresShell();
|
2010-01-07 13:36:11 +03:00
|
|
|
// Don't mess with the presshell if someone has already handled
|
|
|
|
// its initial reflow.
|
2019-03-29 18:12:47 +03:00
|
|
|
if (presShell && !presShell->DidInitialize()) {
|
|
|
|
nsresult rv = presShell->Initialize();
|
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
|
|
|
|
2014-10-30 08:08:00 +03:00
|
|
|
void 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
|
2017-06-15 10:35:22 +03:00
|
|
|
// the document viewer instead of a bogus value ("windows-1252" set in
|
2019-01-02 16:05:23 +03:00
|
|
|
// |Document|'s ctor), the priority is given to the current charset.
|
2017-07-06 15:00:35 +03:00
|
|
|
// This is necessary to deal with a media document being opened in a new
|
2017-08-02 14:43:30 +03:00
|
|
|
// window or a new tab.
|
2017-07-06 15:00:35 +03:00
|
|
|
if (mCharacterSetSource != kCharsetUninitialized) {
|
2017-06-18 14:37:50 +03:00
|
|
|
mCharacterSet->Name(docCharset);
|
2017-07-06 15:00:35 +03:00
|
|
|
} else {
|
2017-08-02 14:43:30 +03:00
|
|
|
// resort to UTF-8
|
|
|
|
SetDocumentCharacterSet(UTF_8_ENCODING);
|
2009-01-16 12:07:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
2017-07-06 15:00:35 +03:00
|
|
|
nsCOMPtr<nsITextToSubURI> textToSubURI =
|
2009-01-16 12:07:26 +03:00
|
|
|
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, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE);
|
2011-11-11 03:08:07 +04:00
|
|
|
|
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);
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
link->SetAttr(kNameSpaceID_None, nsGkAtoms::rel,
|
2011-11-11 03:08:07 +04:00
|
|
|
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, nsINode::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,
|
2017-02-26 15:41:01 +03:00
|
|
|
NS_LITERAL_STRING("text/javascript"), true);
|
2015-10-04 14:04:55 +03:00
|
|
|
|
|
|
|
script->SetAttr(kNameSpaceID_None, nsGkAtoms::src, aScript, true);
|
|
|
|
|
|
|
|
Element* head = GetHeadElement();
|
|
|
|
return head->AppendChildTo(script, false);
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
void 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) {
|
2017-08-08 09:07:55 +03:00
|
|
|
nsAutoString 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);
|
2017-08-04 07:40:52 +03:00
|
|
|
nsAutoString title;
|
2003-04-13 04:40:26 +04:00
|
|
|
|
|
|
|
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()) {
|
2019-06-11 18:51:51 +03:00
|
|
|
AutoTArray<nsString, 4> formatStrings = {fileStr, typeStr, widthStr,
|
|
|
|
heightStr};
|
2017-07-12 08:13:37 +03:00
|
|
|
mStringBundle->FormatStringFromName(aFormatNames[eWithDimAndFile],
|
2019-06-11 18:51:51 +03:00
|
|
|
formatStrings, title);
|
2003-04-13 04:40:26 +04:00
|
|
|
} else {
|
2019-06-11 18:51:51 +03:00
|
|
|
AutoTArray<nsString, 3> formatStrings = {typeStr, widthStr, heightStr};
|
2017-07-12 08:13:37 +03:00
|
|
|
mStringBundle->FormatStringFromName(aFormatNames[eWithDim],
|
2019-06-11 18:51:51 +03:00
|
|
|
formatStrings, title);
|
2003-04-13 04:40:26 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If we got a filename, display it
|
|
|
|
if (!fileStr.IsEmpty()) {
|
2019-06-11 18:51:51 +03:00
|
|
|
AutoTArray<nsString, 2> formatStrings = {fileStr, typeStr};
|
2017-07-12 08:13:37 +03:00
|
|
|
mStringBundle->FormatStringFromName(aFormatNames[eWithFile],
|
2019-06-11 18:51:51 +03:00
|
|
|
formatStrings, title);
|
2003-04-13 04:40:26 +04:00
|
|
|
} else {
|
2019-06-11 18:51:51 +03:00
|
|
|
AutoTArray<nsString, 1> formatStrings = {typeStr};
|
2017-07-12 08:13:37 +03:00
|
|
|
mStringBundle->FormatStringFromName(aFormatNames[eWithNoInfo],
|
2019-06-11 18:51:51 +03:00
|
|
|
formatStrings, title);
|
2003-04-13 04:40:26 +04:00
|
|
|
}
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
}
|
2003-04-13 04:40:26 +04:00
|
|
|
|
|
|
|
// set it on the document
|
2003-04-22 02:45:28 +04:00
|
|
|
if (aStatus.IsEmpty()) {
|
2018-01-31 23:18:10 +03:00
|
|
|
IgnoredErrorResult ignored;
|
|
|
|
SetTitle(title, ignored);
|
2003-04-22 02:45:28 +04:00
|
|
|
} else {
|
2017-08-04 07:40:52 +03:00
|
|
|
nsAutoString titleWithStatus;
|
2019-06-11 18:51:51 +03:00
|
|
|
AutoTArray<nsString, 2> formatStrings;
|
|
|
|
formatStrings.AppendElement(title);
|
|
|
|
formatStrings.AppendElement(aStatus);
|
|
|
|
mStringBundle->FormatStringFromName("TitleWithStatus", formatStrings,
|
2017-08-04 07:40:52 +03:00
|
|
|
titleWithStatus);
|
2019-06-11 18:51:51 +03:00
|
|
|
SetTitle(titleWithStatus, IgnoreErrors());
|
2003-04-22 02:45:28 +04:00
|
|
|
}
|
2003-04-13 04:40:26 +04:00
|
|
|
}
|
2011-05-26 12:06:31 +04:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|