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

Commit

Permalink
Merge pull request #6882 from brave/feature/syncing
Browse files Browse the repository at this point in the history
Add sync
  • Loading branch information
ayumi authored Feb 15, 2017
2 parents 4d8420f + 7809a0a commit 0904162
Show file tree
Hide file tree
Showing 43 changed files with 2,915 additions and 66 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ httpse.leveldb

# webstrom
.idea

# sync bundle file should be built and copied from the brave/sync repo for now
app/extensions/brave/content/scripts/sync.js
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
script:
- npm run download-sync-client
- npm run lint && npm test
notifications:
slack:
Expand Down
58 changes: 55 additions & 3 deletions app/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ let generateBraveManifest = () => {
// allow access to webpack dev server resources
let devServer = 'localhost:' + process.env.npm_package_config_port
cspDirectives['default-src'] = '\'self\' http://' + devServer
cspDirectives['connect-src'] = '\'self\' http://' + devServer + ' ws://' + devServer
cspDirectives['connect-src'] = ['\'self\'',
'http://' + devServer,
'ws://' + devServer].join(' ')
cspDirectives['style-src'] = '\'self\' \'unsafe-inline\' http://' + devServer
}

Expand Down Expand Up @@ -211,6 +213,43 @@ let generateTorrentManifest = () => {
}
}

let generateSyncManifest = () => {
let cspDirectives = {
'default-src': '\'self\'',
'form-action': '\'none\'',
'style-src': '\'self\' \'unsafe-inline\''
}
cspDirectives['connect-src'] = ['\'self\'',
appConfig.sync.serverUrl,
appConfig.sync.s3Url].join(' ')

if (process.env.NODE_ENV === 'development') {
// allow access to webpack dev server resources
let devServer = 'localhost:' + process.env.npm_package_config_port
cspDirectives['default-src'] += 'http://' + devServer
cspDirectives['connect-src'] += ' http://' + devServer + ' ws://' + devServer
cspDirectives['style-src'] += 'http://' + devServer
}

return {
name: 'Brave Sync',
manifest_version: 2,
version: '1.0',
content_security_policy: concatCSP(cspDirectives),
content_scripts: [],
background: {
scripts: [ 'content/scripts/sync.js' ]
},
icons: {
128: 'img/sync-128.png',
48: 'img/sync-48.png',
16: 'img/sync-16.png'
},
incognito: 'spanning',
key: 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxOmBmOVzntEY6zrcrGSAyrhzL2FJt4FaP12nb899+SrV0LgpOgyqDjytuXT5IlHS74j7ZK2zTOTQy5/E9hqo6ioi1GA3PQU8E71DTaN6kW+XzP+VyZmgPoQHIxPg8jkYk/H4erfP9kMhkVOtu/XqDTqluNhOT0BvVlBpWd4unTQFWdgpCYlPrI6PsYya4FSuIDe6rCKtJABfuKFEr7U9d9MNAOJEnRS8vdBHWCuhWHqsfAaAPyKHQhnwFSFZ4eB+JznBQf7cQtB3EpOoBElyR9QvmbWFrYu87eGL5XxsojKHCrxlQ4X5ANsALa1Mdd2DHDMVqLMIiEEU42DVB0ZDewIDAQAB'
}
}

const extensionInfo = {
isEnabled: function (extensionId) {
return this.extensionState[extensionId] === extensionStates.ENABLED
Expand Down Expand Up @@ -290,13 +329,24 @@ module.exports.init = () => {
}
})

process.on('reload-sync-extension', () => {
console.log('reloading sync')
disableExtension(config.syncExtensionId)
})

process.on('extension-load-error', (error) => {
console.error(error)
})

process.on('extension-unloaded', (extensionId) => {
extensionInfo.setState(extensionId, extensionStates.DISABLED)
extensionActions.extensionDisabled(extensionId)
if (extensionId === config.syncExtensionId) {
// Reload sync extension to restart the background script
setImmediate(() => {
enableExtension(config.syncExtensionId)
})
}
})

process.on('extension-ready', (installInfo) => {
Expand All @@ -311,7 +361,7 @@ module.exports.init = () => {
let loadExtension = (extensionId, extensionPath, manifest = {}, manifestLocation = 'unpacked') => {
if (!extensionInfo.isLoaded(extensionId) && !extensionInfo.isLoading(extensionId)) {
extensionInfo.setState(extensionId, extensionStates.LOADING)
if (extensionId === config.braveExtensionId || extensionId === config.torrentExtensionId) {
if (extensionId === config.braveExtensionId || extensionId === config.torrentExtensionId || extensionId === config.syncExtensionId) {
session.defaultSession.extensions.load(extensionPath, manifest, manifestLocation)
return
}
Expand Down Expand Up @@ -357,6 +407,8 @@ module.exports.init = () => {
// Manually install the braveExtension and torrentExtension
extensionInfo.setState(config.braveExtensionId, extensionStates.REGISTERED)
loadExtension(config.braveExtensionId, getExtensionsPath('brave'), generateBraveManifest(), 'component')
extensionInfo.setState(config.syncExtensionId, extensionStates.REGISTERED)
loadExtension(config.syncExtensionId, getExtensionsPath('brave'), generateSyncManifest(), 'unpacked')
if (getSetting(settings.TORRENT_VIEWER_ENABLED)) {
extensionInfo.setState(config.torrentExtensionId, extensionStates.REGISTERED)
loadExtension(config.torrentExtensionId, getExtensionsPath('torrent'), generateTorrentManifest(), 'component')
Expand All @@ -365,7 +417,7 @@ module.exports.init = () => {
extensionActions.extensionDisabled(config.torrentExtensionId)
}

let registerComponents = () => {
let registerComponents = (diff) => {
if (getSetting(settings.PDFJS_ENABLED)) {
registerComponent(config.PDFJSExtensionId)
} else {
Expand Down
Binary file added app/extensions/brave/img/sync-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/extensions/brave/img/sync-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/extensions/brave/img/sync-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ paymentsSidebarText1=Our Partners
paymentsSidebarText2=All transaction IP addresses are anonymized with technology from:
paymentsSidebarText3=Brave Bitcoin Wallets are provided through a partnership with:
paymentsSidebarText4=Your contributions in the form of credit cards and bank cards are handled by:
syncTitle=Brave Sync
syncTitleMessage=Sync encrypted browser data between your devices securely and privately using Brave Sync.
syncEnable=Sync this device
syncData=Sync Data
syncDataMessage=Sync the following data from this device:
syncDeviceName=Device name
syncBookmarks=Bookmarks
syncHistory=Browsing history
syncSiteSettings=Saved site settings
syncNewDevice=Sync a new device...
syncStart=I am new to sync
syncAdd=I have an existing sync code
syncNewDevice1=Open Brave on your new device and go to Preferences > Sync > 'I have an existing synced device'.
syncNewDevice2=If it asks you to scan a QR code, click the button below and point your camera at the QR code.
syncShowQR=Show secret QR code. (Do not share!)
syncHideQR=Hide QR code
syncNewDevice3=If asks you to enter code words, type in the words below.
syncShowPassphrase=Show secret code words. (Do not share!)
syncHidePassphrase=Hide code words
syncDeviceNameInput=Enter an optional name for this device:
syncCreate=Set up sync
syncEnterPassphrase=Enter your sync code words:
accountBalance=account balance
accountBalanceConnectionError=Please check your Internet connection.
accountBalanceLoading=loading…
Expand All @@ -44,7 +66,6 @@ insufficientFundsStatus=Your account balance is under your budget for this month
defaultWalletStatus=Thanks for helping support your favorite websites!
tableEmptyText=No table data.
notificationEmptyText=Top publisher visits
syncEmptyText=Sync settings coming soon.
bitcoin=Bitcoin
bitcoinAdd=Use your existing Bitcoin wallet/account
bitcoinAddDescription=Use any BTC wallet that can transfer Bitcoin to your Brave wallet.
Expand Down Expand Up @@ -249,6 +270,7 @@ engineGoKey=Engine Go Key (type first)
braveSoftware=Brave Software
emailAddress=Email address
viewLog=View Log
comingSoon=Coming soon!
setDefaultButton=Set as default…
setDefaultLabel=Brave is not your default browser:
setDefaultAlwaysSwitch=Always check on startup
Expand Down
2 changes: 2 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const contentSettings = require('../js/state/contentSettings')
const privacy = require('../js/state/privacy')
const async = require('async')
const settings = require('../js/constants/settings')
const sync = require('./sync')
const BookmarksExporter = require('./browser/bookmarksExporter')

app.commandLine.appendSwitch('enable-features', 'BlockSmallPluginContent,PreferHtmlOverPlugins')
Expand Down Expand Up @@ -414,6 +415,7 @@ app.on('ready', () => {
delete initialState.perWindowState
appActions.setState(Immutable.fromJS(initialState))
Menu.init(initialState, null)
sync.init(initialState.sync || {})
return loadedPerWindowState
}).then((loadedPerWindowState) => {
contentSettings.init()
Expand Down
Loading

0 comments on commit 0904162

Please sign in to comment.