void CEFCapture::set_url(const string &url)
{
post_to_cef_ui_thread([this, url] {
+ loaded = false;
browser->GetMainFrame()->LoadURL(url);
});
}
void CEFCapture::execute_javascript_async(const string &js)
{
post_to_cef_ui_thread([this, js] {
- CefString script_url("<theme eval>");
- int start_line = 1;
- browser->GetMainFrame()->ExecuteJavaScript(js, script_url, start_line);
+ if (loaded) {
+ CefString script_url("<theme eval>");
+ int start_line = 1;
+ browser->GetMainFrame()->ExecuteJavaScript(js, script_url, start_line);
+ } else {
+ deferred_javascript.push_back(js);
+ }
});
}
FrameAllocator::Frame(), 0, AudioFormat());
}
+void CEFCapture::OnLoadEnd()
+{
+ post_to_cef_ui_thread([this] {
+ loaded = true;
+ for (const string &js : deferred_javascript) {
+ CefString script_url("<theme eval>");
+ int start_line = 1;
+ browser->GetMainFrame()->ExecuteJavaScript(js, script_url, start_line);
+ }
+ deferred_javascript.clear();
+ });
+}
+
#define FRAME_SIZE (8 << 20) // 8 MB.
void CEFCapture::configure_card()
rect = CefRect(0, 0, width, height);
return true;
}
+
+void NageruCEFClient::OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode)
+{
+ parent->OnLoadEnd();
+}
#include <set>
#include <string>
#include <thread>
+#include <vector>
#undef CHECK
#include <cef_client.h>
// A helper class for CEFCapture to proxy information to CEF, without becoming
// CEF-refcounted itself.
-class NageruCEFClient : public CefClient, public CefRenderHandler
+class NageruCEFClient : public CefClient, public CefRenderHandler, public CefLoadHandler
{
public:
NageruCEFClient(int width, int height, CEFCapture *parent)
return this;
}
+ CefRefPtr<CefLoadHandler> GetLoadHandler() override
+ {
+ return this;
+ }
+
+ // CefRenderHandler.
+
void OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList &dirtyRects, const void *buffer, int width, int height) override;
bool GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect);
+ // CefLoadHandler.
+
+ void OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode) override;
+
private:
int width, height;
CEFCapture *parent;
void OnPaint(const void *buffer, int width, int height);
+ void OnLoadEnd();
+
// CaptureInterface.
void set_video_frame_allocator(bmusb::FrameAllocator *allocator) override
{
// Tasks waiting for <browser> to get ready. Under <browser_mutex>.
std::vector<std::function<void()>> deferred_tasks;
+ // Whether the last set_url() (includes the implicit one in the constructor)
+ // has loaded yet. Accessed from the CEF thread only.
+ bool loaded = false;
+
+ // JavaScript waiting for the first page (well, any page) to have loaded.
+ // Accessed from the CEF thread only.
+ std::vector<std::string> deferred_javascript;
+
int timecode = 0;
};