问题描述:
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) \
wml/WMLAccessElement.cpp \
wml/WMLAElement.cpp \
wml/WMLAnchorElement.cpp \
wml/WMLBRElement.cpp \
wml/WMLCardElement.cpp \
wml/WMLDocument.cpp \
wml/WMLDoElement.cpp \
wml/WMLElement.cpp \
wml/WMLErrorHandling.cpp \
wml/WMLEventHandlingElement.cpp \
wml/WMLFieldSetElement.cpp \
wml/WMLFormControlElement.cpp \
wml/WMLGoElement.cpp \
wml/WMLImageElement.cpp \
wml/WMLImageLoader.cpp \
wml/WMLInputElement.cpp \
wml/WMLInsertedLegendElement.cpp \
wml/WMLIntrinsicEvent.cpp \
wml/WMLIntrinsicEventHandler.cpp \
wml/WMLMetaElement.cpp \
wml/WMLNoopElement.cpp \
wml/WMLOnEventElement.cpp \
wml/WMLOptGroupElement.cpp \
wml/WMLOptionElement.cpp \
wml/WMLPageState.cpp \
wml/WMLPElement.cpp \
wml/WMLPostfieldElement.cpp \
wml/WMLPrevElement.cpp \
wml/WMLRefreshElement.cpp \
wml/WMLSelectElement.cpp \
wml/WMLSetvarElement.cpp \
wml/WMLTableElement.cpp \
wml/WMLTaskElement.cpp \
wml/WMLTemplateElement.cpp \
wml/WMLTimerElement.cpp \
wml/WMLVariables.cpp \
\
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)
$(transform-generated-source)
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"
|| mimeType == "text/vnd.wap.wml")
return true;
2)/frameworks/base/core/java/android/webkit/LoadListener.java
private void handleHeaders(Headers headers) {} 方法中
else if (mMimeType.equals("text/vnd.wap.wml")) {
// As we don't support wml, render it as plain text
mMimeType = "text/plain";
}
蓝色部分需要注释掉。