| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 // Scripts for the message handler. | 5 // Scripts for the message handler. |
| 6 | 6 |
| 7 goog.provide('__crWeb.message'); | 7 goog.provide('__crWeb.message'); |
| 8 | 8 |
| 9 goog.require('__crWeb.common'); | 9 goog.require('__crWeb.common'); |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // in serializing messageQueue_ to an invalid format. | 109 // in serializing messageQueue_ to an invalid format. |
| 110 var originalObjectToJSON = Object.prototype.toJSON; | 110 var originalObjectToJSON = Object.prototype.toJSON; |
| 111 if (originalObjectToJSON) | 111 if (originalObjectToJSON) |
| 112 delete Object.prototype.toJSON; | 112 delete Object.prototype.toJSON; |
| 113 | 113 |
| 114 queueObject.queue.forEach(function(command) { | 114 queueObject.queue.forEach(function(command) { |
| 115 var stringifiedMessage = __gCrWeb.common.JSONStringify({ | 115 var stringifiedMessage = __gCrWeb.common.JSONStringify({ |
| 116 "crwCommand": command, | 116 "crwCommand": command, |
| 117 "crwWindowId": __gCrWeb.windowId | 117 "crwWindowId": __gCrWeb.windowId |
| 118 }); | 118 }); |
| 119 // A web page can override |window.webkit| with any value. Deleting the |
| 120 // object ensures that original and working implementation of |
| 121 // window.webkit is restored. |
| 122 var oldWebkit = window.webkit; |
| 123 delete window.webkit; |
| 119 window.webkit.messageHandlers[queueObject.scheme].postMessage( | 124 window.webkit.messageHandlers[queueObject.scheme].postMessage( |
| 120 stringifiedMessage); | 125 stringifiedMessage); |
| 126 window.webkit = oldWebkit; |
| 121 }); | 127 }); |
| 122 queueObject.reset(); | 128 queueObject.reset(); |
| 123 | 129 |
| 124 if (originalObjectToJSON) { | 130 if (originalObjectToJSON) { |
| 125 // Restore Object.prototype.toJSON to prevent from breaking any | 131 // Restore Object.prototype.toJSON to prevent from breaking any |
| 126 // functionality on the page that depends on its custom implementation. | 132 // functionality on the page that depends on its custom implementation. |
| 127 Object.prototype.toJSON = originalObjectToJSON; | 133 Object.prototype.toJSON = originalObjectToJSON; |
| 128 } | 134 } |
| 129 }; | 135 }; |
| 130 }()); | 136 }()); |
| OLD | NEW |