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

Unified Diff: chrome/renderer/resources/extensions/experimental.socket_custom_bindings.js

Issue 10273016: Refactor the socket API to remove onEvent callback in socket.create() function. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update Created 8 years, 7 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: chrome/renderer/resources/extensions/experimental.socket_custom_bindings.js
diff --git a/chrome/renderer/resources/extensions/experimental.socket_custom_bindings.js b/chrome/renderer/resources/extensions/experimental.socket_custom_bindings.js
deleted file mode 100644
index 80f016b68f6bb99b91dcab1097ce2cf2989c327e..0000000000000000000000000000000000000000
--- a/chrome/renderer/resources/extensions/experimental.socket_custom_bindings.js
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Custom bindings for the experimental.socket API.
-
- var experimentalSocketNatives = requireNative('experimental_socket');
- var GetNextSocketEventId = experimentalSocketNatives.GetNextSocketEventId;
-
- var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
- var sendRequest = require('sendRequest').sendRequest;
- var lazyBG = requireNative('lazy_background_page');
-
- chromeHidden.registerCustomHook('experimental.socket', function(api) {
- var apiFunctions = api.apiFunctions;
-
- apiFunctions.setHandleRequest('create', function() {
- var args = arguments;
- if (args.length > 1 && args[1] && args[1].onEvent) {
- var id = GetNextSocketEventId();
- args[1].srcId = id;
- chromeHidden.socket.handlers[id] = args[1].onEvent;
-
- // Keep the page alive until the event finishes.
- // Balanced in eventHandler.
- lazyBG.IncrementKeepaliveCount();
- }
- sendRequest(this.name, args, this.definition.parameters);
- return id;
- });
-
- // Set up events.
- chromeHidden.socket = {};
- chromeHidden.socket.handlers = {};
- chrome.experimental.socket.onEvent.addListener(function(event) {
- var eventHandler = chromeHidden.socket.handlers[event.srcId];
- if (eventHandler) {
- switch (event.type) {
- case 'writeComplete':
- case 'connectComplete':
- eventHandler({
- type: event.type,
- resultCode: event.resultCode,
- });
- break;
- case 'dataRead':
- eventHandler({
- type: event.type,
- resultCode: event.resultCode,
- data: event.data,
- });
- break;
- default:
- console.error('Unexpected SocketEvent, type ' + event.type);
- break;
- }
- if (event.isFinalEvent) {
- delete chromeHidden.socket.handlers[event.srcId];
- // Balanced in 'create' handler.
- lazyBG.DecrementKeepaliveCount();
- }
- }
- });
- });
« no previous file with comments | « chrome/renderer/renderer_resources.grd ('k') | chrome/test/data/extensions/api_test/socket/api/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698