Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / test / data / web_view / dialog / inject_dialog.js
blob5d7a31eafa0d1e4e3b653a0d6ada1e41eee9b2a2
1 // Copyright 2013 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 embedder = null;
7 function reportConnected() {
8 var msg = ['connected'];
9 embedder.postMessage(JSON.stringify(msg), '*');
12 function reportAlertCompletion(messageText) {
13 window.alert(messageText);
14 var msg = ['alert-dialog-done'];
15 embedder.postMessage(JSON.stringify(msg), '*');
18 function reportConfirmDialogResult(messageText) {
19 var result = window.confirm(messageText);
20 var msg = ['confirm-dialog-result', result];
21 embedder.postMessage(JSON.stringify(msg), '*');
24 function reportPromptDialogResult(messageText, defaultPromptText) {
25 var result = window.prompt(messageText, defaultPromptText);
26 var msg = ['prompt-dialog-result', result];
27 embedder.postMessage(JSON.stringify(msg), '*');
30 window.addEventListener('message', function(e) {
31 embedder = e.source;
32 var data = JSON.parse(e.data);
33 switch (data[0]) {
34 case 'connect': {
35 reportConnected();
36 break;
38 case 'start-confirm-dialog-test': {
39 var messageText = data[1];
40 reportConfirmDialogResult(messageText);
41 break;
43 case 'start-alert-dialog-test': {
44 var messageText = data[1];
45 reportAlertCompletion(messageText);
46 break;
48 case 'start-prompt-dialog-test': {
49 var messageText = data[1];
50 var defaultPromptText = data[2];
51 reportPromptDialogResult(messageText, defaultPromptText);
52 break;
55 });