Skip to content

Commit

Permalink
[Desktop Android CRX] Update content clients
Browse files Browse the repository at this point in the history
We are experimenting with desktop-android configurations for Chrome.

This CL updates the content client implementations (ChromeContentClient,
ChromeContentBrowserClient, ChromeContentRendererClient) to leverage
extensions code on the experimental desktop-android build.

In practice, this largely means:
* Updating ENABLE_EXTENSIONS (which is true for existing desktop
  platforms) if-defs to ENABLE_EXTENSIONS_CORE (which is true for both
  existing platforms and the experimental desktop-android platform).
* Adding additional ENABLE_EXTENSIONS blocks for cases where some
  handling is not yet supported in the experimental build.
* Updating ENABLE_EXTENSIONS blocks to use more specific flags, such
  as ENABLE_GUEST_VIEW and ENABLE_PLATFORM_APPS.

With this, the experimental desktop-android build is able to load
extensions, start extension processes, and serve resources from the
chrome-extensions protocol -- which are major steps in establishing
the extensions runtime environment. A browser test has been added
to exercise this functionality.

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: I28896e0ad54fdc4619e171e5f10eb7c623725825
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5827844
Commit-Queue: Devlin Cronin <[email protected]>
Auto-Submit: Devlin Cronin <[email protected]>
Code-Coverage: [email protected] <[email protected]>
Commit-Queue: Matthew Denton <[email protected]>
Reviewed-by: Lei Zhang <[email protected]>
Reviewed-by: Matthew Denton <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1349334}
  • Loading branch information
rdcronin authored and Chromium LUCI CQ committed Aug 30, 2024
1 parent 5384739 commit b9e28e7
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 106 deletions.
127 changes: 74 additions & 53 deletions chrome/browser/chrome_content_browser_client.cc

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion chrome/browser/chrome_content_browser_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
base::OnceCallback<void(bool)> callback,
bool allow);

#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_GUEST_VIEW)
void GuestPermissionRequestHelper(
const GURL& url,
const std::vector<content::GlobalRenderFrameHostId>& render_frames,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
#include "chrome/browser/chromeos/printing/print_preview/print_view_manager_cros_basic.h"
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "chrome/browser/extensions/chrome_extensions_browser_client.h"
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_web_contents_observer.h"
#include "extensions/browser/extensions_browser_client.h"
#endif

Expand Down Expand Up @@ -336,7 +336,7 @@ void ChromeContentBrowserClient::RegisterBrowserInterfaceBindersForFrame(
}));
#endif // BUILDFLAG(ENABLE_SPELLCHECK)

#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
const GURL& site = render_frame_host->GetSiteInstance()->GetSiteURL();
if (!site.SchemeIs(extensions::kExtensionScheme))
return;
Expand Down Expand Up @@ -496,7 +496,7 @@ void ChromeContentBrowserClient::
std::move(receiver), render_frame_host);
},
&render_frame_host));
#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
associated_registry.AddInterface<extensions::mojom::LocalFrameHost>(
base::BindRepeating(
[](content::RenderFrameHost* render_frame_host,
Expand All @@ -506,7 +506,7 @@ void ChromeContentBrowserClient::
std::move(receiver), render_frame_host);
},
&render_frame_host));
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
#endif // BUILDFLAG(ENABLE_EXTENSIONS_CORE)
#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
associated_registry.AddInterface<offline_pages::mojom::MhtmlPageNotifier>(
base::BindRepeating(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
// found in the LICENSE file.

#include "base/threading/thread_restrictions.h"
#include "chrome/browser/extensions/desktop_android/desktop_android_extension_system.h"
#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
#include "chrome/test/base/android/android_browser_test.h"
#include "chrome/test/base/chrome_test_utils.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/file_util.h"
#include "extensions/test/result_catcher.h"
#include "extensions/test/test_extension_dir.h"
#include "net/dns/mock_host_resolver.h"

Expand Down Expand Up @@ -90,4 +93,43 @@ IN_PROC_BROWSER_TEST_F(DesktopAndroidExtensionsBrowserTest,
EXPECT_EQ(3, extension->manifest_version());
}

// Tests the adding an extension to the registry and navigating to a
// corresponding page in the extension, verifying the expected content.
IN_PROC_BROWSER_TEST_F(DesktopAndroidExtensionsBrowserTest,
NavigateToExtensionPage) {
static constexpr char kManifest[] =
R"({
"name": "Test Extension",
"version": "0.1",
"manifest_version": 3
})";
static constexpr char kPageHtml[] =
R"(<html>
Hello, world
</html>)";

TestExtensionDir test_dir;
test_dir.WriteManifest(kManifest);
test_dir.WriteFile(FILE_PATH_LITERAL("page.html"), kPageHtml);

scoped_refptr<const Extension> extension =
LoadExtensionFromDirectory(test_dir.UnpackedPath());
ASSERT_TRUE(extension);

content::BrowserContext* browser_context =
GetActiveWebContents()->GetBrowserContext();

auto* android_system = static_cast<DesktopAndroidExtensionSystem*>(
ExtensionSystem::Get(browser_context));
ASSERT_TRUE(android_system);
android_system->AddExtension(extension);

GURL extension_page = extension->GetResourceURL("page.html");

EXPECT_TRUE(content::NavigateToURL(GetActiveWebContents(), extension_page));
EXPECT_EQ(extension_page, GetActiveWebContents()->GetLastCommittedURL());
EXPECT_EQ("Hello, world",
content::EvalJs(GetActiveWebContents(), "document.body.innerText"));
}

} // namespace extensions
16 changes: 11 additions & 5 deletions chrome/browser/prefs/browser_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@
#include "chrome/browser/background/background_mode_manager.h"
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/permissions_manager.h"
#include "extensions/browser/pref_names.h"
#endif // BUILDFLAG(ENABLE_EXTENSIONS_CORE)

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/accessibility/animation_policy_prefs.h"
#include "chrome/browser/apps/platform_apps/shortcut_manager.h"
Expand All @@ -218,9 +224,6 @@
#include "chrome/browser/ui/webui/extensions/extensions_ui.h"
#include "extensions/browser/api/audio/audio_api.h"
#include "extensions/browser/api/runtime/runtime_api.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/permissions_manager.h"
#include "extensions/browser/pref_names.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/crosapi/browser_data_migrator.h"
#include "chrome/browser/ash/device_name/device_name_store.h"
Expand Down Expand Up @@ -1926,17 +1929,20 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
SessionDataService::RegisterProfilePrefs(registry);
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
extensions::PermissionsManager::RegisterProfilePrefs(registry);
extensions::ExtensionPrefs::RegisterProfilePrefs(registry);
#endif // BUILDFLAG(ENABLE_EXTENSIONS_CORE)

#if BUILDFLAG(ENABLE_EXTENSIONS)
ExtensionWebUI::RegisterProfilePrefs(registry);
RegisterAnimationPolicyPrefs(registry);
extensions::ActivityLog::RegisterProfilePrefs(registry);
extensions::AudioAPI::RegisterUserPrefs(registry);
extensions::ExtensionPrefs::RegisterProfilePrefs(registry);
extensions::ExtensionsUI::RegisterProfilePrefs(registry);
#if BUILDFLAG(IS_CHROMEOS_ASH)
extensions::shared_storage::RegisterProfilePrefs(registry);
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
extensions::PermissionsManager::RegisterProfilePrefs(registry);
extensions::RuntimeAPI::RegisterPrefs(registry);
// TODO(devlin): This would be more inline with the other calls here if it
// were nested in either a class or separate namespace with a simple
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@
#include "chrome/browser/signin/signin_manager_factory.h"
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
#include "extensions/browser/browser_context_keyed_service_factories.h"
#endif // BUILDFLAG(ENABLE_EXTENSIONS_CORE)

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "apps/browser_context_keyed_service_factories.h"
#include "chrome/browser/apps/platform_apps/api/browser_context_keyed_service_factories.h"
Expand All @@ -384,12 +388,15 @@
#include "chrome/browser/web_applications/web_app_provider_factory.h"
#include "components/omnibox/browser/omnibox_input_watcher.h"
#include "components/omnibox/browser/omnibox_suggestions_watcher.h"
#include "extensions/browser/browser_context_keyed_service_factories.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/chromeos/extensions/telemetry/api/telemetry_extension_api_browser_context_keyed_service_factories.h"
#include "chrome/browser/extensions/api/chromeos_api_browser_context_keyed_service_factories.h"
#endif
#endif // BUILDFLAG(IS_CHROMEOS)
#endif // BUILDFLAG(ENABLE_EXTENSIONS)

#if BUILDFLAG(ENABLE_DESKTOP_ANDROID_EXTENSIONS)
#include "chrome/browser/extensions/desktop_android/desktop_android_extension_system.h"
#endif

#if BUILDFLAG(ENABLE_SESSION_SERVICE)
Expand Down Expand Up @@ -591,9 +598,16 @@ void ChromeBrowserMainExtraPartsProfiles::
chromeos::EnsureBrowserContextKeyedServiceFactoriesBuilt();
chromeos_extensions::EnsureBrowserContextKeyedServiceFactoriesBuilt();
#endif // BUILDFLAG(IS_CHROMEOS)
extensions::EnsureBrowserContextKeyedServiceFactoriesBuilt();
#endif // BUILDFLAG(ENABLE_EXTENSIONS)

#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
extensions::EnsureBrowserContextKeyedServiceFactoriesBuilt();
#endif

#if BUILDFLAG(ENABLE_DESKTOP_ANDROID_EXTENSIONS)
extensions::DesktopAndroidExtensionSystem::GetFactory();
#endif

// ---------------------------------------------------------------------------
// Common factory registrations (Please keep this list ordered without taking
// into consideration buildflags, repeating buildflags is ok):
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/profiles/profile_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include "net/net_buildflags.h"
#include "url/gurl.h"

#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
#include "extensions/common/constants.h"
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
#endif // BUILDFLAG(ENABLE_EXTENSIONS_CORE)

// static
bool ProfileIOData::IsHandledProtocol(const std::string& scheme) {
Expand All @@ -35,7 +35,7 @@ bool ProfileIOData::IsHandledProtocol(const std::string& scheme) {
url::kFileScheme,
content::kChromeDevToolsScheme,
dom_distiller::kDomDistillerScheme,
#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
extensions::kExtensionScheme,
#endif
content::kChromeUIScheme,
Expand Down
12 changes: 9 additions & 3 deletions chrome/browser/profiles/profile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,14 @@
#include "google_apis/gaia/gaia_auth_util.h"
#include "ui/base/l10n/l10n_util.h"

#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
#include "extensions/browser/extension_system.h"
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/extension_service.h"
#include "extensions/browser/api/management/management_api.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/manifest.h"
#endif
Expand Down Expand Up @@ -1472,7 +1475,7 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,

TRACE_EVENT0("browser", "ProfileManager::DoFinalInitForServices");

#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
bool extensions_enabled = !go_off_the_record;
#if BUILDFLAG(IS_CHROMEOS_ASH)
if ((!base::CommandLine::ForCurrentProcess()->HasSwitch(
Expand All @@ -1486,6 +1489,7 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
extensions::ExtensionSystem::Get(profile)->InitForRegularProfile(
extensions_enabled);

#if BUILDFLAG(ENABLE_EXTENSIONS)
// Set the block extensions bit on the ExtensionService. There likely are no
// blockable extensions to block.
ProfileAttributesEntry* entry =
Expand All @@ -1496,6 +1500,7 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
->extension_service()
->BlockAllExtensions();
}
#endif // BUILDFLAG(ENABLE_EXTENSIONS)

#if BUILDFLAG(IS_CHROMEOS)
// Ensure that the `ContactCenterInsightsExtensionManager` is instantiated
Expand All @@ -1510,7 +1515,8 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
}
#endif

#endif
#endif // BUILDFLAG(ENABLE_EXTENSIONS_CORE)

// Initialization needs to happen after extension system initialization (for
// extension::ManagementPolicy) and InitProfileUserPrefs (for setting the
// initializing the supervised flag if necessary).
Expand Down
6 changes: 4 additions & 2 deletions chrome/browser/sync/prefs/chrome_syncable_prefs_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
#include "components/variations/service/google_groups_manager_prefs.h"
#include "ui/events/ash/pref_names.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
#include "extensions/browser/pref_names.h" // nogncheck
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "components/supervised_user/core/common/pref_names.h"
#include "extensions/browser/pref_names.h" // nogncheck
#endif

namespace browser_sync {
Expand Down Expand Up @@ -532,7 +534,7 @@ constexpr auto kChromeSyncablePrefsAllowlist = base::MakeFixedFlatMap<
syncer::PREFERENCES, sync_preferences::PrefSensitivity::kNone,
sync_preferences::MergeBehavior::kNone}},
#endif // BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
{extensions::pref_names::kPinnedExtensions,
{syncable_prefs_ids::kPinnedExtensions, syncer::PREFERENCES,
sync_preferences::PrefSensitivity::kNone,
Expand Down
12 changes: 6 additions & 6 deletions chrome/common/chrome_content_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
#include "base/win/windows_version.h"
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
#include "extensions/common/constants.h"
#endif

Expand Down Expand Up @@ -238,7 +238,7 @@ void ChromeContentClient::AddContentDecryptionModules(
// details). If you add a new scheme, please also add WPT tests for it like
// https://crrev.com/c/5790445.
static const char* const kChromeStandardURLSchemes[] = {
#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
extensions::kExtensionScheme,
#endif
chrome::kIsolatedAppScheme, chrome::kChromeNativeScheme,
Expand All @@ -256,11 +256,11 @@ void ChromeContentClient::AddAdditionalSchemes(Schemes* schemes) {
schemes->referrer_schemes.push_back(content::kAndroidAppScheme);
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
schemes->extension_schemes.push_back(extensions::kExtensionScheme);
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
schemes->savable_schemes.push_back(extensions::kExtensionScheme);
#endif
schemes->savable_schemes.push_back(chrome::kChromeSearchScheme);
Expand All @@ -269,7 +269,7 @@ void ChromeContentClient::AddAdditionalSchemes(Schemes* schemes) {
// chrome-search: resources shouldn't trigger insecure content warnings.
schemes->secure_schemes.push_back(chrome::kChromeSearchScheme);

#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
// Treat extensions as secure because communication with them is entirely in
// the browser, so there is no danger of manipulation or eavesdropping on
// communication with them by third parties.
Expand All @@ -283,7 +283,7 @@ void ChromeContentClient::AddAdditionalSchemes(Schemes* schemes) {
schemes->no_access_schemes.push_back(chrome::kChromeNativeScheme);
schemes->secure_schemes.push_back(chrome::kChromeNativeScheme);

#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS_CORE)
schemes->service_worker_schemes.push_back(extensions::kExtensionScheme);
schemes->service_worker_schemes.push_back(url::kFileScheme);

Expand Down
Loading

0 comments on commit b9e28e7

Please sign in to comment.