Commit 02209401 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Do not use RequestInfo::source_url.

This argument has incorrect value when displaying SSL interstitial and
during provisional navigation. This CL replaces RequestInfo::source_url
usage with WebState::GetLastCommittedURL, which actually represents
page URL. RequestInfo::source_url will be deleted in a separate CL.

Bug: None
Test: App Launcher prompt works correctly.
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I0e320bd2d68df9eb96f5ca71c6e764bb12c6e7f5
Reviewed-on: https://chromium-review.googlesource.com/1217583Reviewed-by: default avatarMohammad Refaat <mrefaat@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593812}
parent b52ecff7
......@@ -201,28 +201,32 @@ bool AppLauncherTabHelper::ShouldAllowRequest(
request_url = [tab XCallbackFromRequestURL:request_url originURL:origin];
}
const GURL& source_url = request_info.source_url;
GURL last_committed_url = web_state_->GetLastCommittedURL();
web::NavigationItem* pending_item =
web_state_->GetNavigationManager()->GetPendingItem();
GURL original_pending_url =
pending_item ? pending_item->GetOriginalRequestURL() : GURL::EmptyGURL();
bool is_link_transition = ui::PageTransitionTypeIncludingQualifiersIs(
request_info.transition_type, ui::PAGE_TRANSITION_LINK);
if (base::FeatureList::IsEnabled(kAppLauncherRefresh)) {
if (!is_link_transition && source_url.is_valid()) {
if (!is_link_transition && original_pending_url.is_valid()) {
// At this stage the navigation will be canceled in all cases. If this
// was a redirection, the |source_url| may not have been reported to
// ReadingListWebStateObserver. Report it to mark as read if needed.
ReadingListModel* model =
ReadingListModelFactory::GetForBrowserState(tab.browserState);
if (model && model->loaded())
model->SetReadStatus(source_url, true);
model->SetReadStatus(original_pending_url, true);
}
if (IsValidAppUrl(request_url)) {
RequestToLaunchApp(request_url, source_url, is_link_transition);
if (IsValidAppUrl(request_url) && last_committed_url.is_valid()) {
RequestToLaunchApp(request_url, last_committed_url, is_link_transition);
}
return false;
}
if (IsValidAppUrl(request_url) &&
RequestToLaunchApp(request_url, source_url, is_link_transition)) {
RequestToLaunchApp(request_url, last_committed_url, is_link_transition)) {
// Clears pending navigation history after successfully launching the
// external app.
web_state_->GetNavigationManager()->DiscardNonCommittedItems();
......@@ -230,11 +234,11 @@ bool AppLauncherTabHelper::ShouldAllowRequest(
// When opening applications, the navigation is cancelled. Report the
// opening of the application to the ReadingListWebStateObserver to mark the
// entry as read if needed.
if (source_url.is_valid()) {
if (original_pending_url.is_valid()) {
ReadingListModel* model =
ReadingListModelFactory::GetForBrowserState(tab.browserState);
if (model && model->loaded())
model->SetReadStatus(source_url, true);
model->SetReadStatus(original_pending_url, true);
}
}
return false;
......
......@@ -113,7 +113,9 @@ class AppLauncherTabHelperTest : public PlatformTest {
delegate_);
// Allow is the default policy for this test.
abuse_detector_.policy = ExternalAppLaunchPolicyAllow;
web_state_.SetNavigationManager(std::make_unique<FakeNavigationManager>());
auto navigation_manager = std::make_unique<FakeNavigationManager>();
navigation_manager_ = navigation_manager.get();
web_state_.SetNavigationManager(std::move(navigation_manager));
tab_helper_ = AppLauncherTabHelper::FromWebState(&web_state_);
}
......@@ -151,12 +153,17 @@ class AppLauncherTabHelperTest : public PlatformTest {
if (!is_reading_list_initialized_)
InitializeReadingListModel();
GURL test_source_url("http://google.com");
web_state_.SetCurrentURL(GURL("https://chromium.org"));
GURL pending_url("http://google.com");
navigation_manager_->AddItem(pending_url, ui::PAGE_TRANSITION_LINK);
web::NavigationItem* item = navigation_manager_->GetItemAtIndex(0);
navigation_manager_->SetPendingItem(item);
item->SetOriginalRequestURL(pending_url);
ReadingListModel* model = ReadingListModelFactory::GetForBrowserState(
chrome_browser_state_.get());
EXPECT_TRUE(model->DeleteAllEntries());
model->AddEntry(test_source_url, "unread",
reading_list::ADDED_VIA_CURRENT_APP);
model->AddEntry(pending_url, "unread", reading_list::ADDED_VIA_CURRENT_APP);
abuse_detector_.policy = is_app_blocked ? ExternalAppLaunchPolicyBlock
: ExternalAppLaunchPolicyAllow;
ui::PageTransition transition_type =
......@@ -167,17 +174,19 @@ class AppLauncherTabHelperTest : public PlatformTest {
NSURL* url = [NSURL
URLWithString:@"itms-apps://itunes.apple.com/us/app/appname/id123"];
web::WebStatePolicyDecider::RequestInfo request_info(
transition_type, test_source_url,
transition_type, pending_url,
/*target_frame_is_main=*/true, /*has_user_gesture=*/true);
EXPECT_FALSE(tab_helper_->ShouldAllowRequest(
[NSURLRequest requestWithURL:url], request_info));
const ReadingListEntry* entry = model->GetEntryByURL(test_source_url);
const ReadingListEntry* entry = model->GetEntryByURL(pending_url);
return entry->IsRead() == expected_read_status;
}
base::test::ScopedTaskEnvironment scoped_task_environment;
web::TestWebState web_state_;
FakeNavigationManager* navigation_manager_ = nullptr;
std::unique_ptr<TestChromeBrowserState> chrome_browser_state_ = nil;
FakeAppLauncherAbuseDetector* abuse_detector_ = nil;
FakeAppLauncherTabHelperDelegate* delegate_ = nil;
......
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