2012-04-27 21:12:01 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2012-09-28 22:14:02 +02:00
|
|
|
#include "libcef/browser/web_plugin_impl.h"
|
2016-10-14 17:56:41 +02:00
|
|
|
|
2012-04-27 21:12:01 +02:00
|
|
|
#include "libcef/browser/context.h"
|
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
|
|
|
#include "base/bind.h"
|
2013-02-27 18:56:03 +01:00
|
|
|
#include "base/files/file_path.h"
|
2012-04-27 21:12:01 +02:00
|
|
|
#include "content/browser/plugin_service_impl.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void PluginsCallbackImpl(
|
|
|
|
CefRefPtr<CefWebPluginInfoVisitor> visitor,
|
2013-07-24 22:15:18 +02:00
|
|
|
const std::vector<content::WebPluginInfo>& all_plugins) {
|
2012-04-27 21:12:01 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
int total = static_cast<int>(all_plugins.size());
|
|
|
|
|
2013-07-24 22:15:18 +02:00
|
|
|
std::vector<content::WebPluginInfo>::const_iterator it = all_plugins.begin();
|
2012-04-27 21:12:01 +02:00
|
|
|
for (; it != all_plugins.end(); ++it, ++count) {
|
|
|
|
CefRefPtr<CefWebPluginInfoImpl> info(new CefWebPluginInfoImpl(*it));
|
|
|
|
if (!visitor->Visit(info.get(), count, total))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2012-09-28 22:14:02 +02:00
|
|
|
// CefWebPluginInfoImpl
|
|
|
|
|
|
|
|
CefWebPluginInfoImpl::CefWebPluginInfoImpl(
|
2013-07-24 22:15:18 +02:00
|
|
|
const content::WebPluginInfo& plugin_info)
|
2017-05-17 11:29:28 +02:00
|
|
|
: plugin_info_(plugin_info) {}
|
2012-09-28 22:14:02 +02:00
|
|
|
|
|
|
|
CefString CefWebPluginInfoImpl::GetName() {
|
|
|
|
return plugin_info_.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefWebPluginInfoImpl::GetPath() {
|
|
|
|
return plugin_info_.path.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefWebPluginInfoImpl::GetVersion() {
|
|
|
|
return plugin_info_.version;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefWebPluginInfoImpl::GetDescription() {
|
|
|
|
return plugin_info_.desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Global functions.
|
|
|
|
|
2012-04-27 21:12:01 +02:00
|
|
|
void CefVisitWebPluginInfo(CefRefPtr<CefWebPluginInfoVisitor> visitor) {
|
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-28 22:14:02 +02:00
|
|
|
if (!visitor.get()) {
|
|
|
|
NOTREACHED() << "invalid parameter";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-27 21:12:01 +02:00
|
|
|
if (CEF_CURRENTLY_ON_UIT()) {
|
2012-11-05 21:18:20 +01:00
|
|
|
content::PluginServiceImpl::GetInstance()->GetPlugins(
|
2021-06-04 03:34:56 +02:00
|
|
|
base::BindOnce(PluginsCallbackImpl, visitor));
|
2012-04-27 21:12:01 +02:00
|
|
|
} else {
|
|
|
|
// Execute on the UI thread.
|
2021-06-04 03:34:56 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(CefVisitWebPluginInfo, visitor));
|
2012-04-27 21:12:01 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-28 22:14:02 +02:00
|
|
|
|
|
|
|
void CefRefreshWebPlugins() {
|
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No thread affinity.
|
2012-11-05 21:18:20 +01:00
|
|
|
content::PluginServiceImpl::GetInstance()->RefreshPlugins();
|
2012-09-28 22:14:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefUnregisterInternalWebPlugin(const CefString& path) {
|
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path.empty()) {
|
|
|
|
NOTREACHED() << "invalid parameter";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No thread affinity.
|
2012-11-05 21:18:20 +01:00
|
|
|
content::PluginServiceImpl::GetInstance()->UnregisterInternalPlugin(
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath(path));
|
2012-09-28 22:14:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRegisterWebPluginCrash(const CefString& path) {
|
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path.empty()) {
|
|
|
|
NOTREACHED() << "invalid parameter";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
2012-11-05 21:18:20 +01:00
|
|
|
content::PluginServiceImpl::GetInstance()->RegisterPluginCrash(
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath(path));
|
2012-09-28 22:14:02 +02:00
|
|
|
} else {
|
|
|
|
// Execute on the IO thread.
|
2021-06-04 03:34:56 +02:00
|
|
|
CEF_POST_TASK(CEF_IOT, base::BindOnce(CefRegisterWebPluginCrash, path));
|
2012-09-28 22:14:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefIsWebPluginUnstable(const CefString& path,
|
|
|
|
CefRefPtr<CefWebPluginUnstableCallback> callback) {
|
2012-09-28 22:14:02 +02:00
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path.empty() || !callback.get()) {
|
|
|
|
NOTREACHED() << "invalid parameter";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
callback->IsUnstable(
|
|
|
|
path, content::PluginServiceImpl::GetInstance()->IsPluginUnstable(
|
|
|
|
base::FilePath(path)));
|
2012-09-28 22:14:02 +02:00
|
|
|
} else {
|
|
|
|
// Execute on the IO thread.
|
2021-06-04 03:34:56 +02:00
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::BindOnce(CefIsWebPluginUnstable, path, callback));
|
2012-09-28 22:14:02 +02:00
|
|
|
}
|
|
|
|
}
|