OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * @fileoverview This is the content script injected by the opt in helper. | 8 * @fileoverview This is the content script injected by the opt in helper. |
9 * It is injected into the newtab page and also google.com and notifies the | 9 * It is injected into the newtab page and also google.com and notifies the |
10 * page to show an opt-in message for the user to enable the built-in hotword | 10 * page to show an opt-in message for the user to enable the built-in hotword |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 | 29 |
30 /** | 30 /** |
31 * Commands sent from the page to this content script. | 31 * Commands sent from the page to this content script. |
32 * @enum {string} | 32 * @enum {string} |
33 */ | 33 */ |
34 OptInClient.CommandFromPage = { | 34 OptInClient.CommandFromPage = { |
35 // User has explicitly clicked 'no'. | 35 // User has explicitly clicked 'no'. |
36 CLICKED_NO_OPTIN: 'hcno', | 36 CLICKED_NO_OPTIN: 'hcno', |
37 // User has opted in. | 37 // User has opted in. |
38 CLICKED_OPTIN: 'hco' | 38 CLICKED_OPTIN: 'hco', |
| 39 // Audio logging is opted in. |
| 40 AUDIO_LOGGING_ON: 'alon', |
| 41 // Audio logging is opted out. |
| 42 AUDIO_LOGGING_OFF: 'aloff', |
39 }; | 43 }; |
40 | 44 |
41 | 45 |
42 /** | 46 /** |
43 * Used to determine if this content script has already been injected. | 47 * Used to determine if this content script has already been injected. |
44 * @const {string} | 48 * @const {string} |
45 * @private | 49 * @private |
46 */ | 50 */ |
47 OptInClient.EXISTS_ = 'chwoihe'; | 51 OptInClient.EXISTS_ = 'chwoihe'; |
48 | 52 |
49 | 53 |
50 /** | 54 /** |
51 * Handles the messages posted to the window, mainly listening for | 55 * Handles the messages posted to the window, mainly listening for |
52 * the optin and no optin clicks. | 56 * the optin and no optin clicks. Also listening for preference on |
| 57 * audio logging. |
53 * @param {!MessageEvent} messageEvent Message event from the window. | 58 * @param {!MessageEvent} messageEvent Message event from the window. |
54 * @private | 59 * @private |
55 */ | 60 */ |
56 OptInClient.prototype.handleCommandFromPage_ = function(messageEvent) { | 61 OptInClient.prototype.handleCommandFromPage_ = function(messageEvent) { |
57 if (messageEvent.source === window && messageEvent.data.type) { | 62 if (messageEvent.source === window && messageEvent.data.type) { |
58 var command = messageEvent.data.type; | 63 var command = messageEvent.data.type; |
59 switch (command) { | 64 chrome.runtime.sendMessage({'type': command}); |
60 case OptInClient.CommandFromPage.CLICKED_OPTIN: | |
61 chrome.runtime.sendMessage( | |
62 {'type': command}); | |
63 break; | |
64 case OptInClient.CommandFromPage.CLICKED_NO_OPTIN: | |
65 chrome.runtime.sendMessage( | |
66 {'type': command}); | |
67 break; | |
68 } | |
69 } | 65 } |
70 }; | 66 }; |
71 | 67 |
72 | 68 |
73 /** | 69 /** |
74 * Sends a command to the page allowing it to display the hotword opt-in | 70 * Sends a command to the page allowing it to display the hotword opt-in |
75 * message. It is up to the page whether it is actually displayed. | 71 * message. It is up to the page whether it is actually displayed. |
76 * @private | 72 * @private |
77 */ | 73 */ |
78 OptInClient.prototype.notifyPageAllowOptIn_ = function() { | 74 OptInClient.prototype.notifyPageAllowOptIn_ = function() { |
(...skipping 15 matching lines...) Expand all Loading... |
94 'message', this.handleCommandFromPage_.bind(this), false); | 90 'message', this.handleCommandFromPage_.bind(this), false); |
95 | 91 |
96 if (document.readyState === 'complete') | 92 if (document.readyState === 'complete') |
97 this.notifyPageAllowOptIn_(); | 93 this.notifyPageAllowOptIn_(); |
98 else | 94 else |
99 document.onreadystatechange = this.notifyPageAllowOptIn_; | 95 document.onreadystatechange = this.notifyPageAllowOptIn_; |
100 }; | 96 }; |
101 | 97 |
102 | 98 |
103 new OptInClient().initialize(); | 99 new OptInClient().initialize(); |
OLD | NEW |