一旦你完毕了PPAPI插件的开发,实际使用时可能会有下列需求:

  • 动态创建PPAPI插件
  • 删除PPAPI插件
  • 改变PPAPI插件的尺寸

实现起来非常easy,从JS里直接訪问DOM(BOM)就可以。以下是一个演示样例HTML文件:

<!DOCTYPE html>
<html>
<!--
Copyright (c) 2016 foruok@微信订阅号“程序视界”(programmer_sight).
All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<style type="text/css"> #pluginContainer
{
padding: 0px;
width: 1220px;
height: 540px;
background-color: gray;
}
</style>
<script type="text/javascript">
function createPlugin() {
var plugin = document.createElement("embed");
plugin.setAttribute("id", "explugin");
plugin.setAttribute("type", "application/x-ppapi-example");
plugin.setAttribute("width", "1200px");
plugin.setAttribute("height", "520px"); var container = document.getElementById("pluginContainer");
container.appendChild(plugin);
}
function deletePlugin(){
var container = document.getElementById("pluginContainer");
var plugins = container.getElementsByTagName("embed");
if(plugins.length >= 1){
container.removeChild(plugins[0]);
}
}
function changeSize() {
var plugin = document.getElementById("examplePlugin");
plugin.setAttribute("width", "600px");
plugin.setAttribute("height", "300px");
}
function restoreSize() {
var plugin = document.getElementById("examplePlugin");
plugin.setAttribute("width", "1200px");
plugin.setAttribute("height", "520px");
}
</script>
<meta charset="UTF-8">
<title>Plugin Test</title>
</head> <body>
<input type="button" value="CreatePPAPI" onclick="createPlugin()"/>
<input type="button" value="ChangeSize" onclick="changeSize()"/>
<input type="button" value="RestoreSize" onclick="restoreSize()"/>
<input type="button" value="DeletePPAPI" onclick="deletePlugin()"/> <div id="pluginContainer">
<!--
<embed id="examplePlugin" type="application/x-ppapi-example" width="1200px" height="520px" />
-->
</div>
</body>
</html>

上面的HTML演示了创建、删除、改变大小几种常见的操作。

须要注意的是,当你删除一个PPAPI插件时,会调用到PPP_Instance的DidDestroy方法,你须要在这里的C++/C代码里删除插件实例,释放对应的资源。比方Graphics 2D。Image Data等。DidDestroy调用后,过一会儿。假设没有其它的插件实例存在。就会接着调用PPP_ShutdownModule。假设有,则不会。

个中逻辑,能够參考理解PPAPI的设计

当你设置embed元素的width和height属性后,PPAPI插件里。PPP_Instance的DidChangeView方法会被调用,你须要在这里依据新尺寸又一次创建相关资源。


就这样吧。

其它參考文章详见我的专栏:【CEF与PPAPI开发】。

PPAPI插件的动态创建、改动、删除的更多相关文章

  1. js动态创建表格,删除行列的小例子

    js动态创建表格,删除行列的实例代码. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...

  2. WPF 中动态创建和删除控件

    原文:WPF 中动态创建和删除控件 动态创建控件 1.容器控件.RegisterName("Name",要注册的控件)   //注册控件 2.容器控件.FindName(" ...

  3. js动态创建和删除option

    1.动态创建select function createSelect(){           var mySelect = document.createElement("select&q ...

  4. WPF 中动态创建、删除控件,注册控件名字,根据名字查找控件

    动态创建控件 1.容器控件.RegisterName("Name",要注册的控件)   //注册控件 2.容器控件.FindName("Name") as  控 ...

  5. 动态加入改动删除html表格内容

    1.需求 须要实现收银台上加入改动删除商品信息时顾显能够实时看到其变化 2.解决 收银台和顾显通过tcp传输进行数据通信,顾显通过操作html中的表格进行数据加入改动和删除操作 3.代码 mytest ...

  6. spring与quartz整合实现分布式动态创建,删除,改变执行时间定时任务(mysql数据库)

    背景:因为在项目中用到了定时任务,当时想到了spring的quartz,写完发现费了很大功夫,光是整合就花了一上午,其中最大的问题就是版本问题,项目中用的是spring3.2.8的版本,查阅发现,3. ...

  7. 通过JS动态创建和删除HTML元素

    <script type="text/javascript" language="Javascript"> function InputOnBlur ...

  8. Unity3D 中的面向对象设计 {游戏对象(创建、删除、获取),以及添加修改组件}

    一.创建游戏对象 游戏对象分三种:(1) 将物体模型等资源由Project工程面板拖拽到Hierarchy层次面板中 (2) 由GameObject菜单创建Unity自带的游戏对象,如Cube.Cam ...

  9. [转]C# FileSystemWatcher监控指定文件或目录的文件的创建、删除、改动、重命名等活动

    觉得这个很常用..比如一些软件.   http://www.rabbit8.cn/DoNet/407.html   FileSystemWatcher控件主要功能: 监控指定文件或目录的文件的创建.删 ...

随机推荐

  1. Leetcode30--->Substring with Concatenation of All Words(主串中找出连接给定所有单词的子串的位置)

    题目:给定一个字符串S(主串),一个字符串数组words,其中的字符串的长度相同.找到所有的子串位置,要求是words中字符串的一个连接: 举例: For example, given:s: &quo ...

  2. 一张图展示:用两个栈来实现一个队列,完成队列的Push和Pop操作

    一  基本思路 将s1作为存储空间,以s2作为临时缓冲区. 入队时,将元素压入s1. 出队时,将s1的元素逐个“倒入”(弹出并压入)s2,将s2的顶元素弹出作为出队元素,之后再将s2剩下的元素逐个“倒 ...

  3. TensorFlow学习笔记(6):TensorBoard之Embeddings

    本文基于TensorFlow官网的How-Tos写成. TensorBoard是TensorFlow自带的一个可视化工具,Embeddings是其中的一个功能,用于在二维或三维空间对高维数据进行探索. ...

  4. [Pandas技巧] 如何把pandas dataframe对象或series对象转换成list

    import pandas as pd >>> df = pd.DataFrame({'a':[1,3,5,7,4,5,6,4,7,8,9], 'b':[3,5,6,2,4,6,7, ...

  5. 【Istio】error initializing configuration '/etc/istio/proxy/envoy-rev0.json': malformed IP address: istio-statsd-prom-bridge

    今天遇到一个问题,istio的组件一直在重启,查看log大概是这个样子 --03T07::.935580Z info Epoch starting --03T07::.936317Z info Env ...

  6. Linux Shell系列教程之(七)Shell输出

    本文是Linux Shell系列教程的第(七)篇,更多shell教程请看:Linux Shell系列教程 与其他语言一样,Shell中也有输出操作,而且在实际应用中也是非常重要的,今天就为大家介绍下S ...

  7. Z-Score数据标准化处理(python代码)

    #/usr/bin/python def Z_Score(data): lenth = len(data) total = sum(data) ave = float(total)/lenth tem ...

  8. kb-01-a<简单搜索--dfs八皇后问题变种>

    题目描述: 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的 ...

  9. VK Cup 2016 - Qualification Round 1——A. Voting for Photos(queue+map)

    A. Voting for Photos time limit per test 1 second memory limit per test 256 megabytes input standard ...

  10. php的异常处理

    https://my.oschina.net/sallency/blog/837615