summaryrefslogtreecommitdiffstats
path: root/android_webview/lib/main/webview_jni_onload.cc
blob: 49d3c632e89056802c9adb72538557cd166e197d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2015 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/lib/main/webview_jni_onload.h"

#include "android_webview/lib/main/aw_main_delegate.h"
#include "android_webview/native/android_webview_jni_registrar.h"
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
#include "base/bind.h"
#include "components/external_video_surface/component_jni_registrar.h"
#include "components/navigation_interception/component_jni_registrar.h"
#include "components/web_contents_delegate_android/component_jni_registrar.h"
#include "content/public/app/content_jni_onload.h"
#include "content/public/app/content_main.h"
#include "url/url_util.h"

namespace android_webview {

namespace {

static base::android::RegistrationMethod
    kWebViewDependencyRegisteredMethods[] = {
#if defined(VIDEO_HOLE)
    { "ExternalVideoSurfaceContainer",
        external_video_surface::RegisterExternalVideoSurfaceJni },
#endif
    { "NavigationInterception",
        navigation_interception::RegisterNavigationInterceptionJni },
    { "WebContentsDelegateAndroid",
        web_contents_delegate_android::RegisterWebContentsDelegateAndroidJni },
};

bool RegisterJNI(JNIEnv* env) {
  // Register JNI for components we depend on.
  if (!RegisterNativeMethods(
          env,
          kWebViewDependencyRegisteredMethods,
          arraysize(kWebViewDependencyRegisteredMethods)) ||
      !android_webview::RegisterJni(env)) {
    return false;
  }
  return true;
}

bool Init() {
  content::SetContentMainDelegate(new android_webview::AwMainDelegate());

  // Initialize url lib here while we are still single-threaded, in case we use
  // CookieManager before initializing Chromium (which would normally have done
  // this). It's safe to call this multiple times.
  url::Initialize();
  return true;
}

}  // namespace

bool OnJNIOnLoadRegisterJNI(JavaVM* vm) {
  std::vector<base::android::RegisterCallback> register_callbacks;
  register_callbacks.push_back(base::Bind(&RegisterJNI));
  return content::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks);
}

bool OnJNIOnLoadInit() {
  std::vector<base::android::InitCallback> init_callbacks;
  init_callbacks.push_back(base::Bind(&Init));
  return content::android::OnJNIOnLoadInit(init_callbacks);
}

}  // android_webview