Bug 1336714 - Added a null check to the GetParentDocument call in nsDocument::ComputeFlashClassification. Change nsDocument::GetAllowPlugins to return result rather than using unnecessary outparam. nsPluginArray::AllowPlugins changed to call the GetAllowPlugins method on the inner window's document rather than on the docshell's mContentViewer's document.
MozReview-Commit-ID: Crx9v8OBKKq
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -14243,29 +14243,27 @@ nsDocShell::ShouldBlockLoadingForBackBut
bool canGoForward = false;
GetCanGoForward(&canGoForward);
return canGoForward;
}
bool
nsDocShell::PluginsAllowedInCurrentDoc()
{
- bool pluginsAllowed = false;
if (!mContentViewer) {
return false;
}
nsIDocument* doc = mContentViewer->GetDocument();
if (!doc) {
return false;
}
- doc->GetAllowPlugins(&pluginsAllowed);
- return pluginsAllowed;
+ return doc->GetAllowPlugins();
}
//----------------------------------------------------------------------
// Web Shell Services API
// This functions is only called when a new charset is detected in loading a
// document. Its name should be changed to "CharsetReloadDocument"
NS_IMETHODIMP
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -3139,37 +3139,42 @@ nsDocument::GetContentType(nsAString& aC
}
void
nsDocument::SetContentType(const nsAString& aContentType)
{
SetContentTypeInternal(NS_ConvertUTF16toUTF8(aContentType));
}
-nsresult
-nsDocument::GetAllowPlugins(bool * aAllowPlugins)
+bool
+nsDocument::GetAllowPlugins()
{
// First, we ask our docshell if it allows plugins.
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
if (docShell) {
- docShell->GetAllowPlugins(aAllowPlugins);
+ bool allowPlugins = false;
+ docShell->GetAllowPlugins(&allowPlugins);
+ if (!allowPlugins) {
+ return false;
+ }
// If the docshell allows plugins, we check whether
// we are sandboxed and plugins should not be allowed.
- if (*aAllowPlugins)
- *aAllowPlugins = !(mSandboxFlags & SANDBOXED_PLUGINS);
- }
-
- if (*aAllowPlugins) {
- FlashClassification classification = DocumentFlashClassification();
- *aAllowPlugins = (classification != FlashClassification::Denied);
- }
-
- return NS_OK;
+ if (mSandboxFlags & SANDBOXED_PLUGINS) {
+ return false;
+ }
+ }
+
+ FlashClassification classification = DocumentFlashClassification();
+ if (classification == FlashClassification::Denied) {
+ return false;
+ }
+
+ return true;
}
bool
nsDocument::IsElementAnimateEnabled(JSContext* aCx, JSObject* /*unused*/)
{
MOZ_ASSERT(NS_IsMainThread());
return nsContentUtils::IsSystemCaller(aCx) ||
@@ -13132,16 +13137,19 @@ nsDocument::ComputeFlashClassification()
"nsIDocShellTreeItem::GetSameTypeParent should never fail");
bool isTopLevel = !parent;
FlashClassification classification;
if (isTopLevel) {
classification = PrincipalFlashClassification(isTopLevel);
} else {
nsCOMPtr<nsIDocument> parentDocument = GetParentDocument();
+ if (!parentDocument) {
+ return FlashClassification::Denied;
+ }
FlashClassification parentClassification =
parentDocument->DocumentFlashClassification();
if (parentClassification == FlashClassification::Denied) {
classification = FlashClassification::Denied;
} else {
classification = PrincipalFlashClassification(isTopLevel);
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -594,17 +594,17 @@ public:
* shared among multiple presentation shells).
*/
already_AddRefed<nsIPresShell> CreateShell(nsPresContext* aContext,
nsViewManager* aViewManager,
mozilla::StyleSetHandle aStyleSet)
final;
virtual void DeleteShell() override;
- virtual nsresult GetAllowPlugins(bool* aAllowPlugins) override;
+ virtual bool GetAllowPlugins() override;
static bool IsElementAnimateEnabled(JSContext* aCx, JSObject* aObject);
static bool IsWebAnimationsEnabled(JSContext* aCx, JSObject* aObject);
virtual mozilla::dom::DocumentTimeline* Timeline() override;
virtual void GetAnimations(
nsTArray<RefPtr<mozilla::dom::Animation>>& aAnimations) override;
mozilla::LinkedList<mozilla::dom::DocumentTimeline>& Timelines() override
{
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -876,17 +876,17 @@ public:
void SetParentDocument(nsIDocument* aParent)
{
mParentDocument = aParent;
}
/**
* Are plugins allowed in this document ?
*/
- virtual nsresult GetAllowPlugins (bool* aAllowPlugins) = 0;
+ virtual bool GetAllowPlugins () = 0;
/**
* Set the sub document for aContent to aSubDoc.
*/
virtual nsresult SetSubDocumentFor(Element* aContent,
nsIDocument* aSubDoc) = 0;
/**
--- a/dom/base/nsPluginArray.cpp
+++ b/dom/base/nsPluginArray.cpp
@@ -306,19 +306,25 @@ nsPluginArray::Observe(nsISupports *aSub
}
return NS_OK;
}
bool
nsPluginArray::AllowPlugins() const
{
- nsCOMPtr<nsIDocShell> docShell = mWindow ? mWindow->GetDocShell() : nullptr;
+ if (!mWindow) {
+ return false;
+ }
+ nsCOMPtr<nsIDocument> doc = mWindow->GetDoc();
+ if (!doc) {
+ return false;
+ }
- return docShell && docShell->PluginsAllowedInCurrentDoc();
+ return doc->GetAllowPlugins();
}
static bool
operator<(const RefPtr<nsPluginElement>& lhs,
const RefPtr<nsPluginElement>& rhs)
{
// Sort plugins alphabetically by name.
return lhs->PluginTag()->Name() < rhs->PluginTag()->Name();