Bug 1678618: Avoid firing extra events in NewTabUtils. r=mak

Depends on D101118

Differential Revision: https://phabricator.services.mozilla.com/D101119
This commit is contained in:
Daisuke Akatsuka 2021-02-15 02:47:39 +00:00
Родитель d41c3d5379
Коммит 8a680848fe
1 изменённых файлов: 10 добавлений и 44 удалений

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

@ -599,13 +599,7 @@ var PlacesProvider = {
this.handlePlacesEvents.bind(this)
);
PlacesObservers.addListener(
[
"page-visited",
"page-title-changed",
"history-cleared",
"pages-rank-changed",
"page-removed",
],
["page-visited", "page-title-changed", "pages-rank-changed"],
this._placesObserver
);
},
@ -707,55 +701,28 @@ var PlacesProvider = {
switch (event.type) {
case "page-visited": {
if (event.visitCount == 1 && event.lastKnownTitle) {
this.onTitleChanged(
event.url,
event.lastKnownTitle,
event.pageGuid
);
this._callObservers("onLinkChanged", {
url: event.url,
title: event.lastKnownTitle,
});
}
break;
}
case "page-title-changed": {
this.onTitleChanged(event.url, event.title, event.pageGuid);
break;
}
case "history-cleared": {
this.onClearHistory();
this._callObservers("onLinkChanged", {
url: event.url,
title: event.title,
});
break;
}
case "pages-rank-changed": {
this.onManyFrecenciesChanged();
break;
}
case "page-removed": {
if (event.isRemovedFromStore) {
this.onDeleteURI(event.url, event.pageGuid, event.reason);
}
this._callObservers("onManyLinksChanged");
break;
}
}
}
},
onDeleteURI: function PlacesProvider_onDeleteURI(aURI, aGUID, aReason) {
// let observers remove sensetive data associated with deleted visit
this._callObservers("onDeleteURI", {
url: aURI.spec,
});
},
onClearHistory() {
this._callObservers("onClearHistory");
},
onManyFrecenciesChanged() {
this._callObservers("onManyLinksChanged");
},
onTitleChanged(url, title, guid) {
this._callObservers("onLinkChanged", { url, title });
},
_callObservers: function PlacesProvider__callObservers(aMethodName, aArg) {
for (let obs of this._observers) {
if (obs[aMethodName]) {
@ -2378,7 +2345,6 @@ var NewTabUtils = {
allPages: AllPages,
pinnedLinks: PinnedLinks,
blockedLinks: BlockedLinks,
placesProvider: PlacesProvider,
activityStreamLinks: ActivityStreamLinks,
activityStreamProvider: ActivityStreamProvider,
};