Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
| 8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 htmlNode.classList.add('apps-v2'); | 23 htmlNode.classList.add('apps-v2'); |
| 24 } | 24 } |
| 25 | 25 |
| 26 console.log(remoting.getExtensionInfo()); | 26 console.log(remoting.getExtensionInfo()); |
| 27 l10n.localize(); | 27 l10n.localize(); |
| 28 | 28 |
| 29 remoting.stats = new remoting.ConnectionStats( | 29 remoting.stats = new remoting.ConnectionStats( |
| 30 document.getElementById('statistics')); | 30 document.getElementById('statistics')); |
| 31 remoting.formatIq = new remoting.FormatIq(); | 31 remoting.formatIq = new remoting.FormatIq(); |
| 32 | 32 |
| 33 remoting.clipboard = new remoting.Clipboard(); | |
| 34 var sandbox = | 33 var sandbox = |
| 35 /** @type {HTMLIFrameElement} */ (document.getElementById('wcs-sandbox')); | 34 /** @type {HTMLIFrameElement} */ (document.getElementById('wcs-sandbox')); |
| 36 remoting.wcsSandbox = new remoting.WcsSandboxContainer(sandbox.contentWindow); | 35 remoting.wcsSandbox = new remoting.WcsSandboxContainer(sandbox.contentWindow); |
| 37 | 36 |
| 38 // The plugin's onFocus handler sends a paste command to |window|, because | |
| 39 // it can't send one to the plugin element itself. | |
| 40 window.addEventListener('paste', pluginGotPaste_, false); | |
|
kelvinp
2015/04/09 00:28:26
moved to clipboard.js
| |
| 41 window.addEventListener('copy', pluginGotCopy_, false); | |
| 42 | |
| 43 remoting.initModalDialogs(); | 37 remoting.initModalDialogs(); |
| 44 | 38 |
| 45 remoting.testEvents = new base.EventSourceImpl(); | 39 remoting.testEvents = new base.EventSourceImpl(); |
| 46 /** @enum {string} */ | 40 /** @enum {string} */ |
| 47 remoting.testEvents.Names = { | 41 remoting.testEvents.Names = { |
| 48 uiModeChanged: 'uiModeChanged' | 42 uiModeChanged: 'uiModeChanged' |
| 49 }; | 43 }; |
| 50 remoting.testEvents.defineEvents(base.values(remoting.testEvents.Names)); | 44 remoting.testEvents.defineEvents(base.values(remoting.testEvents.Names)); |
| 51 } | 45 } |
| 52 | 46 |
| 53 /** | 47 /** |
| 54 * @return {string} Information about the current extension. | 48 * @return {string} Information about the current extension. |
| 55 */ | 49 */ |
| 56 remoting.getExtensionInfo = function() { | 50 remoting.getExtensionInfo = function() { |
| 57 var v2OrLegacy = base.isAppsV2() ? " (v2)" : " (legacy)"; | 51 var v2OrLegacy = base.isAppsV2() ? " (v2)" : " (legacy)"; |
| 58 var manifest = chrome.runtime.getManifest(); | 52 var manifest = chrome.runtime.getManifest(); |
| 59 if (manifest && manifest.version) { | 53 if (manifest && manifest.version) { |
| 60 var name = remoting.app.getApplicationName(); | 54 var name = remoting.app.getApplicationName(); |
| 61 return name + ' version: ' + manifest.version + v2OrLegacy; | 55 return name + ' version: ' + manifest.version + v2OrLegacy; |
| 62 } else { | 56 } else { |
| 63 return 'Failed to get product version. Corrupt manifest?'; | 57 return 'Failed to get product version. Corrupt manifest?'; |
| 64 } | 58 } |
| 65 }; | 59 }; |
| 66 | 60 |
| 67 /** | 61 /** |
| 68 * Callback function called when the browser window gets a paste operation. | |
| 69 * | |
| 70 * @param {Event} event | |
| 71 * @return {void} Nothing. | |
| 72 */ | |
| 73 function pluginGotPaste_(event) { | |
| 74 if (event && event.clipboardData) { | |
| 75 remoting.clipboard.toHost(event.clipboardData); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 /** | |
| 80 * Callback function called when the browser window gets a copy operation. | |
| 81 * | |
| 82 * @param {Event} event | |
| 83 * @return {void} Nothing. | |
| 84 */ | |
| 85 function pluginGotCopy_(event) { | |
| 86 if (event && event.clipboardData) { | |
| 87 if (remoting.clipboard.toOs(event.clipboardData)) { | |
| 88 // The default action may overwrite items that we added to clipboardData. | |
| 89 event.preventDefault(); | |
| 90 } | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 /** | |
| 95 * Return the current time as a formatted string suitable for logging. | 62 * Return the current time as a formatted string suitable for logging. |
| 96 * | 63 * |
| 97 * @return {string} The current time, formatted as [mmdd/hhmmss.xyz] | 64 * @return {string} The current time, formatted as [mmdd/hhmmss.xyz] |
| 98 */ | 65 */ |
| 99 remoting.timestamp = function() { | 66 remoting.timestamp = function() { |
| 100 /** | 67 /** |
| 101 * @param {number} num A number. | 68 * @param {number} num A number. |
| 102 * @param {number} len The required length of the answer. | 69 * @param {number} len The required length of the answer. |
| 103 * @return {string} The number, formatted as a string of the specified length | 70 * @return {string} The number, formatted as a string of the specified length |
| 104 * by prepending zeroes as necessary. | 71 * by prepending zeroes as necessary. |
| 105 */ | 72 */ |
| 106 var pad = function(num, len) { | 73 var pad = function(num, len) { |
| 107 var result = num.toString(); | 74 var result = num.toString(); |
| 108 if (result.length < len) { | 75 if (result.length < len) { |
| 109 result = new Array(len - result.length + 1).join('0') + result; | 76 result = new Array(len - result.length + 1).join('0') + result; |
| 110 } | 77 } |
| 111 return result; | 78 return result; |
| 112 }; | 79 }; |
| 113 var now = new Date(); | 80 var now = new Date(); |
| 114 var timestamp = pad(now.getMonth() + 1, 2) + pad(now.getDate(), 2) + '/' + | 81 var timestamp = pad(now.getMonth() + 1, 2) + pad(now.getDate(), 2) + '/' + |
| 115 pad(now.getHours(), 2) + pad(now.getMinutes(), 2) + | 82 pad(now.getHours(), 2) + pad(now.getMinutes(), 2) + |
| 116 pad(now.getSeconds(), 2) + '.' + pad(now.getMilliseconds(), 3); | 83 pad(now.getSeconds(), 2) + '.' + pad(now.getMilliseconds(), 3); |
| 117 return '[' + timestamp + ']'; | 84 return '[' + timestamp + ']'; |
| 118 }; | 85 }; |
| OLD | NEW |