track async api requests

This commit is contained in:
Robo 2016-02-22 19:30:21 +05:30
parent 2b547bd44a
commit a734326907
8 changed files with 39 additions and 39 deletions

View file

@ -8,7 +8,6 @@
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/native_mate_converters/blink_converter.h"
#include "atom/renderer/api/atom_api_spell_check_client.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_view.h"
@ -33,7 +32,7 @@ class ScriptExecutionCallback : public blink::WebScriptExecutionCallback {
public:
using CompletionCallback =
base::Callback<void(
const blink::WebVector<v8::Local<v8::Value>>& result)>;
const v8::Local<v8::Value>& result)>;
explicit ScriptExecutionCallback(const CompletionCallback& callback)
: callback_(callback) {}
@ -42,7 +41,8 @@ class ScriptExecutionCallback : public blink::WebScriptExecutionCallback {
void completed(
const blink::WebVector<v8::Local<v8::Value>>& result) override {
if (!callback_.is_null())
callback_.Run(result);
// Right now only single results per frame is supported.
callback_.Run(result[0]);
delete this;
}

View file

@ -32,17 +32,16 @@ v8Util.setHiddenValue(global, 'ipc', new events.EventEmitter);
const electron = require('electron');
// Call webFrame method.
const asyncWebFrameMethods = [
'executeJavaScript'
];
electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', (event, method, args) => {
if (asyncWebFrameMethods.includes(method)) {
const responseCallback = function(result) {
event.sender.send('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_RESPONSE', method, result);
};
args.push(responseCallback);
}
electron.webFrame[method].apply(electron.webFrame, args);
});
electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (event, method, args) => {
let requestId = args.shift();
const responseCallback = function(result) {
event.sender.send('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_RESPONSE', requestId, result);
};
args.push(responseCallback);
electron.webFrame[method].apply(electron.webFrame, args);
});

View file

@ -393,14 +393,14 @@ var registerWebViewElement = function() {
nonblockMethods = [
'insertCSS',
'send',
'sendInputEvent'
'sendInputEvent',
];
webFrameMethods = [
'executeJavaScript',
'insertText',
'setZoomFactor',
'setZoomLevel',
'setZoomLevelLimits'
'setZoomLevelLimits',
];
// Forward proto.foo* method calls to WebViewImpl.foo*.