Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Using Chromium's spellchecker
Browse files Browse the repository at this point in the history
fixes #9880

Auditors: @bridiver, @bbondy, @bsclifton

Test plan:
a. Suggestions

1. Go to `about:styles`
2. Type `braave` in textbox
3. There should be redline under `braave`
4. Open context menu on `braave`
5. You can see `bravo`, `brave`, `Brava`
6. Click on `brave`
7. The text should be replaced with `brave` with no redline

b. Learn Spelling
1. Go to `about:styles`
2. Type `braave` in textbox
3. There should be redline under `braave`
4. Open context menu on `braave`
5. Click `Learn Spelling`
6. `braave` will no longer be redlined
7.  Next time you type `braave`, you will not see redline

c. Forget Learned Spelling
1. Go to `about:styles`
2. Type `braave` in textbox
3. There should be redline under `braave`
4. Open context menu on `braave`
5. Click `Learn Spelling`
6. `braave` will no longer be redlined
7. Open context menu on `braave`
8. Click `Forget Learned Spelling`
9.  Next time you type `braave`, you will see redline under it

d. Legacy data migration
1. Use older Brave to `Learn Spelling` for `braave` and `Ignore
Spelling` for `braaave`
2. Update to the version with chromium spellchecker
3. There will be no `dictionary` structure in session store
4. You can see those two words will be added to `Custom Dictionary.txt`
under user folder
5. And try to type `braave` and `braaave` in `about:styles`
6. They should be valid words
  • Loading branch information
darkdh committed Jul 14, 2017
1 parent 69dfb59 commit 04b1288
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 239 deletions.
21 changes: 0 additions & 21 deletions app/browser/reducers/spellCheckReducer.js

This file was deleted.

66 changes: 66 additions & 0 deletions app/browser/reducers/spellCheckerReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* 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 {makeImmutable} = require('../../common/state/immutableUtil')
const {getWebContents} = require('../webContentsCache')
const spellChecker = require('../../spellChecker')

const migrate = (state) => {
if (state.get('dictionary')) {
const addedWords = state.getIn(['dictionary', 'addedWords'])
const ignoredWords = state.getIn(['dictionary', 'ignoredWords'])
if (addedWords.size) {
addedWords.forEach((word) => {
spellChecker.addWord(word)
})
}
if (ignoredWords.size) {
ignoredWords.forEach((word) => {
spellChecker.addWord(word)
})
}
state = state.delete('dictionary')
}
return state
}

const spellCheckerReducer = (state, action, immutableAction) => {
action = immutableAction || makeImmutable(action)
switch (action.get('actionType')) {
case appConstants.APP_SET_STATE:
state = migrate(state)
break
case appConstants.APP_SPELLING_SUGGESTED:
if (typeof action.suggestion === 'string') {
const webContents = getWebContents(action.tabId)
if (webContents && !webContents.isDestroyed()) {
webContents.replaceMisspelling(action.suggestion)
}
}
break
case appConstants.APP_LEARN_SPELLING:
if (typeof action.word === 'string') {
spellChecker.addWord(action.word)
const webContents = getWebContents(action.tabId)
if (webContents && !webContents.isDestroyed()) {
webContents.replaceMisspelling(action.word)
}
}
break
case appConstants.APP_FORGET_LEARNED_SPELLING:
if (typeof action.word === 'string') {
spellChecker.removeWord(action.word)
const webContents = getWebContents(action.tabId)
if (webContents && !webContents.isDestroyed()) {
webContents.replace(action.word)
}
}
}
return state
}

module.exports = spellCheckerReducer
1 change: 0 additions & 1 deletion app/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ let generateBraveManifest = () => {
getBraveExtUrl('about-blank.html') + '#*'
],
js: [
'content/scripts/spellCheck.js',
'content/scripts/themeColor.js'
]
},
Expand Down
22 changes: 0 additions & 22 deletions app/extensions/brave/content/scripts/spellCheck.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/extensions/brave/locales/en-US/menu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const PDFJS = require('./pdfJS')
const SiteHacks = require('./siteHacks')
const CmdLine = require('./cmdLine')
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')
Expand Down Expand Up @@ -181,7 +180,6 @@ app.on('ready', () => {
Autofill.init()
Extensions.init()
SiteHacks.init()
spellCheck.init()
HttpsEverywhere.init()
TrackingProtection.init()
AdBlock.init()
Expand Down
2 changes: 1 addition & 1 deletion app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ var rendererIdentifiers = function () {
'braveryStartUsingPayments',
'blockPopups',
'learnSpelling',
'ignoreSpelling',
'forgetLearnedSpelling',
'lookupSelection',
// Other identifiers
'aboutBlankTitle',
Expand Down
4 changes: 0 additions & 4 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,6 @@ module.exports.defaultAppState = () => {
passwords: [],
notifications: [],
temporarySiteSettings: {},
dictionary: {
addedWords: [],
ignoredWords: []
},
autofill: {
addresses: {
guid: [],
Expand Down
90 changes: 0 additions & 90 deletions app/spellCheck.js

This file was deleted.

14 changes: 14 additions & 0 deletions app/spellChecker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* 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/. */

const electron = require('electron')
const session = electron.session

module.exports.addWord = (word) => {
session.defaultSession.spellChecker.addWord(word)
}

module.exports.removeWord = (word) => {
session.defaultSession.spellChecker.removeWord(word)
}
22 changes: 0 additions & 22 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,28 +450,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
Expand Down
5 changes: 0 additions & 5 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ AppStore
y: number
},
defaultWindowWidth: number, // DEPRECATED (0.12.7); replaced w/ defaultWindowParams.width
dictionary: {
addedWords: Array<string>, // list of words to add to the dictionary
ignoredWords: Array<string>, // list of words to ignore
locale: string // en_US, en, or any other locale string
},
downloads: [{
[downloadId]: {
filename: string,
Expand Down
48 changes: 24 additions & 24 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,30 +548,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
Expand Down Expand Up @@ -1515,6 +1491,30 @@ const appActions = {
windowId
}
})
},

spellingSuggested: function (suggestion, tabId) {
dispatch({
actionType: appConstants.APP_SPELLING_SUGGESTED,
suggestion,
tabId
})
},

learnSpelling: function (word, tabId) {
dispatch({
actionType: appConstants.APP_LEARN_SPELLING,
word,
tabId
})
},

forgetLearnedSpelling: function (word, tabId) {
dispatch({
actionType: appConstants.APP_FORGET_LEARNED_SPELLING,
word,
tabId
})
}
}

Expand Down
11 changes: 0 additions & 11 deletions js/actions/webviewActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@ const webviewActions = {
}
},

/**
* Replaces the selected text in an editable
* @param {string} text - The text to replace with
*/
replace: function (text) {
const webview = getWebview()
if (webview) {
webview.replaceMisspelling(text)
}
},

/**
* Shows the certificate infomation
*/
Expand Down
Loading

0 comments on commit 04b1288

Please sign in to comment.