From 97561ac51ab0ef9f3fb5b0b5d7ff395e6be50d2b Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 20 Apr 2012 20:40:53 +0000 Subject: [PATCH] Add ability to directly retrieve plugin information (issue #575). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@600 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- cef1/cef.gyp | 1 + cef1/cef_paths.gypi | 6 + cef1/include/capi/cef_web_plugin_capi.h | 110 ++++++++++++++++++ cef1/include/cef_web_plugin.h | 97 +++++++++++++++ cef1/libcef/web_plugin_impl.cc | 105 +++++++++++++++++ .../cpptoc/web_plugin_info_cpptoc.cc | 94 +++++++++++++++ .../cpptoc/web_plugin_info_cpptoc.h | 37 ++++++ .../ctocpp/web_plugin_info_ctocpp.cc | 83 +++++++++++++ .../ctocpp/web_plugin_info_ctocpp.h | 45 +++++++ cef1/libcef_dll/libcef_dll.cc | 42 +++++++ cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc | 42 +++++++ cef1/tests/cefclient/cefclient.cpp | 51 ++++++++ cef1/tests/cefclient/cefclient.h | 1 + cef1/tests/cefclient/cefclient.rc | 1 + cef1/tests/cefclient/cefclient_gtk.cpp | 10 ++ cef1/tests/cefclient/cefclient_mac.mm | 9 ++ cef1/tests/cefclient/cefclient_win.cpp | 4 + cef1/tests/cefclient/resource.h | 1 + 18 files changed, 739 insertions(+) create mode 100644 cef1/include/capi/cef_web_plugin_capi.h create mode 100644 cef1/include/cef_web_plugin.h create mode 100644 cef1/libcef/web_plugin_impl.cc create mode 100644 cef1/libcef_dll/cpptoc/web_plugin_info_cpptoc.cc create mode 100644 cef1/libcef_dll/cpptoc/web_plugin_info_cpptoc.h create mode 100644 cef1/libcef_dll/ctocpp/web_plugin_info_ctocpp.cc create mode 100644 cef1/libcef_dll/ctocpp/web_plugin_info_ctocpp.h diff --git a/cef1/cef.gyp b/cef1/cef.gyp index 6312bebb2..ab0db5332 100644 --- a/cef1/cef.gyp +++ b/cef1/cef.gyp @@ -769,6 +769,7 @@ 'libcef/url_impl.cc', 'libcef/v8_impl.cc', 'libcef/v8_impl.h', + 'libcef/web_plugin_impl.cc', 'libcef/web_urlrequest_impl.cc', 'libcef/web_urlrequest_impl.h', 'libcef/webview_host.cc', diff --git a/cef1/cef_paths.gypi b/cef1/cef_paths.gypi index 5c9075fdd..13b2f1ad7 100644 --- a/cef1/cef_paths.gypi +++ b/cef1/cef_paths.gypi @@ -47,6 +47,7 @@ 'include/cef_url.h', 'include/cef_v8.h', 'include/cef_v8context_handler.h', + 'include/cef_web_plugin.h', 'include/cef_web_urlrequest.h', 'include/cef_xml_reader.h', 'include/cef_zip_reader.h', @@ -87,6 +88,7 @@ 'include/capi/cef_url_capi.h', 'include/capi/cef_v8_capi.h', 'include/capi/cef_v8context_handler_capi.h', + 'include/capi/cef_web_plugin_capi.h', 'include/capi/cef_web_urlrequest_capi.h', 'include/capi/cef_xml_reader_capi.h', 'include/capi/cef_zip_reader_capi.h', @@ -188,6 +190,8 @@ 'libcef_dll/ctocpp/v8handler_ctocpp.h', 'libcef_dll/cpptoc/v8value_cpptoc.cc', 'libcef_dll/cpptoc/v8value_cpptoc.h', + 'libcef_dll/cpptoc/web_plugin_info_cpptoc.cc', + 'libcef_dll/cpptoc/web_plugin_info_cpptoc.h', 'libcef_dll/cpptoc/web_urlrequest_cpptoc.cc', 'libcef_dll/cpptoc/web_urlrequest_cpptoc.h', 'libcef_dll/ctocpp/web_urlrequest_client_ctocpp.cc', @@ -296,6 +300,8 @@ 'libcef_dll/cpptoc/v8handler_cpptoc.h', 'libcef_dll/ctocpp/v8value_ctocpp.cc', 'libcef_dll/ctocpp/v8value_ctocpp.h', + 'libcef_dll/ctocpp/web_plugin_info_ctocpp.cc', + 'libcef_dll/ctocpp/web_plugin_info_ctocpp.h', 'libcef_dll/ctocpp/web_urlrequest_ctocpp.cc', 'libcef_dll/ctocpp/web_urlrequest_ctocpp.h', 'libcef_dll/cpptoc/web_urlrequest_client_cpptoc.cc', diff --git a/cef1/include/capi/cef_web_plugin_capi.h b/cef1/include/capi/cef_web_plugin_capi.h new file mode 100644 index 000000000..d5aab64bd --- /dev/null +++ b/cef1/include/capi/cef_web_plugin_capi.h @@ -0,0 +1,110 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#ifndef CEF_INCLUDE_CAPI_CEF_WEB_PLUGIN_CAPI_H_ +#define CEF_INCLUDE_CAPI_CEF_WEB_PLUGIN_CAPI_H_ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "include/capi/cef_base_capi.h" + + +/// +// Returns the number of installed web plugins. This function must be called on +// the UI thread. +/// +CEF_EXPORT size_t cef_get_web_plugin_count(); + +/// +// Returns information for web plugin at the specified zero-based index. This +// function must be called on the UI thread. +/// +CEF_EXPORT struct _cef_web_plugin_info_t* cef_get_web_plugin_info(int index); + +/// +// Returns information for web plugin with the specified name. This function +// must be called on the UI thread. +/// +CEF_EXPORT struct _cef_web_plugin_info_t* cef_get_web_plugin_info_byname( + const cef_string_t* name); + +/// +// Information about a specific web plugin. +/// +typedef struct _cef_web_plugin_info_t { + /// + // Base structure. + /// + cef_base_t base; + + /// + // Returns the plugin name (i.e. Flash). + /// + // The resulting string must be freed by calling cef_string_userfree_free(). + cef_string_userfree_t (CEF_CALLBACK *get_name)( + struct _cef_web_plugin_info_t* self); + + /// + // Returns the plugin file path (DLL/bundle/library). + /// + // The resulting string must be freed by calling cef_string_userfree_free(). + cef_string_userfree_t (CEF_CALLBACK *get_path)( + struct _cef_web_plugin_info_t* self); + + /// + // Returns the version of the plugin (may be OS-specific). + /// + // The resulting string must be freed by calling cef_string_userfree_free(). + cef_string_userfree_t (CEF_CALLBACK *get_version)( + struct _cef_web_plugin_info_t* self); + + /// + // Returns a description of the plugin from the version information. + /// + // The resulting string must be freed by calling cef_string_userfree_free(). + cef_string_userfree_t (CEF_CALLBACK *get_description)( + struct _cef_web_plugin_info_t* self); +} cef_web_plugin_info_t; + + +#ifdef __cplusplus +} +#endif + +#endif // CEF_INCLUDE_CAPI_CEF_WEB_PLUGIN_CAPI_H_ diff --git a/cef1/include/cef_web_plugin.h b/cef1/include/cef_web_plugin.h new file mode 100644 index 000000000..e00b2349b --- /dev/null +++ b/cef1/include/cef_web_plugin.h @@ -0,0 +1,97 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// The contents of this file must follow a specific format in order to +// support the CEF translator tool. See the translator.README.txt file in the +// tools directory for more information. +// + +#ifndef CEF_INCLUDE_CEF_WEB_PLUGIN_H_ +#define CEF_INCLUDE_CEF_WEB_PLUGIN_H_ + +#include "include/cef_base.h" + +class CefWebPluginInfo; + +/// +// Returns the number of installed web plugins. This method must be called on +// the UI thread. +/// +/*--cef()--*/ +size_t CefGetWebPluginCount(); + +/// +// Returns information for web plugin at the specified zero-based index. This +// method must be called on the UI thread. +/// +/*--cef()--*/ +CefRefPtr CefGetWebPluginInfo(int index); + +/// +// Returns information for web plugin with the specified name. This method must +// be called on the UI thread. +/// +/*--cef(capi_name=cef_get_web_plugin_info_byname)--*/ +CefRefPtr CefGetWebPluginInfo(const CefString& name); + + +/// +// Information about a specific web plugin. +/// +/*--cef(source=library)--*/ +class CefWebPluginInfo : public virtual CefBase { + public: + /// + // Returns the plugin name (i.e. Flash). + /// + /*--cef()--*/ + virtual CefString GetName() =0; + + /// + // Returns the plugin file path (DLL/bundle/library). + /// + /*--cef()--*/ + virtual CefString GetPath() =0; + + /// + // Returns the version of the plugin (may be OS-specific). + /// + /*--cef()--*/ + virtual CefString GetVersion() =0; + + /// + // Returns a description of the plugin from the version information. + /// + /*--cef()--*/ + virtual CefString GetDescription() =0; +}; + +#endif // CEF_INCLUDE_CEF_WEB_PLUGIN_H_ diff --git a/cef1/libcef/web_plugin_impl.cc b/cef1/libcef/web_plugin_impl.cc new file mode 100644 index 000000000..1cb0b1415 --- /dev/null +++ b/cef1/libcef/web_plugin_impl.cc @@ -0,0 +1,105 @@ +// 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. + +#include "include/cef_web_plugin.h" +#include "libcef/cef_context.h" +#include "libcef/cef_thread.h" + +#include "base/file_path.h" +#include "base/string_util.h" +#include "webkit/plugins/npapi/plugin_list.h" + +namespace { + +class CefWebPluginInfoImpl : public CefWebPluginInfo { + public: + explicit CefWebPluginInfoImpl(const webkit::WebPluginInfo& plugin_info) + : plugin_info_(plugin_info) { + } + + virtual CefString GetName() OVERRIDE { + return plugin_info_.name; + } + + virtual CefString GetPath() OVERRIDE { + return plugin_info_.path.value(); + } + + virtual CefString GetVersion() OVERRIDE { + return plugin_info_.version; + } + + virtual CefString GetDescription() OVERRIDE { + return plugin_info_.desc; + } + + private: + webkit::WebPluginInfo plugin_info_; + + IMPLEMENT_REFCOUNTING(CefWebPluginInfoImpl); +}; + +} // namespace + +size_t CefGetWebPluginCount() { + if (!CONTEXT_STATE_VALID()) { + NOTREACHED() << "context not valid"; + return 0; + } + + if (!CefThread::CurrentlyOn(CefThread::UI)) { + NOTREACHED() << "called on invalid thread"; + return 0; + } + + std::vector plugins; + webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); + return plugins.size(); +} + +CefRefPtr CefGetWebPluginInfo(int index) { + if (!CONTEXT_STATE_VALID()) { + NOTREACHED() << "context not valid"; + return 0; + } + + if (!CefThread::CurrentlyOn(CefThread::UI)) { + NOTREACHED() << "called on invalid thread"; + return 0; + } + + std::vector plugins; + webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); + + if (index < 0 || index >= static_cast(plugins.size())) + return NULL; + + return new CefWebPluginInfoImpl(plugins[index]); +} + +CefRefPtr CefGetWebPluginInfo(const CefString& name) { + if (!CONTEXT_STATE_VALID()) { + NOTREACHED() << "context not valid"; + return 0; + } + + if (!CefThread::CurrentlyOn(CefThread::UI)) { + NOTREACHED() << "called on invalid thread"; + return 0; + } + + std::vector plugins; + webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); + + std::string nameStr = name; + StringToLowerASCII(&nameStr); + + std::vector::const_iterator it = plugins.begin(); + for (; it != plugins.end(); ++it) { + if (LowerCaseEqualsASCII(it->name, nameStr.c_str())) + return new CefWebPluginInfoImpl(*it); + } + + return NULL; +} diff --git a/cef1/libcef_dll/cpptoc/web_plugin_info_cpptoc.cc b/cef1/libcef_dll/cpptoc/web_plugin_info_cpptoc.cc new file mode 100644 index 000000000..46caf75f6 --- /dev/null +++ b/cef1/libcef_dll/cpptoc/web_plugin_info_cpptoc.cc @@ -0,0 +1,94 @@ +// 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. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/cpptoc/web_plugin_info_cpptoc.h" + + +// MEMBER FUNCTIONS - Body may be edited by hand. + +cef_string_userfree_t CEF_CALLBACK web_plugin_info_get_name( + struct _cef_web_plugin_info_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefString _retval = CefWebPluginInfoCppToC::Get(self)->GetName(); + + // Return type: string + return _retval.DetachToUserFree(); +} + +cef_string_userfree_t CEF_CALLBACK web_plugin_info_get_path( + struct _cef_web_plugin_info_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefString _retval = CefWebPluginInfoCppToC::Get(self)->GetPath(); + + // Return type: string + return _retval.DetachToUserFree(); +} + +cef_string_userfree_t CEF_CALLBACK web_plugin_info_get_version( + struct _cef_web_plugin_info_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefString _retval = CefWebPluginInfoCppToC::Get(self)->GetVersion(); + + // Return type: string + return _retval.DetachToUserFree(); +} + +cef_string_userfree_t CEF_CALLBACK web_plugin_info_get_description( + struct _cef_web_plugin_info_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefString _retval = CefWebPluginInfoCppToC::Get(self)->GetDescription(); + + // Return type: string + return _retval.DetachToUserFree(); +} + + +// CONSTRUCTOR - Do not edit by hand. + +CefWebPluginInfoCppToC::CefWebPluginInfoCppToC(CefWebPluginInfo* cls) + : CefCppToC(cls) { + struct_.struct_.get_name = web_plugin_info_get_name; + struct_.struct_.get_path = web_plugin_info_get_path; + struct_.struct_.get_version = web_plugin_info_get_version; + struct_.struct_.get_description = web_plugin_info_get_description; +} + +#ifndef NDEBUG +template<> long CefCppToC::DebugObjCt = 0; +#endif + diff --git a/cef1/libcef_dll/cpptoc/web_plugin_info_cpptoc.h b/cef1/libcef_dll/cpptoc/web_plugin_info_cpptoc.h new file mode 100644 index 000000000..9ede6a894 --- /dev/null +++ b/cef1/libcef_dll/cpptoc/web_plugin_info_cpptoc.h @@ -0,0 +1,37 @@ +// 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. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CPPTOC_WEB_PLUGIN_INFO_CPPTOC_H_ +#define CEF_LIBCEF_DLL_CPPTOC_WEB_PLUGIN_INFO_CPPTOC_H_ +#pragma once + +#ifndef BUILDING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed DLL-side only") +#else // BUILDING_CEF_SHARED + +#include "include/cef_web_plugin.h" +#include "include/capi/cef_web_plugin_capi.h" +#include "libcef_dll/cpptoc/cpptoc.h" + +// Wrap a C++ class with a C structure. +// This class may be instantiated and accessed DLL-side only. +class CefWebPluginInfoCppToC + : public CefCppToC { + public: + explicit CefWebPluginInfoCppToC(CefWebPluginInfo* cls); + virtual ~CefWebPluginInfoCppToC() {} +}; + +#endif // BUILDING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CPPTOC_WEB_PLUGIN_INFO_CPPTOC_H_ + diff --git a/cef1/libcef_dll/ctocpp/web_plugin_info_ctocpp.cc b/cef1/libcef_dll/ctocpp/web_plugin_info_ctocpp.cc new file mode 100644 index 000000000..4c814e969 --- /dev/null +++ b/cef1/libcef_dll/ctocpp/web_plugin_info_ctocpp.cc @@ -0,0 +1,83 @@ +// 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. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/ctocpp/web_plugin_info_ctocpp.h" + + +// VIRTUAL METHODS - Body may be edited by hand. + +CefString CefWebPluginInfoCToCpp::GetName() { + if (CEF_MEMBER_MISSING(struct_, get_name)) + return CefString(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_string_userfree_t _retval = struct_->get_name(struct_); + + // Return type: string + CefString _retvalStr; + _retvalStr.AttachToUserFree(_retval); + return _retvalStr; +} + +CefString CefWebPluginInfoCToCpp::GetPath() { + if (CEF_MEMBER_MISSING(struct_, get_path)) + return CefString(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_string_userfree_t _retval = struct_->get_path(struct_); + + // Return type: string + CefString _retvalStr; + _retvalStr.AttachToUserFree(_retval); + return _retvalStr; +} + +CefString CefWebPluginInfoCToCpp::GetVersion() { + if (CEF_MEMBER_MISSING(struct_, get_version)) + return CefString(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_string_userfree_t _retval = struct_->get_version(struct_); + + // Return type: string + CefString _retvalStr; + _retvalStr.AttachToUserFree(_retval); + return _retvalStr; +} + +CefString CefWebPluginInfoCToCpp::GetDescription() { + if (CEF_MEMBER_MISSING(struct_, get_description)) + return CefString(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_string_userfree_t _retval = struct_->get_description(struct_); + + // Return type: string + CefString _retvalStr; + _retvalStr.AttachToUserFree(_retval); + return _retvalStr; +} + + +#ifndef NDEBUG +template<> long CefCToCpp::DebugObjCt = 0; +#endif + diff --git a/cef1/libcef_dll/ctocpp/web_plugin_info_ctocpp.h b/cef1/libcef_dll/ctocpp/web_plugin_info_ctocpp.h new file mode 100644 index 000000000..b8bd1cbf0 --- /dev/null +++ b/cef1/libcef_dll/ctocpp/web_plugin_info_ctocpp.h @@ -0,0 +1,45 @@ +// 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. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CTOCPP_WEB_PLUGIN_INFO_CTOCPP_H_ +#define CEF_LIBCEF_DLL_CTOCPP_WEB_PLUGIN_INFO_CTOCPP_H_ +#pragma once + +#ifndef USING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed wrapper-side only") +#else // USING_CEF_SHARED + +#include "include/cef_web_plugin.h" +#include "include/capi/cef_web_plugin_capi.h" +#include "libcef_dll/ctocpp/ctocpp.h" + +// Wrap a C structure with a C++ class. +// This class may be instantiated and accessed wrapper-side only. +class CefWebPluginInfoCToCpp + : public CefCToCpp { + public: + explicit CefWebPluginInfoCToCpp(cef_web_plugin_info_t* str) + : CefCToCpp(str) {} + virtual ~CefWebPluginInfoCToCpp() {} + + // CefWebPluginInfo methods + virtual CefString GetName() OVERRIDE; + virtual CefString GetPath() OVERRIDE; + virtual CefString GetVersion() OVERRIDE; + virtual CefString GetDescription() OVERRIDE; +}; + +#endif // USING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CTOCPP_WEB_PLUGIN_INFO_CTOCPP_H_ + diff --git a/cef1/libcef_dll/libcef_dll.cc b/cef1/libcef_dll/libcef_dll.cc index 4052ad84a..0089d5c64 100644 --- a/cef1/libcef_dll/libcef_dll.cc +++ b/cef1/libcef_dll/libcef_dll.cc @@ -24,6 +24,8 @@ #include "include/capi/cef_url_capi.h" #include "include/cef_v8.h" #include "include/capi/cef_v8_capi.h" +#include "include/cef_web_plugin.h" +#include "include/capi/cef_web_plugin_capi.h" #include "libcef_dll/cpptoc/browser_cpptoc.h" #include "libcef_dll/cpptoc/cookie_manager_cpptoc.h" #include "libcef_dll/cpptoc/domdocument_cpptoc.h" @@ -41,6 +43,7 @@ #include "libcef_dll/cpptoc/v8context_cpptoc.h" #include "libcef_dll/cpptoc/v8exception_cpptoc.h" #include "libcef_dll/cpptoc/v8value_cpptoc.h" +#include "libcef_dll/cpptoc/web_plugin_info_cpptoc.h" #include "libcef_dll/cpptoc/web_urlrequest_cpptoc.h" #include "libcef_dll/cpptoc/xml_reader_cpptoc.h" #include "libcef_dll/cpptoc/zip_reader_cpptoc.h" @@ -156,6 +159,7 @@ CEF_EXPORT void cef_shutdown() { DCHECK_EQ(CefV8ExceptionCppToC::DebugObjCt, 0); DCHECK_EQ(CefV8HandlerCToCpp::DebugObjCt, 0); DCHECK_EQ(CefV8ValueCppToC::DebugObjCt, 0); + DCHECK_EQ(CefWebPluginInfoCppToC::DebugObjCt, 0); DCHECK_EQ(CefWebURLRequestClientCToCpp::DebugObjCt, 0); DCHECK_EQ(CefWebURLRequestCppToC::DebugObjCt, 0); DCHECK_EQ(CefWriteHandlerCToCpp::DebugObjCt, 0); @@ -518,3 +522,41 @@ CEF_EXPORT int cef_register_extension(const cef_string_t* extension_name, return _retval; } +CEF_EXPORT size_t cef_get_web_plugin_count() { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + size_t _retval = CefGetWebPluginCount(); + + // Return type: simple + return _retval; +} + +CEF_EXPORT struct _cef_web_plugin_info_t* cef_get_web_plugin_info(int index) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + CefRefPtr _retval = CefGetWebPluginInfo( + index); + + // Return type: refptr_same + return CefWebPluginInfoCppToC::Wrap(_retval); +} + +CEF_EXPORT struct _cef_web_plugin_info_t* cef_get_web_plugin_info_byname( + const cef_string_t* name) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: name; type: string_byref_const + DCHECK(name); + if (!name) + return NULL; + + // Execute + CefRefPtr _retval = CefGetWebPluginInfo( + CefString(name)); + + // Return type: refptr_same + return CefWebPluginInfoCppToC::Wrap(_retval); +} + diff --git a/cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc b/cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc index f275c1d8b..2b6d63da5 100644 --- a/cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc +++ b/cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc @@ -24,6 +24,8 @@ #include "include/capi/cef_url_capi.h" #include "include/cef_v8.h" #include "include/capi/cef_v8_capi.h" +#include "include/cef_web_plugin.h" +#include "include/capi/cef_web_plugin_capi.h" #include "include/cef_version.h" #include "libcef_dll/cpptoc/app_cpptoc.h" #include "libcef_dll/cpptoc/content_filter_cpptoc.h" @@ -73,6 +75,7 @@ #include "libcef_dll/ctocpp/v8context_ctocpp.h" #include "libcef_dll/ctocpp/v8exception_ctocpp.h" #include "libcef_dll/ctocpp/v8value_ctocpp.h" +#include "libcef_dll/ctocpp/web_plugin_info_ctocpp.h" #include "libcef_dll/ctocpp/web_urlrequest_ctocpp.h" #include "libcef_dll/ctocpp/xml_reader_ctocpp.h" #include "libcef_dll/ctocpp/zip_reader_ctocpp.h" @@ -158,6 +161,7 @@ CEF_GLOBAL void CefShutdown() { DCHECK_EQ(CefV8ExceptionCToCpp::DebugObjCt, 0); DCHECK_EQ(CefV8HandlerCppToC::DebugObjCt, 0); DCHECK_EQ(CefV8ValueCToCpp::DebugObjCt, 0); + DCHECK_EQ(CefWebPluginInfoCToCpp::DebugObjCt, 0); DCHECK_EQ(CefWebURLRequestCToCpp::DebugObjCt, 0); DCHECK_EQ(CefWebURLRequestClientCppToC::DebugObjCt, 0); DCHECK_EQ(CefWriteHandlerCppToC::DebugObjCt, 0); @@ -485,3 +489,41 @@ CEF_GLOBAL bool CefRegisterExtension(const CefString& extension_name, return _retval?true:false; } +CEF_GLOBAL size_t CefGetWebPluginCount() { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + size_t _retval = cef_get_web_plugin_count(); + + // Return type: simple + return _retval; +} + +CEF_GLOBAL CefRefPtr CefGetWebPluginInfo(int index) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_web_plugin_info_t* _retval = cef_get_web_plugin_info( + index); + + // Return type: refptr_same + return CefWebPluginInfoCToCpp::Wrap(_retval); +} + +CEF_GLOBAL CefRefPtr CefGetWebPluginInfo( + const CefString& name) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: name; type: string_byref_const + DCHECK(!name.empty()); + if (name.empty()) + return NULL; + + // Execute + cef_web_plugin_info_t* _retval = cef_get_web_plugin_info_byname( + name.GetStruct()); + + // Return type: refptr_same + return CefWebPluginInfoCToCpp::Wrap(_retval); +} + diff --git a/cef1/tests/cefclient/cefclient.cpp b/cef1/tests/cefclient/cefclient.cpp index 7a953066a..617852228 100644 --- a/cef1/tests/cefclient/cefclient.cpp +++ b/cef1/tests/cefclient/cefclient.cpp @@ -12,6 +12,7 @@ #include "include/cef_command_line.h" #include "include/cef_frame.h" #include "include/cef_runnable.h" +#include "include/cef_web_plugin.h" #include "include/cef_web_urlrequest.h" #include "cefclient/cefclient_switches.h" #include "cefclient/client_handler.h" @@ -65,6 +66,46 @@ void UIT_InvokeScript(CefRefPtr browser) { } } +void UIT_RunPluginInfoTest(CefRefPtr browser) { + std::string html = "Plugin Info Test"; + + // Find the flash plugin first to test that get by name works. + std::string flash_name; + CefRefPtr info = CefGetWebPluginInfo("Shockwave Flash"); + if (info.get()) { + flash_name = info->GetName(); + html += "\nFlash is installed!" + "
Name: " + flash_name + + "\n
Description: " + info->GetDescription().ToString() + + "\n
Version: " + info->GetVersion().ToString() + + "\n
Path: " + info->GetPath().ToString(); + } + + if (!flash_name.empty()) { + html += "\n

Other installed plugins:"; + } else { + html += "\nInstalled plugins:"; + } + + // Display all other plugins. + size_t count = CefGetWebPluginCount(); + for (size_t i = 0; i < count; ++i) { + CefRefPtr info = CefGetWebPluginInfo(i); + ASSERT(info.get()); + if (!flash_name.empty() && info->GetName() == flash_name) + continue; + + html += "\n

Name: " + info->GetName().ToString() + + "\n
Description: " + info->GetDescription().ToString() + + "\n
Version: " + info->GetVersion().ToString() + + "\n
Path: " + info->GetPath().ToString(); + } + + html += ""; + + browser->GetMainFrame()->LoadString(html, "http://tests/plugin_info"); +} + // Return the int representation of the specified string. int GetIntValue(const CefString& str) { if (str.empty()) @@ -599,3 +640,13 @@ void RunDragDropTest(CefRefPtr browser) { void RunModalDialogTest(CefRefPtr browser) { browser->GetMainFrame()->LoadURL("http://tests/modalmain"); } + +void RunPluginInfoTest(CefRefPtr browser) { + if (CefCurrentlyOn(TID_UI)) { + UIT_RunPluginInfoTest(browser); + } else { + // Execute on the UI thread. + CefPostTask(TID_UI, + NewCefRunnableFunction(&UIT_RunPluginInfoTest, browser)); + } +} diff --git a/cef1/tests/cefclient/cefclient.h b/cef1/tests/cefclient/cefclient.h index f091ca9e8..27ba93576 100644 --- a/cef1/tests/cefclient/cefclient.h +++ b/cef1/tests/cefclient/cefclient.h @@ -51,6 +51,7 @@ void RunWebURLRequestTest(CefRefPtr browser); void RunDOMAccessTest(CefRefPtr browser); void RunDragDropTest(CefRefPtr browser); void RunModalDialogTest(CefRefPtr browser); +void RunPluginInfoTest(CefRefPtr browser); #if defined(OS_WIN) void RunTransparentPopupTest(CefRefPtr browser); diff --git a/cef1/tests/cefclient/cefclient.rc b/cef1/tests/cefclient/cefclient.rc index a058a5686..277ca44b7 100644 --- a/cef1/tests/cefclient/cefclient.rc +++ b/cef1/tests/cefclient/cefclient.rc @@ -79,6 +79,7 @@ BEGIN MENUITEM "JavaScript Execute", ID_TESTS_JAVASCRIPT_EXECUTE MENUITEM "JavaScript Invoke", ID_TESTS_JAVASCRIPT_INVOKE MENUITEM "Plugin", ID_TESTS_PLUGIN + MENUITEM "Plugin Info", ID_TESTS_PLUGIN_INFO MENUITEM "Popup Window", ID_TESTS_POPUP MENUITEM "Transparent Popup Window", ID_TESTS_TRANSPARENT_POPUP MENUITEM "Request", ID_TESTS_REQUEST diff --git a/cef1/tests/cefclient/cefclient_gtk.cpp b/cef1/tests/cefclient/cefclient_gtk.cpp index 5b0afa081..853e2c27a 100644 --- a/cef1/tests/cefclient/cefclient_gtk.cpp +++ b/cef1/tests/cefclient/cefclient_gtk.cpp @@ -206,6 +206,14 @@ gboolean ShowDevtoolsActivated(GtkWidget* widget) { return FALSE; // Don't stop this message. } +// Callback for Debug > Plugin Info... menu item. +gboolean PluginInfoActivated(GtkWidget* widget) { + if (g_handler.get() && g_handler->GetBrowserHwnd()) + RunPluginInfoTest(g_handler->GetBrowser()); + + return FALSE; // Don't stop this message. +} + // Callback for when you click the back button. void BackButtonClicked(GtkButton* button) { if (g_handler.get() && g_handler->GetBrowserHwnd()) @@ -301,6 +309,8 @@ GtkWidget* CreateMenuBar() { G_CALLBACK(DragDropActivated)); AddMenuEntry(debug_menu, "Show DevTools", G_CALLBACK(ShowDevtoolsActivated)); + AddMenuEntry(debug_menu, "Plugin Info", + G_CALLBACK(PluginInfoActivated)); return menu_bar; } diff --git a/cef1/tests/cefclient/cefclient_mac.mm b/cef1/tests/cefclient/cefclient_mac.mm index 1236aee1d..3b29bb1a8 100644 --- a/cef1/tests/cefclient/cefclient_mac.mm +++ b/cef1/tests/cefclient/cefclient_mac.mm @@ -211,6 +211,7 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) { - (IBAction)testZoomReset:(id)sender; - (IBAction)testDevToolsShow:(id)sender; - (IBAction)testDevToolsClose:(id)sender; +- (IBAction)testPluginInfo:(id)sender; @end @implementation ClientAppDelegate @@ -301,6 +302,9 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) { [testMenu addItemWithTitle:@"Close DevTools" action:@selector(testDevToolsClose:) keyEquivalent:@""]; + [testMenu addItemWithTitle:@"Plugin Info" + action:@selector(testPluginInfo:) + keyEquivalent:@""]; [testItem setSubmenu:testMenu]; [menubar addItem:testItem]; @@ -522,6 +526,11 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) { } } +- (IBAction)testPluginInfo:(id)sender { + if (g_handler.get() && g_handler->GetBrowserHwnd()) + RunPluginInfoTest(g_handler->GetBrowser()); +} + // Sent by the default notification center immediately before the application // terminates. - (void)applicationWillTerminate:(NSNotification *)aNotification { diff --git a/cef1/tests/cefclient/cefclient_win.cpp b/cef1/tests/cefclient/cefclient_win.cpp index 10b3a359f..3f3d89b32 100644 --- a/cef1/tests/cefclient/cefclient_win.cpp +++ b/cef1/tests/cefclient/cefclient_win.cpp @@ -464,6 +464,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, if (browser.get()) RunPluginTest(browser); return 0; + case ID_TESTS_PLUGIN_INFO: // Test plugin info + if (browser.get()) + RunPluginInfoTest(browser); + return 0; case ID_TESTS_POPUP: // Test a popup window if (browser.get()) RunPopupTest(browser); diff --git a/cef1/tests/cefclient/resource.h b/cef1/tests/cefclient/resource.h index 7ca2da3bd..725f12b88 100644 --- a/cef1/tests/cefclient/resource.h +++ b/cef1/tests/cefclient/resource.h @@ -57,6 +57,7 @@ #define ID_TESTS_TRANSPARENT_OSRAPP 32797 #define ID_TESTS_JAVASCRIPT_INVOKE 32798 #define ID_TESTS_GETIMAGE 32799 +#define ID_TESTS_PLUGIN_INFO 32800 #define IDC_STATIC -1 #define IDS_LOGO 1000 #define IDS_UIPLUGIN 1001