Chromium实现供JavaScript调用方法
2012-01-14 20:41
239 查看
Chromium是支持Video对象的,这个是HTML5的新特性,如今为了在JavaScript中能够调用到底层的一些特性,需要给其添加一个新的方法,即: 如何使JavaScript能够调用到Chromium底层的一些特性。
首先看一下Video Play方法的调用堆栈,
通过调用堆栈我们可以看到,Play方法最初是应该属于HTMLMediaElement,这个也是HTML5的一个元素,Video继承至它。
我们再来看看相关一些类的关系,
这样就更清晰了,通过调查可以得知,我们只有在HTMLMediaElement中定义相应的接口,然后一路调用下去,最后就可以调用到WebMediaPlayerImpl,这个类具体实现Player的相应功能,这个类中可以调用到PipeLine,这样我们就可以调用我们任意想调用的东西了,例如: demux,decoder,render等。要想把相应的接口Export到JavaScript层,在HTMLMediaElement.idl中定义是关键,其他的事情框架就给我做了。下面讲一个小例子。
----------------------------------------------------Sample--------------------------------------------
We implement a specialcall interface on HTMLMediaElementand it call WebMediaPlayerImpl’s function finally.
First we prepare a sample.html to triggerthe call as below:
Second, we add implemented code in Chromiumproject as below:
1, Add specialcall function inHTMLMediaElement class
voidHTMLMediaElement::specialcall() {
printf("Good , called my function in HTMLMediaElement! \n");
if(m_player)
m_player->myspecialcall();
else
printf("can't get m_player in HTMLMediaElement \n");
}
2, Export specialcall funciton inHTMLMediaElement.idl file
void specialcall();
3, Add specialcall in MediaPlayer class
void MediaPlayer::specialcall(){
printf("myspecialcall is called in MediaPlayer class \n");
m_private->myspecialcall();
}
4, Add a virtual function in WebMediaPlayerclass in WebMediaPlayer.h
virtual void myspecialcall() { }
5, Add a virtual function in MediaPlayerPrivateclass in WebMediaPlayer.h
virtual void specialcall() { }
6, Add a virtual function in WebMediaPlayerClientImplclass
void WebMediaPlayerClientImpl::specialcall(){
printf("specialcall is called in WebMediaPlayerClientImpl class\n");
if (m_webMediaPlayer.get())
m_webMediaPlayer->specialcall();
else
printf("can't get web media player at this moment \n");
}
7, Add a virtual function in WebMediaPlayerImpl class
voidWebMediaPlayerImpl::specialcall(){
printf("myspecialcall is called in WebMediaPlayerImpl class\n");
printf("Here,i think it's enough,you can get what you want becauseyou can get pipeline here \n");
}
Third, build theChromium project and run Chrome and load sample.html, click pay button afterload. The result is as below:
首先看一下Video Play方法的调用堆栈,
通过调用堆栈我们可以看到,Play方法最初是应该属于HTMLMediaElement,这个也是HTML5的一个元素,Video继承至它。
我们再来看看相关一些类的关系,
这样就更清晰了,通过调查可以得知,我们只有在HTMLMediaElement中定义相应的接口,然后一路调用下去,最后就可以调用到WebMediaPlayerImpl,这个类具体实现Player的相应功能,这个类中可以调用到PipeLine,这样我们就可以调用我们任意想调用的东西了,例如: demux,decoder,render等。要想把相应的接口Export到JavaScript层,在HTMLMediaElement.idl中定义是关键,其他的事情框架就给我做了。下面讲一个小例子。
----------------------------------------------------Sample--------------------------------------------
We implement a specialcall interface on HTMLMediaElementand it call WebMediaPlayerImpl’s function finally.
First we prepare a sample.html to triggerthe call as below:
|
1, Add specialcall function inHTMLMediaElement class
voidHTMLMediaElement::specialcall() {
printf("Good , called my function in HTMLMediaElement! \n");
if(m_player)
m_player->myspecialcall();
else
printf("can't get m_player in HTMLMediaElement \n");
}
2, Export specialcall funciton inHTMLMediaElement.idl file
void specialcall();
3, Add specialcall in MediaPlayer class
void MediaPlayer::specialcall(){
printf("myspecialcall is called in MediaPlayer class \n");
m_private->myspecialcall();
}
4, Add a virtual function in WebMediaPlayerclass in WebMediaPlayer.h
virtual void myspecialcall() { }
5, Add a virtual function in MediaPlayerPrivateclass in WebMediaPlayer.h
virtual void specialcall() { }
6, Add a virtual function in WebMediaPlayerClientImplclass
void WebMediaPlayerClientImpl::specialcall(){
printf("specialcall is called in WebMediaPlayerClientImpl class\n");
if (m_webMediaPlayer.get())
m_webMediaPlayer->specialcall();
else
printf("can't get web media player at this moment \n");
}
7, Add a virtual function in WebMediaPlayerImpl class
voidWebMediaPlayerImpl::specialcall(){
printf("myspecialcall is called in WebMediaPlayerImpl class\n");
printf("Here,i think it's enough,you can get what you want becauseyou can get pipeline here \n");
}
Third, build theChromium project and run Chrome and load sample.html, click pay button afterload. The result is as below:
相关文章推荐
- javascript实现相同事件名称,不同命名空间的调用方法
- 基于JavaScript实现继承机制之调用call()与apply()的方法详解
- javascript实现根据iphone屏幕方向调用不同样式表的方法
- 【转】利用ScriptManager实现Javascript调用WebService中的方法
- Android中通过WebView控件实现与JavaScript方法相互调用的地图应用
- JavaScript调用Activex控件的事件的实现方法
- JavaScript中模拟实现类似于Java的super关键字调用父类中同名方法
- Krpano学习:krpano调用javascript方法并传参、在krpano中用javascript实现视频音频播放
- 怎么实现javascript中调用java类中的方法
- JavaScript实现继承机制(2)——调用call()与apply()方法
- Asp.net中使用javaScript实现前后台方法的相互调用
- 基于JavaScript如何实现ajax调用后台定义的方法
- javascript中数组Array对象调用不同的方法可以实现几种数据结构
- JavaScript实现显示函数调用堆栈的方法
- javascript中定时器,主要用来实现局部刷新技术,或者定时调用某方法
- Android 实现WebView与JavaScript相互调用//支持javaScript对android方法调用 mWebView.addJavascriptInterface(n
- AJAXPRC实现了使用Javascript调用服务端方法
- 简谈 JavaScript、Java 中链式方法调用大致实现原理
- JavaScript 实现父,子页面(窗口)方法之间的相互调用
- javascript实现方法调用与方法触发小结