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

Unified Diff: chrome/renderer/resources/event_bindings.js

Issue 2754014: Merge 48667 - Prevent extensions from clobbering JSON implementation that ext... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/375/src/
Patch Set: Created 10 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/renderer/resources/extension_process_bindings.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/resources/event_bindings.js
===================================================================
--- chrome/renderer/resources/event_bindings.js (revision 49570)
+++ chrome/renderer/resources/event_bindings.js (working copy)
@@ -9,7 +9,41 @@
native function DetachEvent(eventName);
var chromeHidden = GetChromeHidden();
+
+ // Local implementation of JSON.parse & JSON.stringify that protect us
+ // from being clobbered by an extension.
+ chromeHidden.JSON = new (function() {
+ const $Object = Object;
+ const $Array = Array;
+ const $jsonStringify = JSON.stringify;
+ const $jsonParse = JSON.parse;
+ this.stringify = function(thing) {
+ var customizedObjectToJSON = $Object.prototype.toJSON;
+ var customizedArrayToJSON = $Array.prototype.toJSON;
+ if (customizedObjectToJSON !== undefined) {
+ $Object.prototype.toJSON = null;
+ }
+ if (customizedArrayToJSON !== undefined) {
+ $Array.prototype.toJSON = null;
+ }
+ try {
+ return $jsonStringify(thing);
+ } finally {
+ if (customizedObjectToJSON !== undefined) {
+ $Object.prototype.toJSON = customizedObjectToJSON;
+ }
+ if (customizedArrayToJSON !== undefined) {
+ $Array.prototype.toJSON = customizedArrayToJSON;
+ }
+ }
+ };
+
+ this.parse = function(thing) {
+ return $jsonParse(thing);
+ };
+ })();
+
// Event object. If opt_eventName is provided, this object represents
// the unique instance of that named event, and dispatching an event
// with that name will route through this object's listeners.
@@ -53,7 +87,7 @@
chromeHidden.Event.dispatchJSON = function(name, args) {
if (attachedNamedEvents[name]) {
if (args) {
- args = JSON.parse(args);
+ args = chromeHidden.JSON.parse(args);
}
return attachedNamedEvents[name].dispatch.apply(
attachedNamedEvents[name], args);
« no previous file with comments | « no previous file | chrome/renderer/resources/extension_process_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698