2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
#include "MediaDocument.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIPluginDocument.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIObjectFrame.h"
|
2011-05-17 18:48:34 -07:00
|
|
|
#include "nsNPAPIPluginInstance.h"
|
2013-01-12 13:53:01 -08:00
|
|
|
#include "nsIDocumentInlines.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
2007-08-20 15:55:06 -07:00
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsIPropertyBag2.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-01-31 13:55:54 -08:00
|
|
|
#include "nsObjectLoadingContent.h"
|
2013-03-18 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2010-04-30 06:12:05 -07:00
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-11 14:26:54 -07:00
|
|
|
class PluginDocument MOZ_FINAL : public MediaDocument
|
|
|
|
, public nsIPluginDocument
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-05-26 01:06:31 -07:00
|
|
|
PluginDocument();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-20 15:55:06 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIPLUGINDOCUMENT
|
|
|
|
|
|
|
|
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,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContentSink* aSink = nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool CanSavePresentation(nsIRequest *aNewRequest);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const nsCString& GetType() const { return mMimeType; }
|
2013-12-03 06:40:10 -08:00
|
|
|
Element* GetPluginContent() { return mPluginContent; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
void StartLayout() { MediaDocument::StartLayout(); }
|
2009-01-09 09:54:23 -08:00
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PluginDocument, MediaDocument)
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2014-07-08 14:23:16 -07:00
|
|
|
virtual ~PluginDocument();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult CreateSyntheticPluginDocument();
|
|
|
|
|
2013-12-03 06:40:10 -08:00
|
|
|
nsCOMPtr<Element> mPluginContent;
|
2011-05-26 01:06:31 -07:00
|
|
|
nsRefPtr<MediaDocumentStreamListener> mStreamListener;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCString mMimeType;
|
|
|
|
};
|
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
class PluginStreamListener : public MediaDocumentStreamListener
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-09 09:54:23 -08:00
|
|
|
public:
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit PluginStreamListener(PluginDocument* aDoc)
|
|
|
|
: MediaDocumentStreamListener(aDoc)
|
|
|
|
, mPluginDoc(aDoc)
|
2011-05-26 01:06:31 -07:00
|
|
|
{}
|
2009-01-09 09:54:23 -08:00
|
|
|
NS_IMETHOD OnStartRequest(nsIRequest* request, nsISupports *ctxt);
|
|
|
|
private:
|
2011-05-26 01:06:31 -07:00
|
|
|
nsRefPtr<PluginDocument> mPluginDoc;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-05-26 01:06:31 -07:00
|
|
|
PluginStreamListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-23 14:12:29 -07:00
|
|
|
PROFILER_LABEL("PluginStreamListener", "OnStartRequest",
|
|
|
|
js::ProfileEntry::Category::NETWORK);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-02 10:54:36 -07:00
|
|
|
nsCOMPtr<nsIContent> embed = mPluginDoc->GetPluginContent();
|
2012-12-10 16:35:05 -08:00
|
|
|
nsCOMPtr<nsIObjectLoadingContent> objlc = do_QueryInterface(embed);
|
|
|
|
nsCOMPtr<nsIStreamListener> objListener = do_QueryInterface(objlc);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-10 16:35:05 -08:00
|
|
|
if (!objListener) {
|
|
|
|
NS_NOTREACHED("PluginStreamListener without appropriate content node");
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_BINDING_ABORTED;
|
|
|
|
}
|
|
|
|
|
2012-12-10 16:35:05 -08:00
|
|
|
SetStreamListener(objListener);
|
2007-08-02 10:54:36 -07:00
|
|
|
|
2012-12-10 16:35:05 -08: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2012-12-10 16:35:05 -08:00
|
|
|
NS_NOTREACHED("InitializeFromChannel failed");
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-12-10 16:35:05 -08: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE! nsDocument::operator new() zeroes out all members, so don't
|
|
|
|
// bother initializing members to 0.
|
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
PluginDocument::PluginDocument()
|
2012-12-10 16:35:05 -08:00
|
|
|
{}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
PluginDocument::~PluginDocument()
|
2012-12-10 16:35:05 -08:00
|
|
|
{}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-03 02:30:26 -08:00
|
|
|
|
2014-04-25 09:49:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(PluginDocument, MediaDocument,
|
|
|
|
mPluginContent)
|
2008-12-03 02:30:26 -08:00
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(PluginDocument, MediaDocument)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(PluginDocument, MediaDocument)
|
2010-12-02 08:19:37 -08:00
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(PluginDocument)
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(PluginDocument, nsIPluginDocument)
|
2011-05-26 01:06:31 -07:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(MediaDocument)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void
|
2011-05-26 01:06:31 -07:00
|
|
|
PluginDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-09-25 13:58:47 -07:00
|
|
|
// Set the script global object on the superclass before doing
|
|
|
|
// anything that might require it....
|
2011-05-26 01:06:31 -07:00
|
|
|
MediaDocument::SetScriptGlobalObject(aScriptGlobalObject);
|
2009-09-25 13:58:47 -07: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 06:35:09 -07:00
|
|
|
BecomeInteractive();
|
2009-09-25 13:58:47 -07:00
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
mStreamListener = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-05-26 01:06:31 -07:00
|
|
|
PluginDocument::CanSavePresentation(nsIRequest *aNewRequest)
|
2007-03-22 10:30:00 -07: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 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2011-05-26 01:06:31 -07:00
|
|
|
PluginDocument::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)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-09-25 13:58:47 -07: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-28 23:19:26 -07:00
|
|
|
bool isMsgPane = false;
|
2013-12-12 17:50:01 -08:00
|
|
|
dsti->NameEquals(MOZ_UTF16("messagepane"), &isMsgPane);
|
2009-09-25 13:58:47 -07:00
|
|
|
if (isMsgPane) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv =
|
2011-05-26 01:06:31 -07:00
|
|
|
MediaDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer,
|
|
|
|
aDocListener, aReset, aSink);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = aChannel->GetContentType(mMimeType);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-10-29 22:08:00 -07:00
|
|
|
MediaDocument::UpdateTitleAndCharset(mMimeType, aChannel);
|
2012-12-10 16:35:05 -08:00
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
mStreamListener = new PluginStreamListener(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(aDocListener, "null aDocListener");
|
|
|
|
NS_ADDREF(*aDocListener = mStreamListener);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-05-26 01:06:31 -07:00
|
|
|
PluginDocument::CreateSyntheticPluginDocument()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-06 21:16:09 -07:00
|
|
|
NS_ASSERTION(!GetShell() || !GetShell()->DidInitialize(),
|
2009-09-25 13:58:47 -07:00
|
|
|
"Creating synthetic plugin document content too late");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// make our generic document
|
2011-05-26 01:06:31 -07:00
|
|
|
nsresult rv = MediaDocument::CreateSyntheticDocument();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// then attach our plugin
|
|
|
|
|
2010-04-30 06:12:05 -07:00
|
|
|
Element* body = GetBodyElement();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!body) {
|
|
|
|
NS_WARNING("no body on plugin document!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove margins from body
|
|
|
|
NS_NAMED_LITERAL_STRING(zero, "0");
|
2011-10-17 07:59:28 -07:00
|
|
|
body->SetAttr(kNameSpaceID_None, nsGkAtoms::marginwidth, zero, false);
|
|
|
|
body->SetAttr(kNameSpaceID_None, nsGkAtoms::marginheight, zero, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
// make plugin content
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-07-30 07:20:58 -07:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::embed, nullptr,
|
2011-06-14 00:56:49 -07:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2010-07-23 02:49:57 -07:00
|
|
|
rv = NS_NewHTMLElement(getter_AddRefs(mPluginContent), nodeInfo.forget(),
|
2010-10-25 05:17:38 -07:00
|
|
|
NOT_FROM_PARSER);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// make it a named element
|
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::name,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("plugin"), false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// fill viewport and auto-resize
|
|
|
|
NS_NAMED_LITERAL_STRING(percent100, "100%");
|
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::width, percent100,
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2007-03-22 10:30:00 -07:00
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::height, percent100,
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// set URL
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString src;
|
2007-03-22 10:30:00 -07:00
|
|
|
mDocumentURI->GetSpec(src);
|
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::src,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ConvertUTF8toUTF16(src), false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// set mime type
|
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ConvertUTF8toUTF16(mMimeType), false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-10 16:35:05 -08:00
|
|
|
// nsHTML(Shared)ObjectElement does not kick off a load on BindToTree if it is
|
|
|
|
// to a PluginDocument
|
2011-10-17 07:59:28 -07:00
|
|
|
body->AppendChildTo(mPluginContent, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-05-26 01:06:31 -07:00
|
|
|
PluginDocument::Print()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mPluginContent, NS_ERROR_FAILURE);
|
|
|
|
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIObjectFrame* objectFrame =
|
|
|
|
do_QueryFrame(mPluginContent->GetPrimaryFrame());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (objectFrame) {
|
2012-01-31 13:55:54 -08:00
|
|
|
nsRefPtr<nsNPAPIPluginInstance> pi;
|
2011-05-17 18:48:34 -07:00
|
|
|
objectFrame->GetPluginInstance(getter_AddRefs(pi));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (pi) {
|
2009-09-16 18:30:26 -07:00
|
|
|
NPPrint npprint;
|
|
|
|
npprint.mode = NP_FULL;
|
2011-10-17 07:59:28 -07:00
|
|
|
npprint.print.fullPrint.pluginPrinted = false;
|
|
|
|
npprint.print.fullPrint.printOne = false;
|
2012-07-30 07:20:58 -07:00
|
|
|
npprint.print.fullPrint.platformPrint = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
pi->Print(&npprint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-26 01:06:31 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
NS_NewPluginDocument(nsIDocument** aResult)
|
|
|
|
{
|
2011-05-26 01:06:31 -07:00
|
|
|
mozilla::dom::PluginDocument* doc = new mozilla::dom::PluginDocument();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_ADDREF(doc);
|
|
|
|
nsresult rv = doc->Init();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = doc;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|