-
Notifications
You must be signed in to change notification settings - Fork 974
Notify users when autoplay has been blocked and provide option to allow it #8751
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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('allowAutoplay', {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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1292,6 +1292,19 @@ const appActions = { | |
AppDispatcher.dispatch({ | ||
actionType: appConstants.APP_DRAG_CANCELLED | ||
}) | ||
}, | ||
|
||
/** | ||
* Notifies autoplay has been blocked | ||
* @param {string} location - Location of current frame | ||
* @param {number} tabId - Tab id of current frame | ||
*/ | ||
autoplayBlocked: function (location, tabId) { | ||
AppDispatcher.dispatch({ | ||
actionType: appConstants.APP_AUTOPLAY_BLOCKED, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not blocking merging, but why is location needed here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is for displaying origin for message box There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just mean that the browser process already has this info so it is not needed to send from the window renderer. Pls do for a follow up but not high priority. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically it just leaves the chance that someone will use the API wrongly at some point, so better not to include it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do |
||
location, | ||
tabId | ||
}) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ module.exports = { | |
quitTimeout: 10 * 1000, | ||
resourceNames: { | ||
ADBLOCK: 'adblock', | ||
AUTOPLAY: 'autoplay', | ||
NOAUTOPLAY: 'noAutoplay', | ||
SAFE_BROWSING: 'safeBrowsing', | ||
HTTPS_EVERYWHERE: 'httpsEverywhere', | ||
TRACKING_PROTECTION: 'trackingProtection', | ||
|
@@ -36,8 +36,8 @@ module.exports = { | |
cookieblock: { | ||
enabled: true | ||
}, | ||
autoplay: { | ||
enabled: false | ||
noAutoplay: { | ||
enabled: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per our discussions, we want to default this to false, right? So that content isn't blocked There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the default is false, the notification won't popup in most of the cases because https://github.com/brave/browser-laptop/pull/8751/files#diff-d4f09c262fdb2f86d8f7407afb926c8eR21 The setting is similar to our default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was under the understanding we were defaulting to on with notification bar. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My mistake- I think I missed part of the convo 😄 ++ |
||
}, | ||
cookieblockAll: { | ||
enabled: false | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is being returned here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do a follow-up along with
browser-laptop/js/flash.js
Line 83 in b2618c9