Category Archives: Android5.0_chromium

how to download/compile/run(emulator) the source code of android5.0

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

https://www.googlesource.com/new-password

repo init -u https://android.googlesource.com/platform/manifest/ -b android-5.0.1_r1

repo sync
——-for auto restart when repo sync fail—
#!/bin/bash
FAIL_COUNTS=0
echo “begin to repo sync”
repo sync -f -j4

while [ $? -ne 0 ]; do
((FAIL_COUNTS++))
echo “repo sync fail $FAIL_COUNTS times”
sleep 3
echo “repo sync retry”
repo sync -f -j4
#if [ $FAIL_COUNTS -ge 4 ]; then
#        break;
#    fi
done

echo “repo sync faild $FAIL_COUNTS times”
————-

source build/envsetup.sh

lunch //select the target  aosp_arm-eng

make -j8
—–start the emulator———
emulator -partition-size 1024

 | 509,168 views | 8,339 comments | 0 flags | 

Java jni invoke process under android5.0

android_webview_native_webview_native_gyp.a

external/chromium_org/android_webview/Android.mk(responsible for the java compile)
JNI_Invoke process
external/chromium_org/android_webview/lib/main/webview_entry_point.cc
	JNI_OnLoad
		->base::android::RegisterLibraryLoaderEntryHook
		->content::EnsureJniRegistered
		->RegisterNativeMethods
		->android_webview::RegisterJni
			->android_webview/native/android_webview_jni_registrar.cc
				->RegisterNativeMethods
				->android_webview/native/aw_contents.cc
					->RegisterNativesImpl[AwContents_jni.h]
					->
		->base::android::InitReplacementClassLoader
		->content::SetContentMainDelegate
		->url::Initialize
external/chromium_org/GypAndroid.linux-arm.mk
	[
		AwContents.java
		{
			// Return true if the GeolocationPermissionAPI should be used.
			@CalledByNative
			private boolean useLegacyGeolocationPermissionAPI() {
			    // Always return true since we are not ready to swap the geolocation yet.
			    // TODO: If we decide not to migrate tarm-linux-androideabi-objdump -tT libwebviewchromium.so | grep Java_com_android_org_chromium_android_1webview_AwContents_nativeInit
001d2834 g    DF .text	000000ec Java_com_android_org_chromium_android_1webview_AwContents_nativeInit

refer the autogenerated xxx_jni.h to create the interface(c++ -> native, native -> c++)he geolocation, there are some unreachable
			    // code need to remove. http://crbug.com/396184.
			    return true;
			}
			private static native long nativeInit(AwBrowserContext browserContext);
		}
		//--------------------------------------------
		aw_contents.cc
		{
			static jlong Init(JNIEnv* env, jclass, jobject browser_context) {
			  // TODO(joth): Use |browser_context| to get the native BrowserContext, rather
			  // than hard-code the default instance lookup here.
			  scoped_ptr<WebContents> web_contents(content::WebContents::Create(
			      content::WebContents::CreateParams(AwBrowserContext::GetDefault())));
			  // Return an 'uninitialized' instance; most work is deferred until the
			  // subsequent SetJavaPeers() call.
			  return reinterpret_cast<intptr_t>(new AwContents(web_contents.Pass()));
			}
			//====================================
			void AwContents::RequestGeolocationPermission(
			    const GURL& origin,
			    const base::Callback<void(bool)>& callback) {
			  JNIEnv* env = AttachCurrentThread();
			  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
			  if (obj.is_null())
			    return;

			  if (Java_AwContents_useLegacyGeolocarm-linux-androideabi-objdump -tT libwebviewchromium.so | grep Java_com_android_org_chromium_android_1webview_AwContents_nativeInit
001d2834 g    DF .text	000000ec Java_com_android_org_chromium_android_1webview_AwContents_nativeInit

refer the autogenerated xxx_jni.h to create the interface(c++ -> native, native -> c++)ationPermissionAPI(env, obj.obj())) {
			    ShowGeolocationPrompt(origin, callback);
			    return;
			  }
			  permission_request_handler_->SendRequest(
			      scoped_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest(
				  origin, AwPermissionRequest::Geolocation, callback)));
			}

		}
		//--------------------------------------------
		AwContents_jni.h
		{
		extern "C" {
			static jlong Init(JNIEnv* env, jclass jcaller,
			    jobject browserContext);

			__attribute__((visibility("default")))
			jlong
			    Java_com_android_org_chromium_android_1webview_AwContents_nativeInit(JNIEnv*
			    env, jclass jcaller,
			    jobject browserContext) {arm-linux-androideabi-objdump -tT libwebviewchromium.so | grep Java_com_android_org_chromium_android_1webview_AwContents_nativeInit
001d2834 g    DF .text	000000ec Java_com_android_org_chromium_android_1webview_AwContents_nativeInit

refer the autogenerated xxx_jni.h to create the interface(c++ -> native, native -> c++)
			  return Init(env, jcaller, browserContext);
			}
			//==================================================//
			static base::subtle::AtomicWord g_AwContents_useLegacyGeolocationPermissionAPI =
			    0;
			static jboolean Java_AwContents_useLegacyGeolocationPermissionAPI(JNIEnv* env,
			    jobject obj) {
			  /* Must call RegisterNativesImpl()  */
			  CHECK_CLAZZ(env, obj,
			      AwContents_clazz(env), false);
			  jmethodID method_id =
			      base::android::MethodID::LazyGet<
			      base::android::MethodID::TYPE_INSTANCE>(
			      env, AwContents_clazz(env),
			      "useLegacyGeolocationPermissionAPI",

			"("
			")"
			"Z",
			      &g_AwContents_useLegacyGeolocationPermissionAPI);

			  jboolean ret =
			      env->CallBooleanMethod(obj,arm-linux-androideabi-objdump -tT libwebviewchromium.so | grep Java_com_android_org_chromium_android_1webview_AwContents_nativeInit
001d2834 g    DF .text	000000ec Java_com_android_org_chromium_android_1webview_AwContents_nativeInit

refer the autogenerated xxx_jni.h to create the interface(c++ -> native, native -> c++)
				  method_id);
			  jni_generator::CheckException(env);
			  return ret;
			}
			//==================================
			static bool RegisterNativesImpl(JNIEnv* env) {
			//??????????????????should invoke env->RegisterNatives
			  return true;
			}

		}
		}
	]
	base/android/jni_generator/jni_generator.py
	../../base/android/jni_generator/jni_generator.py 
		--input_file ../java/src/org/chromium/android_webview/AwContents.java 
		--output_dir "/home/leliang/work/android/sourcecode/out/target/product/generic/obj/GYP/shared_intermediates/android_webview/jni" 
		--includes base/android/jni_generator/jni_generator_helper.h 
		--optimize_generation 0       
		--jarjar ../../android_webview/build/jarjar-rules.txt 
		--ptr_type long --native_exports
	out/target/product/generic/obj/GYP/shared_intermediates/android_webview/jni
		[dynamic generate callback&registar native]
		android_webview_jni_registrar.cc
===============================================================================================
GYP_HOST_MULTILIB = 32
GYP_HOST_VAR_PREFIX = 2ND_
====external/chromium_org/GypAndroid.linux-arm.mk===============================
arm-linux-androideabi-objdump -tT libwebviewchromium.so | grep Java_com_android_org_chromium_android_1webview_AwContents_nativeInit
001d2834 g    DF .text	000000ec Java_com_android_org_chromium_android_1webview_AwContents_nativeInit

refer the autogenerated xxx_jni.h to create the interface(c++ -> native, native -> c++)
=========================

https://chromium.googlesource.com/android_tools/+/master/ndk/sources/android/crazy_linker/README.TXT

The first time you call a native method like:
    'mypackage.MyClass.myNativeMethod()'
  The VM will look into existing native libraries with dlsym() for a
  function symbol named like:
    Java_mypackage_MyClass_myNativeMethod

 

 | 129,739 views | 1,031 comments | 0 flags | 

Android 5.0 WebView initialize process

下面是WebView的初始化过程,从WebView constructor 到 AwContents的constructor结束,
列出了主要类的创建,和相关库(.so)的加载过程 (base on Android 5.0.1_r1)

 | 382,451 views | 5,662 comments | 0 flags | 

学习Chromium的一点总结

学习了chromium一段时间,下面是自己的一点学习过程.

Process Model,:http://dev.chromium.org/developers/design-documents/process-models
one process for all instances of a web site, one process for each group of connected tabs, or everything in a single process.
Multi-process Architecture:
http://dev.chromium.org/developers/design-documents/multi-process-architecture

Multi-process Resource Loading:
http://dev.chromium.org/developers/design-documents/multi-process-resource-loading

Displaying a web page in chrome:
http://dev.chromium.org/developers/design-documents/displaying-a-web-page-in-chrome
the render process, Chromium’s render process embeds our WebKit port using the glue interface. It does not contain very much code: its job is primarily to be the renderer side of the IPC channel to the browser.

the Browser process,
 Note:
pay your attention to the below two part, which will help you understand how the messages handling between browser and render process.
Life of a “set cursor” message
Life of a “mouse click” message

Inter-process Communication (IPC)
http://dev.chromium.org/developers/design-documents/inter-process-communication

Content/Browser component
http://dev.chromium.org/developers/content-module
http://dev.chromium.org/developers/design-documents/browser-components

Plugin Architecture

Pepper plugin implementation
http://dev.chromium.org/developers/design-documents/pepper-plugin-implementation

pepper(PPAPI) concepts
https://code.google.com/p/ppapi/wiki/Concepts

 | 705,426 views | 13,312 comments | 0 flags | 

如何学习Android5.0 下 新的 webview 的实现。

我们知道从Android4.4开始, WebView的实现开始使用chromium,但是对外API并没有改变,但是内部的实现已经彻底改变。本文总结一下个人学习中接触的资料。

主要的资料都是来源于官网:
http://dev.chromium.org/developers
http://dev.chromium.org/developers/design-documents
相信看完官网的资料应该对新的实现很了解了,但是资料众多,总结一下入门步骤。 

了解一下chromium project的开发过程(Life of a Chromium Developer), 仅仅知道开发中用到工具即可,比如gclient, ninja…
 https://docs.google.com/presentation/d/1owPEVVzP0rLJrxSff4ncucy9G2yZ7Goxz9SJbfEBEHc/preview?slide=id.p

学习一下chromium project各个目录的介绍,
http://dev.chromium.org/developers/how-tos/getting-around-the-chrome-source-code
看完我们需要知道在chromium中有很好的分层组织结构,下层的代码决定不可以依赖上层代码(编译依赖),如果上层要调用下层的实现可以通过嵌入API(embedder API),也就是回调的方式。

重点我们还是学习Android相关Code的组织(Organization of code for Android WebView):

https://docs.google.com/document/d/1a_cUP1dGIlRQFUSic8bhAOxfclj4Xzw-yRDljVk1wB0/edit#heading=h.kpg68p8kaepe

在看完这个文档后对下图就能看懂了,也需要记住这张图,是后面学习的的必须。
下面这个链接是对这个文档的翻译,
http://blog.csdn.net/typename/article/details/40896627

 

为了有针对性的学习,现在应该是我们进一步学习一下重要类的时候了,下面这个链接里面介绍的每一个类,每一个流程都是非常重要的,多看,以便牢记于心。
http://www.it165.net/pro/html/201406/15259.html
为了做个提示,将内部重要的图摘录在下面(注意图中有些地方关系错误,不影响总体):

AwContents 的创建过程:
\" data-mce-src=
AwContents的java层和native层的结构
\" data-mce-src= WebContentsImpl 创建过程:
\" data-mce-src=
WebContentsImpl 类图:

RenderViewHostImpl与RenderViewImpl是一一对应的,他们分别对应于Browser进程和Render进程中的View表示.
Render 创建过程:
\" data-mce-src=

RenderViewImpl 通过webkit glue层实现与WebKit的连接:
\" data-mce-src=

在掌握上面的知识后,基本就入门了,这个时候就可以根据WebView的创建过程和loadUrl的流程,从源码级别学习了。

 

 

 

 

 

 

 | 1,021,846 views | 13,423 comments | 0 flags |