Skip to content

Commit

Permalink
[ads] Fixes NotifyTab[Text|Html]ContentDidChange are not triggered …
Browse files Browse the repository at this point in the history
…for domains blocked by aggressive tracker and ad blocking
  • Loading branch information
tmancey committed Oct 14, 2024
1 parent f6d9165 commit 361f15b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions browser/brave_ads/tabs/ads_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "components/sessions/content/session_tab_helper.h"
#include "components/sessions/core/session_id.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/page.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "net/http/http_response_headers.h"
Expand Down Expand Up @@ -327,6 +328,18 @@ void AdsTabHelper::MaybeNotifyTabdidClose() {
}
}

void AdsTabHelper::PrimaryPageChanged(content::Page& page) {
if (!ads_service_) {
// No-op if the ads service is unavailable.
return;
}

// Calling `ResetNavigationState` from `DidStartNavigation` causes an issue
// where `NotifyTab[Text|Html]ContentDidChange` is not triggered when a user
// enables aggressive tracker and ad blocking, then proceeds to the page.
ResetNavigationState();
}

void AdsTabHelper::DidStartNavigation(
content::NavigationHandle* navigation_handle) {
if (!ads_service_ || !navigation_handle->IsInPrimaryMainFrame()) {
Expand Down
1 change: 1 addition & 0 deletions browser/brave_ads/tabs/ads_tab_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class AdsTabHelper : public content::WebContentsObserver,
void MaybeNotifyTabdidClose();

// content::WebContentsObserver:
void PrimaryPageChanged(content::Page& page) override;
void DidStartNavigation(
content::NavigationHandle* navigation_handle) override;
void DidFinishNavigation(
Expand Down

0 comments on commit 361f15b

Please sign in to comment.