Revert "Reland "[lens-rearch][30/n] Remove update context from overlay controller.""
This reverts commitcac2493a61
. Reason for revert: LUCI Bisection has identified this change as the cause of a test failure. See the analysis: https://ci.chromium.org/ui/p/chromium/bisection/test-analysis/b/6269741137133568 Sample build with failed test: https://ci.chromium.org/b/8714130360255361761 Affected test(s): [ninja://chrome/test:browser_tests/LensOverlayControllerInnerHtmlWithInnerTextAndApc.PageContentTypeHistograms](https://ci.chromium.org/ui/test/chromium/ninja:%2F%2Fchrome%2Ftest:browser_tests%2FLensOverlayControllerInnerHtmlWithInnerTextAndApc.PageContentTypeHistograms?q=VHash%3A6d0a43807ac672d9) If this is a false positive, please report it at http://b.corp.google.com/createIssue?component=1199205&description=Analysis%3A+https%3A%2F%2Fci.chromium.org%2Fui%2Fp%2Fchromium%2Fbisection%2Ftest-analysis%2Fb%2F6269741137133568&format=PLAIN&priority=P3&title=Wrongly+blamed+https%3A%2F%2Fchromium-review.googlesource.com%2Fc%2Fchromium%2Fsrc%2F%2B%2F6575884&type=BUG Original change's description: > Reland "[lens-rearch][30/n] Remove update context from overlay controller." > > Differences from reverted version: These changes by viewing the diff > from PS1 to the latest PS. The differences are the disabling of the > failing tests on branded builds with an added TODO that they should be > re-enabled and fixed when fully resolving crbug.com/417812533 > > This is a reland of commitf213852e17
> > Original change's description: > > [lens-rearch][30/n] Remove update context from overlay controller. > > > > This removes the update page contextualization code from the overlay > > controller in favor of updating the page context via the > > contextualization controller. This also removes the overlay controller > > not showing the overlay when initializing. This should be a no-op. > > > > Bug: 418825720 > > Change-Id: I3f559650c7d67f2cb9b62e9639b8907e9035a886 > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6565474 > > Commit-Queue: Juan Mojica <juanmojica@google.com> > > Commit-Queue: Duncan Mercer <mercerd@google.com> > > Reviewed-by: Duncan Mercer <mercerd@google.com> > > Auto-Submit: Juan Mojica <juanmojica@google.com> > > Cr-Commit-Position: refs/heads/main@{#1463558} > > Bug: 418825720 > Change-Id: Ief6b9e2c41ff5a34145c2d796699933842ffa189 > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6575884 > Auto-Submit: Juan Mojica <juanmojica@google.com> > Reviewed-by: Duncan Mercer <mercerd@google.com> > Commit-Queue: Duncan Mercer <mercerd@google.com> > Cr-Commit-Position: refs/heads/main@{#1464392} > Bug: 418825720 No-Presubmit: true No-Tree-Checks: true No-Try: true Change-Id: Iafd8a49eb833ed7574c990d2095e5f39a120d58c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6581378 Owners-Override: Yoshisato Yanagisawa <yyanagisawa@google.com> Commit-Queue: Yoshisato Yanagisawa <yyanagisawa@chromium.org> Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org> Reviewed-by: Lingqi Chi <lingqi@chromium.org> Cr-Commit-Position: refs/heads/main@{#1464598}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
37bab131cd
commit
610a2eaeac
@ -135,6 +135,11 @@ constexpr base::TimeDelta kFadeoutAnimationTimeout = base::Milliseconds(300);
|
||||
// taking a screenshot.
|
||||
constexpr base::TimeDelta kReflowWaitTimeout = base::Milliseconds(200);
|
||||
|
||||
// The amount of change in bytes that is considered a significant change and
|
||||
// should trigger a page content update request. This provides tolerance in
|
||||
// case there is slight variation in the retrievied bytes in between calls.
|
||||
constexpr float kByteChangeTolerancePercent = 0.01;
|
||||
|
||||
// The maximum length of the DOM text to consider for OCR similarity.
|
||||
// Currently 50 MB
|
||||
constexpr int kMaxDomTextLengthForOcrSimilarity = 50 * 1000 * 1000;
|
||||
@ -455,6 +460,7 @@ void LensOverlayController::CloseUI(
|
||||
}
|
||||
|
||||
lens_selection_type_ = lens::UNKNOWN_SELECTION_TYPE;
|
||||
should_show_overlay_ = true;
|
||||
is_page_context_eligible_ = true;
|
||||
should_send_screenshot_on_init_ = false;
|
||||
|
||||
@ -1018,10 +1024,9 @@ void LensOverlayController::IssueContextualSearchRequest(
|
||||
CHECK(lens_overlay_query_controller_);
|
||||
GetContextualizationController()->StartContextualization(
|
||||
invocation_source,
|
||||
base::BindOnce(
|
||||
&LensOverlayController::OnPageContextUpdatedForSuggestion,
|
||||
weak_factory_.GetWeakPtr(), destination_url, match_type,
|
||||
is_zero_prefix_suggestion, invocation_source));
|
||||
base::BindOnce(&LensOverlayController::OnPageContextUpdated,
|
||||
weak_factory_.GetWeakPtr(), destination_url, match_type,
|
||||
is_zero_prefix_suggestion, invocation_source));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1040,10 +1045,9 @@ void LensOverlayController::IssueContextualSearchRequest(
|
||||
// search request.
|
||||
CHECK(lens_overlay_query_controller_);
|
||||
GetContextualizationController()->TryUpdatePageContextualization(
|
||||
base::BindOnce(
|
||||
&LensOverlayController::OnPageContextUpdatedForSuggestion,
|
||||
weak_factory_.GetWeakPtr(), destination_url, match_type,
|
||||
is_zero_prefix_suggestion, invocation_source));
|
||||
base::BindOnce(&LensOverlayController::OnPageContextUpdated,
|
||||
weak_factory_.GetWeakPtr(), destination_url, match_type,
|
||||
is_zero_prefix_suggestion, invocation_source));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1054,6 +1058,13 @@ void LensOverlayController::IssueContextualSearchRequest(
|
||||
destination_url, match_type, is_zero_prefix_suggestion);
|
||||
}
|
||||
|
||||
void LensOverlayController::StartContextualizationWithoutOverlay(
|
||||
lens::LensOverlayInvocationSource invocation_source,
|
||||
lens::LensOverlayQueryController* lens_overlay_query_controller) {
|
||||
should_show_overlay_ = false;
|
||||
ShowUI(invocation_source, lens_overlay_query_controller);
|
||||
}
|
||||
|
||||
void LensOverlayController::ShowUIWithPendingRegion(
|
||||
lens::LensOverlayQueryController* lens_overlay_query_controller,
|
||||
lens::LensOverlayInvocationSource invocation_source,
|
||||
@ -1159,10 +1170,7 @@ void LensOverlayController::OnSearchboxFocusChanged(bool focused) {
|
||||
// If the live page is showing and the searchbox becomes focused, showing
|
||||
// intent to issue a new query, upload the new page content for
|
||||
// contextualization.
|
||||
// TODO(crbug.com/418856988): Replace this with a call that starts
|
||||
// contextualization without the unneeded callback.
|
||||
GetContextualizationController()->TryUpdatePageContextualization(
|
||||
base::DoNothing());
|
||||
TryUpdatePageContextualization();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1247,10 +1255,13 @@ void LensOverlayController::IssueSearchBoxRequest(
|
||||
|
||||
// If contextual searchbox is enabled, make sure the page bytes are current
|
||||
// prior to issuing the search box request.
|
||||
GetContextualizationController()->TryUpdatePageContextualization(
|
||||
base::BindOnce(&LensOverlayController::IssueSearchBoxRequestPart2,
|
||||
weak_factory_.GetWeakPtr(), query_start_time, search_box_text, match_type,
|
||||
is_zero_prefix_suggestion, additional_query_params));
|
||||
GetContextualizationController()->GetPageContextualization(
|
||||
base::BindOnce(&LensOverlayController::UpdatePageContextualization,
|
||||
weak_factory_.GetWeakPtr())
|
||||
.Then(base::BindOnce(
|
||||
&LensOverlayController::IssueSearchBoxRequestPart2,
|
||||
weak_factory_.GetWeakPtr(), query_start_time, search_box_text,
|
||||
match_type, is_zero_prefix_suggestion, additional_query_params)));
|
||||
}
|
||||
|
||||
void LensOverlayController::IssueContextualTextRequest(
|
||||
@ -1258,7 +1269,6 @@ void LensOverlayController::IssueContextualTextRequest(
|
||||
const std::string& text_query,
|
||||
lens::LensOverlaySelectionType selection_type) {
|
||||
if (is_page_context_eligible_) {
|
||||
lens_selection_type_ = selection_type;
|
||||
lens_overlay_query_controller_->SendContextualTextQuery(
|
||||
query_start_time, text_query, selection_type,
|
||||
initialization_data_->additional_search_query_params_);
|
||||
@ -1572,6 +1582,8 @@ void LensOverlayController::StorePageContentAndContinueInitialization(
|
||||
initialization_data->primary_content_type_ = primary_content_type;
|
||||
initialization_data->pdf_page_count_ = page_count;
|
||||
InitializeOverlay(std::move(initialization_data));
|
||||
|
||||
RecordDocumentMetrics(page_count);
|
||||
}
|
||||
|
||||
std::vector<lens::mojom::CenterRotatedBoxPtr>
|
||||
@ -1616,6 +1628,195 @@ LensOverlayController::ConvertSignificantRegionBoxes(
|
||||
return significant_region_boxes;
|
||||
}
|
||||
|
||||
void LensOverlayController::TryUpdatePageContextualization() {
|
||||
// If there is already an upload, do not send another request.
|
||||
// TODO(crbug.com/399154548): Ideally, there could be two uploads in progress
|
||||
// at a time, however, the current query controller implementation does not
|
||||
// support this.
|
||||
if (lens_overlay_query_controller_->IsPageContentUploadInProgress()) {
|
||||
return;
|
||||
}
|
||||
|
||||
GetContextualizationController()->GetPageContextualization(
|
||||
base::BindOnce(&LensOverlayController::UpdatePageContextualization,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void LensOverlayController::UpdatePageContextualization(
|
||||
std::vector<lens::PageContent> page_contents,
|
||||
lens::MimeType primary_content_type,
|
||||
std::optional<uint32_t> page_count) {
|
||||
if (!lens::features::IsLensOverlayContextualSearchboxEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the protected page is showing, then return early as none of the content
|
||||
// will be sent.
|
||||
if (results_side_panel_coordinator_->IsShowingProtectedErrorPage()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not capture a new screenshot if the feature param is not enabled or if
|
||||
// the user is not viewing the live page, meaning the viewport cannot have
|
||||
// changed.
|
||||
if (!lens::features::UpdateViewportEachQueryEnabled() ||
|
||||
state_ != State::kLivePageAndResults) {
|
||||
UpdatePageContextualizationPart2(page_contents, primary_content_type,
|
||||
page_count, SkBitmap());
|
||||
return;
|
||||
}
|
||||
|
||||
// Begin the process of grabbing a screenshot.
|
||||
content::RenderWidgetHostView* view = tab_->GetContents()
|
||||
->GetPrimaryMainFrame()
|
||||
->GetRenderViewHost()
|
||||
->GetWidget()
|
||||
->GetView();
|
||||
if (!IsScreenshotPossible(view)) {
|
||||
UpdatePageContextualizationPart2(page_contents, primary_content_type,
|
||||
page_count, SkBitmap());
|
||||
return;
|
||||
}
|
||||
view->CopyFromSurface(
|
||||
/*src_rect=*/gfx::Rect(), /*output_size=*/gfx::Size(),
|
||||
base::BindPostTask(
|
||||
base::SequencedTaskRunner::GetCurrentDefault(),
|
||||
base::BindOnce(
|
||||
&LensOverlayController::UpdatePageContextualizationPart2,
|
||||
weak_factory_.GetWeakPtr(), page_contents, primary_content_type,
|
||||
page_count)));
|
||||
}
|
||||
|
||||
void LensOverlayController::UpdatePageContextualizationPart2(
|
||||
std::vector<lens::PageContent> page_contents,
|
||||
lens::MimeType primary_content_type,
|
||||
std::optional<uint32_t> page_count,
|
||||
const SkBitmap& bitmap) {
|
||||
#if BUILDFLAG(ENABLE_PDF)
|
||||
if (lens::features::SendPdfCurrentPageEnabled()) {
|
||||
pdf::PDFDocumentHelper* pdf_helper =
|
||||
pdf::PDFDocumentHelper::MaybeGetForWebContents(tab_->GetContents());
|
||||
if (pdf_helper) {
|
||||
pdf_helper->GetMostVisiblePageIndex(base::BindOnce(
|
||||
&LensOverlayController::UpdatePageContextualizationPart3,
|
||||
weak_factory_.GetWeakPtr(), page_contents, primary_content_type,
|
||||
page_count, bitmap));
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_PDF)
|
||||
|
||||
UpdatePageContextualizationPart3(page_contents, primary_content_type,
|
||||
page_count, bitmap,
|
||||
/*most_visible_page=*/std::nullopt);
|
||||
}
|
||||
|
||||
void LensOverlayController::UpdatePageContextualizationPart3(
|
||||
std::vector<lens::PageContent> page_contents,
|
||||
lens::MimeType primary_content_type,
|
||||
std::optional<uint32_t> page_count,
|
||||
const SkBitmap& bitmap,
|
||||
std::optional<uint32_t> most_visible_page) {
|
||||
bool sending_bitmap = false;
|
||||
if (!bitmap.drawsNothing() &&
|
||||
(initialization_data_->updated_screenshot_.drawsNothing() ||
|
||||
!lens::AreBitmapsEqual(initialization_data_->updated_screenshot_,
|
||||
bitmap))) {
|
||||
initialization_data_->updated_screenshot_ = bitmap;
|
||||
sending_bitmap = true;
|
||||
}
|
||||
initialization_data_->last_retrieved_most_visible_page_ = most_visible_page;
|
||||
|
||||
// TODO(crbug.com/399215935): Ideally, this check should ensure that any of
|
||||
// the content date has not changed. For now, we only check if the
|
||||
// primary_content_type bytes have changed.
|
||||
auto old_page_content_it = std::ranges::find_if(
|
||||
initialization_data_->page_contents_,
|
||||
[&primary_content_type](const auto& page_content) {
|
||||
return page_content.content_type_ == primary_content_type;
|
||||
});
|
||||
auto new_page_content_it = std::ranges::find_if(
|
||||
page_contents, [&primary_content_type](const auto& page_content) {
|
||||
return page_content.content_type_ == primary_content_type;
|
||||
});
|
||||
const lens::PageContent* old_page_content =
|
||||
old_page_content_it != initialization_data_->page_contents_.end()
|
||||
? &(*old_page_content_it)
|
||||
: nullptr;
|
||||
const lens::PageContent* new_page_content =
|
||||
new_page_content_it != page_contents.end() ? &(*new_page_content_it)
|
||||
: nullptr;
|
||||
|
||||
if (initialization_data_->primary_content_type_ == primary_content_type &&
|
||||
old_page_content && new_page_content) {
|
||||
const float old_size = old_page_content->bytes_.size();
|
||||
const float new_size = new_page_content->bytes_.size();
|
||||
const float percent_changed = abs((new_size - old_size) / old_size);
|
||||
if (percent_changed < kByteChangeTolerancePercent) {
|
||||
if (!sending_bitmap) {
|
||||
// If the bytes have not changed more than our threshold and the
|
||||
// screenshot has not changed, exit early. Notify the query controller
|
||||
// that the user may be issuing a search request, and therefore the
|
||||
// query should be restarted if TTL expired. If the bytes did change,
|
||||
// this will happen automatically as a result of the
|
||||
// SendUpdatedPageContent call below.
|
||||
lens_overlay_query_controller_->MaybeRestartQueryFlow();
|
||||
return;
|
||||
}
|
||||
|
||||
// If the screenshot has changed but the bytes have not, send only the
|
||||
// screenshot.
|
||||
lens_overlay_query_controller_->SendUpdatedPageContent(
|
||||
std::nullopt, std::nullopt, std::nullopt, std::nullopt,
|
||||
initialization_data_->last_retrieved_most_visible_page_,
|
||||
sending_bitmap ? bitmap : SkBitmap());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Since the page content has changed, let the query controller know to avoid
|
||||
// dangling pointers.
|
||||
lens_overlay_query_controller_->ResetPageContentData();
|
||||
|
||||
initialization_data_->page_contents_ = page_contents;
|
||||
initialization_data_->primary_content_type_ = primary_content_type;
|
||||
|
||||
// If no bytes were retrieved from the page, the query won't be able to be
|
||||
// contextualized. Notify the side panel so the ghost loader isn't shown. No
|
||||
// need to update update the overlay as this update only happens on navigation
|
||||
// where the side panel will already be open.
|
||||
if (!new_page_content || new_page_content->bytes_.empty()) {
|
||||
SuppressGhostLoader();
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_PDF)
|
||||
// If the new page is a PDF, fetch the text from the page to be used as early
|
||||
// suggest signals.
|
||||
if (new_page_content &&
|
||||
new_page_content->content_type_ == lens::MimeType::kPdf) {
|
||||
CHECK(lens_overlay_query_controller_);
|
||||
GetContextualizationController()->FetchVisiblePageIndexAndGetPartialPdfText(
|
||||
page_count.value_or(0),
|
||||
base::BindOnce(&LensOverlayController::OnPdfPartialPageTextRetrieved,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
#endif
|
||||
|
||||
is_upload_progress_bar_shown_ = true;
|
||||
is_first_upload_handler_event_ = true;
|
||||
lens_overlay_query_controller_->SendUpdatedPageContent(
|
||||
initialization_data_->page_contents_,
|
||||
initialization_data_->primary_content_type_,
|
||||
lens_search_controller_->GetPageURL(),
|
||||
lens_search_controller_->GetPageTitle(),
|
||||
initialization_data_->last_retrieved_most_visible_page_,
|
||||
sending_bitmap ? bitmap : SkBitmap());
|
||||
|
||||
GetLensSessionMetricsLogger()->OnFollowUpPageContentRetrieved(
|
||||
primary_content_type);
|
||||
RecordDocumentMetrics(page_count);
|
||||
}
|
||||
|
||||
void LensOverlayController::SuppressGhostLoader() {
|
||||
if (page_) {
|
||||
page_->SuppressGhostLoader();
|
||||
@ -1640,10 +1841,16 @@ void LensOverlayController::ShowOverlay() {
|
||||
// Grab the tab contents web view and disable mouse and keyboard inputs to it.
|
||||
auto* contents_web_view = tab_->GetBrowserWindowInterface()->GetWebView();
|
||||
CHECK(contents_web_view);
|
||||
contents_web_view->SetEnabled(false);
|
||||
if (should_show_overlay_) {
|
||||
contents_web_view->SetEnabled(false);
|
||||
}
|
||||
|
||||
// If the view already exists, we just need to reshow it.
|
||||
if (overlay_view_) {
|
||||
// Exit early to avoid reshowing the overlay if it should not be shown.
|
||||
if (!should_show_overlay_) {
|
||||
return;
|
||||
}
|
||||
// Restore the state to show the overlay.
|
||||
overlay_view_->SetVisible(true);
|
||||
preselection_widget_anchor_->SetVisible(true);
|
||||
@ -1658,9 +1865,11 @@ void LensOverlayController::ShowOverlay() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the views that will house our UI.
|
||||
// Create the views that will house our UI. The overlay view might not
|
||||
// actually be shown, as dictated by `should_show_overlay_`. It still needs to
|
||||
// be created so the initialization process completes.
|
||||
overlay_view_ = CreateViewForOverlay();
|
||||
overlay_view_->SetVisible(true);
|
||||
overlay_view_->SetVisible(should_show_overlay_);
|
||||
|
||||
// Sanity check that the overlay view is above the contents web view.
|
||||
auto* parent_view = overlay_view_->parent();
|
||||
@ -1686,8 +1895,10 @@ void LensOverlayController::ShowOverlay() {
|
||||
|
||||
// The overlay needs to be focused on show to immediately begin
|
||||
// receiving key events.
|
||||
CHECK(overlay_web_view_);
|
||||
overlay_web_view_->RequestFocus();
|
||||
if (should_show_overlay_) {
|
||||
CHECK(overlay_web_view_);
|
||||
overlay_web_view_->RequestFocus();
|
||||
}
|
||||
|
||||
// Listen to the render process housing out overlay.
|
||||
overlay_web_view_->GetWebContents()
|
||||
@ -1760,20 +1971,43 @@ void LensOverlayController::InitializeOverlay(
|
||||
InitializeOverlayUI(*initialization_data_);
|
||||
base::UmaHistogramBoolean("Lens.Overlay.Shown", true);
|
||||
|
||||
#if BUILDFLAG(ENABLE_PDF)
|
||||
// If PDF content was extracted from the page, fetch the text from the PDF to
|
||||
// be used as early suggest signals.
|
||||
if (!initialization_data_->page_contents_.empty() &&
|
||||
initialization_data_->page_contents_.front().content_type_ ==
|
||||
lens::MimeType::kPdf) {
|
||||
CHECK(initialization_data_->pdf_page_count_.has_value());
|
||||
CHECK(lens_overlay_query_controller_);
|
||||
GetContextualizationController()->FetchVisiblePageIndexAndGetPartialPdfText(
|
||||
initialization_data_->pdf_page_count_.value(),
|
||||
base::BindOnce(&LensOverlayController::OnPdfPartialPageTextRetrieved,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
#endif
|
||||
|
||||
// If the StartQueryFlow optimization is enabled, the page contents will not
|
||||
// be sent with the initial image request, so we need to send it here.
|
||||
if (lens::features::IsLensOverlayContextualSearchboxEnabled() &&
|
||||
lens::features::IsLensOverlayEarlyStartQueryFlowOptimizationEnabled() &&
|
||||
is_page_context_eligible_) {
|
||||
// TODO(crbug.com/418856988): Replace this with a call that starts
|
||||
// contextualization without the unneeded callback.
|
||||
GetContextualizationController()->TryUpdatePageContextualization(
|
||||
base::DoNothing());
|
||||
// The screenshot is not sent here unless forced by
|
||||
// `should_send_screenshot_on_init_` as it should have been sent in the
|
||||
// original StartQueryFlow call.
|
||||
lens_overlay_query_controller_->SendUpdatedPageContent(
|
||||
initialization_data_->page_contents_,
|
||||
initialization_data_->primary_content_type_,
|
||||
lens_search_controller_->GetPageURL(),
|
||||
lens_search_controller_->GetPageTitle(),
|
||||
initialization_data_->last_retrieved_most_visible_page_,
|
||||
should_send_screenshot_on_init_
|
||||
? initialization_data_->initial_screenshot_
|
||||
: SkBitmap());
|
||||
}
|
||||
|
||||
// Show the preselection overlay now that the overlay is initialized and ready
|
||||
// to be shown.
|
||||
if (!pending_region_) {
|
||||
if (!pending_region_ && should_show_overlay_) {
|
||||
ShowPreselectionBubble();
|
||||
}
|
||||
|
||||
@ -2358,7 +2592,7 @@ void LensOverlayController::ClosePreselectionBubble() {
|
||||
|
||||
void LensOverlayController::ShowPreselectionBubble() {
|
||||
// Don't show the preselection bubble if the overlay is not being shown.
|
||||
if (state() == State::kOverlayAndResults) {
|
||||
if (!should_show_overlay_ || state() == State::kOverlayAndResults) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2918,7 +3152,7 @@ void LensOverlayController::OnPdfPartialPageTextRetrieved(
|
||||
initialization_data_->pdf_pages_text_ = std::move(pdf_pages_text);
|
||||
}
|
||||
|
||||
void LensOverlayController::OnPageContextUpdatedForSuggestion(
|
||||
void LensOverlayController::OnPageContextUpdated(
|
||||
const GURL& destination_url,
|
||||
AutocompleteMatchType::Type match_type,
|
||||
bool is_zero_prefix_suggestion,
|
||||
|
@ -356,16 +356,6 @@ class LensOverlayController : public lens::mojom::LensPageHandler,
|
||||
// Gets string for invocation source enum, used for logging metrics.
|
||||
std::string GetInvocationSourceString();
|
||||
|
||||
// Records the UMA for the metrics relating to the document where the
|
||||
// contextual search box was shown. If this is a webpage, records the size of
|
||||
// the innerHtml and the innerText. If this is a PDF, records the byte size of
|
||||
// the PDF and the number of pages. `pdf_page_count` is only used for PDFs.
|
||||
// TODO(crbug.com/404941800): Move the document metrics to where the page
|
||||
// content bytes are stored. Temporarily public and should be made a private
|
||||
// function again after contextualization controller is fully migrated to
|
||||
// avoid overlay dependencies.
|
||||
void RecordDocumentMetrics(std::optional<uint32_t> pdf_page_count);
|
||||
|
||||
// Gets the WebContents housed in the side panel for testing.
|
||||
content::WebContents* GetSidePanelWebContentsForTesting();
|
||||
|
||||
@ -453,6 +443,19 @@ class LensOverlayController : public lens::mojom::LensPageHandler,
|
||||
bool is_zero_prefix_suggestion,
|
||||
lens::LensOverlayInvocationSource invocation_source);
|
||||
|
||||
// Starts the contextualization flow without the overlay being shown to the
|
||||
// user.
|
||||
// TODO(crbug.com/404941800): This still goes through the entire
|
||||
// TODO(crbug.com/404941800): This still goes through the entire
|
||||
// initialization flow for the overlay. This is not efficient, but is being
|
||||
// done to unblock the contextual searchbox prototype. This should be
|
||||
// refactored to be done in the LensSearchController to not go through the
|
||||
// overlay controller.
|
||||
// Virtual for testing.
|
||||
virtual void StartContextualizationWithoutOverlay(
|
||||
lens::LensOverlayInvocationSource invocation_source,
|
||||
lens::LensOverlayQueryController* lens_overlay_query_controller);
|
||||
|
||||
// Sets a region to search after the overlay loads, then calls ShowUI().
|
||||
// All units are in device pixels. region_bitmap contains the high definition
|
||||
// image bytes to use for the search instead of cropping the region from the
|
||||
@ -717,6 +720,34 @@ class LensOverlayController : public lens::mojom::LensPageHandler,
|
||||
std::vector<lens::mojom::CenterRotatedBoxPtr> ConvertSignificantRegionBoxes(
|
||||
const std::vector<gfx::Rect>& all_bounds);
|
||||
|
||||
// Tries to fetch the underlying page content bytes and update the query flow
|
||||
// with them.
|
||||
void TryUpdatePageContextualization();
|
||||
|
||||
// Begin updating page contextualization by potentially taking a new
|
||||
// screenshot.
|
||||
void UpdatePageContextualization(std::vector<lens::PageContent> page_contents,
|
||||
lens::MimeType primary_content_type,
|
||||
std::optional<uint32_t> pdf_page_count);
|
||||
|
||||
// Continue updating page contextualization by potentially getting the current
|
||||
// PDF page.
|
||||
void UpdatePageContextualizationPart2(
|
||||
std::vector<lens::PageContent> page_contents,
|
||||
lens::MimeType primary_content_type,
|
||||
std::optional<uint32_t> pdf_page_count,
|
||||
const SkBitmap& bitmap);
|
||||
|
||||
// Updates the query flow with the new page content bytes and/or screenshot. A
|
||||
// request will only be sent if the bytes are different from the previous
|
||||
// bytes sent or the screenshot is different from the previous screenshot.
|
||||
void UpdatePageContextualizationPart3(
|
||||
std::vector<lens::PageContent> page_contents,
|
||||
lens::MimeType primary_content_type,
|
||||
std::optional<uint32_t> pdf_page_count,
|
||||
const SkBitmap& bitmap,
|
||||
std::optional<uint32_t> pdf_current_page);
|
||||
|
||||
// Updates state of the ghost loader. |suppress_ghost_loader| is true when
|
||||
// the page bytes can't be uploaded.
|
||||
void SuppressGhostLoader();
|
||||
@ -898,6 +929,14 @@ class LensOverlayController : public lens::mojom::LensPageHandler,
|
||||
bool is_zero_prefix_suggestion,
|
||||
std::map<std::string, std::string> additional_query_params);
|
||||
|
||||
// Records the UMA for the metrics relating to the document where the
|
||||
// contextual search box was shown. If this is a webpage, records the size of
|
||||
// the innerHtml and the innerText. If this is a PDF, records the byte size of
|
||||
// the PDF and the number of pages. `pdf_page_count` is only used for PDFs.
|
||||
// TODO(crbug.com/404941800): Move the document metrics to where the page
|
||||
// content bytes are stored.
|
||||
void RecordDocumentMetrics(std::optional<uint32_t> pdf_page_count);
|
||||
|
||||
// Posts a task to the background thread to calculate the OCR DOM similarity
|
||||
// and then records the result. Only records the similarity once per session.
|
||||
// Only records the similarity if the OCR text and page content are available.
|
||||
@ -936,9 +975,8 @@ class LensOverlayController : public lens::mojom::LensPageHandler,
|
||||
void OnPdfPartialPageTextRetrieved(
|
||||
std::vector<std::u16string> pdf_pages_text);
|
||||
|
||||
// Callback to run when the page context has been updated and the suggestion
|
||||
// query should now be issued.
|
||||
void OnPageContextUpdatedForSuggestion(
|
||||
// Callback to run when the page context has been updated.
|
||||
void OnPageContextUpdated(
|
||||
const GURL& destination_url,
|
||||
AutocompleteMatchType::Type match_type,
|
||||
bool is_zero_prefix_suggestion,
|
||||
@ -978,6 +1016,11 @@ class LensOverlayController : public lens::mojom::LensPageHandler,
|
||||
lens::LensOverlayInvocationSource invocation_source_ =
|
||||
lens::LensOverlayInvocationSource::kAppMenu;
|
||||
|
||||
// Whether the overlay should be visible when it is opened. This is a hacky
|
||||
// approach to start contextual searchbox flow without the overlay UI being
|
||||
// shown. See StartContextualizationWithoutOverlay todo for more details.
|
||||
bool should_show_overlay_ = true;
|
||||
|
||||
// A contextual search request to be issued once the overlay is initialized.
|
||||
base::OnceClosure pending_contextual_search_request_;
|
||||
|
||||
|
@ -235,10 +235,6 @@ constexpr char kCheckSidePanelTranslateResultsLoadedScript[] =
|
||||
" === $1; return iframeSrcLoaded && stickPresent && "
|
||||
" searchboxInputLoaded;})();";
|
||||
|
||||
// TODO(crbug.com/417812533): Tests are currently failing in branded builds due
|
||||
// to missing metrics. Will be fixed as part of work to move recording document
|
||||
// metrics to the contextualization controller.
|
||||
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
constexpr char kCheckSidePanelThumbnailShownScript[] =
|
||||
"(function() {const appRoot = "
|
||||
"document.getElementsByTagName('lens-side-panel-app')[0].shadowRoot;"
|
||||
@ -249,7 +245,6 @@ constexpr char kCheckSidePanelThumbnailShownScript[] =
|
||||
"const imageSrc = thumbnailRoot.getElementById('image').src;"
|
||||
"return window.getComputedStyle(thumbContainer).display !== 'none' && "
|
||||
" imageSrc.startsWith('data:image/jpeg');})();";
|
||||
#endif // !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
|
||||
constexpr char kCheckSidePanelToastShownScript[] =
|
||||
"(function() {const appRoot = "
|
||||
@ -1463,10 +1458,6 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
ASSERT_TRUE(base::test::RunUntil([&]() { return observer.request_shown(); }));
|
||||
}
|
||||
|
||||
// TODO(crbug.com/417812533): Tests are currently failing in branded builds due
|
||||
// to missing metrics. Will be fixed as part of work to move recording document
|
||||
// metrics to the contextualization controller.
|
||||
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
// TODO(b/335801964): Test flaky on Mac.
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
#define MAYBE_SidePanelInteractionsAfterRegionSelection \
|
||||
@ -1528,7 +1519,7 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
EXPECT_FALSE(controller->get_selected_region_for_testing().is_null());
|
||||
EXPECT_TRUE(base::StartsWith(controller->GetThumbnailForTesting(), "data:"));
|
||||
EXPECT_EQ(controller->GetPageClassificationForTesting(),
|
||||
metrics::OmniboxEventProto::CONTEXTUAL_SEARCHBOX);
|
||||
metrics::OmniboxEventProto::LENS_SIDE_PANEL_SEARCHBOX);
|
||||
|
||||
// Verify that after text selection, the controller has a copy of the text,
|
||||
// the thumbnail is no longer shown and the controller's copy of the
|
||||
@ -1546,7 +1537,7 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
EXPECT_TRUE(controller->get_selected_region_for_testing().is_null());
|
||||
EXPECT_TRUE(controller->GetThumbnailForTesting().empty());
|
||||
EXPECT_EQ(controller->GetPageClassificationForTesting(),
|
||||
metrics::OmniboxEventProto::CONTEXTUAL_SEARCHBOX);
|
||||
metrics::OmniboxEventProto::SEARCH_SIDE_PANEL_SEARCHBOX);
|
||||
|
||||
// Verify that after a signal from the searchbox that the text was modified,
|
||||
// no text selection is present.
|
||||
@ -1556,7 +1547,6 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
fake_controller->FlushForTesting();
|
||||
EXPECT_TRUE(fake_controller->fake_overlay_page_.did_clear_text_selection_);
|
||||
}
|
||||
#endif // !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
|
||||
// TODO(b/350991033): Test flaky on Mac.
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
@ -3515,6 +3505,188 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
first_search_url);
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
PopAndLoadTranslateQueryFromHistory) {
|
||||
WaitForPaint();
|
||||
|
||||
// State should start in off.
|
||||
auto* controller = GetLensOverlayController();
|
||||
ASSERT_EQ(controller->state(), State::kOff);
|
||||
|
||||
// Showing UI should change the state to screenshot and eventually to overlay.
|
||||
OpenLensOverlayWithPendingRegion(
|
||||
LensOverlayInvocationSource::kContentAreaContextMenuImage,
|
||||
kTestRegion->Clone(), CreateNonEmptyBitmap(100, 100));
|
||||
ASSERT_EQ(controller->state(), State::kScreenshot);
|
||||
ASSERT_TRUE(base::test::RunUntil(
|
||||
[&]() { return controller->state() == State::kOverlayAndResults; }));
|
||||
EXPECT_TRUE(content::WaitForLoadStop(GetOverlayWebContents()));
|
||||
EXPECT_TRUE(content::WaitForLoadStop(
|
||||
controller->GetSidePanelWebContentsForTesting()));
|
||||
EXPECT_TRUE(controller->GetOverlayViewForTesting()->GetVisible());
|
||||
auto* fake_query_controller =
|
||||
static_cast<lens::TestLensOverlayQueryController*>(
|
||||
controller->get_lens_overlay_query_controller_for_testing());
|
||||
EXPECT_EQ(fake_query_controller->last_lens_selection_type(),
|
||||
lens::INJECTED_IMAGE);
|
||||
|
||||
const GURL first_search_url(
|
||||
"https://www.google.com/"
|
||||
"search?source=chrome.cr.ctxi&q=&lns_fp=1&lns_mode=un"
|
||||
"&gsc=2&hl=en-US&cs=0");
|
||||
|
||||
// The search query history stack should be empty and the currently loaded
|
||||
// query should be set.
|
||||
EXPECT_TRUE(GetSearchQueryHistory().empty());
|
||||
const auto first_search_query = GetLoadedSearchQuery();
|
||||
EXPECT_TRUE(first_search_query);
|
||||
EXPECT_TRUE(first_search_query->search_query_text_.empty());
|
||||
VerifySearchQueryParameters(first_search_query->search_query_url_);
|
||||
VerifyTextQueriesAreEqual(first_search_query->search_query_url_,
|
||||
first_search_url);
|
||||
EXPECT_FALSE(first_search_query->selected_region_thumbnail_uri_.empty());
|
||||
EXPECT_EQ(first_search_query->selected_region_, kTestRegion);
|
||||
EXPECT_FALSE(first_search_query->selected_region_bitmap_.drawsNothing());
|
||||
EXPECT_EQ(first_search_query->selected_region_bitmap_.width(), 100);
|
||||
EXPECT_EQ(first_search_query->selected_region_bitmap_.height(), 100);
|
||||
EXPECT_FALSE(first_search_query->selected_text_);
|
||||
EXPECT_EQ(first_search_query->lens_selection_type_, lens::INJECTED_IMAGE);
|
||||
|
||||
// Loading a url in the side panel should show the results page.
|
||||
const GURL second_search_url(
|
||||
"https://www.google.com/"
|
||||
"search?source=chrome.cr.menu&q=oranges&lns_fp=1&lns_mode=text"
|
||||
"&gsc=2&hl=en-US&cs=0");
|
||||
// Do the full image translate query first so it gets attached to the query.
|
||||
const std::string source_lang = "auto";
|
||||
const std::string target_lang = "fi";
|
||||
content::TestNavigationObserver second_observer(
|
||||
controller->GetSidePanelWebContentsForTesting());
|
||||
controller->IssueTranslateFullPageRequestForTesting(source_lang, target_lang);
|
||||
controller->IssueTextSelectionRequestForTesting("oranges", 20, 200);
|
||||
second_observer.Wait();
|
||||
|
||||
// The search query history stack should be size 1.
|
||||
EXPECT_EQ(GetSearchQueryHistory().size(), 1UL);
|
||||
const auto second_search_query = GetLoadedSearchQuery();
|
||||
EXPECT_TRUE(second_search_query);
|
||||
EXPECT_EQ(second_search_query->search_query_text_, "oranges");
|
||||
VerifySearchQueryParameters(second_search_query->search_query_url_);
|
||||
VerifyTextQueriesAreEqual(second_search_query->search_query_url_,
|
||||
second_search_url);
|
||||
EXPECT_TRUE(second_search_query->selected_region_thumbnail_uri_.empty());
|
||||
EXPECT_TRUE(second_search_query->selected_region_bitmap_.drawsNothing());
|
||||
EXPECT_FALSE(second_search_query->selected_region_);
|
||||
EXPECT_TRUE(second_search_query->selected_text_);
|
||||
EXPECT_EQ(second_search_query->selected_text_->first, 20);
|
||||
EXPECT_EQ(second_search_query->selected_text_->second, 200);
|
||||
EXPECT_TRUE(second_search_query->translate_options_);
|
||||
EXPECT_EQ(second_search_query->translate_options_->source_language,
|
||||
source_lang);
|
||||
EXPECT_EQ(second_search_query->translate_options_->target_language,
|
||||
target_lang);
|
||||
EXPECT_EQ(second_search_query->lens_selection_type_,
|
||||
lens::SELECT_TEXT_HIGHLIGHT);
|
||||
VerifySearchQueryParameters(second_observer.last_navigation_url());
|
||||
VerifyTextQueriesAreEqual(second_observer.last_navigation_url(),
|
||||
second_search_url);
|
||||
|
||||
// Loading a second url in the side panel should show the results page.
|
||||
const GURL third_search_url(
|
||||
"https://www.google.com/"
|
||||
"search?source=chrome.cr.menu&q=kiwi&lns_fp=1&lns_mode=text&gsc=2"
|
||||
"&hl=en-US&cs=0");
|
||||
// We can't use content::WaitForLoadStop here since the last navigation is
|
||||
// successful.
|
||||
content::TestNavigationObserver third_observer(
|
||||
controller->GetSidePanelWebContentsForTesting());
|
||||
controller->IssueEndTranslateModeRequestForTesting();
|
||||
controller->results_side_panel_coordinator()->LoadURLInResultsFrameForTesting(
|
||||
third_search_url);
|
||||
third_observer.Wait();
|
||||
|
||||
// The search query history stack should have 2 entries and the currently
|
||||
// loaded query should be set to the new query
|
||||
EXPECT_EQ(GetSearchQueryHistory().size(), 2UL);
|
||||
const auto third_search_query = GetLoadedSearchQuery();
|
||||
EXPECT_TRUE(third_search_query);
|
||||
EXPECT_EQ(third_search_query->search_query_text_, "kiwi");
|
||||
VerifySearchQueryParameters(third_search_query->search_query_url_);
|
||||
VerifyTextQueriesAreEqual(third_search_query->search_query_url_,
|
||||
third_search_url);
|
||||
EXPECT_TRUE(third_search_query->selected_region_thumbnail_uri_.empty());
|
||||
EXPECT_FALSE(third_search_query->selected_region_);
|
||||
EXPECT_FALSE(third_search_query->selected_text_);
|
||||
EXPECT_FALSE(third_search_query->translate_options_);
|
||||
EXPECT_EQ(third_search_query->lens_selection_type_,
|
||||
lens::UNKNOWN_SELECTION_TYPE);
|
||||
VerifySearchQueryParameters(third_observer.last_navigation_url());
|
||||
VerifyTextQueriesAreEqual(third_observer.last_navigation_url(),
|
||||
third_search_url);
|
||||
|
||||
// Popping the query should load the previous query into the results frame.
|
||||
content::TestNavigationObserver fourth_observer(
|
||||
controller->GetSidePanelWebContentsForTesting());
|
||||
controller->results_side_panel_coordinator()->PopAndLoadQueryFromHistory();
|
||||
fourth_observer.Wait();
|
||||
|
||||
// The search query history stack should have 1 entry and the currently loaded
|
||||
// query should be set to the previous query.
|
||||
EXPECT_EQ(GetSearchQueryHistory().size(), 1UL);
|
||||
const auto first_popped_query = GetLoadedSearchQuery();
|
||||
EXPECT_TRUE(first_popped_query);
|
||||
EXPECT_EQ(first_popped_query->search_query_text_, "oranges");
|
||||
VerifySearchQueryParameters(first_popped_query->search_query_url_);
|
||||
VerifyTextQueriesAreEqual(first_popped_query->search_query_url_,
|
||||
second_search_url);
|
||||
EXPECT_TRUE(first_popped_query->selected_region_thumbnail_uri_.empty());
|
||||
EXPECT_FALSE(first_popped_query->selected_region_);
|
||||
EXPECT_TRUE(first_popped_query->selected_text_);
|
||||
EXPECT_EQ(first_popped_query->selected_text_->first, 20);
|
||||
EXPECT_EQ(first_popped_query->selected_text_->second, 200);
|
||||
EXPECT_TRUE(first_popped_query->translate_options_);
|
||||
EXPECT_EQ(first_popped_query->translate_options_->source_language,
|
||||
source_lang);
|
||||
EXPECT_EQ(first_popped_query->translate_options_->target_language,
|
||||
target_lang);
|
||||
EXPECT_EQ(first_popped_query->lens_selection_type_,
|
||||
lens::SELECT_TEXT_HIGHLIGHT);
|
||||
VerifySearchQueryParameters(fourth_observer.last_navigation_url());
|
||||
VerifyTextQueriesAreEqual(fourth_observer.last_navigation_url(),
|
||||
second_search_url);
|
||||
auto* fake_controller = static_cast<LensOverlayControllerFake*>(controller);
|
||||
fake_controller->FlushForTesting();
|
||||
EXPECT_EQ(fake_controller->fake_overlay_page_.source_language_, source_lang);
|
||||
EXPECT_EQ(fake_controller->fake_overlay_page_.target_language_, target_lang);
|
||||
|
||||
// Popping the query should load the previous query into the results frame.
|
||||
content::TestNavigationObserver fifth_observer(
|
||||
controller->GetSidePanelWebContentsForTesting());
|
||||
controller->results_side_panel_coordinator()->PopAndLoadQueryFromHistory();
|
||||
fifth_observer.Wait();
|
||||
|
||||
// The search query history stack should be empty and the currently loaded
|
||||
// query should be set.
|
||||
EXPECT_TRUE(GetSearchQueryHistory().empty());
|
||||
const auto second_popped_query = GetLoadedSearchQuery();
|
||||
EXPECT_TRUE(second_popped_query);
|
||||
EXPECT_TRUE(second_popped_query->search_query_text_.empty());
|
||||
VerifySearchQueryParameters(second_popped_query->search_query_url_);
|
||||
VerifyTextQueriesAreEqual(second_popped_query->search_query_url_,
|
||||
first_search_url);
|
||||
EXPECT_FALSE(second_popped_query->selected_region_thumbnail_uri_.empty());
|
||||
EXPECT_EQ(second_popped_query->selected_region_, kTestRegion);
|
||||
EXPECT_FALSE(second_popped_query->selected_region_bitmap_.drawsNothing());
|
||||
EXPECT_EQ(second_popped_query->selected_region_bitmap_.width(), 100);
|
||||
EXPECT_EQ(second_popped_query->selected_region_bitmap_.height(), 100);
|
||||
EXPECT_FALSE(second_popped_query->selected_text_);
|
||||
EXPECT_EQ(second_popped_query->lens_selection_type_, lens::INJECTED_IMAGE);
|
||||
EXPECT_FALSE(second_popped_query->translate_options_);
|
||||
fake_controller->FlushForTesting();
|
||||
EXPECT_TRUE(fake_controller->fake_overlay_page_.source_language_.empty());
|
||||
EXPECT_TRUE(fake_controller->fake_overlay_page_.target_language_.empty());
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
PopAndLoadQueryFromHistoryWithRegionAndTextSelection) {
|
||||
WaitForPaint();
|
||||
@ -3567,7 +3739,7 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
controller->GetSidePanelWebContentsForTesting());
|
||||
controller->IssueLensRegionRequestForTesting(kTestRegion->Clone(),
|
||||
/*is_click=*/false);
|
||||
second_search_observer.WaitForNavigationFinished();
|
||||
second_search_observer.Wait();
|
||||
|
||||
// The search query history stack should have 1 entry and the currently loaded
|
||||
// region should be set.
|
||||
@ -3589,7 +3761,7 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
content::TestNavigationObserver third_search_observer(
|
||||
controller->GetSidePanelWebContentsForTesting());
|
||||
controller->IssueTextSelectionRequestForTesting("kiwi", 1, 100);
|
||||
third_search_observer.WaitForNavigationFinished();
|
||||
third_search_observer.Wait();
|
||||
|
||||
// The search query history stack should have 2 entries and the currently
|
||||
// loaded query should be set to the new query
|
||||
@ -3629,7 +3801,7 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
EXPECT_EQ(fake_query_controller->last_lens_selection_type(),
|
||||
lens::REGION_SEARCH);
|
||||
|
||||
first_pop_observer.WaitForNavigationFinished();
|
||||
first_pop_observer.Wait();
|
||||
|
||||
// The search query history stack should have 1 entry and the previously
|
||||
// loaded region should be present.
|
||||
@ -3648,7 +3820,7 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
content::TestNavigationObserver second_pop_observer(
|
||||
controller->GetSidePanelWebContentsForTesting());
|
||||
controller->results_side_panel_coordinator()->PopAndLoadQueryFromHistory();
|
||||
second_pop_observer.WaitForNavigationFinished();
|
||||
second_pop_observer.Wait();
|
||||
|
||||
// The search query history stack should be empty and the currently loaded
|
||||
// query should be set to the original query.
|
||||
@ -3659,9 +3831,7 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
EXPECT_EQ(loaded_search_query->search_query_text_, "oranges");
|
||||
url_without_start_time_or_size =
|
||||
RemoveStartTimeAndSizeParams(loaded_search_query->search_query_url_);
|
||||
VerifySearchQueryParameters(loaded_search_query->search_query_url_);
|
||||
VerifyTextQueriesAreEqual(loaded_search_query->search_query_url_,
|
||||
first_search_url);
|
||||
EXPECT_EQ(url_without_start_time_or_size, first_search_url);
|
||||
EXPECT_TRUE(loaded_search_query->selected_region_thumbnail_uri_.empty());
|
||||
EXPECT_FALSE(loaded_search_query->selected_region_);
|
||||
EXPECT_TRUE(loaded_search_query->selected_text_);
|
||||
@ -3669,9 +3839,10 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
lens::SELECT_TEXT_HIGHLIGHT);
|
||||
EXPECT_EQ(loaded_search_query->selected_text_->first, 20);
|
||||
EXPECT_EQ(loaded_search_query->selected_text_->second, 200);
|
||||
VerifySearchQueryParameters(second_pop_observer.last_navigation_url());
|
||||
VerifyTextQueriesAreEqual(second_pop_observer.last_navigation_url(),
|
||||
first_search_url);
|
||||
url_without_start_time_or_size =
|
||||
RemoveStartTimeAndSizeParams(second_pop_observer.last_navigation_url());
|
||||
EXPECT_EQ(url_without_start_time_or_size, first_search_url);
|
||||
|
||||
// Verify the text selection was sent back to mojo and any old selections
|
||||
// were cleared.
|
||||
auto* fake_controller = static_cast<LensOverlayControllerFake*>(controller);
|
||||
@ -5566,10 +5737,6 @@ IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
.last_received_should_show_contextual_searchbox_);
|
||||
}
|
||||
|
||||
// TODO(crbug.com/417812533): Tests are currently failing in branded builds due
|
||||
// to missing metrics. Will be fixed as part of work to move recording document
|
||||
// metrics to the contextualization controller.
|
||||
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
PartialPdfIncludedInRequest) {
|
||||
// Open the PDF document and wait for it to finish loading.
|
||||
@ -5600,7 +5767,6 @@ IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
fake_query_controller->last_sent_partial_content().pages(0).text_segments(
|
||||
0));
|
||||
}
|
||||
#endif // !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
|
||||
IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
PageUrlIncludedInRequest) {
|
||||
@ -5654,10 +5820,6 @@ IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
.pdf_page_number());
|
||||
}
|
||||
|
||||
// TODO(crbug.com/417812533): Tests are currently failing in branded builds due
|
||||
// to missing metrics. Will be fixed as part of work to move recording document
|
||||
// metrics to the contextualization controller.
|
||||
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
PdfBytesInFollowUpRequest) {
|
||||
base::HistogramTester histogram_tester;
|
||||
@ -5724,7 +5886,6 @@ IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
"TimeFromNavigationToFirstInteraction",
|
||||
/*expected_count=*/1);
|
||||
}
|
||||
#endif // !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
|
||||
IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
LargePdfNotIncludedInRequest) {
|
||||
@ -5847,10 +6008,6 @@ IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
}));
|
||||
}
|
||||
|
||||
// TODO(crbug.com/417812533): Tests are currently failing in branded builds due
|
||||
// to missing metrics. Will be fixed as part of work to move recording document
|
||||
// metrics to the contextualization controller.
|
||||
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
Histograms) {
|
||||
ukm::TestAutoSetUkmRecorder test_ukm_recorder;
|
||||
@ -5988,7 +6145,6 @@ IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
kPageContentTypeName,
|
||||
static_cast<int64_t>(lens::MimeType::kPdf));
|
||||
}
|
||||
#endif // !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
|
||||
IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
RecordSearchboxFocusedInSessionNavigationHistograms) {
|
||||
@ -6135,10 +6291,6 @@ IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFContextualizationTest,
|
||||
EXPECT_EQ(tab_count, browser()->tab_strip_model()->count());
|
||||
}
|
||||
|
||||
// TODO(crbug.com/417812533): Tests are currently failing in branded builds due
|
||||
// to missing metrics. Will be fixed as part of work to move recording document
|
||||
// metrics to the contextualization controller.
|
||||
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
class LensOverlayControllerBrowserPDFUpdatedContentFieldsTest
|
||||
: public LensOverlayControllerBrowserPDFContextualizationTest {
|
||||
public:
|
||||
@ -6255,19 +6407,15 @@ IN_PROC_BROWSER_TEST_P(LensOverlayControllerBrowserPDFIncreaseLimitTest,
|
||||
0));
|
||||
}
|
||||
|
||||
// TODO(crbug.com/40268279): Stop testing both modes after OOPIF PDF viewer
|
||||
// launches.
|
||||
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE(
|
||||
LensOverlayControllerBrowserPDFUpdatedContentFieldsTest);
|
||||
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE(
|
||||
LensOverlayControllerBrowserPDFIncreaseLimitTest);
|
||||
#endif // !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
|
||||
// TODO(crbug.com/40268279): Stop testing both modes after OOPIF PDF viewer
|
||||
// launches.
|
||||
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE(LensOverlayControllerBrowserPDFTest);
|
||||
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE(
|
||||
LensOverlayControllerBrowserPDFContextualizationTest);
|
||||
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE(
|
||||
LensOverlayControllerBrowserPDFUpdatedContentFieldsTest);
|
||||
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE(
|
||||
LensOverlayControllerBrowserPDFIncreaseLimitTest);
|
||||
|
||||
// Test with --enable-pixel-output-in-tests enabled, required to actually grab
|
||||
// screenshots for color extraction.
|
||||
@ -6555,9 +6703,8 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
auto* fake_query_controller =
|
||||
static_cast<lens::TestLensOverlayQueryController*>(
|
||||
controller->get_lens_overlay_query_controller_for_testing());
|
||||
ASSERT_TRUE(base::test::RunUntil([&]() {
|
||||
return !fake_query_controller->last_sent_underlying_content_bytes().empty();
|
||||
}));
|
||||
ASSERT_FALSE(
|
||||
fake_query_controller->last_sent_underlying_content_bytes().empty());
|
||||
ASSERT_EQ(lens::MimeType::kPlainText,
|
||||
fake_query_controller->last_sent_underlying_content_type());
|
||||
|
||||
@ -6569,10 +6716,6 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
last_sent_underlying_content_bytes.end()));
|
||||
}
|
||||
|
||||
// TODO(crbug.com/417812533): Tests are currently failing in branded builds due
|
||||
// to missing metrics. Will be fixed as part of work to move recording document
|
||||
// metrics to the contextualization controller.
|
||||
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
InnerTextBytesInFollowUpRequest) {
|
||||
base::HistogramTester histogram_tester;
|
||||
@ -6664,7 +6807,6 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
// Verify the similarity score was only recorded once for the session.
|
||||
histogram_tester.ExpectTotalCount("Lens.Overlay.OcrDomSimilarity", 1);
|
||||
}
|
||||
#endif // !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
UpdateScreenshotOnSearchboxFocus) {
|
||||
@ -6722,10 +6864,6 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
.has_image_data());
|
||||
}
|
||||
|
||||
// TODO(crbug.com/417812533): Tests are currently failing in branded builds due
|
||||
// to missing metrics. Will be fixed as part of work to move recording document
|
||||
// metrics to the contextualization controller.
|
||||
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
WebDocumentTypeHistograms) {
|
||||
ukm::TestAutoSetUkmRecorder test_ukm_recorder;
|
||||
@ -6802,7 +6940,6 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
80) == 1;
|
||||
}));
|
||||
}
|
||||
#endif // !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
RecordSearchboxFocusedInSessionHistograms) {
|
||||
@ -6824,9 +6961,8 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
auto* fake_query_controller =
|
||||
static_cast<lens::TestLensOverlayQueryController*>(
|
||||
controller->get_lens_overlay_query_controller_for_testing());
|
||||
ASSERT_TRUE(base::test::RunUntil([&]() {
|
||||
return !fake_query_controller->last_sent_underlying_content_bytes().empty();
|
||||
}));
|
||||
ASSERT_FALSE(
|
||||
fake_query_controller->last_sent_underlying_content_bytes().empty());
|
||||
|
||||
// Simulate the searchbox being focused.
|
||||
controller->OnFocusChangedForTesting(true);
|
||||
@ -6886,9 +7022,8 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
auto* fake_query_controller =
|
||||
static_cast<lens::TestLensOverlayQueryController*>(
|
||||
controller->get_lens_overlay_query_controller_for_testing());
|
||||
ASSERT_TRUE(base::test::RunUntil([&]() {
|
||||
return !fake_query_controller->last_sent_underlying_content_bytes().empty();
|
||||
}));
|
||||
ASSERT_FALSE(
|
||||
fake_query_controller->last_sent_underlying_content_bytes().empty());
|
||||
|
||||
// Close the overlay and assert that the histogram was recorded once and
|
||||
// that the searchbox was not focused in the session.
|
||||
@ -6945,10 +7080,8 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
auto* fake_query_controller =
|
||||
static_cast<lens::TestLensOverlayQueryController*>(
|
||||
controller->get_lens_overlay_query_controller_for_testing());
|
||||
// Verify bytes was updated.
|
||||
ASSERT_TRUE(base::test::RunUntil([&]() {
|
||||
return !fake_query_controller->last_sent_underlying_content_bytes().empty();
|
||||
}));
|
||||
ASSERT_FALSE(
|
||||
fake_query_controller->last_sent_underlying_content_bytes().empty());
|
||||
|
||||
controller->OnZeroSuggestShownForTesting();
|
||||
|
||||
@ -7084,9 +7217,8 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
auto* fake_query_controller =
|
||||
static_cast<lens::TestLensOverlayQueryController*>(
|
||||
controller->get_lens_overlay_query_controller_for_testing());
|
||||
ASSERT_TRUE(base::test::RunUntil([&]() {
|
||||
return !fake_query_controller->last_sent_underlying_content_bytes().empty();
|
||||
}));
|
||||
ASSERT_FALSE(
|
||||
fake_query_controller->last_sent_underlying_content_bytes().empty());
|
||||
|
||||
controller->OnZeroSuggestShownForTesting();
|
||||
|
||||
@ -7192,9 +7324,8 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerBrowserTest,
|
||||
auto* fake_query_controller =
|
||||
static_cast<lens::TestLensOverlayQueryController*>(
|
||||
controller->get_lens_overlay_query_controller_for_testing());
|
||||
ASSERT_TRUE(base::test::RunUntil([&]() {
|
||||
return !fake_query_controller->last_sent_underlying_content_bytes().empty();
|
||||
}));
|
||||
ASSERT_FALSE(
|
||||
fake_query_controller->last_sent_underlying_content_bytes().empty());
|
||||
|
||||
// Close the overlay and assert that the histogram was recorded once and
|
||||
// that zps was not shown in the session.
|
||||
@ -7866,9 +7997,8 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerInnerHtmlEnabledTest,
|
||||
auto* fake_query_controller =
|
||||
static_cast<lens::TestLensOverlayQueryController*>(
|
||||
controller->get_lens_overlay_query_controller_for_testing());
|
||||
ASSERT_TRUE(base::test::RunUntil([&]() {
|
||||
return !fake_query_controller->last_sent_underlying_content_bytes().empty();
|
||||
}));
|
||||
ASSERT_FALSE(
|
||||
fake_query_controller->last_sent_underlying_content_bytes().empty());
|
||||
ASSERT_EQ(lens::MimeType::kHtml,
|
||||
fake_query_controller->last_sent_underlying_content_type());
|
||||
|
||||
@ -8209,10 +8339,6 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerInnerHtmlWithInnerTextAndApc,
|
||||
.last_received_should_show_contextual_searchbox_);
|
||||
}
|
||||
|
||||
// TODO(crbug.com/417812533): Tests are currently failing in branded builds due
|
||||
// to missing metrics. Will be fixed as part of work to move recording document
|
||||
// metrics to the contextualization controller.
|
||||
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
IN_PROC_BROWSER_TEST_F(LensOverlayControllerInnerHtmlWithInnerTextAndApc,
|
||||
PageContentTypeHistograms) {
|
||||
ukm::TestAutoSetUkmRecorder test_ukm_recorder;
|
||||
@ -8292,7 +8418,6 @@ IN_PROC_BROWSER_TEST_F(LensOverlayControllerInnerHtmlWithInnerTextAndApc,
|
||||
80) == 1;
|
||||
}));
|
||||
}
|
||||
#endif // !BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LensOverlayControllerInnerHtmlWithInnerTextAndApc,
|
||||
PageNotContextEligibleError) {
|
||||
|
@ -128,10 +128,6 @@ void LensSearchContextualizationController::GetPageContextualization(
|
||||
void LensSearchContextualizationController::TryUpdatePageContextualization(
|
||||
OnPageContextUpdatedCallback callback) {
|
||||
if (state_ == State::kOff) {
|
||||
// TODO(crbug.com/418825720): The viewport screenshot should be only be set
|
||||
// in this controller in the future.
|
||||
viewport_screenshot_ = lens_search_controller_->lens_overlay_controller()
|
||||
->initial_screenshot();
|
||||
state_ = State::kActive;
|
||||
}
|
||||
CHECK(state_ == State::kActive);
|
||||
@ -230,13 +226,6 @@ void LensSearchContextualizationController::UpdatePageContextualizationPart2(
|
||||
lens::MimeType primary_content_type,
|
||||
std::optional<uint32_t> page_count,
|
||||
const SkBitmap& bitmap) {
|
||||
// It's possible the Lens session could have been closed while updating the
|
||||
// page context. Return early and do not run the callback as it should have
|
||||
// been cleared.
|
||||
if (state_ == State::kOff || !on_page_context_updated_callback_) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_PDF)
|
||||
if (lens::features::SendPdfCurrentPageEnabled()) {
|
||||
pdf::PDFDocumentHelper* pdf_helper =
|
||||
@ -264,13 +253,6 @@ void LensSearchContextualizationController::UpdatePageContextualizationPart3(
|
||||
std::optional<uint32_t> page_count,
|
||||
const SkBitmap& bitmap,
|
||||
std::optional<uint32_t> most_visible_page) {
|
||||
// It's possible the Lens session could have been closed while updating the
|
||||
// page context. Return early and do not run the callback as it should have
|
||||
// been cleared.
|
||||
if (state_ == State::kOff || !on_page_context_updated_callback_) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool sending_bitmap = false;
|
||||
if (!bitmap.drawsNothing() &&
|
||||
(viewport_screenshot_.drawsNothing() ||
|
||||
@ -363,12 +345,7 @@ void LensSearchContextualizationController::UpdatePageContextualizationPart3(
|
||||
lens_search_controller_->GetPageURL(),
|
||||
lens_search_controller_->GetPageTitle(),
|
||||
last_retrieved_most_visible_page_, sending_bitmap ? bitmap : SkBitmap());
|
||||
// TODO(crbug.com/417812533): Record document metrics in metrics helper or in
|
||||
// this controller instead.
|
||||
if (lens_search_controller_->lens_overlay_controller()->IsOverlayActive()) {
|
||||
lens_search_controller_->lens_overlay_controller()->RecordDocumentMetrics(
|
||||
page_count.value_or(0));
|
||||
}
|
||||
// TODO(crbug.com/417812533): Record document metrics.
|
||||
lens_search_controller_->lens_session_metrics_logger()
|
||||
->OnFollowUpPageContentRetrieved(primary_content_type);
|
||||
|
||||
|
@ -187,10 +187,10 @@ void LensSearchController::StartContextualization(
|
||||
// Setup all state necessary for this Lens session.
|
||||
StartLensSession(invocation_source);
|
||||
|
||||
// TODO(crbug.com/418856988): Replace this with a call that starts
|
||||
// contextualization without the unneeded callback.
|
||||
lens_contextualization_controller_->StartContextualization(invocation_source,
|
||||
base::DoNothing());
|
||||
// TODO(crbug.com/404941800): This flow should not start the overlay once
|
||||
// contextualization is separated from the overlay.
|
||||
lens_overlay_controller_->StartContextualizationWithoutOverlay(
|
||||
invocation_source, lens_overlay_query_controller_.get());
|
||||
}
|
||||
|
||||
void LensSearchController::IssueContextualSearchRequest(
|
||||
|
Reference in New Issue
Block a user