WebView setblocknetworkimage the ins and outs

Source: Internet
Author: User

itself meaning block Picture network data
Websettings.setblocknetworkimage (TRUE);
Unblock data
Websettings.setblocknetworkimage (FALSE);


In fact, a simple sentence is why it's such a powerful skill.
Let's take a look at the concrete implementation.
Websettingsclassic.java
/**
* @see Android.webkit.websettings#setblocknetworkimage (Boolean)
*/
@Override
Public synchronized void Setblocknetworkimage (Boolean flag) {
if (mblocknetworkimage! = flag) {
Mblocknetworkimage = Flag;
Postsync ();
}
}
The key code looks only
Mblocknetworkimage = Flag;
But don't ignore it.
Postsync ();
This is to notify the C + + layer to read the Mblocknetworkimage value
Let's take a look at the specific Postsync function implementation
/* Post a SYNC message to handle syncing the native settings. */
Private synchronized void Postsync () {
Only post if a sync isn't pending
if (!msyncpending) {
msyncpending = Meventhandler.sendmessage (
Message.obtain (NULL, eventhandler.sync));
}
}


Notification to
Create a new handler
Mhandler = new Handler () {
@Override
public void Handlemessage (Message msg) {
Switch (msg.what) {
Case SYNC:
Synchronized (websettingsclassic.this) {
if (mbrowserframe.mnativeframe! = 0) {
Nativesync (Mbrowserframe.mnativeframe);
}
Msyncpending = false;
}
Break


Synchronize the native and Java settings.
Private native void Nativesync (int nativeframe);
The last function called


C + + underlying function implementation
Webkit/android/jni/websettings.cpp
//-------------------------------------------------------------
JNI Registration
//-------------------------------------------------------------
Static Jninativemethod gwebsettingsmethods[] = {
{"Nativesync", "(I) V",
(void*) Websettings::sync}
};
static void Sync (jnienv* env, Jobject obj, jint frame)
{
webcore::frame* pframe = (webcore::frame*) Frame;
Alog_assert (pframe, "%s must take a valid frame pointer!", __function__);
webcore::settings* s = pframe->settings ();
if (!s)
Return
webcore::cachedresourceloader* Cachedresourceloader = pframe->document ()->cachedresourceloader ();


Flag = Env->getbooleanfield (obj, gfieldids->mblocknetworkimage);
S->setblocknetworkimage (flag);
if (!flag)
Cachedresourceloader->setblocknetworkimage (FALSE);
}




Specific implementation
CachedResourceLoader.cpp inside
void Cachedresourceloader::setblocknetworkimage (bool block)
{
if (block = = M_blocknetworkimage)
Return


M_blocknetworkimage = Block;


if (!m_autoloadimages | | m_blocknetworkimage)
Return


Documentresourcemap::iterator end = M_documentresources.end ();
for (Documentresourcemap::iterator it = M_documentresources.begin (); it! = end; ++it) {
cachedresource* resource = It->second.get ();
if (resource->type () = = Cachedresource::imageresource) {
cachedimage* image = Const_cast<cachedimage*> (Static_cast<const cachedimage*> (Resource));
Image->setautoloadwaspreventedbysettings (FALSE);
if (Image->stillneedsload ()) {
Image->setloading (TRUE);
Load (image, true);
}
}
}
}


Finally found this guy, originally engaged in a loop in the whistling execution, send a network request
The overall execution process is now basically clear.

The above code is for the analysis of android4.1.1 version code

Contact information

[Email protected]

qq:390012381

Reprint Please specify source: http://blog.csdn.net/lihui130135











WebView setblocknetworkimage the ins and outs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.