-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix regressions in preferences in Chrome #9490
Fix regressions in preferences in Chrome #9490
Conversation
394a716
to
6e646b8
Compare
<select> | ||
<option value="0">Disable text selection</option> | ||
<option value="1">Enable text selection</option> | ||
<option value="2">Enable enhanced text selection</option> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a good idea to mention here that this mode is still somewhat experimental, and might not be fully stable yet; as noted in https://github.com/mozilla/pdf.js/pull/9490/files#diff-a0d82fd09027b92c6e7bed99dc735626R90.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided against appending (experimental)
because then the dropdown item would become too wide. In #7584 I do not see any open issues that significantly degrade the user experience, so I think that it's safe to expose the enhanced text layer option without declaring it experimental.
Why do we feel the need to explicitly add "experimental" to this option? If it's good enough to use in production, then there is no need for the label. If there are known issues, then they should be reported in an issue and linked to the meta bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #7584 I do not see any open issues that significantly degrade the user experience, so I think that it's safe to expose the enhanced text layer option without declaring it experimental.
I'm not sure that I agree with that assessment, since the open TODOs are related to performance.
More generally the performance of the "enhanced" text-selection mode might not be that good in some edge-cases, in particular it might be quite bad in the "one div per character" case (i.e. for badly generated files where we're not able to coalesce the text).
Also, we've got fairly limited test-coverage currently, so it's a bit difficult to tell what the real state of the enhanced text-selection mode really is in my opinion.
However if you're not concerned too concerned about any of the above points, I suppose that you can keep the existing wording! Do as you wish here, I don't care too much :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair points there. I have reworded it to "Enable enhanced mode (experimental)" (and omitted "text selection" for brevity).
web/chromecom.js
Outdated
items.cursorToolOnLoad = 1; | ||
} | ||
delete items.enableHandToolOnLoad; | ||
if (items.textLayerMode !== 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the condition be items.textLayerMode === 1
here, given that otherwise a non-default textLayerMode
(as set by the user) will always be overwritten which seem strange!?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code here is only concerned with reading and parsing managed preferences. When getPreferences(items)
is called, the given items specify the values to retrieve, along with the default values if no explicit value is set by the user. Lines 308 - 310 briefly state the purpose of the code (without explicitly stating the implementation details that I've written here).
@@ -26,6 +26,11 @@ | |||
], | |||
"default": 0 | |||
}, | |||
"enableHandToolOnLoad": { | |||
"description": "Deprecated. Set cursorToolOnLoad to 1 to enable the hand tool by default.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using an all-caps DEPRECATED
string instead, here and elsewhere, to make it stand out a bit more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me.
This partially reverts df0836b. The entry in preferences_schema.json is restored because that is required to make managed preferences visible to the extension code. The default key is still removed from default_preferences.json, because this change only concerns the Chrome extension, not the other parts of PDF.js. To account for the missing key, the deprecated key was added back in chromecom.js The key needs to be restored in preferences_schema.json too, because that's the only way to make managed preferences visible. I'm using `Object.assign`, which was introduced in Chrome 45, so the preference module will break in Chrome 45 and earlier. This is fine, because we do not support Chrome before 49.
14d1b96
to
c17da59
Compare
@Snuffleupagus Thanks for the review. I have amended all commits with the requested changes, this is the summary of changes: diff --git a/extensions/chromium/preferences_schema.json b/extensions/chromium/preferences_schema.json
index e0e69b5d..46d2d0c6 100644
--- a/extensions/chromium/preferences_schema.json
+++ b/extensions/chromium/preferences_schema.json
@@ -27,7 +27,7 @@
"default": 0
},
"enableHandToolOnLoad": {
- "description": "Deprecated. Set cursorToolOnLoad to 1 to enable the hand tool by default.",
+ "description": "DEPRECATED. Set cursorToolOnLoad to 1 to enable the hand tool by default.",
"type": "boolean",
"default": false
},
@@ -76,12 +76,12 @@
"default": false
},
"disableTextLayer": {
- "description": "Deprecated. Set textLayerMode to 0 to disable the text selection layer by default.",
+ "description": "DEPRECATED. Set textLayerMode to 0 to disable the text selection layer by default.",
"type": "boolean",
"default": false
},
"enhanceTextSelection": {
- "description": "Deprecated. Set textLayerMode to 2 to use the enhanced text selection layer by default.",
+ "description": "DEPRECATED. Set textLayerMode to 2 to use the enhanced text selection layer by default.",
"type": "boolean",
"default": false
},
diff --git a/gulpfile.js b/gulpfile.js
index b1262cfa..3568da31 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -194,10 +194,10 @@ function checkChromePreferencesFile(chromePrefsPath, webPrefsPath) {
var chromePrefsKeys = Object.keys(chromePrefs.properties);
chromePrefsKeys = chromePrefsKeys.filter(function (key) {
var description = chromePrefs.properties[key].description;
- // Deprecated keys are allowed. The code maintained is responsible for
- // adding migration logic to
+ // Deprecated keys are allowed in the managed preferences file.
+ // The code maintained is responsible for adding migration logic to
// extensions/chromium/options/migration.js and web/chromecom.js .
- return !description || !description.startsWith('Deprecated.');
+ return !description || !description.startsWith('DEPRECATED.');
});
chromePrefsKeys.sort();
var webPrefs = JSON.parse(fs.readFileSync(webPrefsPath).toString());
diff --git a/web/chromecom.js b/web/chromecom.js
index 238018cc..a4605b35 100644
--- a/web/chromecom.js
+++ b/web/chromecom.js
@@ -320,15 +320,21 @@ class ChromePreferences extends BasePreferences {
chrome.storage.managed.get(defaultManagedPrefs, function(items) {
items = items || defaultManagedPrefs;
- // Migration code for https://github.com/mozilla/pdf.js/pull/7635.
+ // Migration logic for deprecated preferences: If the new preference
+ // is not defined by an administrator (i.e. the value is the same as
+ // the default value), and a deprecated preference is set with a
+ // non-default value, migrate the deprecated preference value to the
+ // new preference value.
// Never remove this, because we have no means of modifying managed
// preferences.
+
+ // Migration code for https://github.com/mozilla/pdf.js/pull/7635.
if (items.enableHandToolOnLoad && !items.cursorToolOnLoad) {
- // if the old enableHandToolOnLoad has a non-default value,
- // and cursorToolOnLoad has a default value, migrate.
items.cursorToolOnLoad = 1;
}
delete items.enableHandToolOnLoad;
+
+ // Migration code for https://github.com/mozilla/pdf.js/pull/9479.
if (items.textLayerMode !== 1) {
if (items.disableTextLayer) {
items.textLayerMode = 0;
@@ -338,6 +344,7 @@ class ChromePreferences extends BasePreferences {
}
delete items.disableTextLayer;
delete items.enhanceTextSelection;
+
getPreferences(items);
});
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's fold the Clearly mark "enhanced text selection" as "experimental"
commit into the base one instead, i,e. [CRX] Make textLayerMode pref visible and add migration logic
.
r=me with that fixed; thanks for the patch!
In a1cfa5f, the textLayerMode preference was introduced, to replace the disableTextLayer and enhanceTextSelection preferences. As a result, the text selection preference was no longer visible in Chrome (because preferences are only rendered by default for boolean preferences, not for enumerations). This commit adds the necessary bits to extensions/chromium/options/options.{html,js} so that the textLayerMode preference can be changed again. Also, migration logic has been added to move over preferences from the old to the new names: - In web/chromecom.js, the logic is added to translate preferences that were set by an administrator (it is read-only, so this layer is unavoidable). - In extensions/chromium/options/migration.js, similar logic is added, except in this case the preference storage is writable, so this migration logic happens only once. The "enhanced text selection" mode is still experimental, so it has been marked as experimental to signal that there may be bugs. The list of tasks that block promotion to stable is at mozilla#7584.
Deprecated keys are removed from web/default_preferences.json, but still maintained in managed_preferences.json.
d491c45
to
9d55a1e
Compare
…ayerMode Fix regressions in preferences in Chrome
Fixes #9489
The two commits can be reviewed in isolation, see their commit messages.
I've tested this PR by opening the preferences page and observing that the preferences are back. Also, I will shortly open a new bug report to prevent such regressions from happening again.