This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 975
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notify users when autoplay has been blocked and provide option to all…
…ow it Display "Block autoplay" in bravey shield Fix #8738 Fix #8739 Auditors: @bbondy, @bsclifton, @jonathansampson Test Plan: Covered by automatic test
- Loading branch information
Showing
15 changed files
with
200 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* 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 {ipcMain, webContents} = require('electron') | ||
const AppStore = require('../../../js/stores/appStore') | ||
const siteSettings = require('../../../js/state/siteSettings') | ||
const appActions = require('../../../js/actions/appActions') | ||
const {getOrigin} = require('../../../js/state/siteUtil') | ||
const locale = require('../../locale') | ||
const messages = require('../../../js/constants/messages') | ||
const urlParse = require('../../common/urlParse') | ||
|
||
const showAutoplayMessageBox = (location, tabId) => { | ||
const origin = getOrigin(location) | ||
const originSettings = siteSettings.getSiteSettingsForURL(AppStore.getState().get('siteSettings'), origin) | ||
if (originSettings && originSettings.get('noAutoplay') === true) { | ||
return | ||
} | ||
const message = locale.translation('autoplayBlocked', {origin}) | ||
|
||
appActions.showNotification({ | ||
buttons: [ | ||
{text: locale.translation('yes')}, | ||
{text: locale.translation('no')} | ||
], | ||
message, | ||
frameOrigin: origin, | ||
options: { | ||
persist: true | ||
} | ||
}) | ||
|
||
ipcMain.once(messages.NOTIFICATION_RESPONSE, (e, msg, buttonIndex, persist) => { | ||
if (msg === message) { | ||
appActions.hideNotification(message) | ||
let ruleKey = origin | ||
const parsedUrl = urlParse(location) | ||
if ((parsedUrl.protocol === 'https:' || parsedUrl.protocol === 'http:')) { | ||
ruleKey = `https?://${parsedUrl.host}` | ||
} | ||
if (buttonIndex === 0) { | ||
appActions.changeSiteSetting(ruleKey, 'noAutoplay', false) | ||
|
||
if (tabId) { | ||
const tab = webContents.fromTabID(tabId) | ||
if (tab && !tab.isDestroyed()) { | ||
return tab.reload() | ||
} | ||
} | ||
} else { | ||
if (persist) { | ||
appActions.changeSiteSetting(ruleKey, 'noAutoplay', true) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
const autoplayReducer = (state, action, immutableAction) => { | ||
action = immutableAction || makeImmutable(action) | ||
switch (action.get('actionType')) { | ||
case appConstants.APP_AUTOPLAY_BLOCKED: | ||
showAutoplayMessageBox(action.get('location'), action.get('tabId')) | ||
break | ||
} | ||
return state | ||
} | ||
|
||
module.exports = autoplayReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters