Index: chrome/renderer/resources/extensions/platform_app.js |
diff --git a/chrome/renderer/resources/extensions/platform_app.js b/chrome/renderer/resources/extensions/platform_app.js |
index 0982a6a18ea0b4371208292f1fd14f6ed4d3b921..829fa3fe4c2d484bdc78f9b629781dec75da21a4 100644 |
--- a/chrome/renderer/resources/extensions/platform_app.js |
+++ b/chrome/renderer/resources/extensions/platform_app.js |
@@ -75,6 +75,22 @@ function disableMethods(object, objectName, methodNames, useThrowingStubs) { |
} |
/** |
+ * Deletes the given methods from the passed in objext. |
+ * |
+ * This may be needed for feature detection as ('methodName' in object) will |
+ * return false after this. |
+ * |
+ * @param {Object} object The object with methods to disable. The prototype is |
+ * preferred. |
+ * @param {Array.<string>} methodNames names of methods to delete. |
+ */ |
+function deleteMethods(object, methodNames) { |
+ $Array.forEach(methodNames, function(methodName) { |
+ delete object[methodName]; |
+ }); |
+} |
+ |
+/** |
* Replaces the given properties of the passed in object with stubs that log |
* 'not available' warnings to the console and return undefined when gotten. If |
* a property's setter is later invoked, the getter and setter are restored to |
@@ -145,15 +161,33 @@ function disableSetters(object, objectName, propertyNames, opt_messageSuffix) { |
}); |
} |
+/** |
+ * Deletes the given properties of the passed in object. |
+ * |
+ * This may be needed for feature detection as ('propertyName' in object) will |
+ * return false after this. |
+ * |
+ * @param {Object} object The object with properties to disable. |
+ * @param {Array.<string>} propertyNames names of properties to delete. |
+ */ |
+function deleteProperties(object, propertyNames) { |
+ $Array.forEach(propertyNames, function(propertyName) { |
+ delete object[propertyName]; |
+ }); |
+} |
+ |
// Disable benign Document methods. |
disableMethods(HTMLDocument.prototype, 'document', ['open', 'clear', 'close']); |
// Replace evil Document methods with exception-throwing stubs. |
disableMethods(HTMLDocument.prototype, 'document', ['write', 'writeln'], true); |
-// Disable history. |
-window.history = {}; |
arv (Not doing code reviews)
2014/04/22 13:54:42
This one could have been replaced with a definePro
Inactive
2014/04/22 14:43:54
Would be much simpler, let me give this a try.
Inactive
2014/04/22 14:59:59
Done, thanks. Much simpler indeed.
|
+// Disable history API. |
disableGetters(window.history, 'history', ['back', 'forward', 'go', 'length']); |
+// These are part of the HTML5 History API that are feature detected, so we |
+// remove them altogether, allowing apps to have fallback behavior. |
+deleteProperties(window.history, ['state']); |
+deleteMethods(History.prototype, ['pushState', 'replaceState']); |
// Disable find. |
disableMethods(Window.prototype, 'window', ['find']); |