博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WebKit之XMLHttpRequest简单分析
阅读量:4025 次
发布时间:2019-05-24

本文共 5450 字,大约阅读时间需要 18 分钟。

●xmlrequest的用法	test	●Source/WebCore/xml/XMLHttpRequest.idlenum XMLHttpRequestResponseType {    "",    "arraybuffer",    "blob",    "document",    "json",    "text"};[    GlobalContext=DOMWindow&WorkerGlobalScope,//构造函数被添加到window同时WorkerGlobalScope之上    ActiveDOMObject,//指定DOM对象保持激活状态(只要有事件状态下),webcore实现需要继承 public ActiveDOMObject    Constructor,//js调用形式为new Object()    ConstructorCallWith=ScriptExecutionContext,//参数首个加入ScriptExecutionContext    JSCustomMarkFunction,//自定义JSCbinging的代码( JSXXX::visitChildren() )    EventTarget,//对应需要重载 addEventListener() removeEventListener() 具备事件管理的能力    JSNoStaticTables//默认情况为单一的property table,如果要求每个用户维护不同的表,则需要设定该flag] interface XMLHttpRequest {    // event handler attributes    attribute EventListener onabort;    attribute EventListener onerror;    attribute EventListener onload;    attribute EventListener onloadend;    attribute EventListener onloadstart;    attribute EventListener onprogress;    [Conditional=XHR_TIMEOUT] attribute EventListener ontimeout;    // event handler attributes    //用法: g_xmlHttpReq.onreadystatechange=onReplyCallback;    attribute EventListener onreadystatechange;    // state    const unsigned short UNSENT = 0;    const unsigned short OPENED = 1;    const unsigned short HEADERS_RECEIVED = 2;    const unsigned short LOADING = 3;    const unsigned short DONE = 4;    [Conditional=XHR_TIMEOUT, SetterRaisesException] attribute unsigned long timeout;    //if(g_xmlHttpReq.readyState==4 && g_xmlHttpReq.status==200)    readonly attribute unsigned short readyState;    [SetterRaisesException] attribute boolean withCredentials;    // optional修饰表示可传,可不传    // g_xmlHttpReq.open("GET","./service/main.php?cmd=1",true);    [Custom, RaisesException] void open(DOMString method, DOMString url, optional boolean async, optional DOMString user, optional DOMString password);    // xmlHttpRequest可以精确到任何可能的HTTP的字段的模拟    [RaisesException] void setRequestHeader(DOMString header, DOMString value);    //在webcore实现的参数中末尾追加(ExceptionCode& ec)   //JSValue JSXMLHttpRequest::send(ExecState* exec)    [Custom, RaisesException] void send();    void abort();    readonly attribute XMLHttpRequestUpload upload;    // response    [TreatReturnedNullStringAs=Undefined, RaisesException] DOMString getAllResponseHeaders();    [TreatReturnedNullStringAs=Null, RaisesException] DOMString getResponseHeader(DOMString header);    // JSValue JSXMLHttpRequest::responseText(ExecState* exec) const    [GetterRaisesException, CustomGetter] readonly attribute DOMString responseText; // The custom getter implements TreatReturnedNullStringAs=Null    [GetterRaisesException] readonly attribute Document responseXML;    [SetterRaisesException] attribute XMLHttpRequestResponseType responseType;    // JSValue JSXMLHttpRequest::send(ExecState* exec)    [GetterRaisesException, CustomGetter] readonly attribute Object response;    [GetterRaisesException] readonly attribute unsigned short status;    [GetterRaisesException] readonly attribute DOMString statusText;    // Extension    void overrideMimeType(DOMString override);    // EventTarget interface    void addEventListener(DOMString type,                           EventListener listener,                           optional boolean useCapture);    void removeEventListener(DOMString type,                              EventListener listener,                              optional boolean useCapture);    [RaisesException] boolean dispatchEvent(Event evt);};● Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp## 局部函数进行自定义实现● Source/WebCore/xml/XMLHttpRequest.cpp●创建对象PassRefPtr
XMLHttpRequest::create(ScriptExecutionContext* context){}## 构造对象XMLHttpRequest::XMLHttpRequest(ScriptExecutionContext* context){}## 访问DocumentDocument* XMLHttpRequest::document() const{ return static_cast
(scriptExecutionContext());}## 获取安全策略SecurityOrigin* XMLHttpRequest::securityOrigin() const>>return scriptExecutionContext()->securityOrigin();## 访问XHR的运行状态XMLHttpRequest::State XMLHttpRequest::readyState() const>>return m_state;String XMLHttpRequest::responseText(ExceptionCode& ec)>>return m_responseBuilder.toStringPreserveCapacity();Document* XMLHttpRequest::responseXML(ExceptionCode& ec)>> m_responseDocument = HTMLDocument::create(0, m_url);>> m_responseDocument = Document::create(0, m_url);>> m_responseDocument->setContent(m_responseBuilder.toStringPreserveCapacity());>> return m_responseDocument.get();ArrayBuffer* XMLHttpRequest::responseArrayBuffer(ExceptionCode& ec)## 上传对象XMLHttpRequestUpload* XMLHttpRequest::upload()>>m_upload = XMLHttpRequestUpload::create(this);## 改变状态void XMLHttpRequest::changeState(State newState)>>if (m_state != newState) >>callReadyStateChangeListener();void XMLHttpRequest::send(Document* document, ExceptionCode& ec)>>setRequestHeaderInternal("Content-Type", "application/xml");>>createRequest(ec);void XMLHttpRequest::send(ArrayBuffer* body, ExceptionCode& ec)>>sendBytesData(body->data(), body->byteLength(), ec);>>createRequest(ec);void XMLHttpRequest::send(ArrayBufferView* body, ExceptionCode& ec)>>sendBytesData(body->baseAddress(), body->byteLength(), ec);>>>>createRequest(ec);void XMLHttpRequest::createRequest(ExceptionCode& ec)>>通知>>ResourceRequest request(m_url);>>request.setHTTPMethod(m_method);>>ThreadableLoader::loadResourceSynchronously(scriptExecutionContext(), request, *this, options);>>m_loader = ThreadableLoader::create(scriptExecutionContext(), this, request, options);

转载地址:http://ajvbi.baihongyu.com/

你可能感兴趣的文章
attachEvent、addEventListener、detachEvent、removeEventListener
查看>>
最清晰的Android多屏幕适配方案
查看>>
Android使用fitsSystemWindows属性实现--状态栏【status_bar】各版本适配方案
查看>>
flex myeclipse安装.
查看>>
Google推荐的图片加载库Glide介绍
查看>>
如何使用Android Studio把自己的Android library分享到jCenter和Maven Central
查看>>
hibernate中get 与 load 区别
查看>>
AndFix Bug热修复框架的使用
查看>>
AndFix Bug热修复框架原理及源码解析
查看>>
Android各大网络请求库的比较及实战
查看>>
RxAndroid + OkHttp + MVP(Android Studio)
查看>>
ButterKnife使用手册中文
查看>>
Android Studio2.0的逆天功能Instant Run(告别编译运行)
查看>>
Instant Run工作原理及用法
查看>>
JSP文件下载及getOutputStream() has already been的解决
查看>>
Tomcat 6.0 开发配置小结
查看>>
FusionCharts 使用手记
查看>>
Struts,Spring,Hibernate优缺点
查看>>
JQuery+ajax+jsonp 跨域访问
查看>>
用Spring更好地处理Struts动作三种整合
查看>>