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

Side by Side Diff: chrome/renderer/resources/extensions/experimental.socket_custom_bindings.js

Issue 9958147: Fix some uses of global variables in transient pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Custom bindings for the experimental.socket API. 5 // Custom bindings for the experimental.socket API.
6 6
7 var experimentalSocketNatives = requireNative('experimental_socket'); 7 var experimentalSocketNatives = requireNative('experimental_socket');
8 var GetNextSocketEventId = experimentalSocketNatives.GetNextSocketEventId; 8 var GetNextSocketEventId = experimentalSocketNatives.GetNextSocketEventId;
9 9
10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
11 var sendRequest = require('sendRequest').sendRequest; 11 var sendRequest = require('sendRequest').sendRequest;
12 var lazyBG = requireNative('lazy_background_page');
12 13
13 chromeHidden.registerCustomHook('experimental.socket', function(api) { 14 chromeHidden.registerCustomHook('experimental.socket', function(api) {
14 var apiFunctions = api.apiFunctions; 15 var apiFunctions = api.apiFunctions;
15 16
16 apiFunctions.setHandleRequest('create', function() { 17 apiFunctions.setHandleRequest('create', function() {
17 var args = arguments; 18 var args = arguments;
18 if (args.length > 3 && args[3] && args[3].onEvent) { 19 if (args.length > 3 && args[3] && args[3].onEvent) {
19 var id = GetNextSocketEventId(); 20 var id = GetNextSocketEventId();
20 args[3].srcId = id; 21 args[3].srcId = id;
21 chromeHidden.socket.handlers[id] = args[3].onEvent; 22 chromeHidden.socket.handlers[id] = args[3].onEvent;
23
24 // Keep the page alive until the event finishes.
25 // Balanced in eventHandler.
26 lazyBG.IncrementKeepaliveCount();
22 } 27 }
23 sendRequest(this.name, args, this.definition.parameters); 28 sendRequest(this.name, args, this.definition.parameters);
24 return id; 29 return id;
25 }); 30 });
26 31
27 // Set up events. 32 // Set up events.
28 chromeHidden.socket = {}; 33 chromeHidden.socket = {};
29 chromeHidden.socket.handlers = {}; 34 chromeHidden.socket.handlers = {};
30 chrome.experimental.socket.onEvent.addListener(function(event) { 35 chrome.experimental.socket.onEvent.addListener(function(event) {
31 var eventHandler = chromeHidden.socket.handlers[event.srcId]; 36 var eventHandler = chromeHidden.socket.handlers[event.srcId];
(...skipping 12 matching lines...) Expand all
44 resultCode: event.resultCode, 49 resultCode: event.resultCode,
45 data: event.data, 50 data: event.data,
46 }); 51 });
47 break; 52 break;
48 default: 53 default:
49 console.error('Unexpected SocketEvent, type ' + event.type); 54 console.error('Unexpected SocketEvent, type ' + event.type);
50 break; 55 break;
51 } 56 }
52 if (event.isFinalEvent) { 57 if (event.isFinalEvent) {
53 delete chromeHidden.socket.handlers[event.srcId]; 58 delete chromeHidden.socket.handlers[event.srcId];
59 // Balanced in 'create' handler.
60 lazyBG.DecrementKeepaliveCount();
54 } 61 }
55 } 62 }
56 }); 63 });
57 }); 64 });
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/extension_dispatcher.cc ('k') | chrome/renderer/resources/extensions/tts_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698