forked from chromium/chromium
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show reader mode as contextual page action
This CL adds - The ability to show reader mode as a CPA using TabDistillabilityProvider. - Adds a standard interface called ActionProvider to query individual backends. - Adds concept of timeout. Introduced a SignalAccumulator to track signals and timeout together. TODO: - Add filtering criteria to show reader mode less often such as restricting reader mode to once per tab, not showing for already dismissed sites - Hookup reader mode button click to reader mode manager. (cherry picked from commit d8786b0) Bug: 1373444 Change-Id: Ib51df70a55d8dcef7dd82eb16accbd5ac326be00 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3927965 Commit-Queue: Shakti Sahu <shaktisahu@chromium.org> Reviewed-by: Salvador Guerrero Ramos <salg@google.com> Cr-Original-Commit-Position: refs/heads/main@{#1059013} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3962153 Reviewed-by: Shakti Sahu <shaktisahu@chromium.org> Commit-Queue: Salvador Guerrero Ramos <salg@google.com> Cr-Commit-Position: refs/branch-heads/5359@{#47} Cr-Branched-From: 27d3765-refs/heads/main@{#1058933}
- Loading branch information
Shakti Sahu
authored and
Chromium LUCI CQ
committed
Oct 17, 2022
1 parent
dfce288
commit 3d9f378
Showing
12 changed files
with
578 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...va/src/org/chromium/chrome/browser/segmentation_platform/PriceTrackingActionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.chrome.browser.segmentation_platform; | ||
|
||
import org.chromium.base.supplier.Supplier; | ||
import org.chromium.chrome.browser.bookmarks.BookmarkModel; | ||
import org.chromium.chrome.browser.bookmarks.PowerBookmarkUtils; | ||
import org.chromium.chrome.browser.tab.Tab; | ||
import org.chromium.components.bookmarks.BookmarkId; | ||
import org.chromium.components.commerce.core.ShoppingService; | ||
|
||
/** Provides price tracking signal for showing contextual page action for a given tab. */ | ||
public class PriceTrackingActionProvider implements ContextualPageActionController.ActionProvider { | ||
private final Supplier<ShoppingService> mShoppingServiceSupplier; | ||
private final Supplier<BookmarkModel> mBookmarkModelSupplier; | ||
|
||
/** Constructor. */ | ||
public PriceTrackingActionProvider(Supplier<ShoppingService> shoppingServiceSupplier, | ||
Supplier<BookmarkModel> bookmarkModelSupplier) { | ||
mShoppingServiceSupplier = shoppingServiceSupplier; | ||
mBookmarkModelSupplier = bookmarkModelSupplier; | ||
} | ||
|
||
@Override | ||
public void getAction(Tab tab, SignalAccumulator signalAccumulator) { | ||
final BookmarkModel bookmarkModel = mBookmarkModelSupplier.get(); | ||
bookmarkModel.finishLoadingBookmarkModel(() -> { | ||
BookmarkId bookmarkId = bookmarkModel.getUserBookmarkIdForTab(tab); | ||
boolean isAlreadyPriceTracked = | ||
PowerBookmarkUtils.isBookmarkPriceTracked(bookmarkModel, bookmarkId); | ||
if (isAlreadyPriceTracked) { | ||
signalAccumulator.setHasPriceTracking(false); | ||
signalAccumulator.notifySignalAvailable(); | ||
} else { | ||
mShoppingServiceSupplier.get().getProductInfoForUrl(tab.getUrl(), (url, info) -> { | ||
boolean canTrackPrice = info != null; | ||
signalAccumulator.setHasPriceTracking(canTrackPrice); | ||
signalAccumulator.notifySignalAvailable(); | ||
}); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.