From e394659c9bdbbb8df6509ca636a9324c8e5c1dfe Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 10 Jul 2017 19:50:24 -0700 Subject: [PATCH] Using Chromium's spellchecker fixes #9880 Auditors: @bridiver, @bbondy, @bsclifton --- app/browser/reducers/spellCheckReducer.js | 21 -------------- app/extensions.js | 1 - .../brave/content/scripts/spellCheck.js | 22 -------------- .../brave/locales/en-US/menu.properties | 2 +- app/index.js | 2 -- app/locale.js | 2 +- app/spellCheck.js | 7 ----- docs/appActions.md | 22 -------------- js/actions/appActions.js | 24 --------------- js/constants/appConstants.js | 1 - js/constants/messages.js | 1 - js/contextMenus.js | 29 ++++++++++--------- js/stores/appStore.js | 4 --- package.json | 1 - 14 files changed, 18 insertions(+), 121 deletions(-) delete mode 100644 app/browser/reducers/spellCheckReducer.js delete mode 100644 app/extensions/brave/content/scripts/spellCheck.js diff --git a/app/browser/reducers/spellCheckReducer.js b/app/browser/reducers/spellCheckReducer.js deleted file mode 100644 index 8fcfd04ebc5..00000000000 --- a/app/browser/reducers/spellCheckReducer.js +++ /dev/null @@ -1,21 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -'use strict' - -const appConstants = require('../../../js/constants/appConstants') -const tabs = require('../tabs') -const {makeImmutable} = require('../../common/state/immutableUtil') - -const spellCheckReducer = (state, action, immutableAction) => { - action = immutableAction || makeImmutable(action) - switch (action.get('actionType')) { - case appConstants.APP_ADD_WORD: - tabs.sendToAll('add-word', action.get('word')) - break - } - return state -} - -module.exports = spellCheckReducer diff --git a/app/extensions.js b/app/extensions.js index 8b96ec25569..ec6199cb71f 100644 --- a/app/extensions.js +++ b/app/extensions.js @@ -113,7 +113,6 @@ let generateBraveManifest = () => { getBraveExtUrl('about-blank.html') + '#*' ], js: [ - 'content/scripts/spellCheck.js', 'content/scripts/themeColor.js' ] }, diff --git a/app/extensions/brave/content/scripts/spellCheck.js b/app/extensions/brave/content/scripts/spellCheck.js deleted file mode 100644 index dd25116d3c8..00000000000 --- a/app/extensions/brave/content/scripts/spellCheck.js +++ /dev/null @@ -1,22 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -let cache = {} - -chrome.ipcRenderer.on('add-word', (e, word) => { - cache[word] = true -}) - -let lang = navigator.language.split('-')[0].split('_')[0] -chrome.webFrame.setSpellCheckProvider(lang || '', true, { - spellCheck: (word) => { - if (typeof cache[word] !== 'boolean') { - const result = !chrome.ipcRenderer.sendSync('is-misspelled', word) - cache[word] = result - return result - } else { - return cache[word] - } - } -}) diff --git a/app/extensions/brave/locales/en-US/menu.properties b/app/extensions/brave/locales/en-US/menu.properties index 84a42c1d0b5..2bb55a468ed 100644 --- a/app/extensions/brave/locales/en-US/menu.properties +++ b/app/extensions/brave/locales/en-US/menu.properties @@ -155,7 +155,7 @@ extensionsManager=Extensions… zoom=Zoom new=New learnSpelling=Learn Spelling -ignoreSpelling=Ignore Spelling +forgetLearnedSpelling=Forget Learned Spelling autoHideMenuBar=Menu Bar updateChannel=Update Channel licenseText=This software uses libraries from the FFmpeg project under the LGPLv2.1 diff --git a/app/index.js b/app/index.js index 3f0a6b35fe0..2506cd7d22c 100644 --- a/app/index.js +++ b/app/index.js @@ -69,7 +69,6 @@ const SiteHacks = require('./siteHacks') const CmdLine = require('./cmdLine') const UpdateStatus = require('../js/constants/updateStatus') const urlParse = require('./common/urlParse') -const spellCheck = require('./spellCheck') const locale = require('./locale') const contentSettings = require('../js/state/contentSettings') const privacy = require('../js/state/privacy') @@ -346,7 +345,6 @@ app.on('ready', () => { Autofill.init() Extensions.init() SiteHacks.init() - spellCheck.init() HttpsEverywhere.init() TrackingProtection.init() AdBlock.init() diff --git a/app/locale.js b/app/locale.js index dbf54f9b8a2..0508a3b980b 100644 --- a/app/locale.js +++ b/app/locale.js @@ -178,7 +178,7 @@ var rendererIdentifiers = function () { 'braveryStartUsingPayments', 'blockPopups', 'learnSpelling', - 'ignoreSpelling', + 'forgetLearnedSpelling', 'lookupSelection', // Other identifiers 'aboutBlankTitle', diff --git a/app/spellCheck.js b/app/spellCheck.js index 5919e5ec787..770acbf8d96 100644 --- a/app/spellCheck.js +++ b/app/spellCheck.js @@ -35,13 +35,6 @@ module.exports.init = () => { } e.returnValue = misspelled }) - ipcMain.on(messages.GET_MISSPELLING_INFO, (e, word) => { - const misspelled = isMisspelled(word) - e.returnValue = { - isMisspelled: misspelled, - suggestions: !misspelled ? [] : spellchecker.getCorrectionsForMisspelling(word) - } - }) appStore.addChangeListener(() => { let addedWords = appStore.getState().getIn(['dictionary', 'addedWords']) diff --git a/docs/appActions.md b/docs/appActions.md index b2515c36d75..08c0c15d20d 100644 --- a/docs/appActions.md +++ b/docs/appActions.md @@ -455,28 +455,6 @@ Hides a message in the notification bar -### addWord(word, learn) - -Adds a word to the dictionary - -**Parameters** - -**word**: `string`, The word to add - -**learn**: `boolean`, true if the word should be learned, false if ignored - - - -### setDictionary(locale) - -Adds a word to the dictionary - -**Parameters** - -**locale**: `string`, The locale to set for the dictionary - - - ### setLoginRequiredDetail(tabId, detail) Adds information about pending basic auth login requests diff --git a/js/actions/appActions.js b/js/actions/appActions.js index f5fefc1392d..72040554993 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -553,30 +553,6 @@ const appActions = { }) }, - /** - * Adds a word to the dictionary - * @param {string} word - The word to add - * @param {boolean} learn - true if the word should be learned, false if ignored - */ - addWord: function (word, learn) { - dispatch({ - actionType: appConstants.APP_ADD_WORD, - word, - learn - }) - }, - - /** - * Adds a word to the dictionary - * @param {string} locale - The locale to set for the dictionary - */ - setDictionary: function (locale) { - dispatch({ - actionType: appConstants.APP_SET_DICTIONARY, - locale - }) - }, - /** * Adds information about pending basic auth login requests * @param {number} tabId - The tabId that generated the request diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js index f8d6c4d80d0..3c77c81bea0 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -41,7 +41,6 @@ const appConstants = { APP_UPDATE_PUBLISHER_INFO: _, APP_SHOW_NOTIFICATION: _, /** @param {Object} detail */ APP_HIDE_NOTIFICATION: _, /** @param {string} message */ - APP_ADD_WORD: _, /** @param {string} word, @param {boolean} learn */ APP_SET_DICTIONARY: _, /** @param {string} locale */ APP_BACKUP_KEYS: _, APP_RECOVER_WALLET: _, diff --git a/js/constants/messages.js b/js/constants/messages.js index 2473ce0c53c..8c7e31a7cb7 100644 --- a/js/constants/messages.js +++ b/js/constants/messages.js @@ -77,7 +77,6 @@ const messages = { RELOAD: _, DETACH: _, IS_MISSPELLED: _, /** @arg {string} word, the word to check */ - GET_MISSPELLING_INFO: _, /** @arg {string} word, the word to lookup */ PASSWORD_DETAILS_UPDATED: _, /** @arg {Object} passwords app state */ PASSWORD_SITE_DETAILS_UPDATED: _, /** @arg {Object} passwords app state */ // Init diff --git a/js/contextMenus.js b/js/contextMenus.js index 19566685536..a1a81e4fae3 100644 --- a/js/contextMenus.js +++ b/js/contextMenus.js @@ -543,17 +543,19 @@ function getMisspelledSuggestions (selection, isMisspelled, suggestions) { if (isMisspelled) { template.push({ label: locale.translation('learnSpelling'), - click: () => { - appActions.addWord(selection, true) - // This is needed so the underline goes away - webviewActions.replace(selection) + click: (item, focusedWindow) => { + if (focusedWindow) { + focusedWindow.webContents.addWord(selection) + } } - }, { - label: locale.translation('ignoreSpelling'), - click: () => { - appActions.addWord(selection, false) - // This is needed so the underline goes away - webviewActions.replace(selection) + }, CommonMenu.separatorMenuItem) + } else { + template.push({ + label: locale.translation('forgetLearnedSpelling'), + click: (item, focusedWindow) => { + if (focusedWindow) { + focusedWindow.webContents.removeWord(selection) + } } }, CommonMenu.separatorMenuItem) } @@ -953,9 +955,10 @@ function mainTemplateInit (nodeProps, frame, tab) { if (isInputField) { let misspelledSuggestions = [] if (nodeProps.misspelledWord) { - const info = ipc.sendSync(messages.GET_MISSPELLING_INFO, nodeProps.selectionText) - if (info) { - misspelledSuggestions = getMisspelledSuggestions(nodeProps.selectionText, info.isMisspelled, info.suggestions) + if (nodeProps.misspelledWord === 'match-brave-custom-dictionary' && !nodeProps.dictionarySuggestions.length) { + misspelledSuggestions = getMisspelledSuggestions(nodeProps.selectionText, false, nodeProps.dictionarySuggestions) + } else { + misspelledSuggestions = getMisspelledSuggestions(nodeProps.selectionText, true, nodeProps.dictionarySuggestions) } } diff --git a/js/stores/appStore.js b/js/stores/appStore.js index 307c00b647c..4b9e66c29b4 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -395,7 +395,6 @@ const handleAppAction = (action) => { require('../../app/browser/reducers/sitesReducer'), require('../../app/browser/reducers/windowsReducer'), require('../../app/browser/reducers/syncReducer'), - require('../../app/browser/reducers/spellCheckReducer'), require('../../app/browser/reducers/clipboardReducer'), require('../../app/browser/reducers/urlBarSuggestionsReducer'), require('../../app/browser/reducers/passwordManagerReducer'), @@ -654,9 +653,6 @@ const handleAppAction = (action) => { appState = appState.setIn(path, wordList.push(action.word)) } break - case appConstants.APP_SET_DICTIONARY: - appState = appState.setIn(['dictionary', 'locale'], action.locale) - break case appConstants.APP_LEDGER_RECOVERY_STATUS_CHANGED: { const date = new Date().getTime() diff --git a/package.json b/package.json index 808e582cb4f..3bb9eb8c948 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,6 @@ "react-dnd": "^2.1.4", "react-dnd-html5-backend": "^2.1.2", "react-dom": "^15.5.4", - "spellchecker": "brave/node-spellchecker", "string.prototype.endswith": "^0.2.0", "string.prototype.startswith": "^0.2.0", "tablesort": "5.0.0",