2003-03-22 02:22:03 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2003-03-22 02:22:03 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2003-03-22 02:22:03 +00:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2003-03-22 02:22:03 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2003-03-22 02:22:03 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2003-03-22 02:22:03 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsMediaDocument.h"
|
|
|
|
#include "nsIPluginDocument.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIObjectFrame.h"
|
|
|
|
#include "nsIPluginInstance.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
2004-06-25 12:26:02 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
2003-03-22 02:22:03 +00:00
|
|
|
|
|
|
|
class nsPluginDocument : public nsMediaDocument,
|
|
|
|
public nsIPluginDocument
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsPluginDocument();
|
|
|
|
virtual ~nsPluginDocument();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIPLUGINDOCUMENT
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
virtual nsresult StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
PRBool aReset = PR_TRUE,
|
|
|
|
nsIContentSink* aSink = nsnull);
|
2003-03-22 02:22:03 +00:00
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
|
2005-05-04 20:22:32 +00:00
|
|
|
virtual PRBool CanSavePresentation(nsIRequest *aNewRequest);
|
2003-04-04 00:26:33 +00:00
|
|
|
|
2003-03-22 02:22:03 +00:00
|
|
|
protected:
|
2003-04-13 00:40:26 +00:00
|
|
|
nsresult CreateSyntheticPluginDocument();
|
2003-03-22 02:22:03 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsCOMPtr<nsIContent> mPluginContent;
|
2003-03-22 02:22:03 +00:00
|
|
|
nsRefPtr<nsMediaDocumentStreamListener> mStreamListener;
|
2003-04-13 00:40:26 +00:00
|
|
|
nsCString mMimeType;
|
2003-03-22 02:22:03 +00:00
|
|
|
};
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
// NOTE! nsDocument::operator new() zeroes out all members, so don't
|
|
|
|
// bother initializing members to 0.
|
|
|
|
|
2003-03-22 02:22:03 +00:00
|
|
|
nsPluginDocument::nsPluginDocument()
|
|
|
|
{
|
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2003-03-22 02:22:03 +00:00
|
|
|
nsPluginDocument::~nsPluginDocument()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsPluginDocument, nsMediaDocument)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsPluginDocument, nsMediaDocument)
|
2003-03-22 02:22:03 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsPluginDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIPluginDocument)
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsMediaDocument)
|
2003-03-22 02:22:03 +00:00
|
|
|
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
void
|
|
|
|
nsPluginDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
|
2003-04-04 00:26:33 +00:00
|
|
|
{
|
|
|
|
if (!aScriptGlobalObject) {
|
|
|
|
mStreamListener = nsnull;
|
|
|
|
}
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsMediaDocument::SetScriptGlobalObject(aScriptGlobalObject);
|
2003-04-04 00:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-04 20:22:32 +00:00
|
|
|
PRBool
|
|
|
|
nsPluginDocument::CanSavePresentation(nsIRequest *aNewRequest)
|
|
|
|
{
|
|
|
|
// Full-page plugins cannot be cached, currently, because we don't have
|
|
|
|
// the stream listener data to feed to the plugin instance.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2003-03-22 02:22:03 +00:00
|
|
|
nsPluginDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
PRBool aReset,
|
|
|
|
nsIContentSink* aSink)
|
|
|
|
{
|
2003-03-26 07:41:30 +00:00
|
|
|
nsresult rv =
|
|
|
|
nsMediaDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup,
|
|
|
|
aContainer, aDocListener, aReset,
|
|
|
|
aSink);
|
2003-03-22 02:22:03 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-04-13 00:40:26 +00:00
|
|
|
rv = aChannel->GetContentType(mMimeType);
|
2003-03-22 02:22:03 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create synthetic document
|
2003-04-13 00:40:26 +00:00
|
|
|
rv = CreateSyntheticPluginDocument();
|
2003-03-22 02:22:03 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mStreamListener = new nsMediaDocumentStreamListener(this);
|
|
|
|
if (!mStreamListener)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ASSERTION(aDocListener, "null aDocListener");
|
|
|
|
NS_ADDREF(*aDocListener = mStreamListener);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
nsresult
|
2003-04-13 00:40:26 +00:00
|
|
|
nsPluginDocument::CreateSyntheticPluginDocument()
|
2003-03-22 02:22:03 +00:00
|
|
|
{
|
|
|
|
// do not allow message panes to host full-page plugins
|
|
|
|
// returning an error causes helper apps to take over
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dsti (do_QueryReferent(mDocumentContainer));
|
|
|
|
if (dsti) {
|
|
|
|
PRBool isMsgPane = PR_FALSE;
|
|
|
|
dsti->NameEquals(NS_LITERAL_STRING("messagepane").get(), &isMsgPane);
|
|
|
|
if (isMsgPane)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make our generic document
|
|
|
|
nsresult rv = nsMediaDocument::CreateSyntheticDocument();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// then attach our plugin
|
|
|
|
|
2004-02-24 23:55:18 +00:00
|
|
|
nsCOMPtr<nsIContent> body = do_QueryInterface(mBodyContent);
|
2003-03-22 02:22:03 +00:00
|
|
|
if (!body) {
|
|
|
|
NS_WARNING("no body on plugin document!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove margins from body
|
2004-02-24 23:55:18 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(zero, "0");
|
|
|
|
body->SetAttr(kNameSpaceID_None, nsHTMLAtoms::marginwidth, zero, PR_FALSE);
|
|
|
|
body->SetAttr(kNameSpaceID_None, nsHTMLAtoms::marginheight, zero, PR_FALSE);
|
2003-03-22 02:22:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
// make plugin content
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::embed, nsnull,
|
|
|
|
kNameSpaceID_None,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2003-03-22 02:22:03 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-06-06 02:38:32 +00:00
|
|
|
mPluginContent = NS_NewHTMLSharedElement(nodeInfo);
|
|
|
|
if (!mPluginContent) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2003-03-22 02:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make it a named element
|
2004-02-24 23:55:18 +00:00
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::name,
|
|
|
|
NS_LITERAL_STRING("plugin"), PR_FALSE);
|
2003-03-22 02:22:03 +00:00
|
|
|
|
2004-02-24 23:55:18 +00:00
|
|
|
// fill viewport and auto-resize
|
|
|
|
NS_NAMED_LITERAL_STRING(percent100, "100%");
|
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::width, percent100,
|
|
|
|
PR_FALSE);
|
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::height, percent100,
|
|
|
|
PR_FALSE);
|
2003-03-22 02:22:03 +00:00
|
|
|
|
|
|
|
// set URL
|
|
|
|
nsCAutoString src;
|
2004-01-09 23:54:21 +00:00
|
|
|
mDocumentURI->GetSpec(src);
|
2004-02-24 23:55:18 +00:00
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::src,
|
|
|
|
NS_ConvertUTF8toUTF16(src), PR_FALSE);
|
2003-03-22 02:22:03 +00:00
|
|
|
|
|
|
|
// set mime type
|
2004-02-24 23:55:18 +00:00
|
|
|
mPluginContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::type,
|
|
|
|
NS_ConvertUTF8toUTF16(mMimeType), PR_FALSE);
|
2003-03-22 02:22:03 +00:00
|
|
|
|
2005-04-18 22:58:35 +00:00
|
|
|
body->AppendChildTo(mPluginContent, PR_FALSE);
|
2003-03-22 02:22:03 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginDocument::SetStreamListener(nsIStreamListener *aListener)
|
|
|
|
{
|
|
|
|
if (mStreamListener)
|
|
|
|
mStreamListener->SetStreamListener(aListener);
|
|
|
|
|
2003-04-13 00:40:26 +00:00
|
|
|
nsMediaDocument::UpdateTitleAndCharset(mMimeType);
|
2003-03-22 02:22:03 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginDocument::Print()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mPluginContent, NS_ERROR_FAILURE);
|
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIPresShell *shell = GetShellAt(0);
|
|
|
|
if (!shell) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-03-22 02:22:03 +00:00
|
|
|
|
2005-08-22 22:24:29 +00:00
|
|
|
nsIFrame* frame = shell->GetPrimaryFrameFor(mPluginContent);
|
|
|
|
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
|
2003-03-22 02:22:03 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIObjectFrame* objectFrame = nsnull;
|
|
|
|
CallQueryInterface(frame, &objectFrame);
|
2003-03-22 02:22:03 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
if (objectFrame) {
|
|
|
|
nsCOMPtr<nsIPluginInstance> pi;
|
|
|
|
objectFrame->GetPluginInstance(*getter_AddRefs(pi));
|
2003-03-22 02:22:03 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
if (pi) {
|
|
|
|
nsPluginPrint npprint;
|
|
|
|
npprint.mode = nsPluginMode_Full;
|
|
|
|
npprint.print.fullPrint.pluginPrinted = PR_FALSE;
|
|
|
|
npprint.print.fullPrint.printOne = PR_FALSE;
|
|
|
|
npprint.print.fullPrint.platformPrint = nsnull;
|
2003-03-22 02:22:03 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
pi->Print(&npprint);
|
2003-03-22 02:22:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewPluginDocument(nsIDocument** aResult)
|
|
|
|
{
|
|
|
|
nsPluginDocument* doc = new nsPluginDocument();
|
|
|
|
if (!doc) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2005-04-28 17:16:19 +00:00
|
|
|
NS_ADDREF(doc);
|
2003-03-22 02:22:03 +00:00
|
|
|
nsresult rv = doc->Init();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2005-04-28 17:16:19 +00:00
|
|
|
NS_RELEASE(doc);
|
2003-03-22 02:22:03 +00:00
|
|
|
}
|
|
|
|
|
2005-04-28 17:16:19 +00:00
|
|
|
*aResult = doc;
|
2003-03-22 02:22:03 +00:00
|
|
|
|
2005-04-28 17:16:19 +00:00
|
|
|
return rv;
|
2003-03-22 02:22:03 +00:00
|
|
|
}
|