diff options
Diffstat (limited to 'content/shell')
19 files changed, 356 insertions, 21 deletions
diff --git a/content/shell/android/browsertests_apk/AndroidManifest.xml b/content/shell/android/browsertests_apk/AndroidManifest.xml new file mode 100644 index 0000000..5746a43 --- /dev/null +++ b/content/shell/android/browsertests_apk/AndroidManifest.xml @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- Copyright (c) 2012 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. + --> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="org.chromium.content_browsertests_apk"> + + <permission android:name="org.chromium.content_shell.permission.SANDBOX" + android:protectionLevel="signature" /> + + <application android:name="ContentBrowserTestsApplication" + android:label="ContentBrowserTests"> + <activity android:name="ContentBrowserTestsActivity" + android:launchMode="singleTask" + android:theme="@android:style/Theme.Holo.Light.NoActionBar" + android:configChanges="orientation|keyboardHidden|keyboard|screenSize" + android:hardwareAccelerated="true"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + </activity> + <!-- The following service entries exist in order to allow us to + start more than one sandboxed process. --> + + <!-- NOTE: If you change the values of "android:process" for any of the below services, + you also need to update kHelperProcessExecutableName in chrome_constants.cc. --> + <service android:name="org.chromium.content.app.SandboxedProcessService0" + android:process=":sandboxed_process0" + android:permission="org.chromium.content_shell.permission.SANDBOX" + android:isolatedProcess="true" + android:exported="false" /> + <service android:name="org.chromium.content.app.SandboxedProcessService1" + android:process=":sandboxed_process1" + android:permission="org.chromium.content_shell.permission.SANDBOX" + android:isolatedProcess="true" + android:exported="false" /> + <service android:name="org.chromium.content.app.SandboxedProcessService2" + android:process=":sandboxed_process2" + android:permission="org.chromium.content_shell.permission.SANDBOX" + android:isolatedProcess="true" + android:exported="false" /> + <service android:name="org.chromium.content.app.SandboxedProcessService3" + android:process=":sandboxed_process3" + android:permission="org.chromium.content_shell.permission.SANDBOX" + android:isolatedProcess="true" + android:exported="false" /> + <service android:name="org.chromium.content.app.SandboxedProcessService4" + android:process=":sandboxed_process4" + android:permission="org.chromium.content_shell.permission.SANDBOX" + android:isolatedProcess="true" + android:exported="false" /> + <service android:name="org.chromium.content.app.SandboxedProcessService5" + android:process=":sandboxed_process5" + android:permission="org.chromium.content_shell.permission.SANDBOX" + android:isolatedProcess="true" + android:exported="false" /> + </application> + + <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /> + <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> + <uses-permission android:name="android.permission.INTERNET"/> + <uses-permission android:name="android.permission.VIBRATE"/> + <uses-permission android:name="android.permission.READ_PHONE_STATE"/> + <uses-permission android:name="android.permission.WAKE_LOCK"/> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> +</manifest> diff --git a/content/shell/android/browsertests_apk/content_browser_tests_android.cc b/content/shell/android/browsertests_apk/content_browser_tests_android.cc new file mode 100644 index 0000000..4ed222d4 --- /dev/null +++ b/content/shell/android/browsertests_apk/content_browser_tests_android.cc @@ -0,0 +1,127 @@ +// Copyright (c) 2012 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. + +// This class sets up the environment for running the content browser tests +// inside an android application. + +#include <android/log.h> + +#include "base/android/base_jni_registrar.h" +#include "base/android/jni_android.h" +#include "base/android/jni_string.h" +#include "base/android/scoped_java_ref.h" +#include "base/base_switches.h" +#include "base/command_line.h" +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/logging.h" +#include "base/string_tokenizer.h" +#include "base/string_util.h" +#include "base/stringprintf.h" +#include "content/public/app/android_library_loader_hooks.h" +#include "content/shell/android/shell_jni_registrar.h" +#include "jni/ContentBrowserTestsActivity_jni.h" + +// The main function of the program to be wrapped as an apk. +extern int main(int argc, char** argv); + +namespace { + +void ParseArgsFromString(const std::string& command_line, + std::vector<std::string>* args) { + StringTokenizer tokenizer(command_line, kWhitespaceASCII); + tokenizer.set_quote_chars("\""); + while (tokenizer.GetNext()) { + std::string token; + RemoveChars(tokenizer.token(), "\"", &token); + args->push_back(token); + } +} + +void ParseArgsFromCommandLineFile(std::vector<std::string>* args) { + // The test runner script writes the command line file in + // "/data/local/tmp". + static const char kCommandLineFilePath[] = + "/data/local/tmp/content-browser-tests-command-line"; + FilePath command_line(kCommandLineFilePath); + std::string command_line_string; + if (file_util::ReadFileToString(command_line, &command_line_string)) { + ParseArgsFromString(command_line_string, args); + } +} + +int ArgsToArgv(const std::vector<std::string>& args, + std::vector<char*>* argv) { + // We need to pass in a non-const char**. + int argc = args.size(); + + argv->resize(argc + 1); + for (int i = 0; i < argc; ++i) + (*argv)[i] = const_cast<char*>(args[i].c_str()); + (*argv)[argc] = NULL; // argv must be NULL terminated. + + return argc; +} + +class ScopedMainEntryLogger { + public: + ScopedMainEntryLogger() { + printf(">>ScopedMainEntryLogger\n"); + } + + ~ScopedMainEntryLogger() { + printf("<<ScopedMainEntryLogger\n"); + fflush(stdout); + fflush(stderr); + } +}; + +} // namespace + +static void RunTests(JNIEnv* env, + jobject obj, + jstring jfiles_dir, + jobject app_context) { + + // Command line basic initialization, will be fully initialized later. + static const char* const kInitialArgv[] = { "ContentBrowserTestsActivity" }; + CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); + + // Set the application context in base. + base::android::ScopedJavaLocalRef<jobject> scoped_context( + env, env->NewLocalRef(app_context)); + base::android::InitApplicationContext(scoped_context); + base::android::RegisterJni(env); + + std::vector<std::string> args; + ParseArgsFromCommandLineFile(&args); + + // We need to pass in a non-const char**. + std::vector<char*> argv; + int argc = ArgsToArgv(args, &argv); + + // Fully initialize command line with arguments. + CommandLine::ForCurrentProcess()->AppendArguments( + CommandLine(argc, &argv[0]), false); + + ScopedMainEntryLogger scoped_main_entry_logger; + main(argc, &argv[0]); +} + +// This is called by the VM when the shared library is first loaded. +JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { + base::android::InitVM(vm); + JNIEnv* env = base::android::AttachCurrentThread(); + + if (!content::RegisterLibraryLoaderEntryHook(env)) + return -1; + + if (!content::android::RegisterShellJni(env)) + return -1; + + if (!RegisterNativesImpl(env)) + return -1; + + return JNI_VERSION_1_4; +} diff --git a/content/shell/android/res/layout/content_shell_activity.xml b/content/shell/android/browsertests_apk/res/layout/test_activity.xml index c62e66e..c62e66e 100644 --- a/content/shell/android/res/layout/content_shell_activity.xml +++ b/content/shell/android/browsertests_apk/res/layout/test_activity.xml diff --git a/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsActivity.java b/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsActivity.java new file mode 100644 index 0000000..6c7f09a --- /dev/null +++ b/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsActivity.java @@ -0,0 +1,46 @@ +// Copyright (c) 2012 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_browsertests_apk; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.util.Log; + +import org.chromium.content.app.LibraryLoader; +import org.chromium.content.common.ProcessInitException; +import org.chromium.ui.gfx.ActivityNativeWindow; +import org.chromium.content_shell.ShellManager; + +public class ContentBrowserTestsActivity extends Activity { + private static final String TAG = "ChromeBrowserTestsActivity"; + + private ShellManager mShellManager; + private ActivityNativeWindow mActivityNativeWindow; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + try { + LibraryLoader.ensureInitialized(); + } catch (ProcessInitException e) { + Log.i(TAG, "Cannot load content_browsertests:" + e); + } + + setContentView(R.layout.test_activity); + mShellManager = (ShellManager) findViewById(R.id.shell_container); + mActivityNativeWindow = new ActivityNativeWindow(this); + mShellManager.setWindow(mActivityNativeWindow); + + runTests(); + } + + private void runTests() { + nativeRunTests(getFilesDir().getAbsolutePath(), getApplicationContext()); + } + + private native void nativeRunTests(String filesDir, Context appContext); +} diff --git a/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsApplication.java b/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsApplication.java new file mode 100644 index 0000000..315a17e --- /dev/null +++ b/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsApplication.java @@ -0,0 +1,31 @@ +// Copyright (c) 2012 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_browsertests_apk; + +import android.app.Application; + +import org.chromium.base.PathUtils; +import org.chromium.content.app.LibraryLoader; +import org.chromium.content.browser.ResourceExtractor; + +public class ContentBrowserTestsApplication extends Application { + + private static final String NATIVE_LIBRARY = "content_browsertests"; + private static final String[] MANDATORY_PAK_FILES = new String[] {"content_shell.pak"}; + private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "content_shell"; + + @Override + public void onCreate() { + super.onCreate(); + initializeApplicationParameters(); + } + + public static void initializeApplicationParameters() { + ResourceExtractor.setMandatoryPaksToExtract(MANDATORY_PAK_FILES); + LibraryLoader.setLibraryToLoad(NATIVE_LIBRARY); + PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); + } + +} diff --git a/content/shell/android/res/drawable/progress.xml b/content/shell/android/java/res/drawable/progress.xml index 93322b9..93322b9 100644 --- a/content/shell/android/res/drawable/progress.xml +++ b/content/shell/android/java/res/drawable/progress.xml diff --git a/content/shell/android/res/layout/shell_view.xml b/content/shell/android/java/res/layout/shell_view.xml index d6c15d6..d6c15d6 100644 --- a/content/shell/android/res/layout/shell_view.xml +++ b/content/shell/android/java/res/layout/shell_view.xml diff --git a/content/shell/android/res/values/strings.xml b/content/shell/android/java/res/values/strings.xml index 6eaaaec..6eaaaec 100644 --- a/content/shell/android/res/values/strings.xml +++ b/content/shell/android/java/res/values/strings.xml diff --git a/content/shell/android/java/src/org/chromium/content_shell/ShellManager.java b/content/shell/android/java/src/org/chromium/content_shell/ShellManager.java index 4cc0906..7cf962d 100644 --- a/content/shell/android/java/src/org/chromium/content_shell/ShellManager.java +++ b/content/shell/android/java/src/org/chromium/content_shell/ShellManager.java @@ -21,11 +21,12 @@ import org.chromium.ui.gfx.NativeWindow; @JNINamespace("content") public class ShellManager extends FrameLayout { + public static final String DEFAULT_SHELL_URL = "http://www.google.com"; private static boolean sStartup = true; private NativeWindow mWindow; private Shell mActiveShell; - private String mStartupUrl = ContentShellActivity.DEFAULT_SHELL_URL; + private String mStartupUrl = DEFAULT_SHELL_URL; // The target for all content rendering. private ContentViewRenderView mContentViewRenderView; @@ -71,7 +72,7 @@ public class ShellManager extends FrameLayout { /** * @return The currently visible shell view or null if one is not showing. */ - protected Shell getActiveShell() { + public Shell getActiveShell() { return mActiveShell; } diff --git a/content/shell/android/javatests/AndroidManifest.xml b/content/shell/android/javatests/AndroidManifest.xml index fcd2465..3f27e60 100644 --- a/content/shell/android/javatests/AndroidManifest.xml +++ b/content/shell/android/javatests/AndroidManifest.xml @@ -5,7 +5,7 @@ <!-- package name must be unique so suffix with "tests" so package loader doesn't ignore this. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="org.chromium.content_shell.tests"> + package="org.chromium.content_shell_apk.tests"> <!-- We add an application tag here just so that we can indicate that this package needs to link against the android.test library, which is needed when building test cases. --> @@ -14,8 +14,8 @@ </application> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /> <instrumentation android:name="android.test.InstrumentationTestRunner" - android:targetPackage="org.chromium.content_shell" - android:label="Tests for org.chromium.content_shell"/> + android:targetPackage="org.chromium.content_shell_apk" + android:label="Tests for org.chromium.content_shell_apk"/> <uses-permission android:name="android.permission.RUN_INSTRUMENTATION" /> <uses-permission android:name="android.permission.INJECT_EVENTS" /> </manifest> diff --git a/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellTestBase.java b/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellTestBase.java index 23637df..f4d7a2f 100644 --- a/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellTestBase.java +++ b/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellTestBase.java @@ -18,6 +18,7 @@ import org.chromium.content.browser.test.util.CallbackHelper; import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.TestCallbackHelperContainer; +import org.chromium.content_shell_apk.ContentShellActivity; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellUrlTest.java b/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellUrlTest.java index 05eba42..98b06c1 100644 --- a/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellUrlTest.java +++ b/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellUrlTest.java @@ -7,6 +7,7 @@ package org.chromium.content_shell; import android.test.suitebuilder.annotation.SmallTest; import org.chromium.base.test.util.Feature; +import org.chromium.content_shell_apk.ContentShellActivity; /** * Example test that just starts the content shell. diff --git a/content/shell/android/java/AndroidManifest.xml b/content/shell/android/shell_apk/AndroidManifest.xml index cfeb0c4..77444a3 100644 --- a/content/shell/android/java/AndroidManifest.xml +++ b/content/shell/android/shell_apk/AndroidManifest.xml @@ -7,7 +7,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="org.chromium.content_shell"> + package="org.chromium.content_shell_apk"> <permission android:name="org.chromium.content_shell.permission.SANDBOX" android:protectionLevel="signature" /> diff --git a/content/shell/android/shell_apk/res/layout/content_shell_activity.xml b/content/shell/android/shell_apk/res/layout/content_shell_activity.xml new file mode 100644 index 0000000..c62e66e --- /dev/null +++ b/content/shell/android/shell_apk/res/layout/content_shell_activity.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- Copyright (c) 2012 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. + --> + +<merge xmlns:android="http://schemas.android.com/apk/res/android"> + <org.chromium.content_shell.ShellManager + android:id="@+id/shell_container" + android:layout_width="match_parent" + android:layout_height="match_parent" /> +</merge> diff --git a/content/shell/android/java/src/org/chromium/content_shell/ContentShellActivity.java b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java index cd3e546..0ce99d8 100644 --- a/content/shell/android/java/src/org/chromium/content_shell/ContentShellActivity.java +++ b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -package org.chromium.content_shell; +package org.chromium.content_shell_apk; import android.app.Activity; import android.content.BroadcastReceiver; @@ -23,6 +23,8 @@ import org.chromium.content.browser.DeviceUtils; import org.chromium.content.browser.TracingIntentHandler; import org.chromium.content.common.CommandLine; import org.chromium.content.common.ProcessInitException; +import org.chromium.content_shell.Shell; +import org.chromium.content_shell.ShellManager; import org.chromium.ui.gfx.ActivityNativeWindow; /** @@ -38,7 +40,6 @@ public class ContentShellActivity extends ChromiumActivity { "org.chromium.content_shell.action.PROFILE_START"; private static final String ACTION_STOP_TRACE = "org.chromium.content_shell.action.PROFILE_STOP"; - public static final String DEFAULT_SHELL_URL = "http://www.google.com"; public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs"; private ShellManager mShellManager; @@ -76,7 +77,7 @@ public class ContentShellActivity extends ChromiumActivity { mShellManager.setStartupUrl(Shell.sanitizeUrl(startupUrl)); } if (!ContentView.enableMultiProcess(this, ContentView.MAX_RENDERERS_AUTOMATIC)) { - String shellUrl = DEFAULT_SHELL_URL; + String shellUrl = ShellManager.DEFAULT_SHELL_URL; if (savedInstanceState != null && savedInstanceState.containsKey(ACTIVE_SHELL_URL_KEY)) { shellUrl = savedInstanceState.getString(ACTIVE_SHELL_URL_KEY); diff --git a/content/shell/android/java/src/org/chromium/content_shell/ContentShellApplication.java b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellApplication.java index 16f7c51..d070fb0 100644 --- a/content/shell/android/java/src/org/chromium/content_shell/ContentShellApplication.java +++ b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellApplication.java @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -package org.chromium.content_shell; +package org.chromium.content_shell_apk; import android.app.Application; diff --git a/content/shell/android/shell_jni_registrar.cc b/content/shell/android/shell_jni_registrar.cc new file mode 100644 index 0000000..504eda7 --- /dev/null +++ b/content/shell/android/shell_jni_registrar.cc @@ -0,0 +1,30 @@ +// Copyright (c) 2012 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 "content/shell/android/shell_jni_registrar.h" + +#include "base/android/jni_android.h" +#include "base/android/jni_registrar.h" +#include "content/shell/android/shell_manager.h" +#include "content/shell/shell.h" + +namespace { + +static base::android::RegistrationMethod kShellRegistrationMethods[] = { + { "Shell", content::Shell::Register }, + { "ShellManager", content::RegisterShellManager }, +}; + +} // namespace + +namespace content { +namespace android { + +bool RegisterShellJni(JNIEnv* env) { + return RegisterNativeMethods(env, kShellRegistrationMethods, + arraysize(kShellRegistrationMethods)); +} + +} // namespace android +} // namespace content diff --git a/content/shell/android/shell_jni_registrar.h b/content/shell/android/shell_jni_registrar.h new file mode 100644 index 0000000..f336c52 --- /dev/null +++ b/content/shell/android/shell_jni_registrar.h @@ -0,0 +1,19 @@ +// Copyright (c) 2012 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 CONTENT_SHELL_ANDROID_SHELL_JNI_REGISTRAR_H_ +#define CONTENT_SHELL_ANDROID_SHELL_JNI_REGISTRAR_H_ + +#include <jni.h> + +namespace content { +namespace android { + +// Register all JNI bindings necessary for content shell. +bool RegisterShellJni(JNIEnv* env); + +} // namespace android +} // namespace content + +#endif // CONTENT_SHELL_ANDROID_SHELL_JNI_REGISTRAR_H_ diff --git a/content/shell/android/shell_library_loader.cc b/content/shell/android/shell_library_loader.cc index 88262c9..f320387f 100644 --- a/content/shell/android/shell_library_loader.cc +++ b/content/shell/android/shell_library_loader.cc @@ -10,31 +10,23 @@ #include "content/public/app/android_library_loader_hooks.h" #include "content/public/app/content_main.h" #include "content/public/browser/android/compositor.h" -#include "content/shell/android/shell_manager.h" -#include "content/shell/shell.h" +#include "content/shell/android/shell_jni_registrar.h" #include "content/shell/shell_main_delegate.h" -static base::android::RegistrationMethod kRegistrationMethods[] = { - { "Shell", content::Shell::Register }, - { "ShellManager", content::RegisterShellManager }, -}; - // This is called by the VM when the shared library is first loaded. JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { base::android::InitVM(vm); JNIEnv* env = base::android::AttachCurrentThread(); + if (!content::RegisterLibraryLoaderEntryHook(env)) return -1; // To be called only from the UI thread. If loading the library is done on // a separate thread, this should be moved elsewhere. - if (!base::android::RegisterNativeMethods(env, kRegistrationMethods, - arraysize(kRegistrationMethods))) + if (!content::android::RegisterShellJni(env)) return -1; content::Compositor::Initialize(); - content::SetContentMainDelegate(new content::ShellMainDelegate()); - return JNI_VERSION_1_4; } |