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 switch (command) { |
60 case OptInClient.CommandFromPage.CLICKED_OPTIN: | 65 case OptInClient.CommandFromPage.CLICKED_OPTIN: |
61 chrome.runtime.sendMessage( | 66 chrome.runtime.sendMessage( |
62 {'type': command}); | 67 {'type': command}); |
63 break; | 68 break; |
64 case OptInClient.CommandFromPage.CLICKED_NO_OPTIN: | 69 case OptInClient.CommandFromPage.CLICKED_NO_OPTIN: |
65 chrome.runtime.sendMessage( | 70 chrome.runtime.sendMessage( |
66 {'type': command}); | 71 {'type': command}); |
67 break; | 72 break; |
73 case OptInClient.CommandFromPage.AUDIO_LOGGING_ON: | |
74 chrome.runtime.sendMessage( | |
75 {'type': command}); | |
76 break; | |
77 case OptInClient.CommandFromPage.AUDIO_LOGGING_OFF: | |
78 chrome.runtime.sendMessage( | |
79 {'type': command}); | |
saurya1
2014/03/27 16:29:22
If you want to clean this up you can just remove t
rpetterson
2014/03/27 16:37:19
I assume I don't actually need the switch statemen
| |
80 break; | |
68 } | 81 } |
69 } | 82 } |
70 }; | 83 }; |
71 | 84 |
72 | 85 |
73 /** | 86 /** |
74 * Sends a command to the page allowing it to display the hotword opt-in | 87 * 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. | 88 * message. It is up to the page whether it is actually displayed. |
76 * @private | 89 * @private |
77 */ | 90 */ |
(...skipping 16 matching lines...) Expand all Loading... | |
94 'message', this.handleCommandFromPage_.bind(this), false); | 107 'message', this.handleCommandFromPage_.bind(this), false); |
95 | 108 |
96 if (document.readyState === 'complete') | 109 if (document.readyState === 'complete') |
97 this.notifyPageAllowOptIn_(); | 110 this.notifyPageAllowOptIn_(); |
98 else | 111 else |
99 document.onreadystatechange = this.notifyPageAllowOptIn_; | 112 document.onreadystatechange = this.notifyPageAllowOptIn_; |
100 }; | 113 }; |
101 | 114 |
102 | 115 |
103 new OptInClient().initialize(); | 116 new OptInClient().initialize(); |
OLD | NEW |