OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var REQUEST_TO_COMM_CHANNEL_1 = 'connect'; | 5 var REQUEST_TO_COMM_CHANNEL_1 = 'connect'; |
6 var REQUEST_TO_COMM_CHANNEL_2 = 'connect_request'; | 6 var REQUEST_TO_COMM_CHANNEL_2 = 'connect_request'; |
7 var RESPONSE_FROM_COMM_CHANNEL_1 = 'connected'; | 7 var RESPONSE_FROM_COMM_CHANNEL_1 = 'connected'; |
8 var RESPONSE_FROM_COMM_CHANNEL_2 = 'connected_response'; | 8 var RESPONSE_FROM_COMM_CHANNEL_2 = 'connected_response'; |
9 | 9 |
10 function createWebview() { | 10 function createWebview() { |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 newwebview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 340 newwebview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
341 }); | 341 }); |
342 | 342 |
343 document.body.appendChild(newwebview); | 343 document.body.appendChild(newwebview); |
344 // attach the new window to the new <webview>. | 344 // attach the new window to the new <webview>. |
345 console.log('Step 3: attaches the new webview.'); | 345 console.log('Step 3: attaches the new webview.'); |
346 e.window.attach(newwebview); | 346 e.window.attach(newwebview); |
347 }); | 347 }); |
348 | 348 |
349 window.addEventListener('message', function(e) { | 349 window.addEventListener('message', function(e) { |
350 if (e.source != newwebview.contentWindow) | 350 if (!newwebview || e.source != newwebview.contentWindow) |
351 return; | 351 return; |
352 var data = JSON.parse(e.data); | 352 var data = JSON.parse(e.data); |
353 if (data == RESPONSE_FROM_COMM_CHANNEL_1 && | 353 if (data == RESPONSE_FROM_COMM_CHANNEL_1 && |
354 e.source == newwebview.contentWindow) { | 354 e.source == newwebview.contentWindow) { |
355 console.log('Step 5: a communication channel has been established ' + | 355 console.log('Step 5: a communication channel has been established ' + |
356 'with the new webview.'); | 356 'with the new webview.'); |
357 chrome.send('testResult', [true]); | 357 chrome.send('testResult', [true]); |
358 return; | 358 return; |
359 } else { | 359 } else { |
360 chrome.send('testResult', [false]); | 360 chrome.send('testResult', [false]); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 console.log('Step 5: check the result of content script injected again.'); | 437 console.log('Step 5: check the result of content script injected again.'); |
438 webview.executeScript({ | 438 webview.executeScript({ |
439 code: 'document.body.style.backgroundColor;' | 439 code: 'document.body.style.backgroundColor;' |
440 }, onGetBackgroundExecuted); | 440 }, onGetBackgroundExecuted); |
441 } | 441 } |
442 }); | 442 }); |
443 | 443 |
444 webview.src = url; | 444 webview.src = url; |
445 document.body.appendChild(webview); | 445 document.body.appendChild(webview); |
446 } | 446 } |
OLD | NEW |