2015-09-24 03:02:22 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-09-24 03:02:22 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-05-11 19:43:49 +00:00
|
|
|
*
|
|
|
|
* @format
|
2015-09-24 03:02:22 +00:00
|
|
|
*/
|
2016-10-31 18:16:17 +00:00
|
|
|
|
2015-12-08 23:57:34 +00:00
|
|
|
/* global __fbBatchedBridge, self, importScripts, postMessage, onmessage: true */
|
2015-09-24 03:02:22 +00:00
|
|
|
/* eslint no-unused-vars: 0 */
|
2016-10-31 18:16:17 +00:00
|
|
|
|
2015-09-24 03:02:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-10-31 18:16:17 +00:00
|
|
|
onmessage = (function() {
|
|
|
|
var visibilityState;
|
|
|
|
var showVisibilityWarning = (function() {
|
|
|
|
var hasWarned = false;
|
|
|
|
return function() {
|
|
|
|
// Wait until `YellowBox` gets initialized before displaying the warning.
|
|
|
|
if (hasWarned || console.warn.toString().includes('[native code]')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hasWarned = true;
|
|
|
|
console.warn(
|
|
|
|
'Remote debugger is in a background tab which may cause apps to ' +
|
2018-05-11 19:43:49 +00:00
|
|
|
'perform slowly. Fix this by foregrounding the tab (or opening it in ' +
|
|
|
|
'a separate window).',
|
2016-10-31 18:16:17 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
var messageHandlers = {
|
2018-05-11 19:43:49 +00:00
|
|
|
executeApplicationScript: function(message, sendReply) {
|
2016-10-31 18:16:17 +00:00
|
|
|
for (var key in message.inject) {
|
|
|
|
self[key] = JSON.parse(message.inject[key]);
|
|
|
|
}
|
|
|
|
var error;
|
|
|
|
try {
|
|
|
|
importScripts(message.url);
|
|
|
|
} catch (err) {
|
2017-06-12 10:31:44 +00:00
|
|
|
error = err.message;
|
2016-10-31 18:16:17 +00:00
|
|
|
}
|
|
|
|
sendReply(null /* result */, error);
|
|
|
|
},
|
2018-05-11 19:43:49 +00:00
|
|
|
setDebuggerVisibility: function(message) {
|
2016-10-31 18:16:17 +00:00
|
|
|
visibilityState = message.visibilityState;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
return function(message) {
|
|
|
|
if (visibilityState === 'hidden') {
|
|
|
|
showVisibilityWarning();
|
2016-09-07 19:13:34 +00:00
|
|
|
}
|
2015-09-24 03:02:22 +00:00
|
|
|
|
2016-10-31 18:16:17 +00:00
|
|
|
var object = message.data;
|
2015-09-24 03:02:22 +00:00
|
|
|
|
2016-10-31 18:16:17 +00:00
|
|
|
var sendReply = function(result, error) {
|
|
|
|
postMessage({replyID: object.id, result: result, error: error});
|
|
|
|
};
|
2015-09-24 03:02:22 +00:00
|
|
|
|
2016-10-31 18:16:17 +00:00
|
|
|
var handler = messageHandlers[object.method];
|
|
|
|
if (handler) {
|
|
|
|
// Special cased handlers
|
|
|
|
handler(object, sendReply);
|
|
|
|
} else {
|
|
|
|
// Other methods get called on the bridge
|
|
|
|
var returnValue = [[], [], [], 0];
|
2017-06-12 10:31:44 +00:00
|
|
|
var error;
|
2016-10-31 18:16:17 +00:00
|
|
|
try {
|
|
|
|
if (typeof __fbBatchedBridge === 'object') {
|
2018-05-11 19:43:49 +00:00
|
|
|
returnValue = __fbBatchedBridge[object.method].apply(
|
|
|
|
null,
|
|
|
|
object.arguments,
|
|
|
|
);
|
2017-06-12 10:31:44 +00:00
|
|
|
} else {
|
|
|
|
error = 'Failed to call function, __fbBatchedBridge is undefined';
|
2016-10-31 18:16:17 +00:00
|
|
|
}
|
2017-06-12 10:31:44 +00:00
|
|
|
} catch (err) {
|
|
|
|
error = err.message;
|
2016-10-31 18:16:17 +00:00
|
|
|
} finally {
|
2017-06-12 10:31:44 +00:00
|
|
|
sendReply(JSON.stringify(returnValue), error);
|
2015-12-08 23:57:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-31 18:16:17 +00:00
|
|
|
};
|
|
|
|
})();
|