How to set/coding in CEF to allow flash on current page

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

How to set/coding in CEF to allow flash on current page

Postby QtHarry » Mon Aug 20, 2018 1:03 am

When I visited http://get.adobe.com/it/flashplayer/about/, the chrome displayed "Flash was blocked on this page", but I can set Flash to "Allow" by the information menu and let flash be played successfully.
At least in chrome flash can be set to allow manually, but how to do this in CEF? I visited the same url in cefclient or cefsimple app, the flash was blocked, how to set flash to allow? Thanks.
QtHarry
Newbie
 
Posts: 2
Joined: Sun Aug 19, 2018 10:04 pm

Re: How to set/coding in CEF to allow flash on current page

Postby magreenblatt » Mon Aug 20, 2018 10:45 am

If you are on Windows or macOS install the "Opera and Chromium PPAPI" version from https://get.adobe.com/flashplayer/otherversions/ and then run CEF with the `--enable-system-flash` command-line flag.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to set/coding in CEF to allow flash on current page

Postby QtHarry » Mon Aug 20, 2018 9:28 pm

Thanks magreenblatt.
I'ved installed ppapi flash plugin, for normal flash website, there is no problem, flash content can be played. But for http://get.adobe.com/it/flashplayer/about/, the flash is blocked.
I can see the difference between chrome and cef (cefclient or cefsimple app) is that, in chrome, flash can be set to allow through menu, but how to set it in cef?
QtHarry
Newbie
 
Posts: 2
Joined: Sun Aug 19, 2018 10:04 pm

Re: How to set/coding in CEF to allow flash on current page

Postby JimmyO » Mon Jan 07, 2019 2:51 pm

Hello,

i also have some trouble with blocked flash.
Any solution to enable the blocked flash in software or as commandline paramater for cefclient.exe.
Thanks
Jimmy
JimmyO
Newbie
 
Posts: 2
Joined: Mon Jan 07, 2019 2:46 pm

Re: How to set/coding in CEF to allow flash on current page

Postby magreenblatt » Mon Jan 07, 2019 2:58 pm

See CefRequestContextHandler::OnBeforePluginLoad documentation.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to set/coding in CEF to allow flash on current page

Postby JimmyO » Mon Jan 07, 2019 8:41 pm

Hello,

Where can i found then CefRequestContextHandler::OnBeforePluginLoad documentation ?

I've add a CefRequestContextHandler and overwrite the function OnBeforePluginLoad.
The function OnBeforePluginLoad is called, but
a) mime_type is only applicaton/pdf and no flash ?
b) and the default policy is ALLOWED.
But i don't see any flag for enable the plugin.

Please can you give me more information about this. I'm new in CEF.

Thanks
JimmyO
Newbie
 
Posts: 2
Joined: Mon Jan 07, 2019 2:46 pm

Re: How to set/coding in CEF to allow flash on current page

Postby ndesktop » Tue Jan 08, 2019 3:17 am

OnBeforePluginLoad is implemented by CefRequestContextHandler.
You need to derive a class from CefRequestContextHandler, and instantiate it in your client handler GetRequestContext.
Something like this:

// declaration in client_handler.h
Code: Select all
class ClientHandler
  : public CefClient
...
  , public CefRequestContextHandler
{
...
  critical_section_t _csSharedRequestContext; // protection for m_SharedRequestContext
  CefRefPtr<CefRequestContext> m_SharedRequestContext;
...
    public:
        CefRefPtr<CefRequestContext> GetRequestContext(
            ClientHandler* client_handler);
        void CloseRequestContext();
...
};


Browser creation:
Code: Select all
... function to create a CefBrowser
   return CefBrowserHost::CreateBrowser(
            info,
            static_cast<CefRefPtr<CefClient>>(m_Handler),
            url, settings,
            GetRequestContext( pClientHandler )  // <== here we create (the "de facto" singleton) context and pass client handler to our ClientRequestContextHandler implementation
        );


// client handler GetRequestContext implementation
Code: Select all
CefRefPtr<CefRequestContext> ClientHandler::GetRequestContext(
    ClientHandler* client_handler)
{
    DCHECK(CefCurrentlyOn(TID_UI));

...

    //  all browsers are sharing the same request context (for now)
    critical_section_lock_t lock(&_csSharedRequestContext);
    if(m_SharedRequestContext.get() == nullptr)
    {
        m_SharedRequestContext =
            CefRequestContext::CreateContext(
                CefRequestContext::GetGlobalContext(),
                new ClientRequestContextHandler(this)
            );
    }
    DCHECK(m_SharedRequestContext.get());
    return m_SharedRequestContext;
}

void ClientHandler::CloseRequestContext()  // call this on shutdown - lifetime it's up to you
{
    critical_section_lock_t lock(&_csSharedRequestContext);
    m_SharedRequestContext = nullptr;
}


ClientRequestContextHandler implementation:
Code: Select all
        class ClientRequestContextHandler
            : public CefRequestContextHandler {
        private:
            ClientHandler* m_handler; // weak ref
        public:
            ClientRequestContextHandler(ClientHandler* handler)
                : m_handler(handler)
            {}
            ~ClientRequestContextHandler()
            {
                m_handler = nullptr;
            }
        public:
            CefRefPtr<CefCookieManager> GetCookieManager() override {
                return NULL;
            }
            bool OnBeforePluginLoad(const CefString& mime_type,
                const CefString& plugin_url, bool is_main_frame,
                const CefString& top_origin_url,
                CefRefPtr<CefWebPluginInfo> plugin_info,
                PluginPolicy* plugin_policy) override {
                // simply forward it to client handler
                if(m_handler) {
                    if(m_handler->OnBeforePluginLoad(mime_type,
                                plugin_url, is_main_frame, top_origin_url,
                                plugin_info, plugin_policy)) {
                        //  handled by client handler
                        return true;
                    }
                }
                return __super::OnBeforePluginLoad(mime_type,
                    plugin_url, is_main_frame, top_origin_url,
                    plugin_info, plugin_policy);
            }
            void OnUnloadablePlugin(const CefString& url,
                const CefString& mime_type) override
            {
                if(m_handler) {
                    m_handler->OnUnloadablePlugin(url, mime_type);
                }
            }
        private:
            IMPLEMENT_REFCOUNTING(ClientRequestContextHandler);
        };


And finally the proxied implementation in client handler (trimmed of sample):
Code: Select all
bool ClientHandler::OnBeforePluginLoad(
    const CefString& mime_type,
    const CefString& plugin_url,
    bool is_main_frame,
    const CefString& policy_url,
    CefRefPtr<CefWebPluginInfo> info,
    CefRequestContextHandler::PluginPolicy* plugin_policy)
{
    METHOD_GUARD_(CefRequestHandler, OnBeforePluginLoad, false)

    if(plugin_policy == nullptr)
        return false;

    const char* kFlashMimeType = "application/x-shockwave-flash";

    if(info.get()) {
        CefRefPtr<CefListValue> mime_types = info->GetMimeTypes();
        if(mime_types.get() != 0) {
            size_t cMimeTypes = mime_types->GetSize();
            for(size_t c = 0; c < cMimeTypes; c++)
            {
                CefString sMimeType = mime_types->GetString(c);
                if(sMimeType == kFlashMimeType) {
                   *plugin_policy = PLUGIN_POLICY_ALLOW;
                   return true; // explicitely allowed by us
                }
            }
        }
    }

...
    return false; // no verdict from us, let the default behavior flow
}
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: How to set/coding in CEF to allow flash on current page

Postby ndesktop » Tue Jan 08, 2019 3:19 am

Also, launch your app with --enable-system-flash. I don't know what version are you using and Flash is on the verge of being obsoleted.
Maybe by default is not even allowing it, that's why you receive only application/pdf which is the internal Chromium PDF viewer (chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/).
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 84 guests