- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / load_pepper_plugin.html
1 <html>
2 <head>
3 <title>Initial Title</title>
4 <script>
5 var QueryString = function() {
6   // Allows access to query parameters on the URL; e.g., given a URL like:
7   //    http://<server>/my.html?test=123&bob=123
8   // Parameters can then be accessed via QueryString.test or QueryString.bob.
9   var params = {};
10   // RegEx to split out values by &.
11   var r = /([^&=]+)=?([^&]*)/g;
12   // Lambda function for decoding extracted match values. Replaces '+' with
13   // space so decodeURIComponent functions properly.
14   function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); }
15   var match;
16   while (match = r.exec(window.location.search.substring(1)))
17     params[d(match[1])] = d(match[2]);
18   return params;
19 }();
20
21 var mimeType = QueryString.mimetype;
22
23 function inject() {
24   var child = document.createElement('div');
25   child.innerHTML = '<object type="' + mimeType + '" id="plugin" border=1>' +
26                     '  <b>You should not see this text!</b>' +
27                     '</object>';
28   document.getElementById('content').appendChild(child);
29   // Plugins are loaded synchronously during layout, so the plugin has either
30   // been loaded or blocked at this point.
31   var plugin = document.getElementById('plugin');
32   try {
33     // All Pepper plugins support postMessage().
34     plugin.postMessage('hello');
35     // If we do not get an exception, the Pepper plugin is loaded.
36     document.title = 'Loaded';
37   } catch (e) {
38     console.log(e.toString());
39     if (e.toString() ==
40         "TypeError: Object #<HTMLObjectElement> has no method 'postMessage'") {
41       document.title = 'Not Loaded';
42     } else {
43       var errorMessage = 'Unexpected Exception: ' + e.toString(); 
44       document.title = errorMessage;
45       console.log(errorMessage);
46     }
47   }
48 }
49 </script>
50 </head>
51 <body onload='inject();'>
52 <div id='content'></div>
53 </body>
54 </html>