Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Unified Diff: extensions/renderer/resources/display_source_custom_bindings.js

Issue 1674583002: [chrome.displaySource] Session notification improvements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from Antony Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/resources/display_source_custom_bindings.js
diff --git a/extensions/renderer/resources/display_source_custom_bindings.js b/extensions/renderer/resources/display_source_custom_bindings.js
index 13e81670a05ec1f7e25ee0a7618bb06b95069f41..a1345ff1a534b8a260fedc8effedfecbaece75dc 100644
--- a/extensions/renderer/resources/display_source_custom_bindings.js
+++ b/extensions/renderer/resources/display_source_custom_bindings.js
@@ -8,34 +8,62 @@ var binding = require('binding').Binding.create('displaySource');
var chrome = requireNative('chrome').GetChrome();
var lastError = require('lastError');
var natives = requireNative('display_source');
+var logging = requireNative('logging');
+
+var callbacksInfo = {};
+
+function callbackWrapper(callback, method, message) {
+ if (callback == undefined)
+ return;
+
+ try {
+ if (message !== null)
+ lastError.set('displaySource.startSession', message, null, chrome);
+ callback();
+ } finally {
+ lastError.clear(chrome);
+ }
+}
+
+function callCompletionCallback(callbackId, error_message) {
+ try {
+ var callbackInfo = callbacksInfo[callbackId];
+ logging.DCHECK(callbackInfo != null);
+ callbackWrapper(callbackInfo.callback, callbackInfo.method, error_message);
+ } finally {
+ delete callbacksInfo[callbackId];
+ }
+}
binding.registerCustomHook(function(bindingsAPI, extensionId) {
var apiFunctions = bindingsAPI.apiFunctions;
- apiFunctions.setHandleRequest('startSession',
- function(sessionInfo, callback) {
+ apiFunctions.setHandleRequest(
+ 'startSession', function(sessionInfo, callback) {
try {
- natives.StartSession(sessionInfo);
+ var callId = natives.StartSession(sessionInfo, callbackWrapper);
+ callbacksInfo[callId] = {
+ callback: callback,
+ method: 'displaySource.startSession'
+ };
} catch (e) {
- lastError.set('displaySource.startSession', e.message, null, chrome);
- } finally {
- if (callback !== undefined)
- callback();
- lastError.clear(chrome);
+ callbackWrapper(callback, 'displaySource.startSession', e.message);
}
- });
- apiFunctions.setHandleRequest('terminateSession',
- function(sink_id, callback) {
+ });
+ apiFunctions.setHandleRequest(
+ 'terminateSession', function(sink_id, callback) {
try {
- natives.TerminateSession(sink_id);
+ var callId = natives.TerminateSession(sink_id, callbackWrapper);
+ callbacksInfo[callId] = {
+ callback: callback,
+ method: 'displaySource.terminateSession'
+ };
} catch (e) {
- lastError.set(
- 'displaySource.terminateSession', e.message, null, chrome);
- } finally {
- if (callback !== undefined)
- callback();
- lastError.clear(chrome);
+ callbackWrapper(
+ callback, 'displaySource.terminateSession', e.message);
}
- });
+ });
});
exports.$set('binding', binding.generate());
+// Called by C++.
+exports.$set('callCompletionCallback', callCompletionCallback);

Powered by Google App Engine
This is Rietveld 408576698