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