diff options
9 files changed, 97 insertions, 42 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java index 4d6c1ff..e930af1 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java +++ b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java @@ -11,7 +11,6 @@ import org.chromium.base.PathUtils; import org.chromium.base.ThreadUtils; import org.chromium.content.app.LibraryLoader; import org.chromium.content.browser.AndroidBrowserProcess; -import org.chromium.content.browser.ResourceExtractor; import org.chromium.content.common.ProcessInitException; /** @@ -35,7 +34,11 @@ public abstract class AwBrowserProcess { public static void loadLibrary() { PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); LibraryLoader.setLibraryToLoad(NATIVE_LIBRARY); - LibraryLoader.loadNow(); + try { + LibraryLoader.loadNow(); + } catch (ProcessInitException e) { + throw new RuntimeException("Cannot load WebView", e); + } } // TODO(joth): remove when downstream is using new version below. diff --git a/build/android/java_cpp_template.gypi b/build/android/java_cpp_template.gypi index 22b7214..c55b100 100644 --- a/build/android/java_cpp_template.gypi +++ b/build/android/java_cpp_template.gypi @@ -56,6 +56,7 @@ 'action': [ 'gcc', # invoke host gcc. '-E', # stop after preprocessing. + '-D', 'ANDROID', # Specify ANDROID define for pre-processor. '-x', 'c-header', # treat sources as C header files '-P', # disable line markers, i.e. '#line 309' '-I', '<(DEPTH)', # Add project top-level to include path diff --git a/content/content.gyp b/content/content.gyp index 0b40689..f5679b9 100644 --- a/content/content.gyp +++ b/content/content.gyp @@ -312,6 +312,7 @@ 'common_aidl', 'content_common', 'page_transition_types_java', + 'result_codes_java', ], 'variables': { 'java_in_dir': '../content/public/android/java', @@ -343,6 +344,18 @@ 'includes': [ '../build/android/java_cpp_template.gypi' ], }, { + 'target_name': 'result_codes_java', + 'type': 'none', + 'sources': [ + 'public/android/java/src/org/chromium/content/common/ResultCodes.template', + ], + 'variables': { + 'package_name': 'org/chromium/content/common', + 'template_deps': ['public/common/result_codes_list.h'], + }, + 'includes': [ '../build/android/java_cpp_template.gypi' ], + }, + { 'target_name': 'surface_texture_jni_headers', 'type': 'none', 'variables': { diff --git a/content/content_common.gypi b/content/content_common.gypi index 07df4dd..7faa1ec 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -78,6 +78,7 @@ 'public/common/resource_dispatcher_delegate.h', 'public/common/resource_response.h', 'public/common/result_codes.h', + 'public/common/result_codes_list.h', 'public/common/sandbox_init.cc', 'public/common/sandbox_init.h', 'public/common/sandbox_linux.h', diff --git a/content/public/android/java/src/org/chromium/content/app/LibraryLoader.java b/content/public/android/java/src/org/chromium/content/app/LibraryLoader.java index 91e3234..0facd0b 100644 --- a/content/public/android/java/src/org/chromium/content/app/LibraryLoader.java +++ b/content/public/android/java/src/org/chromium/content/app/LibraryLoader.java @@ -4,14 +4,13 @@ package org.chromium.content.app; -import android.os.AsyncTask; -import android.os.Handler; import android.text.TextUtils; import android.util.Log; import org.chromium.base.JNINamespace; import org.chromium.content.common.CommandLine; import org.chromium.content.common.ProcessInitException; +import org.chromium.content.common.ResultCodes; import org.chromium.content.common.TraceEvent; /** @@ -78,20 +77,24 @@ public class LibraryLoader { * this is called on will be the thread that runs the native code's static initializers. * See the comment in doInBackground() for more considerations on this. * - * @return Whether the native library was successfully loaded. + * @throws ProcessInitException if the native library failed to load. */ - public static void loadNow() { + public static void loadNow() throws ProcessInitException { if (sLibrary == null) { assert false : "No library specified to load. Call setLibraryToLoad before first."; } - synchronized (sLoadedLock) { - if (!sLoaded) { - assert !sInitialized; - Log.i(TAG, "loading: " + sLibrary); - System.loadLibrary(sLibrary); - Log.i(TAG, "loaded: " + sLibrary); - sLoaded = true; + try { + synchronized (sLoadedLock) { + if (!sLoaded) { + assert !sInitialized; + Log.i(TAG, "loading: " + sLibrary); + System.loadLibrary(sLibrary); + Log.i(TAG, "loaded: " + sLibrary); + sLoaded = true; + } } + } catch (UnsatisfiedLinkError e) { + throw new ProcessInitException(ResultCodes.RESULT_CODE_NATIVE_LIBRARY_LOAD_FAILED, e); } } diff --git a/content/public/android/java/src/org/chromium/content/app/SandboxedProcessService.java b/content/public/android/java/src/org/chromium/content/app/SandboxedProcessService.java index 3933858..2c5bd60 100644 --- a/content/public/android/java/src/org/chromium/content/app/SandboxedProcessService.java +++ b/content/public/android/java/src/org/chromium/content/app/SandboxedProcessService.java @@ -16,16 +16,16 @@ import android.os.RemoteException; import android.util.Log; import android.view.Surface; -import java.util.ArrayList; - import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; -import org.chromium.content.app.ContentMain; import org.chromium.content.browser.SandboxedProcessConnection; import org.chromium.content.common.ISandboxedProcessCallback; import org.chromium.content.common.ISandboxedProcessService; +import org.chromium.content.browser.SandboxedProcessLauncher; import org.chromium.content.common.ProcessInitException; +import java.util.ArrayList; + /** * This is the base class for sandboxed services; the SandboxedProcessService0, 1.. etc * subclasses provide the concrete service entry points, to enable the browser to connect @@ -118,7 +118,12 @@ public class SandboxedProcessService extends Service { } } LibraryLoader.setLibraryToLoad(mNativeLibraryName); - LibraryLoader.loadNow(); + try { + LibraryLoader.loadNow(); + } catch (ProcessInitException e) { + Log.e(TAG, "Failed to load native library, exiting sandboxed process", e); + return; + } synchronized (mSandboxMainThread) { while (mCommandLineParams == null) { mSandboxMainThread.wait(); diff --git a/content/public/android/java/src/org/chromium/content/common/ResultCodes.template b/content/public/android/java/src/org/chromium/content/common/ResultCodes.template new file mode 100644 index 0000000..69962bf --- /dev/null +++ b/content/public/android/java/src/org/chromium/content/common/ResultCodes.template @@ -0,0 +1,13 @@ +// Copyright (c) 2013 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. + +package org.chromium.content.common; + +public class ResultCodes { +#define RESULT_CODE(label, value) public static final int \ + RESULT_CODE_ ## label = value; +#include "content/public/common/result_codes_list.h" +#undef RESULT_CODE +} + diff --git a/content/public/common/result_codes.h b/content/public/common/result_codes.h index b3c4a6b..1bf625d 100644 --- a/content/public/common/result_codes.h +++ b/content/public/common/result_codes.h @@ -5,35 +5,13 @@ #ifndef CONTENT_PUBLIC_COMMON_RESULT_CODES_H_ #define CONTENT_PUBLIC_COMMON_RESULT_CODES_H_ -// This file consolidates all the return codes for the browser and renderer -// process. The return code is the value that: -// a) is returned by main() or winmain(), or -// b) specified in the call for ExitProcess() or TerminateProcess(), or -// c) the exception value that causes a process to terminate. -// -// It is advisable to not use negative numbers because the Windows API returns -// it as an unsigned long and the exception values have high numbers. For -// example EXCEPTION_ACCESS_VIOLATION value is 0xC0000005. - namespace content { enum ResultCode { - // Process terminated normally. - RESULT_CODE_NORMAL_EXIT = 0, - - // Process was killed by user or system. - RESULT_CODE_KILLED = 1, - - // Process hung. - RESULT_CODE_HUNG = 2, - - // A bad message caused the process termination. - RESULT_CODE_KILLED_BAD_MESSAGE = 3, -#if defined(OS_ANDROID) - // Failed to register JNI methods. - RESULT_CODE_FAILED_TO_REGISTER_JNI = 4, -#endif +#define RESULT_CODE(label, value) RESULT_CODE_ ## label = value, +#include "content/public/common/result_codes_list.h" +#undef RESULT_CODE // Last return code (keep this last). RESULT_CODE_LAST_CODE diff --git a/content/public/common/result_codes_list.h b/content/public/common/result_codes_list.h new file mode 100644 index 0000000..9f6453b --- /dev/null +++ b/content/public/common/result_codes_list.h @@ -0,0 +1,38 @@ +// Copyright (c) 2013 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. + +// Intentionally no include guards because this file is meant to be included +// inside a macro to generate enum values. + +// This file consolidates all the return codes for the browser and renderer +// process. The return code is the value that: +// a) is returned by main() or winmain(), or +// b) specified in the call for ExitProcess() or TerminateProcess(), or +// c) the exception value that causes a process to terminate. +// +// It is advisable to not use negative numbers because the Windows API returns +// it as an unsigned long and the exception values have high numbers. For +// example EXCEPTION_ACCESS_VIOLATION value is 0xC0000005. + +#include "build/build_config.h" + +// Process terminated normally. +RESULT_CODE(NORMAL_EXIT, 0) + +// Process was killed by user or system. +RESULT_CODE(KILLED, 1) + +// Process hung. +RESULT_CODE(HUNG, 2) + +// A bad message caused the process termination. +RESULT_CODE(KILLED_BAD_MESSAGE, 3) + +#if defined(OS_ANDROID) +// Failed to register JNI methods. +RESULT_CODE(FAILED_TO_REGISTER_JNI, 4) + +// Failed to find and load the native library. +RESULT_CODE(NATIVE_LIBRARY_LOAD_FAILED, 5) +#endif |