loading file:///android-asset/ urls

1,639 views
Skip to first unread message

Davis Ford

unread,
Aug 28, 2013, 3:54:45 PM8/28/13
to chromi...@chromium.org
Hi, on my own custom build of Chromium Content Shell, I can't seem to get local asset html files to load.

The project contains:
   assets/subdir-name/index.html

I'm doing the following in Shell.java 

LoadUrlParams params = new LoadUrlParams(sanitizeUrl(url));
params.setCanLoadLocalResources(true);
mContentView.loadUrl(params);
 

I've debugged it down to the native call which seems like a straight pass-thru:

    public void loadUrl(LoadUrlParams params) {
        if (mNativeContentViewCore == 0) return;
        nativeLoadUrl(mNativeContentViewCore,
                params.mUrl,
                params.mLoadUrlType,
                params.mTransitionType,
                params.mUaOverrideOption,
                params.getExtraHeadersString(),
                params.mPostData,
                params.mBaseUrlForDataUrl,
                params.mVirtualUrlForDataUrl,
                params.mCanLoadLocalResources);
    }

Nothing loads in the content view, though, and I get no error / info / warn messages in Log Cat -- nothing.  If I instead load an http:// url everything works great.  Is there some other flag / setting, etc. I need to enable to load html resources from inside the project?

Thanks in advance

Ted Choc

unread,
Aug 28, 2013, 5:23:27 PM8/28/13
to davi...@gmail.com, Chromium-dev
The file path is relative to the root directory on the phone, not your APK.

I just pushed a simple HTML file to /sdcard/Download, and it loaded fine using file:///sdcard/Download/test.html.

Maybe checkout PathUtils.java to help get the relative data path to your APK and go from there.


--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

Davis Ford

unread,
Aug 28, 2013, 9:05:54 PM8/28/13
to chromi...@chromium.org, davi...@gmail.com
Ah, ok -- I didn't realize that the content shell didn't support file:///android-* urls.  I guess AndroidWebView does.  I'll either take a look at how it resolves them, or use absolute file urls.

Mikhail Naganov

unread,
Aug 29, 2013, 6:52:18 AM8/29/13
to davi...@gmail.com, Chromium-dev
This is correct. "file:///android_asset" and "file:///android_res" are only supported by Android WebView. Look for "inputStreamForAndroidResource" here: https://android.googlesource.com/platform/frameworks/base.git/+/android-4.2.2_r1/core/java/android/webkit/BrowserFrame.java
Reply all
Reply to author
Forward
0 new messages