зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
acecd71925
Коммит
cb52b8db63
|
@ -13188,7 +13188,20 @@ nsIDocument::SetUserHasInteracted(bool aUserHasInteracted)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
bool isEqual = false;
|
||||||
nsresult rv = aPrincipal->Equals(NodePrincipal(), &isEqual);
|
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
|
// If a child frame is actived, it would always activate the top frame and its
|
||||||
// parent frames which has same priciple.
|
// parent frames which has same priciple.
|
||||||
if (isEqual || IsTopLevelContentDocument()) {
|
if (isEqual || IsTopLevelContentDocument()) {
|
||||||
NotifyUserActivation();
|
ActivateByUserGesture();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsIDocument::NotifyUserActivation()
|
nsIDocument::ActivateByUserGesture()
|
||||||
{
|
{
|
||||||
if (mUserHasActivatedInteraction) {
|
if (mUserHasActivatedInteraction) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -3071,21 +3071,13 @@ public:
|
||||||
return mUserHasInteracted;
|
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();
|
void NotifyUserActivation();
|
||||||
|
|
||||||
// Return true if document has interacted by specific user gestures.
|
// Return true if document has interacted by specific user gestures.
|
||||||
bool HasBeenUserActivated();
|
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 HasScriptsBlockedBySandbox();
|
||||||
|
|
||||||
bool InlineScriptAllowedByCSP();
|
bool InlineScriptAllowedByCSP();
|
||||||
|
@ -3275,6 +3267,17 @@ protected:
|
||||||
// Helper for GetScrollingElement/IsScrollingElement.
|
// Helper for GetScrollingElement/IsScrollingElement.
|
||||||
bool IsPotentiallyScrollable(mozilla::dom::HTMLBodyElement* aBody);
|
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.
|
// Helpers for GetElementsByName.
|
||||||
static bool MatchNameAttribute(mozilla::dom::Element* aElement,
|
static bool MatchNameAttribute(mozilla::dom::Element* aElement,
|
||||||
int32_t aNamespaceID,
|
int32_t aNamespaceID,
|
||||||
|
|
|
@ -922,14 +922,6 @@ EventStateManager::NotifyTargetUserActivation(WidgetEvent* aEvent,
|
||||||
aEvent->mMessage == eMouseUp ||
|
aEvent->mMessage == eMouseUp ||
|
||||||
aEvent->mMessage == eTouchEnd);
|
aEvent->mMessage == eTouchEnd);
|
||||||
doc->NotifyUserActivation();
|
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
|
void
|
||||||
|
|
|
@ -445,6 +445,13 @@ partial interface Document {
|
||||||
[ChromeOnly] readonly attribute boolean userHasInteracted;
|
[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
|
// Extension to give chrome and XBL JS the ability to determine whether
|
||||||
// the document is sandboxed without permission to run scripts
|
// the document is sandboxed without permission to run scripts
|
||||||
// and whether inline scripts are blocked by the document's CSP.
|
// and whether inline scripts are blocked by the document's CSP.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче