Skip to content
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

Merged
merged 3 commits into from
Feb 22, 2018

Conversation

Rob--W
Copy link
Member

@Rob--W Rob--W commented Feb 16, 2018

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.

<select>
<option value="0">Disable text selection</option>
<option value="1">Enable text selection</option>
<option value="2">Enable enhanced text selection</option>
Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Collaborator

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 :-)

Copy link
Member Author

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) {
Copy link
Collaborator

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!?

Copy link
Member Author

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.",
Copy link
Collaborator

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?

Copy link
Member Author

@Rob--W Rob--W Feb 18, 2018

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.
@Rob--W Rob--W force-pushed the crx-migrate-pref-to-textLayerMode branch from 14d1b96 to c17da59 Compare February 18, 2018 11:16
@Rob--W
Copy link
Member Author

Rob--W commented Feb 18, 2018

@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 {

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a 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.
@Rob--W Rob--W force-pushed the crx-migrate-pref-to-textLayerMode branch from d491c45 to 9d55a1e Compare February 22, 2018 13:41
@Rob--W Rob--W merged commit a8a7d81 into mozilla:master Feb 22, 2018
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
…ayerMode

Fix regressions in preferences in Chrome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants