问题描述:
Android使用的Webkit默认是不支持WML格式的网页的,但实际上Webkit已经内置了WML的解析功能,我们可以通过修改环境变量来打开该功能。
问题分析以及解决:
1.添加wml头文件
修改external/webkit/Android.mk
在LOCAL_C_INCLUDES的定义中添加$(LOCAL_PATH)/WebCore/wml
2.添加wml源文件
修改external/webkit/WebCore/Android.mk
添加
LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
3.添加生成中间源文件的脚本
修改external/webkit/WebCore/Android.derived.mk
1)修改生成UserAgentStyleSheets.h的脚本
style_sheets的定义中添加$(LOCAL_PATH)/css/wml.css
2)添加生成WMLNames.cpp和WMLElementFactory.cpp的脚本(参考XMLNames.cpp生成脚本)
GEN:= $(intermediates)/WMLNames.cpp
$(intermediates)/WMLElementFactory.cpp
$(GEN): PRIVATE_PATH := $(LOCAL_PATH)
$(GEN): PRIVATE_CUSTOM_TOOL = perl -I $(PRIVATE_PATH)/bindings/scripts $< --attrs $(wml_attrs) --tags $(wml_tags) --factory --wrapperFactory --output $(dir $@)
$(GEN): wml_attrs := $(LOCAL_PATH)/wml/WMLAttributeNames.in
$(GEN): wml_tags := $(LOCAL_PATH)/wml/WMLTagNames.in
$(GEN): $(LOCAL_PATH)/dom/make_names.pl $(wml_attrs) $(wml_tags)
LOCAL_GENERATED_SOURCES += $(GEN)
4.开启WML宏定义
在external/webkit/WebCore/config.h中添加
#define ENABLE_WML 1
5.其他修改
1)external/webkit/WebCore/dom/DOMImplementation.cpp
在bool DOMImplementation::isXMLMIMEType(const String& mimeType) {}方法中添加对wml的支持
if (mimeType == "text/xml" || mimeType == "application/xml" || mimeType == "text/xsl"
2)/frameworks/base/core/java/android/webkit/LoadListener.java
private void handleHeaders(Headers headers) {} 方法中
else if (mMimeType.equals("text/vnd.wap.wml")) {
}
蓝色部分需要注释掉。