forked from mirrors/gecko-dev
This implements the new HTML spec for these fields, which now serve hard-coded values, depending on whether or not PDFs are supported. The values were deemed important to maintain web compatibility. The spec can be found in section 8.9.1.6: https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewing-support The web-compat test for this can be found at: https://wpt.live/html/webappapis/system-state-and-capabilities/the-navigator-object/plugins-and-mimetypes.html This patch follows the spec for the PDF plugins if "pdfjs.disabled" is false. It also produces empty plugin arrays if "pdfjs.disabled" is true, as per the spec. Both cases are tested by the wpt.live page. Differential Revision: https://phabricator.services.mozilla.com/D133291
133 lines
4 KiB
C++
133 lines
4 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef nsPluginArray_h___
|
|
#define nsPluginArray_h___
|
|
|
|
#include "nsWeakReference.h"
|
|
#include "nsWrapperCache.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsTArray.h"
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
|
|
|
class nsPIDOMWindowInner;
|
|
class nsPluginElement;
|
|
class nsMimeTypeArray;
|
|
class nsMimeType;
|
|
|
|
/**
|
|
* Array class backing HTML's navigator.plugins. This always holds references
|
|
* to the hard-coded set of PDF plugins defined by HTML but it only consults
|
|
* them if "pdfjs.disabled" is false. There is never more than one of these
|
|
* per DOM window.
|
|
*/
|
|
class nsPluginArray final : public nsSupportsWeakReference,
|
|
public nsWrapperCache {
|
|
public:
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsPluginArray)
|
|
|
|
explicit nsPluginArray(nsPIDOMWindowInner* aWindow);
|
|
nsPIDOMWindowInner* GetParentObject() const;
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
nsMimeTypeArray* MimeTypeArray() { return mMimeTypeArray; }
|
|
|
|
// PluginArray WebIDL methods
|
|
uint32_t Length() { return ForceNoPlugins() ? 0 : ArrayLength(mPlugins); }
|
|
|
|
nsPluginElement* Item(uint32_t aIndex) {
|
|
bool unused;
|
|
return IndexedGetter(aIndex, unused);
|
|
}
|
|
|
|
nsPluginElement* NamedItem(const nsAString& aName) {
|
|
bool unused;
|
|
return NamedGetter(aName, unused);
|
|
}
|
|
|
|
nsPluginElement* IndexedGetter(uint32_t aIndex, bool& aFound);
|
|
|
|
nsPluginElement* NamedGetter(const nsAString& aName, bool& aFound);
|
|
|
|
void GetSupportedNames(nsTArray<nsString>& aRetval);
|
|
|
|
void Refresh() {}
|
|
|
|
private:
|
|
virtual ~nsPluginArray();
|
|
|
|
static bool ForceNoPlugins();
|
|
|
|
RefPtr<nsMimeTypeArray> mMimeTypeArray;
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
|
mozilla::Array<RefPtr<nsPluginElement>, 5> mPlugins;
|
|
};
|
|
|
|
/**
|
|
* Plugin class backing entries in HTML's navigator.plugins array. There is
|
|
* a fixed set of these, as defined by HTML.
|
|
*/
|
|
class nsPluginElement final : public nsISupports, public nsWrapperCache {
|
|
public:
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsPluginElement)
|
|
|
|
explicit nsPluginElement(nsPluginArray* aPluginArray,
|
|
nsPIDOMWindowInner* aWindow, const nsAString& aName);
|
|
|
|
nsPluginArray* GetParentObject() const;
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
// Plugin WebIDL methods
|
|
void GetDescription(nsString& retval) const { retval = kDescription; }
|
|
|
|
void GetFilename(nsString& retval) const { retval = kFilename; }
|
|
|
|
void GetName(nsString& retval) const { retval = mName; }
|
|
const nsString& Name() const { return mName; }
|
|
|
|
nsMimeType* Item(uint32_t index) {
|
|
bool unused;
|
|
return IndexedGetter(index, unused);
|
|
}
|
|
|
|
nsMimeType* NamedItem(const nsAString& name) {
|
|
bool unused;
|
|
return NamedGetter(name, unused);
|
|
}
|
|
|
|
uint32_t Length();
|
|
|
|
nsMimeType* IndexedGetter(uint32_t index, bool& found);
|
|
|
|
nsMimeType* NamedGetter(const nsAString& name, bool& found);
|
|
|
|
void GetSupportedNames(nsTArray<nsString>& retval);
|
|
|
|
protected:
|
|
virtual ~nsPluginElement() = default;
|
|
|
|
nsMimeTypeArray* MimeTypeArray() { return mPluginArray->MimeTypeArray(); }
|
|
|
|
static constexpr nsLiteralString kDescription =
|
|
u"Portable Document Format"_ns;
|
|
static constexpr nsLiteralString kFilename = u"internal-pdf-viewer"_ns;
|
|
|
|
// Note that this creates an explicit reference cycle:
|
|
//
|
|
// nsPluginElement -> nsPluginArray -> nsPluginElement
|
|
//
|
|
// We rely on the cycle collector to break this cycle.
|
|
RefPtr<nsPluginArray> mPluginArray;
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
|
nsString mName;
|
|
};
|
|
|
|
#endif /* nsPluginArray_h___ */
|