Creating nsMediaDocument/nsPluginDocument to make full-page

plugins scriptable, bug 90256 r=jkeiser sr=jst
This commit is contained in:
peterlubczynski%netscape.com 2003-03-22 03:20:23 +00:00
parent 9c5c964adf
commit b5850784ea
12 changed files with 257 additions and 211 deletions

View File

@ -486,5 +486,7 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
const nsAString& aQualifiedName,
nsIDOMDocumentType* aDoctype,
nsIURI* aBaseURI);
nsresult
NS_NewPluginDocument(nsIDocument** aInstancePtrResult);
#endif /* nsIDocument_h___ */

View File

@ -159,6 +159,7 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset
#include "nsIDOMHTMLFrameElement.h"
#include "nsIDOMHTMLIFrameElement.h"
#include "nsIDOMHTMLObjectElement.h"
#include "nsIPluginDocument.h"
// Print Preview
#include "nsIPrintPreviewContext.h"
@ -3050,6 +3051,12 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
return rv;
}
// If we are hosting a full-page plugin, tell it to print
// first. It shows its own native print UI.
nsCOMPtr<nsIPluginDocument> pDoc(do_QueryInterface(mDocument));
if (pDoc)
return pDoc->Print();
if (!mPrintEngine) {
mPrintEngine = new nsPrintEngine();
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY);

View File

@ -58,12 +58,15 @@ REQUIRES = xpcom \
unicharutil \
commandhandler \
composer \
plugin \
$(NULL)
CPPSRCS = \
nsHTMLContentSink.cpp \
nsHTMLFragmentContentSink.cpp \
nsHTMLDocument.cpp \
nsMediaDocument.cpp \
nsPluginDocument.cpp \
nsImageDocument.cpp \
nsMarkupDocument.cpp \
nsWyciwygChannel.cpp \

View File

@ -748,6 +748,72 @@ nsHTMLDocument::StartAutodetection(nsIDocShell *aDocShell,
}
}
nsresult
nsHTMLDocument::RetrieveRelevantHeaders(nsIChannel *aChannel)
{
nsAutoString lastModified;
mHttpChannel = do_QueryInterface(aChannel);
if (mHttpChannel) {
nsCAutoString lastModHeader;
nsresult rv = mHttpChannel->GetResponseHeader(NS_LITERAL_CSTRING("last-modified"),
lastModHeader);
if (NS_SUCCEEDED(rv)) {
CopyASCIItoUCS2(lastModHeader, lastModified);
SetLastModified(lastModified);
}
nsCAutoString referrerHeader;
// The misspelled key 'referer' is as per the HTTP spec
rv = mHttpChannel->GetRequestHeader(NS_LITERAL_CSTRING("referer"),
referrerHeader);
if (NS_SUCCEEDED(rv)) {
SetReferrer(NS_ConvertASCIItoUCS2(referrerHeader));
}
}
nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(aChannel);
if (fileChannel) {
PRTime modDate, usecs;
nsCOMPtr<nsIFile> file;
nsresult rv = fileChannel->GetFile(getter_AddRefs(file));
if (NS_SUCCEEDED(rv)) {
// if we failed to get a last modification date, then we don't
// want to necessarily fail to create a document for this
// file. Just don't set the last modified date on it...
rv = file->GetLastModifiedTime(&modDate);
if (NS_SUCCEEDED(rv)) {
PRExplodedTime prtime;
char buf[100];
PRInt64 intermediateValue;
LL_I2L(intermediateValue, PR_USEC_PER_MSEC);
LL_MUL(usecs, modDate, intermediateValue);
PR_ExplodeTime(usecs, PR_LocalTimeParameters, &prtime);
// Use '%#c' for windows, because '%c' is backward-compatible and
// non-y2k with msvc; '%#c' requests that a full year be used in the
// result string. Other OSes just use "%c".
PR_FormatTime(buf, sizeof buf,
#if defined(XP_PC) && !defined(XP_OS2)
"%#c",
#else
"%c",
#endif
&prtime);
lastModified.AssignWithConversion(buf);
SetLastModified(lastModified);
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
@ -780,77 +846,14 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
return rv;
}
nsAutoString lastModified;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
RetrieveRelevantHeaders(aChannel);
if (httpChannel) {
nsCAutoString lastModHeader;
rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("last-modified"),
lastModHeader);
if (NS_SUCCEEDED(rv)) {
CopyASCIItoUCS2(lastModHeader, lastModified);
SetLastModified(lastModified);
}
nsCAutoString referrerHeader;
// The misspelled key 'referer' is as per the HTTP spec
rv = httpChannel->GetRequestHeader(NS_LITERAL_CSTRING("referer"),
referrerHeader);
if (NS_SUCCEEDED(rv)) {
SetReferrer(NS_ConvertASCIItoUCS2(referrerHeader));
}
mHttpChannel = httpChannel;
nsCOMPtr<nsICachingChannel> cachingChan = do_QueryInterface(httpChannel);
if (cachingChan) {
nsCOMPtr<nsISupports> cacheToken;
cachingChan->GetCacheToken(getter_AddRefs(cacheToken));
if (cacheToken)
cacheDescriptor = do_QueryInterface(cacheToken);
}
// Don't propagate the result code beyond here, since it
// could just be that the response header wasn't found.
rv = NS_OK;
}
nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(aChannel);
if (fileChannel) {
PRTime modDate, usecs;
nsCOMPtr<nsIFile> file;
rv = fileChannel->GetFile(getter_AddRefs(file));
if (NS_SUCCEEDED(rv)) {
// if we failed to get a last modification date, then we don't
// want to necessarily fail to create a document for this
// file. Just don't set the last modified date on it...
rv = file->GetLastModifiedTime(&modDate);
if (NS_SUCCEEDED(rv)) {
PRExplodedTime prtime;
char buf[100];
PRInt64 intermediateValue;
LL_I2L(intermediateValue, PR_USEC_PER_MSEC);
LL_MUL(usecs, modDate, intermediateValue);
PR_ExplodeTime(usecs, PR_LocalTimeParameters, &prtime);
// Use '%#c' for windows, because '%c' is backward-compatible and
// non-y2k with msvc; '%#c' requests that a full year be used in the
// result string. Other OSes just use "%c".
PR_FormatTime(buf, sizeof buf,
#if defined(XP_PC) && !defined(XP_OS2)
"%#c",
#else
"%c",
#endif
&prtime);
lastModified.AssignWithConversion(buf);
SetLastModified(lastModified);
}
}
nsCOMPtr<nsICachingChannel> cachingChan = do_QueryInterface(aChannel);
if (cachingChan) {
nsCOMPtr<nsISupports> cacheToken;
cachingChan->GetCacheToken(getter_AddRefs(cacheToken));
if (cacheToken)
cacheDescriptor = do_QueryInterface(cacheToken);
}
if (needsParser) {
@ -946,9 +949,9 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
PRBool isPostPage = PR_FALSE;
//check if current doc is from POST command
if (httpChannel) {
if (mHttpChannel) {
nsCAutoString methodStr;
rv = httpChannel->GetRequestMethod(methodStr);
rv = mHttpChannel->GetRequestMethod(methodStr);
if (NS_SUCCEEDED(rv) && methodStr.Equals(NS_LITERAL_CSTRING("POST")))
isPostPage = PR_TRUE;
}

View File

@ -250,6 +250,8 @@ protected:
nsresult BaseResetToURI(nsIURI* aURI);
nsresult RetrieveRelevantHeaders(nsIChannel *aChannel);
nsCOMPtr<nsIHTMLStyleSheet> mAttrStyleSheet;
nsCOMPtr<nsIHTMLCSSStyleSheet> mStyleAttrStyleSheet;
nsIURI* mBaseURL;

View File

@ -52,22 +52,21 @@
#include "imgIContainer.h"
#include "imgIDecoderObserver.h"
#include "nsIURL.h"
#include "nsIScrollable.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsStyleContext.h"
#include "nsIViewManager.h"
#include "nsIStringBundle.h"
#include "nsIPrefService.h"
#include "nsITextToSubURI.h"
#include "nsAutoPtr.h"
#include "nsMediaDocument.h"
#define NSIMAGEDOCUMENT_PROPERTIES_URI "chrome://communicator/locale/layout/ImageDocument.properties"
#define AUTOMATIC_IMAGE_RESIZING_PREF "browser.enable_automatic_image_resizing"
class nsImageDocument;
class ImageListener: public nsIStreamListener
class ImageListener: public nsMediaDocumentStreamListener
{
public:
ImageListener(nsImageDocument* aDocument);
@ -76,14 +75,9 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
nsImageDocument* mDocument;
nsCOMPtr<nsIStreamListener> mNextStream;
};
class nsImageDocument : public nsHTMLDocument,
class nsImageDocument : public nsMediaDocument,
public nsIImageDocument,
public imgIDecoderObserver,
public nsIDOMEventListener
@ -122,10 +116,10 @@ protected:
nsresult CheckOverflowing();
nsresult StartLayout();
nsresult UpdateTitle();
nsRefPtr<nsMediaDocumentStreamListener> mStreamListener;
nsCOMPtr<nsIStringBundle> mStringBundle;
nsCOMPtr<nsIDOMElement> mImageElement;
nsCOMPtr<imgIRequest> mImageRequest;
@ -140,25 +134,27 @@ protected:
PRPackedBool mImageIsResized;
};
NS_IMPL_ADDREF_INHERITED(ImageListener, nsMediaDocumentStreamListener)
NS_IMPL_RELEASE_INHERITED(ImageListener, nsMediaDocumentStreamListener)
NS_INTERFACE_MAP_BEGIN(ImageListener)
NS_INTERFACE_MAP_END_INHERITING(nsMediaDocumentStreamListener)
ImageListener::ImageListener(nsImageDocument* aDocument)
: nsMediaDocumentStreamListener(aDocument)
{
NS_ADDREF(mDocument = aDocument);
}
ImageListener::~ImageListener()
{
NS_RELEASE(mDocument);
}
NS_IMPL_THREADSAFE_ISUPPORTS2(ImageListener,
nsIRequestObserver,
nsIStreamListener)
};
NS_IMETHODIMP
ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
{
NS_PRECONDITION(!mDocument->mImageRequest, "OnStartRequest called twice!");
nsImageDocument *imgDoc = (nsImageDocument*)mDocument.get();
NS_PRECONDITION(!imgDoc->mImageRequest, "OnStartRequest called twice!");
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (!channel) {
return NS_ERROR_FAILURE;
@ -166,43 +162,22 @@ ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
nsCOMPtr<imgILoader> il(do_GetService("@mozilla.org/image/loader;1"));
nsCOMPtr<nsISupports> docSupports;
CallQueryInterface(mDocument, NS_STATIC_CAST(nsISupports**,
getter_AddRefs(docSupports)));
il->LoadImageWithChannel(channel, mDocument, docSupports,
CallQueryInterface(imgDoc, NS_STATIC_CAST(nsISupports**,
getter_AddRefs(docSupports)));
il->LoadImageWithChannel(channel, imgDoc, docSupports,
getter_AddRefs(mNextStream),
getter_AddRefs(mDocument->mImageRequest));
getter_AddRefs(imgDoc->mImageRequest));
mDocument->StartLayout();
if (mNextStream) {
return mNextStream->OnStartRequest(request, ctxt);
}
return NS_OK;
return nsMediaDocumentStreamListener::OnStartRequest(request, ctxt);
}
NS_IMETHODIMP
ImageListener::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
nsresult status)
{
mDocument->UpdateTitle();
((nsImageDocument*) mDocument.get())->UpdateTitle();
if (mNextStream) {
return mNextStream->OnStopRequest(request, ctxt, status);
}
return NS_OK;
}
NS_IMETHODIMP
ImageListener::OnDataAvailable(nsIRequest* request, nsISupports *ctxt,
nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count)
{
if (mNextStream) {
return mNextStream->OnDataAvailable(request, ctxt, inStr, sourceOffset, count);
}
return NS_OK;
return nsMediaDocumentStreamListener::OnStopRequest(request, ctxt, status);
}
nsImageDocument::nsImageDocument()
@ -268,30 +243,18 @@ nsImageDocument::StartDocumentLoad(const char* aCommand,
PRBool aReset,
nsIContentSink* aSink)
{
nsresult rv = nsDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup,
aContainer, aDocListener, aReset,
aSink);
nsresult rv = nsMediaDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup,
aContainer, aDocListener, aReset,
aSink);
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
// The misspelled key 'referer' is as per the HTTP spec
nsCAutoString referrerHeader;
rv = httpChannel->GetRequestHeader(NS_LITERAL_CSTRING("referer"),
referrerHeader);
if (NS_SUCCEEDED(rv)) {
SetReferrer(NS_ConvertASCIItoUCS2(referrerHeader));
}
}
NS_ASSERTION(aDocListener, "null aDocListener");
*aDocListener = new ImageListener(this);
if (!*aDocListener)
mStreamListener = new ImageListener(this);
if (!mStreamListener)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aDocListener);
NS_ASSERTION(aDocListener, "null aDocListener");
NS_ADDREF(*aDocListener = mStreamListener);
return NS_OK;
}
@ -516,35 +479,16 @@ nsresult
nsImageDocument::CreateSyntheticDocument()
{
// Synthesize an html document that refers to the image
nsresult rv;
nsresult rv = nsMediaDocument::CreateSyntheticDocument();
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIHTMLContent> body = do_QueryInterface(mBodyContent);
if (!body) {
NS_WARNING("no body on image document!");
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsINodeInfo> nodeInfo;
rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::html, nsnull,
kNameSpaceID_None,
*getter_AddRefs(nodeInfo));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIHTMLContent> root;
rv = NS_NewHTMLHtmlElement(getter_AddRefs(root), nodeInfo);
if (NS_FAILED(rv)) {
return rv;
}
root->SetDocument(this, PR_FALSE, PR_TRUE);
SetRootContent(root);
rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::body, nsnull,
kNameSpaceID_None,
*getter_AddRefs(nodeInfo));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIHTMLContent> body;
rv = NS_NewHTMLBodyElement(getter_AddRefs(body), nodeInfo);
if (NS_FAILED(rv)) {
return rv;
}
body->SetDocument(this, PR_FALSE, PR_TRUE);
mBodyContent = do_QueryInterface(body);
rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::img, nsnull,
kNameSpaceID_None,
*getter_AddRefs(nodeInfo));
@ -574,7 +518,6 @@ nsImageDocument::CreateSyntheticDocument()
image->SetAttr(kNameSpaceID_None, nsHTMLAtoms::alt, errorMsg, PR_FALSE);
}
root->AppendChildTo(body, PR_FALSE, PR_FALSE);
body->AppendChildTo(image, PR_FALSE, PR_FALSE);
return NS_OK;
@ -626,42 +569,6 @@ nsImageDocument::CheckOverflowing()
return NS_OK;
}
nsresult
nsImageDocument::StartLayout()
{
// Reset scrolling to default settings for this shell.
// This must happen before the initial reflow, when we create the root frame
nsCOMPtr<nsIScrollable> scrollableContainer(do_QueryReferent(mDocumentContainer));
if (scrollableContainer) {
scrollableContainer->ResetScrollbarPreferences();
}
PRInt32 numberOfShells = GetNumberOfShells();
for (PRInt32 i = 0; i < numberOfShells; i++) {
nsCOMPtr<nsIPresShell> shell;
GetShellAt(i, getter_AddRefs(shell));
if (shell) {
// Make shell an observer for next time.
shell->BeginObservingDocument();
// Initial-reflow this time.
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsRect visibleArea;
context->GetVisibleArea(visibleArea);
shell->InitialReflow(visibleArea.width, visibleArea.height);
// Now trigger a refresh.
nsCOMPtr<nsIViewManager> vm;
shell->GetViewManager(getter_AddRefs(vm));
if (vm) {
vm->EnableRefresh(NS_VMREFRESH_IMMEDIATE);
}
}
}
return NS_OK;
}
nsresult nsImageDocument::UpdateTitle()
{

View File

@ -159,6 +159,7 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset
#include "nsIDOMHTMLFrameElement.h"
#include "nsIDOMHTMLIFrameElement.h"
#include "nsIDOMHTMLObjectElement.h"
#include "nsIPluginDocument.h"
// Print Preview
#include "nsIPrintPreviewContext.h"
@ -3050,6 +3051,12 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
return rv;
}
// If we are hosting a full-page plugin, tell it to print
// first. It shows its own native print UI.
nsCOMPtr<nsIPluginDocument> pDoc(do_QueryInterface(mDocument));
if (pDoc)
return pDoc->Print();
if (!mPrintEngine) {
mPrintEngine = new nsPrintEngine();
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY);

View File

@ -66,6 +66,12 @@
#include "imgILoader.h"
// plugins
#include "nsIPluginManager.h"
#include "nsIPluginHost.h"
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
static NS_DEFINE_CID(kPluginDocumentCID, NS_PLUGINDOCUMENT_CID);
// URL for the "user agent" style sheet
#define UA_CSS_URL "resource:/res/ua.css"
@ -265,6 +271,15 @@ nsContentDLF::CreateInstance(const char* aCommand,
aDocListener, aDocViewer);
}
nsCOMPtr<nsIPluginHost> ph (do_GetService(kPluginManagerCID));
if(ph && NS_SUCCEEDED(ph->IsPluginEnabledForType(aContentType))) {
return CreateDocument(aCommand,
aChannel, aLoadGroup,
aContainer, kPluginDocumentCID,
aDocListener, aDocViewer);
}
// If we get here, then we weren't able to create anything. Sorry!
return NS_ERROR_FAILURE;
}

View File

@ -149,6 +149,10 @@ class nsIDocumentLoaderFactory;
#define NS_HTMLOPTIONELEMENT_CONTRACTID \
"@mozilla.org/content/element/html;1?name=option"
/* 0ddf4df8-4dbb-4133-8b79-9afb966514f5 */
#define NS_PLUGINDOCLOADERFACTORY_CID \
{ 0x0ddf4df8, 0x4dbb, 0x4133, { 0x8b, 0x79, 0x9a, 0xfb, 0x96, 0x65, 0x14, 0xf5 } }
#ifdef MOZ_XUL
#include "nsIXULContentSink.h"
@ -531,6 +535,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsInspectorCSSUtils)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWyciwygProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsContentAreaDragDrop)
MAKE_CTOR(CreateSyncLoadDOMService, nsISyncLoadDOMService, NS_NewSyncLoadDOMService)
MAKE_CTOR(CreatePluginDocument, nsIDocument, NS_NewPluginDocument)
// views are not refcounted, so this is the same as
// NS_GENERIC_FACTORY_CONSTRUCTOR without the NS_ADDREF/NS_RELEASE
@ -1209,7 +1214,17 @@ static const nsModuleComponentInfo gComponents[] = {
{ "Scrolling View", NS_SCROLLING_VIEW_CID, "@mozilla.org/scrolling-view;1",
nsScrollingViewConstructor },
{ "Scroll Port View", NS_SCROLL_PORT_VIEW_CID,
"@mozilla.org/scroll-port-view;1", nsScrollPortViewConstructor }
"@mozilla.org/scroll-port-view;1", nsScrollPortViewConstructor },
{ "Plugin Document Loader Factory",
NS_PLUGINDOCLOADERFACTORY_CID,
"@mozilla.org/content/plugin/document-loader-factory;1",
CreateContentDLF },
{ "Plugin Document",
NS_PLUGINDOCUMENT_CID,
nsnull,
CreatePluginDocument }
};
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsLayoutModule, gComponents, Initialize, Shutdown)

View File

@ -133,6 +133,7 @@
#include "nsIObjectFrame.h"
#include "nsPluginNativeWindow.h"
#include "nsPIPluginHost.h"
#include "nsIPluginDocument.h"
// accessibility support
#ifdef ACCESSIBILITY
@ -1322,7 +1323,32 @@ nsObjectFrame::InstantiatePlugin(nsIPresContext* aPresContext,
}
}
return aPluginHost->InstantiateEmbededPlugin(aMimetype, aURI, mInstanceOwner);
nsCOMPtr<nsIDocument> doc;
nsresult rv = mInstanceOwner->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIPluginDocument> pDoc (do_QueryInterface(doc));
if (pDoc) { /* full-page mode */
nsCAutoString spec;
rv = aURI->GetSpec(spec);
if (NS_SUCCEEDED(rv)) {
NS_ConvertUTF8toUCS2 url(spec);
nsCOMPtr<nsIStreamListener> stream;
rv = aPluginHost->InstantiateFullPagePlugin(aMimetype,
url,
/* resulting stream listener */ *getter_AddRefs(stream),
mInstanceOwner);
if (NS_SUCCEEDED(rv))
pDoc->SetStreamListener(stream);
}
} else { /* embedded mode */
rv = aPluginHost->InstantiateEmbededPlugin(aMimetype,
aURI,
mInstanceOwner);
}
return rv;
}
// This is called when the page containing plugin is resized, and plugin has its dimensions
@ -2247,8 +2273,17 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetWindow(nsPluginWindow *&aWindow)
NS_IMETHODIMP nsPluginInstanceOwner::GetMode(nsPluginMode *aMode)
{
*aMode = nsPluginMode_Embedded;
return NS_OK;
nsCOMPtr<nsIDocument> doc;
nsresult rv = GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIPluginDocument> pDoc (do_QueryInterface(doc));
if (pDoc) {
*aMode = nsPluginMode_Full;
} else {
*aMode = nsPluginMode_Embedded;
}
return rv;
}
NS_IMETHODIMP nsPluginInstanceOwner::GetAttributes(PRUint16& n,

View File

@ -133,6 +133,7 @@
#include "nsIObjectFrame.h"
#include "nsPluginNativeWindow.h"
#include "nsPIPluginHost.h"
#include "nsIPluginDocument.h"
// accessibility support
#ifdef ACCESSIBILITY
@ -1322,7 +1323,32 @@ nsObjectFrame::InstantiatePlugin(nsIPresContext* aPresContext,
}
}
return aPluginHost->InstantiateEmbededPlugin(aMimetype, aURI, mInstanceOwner);
nsCOMPtr<nsIDocument> doc;
nsresult rv = mInstanceOwner->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIPluginDocument> pDoc (do_QueryInterface(doc));
if (pDoc) { /* full-page mode */
nsCAutoString spec;
rv = aURI->GetSpec(spec);
if (NS_SUCCEEDED(rv)) {
NS_ConvertUTF8toUCS2 url(spec);
nsCOMPtr<nsIStreamListener> stream;
rv = aPluginHost->InstantiateFullPagePlugin(aMimetype,
url,
/* resulting stream listener */ *getter_AddRefs(stream),
mInstanceOwner);
if (NS_SUCCEEDED(rv))
pDoc->SetStreamListener(stream);
}
} else { /* embedded mode */
rv = aPluginHost->InstantiateEmbededPlugin(aMimetype,
aURI,
mInstanceOwner);
}
return rv;
}
// This is called when the page containing plugin is resized, and plugin has its dimensions
@ -2247,8 +2273,17 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetWindow(nsPluginWindow *&aWindow)
NS_IMETHODIMP nsPluginInstanceOwner::GetMode(nsPluginMode *aMode)
{
*aMode = nsPluginMode_Embedded;
return NS_OK;
nsCOMPtr<nsIDocument> doc;
nsresult rv = GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIPluginDocument> pDoc (do_QueryInterface(doc));
if (pDoc) {
*aMode = nsPluginMode_Full;
} else {
*aMode = nsPluginMode_Embedded;
}
return rv;
}
NS_IMETHODIMP nsPluginInstanceOwner::GetAttributes(PRUint16& n,

View File

@ -3650,6 +3650,21 @@ nsPluginTag::RegisterWithCategoryManager(PRBool aOverrideInternalTypes,
if (!catMan)
return;
// XXX temporary for testing transition
static nsCOMPtr<nsIPrefService> sPrefService;
static PRBool sLoadViaPlugin = PR_FALSE;
if (!sPrefService) {
sPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (sPrefService) {
nsCOMPtr<nsIPrefBranch> prefBranch;
sPrefService->GetBranch(nsnull, getter_AddRefs(prefBranch));
if (prefBranch)
prefBranch->GetBoolPref("plugin.disable_load_full_page_via_content", &sLoadViaPlugin);
}
}
const char *contractId = sLoadViaPlugin ? "@mozilla.org/plugin/doc-loader/factory;1" :
"@mozilla.org/content/plugin/document-loader-factory;1";
for(int i = 0; i < mVariants; i++) {
if (aType == ePluginUnregister) {
nsXPIDLCString value;
@ -3657,7 +3672,7 @@ nsPluginTag::RegisterWithCategoryManager(PRBool aOverrideInternalTypes,
mMimeTypeArray[i],
getter_Copies(value)))) {
// Only delete the entry if a plugin registered for it
if (strcmp(value, "@mozilla.org/plugin/doc-loader/factory;1") == 0) {
if (strcmp(value, contractId) == 0) {
catMan->DeleteCategoryEntry("Gecko-Content-Viewers",
mMimeTypeArray[i],
PR_TRUE);
@ -3666,7 +3681,7 @@ nsPluginTag::RegisterWithCategoryManager(PRBool aOverrideInternalTypes,
} else {
catMan->AddCategoryEntry("Gecko-Content-Viewers",
mMimeTypeArray[i],
"@mozilla.org/plugin/doc-loader/factory;1",
contractId,
PR_FALSE, /* persist: broken by bug 193031 */
aOverrideInternalTypes, /* replace if we're told to */
nsnull);