cef OnContextCreated不能多次工作

时间:2017-09-18 11:28:23

标签: chromium-embedded

当我使用libcef将C ++函数注册到javascript中时。我在多模式下发现OnContextCreated不起作用。但是当我使用设置sets.single_process = true时。它叫做。

// Client app implementation for the browser process.
class ClientAppBrowser : public ClientApp,
    public CefRenderProcessHandler,
    public CefBrowserProcessHandler {
public:

    //int SetPorxyPort(int port);

    // Interface for browser delegates. All Delegates must be returned via
    // CreateDelegates. Do not perform work in the Delegate
    // constructor. See CefBrowserProcessHandler for documentation.
    class Delegate : public virtual CefBaseRefCounted {
    public:
        virtual void OnBeforeCommandLineProcessing(
            CefRefPtr<ClientAppBrowser> app,
            CefRefPtr<CefCommandLine> command_line) {}

        virtual void OnContextInitialized(CefRefPtr<ClientAppBrowser> app) {}

        virtual void OnBeforeChildProcessLaunch(
            CefRefPtr<ClientAppBrowser> app,
            CefRefPtr<CefCommandLine> command_line) {}

        virtual void OnRenderProcessThreadCreated(
            CefRefPtr<ClientAppBrowser> app,
            CefRefPtr<CefListValue> extra_info) {}
        virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
            CefRefPtr<CefFrame> frame,
            CefRefPtr<CefV8Context> context){}
    };

    typedef std::set<CefRefPtr<Delegate> > DelegateSet;

    ClientAppBrowser();

private:


    // Creates all of the Delegate objects. Implemented by cefclient in
    // client_app_delegates_browser.cc
    static void CreateDelegates(DelegateSet& delegates);

    // Create the Linux print handler. Implemented by cefclient in
    // client_app_delegates_browser.cc
    static CefRefPtr<CefPrintHandler> CreatePrintHandler();

    // CefApp methods.
    void OnBeforeCommandLineProcessing(
        const CefString& process_type,
        CefRefPtr<CefCommandLine> command_line) OVERRIDE;
    CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() OVERRIDE{
        return this;
    }
        CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() OVERRIDE{
        return this;
    }

        void OnContextCreated(CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        CefRefPtr<CefV8Context> context) OVERRIDE;

    // CefBrowserProcessHandler methods.
    void OnContextInitialized() OVERRIDE;
    void OnBeforeChildProcessLaunch(
        CefRefPtr<CefCommandLine> command_line) OVERRIDE;
    void OnRenderProcessThreadCreated(
        CefRefPtr<CefListValue> extra_info) OVERRIDE;
    CefRefPtr<CefPrintHandler> GetPrintHandler() OVERRIDE{
        return print_handler_;
    }
    void OnScheduleMessagePumpWork(int64 delay) OVERRIDE;

    // Set of supported Delegates.
    DelegateSet delegates_;

    CefRefPtr<CefPrintHandler> print_handler_;

    IMPLEMENT_REFCOUNTING(ClientAppBrowser);
    DISALLOW_COPY_AND_ASSIGN(ClientAppBrowser);
};

在代码中可以看到,我在这里使用覆盖和实现。因此,在单进程模式下可以正常工作,我应该在哪里加入这些设置或代码,以使其能够在多线程模式下工作?

0 个答案:

没有答案