| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | 4 |
| 5 require.scopes.info = { | 5 (function() { |
| 6 addonName: {{metadata.get('general', 'basename')|json}}, | 6 var platformVersion = null; |
| 7 addonVersion: {{version|json}}, | 7 var application = null; |
| 8 addonRoot: "", | 8 var applicationVersion; |
| 9 | 9 |
| 10 application: {{type|json}}, | 10 var regexp = /(\S+)\/(\S+)(?:\s*\(.*?\))?/g; |
|
kzar
2015/12/15 17:26:00
Nit: More descriptive name would be nice, perhaps
Sebastian Noack
2015/12/15 17:31:31
Well, the context here is limitted. And after all
| |
| 11 get applicationVersion() | 11 var match; |
| 12 | |
| 13 while (match = regexp.exec(navigator.userAgent)) | |
|
kzar
2015/12/15 17:26:00
Maybe a comment for this loop explaining that we'r
Sebastian Noack
2015/12/15 17:31:31
Well, how could a comment make it more obvious tha
| |
| 12 { | 14 { |
| 13 {%- if type == 'opera' %} | 15 var app = match[1]; |
| 14 var match = /\bOPR\/(\S+)/.exec(navigator.userAgent); | 16 var ver = match[2]; |
| 15 return (match ? match[1] : "0"); | |
| 16 {%- else %} | |
| 17 return this.platformVersion; | |
| 18 {%- endif %} | |
| 19 }, | |
| 20 | 17 |
| 21 platform: "chromium", | 18 if (app == "Chrome") |
| 22 get platformVersion() | 19 { |
| 20 platformVersion = ver; | |
| 21 } | |
| 22 else if (app != "Mozilla" && app != "AppleWebKit" && app != "Safari") | |
| 23 { | |
| 24 // For compatibility with legacy websites, Chrome's UA | |
| 25 // also includes a Mozilla, AppleWebKit and Safari token. | |
| 26 // Any further name/version pair indicates a fork. | |
| 27 application = app == "OPR" ? "opera" : app.toLowerCase(); | |
|
Sebastian Noack
2015/12/15 16:36:58
For reference, some UAs, I tested the logic agains
kzar
2015/12/15 17:26:00
Nit: Maybe just do `application = app.toLowerCase(
Sebastian Noack
2015/12/15 17:31:31
I don't think that spreading these conversions acr
| |
| 28 applicationVersion = ver; | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 // not a Chromium-based UA, probably modifed by the user | |
| 33 if (!platformVersion) | |
| 23 { | 34 { |
| 24 var match = /\bChrome\/(\S+)/.exec(navigator.userAgent); | 35 application = "unknown"; |
| 25 return (match ? match[1] : "0"); | 36 applicationVersion = platformVersion = "0"; |
| 26 } | 37 } |
| 27 }; | 38 |
| 39 // no additional name/version, so this is upstream Chrome | |
| 40 if (!application) | |
| 41 { | |
| 42 application = "chrome"; | |
| 43 applicationVersion = platformVersion; | |
| 44 } | |
| 45 | |
| 46 require.scopes.info = { | |
| 47 addonName: {{ metadata.get('general', 'basename')|json }}, | |
| 48 addonVersion: {{ version|json }}, | |
| 49 addonRoot: "", | |
| 50 | |
| 51 application: application, | |
| 52 applicationVersion: applicationVersion, | |
| 53 | |
| 54 platform: "chromium", | |
| 55 platformVersion: platformVersion | |
| 56 }; | |
| 57 })(); | |
| OLD | NEW |