Skip to content

Commit

Permalink
Split wallpaper search from customize chrome handler
Browse files Browse the repository at this point in the history
Creates a new Mojo interface for Wallpaper Search operations. And binds
that interface in the browser process. Moves all Wallpaper Search
related functions to the new Mojo interface.

The rationale is to componentize the code and make it FastPath++
eligible.

bug: b/308355145
Change-Id: I4299dc89f59b113bf6e84828c0a16bf80048f25d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4985579
Reviewed-by: John Lee <johntlee@chromium.org>
Reviewed-by: Riley Tatum <rtatum@google.com>
Commit-Queue: John Lee <johntlee@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Auto-Submit: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: Alex Gough <ajgo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1217247}
  • Loading branch information
Tibor Goldschwendt authored and Chromium LUCI CQ committed Oct 30, 2023
1 parent 95665af commit 8001fcb
Show file tree
Hide file tree
Showing 22 changed files with 1,271 additions and 1,021 deletions.
11 changes: 11 additions & 0 deletions chrome/browser/chrome_browser_interface_binders.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
#include "chrome/browser/ui/webui/side_panel/companion/companion_side_panel_untrusted_ui.h"
#include "chrome/browser/ui/webui/side_panel/customize_chrome/customize_chrome.mojom.h"
#include "chrome/browser/ui/webui/side_panel/customize_chrome/customize_chrome_ui.h"
#include "chrome/browser/ui/webui/side_panel/customize_chrome/wallpaper_search/wallpaper_search.mojom.h"
#include "chrome/browser/ui/webui/side_panel/history_clusters/history_clusters_side_panel_ui.h"
#include "chrome/browser/ui/webui/side_panel/performance_controls/performance_side_panel_ui.h"
#include "chrome/browser/ui/webui/side_panel/read_anything/read_anything_untrusted_ui.h"
Expand All @@ -208,6 +209,7 @@
#include "chrome/browser/ui/webui/whats_new/whats_new_ui.h"
#include "chrome/common/webui_url_constants.h"
#include "components/commerce/core/mojom/shopping_list.mojom.h" // nogncheck crbug.com/1125897
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/page_image_service/mojom/page_image_service.mojom.h"
#include "components/search/ntp_features.h"
#include "ui/webui/resources/cr_components/color_change_listener/color_change_listener.mojom.h"
Expand Down Expand Up @@ -1284,6 +1286,15 @@ void PopulateChromeWebUIFrameBinders(
RegisterWebUIControllerInterfaceBinder<
side_panel::mojom::CustomizeChromePageHandlerFactory,
CustomizeChromeUI>(map);

if (base::FeatureList::IsEnabled(
ntp_features::kCustomizeChromeWallpaperSearch) &&
base::FeatureList::IsEnabled(
optimization_guide::features::kOptimizationGuideModelExecution)) {
RegisterWebUIControllerInterfaceBinder<
side_panel::customize_chrome::mojom::WallpaperSearchHandler,
CustomizeChromeUI>(map);
}
}

if (user_notes::IsUserNotesEnabled()) {
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/resources/side_panel/customize_chrome/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ build_webui("build") {
non_web_component_files = [
"chrome_cart_proxy.ts",
"customize_chrome_api_proxy.ts",
"wallpaper_search/wallpaper_search_proxy.ts",
"window_proxy.ts",
]

Expand All @@ -44,6 +45,7 @@ build_webui("build") {
mojo_files = [
"$root_gen_dir/chrome/browser/cart/chrome_cart.mojom-webui.ts",
"$root_gen_dir/chrome/browser/ui/webui/side_panel/customize_chrome/customize_chrome.mojom-webui.ts",
"$root_gen_dir/chrome/browser/ui/webui/side_panel/customize_chrome/wallpaper_search/wallpaper_search.mojom-webui.ts",
]

ts_composite = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import {Token} from 'chrome://resources/mojo/mojo/public/mojom/base/token.mojom-
import {DomRepeatEvent, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {CustomizeChromeCombobox} from './combobox/customize_chrome_combobox.js';
import {CustomizeChromePageCallbackRouter, CustomizeChromePageHandlerInterface, DescriptorA, DescriptorDValue, Descriptors, Theme, WallpaperSearchResult} from './customize_chrome.mojom-webui.js';
import {CustomizeChromePageCallbackRouter, CustomizeChromePageHandlerInterface, Theme} from './customize_chrome.mojom-webui.js';
import {CustomizeChromeApiProxy} from './customize_chrome_api_proxy.js';
import {getTemplate} from './wallpaper_search.html.js';
import {DescriptorA, DescriptorDValue, Descriptors, WallpaperSearchHandlerInterface, WallpaperSearchResult} from './wallpaper_search.mojom-webui.js';
import {WallpaperSearchProxy} from './wallpaper_search/wallpaper_search_proxy.js';

export const DESCRIPTOR_D_VALUE =
['#ef4837', '#0984e3', '#f9cc18', '#23cc6a', '#474747'];
Expand Down Expand Up @@ -101,13 +103,15 @@ export class WallpaperSearchElement extends PolymerElement {

private callbackRouter_: CustomizeChromePageCallbackRouter;
private pageHandler_: CustomizeChromePageHandlerInterface;
private wallpaperSearchHandler_: WallpaperSearchHandlerInterface;
private setThemeListenerId_: number|null = null;

constructor() {
super();
this.callbackRouter_ = CustomizeChromeApiProxy.getInstance().callbackRouter;
this.pageHandler_ = CustomizeChromeApiProxy.getInstance().handler;
this.pageHandler_.getDescriptors().then(({descriptors}) => {
this.wallpaperSearchHandler_ = WallpaperSearchProxy.getHandler();
this.wallpaperSearchHandler_.getDescriptors().then(({descriptors}) => {
if (descriptors) {
this.descriptors_ = descriptors;
}
Expand Down Expand Up @@ -169,17 +173,19 @@ export class WallpaperSearchElement extends PolymerElement {
this.loading_ = true;
this.results_ = [];
this.emptyContainers_ = [];
const {results} = await this.pageHandler_.getWallpaperSearchResults(
this.selectedDescriptorA_, this.selectedDescriptorB_,
this.selectedDescriptorC_, this.selectedDescriptorD_);
const {results} =
await this.wallpaperSearchHandler_.getWallpaperSearchResults(
this.selectedDescriptorA_, this.selectedDescriptorB_,
this.selectedDescriptorC_, this.selectedDescriptorD_);
this.loading_ = false;
this.results_ = results;
this.emptyContainers_ = Array.from(
{length: results.length > 0 ? 6 - results.length : 0}, () => 0);
}

private async onResultClick_(e: DomRepeatEvent<WallpaperSearchResult>) {
this.pageHandler_.setBackgroundToWallpaperSearchResult(e.model.item.id);
this.wallpaperSearchHandler_.setBackgroundToWallpaperSearchResult(
e.model.item.id);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.

import {WallpaperSearchHandler, WallpaperSearchHandlerInterface} from '../wallpaper_search.mojom-webui.js';

let handler: WallpaperSearchHandlerInterface|null = null;

export class WallpaperSearchProxy {
static getHandler(): WallpaperSearchHandlerInterface {
return handler || (handler = WallpaperSearchHandler.getRemote());
}

static setHandler(newHandler: WallpaperSearchHandlerInterface) {
handler = newHandler;
}

private constructor() {}
}
2 changes: 2 additions & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,8 @@ static_library("ui") {
"webui/side_panel/customize_chrome/customize_chrome_page_handler.h",
"webui/side_panel/customize_chrome/customize_chrome_ui.cc",
"webui/side_panel/customize_chrome/customize_chrome_ui.h",
"webui/side_panel/customize_chrome/wallpaper_search/wallpaper_search_handler.cc",
"webui/side_panel/customize_chrome/wallpaper_search/wallpaper_search_handler.h",
"webui/side_panel/history_clusters/history_clusters_side_panel_ui.cc",
"webui/side_panel/history_clusters/history_clusters_side_panel_ui.h",
"webui/side_panel/performance_controls/performance_page_handler.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include "components/enterprise/browser/controller/fake_browser_dm_token_storage.h"
#include "components/history_clusters/core/features.h"
#include "components/nacl/common/buildflags.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/search/ntp_features.h"
#include "components/user_notes/user_notes_features.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_handle.h"
Expand Down Expand Up @@ -182,6 +184,9 @@ class ChromeURLDataManagerWebUITrustedTypesTest
enabled_features.push_back(history_clusters::kSidePanelJourneys);
enabled_features.push_back(features::kSupportTool);
enabled_features.push_back(features::kCustomizeChromeSidePanel);
enabled_features.push_back(ntp_features::kCustomizeChromeWallpaperSearch);
enabled_features.push_back(
optimization_guide::features::kOptimizationGuideModelExecution);
enabled_features.push_back(features::kReadAnything);
enabled_features.push_back(user_notes::kUserNotes);

Expand Down
5 changes: 4 additions & 1 deletion chrome/browser/ui/webui/side_panel/customize_chrome/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import("//mojo/public/tools/bindings/mojom.gni")
assert(!is_android)

mojom("mojo_bindings") {
sources = [ "customize_chrome.mojom" ]
sources = [
"customize_chrome.mojom",
"wallpaper_search/wallpaper_search.mojom",
]
webui_module_path = "/"
public_deps = [
"//mojo/public/mojom/base",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,6 @@ enum CustomizeChromeSection {
kModules,
};

struct DescriptorA {
string category;
array<string> labels;
};

struct DescriptorB {
string label;
string image_path;
};

union DescriptorDValue {
skia.mojom.SkColor color;
float hue;
};

struct Descriptors {
array<DescriptorA> descriptor_a;
array<DescriptorB> descriptor_b;
array<string> descriptor_c;
};

struct WallpaperSearchResult {
mojo_base.mojom.Token id;
string image;
};

// Used by the WebUI page to bootstrap bidirectional communication.
interface CustomizeChromePageHandlerFactory {
// The WebUI calls this method when the page is first initialized.
Expand Down Expand Up @@ -180,19 +154,6 @@ interface CustomizeChromePageHandler {

// Triggers a call to |CustomizeChromePage.UpdateScrollToSection()|.
UpdateScrollToSection();

// Retrieves NTP descriptors.
GetDescriptors() => (Descriptors? descriptors);

// Searches NTP wallpaper for descriptors.
// Returns list of sanitized image data.
GetWallpaperSearchResults(string descriptor_a,
string? descriptor_b, string? descriptor_c,
DescriptorDValue? descriptor_d_value)
=> (array<WallpaperSearchResult> results);

// Sets wallpaper search result of index to background image.
SetBackgroundToWallpaperSearchResult(mojo_base.mojom.Token result_id);
};

// WebUI-side handler for requests from the browser.
Expand Down

0 comments on commit 8001fcb

Please sign in to comment.