That's too bad that shouldInterceptLoadRequest() is synchronous because we're
seeing that slow loading of the requested data holds up the UI of the
XWalkView.So, on a webpage with 10 images that need to load from a remote
server, it takes about 10 seconds to show the webpage.
The documentation for the shouldInterceptLoadRequest states the request is made
on the network thread, see
:https://crosswalk-project.org/apis/embeddingapidocs/reference/org/xwalk/core/XWalkResourceClient.html#shouldInterceptLoadRequest(org.xwalk.core.XWalkView,
java.lang.String)but we're seeing that it holds up the javascript execution of
the webpage.
Is there possibly a XWalkView configuration that increases the number of
threads for the data I/O requests ? It feels like 1 thread, but maybe I can
increase the thread-pool to use about 20 ?
With regards to changing the URL, the use-case is as follows :1) the image is
marked as "external" by the webpage developer. He does this by altering the
scheme of the URL, i.e. external://server.com/myimage.jpg2) the app intercepts
the data request with shouldInterceptLoadRequest(), captures the scheme for
metrics, and changes the URL scheme to http://3) the data is downloaded with
OkHttpClient, a WebResourceResponse is generated much like your example, and
shouldInterceptLoadRequest() returns.
snippet of code that performs step #3 :Request request = new
Request.Builder().url(externalUrl).build();Response response =
client.newCall(request).execute();byte []assetData =
response.body().bytes();WebResourceResponse responseToReturn = new
WebResourceResponse("image/jpeg", "UTF-8", new ByteArrayInputStream(assetData));
As you can see, step #3 must be done without affecting the UI and must be done
multi-threaded.
Is there any configuration / any solution at all to prevent the image download
from affecting the UI/javascript animation?At the moment, animation/javascript
is paused until all the images have been completely downloaded for the webpage.
Regards,Alexander
From: [email protected]
To: [email protected]; [email protected]
Subject: RE: [Crosswalk-help] [crosswalk-help] How is it possible to async
download images from shouldInterceptLoadRequest() ?
Date: Tue, 21 Apr 2015 02:00:02 +0000
Is there a response that practically states "hang on whilst we're downloading
this image, I'll let you get back to it later, in the meantime go on to the
next resource" ?
ð
No. This API is suggested to be used synchronously. You need to return
WebResourceResponse asap.
If the answer to my first question is "no", is it possible to alter the URL to
the resource and then have XWalkView download it ?
ð
I did several experiments, cannot alter the url. I do not know your user
case, but this will be weird to users. BTW, you can alter the url to a local
page like this:
private static final String RESTRICTED = "<html><body>not
allowed</body></html>";
@Override
public WebResourceResponse shouldInterceptLoadRequest(XWalkView view,
String url) {
try {
return new
WebResourceResponse("text/html","UTF-8",
new
ByteArrayInputStream(RESTRICTED.getBytes("UTF-8")));
}
catch (Exception ex) {
Log.e(TAG, "Bad file" + ex.toString());
}
return null;
}
From: Crosswalk-help [mailto:[email protected]]
On Behalf Of Alexander Biemann
Sent: Tuesday, April 21, 2015 7:36 AM
To: [email protected]
Subject: [Crosswalk-help] [crosswalk-help] How is it possible to async download
images from shouldInterceptLoadRequest() ?
My app intercepts the shouldInterceptLoadRequest() and needs to download
graphics asynchronously so that multiple images don't download one after
another, but mostly in parallel.
public WebResourceResponse shouldInterceptLoadRequest (XWalkView view,
String url)
My initial idea is to have my app start multiple download threads, however,
after the URL is handed off to the download thread there needs to be some kind
of returned data in the WebResourceResponse.
Is there a response that practically states "hang on whilst we're downloading
this image, I'll let you get back to it later, in the meantime go on to the
next resource" ?
I would return null, so that XWalkView can download it (hopefully
asynchronously - I haven't tested it), but the URL has to be altered so that
the resource can be downloaded.
If the answer to my first question is "no", is it possible to alter the URL to
the resource and then have XWalkView download it ?
Thanks !
_______________________________________________
Crosswalk-help mailing list
[email protected]
https://lists.crosswalk-project.org/mailman/listinfo/crosswalk-help