mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 13:55:43 +00:00
Bug 1453691 - create a Fennec system addon to spoof the UA string as Chrome for Google Search and Facebook. r=rhelmer
MozReview-Commit-ID: FFwhvvAqffs --HG-- extra : rebase_source : 26c0d9226beb8cbcaf32476b4f84dcba7200fb3a
This commit is contained in:
parent
b0a03d10e5
commit
9326cac64c
@ -5,6 +5,9 @@
|
||||
|
||||
include('/toolkit/toolkit.mozbuild')
|
||||
|
||||
if CONFIG['MOZ_EXTENSIONS']:
|
||||
DIRS += ['/extensions']
|
||||
|
||||
DIRS += [
|
||||
'/%s' % CONFIG['MOZ_BRANDING_DIRECTORY'],
|
||||
'/mobile/android',
|
||||
|
@ -48,7 +48,7 @@ $(ABS_DIST)/fennec/$(OMNIJAR_NAME): FORCE
|
||||
|
||||
.PHONY: features
|
||||
features::
|
||||
$(call py_action,generate_builtin_addons,chrome/chrome/content/built_in_addons.json)
|
||||
$(call py_action,generate_builtin_addons,--features=features chrome/chrome/content/built_in_addons.json)
|
||||
|
||||
ifndef MOZILLA_OFFICIAL
|
||||
# Targets built very early during a Gradle build. In automation,
|
||||
|
73
mobile/android/extensions/gws-and-facebook-chrome-spoof/bootstrap.js
vendored
Normal file
73
mobile/android/extensions/gws-and-facebook-chrome-spoof/bootstrap.js
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
/* 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/. */
|
||||
|
||||
/* globals Services */
|
||||
|
||||
"use strict";
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "UserAgentOverrides", "resource://gre/modules/UserAgentOverrides.jsm");
|
||||
Cu.importGlobalProperties(["URL"]);
|
||||
|
||||
const TLDsToSpoof = /(^(www|encrypted|maps)\.google\.)|((.*\.facebook|.*\.fbcdn|.*\.fbsbx)\.(com|net)$)/;
|
||||
|
||||
const OverrideNotice = "The user agent string has been overridden to get the Chrome experience on this site.";
|
||||
|
||||
const defaultUA = Cc["@mozilla.org/network/protocol;1?name=http"].
|
||||
getService(Ci.nsIHttpProtocolHandler).userAgent;
|
||||
|
||||
const RunningFirefoxVersion = (defaultUA.match(/Firefox\/([0-9.]+)/) || ["", "58.0"])[1];
|
||||
const RunningAndroidVersion = defaultUA.match(/Android\/[0-9.]+/) || "Android 6.0";
|
||||
|
||||
const ChromeMajorVersionToMimic = `${parseInt(RunningFirefoxVersion) + 4}.0.0.0`;
|
||||
|
||||
const ChromePhoneUA = `Mozilla/5.0 (Linux; ${RunningAndroidVersion}; Nexus 5 Build/MRA58N) FxQuantum/${RunningFirefoxVersion} AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${ChromeMajorVersionToMimic} Mobile Safari/537.36`;
|
||||
const ChromeTabletUA = `Mozilla/5.0 (Linux; ${RunningAndroidVersion}; Nexus 7 Build/JSS15Q) FxQuantum/${RunningFirefoxVersion} AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${ChromeMajorVersionToMimic} Safari/537.36`;
|
||||
|
||||
const IsPhone = defaultUA.includes("Mobile");
|
||||
|
||||
const TargetUA = IsPhone ? ChromePhoneUA : ChromeTabletUA;
|
||||
|
||||
const EnabledPref = "extensions.gws-and-facebook-chrome-spoof.enabled";
|
||||
|
||||
let Enabled = true;
|
||||
|
||||
function checkIfEnabled() {
|
||||
Enabled = Services.prefs.getBoolPref(EnabledPref, true);
|
||||
}
|
||||
|
||||
this.install = () => {
|
||||
Services.prefs.setBoolPref(EnabledPref, true);
|
||||
};
|
||||
|
||||
this.uninstall = () => {
|
||||
Services.prefs.clearUserPref(EnabledPref);
|
||||
};
|
||||
|
||||
this.shutdown = () => {
|
||||
Services.prefs.removeObserver(EnabledPref, checkIfEnabled);
|
||||
Enabled = false;
|
||||
};
|
||||
|
||||
this.startup = () => {
|
||||
UserAgentOverrides.addComplexOverride((channel, defaultUA) => {
|
||||
if (!Enabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
let domain = new URL(channel.URI.spec).host;
|
||||
if (domain.match(TLDsToSpoof)) {
|
||||
console.info(OverrideNotice);
|
||||
return TargetUA;
|
||||
}
|
||||
} catch (_) {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
Services.prefs.addObserver(EnabledPref, checkIfEnabled);
|
||||
checkIfEnabled();
|
||||
};
|
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- 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/. -->
|
||||
|
||||
#filter substitution
|
||||
|
||||
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
|
||||
<Description about="urn:mozilla:install-manifest">
|
||||
<em:id>gws-and-facebook-spoof@mozilla.org</em:id>
|
||||
<em:type>2</em:type>
|
||||
<em:bootstrap>true</em:bootstrap>
|
||||
<em:multiprocessCompatible>true</em:multiprocessCompatible>
|
||||
|
||||
<em:name>Use Chrome mobile version of Google Search and Facebook</em:name>
|
||||
<em:description>Enables the Chrome Mobile experience for Google Search and Facebook.</em:description>
|
||||
|
||||
<em:version>1.0.0</em:version>
|
||||
|
||||
<em:targetApplication>
|
||||
<Description>
|
||||
<em:id>{aa3c5121-dab2-40e2-81ca-7ea25febc110}</em:id>
|
||||
<em:minVersion>@MOZ_APP_VERSION@</em:minVersion>
|
||||
<em:maxVersion>@MOZ_APP_MAXVERSION@</em:maxVersion>
|
||||
</Description>
|
||||
</em:targetApplication>
|
||||
</Description>
|
||||
</RDF>
|
@ -0,0 +1,19 @@
|
||||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
|
||||
DEFINES['MOZ_APP_MAXVERSION'] = CONFIG['MOZ_APP_MAXVERSION']
|
||||
|
||||
with Files('**'):
|
||||
BUG_COMPONENT = ('Web Compatibility Tools', 'General')
|
||||
|
||||
FINAL_TARGET_FILES.features['gws-and-facebook-spoof@mozilla.org'] += [
|
||||
'bootstrap.js'
|
||||
]
|
||||
|
||||
FINAL_TARGET_PP_FILES.features['gws-and-facebook-spoof@mozilla.org'] += [
|
||||
'install.rdf.in'
|
||||
]
|
14
mobile/android/extensions/moz.build
Normal file
14
mobile/android/extensions/moz.build
Normal file
@ -0,0 +1,14 @@
|
||||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
with Files('**'):
|
||||
BUG_COMPONENT = ('Firefox for Android', 'General')
|
||||
|
||||
# Only include the following system add-ons if building Nightly
|
||||
if CONFIG['NIGHTLY_BUILD']:
|
||||
DIRS += [
|
||||
'gws-and-facebook-chrome-spoof',
|
||||
]
|
@ -52,6 +52,7 @@ DIRS += [
|
||||
'base',
|
||||
'chrome',
|
||||
'components',
|
||||
'extensions',
|
||||
'modules',
|
||||
'themes/core',
|
||||
'themes/geckoview',
|
||||
|
Loading…
Reference in New Issue
Block a user