Repository URL to install this package:
|
Version:
3.0.1.40031-bionic ▾
|
'use strict';
/*
Transpiled to es2015 using https://babeljs.io/repl syntax since some of our targets doesn't support es2016
*/
// Object which keeps yet-unfulfilled Promises, used by PythonHandler HOC
window.PROMISE_STORE = {};
// TODO: Leaving the following code in for now but remember to remove all of this once the transition to PythonHandler is completed.
// It's 4096 for cefpython3.
// WebKit in macOS 10.13 started to limit it to just 1000.
// There should be some reserved for overhead.
var MAX_MESSAGE_SIZE = 900;
var encodeArgs = function encodeArgs(args) {
// Encode args to transfer it reliably to the Python side, where the
// transfer is done in parts and not in one go. We encode to UTF-8
// so that we know exactly the number of bytes needed. If it's just
// plain string that contains unicode characters, we might be
// splitting it at 4000-character blocks, but not 4000-byte blocks
// (it's more than 4000 bytes). Then, just to ensure that setting of
// the title to a possibly "invalid" string (because it's basically
// a binary blob now) won't have issues, we encode it further to
// base64.
// See for implementation details:
// https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/btoa
return btoa(unescape(encodeURIComponent(JSON.stringify(args))));
};
var genCallId = function genCallId() {
return Math.random()
.toString(36)
.substr(2);
};
function callPy() {
var args = [];
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
var methodName = args[0]; // TODO: Properly implement dragging. For now, just temporarily enable this legacy
// method again for these specific methods.
if (methodName !== 'js_start_drag' && methodName !== 'js_stop_drag') {
return;
} // We split up the encoded args into multiple messages. We have a
// callId in case calls are interspersed (not sure if this is
// possible).
var command = encodeArgs(args);
var callId = genCallId();
var numParts = Math.ceil(command.length / MAX_MESSAGE_SIZE);
for (var i = 0; i < numParts; i++) {
var message = 'py::'
.concat(callId, ':')
.concat(numParts, ':')
.concat(i, ':');
message += command.substr(i * MAX_MESSAGE_SIZE, MAX_MESSAGE_SIZE);
document.title = message;
} // To ensure that title change event is called because it's possible
// to have consecutive calls that have the same arguments and thus,
// the same message.
document.title = '-'; // TODO: Enable this when in debug mode.
// console.log(command)
}
window.onerror = function() {
callPy('js_error', arguments);
};