Bug 1330973 - WebsiteMetadata.jsm: Add description length to Metadata JSON. r=Grisha
authorSebastian Kaspari <s.kaspari@gmail.com>
Thu, 02 Feb 2017 16:21:54 +0100
changeset 394836 c7220d8cf144119bac43d78c6953e50c54995abb
parent 394835 69f111a766671ed7bf02bf4a278773a4faeacc4c
child 394837 93af928758e78c567610e7d68ac2ff4f6fb8480b
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGrisha
bugs1330973
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1330973 - WebsiteMetadata.jsm: Add description length to Metadata JSON. r=Grisha MozReview-Commit-ID: 4zxaHPLEWJ6
mobile/android/modules/WebsiteMetadata.jsm
--- a/mobile/android/modules/WebsiteMetadata.jsm
+++ b/mobile/android/modules/WebsiteMetadata.jsm
@@ -17,17 +17,18 @@ var WebsiteMetadata = {
   /**
    * Asynchronously parse the document extract metadata. A 'Website:Metadata' event with the metadata
    * will be sent.
    */
   parseAsynchronously: function(doc) {
     Task.spawn(function() {
       let metadata = getMetadata(doc, doc.location.href, {
         image_url: metadataRules['image_url'],
-        provider: metadataRules['provider']
+        provider: metadataRules['provider'],
+        description_length: metadataRules['description_length']
       });
 
       // No metadata was extracted, so don't bother sending it.
       if (Object.keys(metadata).length === 0) {
         return;
       }
 
       let msg = {
@@ -87,22 +88,31 @@ function buildRuleset(name, rules, proce
           return value.trim();
         }
         return value;
       }
     }
   };
 }
 
+const descriptionRules = [
+  ['meta[property="og:description"]', node => node.element.getAttribute('content')],
+  ['meta[name="description"]', node => node.element.getAttribute('content')],
+];
+
 const metadataRules = {
   description: {
-    rules: [
-      ['meta[property="og:description"]', node => node.element.getAttribute('content')],
-      ['meta[name="description"]', node => node.element.getAttribute('content')],
-    ],
+    rules: descriptionRules
+  },
+
+  description_length: {
+    rules: descriptionRules,
+    processors: [
+      (description) => description.length
+    ]
   },
 
   icon_url: {
     rules: [
       ['link[rel="apple-touch-icon"]', node => node.element.getAttribute('href')],
       ['link[rel="apple-touch-icon-precomposed"]', node => node.element.getAttribute('href')],
       ['link[rel="icon"]', node => node.element.getAttribute('href')],
       ['link[rel="fluid-icon"]', node => node.element.getAttribute('href')],