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

Unified Diff: ios/web/web_state/js/resources/dialog_overrides.js

Issue 1806043004: [ios] Refactored dialogs suppression. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments Created 4 years, 9 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 | « ios/web/public/web_state/ui/crw_web_delegate.h ('k') | ios/web/web_state/ui/crw_web_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/web_state/js/resources/dialog_overrides.js
diff --git a/ios/web/web_state/js/resources/dialog_overrides.js b/ios/web/web_state/js/resources/dialog_overrides.js
index a127becd3823a6e070d994b34a73f3bca416032b..a8f31c7d934ae89465cbbd546e79c17642946550 100644
--- a/ios/web/web_state/js/resources/dialog_overrides.js
+++ b/ios/web/web_state/js/resources/dialog_overrides.js
@@ -6,49 +6,37 @@ goog.provide('__crWeb.dialogOverrides');
goog.require('__crWeb.core');
-// Namespace for this module.
__gCrWeb.dialogOverrides = {};
-// Beginning of anonymous object.
(function() {
/*
- * Install a wrapper around functions displaying dialogs in order to catch
- * code displaying dialog.
+ * Installs a wrapper around geolocation functions displaying dialogs in order
+ * to control their suppression.
*
* Since the Javascript on the page may cache the value of those functions
* and invoke them later, we must only install the wrapper once and change
* their behaviour when required.
*
- * Returns a function that allows changing the value of the two booleans
- * |suppressDialogs| and |notifyAboutDialogs| that are tested by the wrappers.
+ * Returns a function that allows changing the value of
+ * |suppressGeolocationDialogs| that is tested by the wrappers.
*/
- var installDialogOverridesMethods = function() {
- var suppressDialogs = false;
- var notifyAboutDialogs = false;
+ var installGeolocationDialogOverridesMethods = function() {
+ var suppressGeolocationDialogs = false;
- // Returns a wrapper function around |originalDialog|. The wrapper may
- // suppress the dialog and notify host about show/suppress.
+ // Returns a wrapper function around original dialog function. The wrapper
+ // may suppress the dialog and notify host.
var makeDialogWrapper = function(originalDialogGetter) {
return function() {
- if (!suppressDialogs) {
+ if (suppressGeolocationDialogs) {
+ __gCrWeb.message.invokeOnHost({
+ 'command': 'geolocationDialog.suppressed'
+ });
+ } else {
return originalDialogGetter().apply(null, arguments);
- } else if (notifyAboutDialogs) {
- __gCrWeb.message.invokeOnHost({'command': 'dialog.suppressed'});
}
};
};
- // Install wrapper around the following properties of |window|.
- var wrappedFunctionNames = ['alert', 'confirm', 'prompt', 'open'];
- var len = wrappedFunctionNames.length;
- for (var i = 0; i < len; i++) {
- (function(wrappedFunctionName) {
- var wrappedDialogMethod = window[wrappedFunctionName];
- window[wrappedFunctionName] = makeDialogWrapper(
- function() { return wrappedDialogMethod; });
- })(wrappedFunctionNames[i]);
- }
-
// Reading or writing to the property 'geolocation' too early breaks
// the API. Make a copy of navigator and stub in the required methods
// without touching the property. See crbug.com/280818 for more
@@ -99,16 +87,14 @@ __gCrWeb.dialogOverrides = {};
/** @suppress {const} */
navigator = stubNavigator;
- // Returns the closure allowing to change |suppressDialogs| and
- // |notifyAboutDialogs| variables.
- return function(setEnabled, setNotify) {
- suppressDialogs = setEnabled;
- notifyAboutDialogs = setNotify;
+ // Returns the closure allowing to change |suppressGeolocationDialogs|.
+ return function(setEnabled) {
+ suppressGeolocationDialogs = setEnabled;
};
};
- // Override certain methods that produce dialogs. This needs to be installed
- // after other window methods overrides.
- __gCrWeb['setSuppressDialogs'] = installDialogOverridesMethods();
+ // Override geolocation methods that produce dialogs.
+ __gCrWeb['setSuppressGeolocationDialogs'] =
+ installGeolocationDialogOverridesMethods();
}()); // End of anonymous object
« no previous file with comments | « ios/web/public/web_state/ui/crw_web_delegate.h ('k') | ios/web/web_state/ui/crw_web_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698