Bug 1231923 - Enable selection events for documents with the System Principal, r=ehsan

MozReview-Commit-ID: J9UoI9Pdu48
This commit is contained in:
Michael Layzell 2016-09-27 16:05:43 -04:00
parent 8d88d75420
commit 7f30ef3465
2 changed files with 18 additions and 2 deletions

View File

@ -167,6 +167,7 @@ struct nsPrevNextBidiLevels
namespace mozilla {
namespace dom {
class Selection;
class SelectionChangeListener;
} // namespace dom
} // namespace mozilla
class nsIScrollableFrame;
@ -651,6 +652,7 @@ private:
}
friend class mozilla::dom::Selection;
friend class mozilla::dom::SelectionChangeListener;
friend struct mozilla::AutoPrepareFocusRange;
#ifdef DEBUG
void printSelection(); // for debugging

View File

@ -33,6 +33,7 @@
#include "nsIDocumentEncoder.h"
#include "nsTextFragment.h"
#include <algorithm>
#include "nsContentUtils.h"
#include "nsGkAtoms.h"
#include "nsIFrameTraversal.h"
@ -934,7 +935,9 @@ nsFrameSelection::Init(nsIPresShell *aShell, nsIContent *aLimiter)
}
}
if (sSelectionEventsEnabled) {
nsIDocument* doc = aShell->GetDocument();
if (sSelectionEventsEnabled ||
(doc && nsContentUtils::IsSystemPrincipal(doc->NodePrincipal()))) {
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
if (mDomSelections[index]) {
// The Selection instance will hold a strong reference to its selectionchangelistener
@ -3832,9 +3835,14 @@ Selection::AddItem(nsRange* aItem, int32_t* aOutIndex, bool aNoStartSelect)
AutoTArray<RefPtr<nsRange>, 4> rangesToAdd;
*aOutIndex = -1;
nsIDocument* doc = GetParentObject();
bool selectEventsEnabled =
nsFrameSelection::sSelectionEventsEnabled ||
(doc && nsContentUtils::IsSystemPrincipal(doc->NodePrincipal()));
if (!aNoStartSelect &&
mSelectionType == SelectionType::eNormal &&
nsFrameSelection::sSelectionEventsEnabled && Collapsed() &&
selectEventsEnabled && Collapsed() &&
!IsBlockingSelectionChangeEvents()) {
// First, we generate the ranges to add with a scratch range, which is a
// clone of the original range passed in. We do this seperately, because the
@ -6676,6 +6684,12 @@ SelectionChangeListener::NotifySelectionChanged(nsIDOMDocument* aDoc,
{
RefPtr<Selection> sel = aSel->AsSelection();
nsIDocument* doc = sel->GetParentObject();
if (!(doc && nsContentUtils::IsSystemPrincipal(doc->NodePrincipal())) &&
!nsFrameSelection::sSelectionEventsEnabled) {
return NS_OK;
}
// Check if the ranges have actually changed
// Don't bother checking this if we are hiding changes.
if (mOldRanges.Length() == sel->RangeCount() && !sel->IsBlockingSelectionChangeEvents()) {