Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / extensions / test / data / web_view / accept_touch_events / guest.js
blobbc3597e745c138964f553651a4568ec2fb38e5df
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var LOG = function(msg) {
6 window.console.log(msg);
7 };
9 var touchDiv;
10 var embedder;
12 function init() {
13 touchDiv = document.createElement('div');
14 touchDiv.innerText = 'With touch';
15 document.body.appendChild(touchDiv);
18 function handler() {}
20 function onAppCommand(command) {
21 LOG('onAppCommand, command = ' + command);
22 switch (command) {
23 case 'install-touch-handler':
24 touchDiv.addEventListener('touchstart', handler);
25 sendMessageToEmbedder('installed-touch-handler');
26 break;
27 case 'uninstall-touch-handler':
28 touchDiv.removeEventListener('touchstart', handler);
29 sendMessageToEmbedder('uninstalled-touch-handler');
30 break;
34 function sendMessageToEmbedder(message) {
35 if (!embedder) {
36 LOG('no embedder channel to send postMessage');
37 return;
40 embedder.postMessage(JSON.stringify([message]), '*');
43 window.addEventListener('message', function(e) {
44 embedder = e.source;
45 var data = JSON.parse(e.data);
46 if (data[0] == 'connect') {
47 sendMessageToEmbedder('connected');
49 });
51 window.onload = init;