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

Commit

Permalink
Add Importer support
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed Sep 16, 2016
1 parent 6802928 commit 6faabd6
Show file tree
Hide file tree
Showing 21 changed files with 476 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,8 @@ dismissDenyRunInsecureContent=Stay Insecure
denyRunInsecureContent=Stop Loading Unsafe Scripts
runInsecureContentWarning=This page is trying to load scripts from insecure sources. If you allow this content to run it will not be encrypted and it may transmit unencrypted data to other sites.
denyRunInsecureContentWarning=This page is currently loading scripts from insecure sources.
importBrowserData=Import browser data
import=Import
importDataWarning=Note: Each browser has a different set of importable data.
favoritesOrBookmarks=Favorites/Bookmarks
cookies=Cookies
2 changes: 2 additions & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,5 @@ clearBrowsingDataNow=Clear Browsing Data Now…
autofillSettings=Autofill Settings
manageAutofillData=Manage Autofill Data…
enableAutofill=Enable Autofill
importBrowserData=Import Browser Data
importNow=Import now…
11 changes: 11 additions & 0 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,14 @@ module.exports.clearAutofillData = () => {
ses.autofill.clearAutofillData()
}
}

module.exports.setCookie = (cookie) => {
for (let partition in registeredSessions) {
let ses = registeredSessions[partition]
ses.cookies.set(cookie, (error) => {
if (error) {
console.error(error)
}
})
}
}
151 changes: 151 additions & 0 deletions app/importer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/* 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/. */

'strict mode'

const electron = require('electron')
const importer = electron.importer
const dialog = electron.dialog
const BrowserWindow = electron.BrowserWindow
const Immutable = require('immutable')
const siteUtil = require('../js/state/siteUtil')
const AppStore = require('../js/stores/appStore')
const siteTags = require('../js/constants/siteTags')
const appActions = require('../js/actions/appActions')
const messages = require('../js/constants/messages')
const Filtering = require('./filtering')

exports.init = () => {
importer.initialize()
}

exports.importData = (selected) => {
if (selected !== undefined) {
importer.importData(selected.toJS())
}
}

exports.importHTML = () => {
const files = dialog.showOpenDialog({
properties: ['openFile'],
filters: [{
name: 'HTML',
extensions: ['html', 'htm']
}]
})
if (files && files.length > 0) {
const file = files[0]
importer.importHTML(file)
}
}

importer.on('update-supported-browsers', (e, detail) => {
if (BrowserWindow.getFocusedWindow()) {
BrowserWindow.getFocusedWindow().webContents.send(messages.IMPORTER_LIST, detail)
}
})

importer.on('show-warning-dialog', (e) => {
})

importer.on('add-password-form', (e, detail) => {
})

importer.on('add-history-page', (e, history, visitSource) => {
let sites = []
for (let i = 0; i < history.length; ++i) {
const site = {
title: history[i].title,
location: history[i].url,
lastAccessedTime: history[i].last_visit * 1000
}
sites.push(site)
}
appActions.addSite(Immutable.fromJS(sites))
})

importer.on('add-homepage', (e, detail) => {
})

importer.on('add-bookmarks', (e, bookmarks, topLevelFolder) => {
let nextFolderId = siteUtil.getNextFolderId(AppStore.getState().get('sites'))
let pathMap = {}
let sites = []
const topLevelFolderId = nextFolderId++
sites.push({
title: topLevelFolder,
folderId: topLevelFolderId,
parentFolderId: -1,
lastAccessedTime: (new Date()).getTime(),
tags: [siteTags.BOOKMARK_FOLDER]
})
pathMap[topLevelFolder] = topLevelFolderId
for (let i = 0; i < bookmarks.length; ++i) {
const pathLen = bookmarks[i].path.length
let parentFolderId = topLevelFolderId
if (pathLen) {
const parentFolder = bookmarks[i].path[pathLen - 1]
parentFolderId = pathMap[parentFolder]
if (parentFolderId === undefined) {
parentFolderId = nextFolderId++
pathMap[parentFolder] = parentFolderId
const folder = {
title: parentFolder,
folderId: parentFolderId,
parentFolderId: pathMap[bookmarks[i].path[pathLen - 2]] === undefined ? topLevelFolderId : pathMap[bookmarks[i].path[pathLen - 2]],
lastAccessedTime: (new Date()).getTime(),
tags: [siteTags.BOOKMARK_FOLDER]
}
sites.push(folder)
}
}
if (bookmarks[i].is_folder) {
const folderId = nextFolderId++
pathMap[bookmarks[i].title] = folderId
const folder = {
title: bookmarks[i].title,
folderId: folderId,
parentFolderId: parentFolderId,
lastAccessedTime: bookmarks[i].creation_time * 1000,
tags: [siteTags.BOOKMARK_FOLDER]
}
sites.push(folder)
} else {
const site = {
title: bookmarks[i].title,
location: bookmarks[i].url,
parentFolderId: parentFolderId,
lastAccessedTime: bookmarks[i].creation_time * 1000,
tags: [siteTags.BOOKMARK]
}
sites.push(site)
}
}
appActions.addSite(Immutable.fromJS(sites))
})

importer.on('add-favicons', (e, detail) => {
})

importer.on('add-keywords', (e, templateUrls, uniqueOnHostAndPath) => {
})

importer.on('add-autofill-form-data-entries', (e, detail) => {
})

importer.on('add-cookies', (e, cookies) => {
for (let i = 0; i < cookies.length; ++i) {
const cookie = {
url: cookies[i].url,
name: cookies[i].name,
value: cookies[i].value,
domain: cookies[i].domain,
path: cookies[i].path,
secure: cookies[i].secure,
httpOnly: cookies[i].httponly,
expirationDate: cookies[i].expiry_date
}
Filtering.setCookie(cookie)
}
})
5 changes: 5 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const ipcMain = electron.ipcMain
const Immutable = require('immutable')
const Menu = require('./browser/menu')
const Updater = require('./updater')
const Importer = require('./importer')
const messages = require('../js/constants/messages')
const appConfig = require('../js/constants/appConfig')
const appActions = require('../js/actions/appActions')
Expand Down Expand Up @@ -693,6 +694,10 @@ app.on('ready', () => {
}
})

ipcMain.on(messages.IMPORT_BROWSER_DATA_NOW, () => {
Importer.init()
})

// Setup the crash handling
CrashHerald.init()

Expand Down
10 changes: 10 additions & 0 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,16 @@ Clears the data specified in dataDetail



### importBrowserData(selected)

Import browser data specified in selected

**Parameters**

**selected**: `object`, the browser data to import as per doc/state.md's importBroserDataSelected



### addAutofillAddress(detail, originalDetail)

Add address data
Expand Down
17 changes: 17 additions & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,23 @@ WindowStore
month: string,
year: string,
guid: Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
},
importBrowserDataDetail: [
{
index: string,
type: number,
name: string,
history: boolean,
favorites: boolean,
cookies: boolean
}
],
importBroserDataSelected: {
index: string,
type: number,
history: boolean,
favorites: boolean,
cookies: boolean
}
}
```
20 changes: 20 additions & 0 deletions docs/windowActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,26 @@ Sets the clear browsing data popup detail



### setImportBrowserDataDetail(importBrowserDataDetail)

Sets the import browser data popup detail

**Parameters**

**importBrowserDataDetail**: `Array`, list of supported browsers



### setImportBrowserDataSelected(selected)

Sets the selected import browser data

**Parameters**

**selected**: `Object`, selected browser data to import



### setAutofillAddressDetail(currentDetail, originalDetail)

Sets the manage autofill address popup detail
Expand Down
4 changes: 4 additions & 0 deletions js/about/aboutActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ const AboutActions = {
ipc.sendToHost(messages.CLEAR_BROWSING_DATA_NOW, clearBrowsingDataDetail)
},

importBrowerDataNow: function () {
ipc.send(messages.IMPORT_BROWSER_DATA_NOW)
},

createWallet: function () {
ipc.send(messages.LEDGER_CREATE_WALLET)
},
Expand Down
12 changes: 12 additions & 0 deletions js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,15 @@ class PaymentHistoryRow extends ImmutableComponent {
}

class GeneralTab extends ImmutableComponent {
constructor (e) {
super()
this.importBrowserDataNow = this.importBrowserDataNow.bind(this)
}

importBrowserDataNow () {
aboutActions.importBrowerDataNow()
}

enabled (keyArray) {
return keyArray.every((key) => getSetting(key, this.props.settings) === true)
}
Expand Down Expand Up @@ -555,6 +564,9 @@ class GeneralTab extends ImmutableComponent {
}
<SettingCheckbox dataL10nId='disableTitleMode' prefKey={settings.DISABLE_TITLE_MODE} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
</SettingsList>
<div className='sectionTitle' data-l10n-id='importBrowserData' />
<Button l10nId='importNow' className='primaryButton importNowButton'
onClick={this.importBrowserDataNow} />
</SettingsList>
}
}
Expand Down
11 changes: 11 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,17 @@ const appActions = {
})
},

/**
* Import browser data specified in selected
* @param {object} selected - the browser data to import as per doc/state.md's importBroserDataSelected
*/
importBrowserData: function (selected, importHTML) {
AppDispatcher.dispatch({
actionType: AppConstants.APP_IMPORT_BROWSER_DATA,
selected
})
},

/**
* Add address data
* @param {object} detail - the address to add as per doc/state.md's autofillAddressDetail
Expand Down
22 changes: 22 additions & 0 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,28 @@ const windowActions = {
})
},

/**
* Sets the import browser data popup detail
* @param {Array} importBrowserDataDetail - list of supported browsers
*/
setImportBrowserDataDetail: function (importBrowserDataDetail) {
dispatch({
actionType: WindowConstants.WINDOW_SET_IMPORT_BROWSER_DATA_DETAIL,
importBrowserDataDetail
})
},

/**
* Sets the selected import browser data
* @param {Object} selected - selected browser data to import
*/
setImportBrowserDataSelected: function (selected) {
dispatch({
actionType: WindowConstants.WINDOW_SET_IMPORT_BROWSER_DATA_SELECTED,
selected
})
},

/**
* Sets the manage autofill address popup detail
* @param {Object} currentDetail - Properties of the address to change to
Expand Down
Loading

0 comments on commit 6faabd6

Please sign in to comment.