1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.android_webview;
7 import android.content.Context;
8 import android.util.Log;
10 import org.chromium.base.PathUtils;
11 import org.chromium.base.ThreadUtils;
12 import org.chromium.base.library_loader.LibraryLoader;
13 import org.chromium.base.library_loader.ProcessInitException;
14 import org.chromium.content.browser.BrowserStartupController;
15 import org.chromium.media.MediaDrmBridge;
17 import java.util.UUID;
20 * Wrapper for the steps needed to initialize the java and native sides of webview chromium.
22 public abstract class AwBrowserProcess {
23 public static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "webview";
25 private static final String TAG = "AwBrowserProcess";
28 * Loads the native library, and performs basic static construction of objects needed
29 * to run webview in this process. Does not create threads; safe to call from zygote.
30 * Note: it is up to the caller to ensure this is only called once.
32 public static void loadLibrary() {
33 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
35 LibraryLoader.loadNow();
36 } catch (ProcessInitException e) {
37 throw new RuntimeException("Cannot load WebView", e);
39 // Switch the command line implementation from Java to native.
40 // It's okay for the WebView to do this before initialization because we have
41 // setup the JNI bindings by this point.
42 LibraryLoader.switchCommandLineForWebView();
46 * Starts the chromium browser process running within this process. Creates threads
47 * and performs other per-app resource allocations; must not be called from zygote.
48 * Note: it is up to the caller to ensure this is only called once.
49 * @param context The Android application context
51 public static void start(final Context context) {
52 // We must post to the UI thread to cover the case that the user
53 // has invoked Chromium startup by using the (thread-safe)
54 // CookieManager rather than creating a WebView.
55 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
59 BrowserStartupController.get(context).startBrowserProcessesSync(true);
60 initializePlatformKeySystem();
61 } catch (ProcessInitException e) {
62 throw new RuntimeException("Cannot initialize WebView", e);
68 private static void initializePlatformKeySystem() {
69 String[] mappings = AwResource.getConfigKeySystemUuidMapping();
70 for (String mapping : mappings) {
72 String fragments[] = mapping.split(",");
73 String keySystem = fragments[0].trim();
74 UUID uuid = UUID.fromString(fragments[1]);
75 MediaDrmBridge.addKeySystemUuidMapping(keySystem, uuid);
76 } catch (java.lang.RuntimeException e) {
77 Log.e(TAG, "Can't parse key-system mapping: " + mapping);