Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1447)

Side by Side Diff: ios/web/web_state/js/resources/message.js

Issue 1973683002: [ios] Protect JS messaging system from window.webkit object overriding. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Retain and restore the old implementation Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ios/web/web_state/web_state_impl_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }());
OLDNEW
« no previous file with comments | « no previous file | ios/web/web_state/web_state_impl_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698