Android 7 iframe视频'拒绝显示'在WebView中

时间:2017-03-16 10:06:15

标签: android video iframe twitter webview

我有和应用程序,它显示来自其他来源的html内容。此内容可能包含iframe嵌入的视频。对于Twitter视频的特殊情况,行为不同,运行后视频仍为空白。

logcat显示消息:

Refused to display  'videoUrlHere' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors *".", source: about:blank (0) 

示例网址为:https://twitter.com/i/videos/tweet/840948416742117377?embed_source=clientlib&player_id=0&rpc_init=1&language_code=en

有趣的是,这种方法适用于android 5及更低版本。

加载内容

mWebView.loadDataWithBaseURL("file:///android_asset/", mHtmlSource.toString(), "text/html", "utf-8", null);

WebView的初始化:

mWebView.setWebViewClient(new MyWebViewClient());
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.addJavascriptInterface(new InjectedAppObject(), "InjectedAppObject");
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
webSettings.setLoadsImagesAutomatically(true);

标题添加到html:

<html lang=\"cs\" dir=\"ltr\">
<head>
<meta charset=\"utf-8\">
<meta name=\"keywords\" content=\"\">
<meta name=\"description\" content=\"\">
<meta http-equiv=\"Content-Security-Policy\" content=\"default-src * data: \'unsafe-inline\' \'unsafe-eval\'; frame-ancestors *; \">
<meta name=\"robots\" content=\"index,follow\">
  <title>App title</title>
  <link href=\"file:///android_asset/html/css/style.css\" rel=\"stylesheet\">
  <script src=\"file:///android_asset/html/js/jquery.min.js\"></script>
  <script src=\"file:///android_asset/html/js/app.js\"></script>
  <script src=\"file:///android_asset/html/js/disposable-iframe.min.js\"></script>
<script src=\"file:///android_asset/html/js/iframe.js\"></script>
</head>

0 个答案:

没有答案