Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_SITE_AND_SHIELDS_SETTINGS" desc="Label for site and shields settings in clear browsing data dialog">
Site and Shields Settings
</message>
<message name="IDS_SETTINGS_AMP_NEUTRALIZED_SETTING_LABEL" desc="Label for control to automatically redirect AMP pages to their original version">
Automatically redirect AMP pages to their original version
</message>
</messages>
</release>
</grit>
1 change: 1 addition & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(kNoScriptControlType, false);
registry->RegisterBooleanPref(kAdControlType, true);
registry->RegisterBooleanPref(kShieldsAdvancedViewEnabled, false);
registry->RegisterBooleanPref(kShieldsAmpNeutralized, false);

#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
// PushMessaging
Expand Down
2 changes: 2 additions & 0 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetWhitelistedKeys() {
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kShieldsStatsBadgeVisible] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kShieldsAmpNeutralized] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kAdControlType] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kHTTPSEVerywhereControlType] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
</template>
</select>
</div>
<settings-toggle-button id="ampNeutralizerControlType"
pref="{{prefs.brave.shields.amp_neutralized}}"
label="$i18n{ampNeutralizedSettingLabel}">
</settings-toggle-button>
<div class="settings-box">
<div class="label shields-primary-title">$i18n{shieldsLookFeelTitle}</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_REMOTE_DEBUGGING_TITLE},
{"siteSettings",
IDS_SETTINGS_SITE_AND_SHIELDS_SETTINGS},
{"ampNeutralizedSettingLabel",
IDS_SETTINGS_AMP_NEUTRALIZED_SETTING_LABEL},
};
AddLocalizedStringsBulk(html_source, localized_strings);
html_source->AddString("webRTCLearnMoreURL",
Expand Down
2 changes: 2 additions & 0 deletions common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const char kShieldsAdvancedViewEnabled[] =
"brave.shields.advanced_view_enabled";
const char kShieldsStatsBadgeVisible[] =
"brave.shields.stats_badge_visible";
const char kShieldsAmpNeutralized[] =
"brave.shields.amp_neutralized";
const char kAdControlType[] = "brave.ad_default";
const char kGoogleLoginControlType[] = "brave.google_login_default";
const char kFBEmbedControlType[] = "brave.fb_embed_default";
Expand Down
1 change: 1 addition & 0 deletions common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern const char kHTTPSEVerywhereControlType[];
extern const char kNoScriptControlType[];
extern const char kShieldsAdvancedViewEnabled[];
extern const char kShieldsStatsBadgeVisible[];
extern const char kShieldsAmpNeutralized[];
extern const char kAdControlType[];
extern const char kGoogleLoginControlType[];
extern const char kFBEmbedControlType[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ transpile_web_ui("brave_extension") {
["content", rebase_path("content.ts")],
["content_dapps", rebase_path("content_dapps.ts")],
["content_cosmetic", rebase_path("content_cosmetic.ts")],
["content_noamp", rebase_path("content_noamp.ts")],
["webstore", rebase_path("webstore.ts")],
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ require('./api/localeAPI')
require('./api/shieldsAPI')
require('./api/tabsAPI')
require('./api/storageAPI')
require('./api/ampAPI')
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* 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/. */

import * as SettingsPrivate from '../../../../../common/settingsPrivate'

const ampSettingsKey = 'brave.shields.amp_neutralized'

export async function getAMPNeutralized (): Promise<boolean> {
const pref = await SettingsPrivate.getPreference(ampSettingsKey)
if (pref.type !== chrome.settingsPrivate.PrefType.BOOLEAN) {
throw new Error(`Unexpected settings type received for "${ampSettingsKey}.` +
`" Expected: ${chrome.settingsPrivate.PrefType.BOOLEAN}, Received: ${pref.type}`)
}
return pref.value
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { combineReducers } from 'redux'
import shieldsPanelReducer from './reducers/shieldsPanelReducer'
import dappDetectionReducer from './reducers/dappDetectionReducer'
import runtimeReducer from './reducers/runtimeReducer'
import ampReducer from './reducers/ampReducer'

export default combineReducers({
shieldsPanel: shieldsPanelReducer,
dappDetection: dappDetectionReducer,
amp: ampReducer,
runtime: runtimeReducer
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* 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/. */

import * as webNavigationTypes from '../../constants/webNavigationTypes'
import { Actions } from '../../types/actions/index'
import * as ampAPI from '../api/ampAPI'

export default function ampReducer (state = {}, action: Actions) {
switch (action.type) {
case webNavigationTypes.ON_COMMITTED: {
if (action.isMainFrame) {
ampAPI.getAMPNeutralized().then(ampNeutralized => {
if (ampNeutralized) {
chrome.tabs.executeScript(action.tabId, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do the redirect in the native code, we really want to avoid using extensions for stuff like this. Check out brave_common_static_redirect_network_delegate_helper

Copy link
Collaborator

@bridiver bridiver Jun 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so actually in moving this to greaselion we will just conditionally enable this content script when the pref values changes so this won't be needed at all

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file: 'out/content_noamp.bundle.js',
allFrames: false,
runAt: 'document_start',
frameId: 0
})
}
})
.catch(() => console.warn('Failed to read AMP neutralizer preference'))
}
break
}
}
return state
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const redirectAmp = () => {
// Check whether it's AMP html
let h = document.getElementsByTagName('html')
if (h[0].getAttribute('amp') !== null
|| h[0].getAttribute('⚡') !== null
|| document.location.href.substr(0, 29).toLowerCase() === 'https://www.google.com/amp/s/') {

// Try and find a canonical link
let canonicals = document.querySelectorAll('link[rel=canonical]')
for (let i = 0; i < canonicals.length; i++) {
let canonicalURL = canonicals[i].getAttribute('href')
if (canonicalURL !== null && canonicalURL !== window.location.href.split('#')[0]) {
window.location.replace(canonicalURL)
}
}
}
}

document.addEventListener('DOMContentLoaded', redirectAmp, false)
1 change: 1 addition & 0 deletions components/test/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ export const window = () => {

export const initialState = deepFreeze({
dappDetection: {},
amp: {},
runtime: {},
shieldsPanel: {
currentWindowId: -1,
Expand Down