2003-03-22 05:22:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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 "nsIPresShell.h"
|
|
|
|
#include "nsIObjectFrame.h"
|
2011-05-18 05:48:34 +04:00
|
|
|
#include "nsNPAPIPluginInstance.h"
|
2013-01-13 01:53:01 +04:00
|
|
|
#include "nsIDocumentInlines.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"
|
|
|
|
#include "nsIPropertyBag2.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.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
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2013-07-12 01:26:54 +04:00
|
|
|
class PluginDocument MOZ_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
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
virtual nsresult StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aReset = true,
|
2015-01-06 23:13:36 +03:00
|
|
|
nsIContentSink* aSink = nullptr) MOZ_OVERRIDE;
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2015-01-06 23:13:36 +03:00
|
|
|
virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject) MOZ_OVERRIDE;
|
|
|
|
virtual bool CanSavePresentation(nsIRequest *aNewRequest) MOZ_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
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
void StartLayout() { MediaDocument::StartLayout(); }
|
2009-01-09 20:54:23 +03:00
|
|
|
|
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:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~PluginDocument();
|
|
|
|
|
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;
|
2011-05-26 12:06:31 +04:00
|
|
|
nsRefPtr<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
|
2005-09-21 23:14:30 +04:00
|
|
|
{
|
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)
|
2011-05-26 12:06:31 +04:00
|
|
|
{}
|
2009-01-09 20:54:23 +03:00
|
|
|
NS_IMETHOD OnStartRequest(nsIRequest* request, nsISupports *ctxt);
|
|
|
|
private:
|
2011-05-26 12:06:31 +04:00
|
|
|
nsRefPtr<PluginDocument> mPluginDoc;
|
2005-09-21 23:14:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-05-26 12:06:31 +04:00
|
|
|
PluginStreamListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
|
2005-09-21 23:14:30 +04:00
|
|
|
{
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("PluginStreamListener", "OnStartRequest",
|
|
|
|
js::ProfileEntry::Category::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) {
|
|
|
|
NS_NOTREACHED("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)) {
|
2012-12-11 04:35:05 +04:00
|
|
|
NS_NOTREACHED("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.
|
|
|
|
return MediaDocumentStreamListener::OnStartRequest(request, ctxt);
|
2005-09-21 23:14:30 +04:00
|
|
|
}
|
|
|
|
|
2003-03-26 10:41:30 +03:00
|
|
|
// NOTE! nsDocument::operator new() zeroes out all members, so don't
|
|
|
|
// bother initializing members to 0.
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
PluginDocument::PluginDocument()
|
2012-12-11 04:35:05 +04:00
|
|
|
{}
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
PluginDocument::~PluginDocument()
|
2012-12-11 04:35:05 +04:00
|
|
|
{}
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2008-12-03 13:30:26 +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
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(PluginDocument, MediaDocument)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(PluginDocument, MediaDocument)
|
2010-12-02 19:19:37 +03:00
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(PluginDocument)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(PluginDocument, nsIPluginDocument)
|
2011-05-26 12:06:31 +04:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(MediaDocument)
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2003-10-22 10:09:48 +04:00
|
|
|
void
|
2011-05-26 12:06:31 +04:00
|
|
|
PluginDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
|
2003-04-04 04:26:33 +04:00
|
|
|
{
|
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) {
|
|
|
|
if (!mPluginContent) {
|
|
|
|
// Create synthetic document
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
|
|
|
CreateSyntheticPluginDocument();
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create synthetic document");
|
|
|
|
}
|
2012-07-27 17:35:09 +04:00
|
|
|
BecomeInteractive();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-26 12:06:31 +04:00
|
|
|
PluginDocument::CanSavePresentation(nsIRequest *aNewRequest)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult
|
2011-05-26 12:06:31 +04:00
|
|
|
PluginDocument::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
|
|
|
{
|
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;
|
2013-12-13 05:50:01 +04:00
|
|
|
dsti->NameEquals(MOZ_UTF16("messagepane"), &isMsgPane);
|
2009-09-26 00:58:47 +04:00
|
|
|
if (isMsgPane) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-26 10:41:30 +03:00
|
|
|
nsresult rv =
|
2011-05-26 12:06:31 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-03-26 10:41:30 +03:00
|
|
|
nsresult
|
2011-05-26 12:06:31 +04:00
|
|
|
PluginDocument::CreateSyntheticPluginDocument()
|
2003-03-22 05:22:03 +03:00
|
|
|
{
|
2012-09-07 08:16:09 +04:00
|
|
|
NS_ASSERTION(!GetShell() || !GetShell()->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
|
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
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
|
2004-02-25 02:55:18 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(zero, "0");
|
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
|
2014-06-20 06:01:40 +04:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-07-30 18:20:58 +04:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::embed, nullptr,
|
2011-06-14 11:56:49 +04:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::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
|
2006-12-26 20:47:52 +03:00
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::name,
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_LITERAL_STRING("plugin"), false);
|
2003-03-22 05:22:03 +03:00
|
|
|
|
2004-02-25 02:55:18 +03:00
|
|
|
// fill viewport and auto-resize
|
|
|
|
NS_NAMED_LITERAL_STRING(percent100, "100%");
|
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) {
|
2012-02-01 01:55:54 +04:00
|
|
|
nsRefPtr<nsNPAPIPluginInstance> pi;
|
2011-05-18 05:48:34 +04:00
|
|
|
objectFrame->GetPluginInstance(getter_AddRefs(pi));
|
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;
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:06:31 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2003-03-22 05:22:03 +03:00
|
|
|
nsresult
|
|
|
|
NS_NewPluginDocument(nsIDocument** aResult)
|
|
|
|
{
|
2011-05-26 12:06:31 +04:00
|
|
|
mozilla::dom::PluginDocument* 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
|
|
|
}
|