Skip to content

Commit

Permalink
Merge pull request #3451 from kyoshino/bug-1216225-get-firefox-details
Browse files Browse the repository at this point in the history
Bug 1216225 - Add function to provide accurate Firefox channel/version info based on mozUITour API
  • Loading branch information
alexgibson committed Nov 23, 2015
2 parents 8d4ae03 + b262ae3 commit 1584f9e
Show file tree
Hide file tree
Showing 19 changed files with 386 additions and 106 deletions.
2 changes: 1 addition & 1 deletion bedrock/base/templates/base-resp.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!doctype html>
{# Note the "windows" class, without javascript platform-specific
assets default to windows #}
<html class="windows x86 no-js" lang="{{ LANG|replace('en-US', 'en') }}" dir="{{ DIR }}" data-latest-firefox="{{ latest_firefox_version }}" data-esr-versions="{{ esr_firefox_versions }}">
<html class="windows x86 no-js" lang="{{ LANG|replace('en-US', 'en') }}" dir="{{ DIR }}" data-latest-firefox="{{ latest_firefox_version }}" data-esr-versions="{{ esr_firefox_versions|join(' ') }}">
<head>
<meta charset="utf-8">{# Note: Must be within first 512 bytes of page #}

Expand Down
2 changes: 1 addition & 1 deletion bedrock/base/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!doctype html>
{# Note the "windows" class, without javascript platform-specific
assets default to windows #}
<html class="windows x86 no-js" lang="{{ LANG|replace('en-US', 'en') }}" dir="{{ DIR }}" data-latest-firefox="{{ latest_firefox_version }}" data-esr-versions="{{ esr_firefox_versions }}">
<html class="windows x86 no-js" lang="{{ LANG|replace('en-US', 'en') }}" dir="{{ DIR }}" data-latest-firefox="{{ latest_firefox_version }}" data-esr-versions="{{ esr_firefox_versions|join(' ') }}">
<head>
<meta charset="utf-8">{# Note: Must be within first 512 bytes of page #}

Expand Down
2 changes: 1 addition & 1 deletion bedrock/firefox/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
def latest_firefox_versions(request):
return {
'latest_firefox_version': firefox_desktop.latest_version(),
'esr_firefox_versions': firefox_desktop.esr_major_versions,
'esr_firefox_versions': firefox_desktop.esr_minor_versions,
}
15 changes: 13 additions & 2 deletions bedrock/firefox/firefox_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,24 @@ def latest_major_version(self, channel):
@property
def esr_major_versions(self):
versions = []
for version in ('esr', 'esr_next'):
version_int = self.latest_major_version(version)
for channel in ('esr', 'esr_next'):
version_int = self.latest_major_version(channel)
if version_int:
versions.append(version_int)

return versions

@property
def esr_minor_versions(self):
versions = []
for channel in ('esr', 'esr_next'):
version = self.latest_version(channel)
version_int = self.latest_major_version(channel)
if version and version_int:
versions.append(str(version).replace('esr', ''))

return versions

def latest_builds(self, locale, channel='release'):
"""Return build info for a locale and channel.
Expand Down
9 changes: 6 additions & 3 deletions bedrock/firefox/tests/test_firefox_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,26 @@ def test_linux64_build(self):

@patch.object(firefox_desktop._storage, 'data',
Mock(return_value=dict(FIREFOX_ESR='24.2')))
def test_esr_major_versions(self):
def test_esr_versions(self):
"""ESR versions should be dynamic based on data."""
eq_(firefox_desktop.esr_major_versions, [24])
eq_(firefox_desktop.esr_minor_versions, ['24.2'])

@patch.object(firefox_desktop._storage, 'data',
Mock(return_value=dict(FIREFOX_ESR='24.6.0',
FIREFOX_ESR_NEXT='31.0.0')))
def test_esr_major_versions_prev(self):
def test_esr_versions_prev(self):
"""ESR versions should show previous when available."""
eq_(firefox_desktop.esr_major_versions, [24, 31])
eq_(firefox_desktop.esr_minor_versions, ['24.6.0', '31.0.0'])

@patch.object(firefox_desktop._storage, 'data',
Mock(return_value=dict(LATEST_FIREFOX_VERSION='Phoenix',
FIREFOX_ESR='Albuquerque')))
def test_esr_major_versions_no_latest(self):
def test_esr_versions_no_latest(self):
"""ESR versions should not blow up if current version is broken."""
eq_(firefox_desktop.esr_major_versions, [])
eq_(firefox_desktop.esr_minor_versions, [])

@patch.object(firefox_desktop._storage, 'data',
Mock(return_value=dict(LATEST_FIREFOX_VERSION='18.0.1')))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% add_lang_files "mozorg/contribute" "mozorg/contribute-form" %}
{# Note the "windows" class, without javascript platform-specific
assets default to windows #}
<html class="windows x86 no-js" lang="{{ LANG }}" dir="{{ DIR }}" data-latest-firefox="{{ latest_firefox_version }}" data-esr-versions="{{ esr_firefox_versions }}">
<html class="windows x86 no-js" lang="{{ LANG }}" dir="{{ DIR }}" data-latest-firefox="{{ latest_firefox_version }}" data-esr-versions="{{ esr_firefox_versions|join(' ') }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand Down
1 change: 1 addition & 0 deletions bedrock/settings/static_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@
'js/base/global.js',
'js/base/global-init.js',
'js/newsletter/form.js',
'js/base/mozilla-client.js',
'js/base/mozilla-input-placeholder.js',
'js/base/mozilla-image-helper.js',
'js/base/nav-main-resp.js',
Expand Down
5 changes: 5 additions & 0 deletions docs/uitour.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ https://support.mozilla.org and the special about:home page.

The ``Mozilla.UITour`` library is maintained on `Mozilla Central`_.

.. Important::

The API is supported only on the desktop versions of Firefox. It doesn't
work on Firefox for Android and iOS.

Local development
-----------------

Expand Down
32 changes: 8 additions & 24 deletions media/css/firefox/family/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
/*--------------------------------------------------------------------------*/
// Conditional download bar
#conditional-download-bar {
display: none;
background: #fff;
color: @textColorPrimary;
min-height: 1.5em;
Expand Down Expand Up @@ -118,34 +119,17 @@
}
}

#conditional-download-bar #dlbar-nonfx {
display: block;
}

html.firefox-latest #conditional-download-bar {
display: none;
}

html.firefox-old #conditional-download-bar #dlbar-oldfx-desktop {
display: block;
}

html.ios #conditional-download-bar #dlbar-ios {
display: block;
}

html.nonfx #conditional-download-bar,
html.nonfx #conditional-download-bar #dlbar-nonfx,
html.firefox-old #conditional-download-bar,
html.firefox-old #conditional-download-bar #dlbar-oldfx-desktop,
html.ios #conditional-download-bar,
html.ios #conditional-download-bar #dlbar-ios,
html.android #conditional-download-bar,
html.android #conditional-download-bar #dlbar-nonfx-android {
display: block;
}

html.firefox-old,
html.android,
html.ios {
#conditional-download-bar #dlbar-nonfx {
display: none;
}
}



/*--------------------------------------------------------------------------*/
Expand Down
53 changes: 20 additions & 33 deletions media/js/base/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ function init_download_links() {
}

function update_download_text_for_old_fx() {
// if using an out of date firefox
if (isFirefox() && !isFirefoxUpToDate()) {
// if using Firefox
if (isFirefox()) {
// look at each button to see if it's set to check for old firefox
$('.download-button').each(function() {
var $button = $(this);

if ($button.hasClass('download-button-check-old-fx')) {
// replace subtitle copy
$button.find('.download-subtitle').text(window.trans('global-update-firefox'));
}
});
var $buttons = $('.download-button-check-old-fx');

// if the page has download buttons
if ($buttons.length) {
window.Mozilla.Client.getFirefoxDetails(function(data) {
// if using an out of date firefox
if (!data.isUpToDate) {
// replace subtitle copy
$buttons.find('.download-subtitle').text(window.trans('global-update-firefox'));
}
});
}
}
}

Expand Down Expand Up @@ -75,6 +79,7 @@ function init_lang_switcher() {
}

//get Master firefox version
// TODO: Move this to Mozilla.Client
function getFirefoxMasterVersion(userAgent) {
var version = 0;
var ua = userAgent || navigator.userAgent;
Expand All @@ -91,19 +96,22 @@ function getFirefoxMasterVersion(userAgent) {
}

// Used on the plugincheck page to also support all browsers based on Gecko.
// TODO: Move this to Mozilla.Client
function isLikeFirefox(userAgent) {
var ua = userAgent || navigator.userAgent;
return (/Iceweasel/i).test(ua) || (/IceCat/i).test(ua) ||
(/SeaMonkey/i).test(ua) || (/Camino/i).test(ua) ||
(/like Firefox/i).test(ua);
}

// TODO: Move this to Mozilla.Client
function isFirefox(userAgent) {
var ua = userAgent || navigator.userAgent;
return (/\sFirefox/).test(ua) && !isLikeFirefox(ua);
}

// 2015-01-20: Gives no special consideration to ESR builds
// TODO: Move this to Mozilla.Client
function isFirefoxUpToDate(latest) {
var $html = $(document.documentElement);
var fx_version = getFirefoxMasterVersion();
Expand All @@ -121,41 +129,20 @@ function isFirefoxUpToDate(latest) {

// used in bedrock for desktop specific checks like `isFirefox() && !isFirefoxMobile()`
// reference https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference
// TODO: Move this to Mozilla.Client
function isFirefoxMobile(userAgent) {
var ua = userAgent || navigator.userAgent;
return /Mobile|Tablet|Fennec/.test(ua);
}

// iOS does not follow same version numbers as desktop & Android, so may not be safe to
// simply add this check to isFirefox. Will require further investigation/testing.
// TODO: Move this to Mozilla.Client
function isFirefoxiOS(userAgent) {
var ua = userAgent || navigator.userAgent;
return /FxiOS/.test(ua);
}

// Detect Firefox ESR simply by the *non-ESR* build IDs, as a fallback of the channel detection by
// the mozUITour API. There would be some false positives if the browser is a pre-release (Nightly,
// Aurora or Beta), semi-official (e.g. Ubuntu build by Canonical) or unofficial version of Firefox,
// because those builds have a different build ID from the official non-ESR build.
function isFirefoxESR(userAgent, buildID) {
userAgent = userAgent || navigator.userAgent;
buildID = buildID || navigator.buildID;

if (!isFirefox(userAgent) || isFirefoxMobile(userAgent) || !buildID) {
return false;
}

var version = getFirefoxMasterVersion(userAgent);
var ESRs = {
// 38.0, 38.0.1, 38.0.5 and 38.0.6
// https://wiki.mozilla.org/Releases/Firefox_38/Test_Plan
38: ['20150508094354', '20150513174244', '20150525141253', '20150605094246']
// 45.0 goes here
};

return version in ESRs && ESRs[version].indexOf(buildID) === -1;
}

// Create text translation function using #strings element.
// TODO: Move to docs
// In order to use it, you need a block string_data bit inside your template,
Expand Down
Loading

0 comments on commit 1584f9e

Please sign in to comment.