Skip to content

Commit

Permalink
gui, bugfix: executeDevToolsMethod does not return when the parameter…
Browse files Browse the repository at this point in the history
… is wrong.
  • Loading branch information
xicilion committed Mar 10, 2021
1 parent deeae31 commit 90d0e24
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
24 changes: 20 additions & 4 deletions fibjs/src/gui/cef/CefWebView.cpp
Expand Up @@ -283,7 +283,7 @@ result_t CefWebView::printToPDF(exlib::string file, AsyncEvent* ac)
public:
virtual void OnPdfPrintFinished(const CefString& path, bool ok)
{
m_ac->apost(ok ? 0 : CALL_E_INTERNAL);
m_ac->post(ok ? 0 : CALL_E_INTERNAL);
}

private:
Expand Down Expand Up @@ -322,14 +322,20 @@ result_t CefWebView::executeJavaScript(exlib::string code, AsyncEvent* ac)
void CefWebView::OnDevToolsMethodResult(CefRefPtr<CefBrowser> browser, int message_id,
bool success, const void* result, size_t result_size)
{
m_method_lock.lock();
std::map<int32_t, ac_method>::iterator it_method;

it_method = m_method.find(message_id);
if (it_method != m_method.end()) {
it_method->second.m_retVal.setJSON(exlib::string((const char*)result, result_size));
it_method->second.m_ac->apost(0);
it_method->second.m_ac->post(0);
m_method.erase(it_method);
} else {
Variant v;

v.setJSON(exlib::string((const char*)result, result_size));
m_result.insert(std::pair<int32_t, Variant>(message_id, v));
}
m_method_lock.unlock();
}

void CefWebView::OnDevToolsEvent(CefRefPtr<CefBrowser> browser, const CefString& method,
Expand Down Expand Up @@ -379,7 +385,17 @@ result_t CefWebView::executeDevToolsMethod(exlib::string method, v8::Local<v8::O
if (rid == 0)
return CALL_E_INTERNAL;

m_method.insert(std::pair<int32_t, ac_method>(rid, ac_method(retVal, ac)));
m_method_lock.lock();
std::map<int32_t, Variant>::iterator it_method;
it_method = m_result.find(rid);
if (it_method != m_result.end()) {
retVal = it_method->second;
m_result.erase(it_method);
ac->post(0);
} else
m_method.insert(std::pair<int32_t, ac_method>(rid, ac_method(retVal, ac)));
m_method_lock.unlock();

return CALL_E_PENDDING;
}

Expand Down
2 changes: 2 additions & 0 deletions fibjs/src/gui/cef/CefWebView.h
Expand Up @@ -119,7 +119,9 @@ class CefWebView : public WebView_base,
};

int32_t m_eid;
exlib::spinlock m_method_lock;
std::map<int32_t, ac_method> m_method;
std::map<int32_t, Variant> m_result;
};
}

Expand Down
33 changes: 32 additions & 1 deletion test/cef_test.js
Expand Up @@ -235,9 +235,19 @@ describe("cef", () => {
});

win.on("load", () => {
var ret = win.dev.Page.captureScreenshot();
var ret = win.dev.Page.captureScreenshot({
clip: {
x: 0,
y: 0,
width: 100,
height: 100,
scale: 1
}
});
try {
var img = gd.load(encoding.base64.decode(ret.data));
assert.equal(img.width, 100);
assert.equal(img.height, 100);
assert.equal(img.getPixel(1, 1), gd.rgb(255, 255, 255));
done();
} catch (e) {
Expand All @@ -247,6 +257,27 @@ describe("cef", () => {
win.close();
});
});

it("FIX: screenshot with wrong clip", done => {
var win = gui.open("cef://test/basic.html", {
headless: true
});

win.on("load", () => {
var ret = win.dev.Page.captureScreenshot({
clip: {}
});

try {
assert.equal(ret.code, -32602);
done();
} catch (e) {
done(e);
}

win.close();
});
});
});

require.main === module && test.run(console.DEBUG);

0 comments on commit 90d0e24

Please sign in to comment.