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"
|
2003-03-22 05:22:03 +03:00
|
|
|
#include "nsIPluginDocument.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2003-03-22 05:22:03 +03:00
|
|
|
#include "nsIObjectFrame.h"
|
2011-05-18 05:48:34 +04:00
|
|
|
#include "nsNPAPIPluginInstance.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "DocumentInlines.h"
|
2003-03-22 05:22:03 +03:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
2006-05-23 19:33:15 +04:00
|
|
|
#include "nsContentCreatorFunctions.h"
|
2007-08-21 02:55:06 +04:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2019-03-29 18:12:47 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2012-02-01 01:55:54 +04:00
|
|
|
#include "nsObjectLoadingContent.h"
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2010-04-30 17:12:05 +04:00
|
|
|
|
2020-01-18 16:48:34 +03:00
|
|
|
namespace mozilla::dom {
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class PluginDocument final : public MediaDocument, public nsIPluginDocument {
|
2003-03-22 05:22:03 +03:00
|
|
|
public:
|
2011-05-26 12:06:31 +04:00
|
|
|
PluginDocument();
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2007-08-21 02:55:06 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2003-03-22 05:22:03 +03:00
|
|
|
NS_DECL_NSIPLUGINDOCUMENT
|
|
|
|
|
2018-07-19 14:36:20 +03:00
|
|
|
enum MediaDocumentKind MediaDocumentKind() const override {
|
|
|
|
return MediaDocumentKind::Plugin;
|
|
|
|
}
|
|
|
|
|
2016-11-15 14:09:07 +03:00
|
|
|
nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup, nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
bool aReset = true,
|
|
|
|
nsIContentSink* aSink = nullptr) override;
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2016-11-15 14:09:07 +03:00
|
|
|
void SetScriptGlobalObject(
|
|
|
|
nsIScriptGlobalObject* aScriptGlobalObject) override;
|
2019-05-14 19:21:09 +03:00
|
|
|
bool CanSavePresentation(nsIRequest* aNewRequest,
|
|
|
|
uint16_t& aBFCacheStatus) override;
|
2003-04-04 04:26:33 +04:00
|
|
|
|
2005-09-21 23:14:30 +04:00
|
|
|
const nsCString& GetType() const { return mMimeType; }
|
2013-12-03 18:40:10 +04:00
|
|
|
Element* GetPluginContent() { return mPluginContent; }
|
2005-09-21 23:14:30 +04:00
|
|
|
|
2017-12-07 08:10:51 +03:00
|
|
|
virtual void Destroy() override {
|
|
|
|
if (mStreamListener) {
|
|
|
|
mStreamListener->DropDocumentRef();
|
|
|
|
}
|
|
|
|
MediaDocument::Destroy();
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PluginDocument, MediaDocument)
|
2003-03-22 05:22:03 +03:00
|
|
|
protected:
|
2016-11-15 14:09:07 +03:00
|
|
|
~PluginDocument() override;
|
2014-07-09 01:23:16 +04:00
|
|
|
|
2003-04-13 04:40:26 +04:00
|
|
|
nsresult CreateSyntheticPluginDocument();
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2013-12-03 18:40:10 +04:00
|
|
|
nsCOMPtr<Element> mPluginContent;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaDocumentStreamListener> mStreamListener;
|
2003-04-13 04:40:26 +04:00
|
|
|
nsCString mMimeType;
|
2003-03-22 05:22:03 +03:00
|
|
|
};
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
class PluginStreamListener : public MediaDocumentStreamListener {
|
2009-01-09 20:54:23 +03:00
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit PluginStreamListener(PluginDocument* aDoc)
|
|
|
|
: MediaDocumentStreamListener(aDoc), mPluginDoc(aDoc) {}
|
2019-02-28 02:41:04 +03:00
|
|
|
NS_IMETHOD OnStartRequest(nsIRequest* request) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-01-09 20:54:23 +03:00
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PluginDocument> mPluginDoc;
|
2005-09-21 23:14:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-02-28 02:41:04 +03:00
|
|
|
PluginStreamListener::OnStartRequest(nsIRequest* request) {
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
AUTO_PROFILER_LABEL("PluginStreamListener::OnStartRequest", NETWORK);
|
2005-09-21 23:14:30 +04:00
|
|
|
|
2007-08-02 21:54:36 +04:00
|
|
|
nsCOMPtr<nsIContent> embed = mPluginDoc->GetPluginContent();
|
2012-12-11 04:35:05 +04:00
|
|
|
nsCOMPtr<nsIObjectLoadingContent> objlc = do_QueryInterface(embed);
|
|
|
|
nsCOMPtr<nsIStreamListener> objListener = do_QueryInterface(objlc);
|
2005-09-21 23:14:30 +04:00
|
|
|
|
2012-12-11 04:35:05 +04:00
|
|
|
if (!objListener) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"PluginStreamListener without appropriate content "
|
|
|
|
"node");
|
2005-09-23 21:35:08 +04:00
|
|
|
return NS_BINDING_ABORTED;
|
|
|
|
}
|
|
|
|
|
2012-12-11 04:35:05 +04:00
|
|
|
SetStreamListener(objListener);
|
2007-08-02 21:54:36 +04:00
|
|
|
|
2012-12-11 04:35:05 +04:00
|
|
|
// Sets up the ObjectLoadingContent tag as if it is waiting for a
|
|
|
|
// channel, so it can proceed with a load normally once it gets OnStartRequest
|
|
|
|
nsresult rv = objlc->InitializeFromChannel(request);
|
2005-09-21 23:14:30 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("InitializeFromChannel failed");
|
2005-09-21 23:14:30 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-12-11 04:35:05 +04:00
|
|
|
// Note that because we're now hooked up to a plugin listener, this will
|
|
|
|
// likely spawn a plugin, which may re-enter.
|
2019-02-28 02:41:04 +03:00
|
|
|
return MediaDocumentStreamListener::OnStartRequest(request);
|
2005-09-21 23:14:30 +04:00
|
|
|
}
|
|
|
|
|
2020-02-20 19:19:15 +03:00
|
|
|
PluginDocument::PluginDocument() = default;
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2016-11-14 12:40:37 +03:00
|
|
|
PluginDocument::~PluginDocument() = default;
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(PluginDocument, MediaDocument,
|
|
|
|
mPluginContent)
|
2008-12-03 13:30:26 +03:00
|
|
|
|
2017-09-01 02:29:22 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(PluginDocument, MediaDocument,
|
|
|
|
nsIPluginDocument)
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
void PluginDocument::SetScriptGlobalObject(
|
|
|
|
nsIScriptGlobalObject* aScriptGlobalObject) {
|
2009-09-26 00:58:47 +04:00
|
|
|
// Set the script global object on the superclass before doing
|
|
|
|
// anything that might require it....
|
2011-05-26 12:06:31 +04:00
|
|
|
MediaDocument::SetScriptGlobalObject(aScriptGlobalObject);
|
2009-09-26 00:58:47 +04:00
|
|
|
|
|
|
|
if (aScriptGlobalObject) {
|
2018-05-23 18:06:34 +03:00
|
|
|
if (!InitialSetupHasBeenDone()) {
|
2009-09-26 00:58:47 +04:00
|
|
|
// Create synthetic document
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
|
|
|
CreateSyntheticPluginDocument();
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create synthetic document");
|
2018-05-23 18:06:34 +03:00
|
|
|
InitialSetupDone();
|
2009-09-26 00:58:47 +04:00
|
|
|
}
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
mStreamListener = nullptr;
|
2003-04-04 04:26:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 19:21:09 +03:00
|
|
|
bool PluginDocument::CanSavePresentation(nsIRequest* aNewRequest,
|
|
|
|
uint16_t& aBFCacheStatus) {
|
2005-05-05 00:22:32 +04:00
|
|
|
// Full-page plugins cannot be cached, currently, because we don't have
|
|
|
|
// the stream listener data to feed to the plugin instance.
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2005-05-05 00:22:32 +04:00
|
|
|
}
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
nsresult PluginDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
bool aReset, nsIContentSink* aSink) {
|
2009-09-26 00:58:47 +04:00
|
|
|
// do not allow message panes to host full-page plugins
|
|
|
|
// returning an error causes helper apps to take over
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dsti(do_QueryInterface(aContainer));
|
|
|
|
if (dsti) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isMsgPane = false;
|
2020-07-01 11:29:29 +03:00
|
|
|
dsti->NameEquals(u"messagepane"_ns, &isMsgPane);
|
2009-09-26 00:58:47 +04:00
|
|
|
if (isMsgPane) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
nsresult rv = MediaDocument::StartDocumentLoad(
|
|
|
|
aCommand, aChannel, aLoadGroup, aContainer, aDocListener, aReset, aSink);
|
2003-03-22 05:22:03 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-04-13 04:40:26 +04:00
|
|
|
rv = aChannel->GetContentType(mMimeType);
|
2003-03-22 05:22:03 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-10-30 08:08:00 +03:00
|
|
|
MediaDocument::UpdateTitleAndCharset(mMimeType, aChannel);
|
2012-12-11 04:35:05 +04:00
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
mStreamListener = new PluginStreamListener(this);
|
2003-03-22 05:22:03 +03:00
|
|
|
NS_ASSERTION(aDocListener, "null aDocListener");
|
|
|
|
NS_ADDREF(*aDocListener = mStreamListener);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
nsresult PluginDocument::CreateSyntheticPluginDocument() {
|
2019-03-29 18:12:47 +03:00
|
|
|
NS_ASSERTION(!GetPresShell() || !GetPresShell()->DidInitialize(),
|
2009-09-26 00:58:47 +04:00
|
|
|
"Creating synthetic plugin document content too late");
|
2003-03-22 05:22:03 +03:00
|
|
|
|
|
|
|
// make our generic document
|
2011-05-26 12:06:31 +04:00
|
|
|
nsresult rv = MediaDocument::CreateSyntheticDocument();
|
2003-03-22 05:22:03 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// then attach our plugin
|
|
|
|
|
2019-08-06 16:43:01 +03:00
|
|
|
RefPtr<Element> body = GetBodyElement();
|
2003-03-22 05:22:03 +03:00
|
|
|
if (!body) {
|
|
|
|
NS_WARNING("no body on plugin document!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove margins from body
|
2020-07-01 11:42:31 +03:00
|
|
|
constexpr auto zero = u"0"_ns;
|
2011-10-17 18:59:28 +04:00
|
|
|
body->SetAttr(kNameSpaceID_None, nsGkAtoms::marginwidth, zero, false);
|
|
|
|
body->SetAttr(kNameSpaceID_None, nsGkAtoms::marginheight, zero, false);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
|
|
|
// make plugin content
|
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::embed, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE);
|
2010-07-23 13:49:57 +04:00
|
|
|
rv = NS_NewHTMLElement(getter_AddRefs(mPluginContent), nodeInfo.forget(),
|
2010-10-25 16:17:38 +04:00
|
|
|
NOT_FROM_PARSER);
|
2006-05-23 19:33:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
|
|
|
// make it a named element
|
2020-07-01 11:29:29 +03:00
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::name, u"plugin"_ns,
|
|
|
|
false);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2004-02-25 02:55:18 +03:00
|
|
|
// fill viewport and auto-resize
|
2020-07-01 11:42:31 +03:00
|
|
|
constexpr auto percent100 = u"100%"_ns;
|
2006-12-26 20:47:52 +03:00
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::width, percent100,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2006-12-26 20:47:52 +03:00
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::height, percent100,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
|
|
|
// set URL
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString src;
|
2004-01-10 02:54:21 +03:00
|
|
|
mDocumentURI->GetSpec(src);
|
2006-12-26 20:47:52 +03:00
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::src,
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ConvertUTF8toUTF16(src), false);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
|
|
|
// set mime type
|
2006-12-26 20:47:52 +03:00
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ConvertUTF8toUTF16(mMimeType), false);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2012-12-11 04:35:05 +04:00
|
|
|
// nsHTML(Shared)ObjectElement does not kick off a load on BindToTree if it is
|
|
|
|
// to a PluginDocument
|
2011-10-17 18:59:28 +04:00
|
|
|
body->AppendChildTo(mPluginContent, false);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-05-26 12:06:31 +04:00
|
|
|
PluginDocument::Print() {
|
2003-03-22 05:22:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPluginContent, NS_ERROR_FAILURE);
|
|
|
|
|
2009-12-25 00:20:05 +03:00
|
|
|
nsIObjectFrame* objectFrame =
|
|
|
|
do_QueryFrame(mPluginContent->GetPrimaryFrame());
|
2003-09-27 08:18:26 +04:00
|
|
|
if (objectFrame) {
|
2018-11-20 04:20:17 +03:00
|
|
|
RefPtr<nsNPAPIPluginInstance> pi = objectFrame->GetPluginInstance();
|
2003-09-27 08:18:26 +04:00
|
|
|
if (pi) {
|
2009-09-17 05:30:26 +04:00
|
|
|
NPPrint npprint;
|
|
|
|
npprint.mode = NP_FULL;
|
2011-10-17 18:59:28 +04:00
|
|
|
npprint.print.fullPrint.pluginPrinted = false;
|
|
|
|
npprint.print.fullPrint.printOne = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
npprint.print.fullPrint.platformPrint = nullptr;
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
pi->Print(&npprint);
|
2003-03-22 05:22:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-01-18 16:48:34 +03:00
|
|
|
} // namespace mozilla::dom
|
2011-05-26 12:06:31 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult NS_NewPluginDocument(mozilla::dom::Document** aResult) {
|
2016-11-14 12:35:58 +03:00
|
|
|
auto* doc = new mozilla::dom::PluginDocument();
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2005-04-28 21:16:19 +04:00
|
|
|
NS_ADDREF(doc);
|
2003-03-22 05:22:03 +03:00
|
|
|
nsresult rv = doc->Init();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2005-04-28 21:16:19 +04:00
|
|
|
NS_RELEASE(doc);
|
2003-03-22 05:22:03 +03:00
|
|
|
}
|
|
|
|
|
2005-04-28 21:16:19 +04:00
|
|
|
*aResult = doc;
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2005-04-28 21:16:19 +04:00
|
|
|
return rv;
|
2003-03-22 05:22:03 +03:00
|
|
|
}
|