Chromium Code Reviews| 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 // If |window.webkit| has been overridden deleting the object restores | |
|
Jackie Quinn
2016/05/12 17:33:58
Well that's nifty! Probably still good to have a c
Eugene But (OOO till 7-30)
2016/05/12 18:44:41
I did my best changing the comment :)
| |
| 120 // the original implementation. | |
| 121 var oldWebkit = window.webkit; | |
| 122 delete window.webkit; | |
| 119 window.webkit.messageHandlers[queueObject.scheme].postMessage( | 123 window.webkit.messageHandlers[queueObject.scheme].postMessage( |
| 120 stringifiedMessage); | 124 stringifiedMessage); |
| 125 window.webkit = oldWebkit; | |
| 121 }); | 126 }); |
| 122 queueObject.reset(); | 127 queueObject.reset(); |
| 123 | 128 |
| 124 if (originalObjectToJSON) { | 129 if (originalObjectToJSON) { |
| 125 // Restore Object.prototype.toJSON to prevent from breaking any | 130 // Restore Object.prototype.toJSON to prevent from breaking any |
| 126 // functionality on the page that depends on its custom implementation. | 131 // functionality on the page that depends on its custom implementation. |
| 127 Object.prototype.toJSON = originalObjectToJSON; | 132 Object.prototype.toJSON = originalObjectToJSON; |
| 128 } | 133 } |
| 129 }; | 134 }; |
| 130 }()); | 135 }()); |
| OLD | NEW |