// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module side_panel.mojom;
import "url/mojom/url.mojom";
// Methods called on the browser from the companion UI.
// Keep this file in sync with
// google3/java/com/google/lens/web/interfaces/standalone/commonweb/companionparent/companion_parent_communication_service.ts
enum MethodType {
// Methods used in renderer -> browser communication.
// Method corresponding to `CompanionPageHandler.OnPromoAction`.
kOnPromoAction = 1,
// Method corresponding to `CompanionPageHandler.OnRegionSearchClicked`.
kOnRegionSearchClicked = 2,
// Method corresponding to `CompanionPageHandler.OnExpsOptInStatusAvailable`.
kOnExpsOptInStatusAvailable = 3,
// Method corresponding to
// `CompanionPageHandler.OnOpenInNewTabButtonURLChanged`.
kOnOpenInNewTabButtonURLChanged = 4,
// Method corresponding to `CompanionPageHandler.RecordUiSurfaceShown`.
kRecordUiSurfaceShown = 5,
// Method corresponding to `CompanionPageHandler.RecordUiSurfaceClicked`.
kRecordUiSurfaceClicked = 6,
// Method corresponding to `CompanionPageHandler.OnCqCandidatesAvailable`.
kOnCqCandidatesAvailable = 7,
// Method corresponding to `CompanionPageHandler.OnPhFeedback`.
kOnPhFeedback = 8,
// Method corresponding to `CompanionPageHandler.OnCqJumptagClicked`.
kOnCqJumptagClicked = 9,
// Method corresponding to `CompanionPageHandler.OpenUrlInBrowser`.
kOpenUrlInBrowser = 10,
// Method corresponding to `CompanionPageHandler.UpdateLoadingState`.
kCompanionLoadingState = 11,
// Method corresponding to `CompanionPage.RefreshCompanionPage`.
kRefreshCompanionPage = 12,
// Method corresponding to `CompanionPage.ServerSideUrlFilterEvent`.
kServerSideUrlFilterEvent = 13,
// Methods used in browser -> renderer communication.
// Method corresponding to `CompanionPage.UpdateCompanionPage`.
kUpdateCompanionPage = 31,
// Method corresponding to `CompanionPage.OnCqFindTextResultsAvailable`.
kOnCqFindTextResultsAvailable = 32,
// Method corresponding to `CompanionPage.OnDeviceVisualClassificationResult`.
kOnDeviceVisualClassificationResult = 33,
// Method corresponding to `CompanionPage.NotifyLinkOpen`.
kNotifyLinkOpen = 34,
// Method corresponding to `CompanionPage.UpdatePageContent`.
kUpdatePageContent = 35,
};
// Types of promos shown in the companion UI.
// Keep this file in sync with
// google3/java/com/google/lens/web/interfaces/standalone/commonweb/companionparent/companion_parent_communication_service.ts
enum PromoType {
// Promo to sign-in to chrome.
kSignin = 1,
// Promo to turn on make searches and browsing better.
kMsbb = 2,
// Promo to opt into experience api.
kExps = 3,
// IPH about region search capability.
kRegionSearchIPH = 4,
// Promo to enable page content opt-in.
kPco = 5,
};
// Loading states currently in the Companion UI.
// Keep this file in sync with
// google3/java/com/google/lens/web/interfaces/standalone/commonweb/companionparent/companion_parent_communication_service.ts
enum LoadingState {
// The companion is not yet loaded, iFrame not ready for post messages.
kNotStartedLoading = 1,
// The companion has started loading, iFrame ready to handle post messages.
kStartedLoading = 2,
// The companion is done loading, iFrame will drop incoming post messages.
kFinishedLoading = 3,
};
// User actions taken on a promo.
// Keep this file in sync with
// google3/java/com/google/lens/web/interfaces/standalone/commonweb/companionparent/companion_parent_communication_service.ts
enum PromoAction {
// Promo was shown in the companion UI.
kShown = 1,
// User accepted the promo.
kAccepted = 2,
// User declined the promo.
kRejected = 3,
};
// User feedback actions on the PH surface.
// Keep this file in sync with
// google3/java/com/google/lens/web/interfaces/standalone/commonweb/companionparent/companion_parent_communication_service.ts
enum PhFeedback {
// Unknown value. Can be used when the user resets the previous feedback
// action.
kUnknown = 0,
// User clicked thumbs up.
kThumbsUp = 1,
// User clicked thumbs down.
kThumbsDown = 2,
// User clicked report content.
kReportContent = 3,
};
// Data for uploading an image query.
struct ImageQuery {
// URL to upload the image query to.
url.mojom.Url upload_url;
// URL of the image if it exists.
url.mojom.Url image_url;
// Content type representing the image to pass in the POST form.
string content_type;
// Array of image bytes to query.
array<uint8> image_bytes;
// Height of the image before transformations.
uint32 height;
// Width of the image before transformations.
uint32 width;
// Height of the image after transformations.
uint32 downscaled_height;
// Width of the image after transformations.
uint32 downscaled_width;
};
// Metadata for NotifyLinkOpen
// Keep this file in sync with
// google3/java/com/google/lens/web/interfaces/standalone/commonweb/companionparent/companion_parent_communication_service.ts
struct LinkOpenMetadata {
enum LinkOpenAction {
// Link was opened in a new tab.
kNewTab = 1,
// Link opened in the existing main active tab
kClobbered = 2,
// Link click was ignored and did not open
kIgnored = 3,
};
// How the link click was handled by the browser
LinkOpenAction open_action;
// Bool to help with HATS survey metadata
bool is_search_companion_pinned_by_default;
};
// Various UI surfaces on the companion page.
// Keep this file in sync with
// google3/java/com/google/lens/web/interfaces/standalone/commonweb/companionparent/companion_parent_communication_service.ts
enum UiSurface {
kUnknown = 0,
// Used for when the PH initial surface is shown that allows PH to be requested by the user.
kPH = 1,
kCQ = 2,
kRegionSearch = 3,
kSearchBox = 4,
kVQ = 5,
kRelQr = 6,
kRelQs = 7,
kPageEntities = 8,
kATX = 9,
// Used for when requested PH is shown to report the resulting elements and interactions.
kPHResult = 10
};
// Container for sending visual suggestion results to the side panel renderer.
struct VisualSearchResult {
// Base64 encoded image bytes.
string data_uri;
// Alt-text for the image specified by the data uri.
string alt_text;
};
// Factory method for creating a new WebUI page handler.
interface CompanionPageHandlerFactory {
// The WebUI calls this method when the page is first initialized.
CreateCompanionPageHandler(
pending_receiver<CompanionPageHandler> handler,
pending_remote<CompanionPage> page);
};
// Browser-side handler for requests from WebUI page. (TypeScript -> C++)
interface CompanionPageHandler {
// Notify the backend that the UI is ready to be shown.
ShowUI();
// Called to notify the browser about user action of type `promo_action` on a
// promo of type `promo_type`.
OnPromoAction(PromoType promo_type, PromoAction promo_action);
// Called to notify the browser that user has clicked on region search button.
OnRegionSearchClicked();
// Called to notify the browser that the user's experience opt-in status is
// available.
OnExpsOptInStatusAvailable(bool is_exps_opted_in);
// Called to notify the browser that the url used for the 'open in new tab'
// button in the side panel header should be updated. If the url is empty
// the button would be hidden.
OnOpenInNewTabButtonURLChanged(url.mojom.Url url_to_open);
// For metrics only. Called to record that a certain UI surface was shown on
// the companion page. Additionally indicates the number of child elements
// shown within the surface, e.g. the number of related queries shown in
// the related queries component.
// `ui_surface_position` indicates the position of this UI surface within the
// page.
// `child_element_available_count` is the number of candidate children that
// were considered to be shown in the page.
// 'child_element_shown_count` is the number of children that were actually
// shown.
RecordUiSurfaceShown(UiSurface ui_surface, int32 ui_surface_position,
int32 child_element_available_count, int32 child_element_shown_count);
// For metrics only. Called to record that the user clicked on the given UI
// surface on the companion page. These clicks are actual clicks on the
// surface which exclude clicks on the feedback elements. The
// `click_position` refers to the position of the surface within a
// list. Applicable only to certain UI surfaces. Pass -1 when not applicable.
RecordUiSurfaceClicked(UiSurface ui_surface, int32 click_position);
// Called to notify the browser that the cq candidates are available.
OnCqCandidatesAvailable(array<string> text_directives);
// Called in response to user feedback action on the PH surface.
OnPhFeedback(PhFeedback ph_feedback);
// Called to notify the browser that the user has clicked on a jumptag.
// `text_directive` is the URL fragment for highlighting and scrolling-to.
// Ref: https://wicg.github.io/scroll-to-text-fragment/#syntax.
OnCqJumptagClicked(string text_directive);
// Generic method that can be used to open a URL in the browser. Ignored if
// `url_to_open` is invalid.
OpenUrlInBrowser(url.mojom.Url? url_to_open, bool use_new_tab);
// Called to update the browser with the appropriate companion loading state.
OnLoadingState(LoadingState state);
// Does a hard refresh of the companion page with new state.
RefreshCompanionPage();
// For metrics only. Called to record that a URL was excluded from VQS
// triggering due to pXLQ or pornography signals from Diner.
OnServerSideUrlFilterEvent();
};
// WebUI page handler for request from Browser side. (C++ -> TypeScript)
interface CompanionPage {
// Pass the companion URL needed to request the iframe to the frontend for
// rendering. Results in a full reload of the companion side panel.
LoadCompanionPage(url.mojom.Url new_url);
// Notifies the companion page about subsequent navigations on the main page.
// Results in a postmessage() call to the companion with the encoded protobuf
// representation of the update params.
UpdateCompanionPage(string companion_update_proto);
// Pass a new companion URL needed along with a byte string representing the
// image bytes that should be used for the query.
OnImageQuery(ImageQuery image_query);
// Pass the finding results for cq texts to the iframe.
// `text_directives` and `results` have the same length.
OnCqFindTextResultsAvailable(array<string> text_directives,
array<bool> results);
// Pass back results from visual classifier for rendering.
OnDeviceVisualClassificationResult(array<VisualSearchResult> results);
// Called when the companion page attempts a navigation that resulted in an
// error page.
OnNavigationError();
// Notify the frontend that the user clicked a link that is meant to open
// outside of side panel. `opened_url` is the link the user clicked on.
NotifyLinkOpen(url.mojom.Url opened_url, LinkOpenMetadata metadata );
// Passes the title and the innerHtml of the main page to the companion page.
UpdatePageContent(string page_title, string inner_html);
};