Skip to content
This repository has been archived by the owner on Jan 7, 2018. It is now read-only.

Commit

Permalink
ChromeView works for both file:///android_asset/ and http:// resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnall committed May 21, 2013
0 parents commit e5d3d24
Show file tree
Hide file tree
Showing 225 changed files with 35,932 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Files for the dex VM.
*.dex

# Java class files.
*.class

# Generated files.
bin/
gen/

# Local configuration file (sdk path, etc).
local.properties

# Vim.
*.sw*
33 changes: 33 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>chromeview</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
281 changes: 281 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .settings/org.eclipse.jdt.ui.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
formatter_profile=_NetMap
formatter_settings_version=12
9 changes: 9 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="us.costan.chrome"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
</manifest>
179 changes: 179 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# ChromeView

ChormeView works like Android's WebView, but is backed by the latest Chromium
code.


## Why ChromeView

ChromeView lets you ship your own Chromium code, instead of using whatever
version comes with your user's Android image. This gives your application
early access to the newest features in Chromium, and removes the variability
due to different WebView implementations in different versions of Android.


## Setting Up

This section explains how to set up your Android project to use ChromeView.

### Get the Code

Check out the repository in your Eclipse workspace, and make your project use
ChromeView as a library. In Eclipse, right-click your project directory, select
`Properties`, choose the `Android` category, and click on the `Add` button in
the `Library section`.

### Copy Data

Copy `assets/webviewchromium.pak` to your project's `assets` directory.
[Star this bug](https://code.google.com/p/android/issues/detail?id=35748) if
you agree that this is annoying.

In your `Application` subclass, call `ChromeView.initialize` and pass it the
application's context. For example,

### Initialize Chromium

```java
import us.costan.chrome.ChromeView;
import android.app.Application;

public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
ChromeView.initialize(this);
}
}
```

Now you can use ChromeView in the same contexts as you would use WebView.

### Star some bugs

If you use this project and want to help move it along, please star the
following bugs.

* [crbug.com/113088](http://crbug.com/113088)
* [crbug.com/234907](http://crbug.com/234907) and
* [this Android bug](https://code.google.com/p/android/issues/detail?id=35748)


## Usage

To access ChromeView in the graphical layout editor, go to the `Palette`,
expand the `Custom and Library Views` section, and click the `Refresh` button.

ChromeView supports most of the WebView methods. For example,

```java
ChromeView chromeView = (ChromeView)findViewById(R.id.gameUiView);
chromeView.getSettings().setJavaScriptEnabled(true);
chromeView.loadUrl("http://www.google.com");
```

### JavaScript

ChromeView's `addJavaScriptInterface` exposes public methods that are annotated
with `@ChromeJavascriptInterface`. This is because WebView's
`@JavascriptInterface` is only available on Android 4.2 and above, but
ChromeView targets 4.0 and 4.1 as well.

```java
import us.costan.chrome.ChromeJavascriptInterface;

public class JsBindings {
@ChromeJavascriptInterface
public String getHello() {
return "Hello world";
}
}

chromeView.addJavascriptInterface(new JsBindings(), "AndroidBindings");
```

### Cookies

ChromeCookieManager is ChromeView's equivalent of CookieManager.

```java
ChromeCookieManager.getInstance().getCookie("https://www.google.com");
```

### Faster Development

To speed up the application launch on real devices, remove the `libs/x86`
directory. When developing on Atom devices, remove the ARM directory instead.

Remember to `git checkout -- .` and get the library back before building a
release APK.

### Internet Access

If your application manifest doesn't specify the
[INTERNET permission](http://developer.android.com/reference/android/Manifest.permission.html#INTERNET),
the Chromium code behind ChromeView silentely blocks all network requests. This
is mentioned here because it can be hard to debug.


## Building

The bulk of this project is Chromium source code and build products. With the
appropriate infrastructure, the Chromium bits can be easily updated.

[crbuild/vm-build.md](crbuild/vm-build.md) contains step-by-step instructions
for setting up a VM and building the Chromium for Android components used by
ChromeView.

Once Chromium has been successfully built, running
[crbuild/update.sh](crbuild/update.sh) will copy the relevant bits from the
build VM into the ChromeView source tree.


## Issues

Attempting to scroll the view (by swiping a finger across the screen) does not
update the displayed image. However, internally, the view is scrolled. This can
be seen by displaying a stack of buttons and trying to click on the topmost
one. This issue makes ChromeView mostly unusable in production.

The core issue is that the integration is done via `AwContent` in the
`android_webview` directory of the Chromium source tree, which is experimental
and not intended for embedding use. The "right" way of doing this is to embed
a `ContentView` from the `content` directory, or a `Shell` in `content/shell`.
Unfortunately, these components' APIs don't match WebView nearly as well as
AwContent, and they're much harder to integrate. Pull requests or a fork would
be welcome.

This repository is rebased often, because the large files in `lib/` would
result in a huge repository if new commits were created for each build. The
large files are Chromium build products.


## Contributing

Please don't hesitate to send your Pull Requests!

Please don't send pull requests including the binary assets or code extracted
from Android (`assets/`, `libs/`, `src/com/googlecode/` and `src/org/android`).
If your Pull Request requires updated Android bits, mention that in the PR
description, and I will rebuild the Android bits.


## Copyright and License

The directories below contain code from the
[The Chromium Project](http://www.chromium.org/), which is subject to the
copyright and license on the project site.

* `assets/`
* `libs/`
* `src/com/googlecode`
* `src/org/chromium`

Some of the source code in `src/us/costan/chrome` has been derived from the
Android source code, and is therefore covered by the
[Android project licenses](http://source.android.com/source/licenses.html).

The rest of the code is Copyright 2013, Victor Costan, and available under the
MIT license.
Binary file added assets/webviewchromium.pak
Binary file not shown.
59 changes: 59 additions & 0 deletions crbuild/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Updates this project with the Chrome build files.
# This script assumes the Chrome build VM is up at crbuild.local

# Clean up.
rm -r assets/*
rm -r libs/*
rm -r src/com/googlecode
rm -r src/org/chromium

# ContentShell core -- use this if android_webview doesn't work out.
#scp [email protected]:chromium/src/out/Release/content_shell/assets/* \
# assets/
#scp -r [email protected]:chromium/src/out/Release/content_shell_apk/libs/* \
# libs
#scp -r [email protected]:chromium/src/content/shell/android/java/res/* res
#scp -r [email protected]:chromium/src/content/shell/android/java/src/* src
#scp -r [email protected]:chromium/src/content/shell_apk/android/java/res/* res

# android_webview
scp [email protected]:chromium/src/out/Release/android_webview_apk/assets/*.pak \
assets
scp -r [email protected]:chromium/src/out/Release/android_webview_apk/libs/* \
libs
rm libs/**/gdbserver
scp -r [email protected]:chromium/src/android_webview/java/src/* src/

## Dependencies inferred from android_webview/Android.mk

# Resources.
scp -r [email protected]:chromium/src/content/public/android/java/resource_map/* src/
scp -r [email protected]:chromium/src/ui/android/java/resource_map/* src/

# ContentView dependencies.
scp -r [email protected]:chromium/src/base/android/java/src/* src/
scp -r [email protected]:chromium/src/content/public/android/java/src/* src/
scp -r [email protected]:chromium/src/media/base/android/java/src/* src/
scp -r [email protected]:chromium/src/net/android/java/src/* src/
scp -r [email protected]:chromium/src/ui/android/java/src/* src/
scp -r [email protected]:chromium/src/third_party/eyesfree/src/android/java/src/* src/

# Strip a ContentView file that's not supposed to be here.
rm src/org/chromium/content/common/common.aidl

# Get rid of the .svn directory in eyesfree.
rm -r src/com/googlecode/eyesfree/braille/.svn

# Browser components.
scp -r [email protected]:chromium/src/components/web_contents_delegate_android/android/java/src/* src/
scp -r [email protected]:chromium/src/components/navigation_interception/android/java/src/* src/

# Generated files.
scp -r [email protected]:chromium/src/out/Release/gen/templates/* src/

# JARs.
scp -r [email protected]:chromium/src/out/Release/lib.java/guava_javalib.jar libs/
scp -r [email protected]:chromium/src/out/Release/lib.java/jsr_305_javalib.jar libs/

# android_webview generated sources. Must come after all the other sources.
scp -r [email protected]:chromium/src/android_webview/java/generated_src/* src/
Loading

0 comments on commit e5d3d24

Please sign in to comment.