summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsimonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-15 19:58:32 +0000
committersimonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-15 19:58:32 +0000
commitb7bd504476aea1084120dca578c309c08ff95629 (patch)
treec8695b33b66fdf7e9184af2e7c264eda77baf429
parent07a2c7735be6e3a79e22d05ed45c814b5cc91dc4 (diff)
downloadchromium_src-b7bd504476aea1084120dca578c309c08ff95629.zip
chromium_src-b7bd504476aea1084120dca578c309c08ff95629.tar.gz
chromium_src-b7bd504476aea1084120dca578c309c08ff95629.tar.bz2
[Chromoting] Let the webapp detect new clipboard text items when it gets focus.
BUG=117473 Review URL: http://codereview.chromium.org/9703003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126974 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--remoting/remoting.gyp1
-rw-r--r--remoting/webapp/clipboard.js65
-rw-r--r--remoting/webapp/clipboard_event_proto.js28
-rw-r--r--remoting/webapp/main.html1
-rw-r--r--remoting/webapp/manifest.json4
-rw-r--r--remoting/webapp/remoting.js26
6 files changed, 124 insertions, 1 deletions
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index 63510c4..a37d057 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -112,6 +112,7 @@
'webapp/client_plugin_v1.js',
'webapp/client_screen.js',
'webapp/client_session.js',
+ 'webapp/clipboard.js',
'webapp/connection_history.css',
'webapp/connection_history.js',
'webapp/connection_stats.css',
diff --git a/remoting/webapp/clipboard.js b/remoting/webapp/clipboard.js
new file mode 100644
index 0000000..dcf55d8
--- /dev/null
+++ b/remoting/webapp/clipboard.js
@@ -0,0 +1,65 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview
+ * A class for moving clipboard items between the plugin and the OS.
+ */
+
+'use strict';
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+/**
+ * @constructor
+ */
+remoting.Clipboard = function() {
+};
+
+/**
+ * @private
+ * @enum {string}
+ */
+remoting.Clipboard.prototype.ItemTypes = {
+ TEXT_TYPE: 'text/plain'
+};
+
+/**
+ * @private
+ * @type {string}
+ */
+remoting.Clipboard.prototype.recentItemText = "";
+
+/**
+ * Accepts a clipboard from the OS, and sends any changed clipboard items to
+ * the host.
+ *
+ * Currently only text items are supported.
+ *
+ * @param {remoting.ClipboardData} clipboardData
+ * @return {void} Nothing.
+ */
+remoting.Clipboard.prototype.toHost = function(clipboardData) {
+ if (!clipboardData || !clipboardData.types || !clipboardData.getData) {
+ return;
+ }
+ var textType = 'text/plain';
+ for (var i = 0; i < clipboardData.types.length; i++) {
+ var type = clipboardData.types[i];
+ if (type == this.ItemTypes.TEXT_TYPE) {
+ var item = clipboardData.getData(type);
+ if (!item) {
+ item = "";
+ }
+ if (item != this.recentItemText) {
+ // TODO(simonmorris): Pass the clipboard text item to the plugin.
+ this.recentItemText = item;
+ }
+ }
+ }
+};
+
+/** @type {remoting.Clipboard} */
+remoting.clipboard = null;
diff --git a/remoting/webapp/clipboard_event_proto.js b/remoting/webapp/clipboard_event_proto.js
new file mode 100644
index 0000000..8a95bb6
--- /dev/null
+++ b/remoting/webapp/clipboard_event_proto.js
@@ -0,0 +1,28 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file contains type definitions for the remoting.ClipboardEvent class,
+// which is a subclass of Event.
+// It is used only with JSCompiler to verify the type-correctness of our code.
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+/** @constructor
+ * @extends Event
+ */
+remoting.ClipboardData = function() {};
+
+/** @type {Array.<string>} */
+remoting.ClipboardData.prototype.types;
+
+/** @type {function(string): string} */
+remoting.ClipboardData.prototype.getData;
+
+/** @constructor
+ */
+remoting.ClipboardEvent = function() {};
+
+/** @type {remoting.ClipboardData} */
+remoting.ClipboardEvent.prototype.clipboardData;
diff --git a/remoting/webapp/main.html b/remoting/webapp/main.html
index 2e27a49..af72b2e 100644
--- a/remoting/webapp/main.html
+++ b/remoting/webapp/main.html
@@ -20,6 +20,7 @@ found in the LICENSE file.
<script src="client_plugin_v1.js"></script>
<script src="client_screen.js"></script>
<script src="client_session.js"></script>
+ <script src="clipboard.js"></script>
<script src="connection_history.js"></script>
<script src="connection_stats.js"></script>
<script src="daemon_plugin.js"></script>
diff --git a/remoting/webapp/manifest.json b/remoting/webapp/manifest.json
index cf707e4..6696918 100644
--- a/remoting/webapp/manifest.json
+++ b/remoting/webapp/manifest.json
@@ -25,7 +25,9 @@
"https://accounts.google.com/o/oauth2/*",
"https://www.google.com/accounts/*",
"https://www.googleapis.com/chromoting/*",
- "https://talkgadget.google.com/talkgadget/*"
+ "https://talkgadget.google.com/talkgadget/*",
+ "clipboardRead",
+ "clipboardWrite"
],
"plugins": [
{ "path": "remoting_host_plugin.dll", "public": false },
diff --git a/remoting/webapp/remoting.js b/remoting/webapp/remoting.js
index 15b0968..e7df0b3 100644
--- a/remoting/webapp/remoting.js
+++ b/remoting/webapp/remoting.js
@@ -44,6 +44,7 @@ remoting.init = function() {
document.getElementById('host-list-error'));
remoting.toolbar = new remoting.Toolbar(
document.getElementById('session-toolbar'));
+ remoting.clipboard = new remoting.Clipboard();
refreshEmail_();
var email = remoting.oauth2.getCachedEmail();
@@ -51,7 +52,9 @@ remoting.init = function() {
document.getElementById('current-email').innerText = email;
}
+ window.addEventListener('focus', pluginGotFocus_, false);
window.addEventListener('blur', pluginLostFocus_, false);
+ window.addEventListener('paste', pluginGotPaste_, false);
if (isHostModeSupported_()) {
var noShare = document.getElementById('chrome-os-no-share');
@@ -131,6 +134,29 @@ remoting.clearOAuth2 = function() {
};
/**
+ * Callback function called when the browser window gets focus.
+ */
+function pluginGotFocus_() {
+ /** @type {function(string): void} */
+ document.execCommand;
+ document.execCommand("paste");
+}
+
+/**
+ * Callback function called when the browser window gets a paste operation.
+ *
+ * @param {Event} eventUncast
+ * @return {boolean}
+ */
+function pluginGotPaste_(eventUncast) {
+ var event = /** @type {remoting.ClipboardEvent} */ eventUncast;
+ if (event && event.clipboardData) {
+ remoting.clipboard.toHost(event.clipboardData);
+ }
+ return false;
+}
+
+/**
* Callback function called when the browser window loses focus. In this case,
* release all keys to prevent them becoming 'stuck down' on the host.
*/