Skip to content

Latest commit

 

History

History
410 lines (324 loc) · 15.4 KB

chromium.md

File metadata and controls

410 lines (324 loc) · 15.4 KB

Chromium

OUYA fork of Chromium

The purpose of Chromium on Android is to achieve a hardware accelerated WebView capable of playing HTML5 games, rendering browser content, and streaming accelerated video. HTML5 game engines like Twine (text adventure games), Construct 2 (visual-scripting-engine), Gootechnologies (WebGL acceleration), and HTML5 browser games all need to make use of an HTML5 rendering engine that supports hardware acceleration. The previously mentioned engines will have their own documentation that extends this base Chromium documentation.

The steps below is an extension that begins from the Chromium trunk and make customizations to support the OUYA controller and in-app-purchases. You will need to build a Ubuntu 12.04 Linux guest in order to build Chromium from the trunk. There are a set of dependencies that need installed before you can obtain the Chromium source. Some customization to the build files and tweaks to the source code are necessary to add controller and ODK functionality.

The Chromium apps also have flags that enable or change the default behaviour. These options are configurable from a file and the flags can be hardcoded in the settings once you find the optimal flag settings. One example of Chromium flags the spatial navigation feature.

More

First thing, the Chromium code-base is very large. [Searching] the code will help reveal the size of the source. Rather than fork multiple repros, this assumes you've already cloned the chromium trunk.

These files are intended to supplement the trunk.

Some customization of the content-shell via content-flags are necessary.

Create a text file content-shell-command-line with the following content, these are the content flags.

content_shell chrome --js-flags=--expose-gc --enable-dcheck --disable-gesture-requirement-for-media-playback --v=1 --vmodule=chunk*=1,source*=1,media*=1,webmed*=1,*=0 --webcore-log-channels=Media --no-restore-state --tablet-ui --tablet-ui --force-compositing-mode --allow-webui-compositing --enable-threaded-compositing --enable-fixed-position-compositing --enable-accelerated-overflow-scroll --enable-accelerated-scrollable-frames --enable-composited-scrolling-for-frames --enable-begin-frame-scheduling --enable-deadline-scheduling --disable-gesture-debounce --enable-gesture-tap-highlight --enable-pinch --enable-overlay-fullscreen-video --enable-overlay-scrollbars --enable-overscroll-notifications --touch-ack-timeout-delay-ms=200 --in-process-gpu --disable-gpu-shader-disk-cache --enable-viewport --enable-viewport-meta --main-frame-resizes-are-orientation-changes --disable-composited-antialiasing --ui-prioritize-in-gpu-process --profiler-timing=0 --composite-to-mailbox --gpu-driver-bug-workarounds=0,23,26,34 --disable-gpu-watchdog chrome

Deploy the file and restart chrome-shell.

adb push content-shell-command-line /data/local/tmp/content-shell-command-line

The build/deploy/run command. Run from the command from the chromium/src folder.

ninja -C out/Release -j10 content_shell_apk && build/android/adb_install_apk.py --apk ContentShell.apk --release && build/android/adb_run_content_shell

Altered file list:

.gclient
\---src
    +---content
    |   |   content_shell.gypi
    |   |
    |   +---public
    |   |   +---android
    |   |   |   \---java
    |   |   |       \---src
    |   |   |           \---org
    |   |   |               \---chromium
    |   |   |                   \---content
    |   |   |                       \---browser
    |   |   |                           |   ContentView.java
    |   |   |                           |   ContentViewClient.java
    |   |   |                           |   ContentViewCore.java
    |   |   |                           |
    |   |   |                           \---input
    |   |   |                                   ImeAdapter.java
    |   |   |
    |   |   \---common
    |   |           content_client.cc
    |   |
    |   +---renderer
    |   |   web_preferences.cc
    |   |
    |   \---shell
    |       \---android
    |           +---java
    |           |   +---res
    |           |   |   \---layout
    |           |   |           shell_view.xml
    |           |   |
    |           |   \---src
    |           |       \---org
    |           |           \---chromium
    |           |               \---content_shell
    |           |                       Shell.java
    |           |                       ShellManager.java
    |           |
    |           \---shell_apk
    |               |   AndroidManifest.xml
    |               |
    |               +---libs
    |               |       ouya-sdk.jar
    |               |
    |               +---res
    |               |   +---drawable
    |               |   |       app_icon.png
    |               |   |
    |               |   +---drawable-xhdpi
    |               |   |       ouya_icon.png
    |               |   |
    |               |   \---layout
    |               |           content_shell_activity.xml
    |               |
    |               \---src
    |                   \---org
    |                       \---chromium
    |                           \---content_shell_apk
    |                                   ContentShellActivity.java
    |
    +---media
    |   \---base
    |       \---android
    |           \---java
    |               \---src
    |                   \---org
    |                       \---chromium
    |                           \---media
    |                                   MediaCodecBridge.java
    |
    \---ui
        \---events
            \---keycodes
                    keyboard_code_conversion_android.cc

Turn on spatial navigation

src/content/renderer/web_preferences.cc
#if defined(OS_ANDROID)
  settings->setSpatialNavigationEnabled(true);
#endif

Quick ways to browse a specific URL

* The URL toolbar can be toggled.
mShellManager.showToolbar();

mShellManager.hideToolbar();

* Run activity manager to use an intent filter and set the URL via the command-line.
adb shell am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n org.chromium.content_shell_apk/org.chromium.content_shell_apk.ContentShellActivity -d http://google.com

Check Capabilities

adb shell am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n org.chromium.content_shell_apk/org.chromium.content_shell_apk.ContentShellActivity -d chrome://gpu

Setting up the build environment

  • Install the [JDK6 1.6] from the Oracle archives.

cd ~/Downloads
chmod +x ./jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin
  • Add Java to your environment.
Add this to the end of the ~/.bashrc file.
export JAVA_HOME=~/Downloads/jdk1.6.0_45
export PATH=$PATH:~/Downloads/jdk1.6.0_45/bin
  • Install [Android Studio]. This is the easiest way to get the Android Build Tools and SDK needed for the build.

cd ~/Downloads
tar zxvf android-studio-bundle-133.970939-linux.tgz
cd ~/Downloads/android-studio/bin
./studio.sh
  • Launch the SDK Manager from inside Android Studio (Tools -> Android -> SDK Manager) and configure it so it matches at least the following:

* Android SDK Tools 22.3
* Android SDK Platform-Tools 19
* Android 4.3 (API 18) SDK Platform
* Extras Android Support Repository
* Extras Android Support Library
* Extras Google Repository

  • Create a Virtual Machine in (VMWare Workstation/Fusion or Virtual Box) with [Ubuntu 12.04 LTS Desktop 64-bit] as your guest image. VMWare is recommended as you don't need to export/import to backup/restore the virtual machine image.

  • For the guest, you want about 80GB of disk space to handle compiling Chromium. You'll want 160GB if you need the space to duplicate the compiled source or to archive the folder for backup.

  • The guest needs a minimum of 2GB of RAM to compile, 4GB is recommended.

  • I typically turn off the power settings and lock screen for guests, since the host can handle the lock screen. Open All Settings->Brightness and Lock. Set inactive screen to "Never". Turn off the "Lock". Turn off "Require my password when waking up from suspend". That way your VM is always responsive and you don't miss anything while compiling.

(After you've created a VM and installed Ubuntu):


cd ~/Downloads
sudo apt-get install git
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

Getting chromium from trunk

Guide: [how-to-get-the-code].

These are the quick steps that I use. Open a terminal.

Make/change to folder

mkdir ~/Documents/chromium
cd ~/Documents/chromium

Make sure the tools are in your path:

export PATH="$PATH":`echo ~`/Downloads/depot_tools/

Get the Android source

fetch android --nosvn=True

Sync the code

cd ~/Documents/chromium/src
git pull --rebase origin master
gclient sync

GIT is needed to get the source.

sudo apt-get install git-core gitk git-gui subversion curl lib32z1 ant

Get the dependencies, you may need to run several times if 'gclient sync' returns errors. You should see an agreement if you've run it enough times.

./build/install-build-deps.sh

Enable the Android flag, edit the .gclient file (for trunk)

vi ../.gclient
solutions = [{u'managed': False, u'name': u'src', u'url': u'https://chromium.googlesource.com/chromium/src.git', u'custom_deps': {}, u'deps_file': u'.DEPS.git', u'safesync_url': u''}] target_os = ['android']

Sync the code again

git pull --rebase origin master
gclient sync

Make sure adb is in your path. Add the Android SDK paths for your location to the end of your ~/.bashrc file.

export PATH=$PATH:~/Downloads/android-studio/sdk/platform-tools/:~/Downloads/android-studio/sdk/tools/

Make sure device is connected to adb

adb connect IP:port

Compile

export CHROME_SRC=~/Documents/chromium/src
. build/android/envsetup.sh
android_gyp
ninja -C out/Release content_shell_apk

Building updates and launching:

ninja -C out/Release -j10 content_shell_apk && build/android/adb_install_apk.py --apk ContentShell.apk --release && build/android/adb_run_content_shell

At this point, copy the files from this repository into /path/to/chrome.

Repeat the build and launching step.

And then apply the chrome-shell flags from above.

<h1Running the Chromium profiler

Make sure there's an output folder and give write permissions

adb shell mkdir sdcard/Download
chmod 777 /sdcard/Download

Login with Super User

adb shell
su

Start the trace (limit to 10 seconds)

am broadcast -a org.chromium.content_shell_apk.GPU_PROFILER_START -e file /sdcard/Download/trace.txt

Stop the trace

am broadcast -a org.chromium.content_shell_apk.GPU_PROFILER_STOP

Pull the file for analysis

adb pull /sdcard/Download/trace.txt

Browse the trace file in your desktop Chrome browser

chrome://tracing/

Check out more info on the [tracing tool].

Keyboard definitions

ui/events/keycodes/keyboard_codes_posix.h

Any KeyEvents that map to KEYCODE_UNKNOWN can be added to the mapping.

ui/events/keycodes/keyboard_code_conversion_android.cc

IDE

  • Sublime Text makes a good editor for working with the Chromium source.

Debugging

Remote Debugging

  • Remote Debugging is a great way to debug JavaScript on the Android device.

  • Chrome Canary is needed to do remote debugging against the trunk. You want your desktop browser to be at or a better version of Chrome than the version you are debugging.

Logging

You can filter logs by your specific process id when looking for issues.

Find your process id - PID. Replace your.bundle.id with your package identifier to find the process.
adb shell ps | grep your.bundle.id
And then use the PID with process logging turned on to find log messages just for your application.
adb logcat -v process | grep THE_PROCESS_ID

Enable logging - http://www.chromium.org/developers/how-tos/debugging-on-android#TOC-Log-output