含义本身防止网络数据图片
webSettings.setBlockNetworkImage(true);
停止发布数据
webSettings.setBlockNetworkImage(false);
造成这么强大的功力
我们来看下详细的实现
WebSettingsClassic.java
/**
* @see android.webkit.WebSettings#setBlockNetworkImage(boolean)
*/
@Override
public synchronized void setBlockNetworkImage(boolean flag) {
if (mBlockNetworkImage != flag) {
mBlockNetworkImage = flag;
postSync();
}
}
关键代码看上去仅仅有
mBlockNetworkImage = flag;
可是不要忽略了
postSync();
这个就是通知c++层去读取mBlockNetworkImage数值
我们看下详细的postSync函数实现
/* Post a SYNC message to handle syncing the native settings. */
private synchronized void postSync() {
// Only post if a sync is not pending
if (!mSyncPending) {
mSyncPending = mEventHandler.sendMessage(
Message.obtain(null, EventHandler.SYNC));
}
}
通知给
// 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);
最后调用的函数
c++底层函数实现
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);
}
详细实现
CachedResourceLoader.cpp里面
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);
}
}
}
}
最终找到这个家伙了,原来搞了一个循环在呼呼的运行,发送一个个的网络请求
总体运行流程如今来看基本清晰了。
上面代码是针对android4.1.1版本号代码的分析
假设对这篇讲的技术有不论什么疑问,第一时间获得文章更新,每天公布一篇技术大牛的原创文章。很多其它技术信息分享。
欢迎关注个人微信公众平台:程序猿互动联盟,扫一扫下方二维码或搜索微信号coder_online就可以关注,在线帮您解决技术难点,给大牛直接出难题。
联系方式
QQ:390012381
微信:donghuitalk
转载请注明出处:http://blog.csdn.net/lihui130135
版权声明:本文博主原创文章,博客,未经同意不得转载。