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

Side by Side Diff: chrome/renderer/resources/extensions/tts_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: 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 tts API. 5 // Custom bindings for the tts API.
6 6
7 var ttsNatives = requireNative('tts'); 7 var ttsNatives = requireNative('tts');
8 var GetNextTTSEventId = ttsNatives.GetNextTTSEventId; 8 var GetNextTTSEventId = ttsNatives.GetNextTTSEventId;
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('tts', function(api) { 14 chromeHidden.registerCustomHook('tts', function(api) {
14 var apiFunctions = api.apiFunctions; 15 var apiFunctions = api.apiFunctions;
15 16
16 chromeHidden.tts = {}; 17 chromeHidden.tts = {};
17 chromeHidden.tts.handlers = {}; 18 chromeHidden.tts.handlers = {};
18 chrome.tts.onEvent.addListener(function(event) { 19 chrome.tts.onEvent.addListener(function(event) {
19 var eventHandler = chromeHidden.tts.handlers[event.srcId]; 20 var eventHandler = chromeHidden.tts.handlers[event.srcId];
20 if (eventHandler) { 21 if (eventHandler) {
21 eventHandler({ 22 eventHandler({
22 type: event.type, 23 type: event.type,
23 charIndex: event.charIndex, 24 charIndex: event.charIndex,
24 errorMessage: event.errorMessage 25 errorMessage: event.errorMessage
25 }); 26 });
26 if (event.isFinalEvent) { 27 if (event.isFinalEvent) {
27 delete chromeHidden.tts.handlers[event.srcId]; 28 delete chromeHidden.tts.handlers[event.srcId];
29 // Balanced in 'speak' handler.
30 lazyBG.DecrementKeepaliveCount();
28 } 31 }
29 } 32 }
30 }); 33 });
31 34
32 apiFunctions.setHandleRequest('speak', function() { 35 apiFunctions.setHandleRequest('speak', function() {
33 var args = arguments; 36 var args = arguments;
34 if (args.length > 1 && args[1] && args[1].onEvent) { 37 if (args.length > 1 && args[1] && args[1].onEvent) {
35 var id = GetNextTTSEventId(); 38 var id = GetNextTTSEventId();
36 args[1].srcId = id; 39 args[1].srcId = id;
37 chromeHidden.tts.handlers[id] = args[1].onEvent; 40 chromeHidden.tts.handlers[id] = args[1].onEvent;
41 // Keep the page alive until the event finishes.
42 // Balanced in eventHandler.
43 lazyBG.IncrementKeepaliveCount();
38 } 44 }
39 sendRequest(this.name, args, this.definition.parameters); 45 sendRequest(this.name, args, this.definition.parameters);
40 return id; 46 return id;
41 }); 47 });
42 }); 48 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698