Commit 2f6426ae authored by Mustafa Emre Acer's avatar Mustafa Emre Acer Committed by Commit Bot

Use the correct navigation event when checking for lookalike URL suggestions

The current code uses NavigationEntryCommitted, but it should have used
DidNavigationFinish instead.

Bug: 843361, 847662
Change-Id: Ie16016844e636a14c2114450a6e3b2a94cd2529b
Reviewed-on: https://chromium-review.googlesource.com/1197083Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Commit-Queue: Mustafa Emre Acer <meacer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587767}
parent 938e5bb1
...@@ -16,8 +16,7 @@ ...@@ -16,8 +16,7 @@
#include "components/omnibox/browser/autocomplete_match.h" #include "components/omnibox/browser/autocomplete_match.h"
#include "components/url_formatter/idn_spoof_checker.h" #include "components/url_formatter/idn_spoof_checker.h"
#include "components/url_formatter/url_formatter.h" #include "components/url_formatter/url_formatter.h"
#include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/navigation_entry.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
namespace { namespace {
...@@ -54,9 +53,18 @@ LookalikeUrlNavigationObserver::LookalikeUrlNavigationObserver( ...@@ -54,9 +53,18 @@ LookalikeUrlNavigationObserver::LookalikeUrlNavigationObserver(
LookalikeUrlNavigationObserver::~LookalikeUrlNavigationObserver() {} LookalikeUrlNavigationObserver::~LookalikeUrlNavigationObserver() {}
void LookalikeUrlNavigationObserver::NavigationEntryCommitted( void LookalikeUrlNavigationObserver::DidFinishNavigation(
const content::LoadCommittedDetails& load_details) { content::NavigationHandle* navigation_handle) {
const GURL url = load_details.entry->GetVirtualURL(); DCHECK(navigation_handle->IsInMainFrame());
// If the navigation was not committed, it means either the page was a
// download or error 204/205, or the navigation never left the previous
// URL. Basically, this isn't a problem since we stayed at the existing URL.
// Also ignore same document navigations.
if (!navigation_handle->HasCommitted() || navigation_handle->IsSameDocument())
return;
const GURL url = navigation_handle->GetURL();
// If the user has engaged with this site, don't show any lookalike // If the user has engaged with this site, don't show any lookalike
// navigation suggestions. // navigation suggestions.
Profile* profile = Profile* profile =
...@@ -91,8 +99,7 @@ void LookalikeUrlNavigationObserver::NavigationEntryCommitted( ...@@ -91,8 +99,7 @@ void LookalikeUrlNavigationObserver::NavigationEntryCommitted(
if (kMetricsOnly.Get().empty()) { if (kMetricsOnly.Get().empty()) {
RecordEvent(NavigationSuggestionEvent::kInfobarShown); RecordEvent(NavigationSuggestionEvent::kInfobarShown);
AlternateNavInfoBarDelegate::CreateForLookalikeUrlNavigation( AlternateNavInfoBarDelegate::CreateForLookalikeUrlNavigation(
web_contents(), base::UTF8ToUTF16(matched_domain), suggested_url, web_contents(), base::UTF8ToUTF16(matched_domain), suggested_url, url,
load_details.entry->GetVirtualURL(),
base::BindOnce(RecordEvent, NavigationSuggestionEvent::kLinkClicked)); base::BindOnce(RecordEvent, NavigationSuggestionEvent::kLinkClicked));
} }
} }
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h" #include "content/public/browser/web_contents_user_data.h"
namespace content {
class NavigationHandle;
}
class SiteEngagementService; class SiteEngagementService;
// Observes navigations and shows an infobar if the navigated domain name // Observes navigations and shows an infobar if the navigated domain name
...@@ -37,8 +41,8 @@ class LookalikeUrlNavigationObserver ...@@ -37,8 +41,8 @@ class LookalikeUrlNavigationObserver
~LookalikeUrlNavigationObserver() override; ~LookalikeUrlNavigationObserver() override;
// content::WebContentsObserver: // content::WebContentsObserver:
void NavigationEntryCommitted( void DidFinishNavigation(
const content::LoadCommittedDetails& load_details) override; content::NavigationHandle* navigation_handle) override;
private: private:
// Returns a site that the user has used before that |url| may be attempting // Returns a site that the user has used before that |url| may be attempting
......
...@@ -75,6 +75,17 @@ class LookalikeUrlNavigationObserverBrowserTest ...@@ -75,6 +75,17 @@ class LookalikeUrlNavigationObserverBrowserTest
->ResetBaseScoreForURL(url, score); ->ResetBaseScoreForURL(url, score);
} }
// Simulates a link click navigation. We don't use
// ui_test_utils::NavigateToURL(const GURL&) because it simulates the user
// typing the URL, causing the site to have a site engagement score of at
// least LOW.
void NavigateToURL(const GURL& url) {
NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK);
params.disposition = WindowOpenDisposition::CURRENT_TAB;
params.is_renderer_initiated = true;
ui_test_utils::NavigateToURL(&params);
}
void TestInfobarNotShown(const GURL& navigated_url) { void TestInfobarNotShown(const GURL& navigated_url) {
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
...@@ -82,7 +93,7 @@ class LookalikeUrlNavigationObserverBrowserTest ...@@ -82,7 +93,7 @@ class LookalikeUrlNavigationObserverBrowserTest
InfoBarService::FromWebContents(web_contents); InfoBarService::FromWebContents(web_contents);
content::TestNavigationObserver navigation_observer(web_contents, 1); content::TestNavigationObserver navigation_observer(web_contents, 1);
ui_test_utils::NavigateToURL(browser(), navigated_url); NavigateToURL(navigated_url);
navigation_observer.Wait(); navigation_observer.Wait();
EXPECT_EQ(0u, infobar_service->infobar_count()); EXPECT_EQ(0u, infobar_service->infobar_count());
} }
...@@ -105,7 +116,7 @@ class LookalikeUrlNavigationObserverBrowserTest ...@@ -105,7 +116,7 @@ class LookalikeUrlNavigationObserverBrowserTest
InfoBarService::FromWebContents(web_contents); InfoBarService::FromWebContents(web_contents);
InfoBarObserver infobar_added_observer( InfoBarObserver infobar_added_observer(
infobar_service, InfoBarObserver::Type::kInfoBarAdded); infobar_service, InfoBarObserver::Type::kInfoBarAdded);
ui_test_utils::NavigateToURL(browser(), navigated_url); NavigateToURL(navigated_url);
infobar_added_observer.Wait(); infobar_added_observer.Wait();
infobars::InfoBar* infobar = infobar_service->infobar_at(0); infobars::InfoBar* infobar = infobar_service->infobar_at(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment