forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Desktop Android CRX] Enable the chrome.test API
We are experimenting with desktop-android configurations for Chrome. This CL enables extension runtimes in Chrome in the experimental desktop-android build to call extension APIs and enables the chrome.test API (which is an API that implements a JS testing framework, used extensively in extension tests). This involves adding a few missing pieces needed for the API system (such as an ExtensionWebContentsObserver), properly instantiating the APIs, and further adjusting the content browser client behavior to properly handle extension URLs on desktop-android (replacing ENABLE_EXTENSIONS with ENABLE_EXTENSIONS_CORE). After this, the general extensions API system is functional, including renderer side bindings, custom binding JS injection, serialization of arguments, and handling on the browser side. Update a browsertest to exercise the same. This CL should have no production behavior change, since the desktop-android configuration is still highly experimental. Cq-Include-Trybots: luci.chromium.try:android-desktop-arm64-compile-rel,android-desktop-x64-compile-rel Bug: 356905053 Change-Id: I5f83b3b72a351461555e458b705fb6d90b227874 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5827799 Commit-Queue: Devlin Cronin <[email protected]> Reviewed-by: David Bertoni <[email protected]> Reviewed-by: Lei Zhang <[email protected]> Cr-Commit-Position: refs/heads/main@{#1351015}
- Loading branch information
Showing
9 changed files
with
179 additions
and
28 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
30 changes: 30 additions & 0 deletions
30
chrome/browser/extensions/desktop_android/desktop_android_extension_web_contents_observer.cc
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,30 @@ | ||
// Copyright 2024 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/extensions/desktop_android/desktop_android_extension_web_contents_observer.h" | ||
|
||
namespace extensions { | ||
|
||
DesktopAndroidExtensionWebContentsObserver:: | ||
DesktopAndroidExtensionWebContentsObserver( | ||
content::WebContents* web_contents) | ||
: ExtensionWebContentsObserver(web_contents), | ||
content::WebContentsUserData<DesktopAndroidExtensionWebContentsObserver>( | ||
*web_contents) {} | ||
|
||
DesktopAndroidExtensionWebContentsObserver:: | ||
~DesktopAndroidExtensionWebContentsObserver() = default; | ||
|
||
void DesktopAndroidExtensionWebContentsObserver::CreateForWebContents( | ||
content::WebContents* web_contents) { | ||
content::WebContentsUserData<DesktopAndroidExtensionWebContentsObserver>:: | ||
CreateForWebContents(web_contents); | ||
|
||
// Initialize this instance if necessary. | ||
FromWebContents(web_contents)->Initialize(); | ||
} | ||
|
||
WEB_CONTENTS_USER_DATA_KEY_IMPL(DesktopAndroidExtensionWebContentsObserver); | ||
|
||
} // namespace extensions |
74 changes: 74 additions & 0 deletions
74
chrome/browser/extensions/desktop_android/desktop_android_extension_web_contents_observer.h
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,74 @@ | ||
// Copyright 2024 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_EXTENSIONS_DESKTOP_ANDROID_DESKTOP_ANDROID_EXTENSION_WEB_CONTENTS_OBSERVER_H_ | ||
#define CHROME_BROWSER_EXTENSIONS_DESKTOP_ANDROID_DESKTOP_ANDROID_EXTENSION_WEB_CONTENTS_OBSERVER_H_ | ||
|
||
#include "content/public/browser/web_contents_user_data.h" | ||
#include "extensions/browser/extension_web_contents_observer.h" | ||
|
||
namespace extensions { | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// S T O P | ||
// ALL THIS CODE WILL BE DELETED. | ||
// THINK TWICE (OR THRICE) BEFORE ADDING MORE. | ||
// | ||
// The details: | ||
// This is part of an experimental desktop-android build and allows us to | ||
// bootstrap the extension system by incorporating a lightweight extensions | ||
// runtime into the chrome binary. This allows us to do things like load | ||
// extensions in tests and exercise code in these builds without needing to have | ||
// the entirety of the //chrome/browser/extensions system either compiled and | ||
// implemented (which is a massive undertaking) or gracefully if-def'd out | ||
// (which is a massive amount of technical debt). | ||
// This approach, by comparison, allows us to have a minimal interface in the | ||
// chrome browser that mostly relies on the top-level //extensions layer, along | ||
// with small bits of the //chrome code that compile cleanly on the | ||
// experimental desktop-android build. | ||
// | ||
// This entire class should go away. Instead of adding new functionality here, | ||
// it should be added in a location that can be shared across desktop-android | ||
// and other desktop builds. In practice, this means: | ||
// * Pulling the code up to //extensions. If it can be cleanly segmented from | ||
// the //chrome layer, this is preferable. It gets cleanly included across | ||
// all builds, encourages proper separation of concerns, and reduces the | ||
// interdependency between features. | ||
// * Including the functionality in the desktop-android build. This can be done | ||
// for //chrome sources that do not have any dependencies on areas that | ||
// cannot be included in desktop-android (such as dependencies on `Browser` | ||
// or native UI code). | ||
// | ||
// TODO(https://crbug.com/356905053): Delete this class once desktop-android | ||
// properly leverages the extension system. | ||
//////////////////////////////////////////////////////////////////////////////// | ||
class DesktopAndroidExtensionWebContentsObserver | ||
: public ExtensionWebContentsObserver, | ||
public content::WebContentsUserData< | ||
DesktopAndroidExtensionWebContentsObserver> { | ||
public: | ||
DesktopAndroidExtensionWebContentsObserver( | ||
const DesktopAndroidExtensionWebContentsObserver&) = delete; | ||
DesktopAndroidExtensionWebContentsObserver& operator=( | ||
const DesktopAndroidExtensionWebContentsObserver&) = delete; | ||
|
||
~DesktopAndroidExtensionWebContentsObserver() override; | ||
|
||
// Creates and initializes an instance of this class for the given | ||
// `web_contents`, if it doesn't already exist. | ||
static void CreateForWebContents(content::WebContents* web_contents); | ||
|
||
private: | ||
friend class content::WebContentsUserData< | ||
DesktopAndroidExtensionWebContentsObserver>; | ||
|
||
explicit DesktopAndroidExtensionWebContentsObserver( | ||
content::WebContents* web_contents); | ||
|
||
WEB_CONTENTS_USER_DATA_KEY_DECL(); | ||
}; | ||
|
||
} // namespace extensions | ||
|
||
#endif // CHROME_BROWSER_EXTENSIONS_DESKTOP_ANDROID_DESKTOP_ANDROID_EXTENSION_WEB_CONTENTS_OBSERVER_H_ |
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
Oops, something went wrong.