Bug 1428722 - part2 : move all user-activation implementation details to nsDocument. r=smaug

In order to write tests, I would like to create an method that allows chorome js can directly set the user-activation flag.

Therefore, I need to move all these details into nsDocument, then we could easily simulate the user activation.

MozReview-Commit-ID: 5JrCoQc0vF7

--HG--
extra : rebase_source : 256ff2993ef754dc51409e7e444b868a3302bd65
This commit is contained in:
Alastor Wu 2018-01-11 17:26:30 +08:00
Родитель acecd71925
Коммит cb52b8db63
4 изменённых файлов: 36 добавлений и 21 удалений

Просмотреть файл

@ -13188,7 +13188,20 @@ nsIDocument::SetUserHasInteracted(bool aUserHasInteracted)
}
void
nsIDocument::MaybeNotifyUserActivation(nsIPrincipal* aPrincipal)
nsIDocument::NotifyUserActivation()
{
ActivateByUserGesture();
// Activate parent document which has same principle on the parent chain.
nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
nsCOMPtr<nsIDocument> parent = GetSameTypeParentDocument();
while (parent) {
parent->MaybeActivateByUserGesture(principal);
parent = parent->GetSameTypeParentDocument();
}
}
void
nsIDocument::MaybeActivateByUserGesture(nsIPrincipal* aPrincipal)
{
bool isEqual = false;
nsresult rv = aPrincipal->Equals(NodePrincipal(), &isEqual);
@ -13199,12 +13212,12 @@ nsIDocument::MaybeNotifyUserActivation(nsIPrincipal* aPrincipal)
// If a child frame is actived, it would always activate the top frame and its
// parent frames which has same priciple.
if (isEqual || IsTopLevelContentDocument()) {
NotifyUserActivation();
ActivateByUserGesture();
}
}
void
nsIDocument::NotifyUserActivation()
nsIDocument::ActivateByUserGesture()
{
if (mUserHasActivatedInteraction) {
return;

Просмотреть файл

@ -3071,21 +3071,13 @@ public:
return mUserHasInteracted;
}
// This would be called when document get activated by specific user gestures.
// This would be called when document get activated by specific user gestures
// and propagate the user activation flag to its parent.
void NotifyUserActivation();
// Return true if document has interacted by specific user gestures.
bool HasBeenUserActivated();
void MaybeNotifyUserActivation(nsIPrincipal* aPrincipal);
// Return the same type parent docuement if exists, or return null.
nsIDocument* GetSameTypeParentDocument();
// Return the first parent document with same pricipal, return nullptr if we
// can't find it.
nsIDocument* GetFirstParentDocumentWithSamePrincipal(nsIPrincipal* aPrincipal);
bool HasScriptsBlockedBySandbox();
bool InlineScriptAllowedByCSP();
@ -3275,6 +3267,17 @@ protected:
// Helper for GetScrollingElement/IsScrollingElement.
bool IsPotentiallyScrollable(mozilla::dom::HTMLBodyElement* aBody);
// Return the same type parent docuement if exists, or return null.
nsIDocument* GetSameTypeParentDocument();
// Return the first parent document with same pricipal, return nullptr if we
// can't find it.
nsIDocument* GetFirstParentDocumentWithSamePrincipal(nsIPrincipal* aPrincipal);
// Activate the flag 'mUserHasActivatedInteraction' by specific user gestures.
void ActivateByUserGesture();
void MaybeActivateByUserGesture(nsIPrincipal* aPrincipal);
// Helpers for GetElementsByName.
static bool MatchNameAttribute(mozilla::dom::Element* aElement,
int32_t aNamespaceID,

Просмотреть файл

@ -922,14 +922,6 @@ EventStateManager::NotifyTargetUserActivation(WidgetEvent* aEvent,
aEvent->mMessage == eMouseUp ||
aEvent->mMessage == eTouchEnd);
doc->NotifyUserActivation();
// Activate parent document which has same principle on the parent chain.
nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
nsCOMPtr<nsIDocument> parent = doc->GetSameTypeParentDocument();
while (parent) {
parent->MaybeNotifyUserActivation(principal);
parent = parent->GetSameTypeParentDocument();
}
}
void

Просмотреть файл

@ -445,6 +445,13 @@ partial interface Document {
[ChromeOnly] readonly attribute boolean userHasInteracted;
};
// Extension to give chrome JS the ability to simulate activate the docuement
// by user gesture.
partial interface Document {
[ChromeOnly]
void notifyUserActivation();
};
// Extension to give chrome and XBL JS the ability to determine whether
// the document is sandboxed without permission to run scripts
// and whether inline scripts are blocked by the document's CSP.