Files
palemoon27/gfx/layers/ipc/RemoteContentController.cpp
T
roytam1 18db03a181 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1249280 - Fix coordinates of APZ-detected gestures when crossing process boundaries. r=kats (090ebc1700)
- Bug 1245016 - b2g build failure in gfx/layers/ipc/LayerAnimationUtils.h r=hiro (a577fdc500)
- 10.5 & 10.6 compatibility (72e2c45a47)
- Bug 1157018 - NsckPuk and PckPuk lock types that should require PUK instead require PIN. r=echen (7a5e5e0fe1)
- Bug 1218721 - Part 1 - Always Insert Name/Number when Providing IccContact Response. r=echen (5348f2b567)
- Bug 1213785 - Fixed test_icc_contact_add.js and test_icc_contact_update.js testcases timeout. r=echen (fb2020a04e)
- Bug 1218721 - Part 2 - Improve Test Coverage. r=echen (124bd4761b)
- Bug 1195273 - Suppress assertion check in ~ErrorResult() if no exception to be thrown. r=echen (c49167db1e)
- Bug 1189884 - Read/Update ANR of SIM Contact Properly. r=echen (037f45bad6)
- Bug 1172873 - Suppress the notification of STK proactive command if there is no Icc detected. r=echen (9099119665)
- var-let (0d751e9ded)
- Bug 1213766 - modify tests to match emulator's new mcc/mnc. r=echen (443412df79)
- Bug 1244480, don't throw when passing random value as the second argument to canvas.getContext, r=bz (892beb551d)
- Bug 591737 - Add pref for details and summary elements. r=bz (20865b31d9)
- remove HTMLSummaryElement binding (c55d1c1e41)
- Bug 1246185 - Do not collapsed <details> when preference off. r=bz (38bba73df0)
- more SummaryElement cleanup (e567f0a554)
- Bug 1176849 - Make the file picker fatally assert if any of the objects returned by the file picker are not nsIDOMBlob objects. r=baku (519cae0e25)
- Bug 1201106 - Make sure that HTMLInputElement.files is always null if the 'directory' attribute is set. r=baku (7a707c3bdc)
- Bug 1239280 - HTMLInputElement::GetFiles should work also if 'directory' attribute is set, r=smaug (fd18ef9377)
- Bug 1207570 - Make HTMLInputElement::GetFilesAndDirectories throw when the type is not file. r=baku (7cf1efc3ec)
- Bug 1238433 - Added telemetry for the proportion of dropped frames. r=cpearce, f=bsmedberg (92af25de66)
- Bug 1240478 - Remove Mutex from MediaStreamSizeListener. r=jesup (b042225707)
- Bug 1240478 - Have MediaStreamSizeListener active immediately, until the initial size is known. r=jesup (6094996687)
- Bug 1241405 - reset mCurrentPlayRangeStart in AbortExistingLoads(). r=jya. (93eb8e67ed)
- Bug 1224936 - AudioChannelAgent should be informed when HTMLMediaElement dispatches an error, r=roc (4f6425922d)
- Bug 1238906 - part1 : check whether audio data is audible. r=jwwang (0ef051dc27)
- Bug 1238906 - part2 : notify audible state from MDSM to ME. r=jwwang (125829a019)
- Bug 1245982 - Added telemetry for the number of uses of HTMLMediaElement.fastSeek(). r=cpearce (34f4bd5490)
- Bug 1233274 - Don't shutdown detached MediaKeys. r=gerald (d73512a2b1)
- Bug 1237616 - Remove the aForceBuffering arugment from MediaDecoder::Resume(). r=cpearce. (97eb603c20)
- Bug 1246521: P1. Add MediaDecoderOwner::HasError method. r=gerald (605905c959)
- Bug 1246521: P2. Add MediaDecoder::OwnerHasError method. r=gerald (0794b84bc2)
- Bug 1246521: [MSE] P3. Only error during Prepare Append algorithm if the media element is in error. r=gerald (5e5f48c50b)
- Bug 1235411 - Remove IsCallerChrome check in HTMLMediaElement::Observe. r=khuey (b68191da8e)
2024-01-05 09:55:04 +08:00

387 lines
12 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/layers/RemoteContentController.h"
#include "base/message_loop.h"
#include "base/task.h"
#include "MainThreadUtils.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/TabParent.h"
#include "mozilla/layers/APZCTreeManager.h"
#include "mozilla/layers/APZThreadUtils.h"
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layout/RenderFrameParent.h"
#include "mozilla/unused.h"
#include "Units.h"
#ifdef MOZ_WIDGET_ANDROID
#include "AndroidBridge.h"
#endif
namespace mozilla {
namespace layers {
RemoteContentController::RemoteContentController(uint64_t aLayersId,
dom::TabParent* aBrowserParent)
: mUILoop(MessageLoop::current())
, mLayersId(aLayersId)
, mBrowserParent(aBrowserParent)
, mMutex("RemoteContentController")
{
MOZ_ASSERT(NS_IsMainThread());
}
RemoteContentController::~RemoteContentController()
{
if (mBrowserParent) {
Unused << PAPZParent::Send__delete__(this);
}
}
void
RemoteContentController::RequestContentRepaint(const FrameMetrics& aFrameMetrics)
{
MOZ_ASSERT(NS_IsMainThread());
if (CanSend()) {
Unused << SendUpdateFrame(aFrameMetrics);
}
}
void
RemoteContentController::RequestFlingSnap(const FrameMetrics::ViewID& aScrollId,
const mozilla::CSSPoint& aDestination)
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::RequestFlingSnap,
aScrollId, aDestination));
return;
}
if (CanSend()) {
Unused << SendRequestFlingSnap(aScrollId, aDestination);
}
}
void
RemoteContentController::AcknowledgeScrollUpdate(const FrameMetrics::ViewID& aScrollId,
const uint32_t& aScrollGeneration)
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::AcknowledgeScrollUpdate,
aScrollId, aScrollGeneration));
return;
}
if (CanSend()) {
Unused << SendAcknowledgeScrollUpdate(aScrollId, aScrollGeneration);
}
}
void
RemoteContentController::HandleDoubleTap(const CSSPoint& aPoint,
Modifiers aModifiers,
const ScrollableLayerGuid& aGuid)
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::HandleDoubleTap,
aPoint, aModifiers, aGuid));
return;
}
if (CanSend()) {
Unused << SendHandleDoubleTap(mBrowserParent->AdjustTapToChildWidget(aPoint),
aModifiers, aGuid);
}
}
void
RemoteContentController::HandleSingleTap(const CSSPoint& aPoint,
Modifiers aModifiers,
const ScrollableLayerGuid& aGuid)
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::HandleSingleTap,
aPoint, aModifiers, aGuid));
return;
}
bool callTakeFocusForClickFromTap;
layout::RenderFrameParent* frame;
if (mBrowserParent && (frame = mBrowserParent->GetRenderFrame()) &&
mLayersId == frame->GetLayersId()) {
// Avoid going over IPC and back for calling TakeFocusForClickFromTap,
// since the right RenderFrameParent is living in this process.
frame->TakeFocusForClickFromTap();
callTakeFocusForClickFromTap = false;
} else {
callTakeFocusForClickFromTap = true;
}
if (CanSend()) {
Unused << SendHandleSingleTap(mBrowserParent->AdjustTapToChildWidget(aPoint),
aModifiers, aGuid, callTakeFocusForClickFromTap);
}
}
void
RemoteContentController::HandleLongTap(const CSSPoint& aPoint,
Modifiers aModifiers,
const ScrollableLayerGuid& aGuid,
uint64_t aInputBlockId)
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::HandleLongTap,
aPoint, aModifiers, aGuid, aInputBlockId));
return;
}
if (CanSend()) {
Unused << SendHandleLongTap(mBrowserParent->AdjustTapToChildWidget(aPoint),
aModifiers, aGuid, aInputBlockId);
}
}
void
RemoteContentController::PostDelayedTask(Task* aTask, int aDelayMs)
{
#ifdef MOZ_ANDROID_APZ
AndroidBridge::Bridge()->PostTaskToUiThread(aTask, aDelayMs);
#else
(MessageLoop::current() ? MessageLoop::current() : mUILoop)->
PostDelayedTask(FROM_HERE, aTask, aDelayMs);
#endif
}
bool
RemoteContentController::GetTouchSensitiveRegion(CSSRect* aOutRegion)
{
MutexAutoLock lock(mMutex);
if (mTouchSensitiveRegion.IsEmpty()) {
return false;
}
*aOutRegion = CSSRect::FromAppUnits(mTouchSensitiveRegion.GetBounds());
return true;
}
void
RemoteContentController::NotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
APZStateChange aChange,
int aArg)
{
if (MessageLoop::current() != mUILoop) {
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::NotifyAPZStateChange,
aGuid, aChange, aArg));
return;
}
if (CanSend()) {
Unused << SendNotifyAPZStateChange(aGuid.mScrollId, aChange, aArg);
}
}
void
RemoteContentController::NotifyMozMouseScrollEvent(const FrameMetrics::ViewID& aScrollId,
const nsString& aEvent)
{
if (MessageLoop::current() != mUILoop) {
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::NotifyMozMouseScrollEvent,
aScrollId, aEvent));
return;
}
if (mBrowserParent) {
Unused << mBrowserParent->SendMouseScrollTestEvent(mLayersId, aScrollId, aEvent);
}
}
void
RemoteContentController::NotifyFlushComplete()
{
MOZ_ASSERT(NS_IsMainThread());
if (CanSend()) {
Unused << SendNotifyFlushComplete();
}
}
bool
RemoteContentController::RecvUpdateHitRegion(const nsRegion& aRegion)
{
MutexAutoLock lock(mMutex);
mTouchSensitiveRegion = aRegion;
return true;
}
bool
RemoteContentController::RecvZoomToRect(const uint32_t& aPresShellId,
const ViewID& aViewId,
const CSSRect& aRect,
const uint32_t& aFlags)
{
if (RefPtr<APZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
apzcTreeManager->ZoomToRect(ScrollableLayerGuid(mLayersId, aPresShellId, aViewId),
aRect, aFlags);
}
return true;
}
bool
RemoteContentController::RecvContentReceivedInputBlock(const ScrollableLayerGuid& aGuid,
const uint64_t& aInputBlockId,
const bool& aPreventDefault)
{
if (aGuid.mLayersId != mLayersId) {
// Guard against bad data from hijacked child processes
NS_ERROR("Unexpected layers id in RecvContentReceivedInputBlock; dropping message...");
return false;
}
if (RefPtr<APZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
apzcTreeManager.get(), &APZCTreeManager::ContentReceivedInputBlock,
aInputBlockId, aPreventDefault));
}
return true;
}
bool
RemoteContentController::RecvStartScrollbarDrag(const AsyncDragMetrics& aDragMetrics)
{
if (RefPtr<APZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
ScrollableLayerGuid guid(mLayersId, aDragMetrics.mPresShellId,
aDragMetrics.mViewId);
APZThreadUtils::RunOnControllerThread(
NewRunnableMethod(apzcTreeManager.get(),
&APZCTreeManager::StartScrollbarDrag,
guid, aDragMetrics));
}
return true;
}
bool
RemoteContentController::RecvSetTargetAPZC(const uint64_t& aInputBlockId,
nsTArray<ScrollableLayerGuid>&& aTargets)
{
for (size_t i = 0; i < aTargets.Length(); i++) {
if (aTargets[i].mLayersId != mLayersId) {
// Guard against bad data from hijacked child processes
NS_ERROR("Unexpected layers id in SetTargetAPZC; dropping message...");
return false;
}
}
if (RefPtr<APZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
// need a local var to disambiguate between the SetTargetAPZC overloads.
void (APZCTreeManager::*setTargetApzcFunc)(uint64_t, const nsTArray<ScrollableLayerGuid>&)
= &APZCTreeManager::SetTargetAPZC;
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
apzcTreeManager.get(), setTargetApzcFunc,
aInputBlockId, aTargets));
}
return true;
}
bool
RemoteContentController::RecvSetAllowedTouchBehavior(const uint64_t& aInputBlockId,
nsTArray<TouchBehaviorFlags>&& aFlags)
{
if (RefPtr<APZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
apzcTreeManager.get(), &APZCTreeManager::SetAllowedTouchBehavior,
aInputBlockId, Move(aFlags)));
}
return true;
}
bool
RemoteContentController::RecvUpdateZoomConstraints(const uint32_t& aPresShellId,
const ViewID& aViewId,
const MaybeZoomConstraints& aConstraints)
{
if (RefPtr<APZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
apzcTreeManager->UpdateZoomConstraints(ScrollableLayerGuid(mLayersId, aPresShellId, aViewId),
aConstraints);
}
return true;
}
void
RemoteContentController::ActorDestroy(ActorDestroyReason aWhy)
{
{
MutexAutoLock lock(mMutex);
mApzcTreeManager = nullptr;
}
mBrowserParent = nullptr;
}
// TODO: Remove once upgraded to GCC 4.8+ on linux. Calling a static member
// function (like PAPZParent::Send__delete__) in a lambda leads to a bogus
// error: "'this' was not captured for this lambda function".
//
// (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51494)
static void
DeletePAPZParent(PAPZParent* aPAPZ)
{
Unused << PAPZParent::Send__delete__(aPAPZ);
}
void
RemoteContentController::Destroy()
{
RefPtr<RemoteContentController> controller = this;
NS_DispatchToMainThread(NS_NewRunnableFunction([controller] {
if (controller->CanSend()) {
DeletePAPZParent(controller);
}
}));
}
void
RemoteContentController::ChildAdopted()
{
// Clear the cached APZCTreeManager.
MutexAutoLock lock(mMutex);
mApzcTreeManager = nullptr;
}
already_AddRefed<APZCTreeManager>
RemoteContentController::GetApzcTreeManager()
{
// We can't get a ref to the APZCTreeManager until after the child is
// created and the static getter knows which CompositorParent is
// instantiated with this layers ID. That's why try to fetch it when
// we first need it and cache the result.
MutexAutoLock lock(mMutex);
if (!mApzcTreeManager) {
mApzcTreeManager = CompositorParent::GetAPZCTreeManager(mLayersId);
}
RefPtr<APZCTreeManager> apzcTreeManager(mApzcTreeManager);
return apzcTreeManager.forget();
}
} // namespace layers
} // namespace mozilla