Bug 1215376 - refactor: re-use onShown event generator for onClicked draft
authorRob Wu <rob@robwu.nl>
Thu, 14 Sep 2017 16:41:14 +0200
changeset 670564 529890e6596990efbfc5f6023cc76481f571e016
parent 670563 ad3206237adc93d3eba1b0c69d53ad57fd0bed8b
child 670565 c5173f32aea2ef3a809f031c92a36107e6112bac
push id81676
push userbmo:rob@robwu.nl
push dateTue, 26 Sep 2017 17:26:42 +0000
bugs1215376
milestone57.0a1
Bug 1215376 - refactor: re-use onShown event generator for onClicked The logic in onClicked had some flaws: - editable can be undefined instead of a boolean. - linkText, linkUrl is set in non-link contexts. - srcUrl is set even in non-media contexts. This change does not add new tests, because test coverage for the event data generator is provided by: browser/components/extensions/test/browser/browser_ext_menus_events.js There is one observable change here. Previously, linkUrl and linkText would also be set for non-link context if the selected text contained a URL. When this happens, then nsContextMenu.js sets onPlainTextLink=true. With this refactor, linkText and linkUrl are only set if the context is "link" (onLink=true). MozReview-Commit-ID: 2xf1F41bn0U
browser/components/extensions/ext-menus.js
--- a/browser/components/extensions/ext-menus.js
+++ b/browser/components/extensions/ext-menus.js
@@ -628,47 +628,24 @@ MenuItem.prototype = {
     let menuMap = gMenuMap.get(this.extension);
     menuMap.delete(this.id);
     if (this.root == this) {
       gRootItems.delete(this.extension);
     }
   },
 
   getClickInfo(contextData, wasChecked) {
-    let mediaType;
-    if (contextData.onVideo) {
-      mediaType = "video";
-    }
-    if (contextData.onAudio) {
-      mediaType = "audio";
-    }
-    if (contextData.onImage) {
-      mediaType = "image";
-    }
-
     let info = {
       menuItemId: this.id,
-      editable: contextData.onEditableArea || contextData.onPassword,
     };
-
-    function setIfDefined(argName, value) {
-      if (value !== undefined) {
-        info[argName] = value;
-      }
+    if (this.parent) {
+      info.parentMenuItemId = this.parentId;
     }
 
-    setIfDefined("parentMenuItemId", this.parentId);
-    setIfDefined("mediaType", mediaType);
-    setIfDefined("linkText", contextData.linkText);
-    setIfDefined("linkUrl", contextData.linkUrl);
-    setIfDefined("srcUrl", contextData.srcUrl);
-    setIfDefined("pageUrl", contextData.pageUrl);
-    setIfDefined("frameUrl", contextData.frameUrl);
-    setIfDefined("frameId", contextData.frameId);
-    setIfDefined("selectionText", contextData.selectionText);
+    addMenuEventInfo(info, contextData, true);
 
     if ((this.type === "checkbox") || (this.type === "radio")) {
       info.checked = this.checked;
       info.wasChecked = wasChecked;
     }
 
     return info;
   },