Files
brave-core/android
Artem Samoilenko b5fb6d3ad8 [cr149][Android] Changes for Lens Overlay feature
Chromium changes:
https://chromium.googlesource.com/chromium/src/+/5adc915936b90ddebf40821b4cfd1ff29d5ca307

commit 5adc915936b90ddebf40821b4cfd1ff29d5ca307
Author: Samuel Huang <huangs@chromium.org>
Date:   Fri May 1 11:52:17 2026 -0700

    [Lens Overlay] Add App Menu entry point and JNI scaffolding

    This CL introduces the initial Android App Menu entry point for the Lens
    Overlay feature on Android, alongside foundational Java-to-C++ JNI
    scaffolding.

    Implementation follows a staged approach:
    1. Short-term (Current focus): Build an "Intent-based handoff" pipeline
       that captures a screenshot, formats it for external consumption, and
       delegates the search flow to the Google Lens app (AGSA) via Intent.
    2. Long-term: Host a Chrome-native overlay that provides the feature's
       WebUI directly within the browser, reusing existing Desktop code.

    The JNI bridge established here provides the functional entry point for
    the Stage 1 screenshot and handoff logic. In this initial CL, it is
    utilized to invoke shared C++ metrics code to ensure immediate
    feature-parity in tracking with the Desktop implementation.

    Since our ultimate goal is to align with Desktop functionalities, we
    reuse strings and shared code as much as is practical.

    Note: The feature is temporarily disabled in Incognito mode. Because
    the short-term implementation delegates to Google Lens (an external
    app), disabling it in Incognito prevents sending user data across app
    boundaries without explicit consent. We anticipate enabling Incognito
    support in the long-term implementation (matching Desktop behavior).

    Details:
    * Add IDS_LENS_OVERLAY_APP_MENU = "Search with Google lens" (same as the
      Desktop string) as an Android-specific asset. We duplicate for now to
      avoid massive asset refactorization.
    * Add the "Search with Google Lens" item to the App Menu
      (`TabbedAppMenuPropertiesDelegate`), placed between "Find in page" and
      "Translate...".
    * Guard the new UI behind the `ChromeFeatureList.LENS_OVERLAY_ANDROID`
      feature flag.
    * Create `LensOverlayCoordinator` (Java) and
      `LensOverlayControllerAndroid` (C++), bridging them via JNI to
      establish the functional entry point for the feature.
    * Hook the menu click into `RootUiCoordinator` to launch the
      coordinator. This implements a dual-metrics strategy:
      * Record Android core UI metrics via
        `RecordUserAction("MobileMenuLensOverlay")`.
      * Record Lens feature metrics (`lens::RecordInvocation()`) via the
        C++ controller, which will handle slicing by document MIME type in a
        future CL.
    * Generate `LensOverlayInvocationSource` using `java_cpp_enum` to
      mirror the C++ enum for accurate UMA histogram recording across the
      JNI bridge, preventing future desyncs.
    * Add unit tests to `TabbedAppMenuPropertiesDelegateUnitTest` to verify
      the Lens Overlay menu item is correctly shown on standard web pages
      and correctly hidden on the NTP, in Incognito mode, or when the
      feature flag is disabled.
    * Create `chrome/browser/ui/android/lens/OWNERS` to manage the new
      feature directory.

    Bug: 507533812, 493627069
    Change-Id: I87eaaaee9b4e21f8071a3fd88666cb06ff4e2d3f
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7800658
    Reviewed-by: Calder Kitagawa <ckitagawa@chromium.org>
    Commit-Queue: Samuel Huang <huangs@chromium.org>
    Reviewed-by: Bryan Nguyen <nguyenbryan@google.com>
    Cr-Commit-Position: refs/heads/main@{#1623965}
2026-05-22 16:57:34 -04:00
..