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

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

Issue 2581883002: [ios] Do not JSON encode messages sent from WebView to native code. (Closed)
Patch Set: Actually addressed review comments :) Created 3 years, 12 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
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if (typeof __gCrWeb.windowId != 'string') { 70 if (typeof __gCrWeb.windowId != 'string') {
71 return; 71 return;
72 } 72 }
73 // Some pages/plugins implement Object.prototype.toJSON, which can result 73 // Some pages/plugins implement Object.prototype.toJSON, which can result
74 // in serializing messageQueue_ to an invalid format. 74 // in serializing messageQueue_ to an invalid format.
75 var originalObjectToJSON = Object.prototype.toJSON; 75 var originalObjectToJSON = Object.prototype.toJSON;
76 if (originalObjectToJSON) 76 if (originalObjectToJSON)
77 delete Object.prototype.toJSON; 77 delete Object.prototype.toJSON;
78 78
79 queueObject.queue.forEach(function(command) { 79 queueObject.queue.forEach(function(command) {
80 var stringifiedMessage = __gCrWeb.common.JSONStringify({
81 "crwCommand": command,
82 "crwWindowId": __gCrWeb['windowId']
83 });
84 // A web page can override |window.webkit| with any value. Deleting the 80 // A web page can override |window.webkit| with any value. Deleting the
85 // object ensures that original and working implementation of 81 // object ensures that original and working implementation of
86 // window.webkit is restored. 82 // window.webkit is restored.
87 var oldWebkit = window.webkit; 83 var oldWebkit = window.webkit;
88 delete window['webkit']; 84 delete window['webkit'];
89 window.webkit.messageHandlers[queueObject.scheme].postMessage( 85 window.webkit.messageHandlers[queueObject.scheme].postMessage({
90 stringifiedMessage); 86 "crwCommand": command,
87 "crwWindowId": __gCrWeb['windowId']
88 });
91 window.webkit = oldWebkit; 89 window.webkit = oldWebkit;
92 }); 90 });
93 queueObject.reset(); 91 queueObject.reset();
94 92
95 if (originalObjectToJSON) { 93 if (originalObjectToJSON) {
96 // Restore Object.prototype.toJSON to prevent from breaking any 94 // Restore Object.prototype.toJSON to prevent from breaking any
97 // functionality on the page that depends on its custom implementation. 95 // functionality on the page that depends on its custom implementation.
98 Object.prototype.toJSON = originalObjectToJSON; 96 Object.prototype.toJSON = originalObjectToJSON;
99 } 97 }
100 }; 98 };
101 }()); 99 }());
OLDNEW
« no previous file with comments | « components/translate/ios/browser/language_detection_controller.mm ('k') | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698