部署 Google Chrome 扩展程序;Adobe Flash Player 已停止可能不安全的操作 [英] Deploying a Google Chrome extension; Adobe Flash Player has stopped a potentially unsafe operation
问题描述
我想知道如何最好地处理在 Google Chrome 扩展程序中没有足够权限的问题.我正在与 YouTube API 交互,但我没有使用 swfobject.js,只是使用了嵌入式 div.我不认为这会引起我的安全问题,但也许确实如此.
I am wondering how to best handle the issue of not having enough permission inside of a Google Chrome Extension. I am interacting with the YouTube API, but I am not using swfobject.js, just using am embdeeded div. I do not believe this is introducing my security issue, but perhaps it is.
在开发过程中,我必须导航到 Adobe 的 Flash Player 安全页面并将我的开发文件夹指定为安全"位置.在部署中,我没有能力做到这一点.我不希望我的用户必须在 Flash 播放器安全性上单击全部允许",但我没有找到其他方法来实现我的结果.
In development, I had to navigate to Adobe's flash player security page and designate my development folder as a 'safe' location. In deployment, I do not have the ability to do this. I do not want my users to have to click 'Allow All' on flash player security, but I do not see another way to achieve my results.
有没有人有任何处理这个的经验?我有哪些选择?
Does anyone have any experience dealing with this? What are my options?
似乎是 Chrome 扩展程序中的 SWFobject - API 不可用 但仍未得到答复.
Seems to be a duplicate of SWFobject in a Chrome Extension - API Unavaiable but remains unanswered.
来源:https://github.com/MeoMix/YouPod
要运行:从存储库中拉出,加载 Chrome,单击扳手,转到扩展程序,选中开发人员工具"-> 加载未打包的扩展程序并浏览到文件夹.
To run: Pull from the repo, load up Chrome, click the wrench, go to extension, check 'Developer Tools' -> Load Unpacked Extension and browse to the folder.
实际操作:http://www.meomixes.com/Chrome%20Extension.crx
推荐答案
由于来源限制,您不能使用 元素.相反,嵌入
并使用 YouTube 播放器 API 与框架通信.
Because of the origin restrictions, you cannot use an <object>
element. Instead, embed an <iframe>
and use the YouTube player API to communicate with the frame.
将您的 function onYouTubePlayerReady
和 function Initialize(playlist)
替换为以下内容(在 background.js
):
Replace your function onYouTubePlayerReady
and function Initialize(playlist)
with the following (in background.js
):
function Initialize(playlist) {
port = chrome.extension.connect({ name: "statusPoller" });
if (!player) {
YT_ready(function() {
var frameID = getFrameID("MusicHolder");
if (frameID) {
player = new YT.Player(frameID, {
events: {
"onReady": function() {
player.cueVideoById(playlist[0].ID, 0);
},
"onStateChange": onPlayerStateChange
}
});
}
});
} else {
// Only reload if the player is not playing. Otherwise, the music
// stops when re-opening the popup.
if (player.getPlayerState && player.getPlayerState() != PLAYING) {
player.cueVideoById(playlist[0].ID, 0);
}
}
}
要使之前的代码工作,您必须在 background.htm
中加载另一个脚本.youtube-player-api-helper.js
的内容是根据我之前的在 JavaScript 或 jQuery 中侦听 Youtube 事件:
To get the previous code to work, you have to load another script in background.htm
. The contents of youtube-player-api-helper.js
are based on my previous answer to Listening for Youtube Event in JavaScript or jQuery:
// @description Easier way to implement the YouTube JavaScript API
// @author Rob W
// @global getFrameID(id) Quick way to find the iframe object which corresponds to the given ID.
// @global YT_ready(Function:function [, Boolean:qeue_at_start])
// @global onYouTubePlayerAPIReady() - Used to trigger the qeued functions
// @website https://stackoverflow.com/a/7988536/938089?listening-for-youtube-event-in-javascript-or-jquery
function getFrameID(id) {
var elem = document.getElementById(id);
if (elem) {
if(/^iframe$/i.test(elem.tagName)) return id; //Frame, OK
// else: Look for frame
var elems = elem.getElementsByTagName("iframe");
if (!elems.length) return null; //No iframe found, FAILURE
for (var i=0; i<elems.length; i++) {
if (/^https?://(?:www.)?youtube(?:-nocookie)?.com(/|$)/i.test(elems[i].src)) break;
}
elem = elems[i]; //The only, or the best iFrame
if (elem.id) return elem.id; //Existing ID, return it
// else: Create a new ID
do { //Keep postfixing `-frame` until the ID is unique
id += "-frame";
} while (document.getElementById(id));
elem.id = id;
return id;
}
// If no element, return null.
return null;
}
// Define YT_ready function.
var YT_ready = (function() {
var onReady_funcs = [], api_isReady = false;
/* @param func function Function to execute on ready
* @param func Boolean If true, all qeued functions are executed
* @param b_before Boolean If true, the func will added to the first
position in the queue*/
return function(func, b_before) {
if (func === true) {
api_isReady = true;
for (var i=0; i<onReady_funcs.length; i++){
// Removes the first func from the array, and execute func
onReady_funcs.shift()();
}
}
else if(typeof func == "function") {
if (api_isReady) func();
else onReady_funcs[b_before?"unshift":"push"](func);
}
}
})();
// This function will be called when the API is fully loaded
function onYouTubePlayerAPIReady() {YT_ready(true);}
// Load YouTube Frame API
(function() { //Closure, to not leak to the scope
var s = document.createElement("script");
s.src = "http://www.youtube.com/player_api"; /* Load Player API*/
var before = document.getElementsByTagName("script")[0];
before.parentNode.insertBefore(s, before);
})();
附加变化的说明(奖励):
Explanation of the additional changes (bonus):
background.htm
:无效.它应该是:
.
- 所有
.htm
文件:type
属性在标签上是可选的.即使你想指定一个,使用
application/javascript
而不是text/javascript
.两者都可以在 Chrome 扩展程序中使用,但第一个更正确. popup.js
:更改了 ctrl+c 的检测.使用e.ctrlKey
属性,而不是检测和记住Ctrl
是否被按下.- 还有一些.看看
popup.js
,然后搜索RobW:
以查找我的注释.
background.htm
:<!DOCTYPE html />
is invalid. It should be:<!DOCTYPE html>
.- All
.htm
files: Thetype
attribute is optional on the<script>
tag. Even if you want to specify one, useapplication/javascript
instead oftext/javascript
. Both will work in a Chrome extension, but the first one is more correct. popup.js
: Changed detection of ctrl+c. Instead of detecting and remembering whetherCtrl
was pressed, use thee.ctrlKey
property.- And some more. Have a look at
popup.js
, and search forRobW:
to find my annotations.
更新文件摘要(基于您的 Github 存储库):
Summary of updated files (based on your Github repo):
YouPod/background.htm
YouPod/popup.htm
(文档类型修复,评论建议占位符焦点)YouPod/js/background.js
YouPod/js/popup.js
YouPad/js/youtube-player-api-helper.js
新
这篇关于部署 Google Chrome 扩展程序;Adobe Flash Player 已停止可能不安全的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!