Skip to content

Commit

Permalink
[AW][ComponentUpdater] Load components during WebView startup
Browse files Browse the repository at this point in the history
Create an EmbeddedComponentLoader and use it to connect to
ComponentProviderService to load components files during WebView
startup.

We don't connect to the service if there are no components registered,
which is the case now.

Bug: 1180835
Change-Id: I42138c13c5a5ce94b843f7b266a8c8b213396827
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2712903
Reviewed-by: Sorin Jianu <[email protected]>
Reviewed-by: Bo <[email protected]>
Reviewed-by: Mugdha Lakhani <[email protected]>
Commit-Queue: Hazem Ashmawy <[email protected]>
Cr-Commit-Position: refs/heads/master@{#861618}
  • Loading branch information
HazemSamir authored and Chromium LUCI CQ committed Mar 10, 2021
1 parent e984f76 commit 870d053
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions android_webview/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ android_library("browser_java") {
"//components/autofill/android:autofill_java",
"//components/autofill/android/provider:java",
"//components/background_task_scheduler:background_task_scheduler_task_ids_java",
"//components/component_updater/android:embedded_component_loader_java",
"//components/content_capture/android:java",
"//components/crash/android:handler_java",
"//components/crash/android:java",
Expand Down
3 changes: 3 additions & 0 deletions android_webview/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ source_set("browser") {
"aw_web_contents_view_delegate.h",
"aw_web_ui_controller_factory.cc",
"aw_web_ui_controller_factory.h",
"component_updater/registration.cc",
"component_updater/registration.h",
"cookie_manager.cc",
"cookie_manager.h",
"find_helper.cc",
Expand Down Expand Up @@ -193,6 +195,7 @@ source_set("browser") {
"//components/autofill/android/provider",
"//components/autofill/content/browser",
"//components/cdm/browser",
"//components/component_updater/android:embedded_component_loader",
"//components/content_capture/android",
"//components/content_capture/browser",
"//components/embedder_support/android:util",
Expand Down
1 change: 1 addition & 0 deletions android_webview/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ include_rules = [
"+components/autofill/core/browser",
"+components/autofill/core/common",
"+components/cdm/browser",
"+components/component_updater/android",
"+components/crash/content/browser",
"+components/crash/core",
"+components/download/public/common",
Expand Down
10 changes: 10 additions & 0 deletions android_webview/browser/aw_browser_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
#include "android_webview/browser/aw_browser_process.h"

#include "android_webview/browser/aw_browser_context.h"
#include "android_webview/browser/component_updater/registration.h"
#include "android_webview/browser/lifecycle/aw_contents_lifecycle_notifier.h"
#include "android_webview/browser/metrics/visibility_metrics_logger.h"
#include "android_webview/browser_jni_headers/AwBrowserProcess_jni.h"
#include "android_webview/common/crash_reporter/crash_keys.h"
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/base_paths_posix.h"
#include "base/path_service.h"
#include "base/task/thread_pool.h"
#include "components/component_updater/android/component_loader_policy.h"
#include "components/crash/core/common/crash_key.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
Expand Down Expand Up @@ -224,4 +227,11 @@ static void JNI_AwBrowserProcess_SetProcessNameCrashKey(
crash_key.Set(ConvertJavaStringToUTF8(env, processName));
}

static base::android::ScopedJavaLocalRef<jobjectArray>
JNI_AwBrowserProcess_GetComponentLoaderPolicies(JNIEnv* env) {
return component_updater::AndroidComponentLoaderPolicy::
ToJavaArrayOfAndroidComponentLoaderPolicy(env,
GetComponentLoaderPolicies());
}

} // namespace android_webview
14 changes: 14 additions & 0 deletions android_webview/browser/component_updater/registration.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "android_webview/browser/component_updater/registration.h"

namespace android_webview {

component_updater::ComponentLoaderPolicyVector GetComponentLoaderPolicies() {
// TODO(crbug.com/1171762) register trust tokens component.
return component_updater::ComponentLoaderPolicyVector();
}

} // namespace android_webview
18 changes: 18 additions & 0 deletions android_webview/browser/component_updater/registration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ANDROID_WEBVIEW_BROWSER_COMPONENT_UPDATER_REGISTRATION_H_
#define ANDROID_WEBVIEW_BROWSER_COMPONENT_UPDATER_REGISTRATION_H_

#include "components/component_updater/android/component_loader_policy.h"

namespace android_webview {

// ComponentLoaderPolicies for component to load in an embedded WebView during
// startup.
component_updater::ComponentLoaderPolicyVector GetComponentLoaderPolicies();

} // namespace android_webview

#endif // ANDROID_WEBVIEW_BROWSER_COMPONENT_UPDATER_REGISTRATION_H_
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ protected void startChromiumLocked() {
AwBrowserProcess.start();
AwBrowserProcess.handleMinidumpsAndSetMetricsConsent(true /* updateMetricsConsent */);

// This has to be done after variations are initialized, so components could be
// registered or not depending on the variations flags.
AwBrowserProcess.loadComponents();

mSharedStatics = new SharedStatics();
if (BuildInfo.isDebugAndroid()) {
mSharedStatics.setWebContentsDebuggingEnabledUnconditionally(true);
Expand Down
1 change: 1 addition & 0 deletions android_webview/java/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include_rules = [
"+components/navigation_interception/android/java",
"+components/policy/android/java",
"+components/safe_browsing/android/java",
"+components/component_updater/android/java",

"-content/public/android/java",
"+content/public/android/java/src/org/chromium/content_public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import org.chromium.base.task.PostTask;
import org.chromium.base.task.TaskRunner;
import org.chromium.base.task.TaskTraits;
import org.chromium.components.component_updater.ComponentLoaderPolicyBridge;
import org.chromium.components.component_updater.EmbeddedComponentLoader;
import org.chromium.components.minidump_uploader.CrashFileManager;
import org.chromium.components.policy.CombinedPolicyProvider;
import org.chromium.content_public.browser.BrowserStartupController;
Expand All @@ -57,6 +59,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -483,11 +486,31 @@ public void onServiceDisconnected(ComponentName className) {}
}
}

/**
* Load components files from {@link
* org.chromium.android_webview.services.ComponentsProviderService}.
*/
public static void loadComponents() {
ComponentLoaderPolicyBridge[] componentPolicies =
AwBrowserProcessJni.get().getComponentLoaderPolicies();
// Don't connect to the service if there are no components to load.
if (componentPolicies.length == 0) {
return;
}
EmbeddedComponentLoader loader =
new EmbeddedComponentLoader(Arrays.asList(componentPolicies));
final Intent intent = new Intent();
intent.setClassName(
ContextUtils.getApplicationContext(), ServiceNames.AW_COMPONENTS_PROVIDER_SERVICE);
loader.connect(intent);
}

// Do not instantiate this class.
private AwBrowserProcess() {}

@NativeMethods
interface Natives {
void setProcessNameCrashKey(String processName);
ComponentLoaderPolicyBridge[] getComponentLoaderPolicies();
}
}

0 comments on commit 870d053

Please sign in to comment.