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