Skip to content

Commit

Permalink
Issue #1638 - Part 1: Put NPAPI code behind MOZ_ENABLE_NPAPI.
Browse files Browse the repository at this point in the history
Adds --disable-npapi as an additional build option. The default is still to build in NPAPI compatibility, but with this flag, it's finally possible to build without pulling in GTK2 on systems that don't have the package.

This essentially ifdefs everything associated with NPAPI, following various Mozilla removal bugs.

Ref: BZ 1682030, BZ 1251202, BZ 1217665, BZ 1687239
  • Loading branch information
athenian200 committed Jan 10, 2024
1 parent 9dac9de commit b787af5
Show file tree
Hide file tree
Showing 106 changed files with 1,400 additions and 273 deletions.
10 changes: 9 additions & 1 deletion accessible/base/nsAccessibilityService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
#ifdef XP_WIN
#include "mozilla/a11y/Compatibility.h"
#include "mozilla/dom/ContentChild.h"
#ifdef MOZ_ENABLE_NPAPI
#include "HTMLWin32ObjectAccessible.h"
#endif
#include "mozilla/StaticPtr.h"
#endif

Expand All @@ -55,7 +57,9 @@
#include "nsImageFrame.h"
#include "nsIObserverService.h"
#include "nsLayoutUtils.h"
#ifdef MOZ_ENABLE_NPAPI
#include "nsPluginFrame.h"
#endif
#include "nsSVGPathGeometryFrame.h"
#include "nsTreeBodyFrame.h"
#include "nsTreeColumns.h"
Expand All @@ -79,7 +83,7 @@
#include "XULTabAccessible.h"
#include "XULTreeGridAccessibleWrap.h"

#if defined(XP_WIN) || defined(MOZ_ACCESSIBILITY_ATK)
#if (defined(XP_WIN) || defined(MOZ_ACCESSIBILITY_ATK)) && defined(MOZ_ENABLE_NPAPI)
#include "nsNPAPIPluginInstance.h"
#endif

Expand Down Expand Up @@ -431,6 +435,7 @@ class PluginTimerCallBack final : public nsITimerCallback
NS_IMPL_ISUPPORTS(PluginTimerCallBack, nsITimerCallback)
#endif

#ifdef MOZ_ENABLE_NPAPI
already_AddRefed<Accessible>
nsAccessibilityService::CreatePluginAccessible(nsPluginFrame* aFrame,
nsIContent* aContent,
Expand Down Expand Up @@ -493,6 +498,7 @@ nsAccessibilityService::CreatePluginAccessible(nsPluginFrame* aFrame,

return nullptr;
}
#endif // MOZ_ENABLE_NPAPI

void
nsAccessibilityService::DeckPanelSwitched(nsIPresShell* aPresShell,
Expand Down Expand Up @@ -1638,11 +1644,13 @@ nsAccessibilityService::CreateAccessibleByFrameType(nsIFrame* aFrame,
case eOuterDocType:
newAcc = new OuterDocAccessible(aContent, document);
break;
#ifdef MOZ_ENABLE_NPAPI
case ePluginType: {
nsPluginFrame* pluginFrame = do_QueryFrame(aFrame);
newAcc = CreatePluginAccessible(pluginFrame, aContent, aContext);
break;
}
#endif
case eTextLeafType:
newAcc = new TextLeafAccessibleWrap(aContent, document);
break;
Expand Down
4 changes: 4 additions & 0 deletions accessible/base/nsAccessibilityService.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
class nsImageFrame;
class nsIArray;
class nsIPersistentProperties;
#ifdef MOZ_ENABLE_NPAPI
class nsPluginFrame;
#endif
class nsITreeView;

namespace mozilla {
Expand Down Expand Up @@ -87,9 +89,11 @@ class nsAccessibilityService final : public mozilla::a11y::DocManager,

Accessible* GetRootDocumentAccessible(nsIPresShell* aPresShell,
bool aCanCreate);
#ifdef MOZ_ENABLE_NPAPI
already_AddRefed<Accessible>
CreatePluginAccessible(nsPluginFrame* aFrame, nsIContent* aContent,
Accessible* aContext);
#endif

/**
* Adds/remove ATK root accessible for gtk+ native window to/from children
Expand Down
3 changes: 2 additions & 1 deletion accessible/ipc/DocAccessibleParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,14 @@ DocAccessibleParent::SetCOMProxy(const RefPtr<IAccessible>& aCOMProxy)
IAccessibleHolder holder(Move(ptr));
Unused << SendParentCOMProxy(holder);
}

#ifdef MOZ_ENABLE_NPAPI
bool
DocAccessibleParent::RecvGetWindowedPluginIAccessible(
const WindowsHandle& aHwnd, IAccessibleHolder* aPluginCOMProxy)
{
return false;
}
#endif

#endif // defined(XP_WIN)

Expand Down
5 changes: 3 additions & 2 deletions accessible/ipc/DocAccessibleParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ class DocAccessibleParent : public ProxyAccessible,

#if defined(XP_WIN)
void SetCOMProxy(const RefPtr<IAccessible>& aCOMProxy);

#ifdef MOZ_ENABLE_NPAPI
virtual bool RecvGetWindowedPluginIAccessible(
const WindowsHandle& aHwnd, IAccessibleHolder* aPluginCOMProxy) override;
#endif
#endif // MOZ_ENABLE_NPAPI
#endif // XP_WIN

private:

Expand Down
2 changes: 2 additions & 0 deletions accessible/ipc/win/PDocAccessible.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ parent:
*/
async BindChildDoc(PDocAccessible aChildDoc, uint64_t aID);

#ifdef MOZ_ENABLE_NPAPI
sync GetWindowedPluginIAccessible(WindowsHandle aHwnd)
returns (IAccessibleHolder aPluginCOMProxy);
#endif

child:
async ParentCOMProxy(IAccessibleHolder aParentCOMProxy);
Expand Down
2 changes: 1 addition & 1 deletion accessible/ipc/win/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if CONFIG['COMPILE_ENVIRONMENT']:

# With --disable-accessibility, we need to compile PDocAccessible.ipdl (which
# also depends on COMPtrTypes.h), but not the C++.
IPDL_SOURCES += ['PDocAccessible.ipdl']
PREPROCESSED_IPDL_SOURCES += ['PDocAccessible.ipdl']
EXPORTS.mozilla.a11y += ['COMPtrTypes.h']

if CONFIG['ACCESSIBILITY']:
Expand Down
7 changes: 7 additions & 0 deletions accessible/windows/msaa/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ SOURCES += [
'XULTreeGridAccessibleWrap.cpp',
]

if CONFIG['MOZ_ENABLE_NPAPI']:
SOURCES += [
'HTMLWin32ObjectAccessible.cpp',
]



LOCAL_INCLUDES += [
'/accessible/base',
'/accessible/generic',
Expand Down
1 change: 1 addition & 0 deletions build/moz.configure/old.configure
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def old_configure_options(*options):
'--enable-necko-wifi',
'--enable-negotiateauth',
'--enable-nfc',
'--enable-npapi',
'--enable-nspr-build',
'--enable-official-branding',
'--enable-official-vendor',
Expand Down
8 changes: 8 additions & 0 deletions dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

#include "Navigator.h"
#include "nsIXULAppInfo.h"
#ifdef MOZ_ENABLE_NPAPI
#include "nsPluginArray.h"
#endif
#include "nsMimeTypeArray.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/BodyExtractor.h"
Expand Down Expand Up @@ -179,7 +181,9 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END

NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMimeTypes)
#ifdef MOZ_ENABLE_NPAPI
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPlugins)
#endif
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPermissions)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGeolocation)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotification)
Expand Down Expand Up @@ -210,10 +214,12 @@ Navigator::Invalidate()

mMimeTypes = nullptr;

#ifdef MOZ_ENABLE_NPAPI
if (mPlugins) {
mPlugins->Invalidate();
mPlugins = nullptr;
}
#endif

mPermissions = nullptr;

Expand Down Expand Up @@ -489,6 +495,7 @@ Navigator::GetMimeTypes(ErrorResult& aRv)
return mMimeTypes;
}

#ifdef MOZ_ENABLE_NPAPI
nsPluginArray*
Navigator::GetPlugins(ErrorResult& aRv)
{
Expand All @@ -503,6 +510,7 @@ Navigator::GetPlugins(ErrorResult& aRv)

return mPlugins;
}
#endif

Permissions*
Navigator::GetPermissions(ErrorResult& aRv)
Expand Down
6 changes: 6 additions & 0 deletions dom/base/Navigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include "nsTArray.h"
#include "nsWeakPtr.h"

#ifdef MOZ_ENABLE_NPAPI
class nsPluginArray;
#endif
class nsMimeTypeArray;
class nsPIDOMWindowInner;
class nsIDOMNavigatorSystemMessages;
Expand Down Expand Up @@ -127,7 +129,9 @@ class Navigator final : public nsIDOMNavigator
void RegisterContentHandler(const nsAString& aMIMEType, const nsAString& aURL,
const nsAString& aTitle, ErrorResult& aRv);
nsMimeTypeArray* GetMimeTypes(ErrorResult& aRv);
#ifdef MOZ_ENABLE_NPAPI
nsPluginArray* GetPlugins(ErrorResult& aRv);
#endif
Permissions* GetPermissions(ErrorResult& aRv);
bool GlobalPrivacyControl();
Geolocation* GetGeolocation(ErrorResult& aRv);
Expand Down Expand Up @@ -260,7 +264,9 @@ class Navigator final : public nsIDOMNavigator
ErrorResult& aRv);

RefPtr<nsMimeTypeArray> mMimeTypes;
#ifdef MOZ_ENABLE_NPAPI
RefPtr<nsPluginArray> mPlugins;
#endif
RefPtr<Permissions> mPermissions;
RefPtr<Geolocation> mGeolocation;
RefPtr<DesktopNotificationCenter> mNotification;
Expand Down
5 changes: 3 additions & 2 deletions dom/base/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,11 @@ SOURCES += [
'nsImageLoadingContent.cpp',
# Because of OS X headers.
'nsObjectLoadingContent.cpp',
# nsPluginArray.cpp includes npapi.h indirectly, and that includes a lot of system headers
'nsPluginArray.cpp',
]

if CONFIG['MOZ_ENABLE_NPAPI']:
SOURCES += ['nsPluginArray.cpp']

# Are we targeting x86-32 or x86-64? If so, we want to include SSE2 code for
# nsTextFragment.cpp
if CONFIG['INTEL_ARCHITECTURE']:
Expand Down
4 changes: 3 additions & 1 deletion dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include "Layers.h"
#include "MediaDecoder.h"
// nsNPAPIPluginInstance must be included before nsIDocument.h, which is included in mozAutoDocUpdate.h.
#ifdef MOZ_ENABLE_NPAPI
#include "nsNPAPIPluginInstance.h"
#endif
#include "gfxDrawable.h"
#include "gfxPrefs.h"
#include "ImageOps.h"
Expand Down Expand Up @@ -6950,7 +6952,7 @@ nsContentUtils::HaveEqualPrincipals(nsIDocument* aDoc1, nsIDocument* aDoc2)
bool
nsContentUtils::HasPluginWithUncontrolledEventDispatch(nsIContent* aContent)
{
#ifdef XP_MACOSX
#if defined(XP_MACOSX) || !defined(MOZ_ENABLE_NPAPI)
// We control dispatch to all mac plugins.
return false;
#else
Expand Down
3 changes: 3 additions & 0 deletions dom/base/nsDOMWindowUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3145,9 +3145,11 @@ nsDOMWindowUtils::GetPaintingSuppressed(bool *aPaintingSuppressed)
return NS_OK;
}


NS_IMETHODIMP
nsDOMWindowUtils::GetPlugins(JSContext* cx, JS::MutableHandle<JS::Value> aPlugins)
{
#ifdef MOZ_ENABLE_NPAPI
nsCOMPtr<nsIDocument> doc = GetDocument();
NS_ENSURE_STATE(doc);

Expand All @@ -3159,6 +3161,7 @@ nsDOMWindowUtils::GetPlugins(JSContext* cx, JS::MutableHandle<JS::Value> aPlugin
NS_ENSURE_SUCCESS(rv, rv);

aPlugins.setObject(*jsPlugins);
#endif
return NS_OK;
}

Expand Down
4 changes: 3 additions & 1 deletion dom/base/nsDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9687,6 +9687,7 @@ nsDocument::RemovePlugin(nsIObjectLoadingContent* aPlugin)
mPlugins.RemoveEntry(aPlugin);
}

#ifdef MOZ_ENABLE_NPAPI
static bool
AllSubDocumentPluginEnum(nsIDocument* aDocument, void* userArg)
{
Expand All @@ -9706,6 +9707,7 @@ nsDocument::GetPlugins(nsTArray<nsIObjectLoadingContent*>& aPlugins)
}
EnumerateSubDocuments(AllSubDocumentPluginEnum, &aPlugins);
}
#endif

nsresult
nsDocument::AddResponsiveContent(nsIContent* aContent)
Expand Down Expand Up @@ -12307,4 +12309,4 @@ nsIDocument::ModuleScriptsEnabled()
}

return nsContentUtils::IsChromeDoc(this) || sEnabledForContent;
}
}
3 changes: 2 additions & 1 deletion dom/base/nsDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,11 @@ class nsDocument : public nsIDocument,
// RemovePlugin removes a plugin-related element to mPlugins when the
// element is removed from the tree.
virtual void RemovePlugin(nsIObjectLoadingContent* aPlugin) override;
#ifdef MOZ_ENABLE_NPAPI
// GetPlugins returns the plugin-related elements from
// the frame and any subframes.
virtual void GetPlugins(nsTArray<nsIObjectLoadingContent*>& aPlugins) override;

#endif
// Adds an element to mResponsiveContent when the element is
// added to the tree.
virtual nsresult AddResponsiveContent(nsIContent* aContent) override;
Expand Down
4 changes: 4 additions & 0 deletions dom/base/nsFrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@
#include "AppProcessChecker.h"
#include "ContentParent.h"
#include "TabParent.h"
#ifdef MOZ_ENABLE_NPAPI
#include "mozilla/plugins/PPluginWidgetParent.h"
#include "../plugins/ipc/PluginWidgetParent.h"
#endif
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/GuardObjects.h"
Expand Down Expand Up @@ -1153,6 +1155,7 @@ nsFrameLoader::SwapWithOtherRemoteLoader(nsFrameLoader* aOther,
aOther->mRemoteBrowser->SetBrowserDOMWindow(browserDOMWindow);
mRemoteBrowser->SetBrowserDOMWindow(otherBrowserDOMWindow);

#ifdef MOZ_ENABLE_NPAPI
// Native plugin windows used by this remote content need to be reparented.
if (nsPIDOMWindowOuter* newWin = ourDoc->GetWindow()) {
RefPtr<nsIWidget> newParent = nsGlobalWindow::Cast(newWin)->GetMainWidget();
Expand All @@ -1162,6 +1165,7 @@ nsFrameLoader::SwapWithOtherRemoteLoader(nsFrameLoader* aOther,
static_cast<mozilla::plugins::PluginWidgetParent*>(iter.Get()->GetKey())->SetParent(newParent);
}
}
#endif // MOZ_ENABLE_NPAPI

MaybeUpdatePrimaryTabParent(eTabParentRemoved);
aOther->MaybeUpdatePrimaryTabParent(eTabParentRemoved);
Expand Down
3 changes: 2 additions & 1 deletion dom/base/nsIDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -2383,8 +2383,9 @@ class nsIDocument : public nsINode,

virtual nsresult AddPlugin(nsIObjectLoadingContent* aPlugin) = 0;
virtual void RemovePlugin(nsIObjectLoadingContent* aPlugin) = 0;
#ifdef MOZ_ENABLE_NPAPI
virtual void GetPlugins(nsTArray<nsIObjectLoadingContent*>& aPlugins) = 0;

#endif
virtual nsresult AddResponsiveContent(nsIContent* aContent) = 0;
virtual void RemoveResponsiveContent(nsIContent* aContent) = 0;
virtual void NotifyMediaFeatureValuesChanged() = 0;
Expand Down
1 change: 1 addition & 0 deletions dom/base/nsIObjectLoadingContent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ interface nsIObjectLoadingContent : nsISupports
* printing the plugin. The returned nsIFrame is in the original document,
* not in the static clone.
*/

[noscript] nsIFrame getPrintFrame();

/*
Expand Down
Loading

0 comments on commit b787af5

Please sign in to comment.