2011-12-23 18:36:30 +01:00
|
|
|
// Copyright (c) 2011 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.
|
|
|
|
|
|
|
|
#include "include/cef_nplugin.h"
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/cef_context.h"
|
|
|
|
#include "libcef/cef_thread.h"
|
2011-12-23 18:36:30 +01:00
|
|
|
|
2012-02-17 15:51:20 +01:00
|
|
|
#include "base/bind.h"
|
2013-03-13 18:05:03 +01:00
|
|
|
#include "base/strings/string_split.h"
|
2011-12-23 18:36:30 +01:00
|
|
|
#include "base/utf_string_conversions.h"
|
|
|
|
#include "webkit/plugins/npapi/plugin_list.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void UIT_RegisterPlugin(CefPluginInfo* plugin_info) {
|
2011-12-23 18:36:30 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
webkit::WebPluginInfo info;
|
|
|
|
|
2013-02-26 00:44:37 +01:00
|
|
|
info.path = base::FilePath(CefString(&plugin_info->unique_name));
|
2011-12-23 18:36:30 +01:00
|
|
|
info.name = CefString(&plugin_info->display_name);
|
|
|
|
info.version = CefString(&plugin_info->version);
|
|
|
|
info.desc = CefString(&plugin_info->description);
|
|
|
|
|
|
|
|
typedef std::vector<std::string> VectorType;
|
|
|
|
VectorType mime_types, file_extensions, descriptions, file_extensions_parts;
|
|
|
|
base::SplitString(CefString(&plugin_info->mime_types), '|', &mime_types);
|
|
|
|
base::SplitString(CefString(&plugin_info->file_extensions), '|',
|
|
|
|
&file_extensions);
|
|
|
|
base::SplitString(CefString(&plugin_info->type_descriptions), '|',
|
|
|
|
&descriptions);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mime_types.size(); ++i) {
|
|
|
|
webkit::WebPluginMimeType mimeType;
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-12-23 18:36:30 +01:00
|
|
|
mimeType.mime_type = mime_types[i];
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-12-23 18:36:30 +01:00
|
|
|
if (file_extensions.size() > i) {
|
|
|
|
base::SplitString(file_extensions[i], ',', &file_extensions_parts);
|
|
|
|
VectorType::const_iterator it = file_extensions_parts.begin();
|
2012-01-10 00:46:23 +01:00
|
|
|
for (; it != file_extensions_parts.end(); ++it)
|
2011-12-23 18:36:30 +01:00
|
|
|
mimeType.file_extensions.push_back(*(it));
|
|
|
|
file_extensions_parts.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (descriptions.size() > i)
|
|
|
|
mimeType.description = UTF8ToUTF16(descriptions[i]);
|
|
|
|
|
|
|
|
info.mime_types.push_back(mimeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
webkit::npapi::PluginEntryPoints entry_points;
|
|
|
|
#if !defined(OS_POSIX) || defined(OS_MACOSX)
|
|
|
|
entry_points.np_getentrypoints = plugin_info->np_getentrypoints;
|
|
|
|
#endif
|
|
|
|
entry_points.np_initialize = plugin_info->np_initialize;
|
|
|
|
entry_points.np_shutdown = plugin_info->np_shutdown;
|
|
|
|
|
2012-02-17 15:51:20 +01:00
|
|
|
webkit::npapi::PluginList::Singleton()->RegisterInternalPluginWithEntryPoints(
|
|
|
|
info, true, entry_points);
|
2011-12-23 18:36:30 +01:00
|
|
|
|
|
|
|
delete plugin_info;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
} // namespace
|
2011-12-23 18:36:30 +01:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefRegisterPlugin(const CefPluginInfo& plugin_info) {
|
2011-12-23 18:36:30 +01:00
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
2012-02-17 15:51:20 +01:00
|
|
|
base::Bind(UIT_RegisterPlugin, new CefPluginInfo(plugin_info)));
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-12-23 18:36:30 +01:00
|
|
|
return true;
|
|
|
|
}
|