Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!--- | 1 <!--- |
| 2 Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 2 Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 3 Use of this source code is governed by a BSD-style license that can be | 3 Use of this source code is governed by a BSD-style license that can be |
| 4 found in the LICENSE file. | 4 found in the LICENSE file. |
| 5 ---> | 5 ---> |
| 6 | 6 |
| 7 <html> | 7 <html> |
| 8 | |
| 9 <script> | |
| 10 // Convert seconds to milliseconds | |
| 11 function seconds(s) { | |
| 12 return s * 1000; | |
| 13 } | |
| 14 | |
| 15 // Convert minutes to milliseconds | |
| 16 function minutes(m) { | |
| 17 return seconds(m * 60); | |
| 18 } | |
| 19 </script> | |
| 20 | |
| 8 <script src='/urls.js'> | 21 <script src='/urls.js'> |
| 9 </script> | 22 </script> |
| 10 | 23 |
| 11 <script src='/params.js'> | 24 <script src='/params.js'> |
| 12 </script> | 25 </script> |
| 13 | 26 |
| 14 <script> | 27 <script> |
| 15 | 28 |
| 16 var cycle_tabs = {}; | 29 var cycle_tabs = {}; |
| 17 var cycles = {}; | 30 var cycles = {}; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 41 sendResponse({"should_scroll": should_scroll, | 54 sendResponse({"should_scroll": should_scroll, |
| 42 "should_scroll_up": should_scroll_up, | 55 "should_scroll_up": should_scroll_up, |
| 43 "scroll_loop": scroll_loop, | 56 "scroll_loop": scroll_loop, |
| 44 "scroll_interval": scroll_interval_ms, | 57 "scroll_interval": scroll_interval_ms, |
| 45 "scroll_by": scroll_by_pixels}); | 58 "scroll_by": scroll_by_pixels}); |
| 46 } | 59 } |
| 47 delete cycle_tabs[sender.tab.id]; | 60 delete cycle_tabs[sender.tab.id]; |
| 48 } | 61 } |
| 49 } | 62 } |
| 50 | 63 |
| 64 function parseTaskList(tasks_string) { | |
| 65 if (tasks_string == '') | |
| 66 return []; | |
| 67 var task_strings = tasks_string.split('&'); | |
| 68 task_strings_global = task_strings; | |
|
Sameer Nanda
2011/03/31 23:42:22
seems like an unused variable? delete it.
Simon Que
2011/04/01 21:37:15
Done.
| |
| 69 var task_list = []; | |
| 70 var time = 0; | |
| 71 | |
| 72 // Parse each task. | |
| 73 for (var i in task_strings) { | |
| 74 // Extract task parameters. | |
| 75 var params = task_strings[i].split(';'); | |
| 76 var cmd = params[0]; | |
| 77 var urls = params[1].split(','); | |
| 78 var duration = minutes(parseInt(params[2])); | |
| 79 if (params.length > 3) | |
| 80 var delay = minutes(parseInt(params[3])); | |
| 81 | |
| 82 if (cmd == 'single') { | |
| 83 task_list.push( { type: 'window', | |
| 84 start: time, | |
| 85 duration: duration, | |
| 86 focus: true, | |
| 87 tabs: urls } ); | |
| 88 } | |
| 89 else if (cmd == 'repeat') { | |
| 90 task_list.push( { type: 'cycle', | |
| 91 start: time, | |
| 92 duration: duration, | |
| 93 delay: delay, | |
| 94 timeout: seconds(10), | |
| 95 focus: true, | |
| 96 urls: urls } ); | |
| 97 } | |
| 98 // Increment the time to determine the start time of the next task. | |
| 99 time += delay; | |
| 100 } | |
| 101 return task_list; | |
| 102 } | |
| 103 | |
| 104 var task_list = []; | |
| 51 | 105 |
| 52 chrome.extension.onRequest.addListener( | 106 chrome.extension.onRequest.addListener( |
| 53 function paramsSetupListener(request, sender) { | 107 function paramsSetupListener(request, sender) { |
| 54 if (undefined != request._test_time_ms && | 108 if (undefined != request._test_time_ms && |
| 55 undefined != request._should_scroll && | 109 undefined != request._should_scroll && |
| 56 undefined != request._should_scroll_up && | 110 undefined != request._should_scroll_up && |
| 57 undefined != request._scroll_loop && | 111 undefined != request._scroll_loop && |
| 58 undefined != request._scroll_interval_ms && | 112 undefined != request._scroll_interval_ms && |
| 59 undefined != request._scroll_by_pixels) { | 113 undefined != request._scroll_by_pixels && |
| 114 undefined != request._tasks) { | |
| 60 // Update test parameters from content script. | 115 // Update test parameters from content script. |
| 61 test_time_ms = request._test_time_ms; | 116 test_time_ms = request._test_time_ms; |
| 62 should_scroll = request._should_scroll; | 117 should_scroll = request._should_scroll; |
| 63 should_scroll_up = request._should_scroll_up; | 118 should_scroll_up = request._should_scroll_up; |
| 64 scroll_loop = request._scroll_loop; | 119 scroll_loop = request._scroll_loop; |
| 65 scroll_interval_ms = request._scroll_interval_ms; | 120 scroll_interval_ms = request._scroll_interval_ms; |
| 66 scroll_by_pixels = request._scroll_by_pixels; | 121 scroll_by_pixels = request._scroll_by_pixels; |
| 122 task_list = parseTaskList(request._tasks); | |
| 123 if (task_list.length != 0) | |
| 124 tasks = task_list; | |
| 67 time_ratio = 3600 * 1000 / test_time_ms; // default test time is 1 hour | 125 time_ratio = 3600 * 1000 / test_time_ms; // default test time is 1 hour |
| 68 chrome.extension.onRequest.removeListener(paramsSetupListener); | 126 chrome.extension.onRequest.removeListener(paramsSetupListener); |
| 69 chrome.extension.onRequest.addListener(testListener); | 127 chrome.extension.onRequest.addListener(testListener); |
| 70 setTimeout(setupTest, 1000); | 128 setTimeout(setupTest, 1000); |
| 71 } else { | 129 } else { |
| 72 console.log("Error. Test parameters not received."); | 130 console.log("Error. Test parameters not received."); |
| 73 } | 131 } |
| 74 } | 132 } |
| 75 ); | 133 ); |
| 76 | 134 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 chrome.extension.onRequest.addListener(testListener); | 244 chrome.extension.onRequest.addListener(testListener); |
| 187 setupTest(); | 245 setupTest(); |
| 188 }); | 246 }); |
| 189 | 247 |
| 190 | 248 |
| 191 </script> | 249 </script> |
| 192 | 250 |
| 193 <body> | 251 <body> |
| 194 </body> | 252 </body> |
| 195 </html> | 253 </html> |
| OLD | NEW |