Bug 1510569 - Refactor BrowserParent nsIWebProgress handlers r=kmag

The BrowserParent's IPC receive methods for nsIWebProgress events in the
BrowserChild were all doing the same set up to ensure they had the correct
state to process them. This has now been refactored out into a single method.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Barret Rennie 2019-05-24 15:45:05 +00:00
Родитель cf23208d84
Коммит bda47d9434
2 изменённых файлов: 58 добавлений и 51 удалений

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

@ -2379,22 +2379,11 @@ mozilla::ipc::IPCResult BrowserParent::RecvOnProgressChange(
const RequestData& aRequestData, const int32_t aCurSelfProgress,
const int32_t aMaxSelfProgress, const int32_t aCurTotalProgress,
const int32_t aMaxTotalProgress) {
nsCOMPtr<nsIBrowser> browser =
mFrameElement ? mFrameElement->AsBrowser() : nullptr;
if (!browser) {
return IPC_OK();
}
nsCOMPtr<nsIBrowser> browser;
nsCOMPtr<nsIWebProgress> manager;
nsresult rv = browser->GetRemoteWebProgressManager(getter_AddRefs(manager));
NS_ENSURE_SUCCESS(rv, IPC_OK());
nsCOMPtr<nsIWebProgressListener> managerAsListener =
do_QueryInterface(manager);
if (!managerAsListener) {
// We are no longer remote, so we cannot propagate this message.
nsCOMPtr<nsIWebProgressListener> managerAsListener;
if (!GetWebProgressListener(getter_AddRefs(browser), getter_AddRefs(manager),
getter_AddRefs(managerAsListener))) {
return IPC_OK();
}
@ -2414,22 +2403,11 @@ mozilla::ipc::IPCResult BrowserParent::RecvOnStatusChange(
const Maybe<WebProgressData>& aWebProgressData,
const RequestData& aRequestData, const nsresult aStatus,
const nsString& aMessage) {
nsCOMPtr<nsIBrowser> browser =
mFrameElement ? mFrameElement->AsBrowser() : nullptr;
if (!browser) {
return IPC_OK();
}
nsCOMPtr<nsIBrowser> browser;
nsCOMPtr<nsIWebProgress> manager;
nsresult rv = browser->GetRemoteWebProgressManager(getter_AddRefs(manager));
NS_ENSURE_SUCCESS(rv, IPC_OK());
nsCOMPtr<nsIWebProgressListener> managerAsListener =
do_QueryInterface(manager);
if (!managerAsListener) {
// We are no longer remote, so we cannot propagate this message.
nsCOMPtr<nsIWebProgressListener> managerAsListener;
if (!GetWebProgressListener(getter_AddRefs(browser), getter_AddRefs(manager),
getter_AddRefs(managerAsListener))) {
return IPC_OK();
}
@ -2447,32 +2425,57 @@ mozilla::ipc::IPCResult BrowserParent::RecvOnStatusChange(
mozilla::ipc::IPCResult BrowserParent::RecvOnContentBlockingEvent(
const Maybe<WebProgressData>& aWebProgressData,
const RequestData& aRequestData, const uint32_t& aEvent) {
nsCOMPtr<nsIBrowser> browser =
mFrameElement ? mFrameElement->AsBrowser() : nullptr;
if (browser) {
nsCOMPtr<nsIWebProgress> manager;
nsresult rv = browser->GetRemoteWebProgressManager(getter_AddRefs(manager));
NS_ENSURE_SUCCESS(rv, IPC_OK());
nsCOMPtr<nsIWebProgressListener> managerAsListener =
do_QueryInterface(manager);
if (!managerAsListener) {
// We are no longer remote, so we cannot propagate this message.
return IPC_OK();
}
nsCOMPtr<nsIWebProgress> webProgress;
nsCOMPtr<nsIRequest> request;
ReconstructWebProgressAndRequest(manager, aWebProgressData, aRequestData,
webProgress, request);
Unused << managerAsListener->OnContentBlockingEvent(webProgress, request,
aEvent);
nsCOMPtr<nsIBrowser> browser;
nsCOMPtr<nsIWebProgress> manager;
nsCOMPtr<nsIWebProgressListener> managerAsListener;
if (!GetWebProgressListener(getter_AddRefs(browser), getter_AddRefs(manager),
getter_AddRefs(managerAsListener))) {
return IPC_OK();
}
nsCOMPtr<nsIWebProgress> webProgress;
nsCOMPtr<nsIRequest> request;
ReconstructWebProgressAndRequest(manager, aWebProgressData, aRequestData,
webProgress, request);
Unused << managerAsListener->OnContentBlockingEvent(webProgress, request,
aEvent);
return IPC_OK();
}
bool BrowserParent::GetWebProgressListener(
nsIBrowser** aOutBrowser, nsIWebProgress** aOutManager,
nsIWebProgressListener** aOutListener) {
MOZ_ASSERT(aOutBrowser);
MOZ_ASSERT(aOutManager);
MOZ_ASSERT(aOutListener);
nsCOMPtr<nsIBrowser> browser =
mFrameElement ? mFrameElement->AsBrowser() : nullptr;
if (!browser) {
return false;
}
nsCOMPtr<nsIWebProgress> manager;
nsresult rv = browser->GetRemoteWebProgressManager(getter_AddRefs(manager));
if (NS_FAILED(rv)) {
return false;
}
nsCOMPtr<nsIWebProgressListener> listener = do_QueryInterface(manager);
if (!listener) {
// We are no longer remote so we cannot forward this event.
return false;
}
browser.forget(aOutBrowser);
manager.forget(aOutManager);
listener.forget(aOutListener);
return true;
}
void BrowserParent::ReconstructWebProgressAndRequest(
nsIWebProgress* aManager, const Maybe<WebProgressData>& aWebProgressData,
const RequestData& aRequestData, nsCOMPtr<nsIWebProgress>& aOutWebProgress,

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

@ -284,6 +284,10 @@ class BrowserParent final : public PBrowserParent,
const Maybe<WebProgressData>& aWebProgressData,
const RequestData& aRequestData, const uint32_t& aEvent);
bool GetWebProgressListener(nsIBrowser** aOutBrowser,
nsIWebProgress** aOutManager,
nsIWebProgressListener** aOutListener);
void ReconstructWebProgressAndRequest(
nsIWebProgress* aManager, const Maybe<WebProgressData>& aWebProgressData,
const RequestData& aRequestData,