webkit 扩展JS(添加新类)
来源:互联网 发布:iphone6s硬件检测软件 编辑:程序博客网 时间:2024/05/20 18:46
webkit 扩展JS(添加新类)
实现本文的方法后,可以在js脚本里用新的类 比如想新加一个类miuiAgent,其中的方法为descript,当调用alert(miuiAgent.descript)时即可弹出包含descript内容的窗口。具体描述如下(可以依葫芦画瓢) (本文是在android 4.1上实现的)
1. WebCore/page目录下在添加MIuiAgent.h文件 (WebCore/page/MiuiAgent.h)
#ifndef MiuiAgent_h
#define MiuiAgent_h
#include <wtf/RefCounted.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
#if PLATFORM(ANDROID) && ENABLE(APPLICATION_INSTALLED)
#include "PlatformString.h"
#endif
namespace WebCore {
class Frame;
class MiuiAgent : public RefCounted<MiuiAgent> {
public:
static PassRefPtr<MiuiAgent> create(Frame* frame)
{
return adoptRef(new MiuiAgent(frame));
}
~MiuiAgent();
void disconnectFrame();
Frame* frame() const { return m_frame; }
String description() const;
private:
MiuiAgent(Frame*);
Frame* m_frame;
};
}
#endif
2. WebCore/page目录下在添加MIuiAgent.cpp文件 (WebCore/page/MiuiAgent.cpp)
#include "config.h"
#include "MiuiAgent.h"
#include "PlatformString.h"
namespace WebCore {
MiuiAgent::MiuiAgent(Frame* frame)
: m_frame(frame)
{
}
MiuiAgent::~MiuiAgent()
{
disconnectFrame();
}
void MiuiAgent::disconnectFrame()
{
m_frame = 0;
}
String MiuiAgent::description() const
{
return "XiaoMIBrowser";
}
}
3. WebCore/page目录下在添加MIuiAgent.idl文件 (WebCore/page/MiuiAgent.idl)
module window {
interface [OmitConstructor] MiuiAgent {
readonly attribute DOMString description;
};
}
4. 修改DOMWindow.h文件(WebCore/page/DOMWindow.h)
//添加声明
class Navigator;
+ class MiuiAgent;
class Node;
......
......
//添加函数
Navigator* navigator() const;
Navigator* clientInformation() const { return navigator(); }
+ MiuiAgent* miuiAgent() const;
Location* optionalLocation() const { return m_location.get(); }
StyleMedia* optionalMedia() const { return m_media.get(); }
+ MiuiAgent* optionMiuiAgent() const { return m_miuiAgent.get(); }
//添加成员
mutable RefPtr<Location> m_location;
mutable RefPtr<StyleMedia> m_media;
+ mutable RefPtr<MiuiAgent> m_miuiAgent;
5. 修改DOMWindow.cpp文件(WebCore/page/DOMWindow.cpp)
+#include "MiuiAgent.h"
//函数添加代码
void DOMWindow::clear() {
m_navigator->disconnectFrame();
m_navigator = 0;
+ if (m_miuiAgent)
+ m_miuiAgent->disconnectFrame();
+ m_miuiAgent = 0;
//添加函数
+MiuiAgent* DOMWindow::miuiAgent() const
+{
+ if (!m_miuiAgent)
+ m_miuiAgent = MiuiAgent::create(m_frame);
+ return m_miuiAgent.get();
+}
6. 修改DOMWindow.idl文件(WebCore/page/DOMWindow.idl)
attribute [Replaceable] Navigator navigator;
attribute [Replaceable] Navigator clientInformation;
+ attribute [Replaceable] MiuiAgent miuiAgent;
7. 修改Andrid.mk文件 (WebCore/Android.mk)
LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
page/Location.cpp \
page/MemoryInfo.cpp \
page/MouseEventWithHitTestResults.cpp \
+ page/MiuiAgent.cpp \
page/Navigator.cpp \
page/NavigatorBase.cpp \
page/OriginAccessEntry.cpp \
8. 修改Android.deviced.v8bindings.mk(WebCore/Android.deviced.v8bindings.mk)
GEN := \
$(intermediates)/bindings/V8History.h \
$(intermediates)/bindings/V8Location.h \
$(intermediates)/bindings/V8MemoryInfo.h \
+ $(intermediates)/bindings/V8MiuiAgent.h \
$(intermediates)/bindings/V8Navigator.h \
9. 大工告成
试着写一个html文件
<html>
<script type="text/javascript">
document.write("<p>--------++++++++++++++++</p>");
document.write("<p>" + miuiAgent.description + "</p>");
</script>
<body>
</body>
</html>
即可看到页面显示文字
XiaoMiBrowser
- webkit 扩展JS(添加新类)
- webkit js扩展方式之Binding添加新DOM对象
- GTK Webkit 添加JS对象
- QT Webkit 添加JS对象
- GTK Webkit 添加JS对象
- GTK Webkit 添加JS对象
- webkit开发之JS扩展篇
- Webkit JS扩展对象 多实例实现
- node-webkit node.js c++扩展
- php 添加新的扩展
- android webkit 添加全局js function
- js,jquery 添加扩展方法
- 新版本的webkit 针对jsc的js扩展方式
- android 4.0.1 webkit 基于JSC的JS 扩展
- WebKit中为JS binding扩展DOM对象
- node.js 和 node-webkit C++扩展方法
- Linux下php添加新扩展
- 虚拟机扩展磁盘--不添加新磁盘
- WebView Touch事件总结
- cocos2d-x 添加admob全屏广告(iOS版)
- 数据结构与算法之——线性表的链式存储结构
- ubuntu(Debian)中ISO相关控制命令
- 我们去哪
- webkit 扩展JS(添加新类)
- 第六周
- 软件工程研究领域最顶级的两个期刊
- 当今商业中使用的三种十分重要的IT应用系统
- SublimeText2 快捷键一览表
- ubuntu 10.10如何开机直接进入命令行界面
- css添加一条属性
- 中文分词
- hdu1404(博弈搜索打表)