Bug 722942 - Obtain private browsing status from document of plugin owner, and watch private mode transitions on a per-instance basis. r=josh

This commit is contained in:
Josh Matthews 2012-04-24 00:49:25 -04:00
Родитель 4e4e1bcb9b
Коммит 41fef8988a
6 изменённых файлов: 46 добавлений и 37 удалений

Просмотреть файл

@ -54,7 +54,6 @@
#include "nsNPAPIPluginStreamListener.h"
#include "nsIServiceManager.h"
#include "nsThreadUtils.h"
#include "nsIPrivateBrowsingService.h"
#include "mozilla/Preferences.h"
#include "nsIPluginStreamListener.h"
@ -105,6 +104,8 @@
#include "nsJSNPRuntime.h"
#include "nsIHttpAuthManager.h"
#include "nsICookieService.h"
#include "nsILoadContext.h"
#include "nsIDocShell.h"
#include "nsNetUtil.h"
@ -2135,11 +2136,12 @@ _getvalue(NPP npp, NPNVariable variable, void *result)
}
case NPNVprivateModeBool: {
nsCOMPtr<nsIPrivateBrowsingService> pbs = do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
if (pbs) {
bool enabled;
pbs->GetPrivateBrowsingEnabled(&enabled);
*(NPBool*)result = (NPBool)enabled;
nsCOMPtr<nsIDocument> doc = GetDocumentFromNPP(npp);
nsCOMPtr<nsPIDOMWindow> domwindow = do_QueryInterface(doc);
if (domwindow) {
nsCOMPtr<nsIDocShell> docShell = domwindow->GetDocShell();
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
*(NPBool*)result = (NPBool)(loadContext && loadContext->UsePrivateBrowsing());
return NPERR_NO_ERROR;
}
return NPERR_GENERIC_ERROR;

Просмотреть файл

@ -48,7 +48,6 @@
#include "nsPluginHost.h"
#include "nsPluginSafety.h"
#include "nsPluginLogging.h"
#include "nsIPrivateBrowsingService.h"
#include "nsContentUtils.h"
#include "nsIDocument.h"
@ -152,7 +151,7 @@ nsresult nsNPAPIPluginInstance::Initialize(nsNPAPIPlugin *aPlugin, nsIPluginInst
PL_strcpy(mMIMEType, aMIMEType);
}
}
return Start();
}
@ -1143,7 +1142,7 @@ nsNPAPIPluginInstance::GetPluginAPIVersion(PRUint16* version)
}
nsresult
nsNPAPIPluginInstance::PrivateModeStateChanged()
nsNPAPIPluginInstance::PrivateModeStateChanged(bool enabled)
{
if (RUNNING != mRunning)
return NS_OK;
@ -1155,23 +1154,15 @@ nsNPAPIPluginInstance::PrivateModeStateChanged()
NPPluginFuncs* pluginFunctions = mPlugin->PluginFuncs();
if (pluginFunctions->setvalue) {
PluginDestructionGuard guard(this);
nsCOMPtr<nsIPrivateBrowsingService> pbs = do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
if (pbs) {
bool pme = false;
nsresult rv = pbs->GetPrivateBrowsingEnabled(&pme);
if (NS_FAILED(rv))
return rv;
if (!pluginFunctions->setvalue)
return NS_ERROR_FAILURE;
NPError error;
NPBool value = static_cast<NPBool>(pme);
NS_TRY_SAFE_CALL_RETURN(error, (*pluginFunctions->setvalue)(&mNPP, NPNVprivateModeBool, &value), this);
return (error == NPERR_NO_ERROR) ? NS_OK : NS_ERROR_FAILURE;
}
}
return NS_ERROR_FAILURE;
PluginDestructionGuard guard(this);
NPError error;
NPBool value = static_cast<NPBool>(enabled);
NS_TRY_SAFE_CALL_RETURN(error, (*pluginFunctions->setvalue)(&mNPP, NPNVprivateModeBool, &value), this);
return (error == NPERR_NO_ERROR) ? NS_OK : NS_ERROR_FAILURE;
}
class DelayUnscheduleEvent : public nsRunnable {

Просмотреть файл

@ -204,7 +204,7 @@ public:
already_AddRefed<nsPIDOMWindow> GetDOMWindow();
nsresult PrivateModeStateChanged();
nsresult PrivateModeStateChanged(bool aEnabled);
nsresult GetDOMElement(nsIDOMElement* *result);

Просмотреть файл

@ -86,7 +86,6 @@
#include "nsIScriptChannel.h"
#include "nsIBlocklistService.h"
#include "nsVersionComparator.h"
#include "nsIPrivateBrowsingService.h"
#include "nsIObjectLoadingContent.h"
#include "nsIWritablePropertyBag2.h"
#include "nsPluginStreamListenerPeer.h"
@ -357,7 +356,6 @@ nsPluginHost::nsPluginHost()
mozilla::services::GetObserverService();
if (obsService) {
obsService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
obsService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, false);
#ifdef MOZ_WIDGET_ANDROID
obsService->AddObserver(this, "application-foreground", false);
obsService->AddObserver(this, "application-background", false);
@ -3330,12 +3328,6 @@ NS_IMETHODIMP nsPluginHost::Observe(nsISupports *aSubject,
Destroy();
sInst->Release();
}
if (!nsCRT::strcmp(NS_PRIVATE_BROWSING_SWITCH_TOPIC, aTopic)) {
// inform all active plugins of changed private mode state
for (PRUint32 i = 0; i < mInstances.Length(); i++) {
mInstances[i]->PrivateModeStateChanged();
}
}
#ifdef MOZ_WIDGET_ANDROID
if (!nsCRT::strcmp("application-background", aTopic)) {
for(PRUint32 i = 0; i < mInstances.Length(); i++) {

Просмотреть файл

@ -100,6 +100,7 @@ using mozilla::DefaultXDisplay;
#include "nsIScrollableFrame.h"
#include "nsIImageLoadingContent.h"
#include "nsIObjectLoadingContent.h"
#include "nsIDocShell.h"
#include "nsContentCID.h"
#include "nsWidgetsCID.h"
@ -404,10 +405,12 @@ nsPluginInstanceOwner::~nsPluginInstanceOwner()
}
}
NS_IMPL_ISUPPORTS3(nsPluginInstanceOwner,
NS_IMPL_ISUPPORTS5(nsPluginInstanceOwner,
nsIPluginInstanceOwner,
nsIPluginTagInfo,
nsIDOMEventListener)
nsIDOMEventListener,
nsIPrivacyTransitionObserver,
nsISupportsWeakReference)
nsresult
nsPluginInstanceOwner::SetInstance(nsNPAPIPluginInstance *aInstance)
@ -427,6 +430,17 @@ nsPluginInstanceOwner::SetInstance(nsNPAPIPluginInstance *aInstance)
mInstance = aInstance;
nsCOMPtr<nsIDocument> doc;
GetDocument(getter_AddRefs(doc));
if (doc) {
nsCOMPtr<nsPIDOMWindow> domWindow = doc->GetWindow();
if (domWindow) {
nsCOMPtr<nsIDocShell> docShell = domWindow->GetDocShell();
if (docShell)
docShell->AddWeakPrivacyTransitionObserver(this);
}
}
return NS_OK;
}
@ -3798,6 +3812,11 @@ void nsPluginInstanceOwner::FixUpURLS(const nsString &name, nsAString &value)
}
}
NS_IMETHODIMP nsPluginInstanceOwner::PrivateModeChanged(bool aEnabled)
{
return mInstance ? mInstance->PrivateModeStateChanged(aEnabled) : NS_OK;
}
// nsPluginDOMContextMenuListener class implementation
nsPluginDOMContextMenuListener::nsPluginDOMContextMenuListener()

Просмотреть файл

@ -52,10 +52,12 @@
#include "nsCOMPtr.h"
#include "nsIPluginInstanceOwner.h"
#include "nsIPluginTagInfo.h"
#include "nsIPrivacyTransitionObserver.h"
#include "nsIDOMEventListener.h"
#include "nsIScrollPositionListener.h"
#include "nsPluginHost.h"
#include "nsPluginNativeWindow.h"
#include "nsWeakReference.h"
#include "gfxRect.h"
// X.h defines KeyPress
@ -103,7 +105,9 @@ namespace mozilla {
class nsPluginInstanceOwner : public nsIPluginInstanceOwner,
public nsIPluginTagInfo,
public nsIDOMEventListener,
public nsIScrollPositionListener
public nsIScrollPositionListener,
public nsIPrivacyTransitionObserver,
public nsSupportsWeakReference
{
public:
nsPluginInstanceOwner();
@ -111,6 +115,7 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPLUGININSTANCEOWNER
NS_DECL_NSIPRIVACYTRANSITIONOBSERVER
NS_IMETHOD GetURL(const char *aURL, const char *aTarget,
nsIInputStream *aPostStream,