Bug 1093693 - [e10s] Don't use sync messages between plugins and chrome process (r=jimm)

This commit is contained in:
Bill McCloskey 2014-11-18 21:46:01 -08:00
parent 36ce9f8f76
commit f5c20f47d7
5 changed files with 178 additions and 76 deletions

View File

@ -17,6 +17,21 @@ using struct nsID from "nsID.h";
namespace mozilla { namespace mozilla {
namespace plugins { namespace plugins {
struct PluginSettings
{
// These settings correspond to NPNVariable. They are fetched from
// mozilla::plugins::parent::_getvalue.
bool javascriptEnabled;
bool asdEnabled;
bool isOffline;
bool supportsXembed;
bool supportsWindowless;
// These settings come from elsewhere.
nsCString userAgent;
bool nativeCursorsSupported;
};
intr protocol PPluginModule intr protocol PPluginModule
{ {
bridges PContent, PPluginModule; bridges PContent, PPluginModule;
@ -34,7 +49,7 @@ child:
intr NP_GetEntryPoints() intr NP_GetEntryPoints()
returns (NPError rv); returns (NPError rv);
intr NP_Initialize() intr NP_Initialize(PluginSettings settings)
returns (NPError rv); returns (NPError rv);
intr PPluginInstance(nsCString aMimeType, intr PPluginInstance(nsCString aMimeType,
@ -69,6 +84,8 @@ child:
intr GeckoGetProfile() intr GeckoGetProfile()
returns (nsCString aProfile); returns (nsCString aProfile);
async SettingChanged(PluginSettings settings);
parent: parent:
/** /**
* This message is only used on X11 platforms. * This message is only used on X11 platforms.
@ -83,13 +100,6 @@ parent:
*/ */
async BackUpXResources(FileDescriptor aXSocketFd); async BackUpXResources(FileDescriptor aXSocketFd);
intr NPN_UserAgent()
returns (nsCString userAgent);
intr NPN_GetValue_WithBoolReturn(NPNVariable aVariable)
returns (NPError aError,
bool aBoolVal);
// Wake up and process a few native events. Periodically called by // Wake up and process a few native events. Periodically called by
// Gtk-specific code upon detecting that the plugin process has // Gtk-specific code upon detecting that the plugin process has
// entered a nested event loop. If the browser doesn't process // entered a nested event loop. If the browser doesn't process
@ -108,7 +118,6 @@ parent:
async ShowCursor(bool show); async ShowCursor(bool show);
async PushCursor(NSCursorInfo cursorInfo); async PushCursor(NSCursorInfo cursorInfo);
async PopCursor(); async PopCursor();
sync GetNativeCursorsSupported() returns (bool supported);
sync NPN_SetException(nsCString message); sync NPN_SetException(nsCString message);

View File

@ -821,10 +821,7 @@ PluginModuleChild::CleanUp()
const char* const char*
PluginModuleChild::GetUserAgent() PluginModuleChild::GetUserAgent()
{ {
if (mUserAgent.IsVoid() && !CallNPN_UserAgent(&mUserAgent)) return NullableStringGet(Settings().userAgent());
return nullptr;
return NullableStringGet(mUserAgent);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -1120,18 +1117,21 @@ _getvalue(NPP aNPP,
#endif #endif
return NPERR_GENERIC_ERROR; return NPERR_GENERIC_ERROR;
case NPNVjavascriptEnabledBool: // Intentional fall-through case NPNVjavascriptEnabledBool:
case NPNVasdEnabledBool: // Intentional fall-through *(NPBool*)aValue = PluginModuleChild::GetChrome()->Settings().javascriptEnabled();
case NPNVisOfflineBool: // Intentional fall-through return NPERR_NO_ERROR;
case NPNVSupportsXEmbedBool: // Intentional fall-through case NPNVasdEnabledBool:
case NPNVSupportsWindowless: { // Intentional fall-through *(NPBool*)aValue = PluginModuleChild::GetChrome()->Settings().asdEnabled();
NPError result; return NPERR_NO_ERROR;
bool value; case NPNVisOfflineBool:
PluginModuleChild::GetChrome()-> *(NPBool*)aValue = PluginModuleChild::GetChrome()->Settings().isOffline();
CallNPN_GetValue_WithBoolReturn(aVariable, &result, &value); return NPERR_NO_ERROR;
*(NPBool*)aValue = value ? true : false; case NPNVSupportsXEmbedBool:
return result; *(NPBool*)aValue = PluginModuleChild::GetChrome()->Settings().supportsXembed();
} return NPERR_NO_ERROR;
case NPNVSupportsWindowless:
*(NPBool*)aValue = PluginModuleChild::GetChrome()->Settings().supportsWindowless();
return NPERR_NO_ERROR;
#if defined(MOZ_WIDGET_GTK) #if defined(MOZ_WIDGET_GTK)
case NPNVxDisplay: { case NPNVxDisplay: {
if (aNPP) { if (aNPP) {
@ -1834,6 +1834,13 @@ _urlredirectresponse(NPP instance, void* notifyData, NPBool allow)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool
PluginModuleChild::RecvSettingChanged(const PluginSettings& aSettings)
{
mCachedSettings = aSettings;
return true;
}
bool bool
PluginModuleChild::AnswerNP_GetEntryPoints(NPError* _retval) PluginModuleChild::AnswerNP_GetEntryPoints(NPError* _retval)
{ {
@ -1852,12 +1859,14 @@ PluginModuleChild::AnswerNP_GetEntryPoints(NPError* _retval)
} }
bool bool
PluginModuleChild::AnswerNP_Initialize(NPError* _retval) PluginModuleChild::AnswerNP_Initialize(const PluginSettings& aSettings, NPError* _retval)
{ {
PLUGIN_LOG_DEBUG_METHOD; PLUGIN_LOG_DEBUG_METHOD;
AssertPluginThread(); AssertPluginThread();
MOZ_ASSERT(mIsChrome); MOZ_ASSERT(mIsChrome);
mCachedSettings = aSettings;
#ifdef OS_WIN #ifdef OS_WIN
SetEventHooks(); SetEventHooks();
#endif #endif

View File

@ -72,9 +72,11 @@ protected:
virtual bool ShouldContinueFromReplyTimeout() MOZ_OVERRIDE; virtual bool ShouldContinueFromReplyTimeout() MOZ_OVERRIDE;
virtual bool RecvSettingChanged(const PluginSettings& aSettings) MOZ_OVERRIDE;
// Implement the PPluginModuleChild interface // Implement the PPluginModuleChild interface
virtual bool AnswerNP_GetEntryPoints(NPError* rv) MOZ_OVERRIDE; virtual bool AnswerNP_GetEntryPoints(NPError* rv) MOZ_OVERRIDE;
virtual bool AnswerNP_Initialize(NPError* rv) MOZ_OVERRIDE; virtual bool AnswerNP_Initialize(const PluginSettings& aSettings, NPError* rv) MOZ_OVERRIDE;
virtual PPluginModuleChild* virtual PPluginModuleChild*
AllocPPluginModuleChild(mozilla::ipc::Transport* aTransport, AllocPPluginModuleChild(mozilla::ipc::Transport* aTransport,
@ -226,9 +228,7 @@ public:
} }
bool GetNativeCursorsSupported() { bool GetNativeCursorsSupported() {
bool supported = false; return Settings().nativeCursorsSupported();
SendGetNativeCursorsSupported(&supported);
return supported;
} }
#endif #endif
@ -278,6 +278,8 @@ public:
int GetQuirks() { return mQuirks; } int GetQuirks() { return mQuirks; }
const PluginSettings& Settings() const { return mCachedSettings; }
private: private:
void AddQuirk(PluginQuirks quirk) { void AddQuirk(PluginQuirks quirk) {
if (mQuirks == QUIRKS_NOT_INITIALIZED) if (mQuirks == QUIRKS_NOT_INITIALIZED)
@ -318,6 +320,8 @@ private:
NPPluginFuncs mFunctions; NPPluginFuncs mFunctions;
PluginSettings mCachedSettings;
#if defined(MOZ_WIDGET_GTK) #if defined(MOZ_WIDGET_GTK)
// If a plugin spins a nested glib event loop in response to a // If a plugin spins a nested glib event loop in response to a
// synchronous IPC message from the browser, the loop might break // synchronous IPC message from the browser, the loop might break

View File

@ -252,6 +252,8 @@ PluginModuleChromeParent::PluginModuleChromeParent(const char* aFilePath, uint32
Preferences::RegisterCallback(TimeoutChanged, kHangUIMinDisplayPref, this); Preferences::RegisterCallback(TimeoutChanged, kHangUIMinDisplayPref, this);
#endif #endif
RegisterSettingsCallbacks();
#ifdef MOZ_ENABLE_PROFILER_SPS #ifdef MOZ_ENABLE_PROFILER_SPS
InitPluginProfiling(); InitPluginProfiling();
#endif #endif
@ -295,6 +297,8 @@ PluginModuleChromeParent::~PluginModuleChromeParent()
Preferences::UnregisterCallback(TimeoutChanged, kHangUITimeoutPref, this); Preferences::UnregisterCallback(TimeoutChanged, kHangUITimeoutPref, this);
Preferences::UnregisterCallback(TimeoutChanged, kHangUIMinDisplayPref, this); Preferences::UnregisterCallback(TimeoutChanged, kHangUIMinDisplayPref, this);
UnregisterSettingsCallbacks();
if (mHangUIParent) { if (mHangUIParent) {
delete mHangUIParent; delete mHangUIParent;
mHangUIParent = nullptr; mHangUIParent = nullptr;
@ -903,6 +907,9 @@ PluginModuleChromeParent::ActorDestroy(ActorDestroyReason why)
#endif #endif
} }
// We can't broadcast settings changes anymore.
UnregisterSettingsCallbacks();
PluginModuleParent::ActorDestroy(why); PluginModuleParent::ActorDestroy(why);
} }
@ -1156,13 +1163,6 @@ PluginModuleParent::NPP_URLRedirectNotify(NPP instance, const char* url,
i->NPP_URLRedirectNotify(url, status, notifyData); i->NPP_URLRedirectNotify(url, status, notifyData);
} }
bool
PluginModuleParent::AnswerNPN_UserAgent(nsCString* userAgent)
{
*userAgent = NullableString(mNPNIface->uagent(nullptr));
return true;
}
PluginInstanceParent* PluginInstanceParent*
PluginModuleParent::InstCast(NPP instance) PluginModuleParent::InstCast(NPP instance)
{ {
@ -1262,6 +1262,107 @@ PluginModuleParent::EndUpdateBackground(NPP instance,
return i->EndUpdateBackground(aCtx, aRect); return i->EndUpdateBackground(aCtx, aRect);
} }
class OfflineObserver MOZ_FINAL : public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
explicit OfflineObserver(PluginModuleChromeParent* pmp)
: mPmp(pmp)
{}
private:
~OfflineObserver() {}
PluginModuleChromeParent* mPmp;
};
NS_IMPL_ISUPPORTS(OfflineObserver, nsIObserver)
NS_IMETHODIMP
OfflineObserver::Observe(nsISupports *aSubject,
const char *aTopic,
const char16_t *aData)
{
MOZ_ASSERT(!strcmp(aTopic, "ipc:network:set-offline"));
mPmp->CachedSettingChanged();
return NS_OK;
}
static const char* kSettingsPrefs[] =
{"javascript.enabled",
"dom.ipc.plugins.nativeCursorSupport"};
void
PluginModuleChromeParent::RegisterSettingsCallbacks()
{
for (size_t i = 0; i < ArrayLength(kSettingsPrefs); i++) {
Preferences::RegisterCallback(CachedSettingChanged, kSettingsPrefs[i], this);
}
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
if (observerService) {
mOfflineObserver = new OfflineObserver(this);
observerService->AddObserver(mOfflineObserver, "ipc:network:set-offline", false);
}
}
void
PluginModuleChromeParent::UnregisterSettingsCallbacks()
{
for (size_t i = 0; i < ArrayLength(kSettingsPrefs); i++) {
Preferences::UnregisterCallback(CachedSettingChanged, kSettingsPrefs[i], this);
}
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
if (observerService) {
observerService->RemoveObserver(mOfflineObserver, "ipc:network:set-offline");
mOfflineObserver = nullptr;
}
}
bool
PluginModuleParent::GetSetting(NPNVariable aVariable)
{
NPBool boolVal = false;
mozilla::plugins::parent::_getvalue(nullptr, aVariable, &boolVal);
return boolVal;
}
void
PluginModuleParent::GetSettings(PluginSettings* aSettings)
{
aSettings->javascriptEnabled() = GetSetting(NPNVjavascriptEnabledBool);
aSettings->asdEnabled() = GetSetting(NPNVasdEnabledBool);
aSettings->isOffline() = GetSetting(NPNVisOfflineBool);
aSettings->supportsXembed() = GetSetting(NPNVSupportsXEmbedBool);
aSettings->supportsWindowless() = GetSetting(NPNVSupportsWindowless);
aSettings->userAgent() = NullableString(mNPNIface->uagent(nullptr));
#if defined(XP_MACOSX)
aSettings->nativeCursorsSupported() =
Preferences::GetBool("dom.ipc.plugins.nativeCursorSupport", false);
#else
// Need to initialize this to satisfy IPDL.
aSettings->nativeCursorsSupported() = false;
#endif
}
void
PluginModuleChromeParent::CachedSettingChanged()
{
PluginSettings settings;
GetSettings(&settings);
unused << SendSettingChanged(settings);
}
/* static */ void
PluginModuleChromeParent::CachedSettingChanged(const char* aPref, void* aModule)
{
PluginModuleChromeParent *module = static_cast<PluginModuleChromeParent*>(aModule);
module->CachedSettingChanged();
}
#if defined(XP_UNIX) && !defined(XP_MACOSX) && !defined(MOZ_WIDGET_GONK) #if defined(XP_UNIX) && !defined(XP_MACOSX) && !defined(MOZ_WIDGET_GONK)
nsresult nsresult
PluginModuleParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs, NPError* error) PluginModuleParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs, NPError* error)
@ -1277,7 +1378,9 @@ PluginModuleParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs
*error = NPERR_NO_ERROR; *error = NPERR_NO_ERROR;
if (IsChrome()) { if (IsChrome()) {
if (!CallNP_Initialize(error)) { PluginSettings settings;
GetSettings(&settings);
if (!CallNP_Initialize(settings, error)) {
Close(); Close();
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -1315,7 +1418,9 @@ PluginModuleChromeParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error)
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
if (!CallNP_Initialize(error)) { PluginSettings settings;
GetSettings(&settings);
if (!CallNP_Initialize(settings, error)) {
Close(); Close();
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -1539,17 +1644,6 @@ PluginModuleParent::ContentsScaleFactorChanged(NPP instance, double aContentsSca
} }
#endif // #if defined(XP_MACOSX) #endif // #if defined(XP_MACOSX)
bool
PluginModuleParent::AnswerNPN_GetValue_WithBoolReturn(const NPNVariable& aVariable,
NPError* aError,
bool* aBoolVal)
{
NPBool boolVal = false;
*aError = mozilla::plugins::parent::_getvalue(nullptr, aVariable, &boolVal);
*aBoolVal = boolVal ? true : false;
return true;
}
#if defined(MOZ_WIDGET_QT) #if defined(MOZ_WIDGET_QT)
static const int kMaxtimeToProcessEvents = 30; static const int kMaxtimeToProcessEvents = 30;
bool bool
@ -1749,21 +1843,6 @@ PluginModuleParent::RecvPopCursor()
#endif #endif
} }
bool
PluginModuleParent::RecvGetNativeCursorsSupported(bool* supported)
{
PLUGIN_LOG_DEBUG(("%s", FULLFUNCTION));
#if defined(XP_MACOSX)
*supported =
Preferences::GetBool("dom.ipc.plugins.nativeCursorSupport", false);
return true;
#else
NS_NOTREACHED(
"PluginInstanceParent::RecvGetNativeCursorSupportLevel not implemented!");
return false;
#endif
}
bool bool
PluginModuleParent::RecvNPN_SetException(const nsCString& aMessage) PluginModuleParent::RecvNPN_SetException(const nsCString& aMessage)
{ {

View File

@ -115,14 +115,6 @@ protected:
virtual bool virtual bool
RecvBackUpXResources(const FileDescriptor& aXSocketFd) MOZ_OVERRIDE; RecvBackUpXResources(const FileDescriptor& aXSocketFd) MOZ_OVERRIDE;
virtual bool
AnswerNPN_UserAgent(nsCString* userAgent) MOZ_OVERRIDE;
virtual bool
AnswerNPN_GetValue_WithBoolReturn(const NPNVariable& aVariable,
NPError* aError,
bool* aBoolVal) MOZ_OVERRIDE;
virtual bool AnswerProcessSomeEvents() MOZ_OVERRIDE; virtual bool AnswerProcessSomeEvents() MOZ_OVERRIDE;
virtual bool virtual bool
@ -154,9 +146,6 @@ protected:
virtual bool virtual bool
RecvPopCursor() MOZ_OVERRIDE; RecvPopCursor() MOZ_OVERRIDE;
virtual bool
RecvGetNativeCursorsSupported(bool* supported) MOZ_OVERRIDE;
virtual bool virtual bool
RecvNPN_SetException(const nsCString& aMessage) MOZ_OVERRIDE; RecvNPN_SetException(const nsCString& aMessage) MOZ_OVERRIDE;
@ -242,6 +231,9 @@ protected:
protected: protected:
void NotifyPluginCrashed(); void NotifyPluginCrashed();
bool GetSetting(NPNVariable aVariable);
void GetSettings(PluginSettings* aSettings);
bool mIsChrome; bool mIsChrome;
bool mShutdown; bool mShutdown;
bool mClearSiteDataSupported; bool mClearSiteDataSupported;
@ -312,6 +304,8 @@ class PluginModuleChromeParent
OnHangUIContinue(); OnHangUIContinue();
#endif // XP_WIN #endif // XP_WIN
void CachedSettingChanged();
private: private:
virtual void virtual void
EnteredCxxStack() MOZ_OVERRIDE; EnteredCxxStack() MOZ_OVERRIDE;
@ -360,8 +354,13 @@ private:
void ShutdownPluginProfiling(); void ShutdownPluginProfiling();
#endif #endif
void RegisterSettingsCallbacks();
void UnregisterSettingsCallbacks();
virtual bool RecvNotifyContentModuleDestroyed() MOZ_OVERRIDE; virtual bool RecvNotifyContentModuleDestroyed() MOZ_OVERRIDE;
static void CachedSettingChanged(const char* aPref, void* aModule);
PluginProcessParent* mSubprocess; PluginProcessParent* mSubprocess;
uint32_t mPluginId; uint32_t mPluginId;
@ -422,6 +421,8 @@ private:
DWORD mFlashProcess1; DWORD mFlashProcess1;
DWORD mFlashProcess2; DWORD mFlashProcess2;
#endif #endif
nsCOMPtr<nsIObserver> mOfflineObserver;
}; };
} // namespace plugins } // namespace plugins