Bug 1596317 - Change the function pointer argument of nsContentUtils::CallOnAllRemoteChildren to std::function. r=smaug

We are going to introduce a new function in Document in this commit series,
which enumerates all child documents regardless of whether it's in the same
process, in content processes or in out-of-process iframes. The function takes
std::functions, but I don't have any good ideas to convert lambda functions with
capturing variables to function pointer.

Differential Revision: https://phabricator.services.mozilla.com/D57434

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Hiroyuki Ikezoe 2019-12-19 07:57:57 +00:00
parent 11f2716492
commit aec08b91cc
6 changed files with 62 additions and 88 deletions

View File

@ -7038,8 +7038,8 @@ nsresult nsContentUtils::GetHostOrIPv6WithBrackets(nsIURI* aURI,
}
bool nsContentUtils::CallOnAllRemoteChildren(
MessageBroadcaster* aManager, CallOnRemoteChildFunction aCallback,
void* aArg) {
MessageBroadcaster* aManager,
const std::function<bool(BrowserParent*)>& aCallback) {
uint32_t browserChildCount = aManager->ChildCount();
for (uint32_t j = 0; j < browserChildCount; ++j) {
RefPtr<MessageListenerManager> childMM = aManager->GetChildAt(j);
@ -7049,7 +7049,7 @@ bool nsContentUtils::CallOnAllRemoteChildren(
RefPtr<MessageBroadcaster> nonLeafMM = MessageBroadcaster::From(childMM);
if (nonLeafMM) {
if (CallOnAllRemoteChildren(nonLeafMM, aCallback, aArg)) {
if (CallOnAllRemoteChildren(nonLeafMM, aCallback)) {
return true;
}
continue;
@ -7060,7 +7060,7 @@ bool nsContentUtils::CallOnAllRemoteChildren(
nsFrameLoader* fl = static_cast<nsFrameLoader*>(cb);
BrowserParent* remote = BrowserParent::GetFrom(fl);
if (remote && aCallback) {
if (aCallback(remote, aArg)) {
if (aCallback(remote)) {
return true;
}
}
@ -7071,13 +7071,13 @@ bool nsContentUtils::CallOnAllRemoteChildren(
}
void nsContentUtils::CallOnAllRemoteChildren(
nsPIDOMWindowOuter* aWindow, CallOnRemoteChildFunction aCallback,
void* aArg) {
nsPIDOMWindowOuter* aWindow,
const std::function<bool(BrowserParent*)>& aCallback) {
nsGlobalWindowOuter* window = nsGlobalWindowOuter::Cast(aWindow);
if (window->IsChromeWindow()) {
RefPtr<MessageBroadcaster> windowMM = window->GetMessageManager();
if (windowMM) {
CallOnAllRemoteChildren(windowMM, aCallback, aArg);
CallOnAllRemoteChildren(windowMM, aCallback);
}
}
}
@ -7089,17 +7089,14 @@ struct UIStateChangeInfo {
: mShowFocusRings(aShowFocusRings) {}
};
bool SetKeyboardIndicatorsChild(BrowserParent* aParent, void* aArg) {
UIStateChangeInfo* stateInfo = static_cast<UIStateChangeInfo*>(aArg);
Unused << aParent->SendSetKeyboardIndicators(stateInfo->mShowFocusRings);
return false;
}
void nsContentUtils::SetKeyboardIndicatorsOnRemoteChildren(
nsPIDOMWindowOuter* aWindow, UIStateChangeType aShowFocusRings) {
UIStateChangeInfo stateInfo(aShowFocusRings);
CallOnAllRemoteChildren(aWindow, SetKeyboardIndicatorsChild,
(void*)&stateInfo);
CallOnAllRemoteChildren(aWindow, [&stateInfo](BrowserParent* aBrowserParent) {
Unused << aBrowserParent->SendSetKeyboardIndicators(
stateInfo.mShowFocusRings);
return false;
});
}
nsresult nsContentUtils::IPCTransferableToTransferable(

View File

@ -204,9 +204,6 @@ struct EventNameMapping {
bool mMaybeSpecialSVGorSMILEvent;
};
typedef bool (*CallOnRemoteChildFunction)(
mozilla::dom::BrowserParent* aBrowserParent, void* aArg);
class nsContentUtils {
friend class nsAutoScriptBlockerSuppressNodeRemoved;
typedef mozilla::dom::Element Element;
@ -2742,9 +2739,9 @@ class nsContentUtils {
* Call the given callback on all remote children of the given top-level
* window. Return true from the callback to stop calling further children.
*/
static void CallOnAllRemoteChildren(nsPIDOMWindowOuter* aWindow,
CallOnRemoteChildFunction aCallback,
void* aArg);
static void CallOnAllRemoteChildren(
nsPIDOMWindowOuter* aWindow,
const std::function<bool(mozilla::dom::BrowserParent*)>& aCallback);
/*
* Call nsPIDOMWindow::SetKeyboardIndicators all all remote children. This is
@ -3221,7 +3218,7 @@ class nsContentUtils {
static bool CallOnAllRemoteChildren(
mozilla::dom::MessageBroadcaster* aManager,
CallOnRemoteChildFunction aCallback, void* aArg);
const std::function<bool(mozilla::dom::BrowserParent*)>& aCallback);
static nsINode* GetCommonAncestorHelper(nsINode* aNode1, nsINode* aNode2);
static nsIContent* GetCommonFlattenedTreeAncestorHelper(

View File

@ -1104,12 +1104,6 @@ void nsFocusManager::EnsureCurrentWidgetFocused() {
widget->SetFocus(nsIWidget::Raise::No);
}
bool ActivateOrDeactivateChild(BrowserParent* aParent, void* aArg) {
bool active = static_cast<bool>(aArg);
Unused << aParent->SendParentActivated(active);
return false;
}
void nsFocusManager::ActivateOrDeactivate(nsPIDOMWindowOuter* aWindow,
bool aActive) {
if (!aWindow) {
@ -1131,8 +1125,11 @@ void nsFocusManager::ActivateOrDeactivate(nsPIDOMWindowOuter* aWindow,
// Look for any remote child frames, iterate over them and send the activation
// notification.
nsContentUtils::CallOnAllRemoteChildren(aWindow, ActivateOrDeactivateChild,
(void*)aActive);
nsContentUtils::CallOnAllRemoteChildren(
aWindow, [&aActive](BrowserParent* aBrowserParent) -> bool {
Unused << aBrowserParent->SendParentActivated(aActive);
return false;
});
}
void nsFocusManager::SetFocusInner(Element* aNewContent, int32_t aFlags,

View File

@ -1126,27 +1126,6 @@ struct MOZ_STACK_CLASS AccessKeyInfo {
: event(aEvent), charCodes(aCharCodes) {}
};
static bool HandleAccessKeyInRemoteChild(BrowserParent* aBrowserParent,
void* aArg) {
AccessKeyInfo* accessKeyInfo = static_cast<AccessKeyInfo*>(aArg);
// Only forward accesskeys for the active tab.
if (aBrowserParent->GetDocShellIsActive()) {
// Even if there is no target for the accesskey in this process,
// the event may match with a content accesskey. If so, the keyboard
// event should be handled with reply event for preventing double action.
// (e.g., Alt+Shift+F on Windows may focus a content in remote and open
// "File" menu.)
accessKeyInfo->event->StopPropagation();
accessKeyInfo->event->MarkAsWaitingReplyFromRemoteProcess();
aBrowserParent->HandleAccessKey(*accessKeyInfo->event,
accessKeyInfo->charCodes);
return true;
}
return false;
}
bool EventStateManager::WalkESMTreeToHandleAccessKey(
WidgetKeyboardEvent* aEvent, nsPresContext* aPresContext,
nsTArray<uint32_t>& aAccessCharCodes, nsIDocShellTreeItem* aBubbledFrom,
@ -1257,7 +1236,24 @@ bool EventStateManager::WalkESMTreeToHandleAccessKey(
else if (!aEvent->IsHandledInRemoteProcess()) {
AccessKeyInfo accessKeyInfo(aEvent, aAccessCharCodes);
nsContentUtils::CallOnAllRemoteChildren(
mDocument->GetWindow(), HandleAccessKeyInRemoteChild, &accessKeyInfo);
mDocument->GetWindow(),
[&accessKeyInfo](BrowserParent* aBrowserParent) -> bool {
// Only forward accesskeys for the active tab.
if (aBrowserParent->GetDocShellIsActive()) {
// Even if there is no target for the accesskey in this process,
// the event may match with a content accesskey. If so, the
// keyboard event should be handled with reply event for
// preventing double action. (e.g., Alt+Shift+F on Windows may
// focus a content in remote and open "File" menu.)
accessKeyInfo.event->StopPropagation();
accessKeyInfo.event->MarkAsWaitingReplyFromRemoteProcess();
aBrowserParent->HandleAccessKey(*accessKeyInfo.event,
accessKeyInfo.charCodes);
return true;
}
return false;
});
}
}

View File

@ -1297,11 +1297,6 @@ void nsPresContext::ThemeChanged() {
}
}
static bool NotifyThemeChanged(BrowserParent* aBrowserParent, void* aArg) {
aBrowserParent->ThemeChanged();
return false;
}
void nsPresContext::ThemeChangedInternal() {
mPendingThemeChanged = false;
@ -1329,8 +1324,11 @@ void nsPresContext::ThemeChangedInternal() {
// Recursively notify all remote leaf descendants that the
// system theme has changed.
if (nsPIDOMWindowOuter* window = mDocument->GetWindow()) {
nsContentUtils::CallOnAllRemoteChildren(window, NotifyThemeChanged,
nullptr);
nsContentUtils::CallOnAllRemoteChildren(
window, [](BrowserParent* aBrowserParent) -> bool {
aBrowserParent->ThemeChanged();
return false;
});
}
}
@ -1597,16 +1595,13 @@ void nsPresContext::FlushPendingMediaFeatureValuesChanged() {
}
}
static bool NotifyTabSizeModeChanged(BrowserParent* aTab, void* aArg) {
nsSizeMode* sizeMode = static_cast<nsSizeMode*>(aArg);
aTab->SizeModeChanged(*sizeMode);
return false;
}
void nsPresContext::SizeModeChanged(nsSizeMode aSizeMode) {
if (nsPIDOMWindowOuter* window = mDocument->GetWindow()) {
nsContentUtils::CallOnAllRemoteChildren(window, NotifyTabSizeModeChanged,
&aSizeMode);
nsContentUtils::CallOnAllRemoteChildren(
window, [&aSizeMode](BrowserParent* aBrowserParent) -> bool {
aBrowserParent->SizeModeChanged(aSizeMode);
return false;
});
}
MediaFeatureValuesChangedAllDocuments(
{MediaFeatureChangeReason::SizeModeChange});

View File

@ -968,13 +968,6 @@ bool nsView::WindowResized(nsIWidget* aWidget, int32_t aWidth,
}
#if defined(MOZ_WIDGET_ANDROID)
static bool NotifyDynamicToolbarMaxHeightChanged(
dom::BrowserParent* aBrowserParent, void* aArg) {
ScreenIntCoord* height = static_cast<ScreenIntCoord*>(aArg);
aBrowserParent->DynamicToolbarMaxHeightChanged(*height);
return false;
}
void nsView::DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight) {
MOZ_ASSERT(XRE_IsParentProcess(),
"Should be only called for the browser parent process");
@ -997,19 +990,10 @@ void nsView::DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight) {
}
nsContentUtils::CallOnAllRemoteChildren(
window, NotifyDynamicToolbarMaxHeightChanged, &aHeight);
}
static bool NotifyDynamicToolbarOffsetChanged(
dom::BrowserParent* aBrowserParent, void* aArg) {
// Skip background tabs.
if (!aBrowserParent->GetDocShellIsActive()) {
return false;
}
ScreenIntCoord* offset = static_cast<ScreenIntCoord*>(aArg);
aBrowserParent->DynamicToolbarOffsetChanged(*offset);
return true;
window, [&aHeight](dom::BrowserParent* aBrowserParent) -> bool {
aBrowserParent->DynamicToolbarMaxHeightChanged(aHeight);
return false;
});
}
void nsView::DynamicToolbarOffsetChanged(ScreenIntCoord aOffset) {
@ -1034,7 +1018,15 @@ void nsView::DynamicToolbarOffsetChanged(ScreenIntCoord aOffset) {
}
nsContentUtils::CallOnAllRemoteChildren(
window, NotifyDynamicToolbarOffsetChanged, &aOffset);
window, [&aOffset](dom::BrowserParent* aBrowserParent) -> bool {
// Skip background tabs.
if (!aBrowserParent->GetDocShellIsActive()) {
return false;
}
aBrowserParent->DynamicToolbarOffsetChanged(aOffset);
return true;
});
}
#endif