Commits

Anonymous committed c38c47f

Fix cookie
Update version

Comments (0)

Files changed (9)

chrome/content/modifyheaders.js

     
     drop: function(targetRowID, orientation, dataTransfer) {
       var sourceRowID = dataTransfer.getData("text/plain");
-      ModifyHeaders.moveRow(sourceRowID, targetRowID, orientation)
+      ModifyHeaders.moveRow(sourceRowID, targetRowID, orientation);
     },
     
     getCellProperties: function(row, columnID, properties) { /* do nothing */ },
       this.saveButton.setAttribute("hidden", "false");
       
       this.nameTextbox.disabled = false;
-      if (this.valueTextbox.value.length > 0) {
+      //if (this.valueTextbox.value.length > 0) {
         this.valueTextbox.disabled = false;
-      }
+      //}
       this.commentTextbox.disabled = false;
       this.addButton.disabled = false;
       this.saveButton.disabled = false;

chrome/content/preferences-tab.xul

     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     ondialoghelp="ModifyHeaders.openHelp()"
     onload="ModifyHeaders.toggleWindow()"
-    onunload="ModifyHeaders.toggleWindow()">
+    onunload="ModifyHeaders.toggleWindow()"
+    ondrop="event.preventDefault()">
     
     <prefpane id="paneHeaders" label="Headers" selected="true" onpaneload="ModifyHeaders.start()"
         insertbefore="modifyheaders-window-sizetocontent"

chrome/content/preferences.xul

     ondialoghelp="ModifyHeaders.openHelp()"
     onload="ModifyHeaders.toggleWindow()"
     onunload="ModifyHeaders.toggleWindow()"
-    persist="screenX screenY width height sizemode">
+    persist="screenX screenY width height sizemode"
+    ondrop="event.preventDefault()">
 
     <prefpane id="paneHeaders" label="Headers" selected="true" onpaneload="ModifyHeaders.start()"
         src="chrome://modifyheaders/content/prefs-headers.xul" flex="1"/>

chrome/content/prefs-headers.xul

             <tree id="modifyheaders-tree" seltype="single" hidecolumnpicker="true" flex="1"
                 ondblclick="ModifyHeaders.enableHeader();"
                 ondragstart="ModifyHeaders.headerListTreeView.dragStart(event)">
-              <treecols>
+              <treecols ondragstart="event.stopPropagation();">
                 <treecol id="actioncol" label="&modifyheaders.treecol.action;" fixed="true" ignoreincolumnpicker="true" />
                 <treecol id="namecol" label="&modifyheaders.treecol.name;" flex="1" persist="width" ignoreincolumnpicker="true" />
                 <splitter class="tree-splitter" />

chrome/locale/en-US/modifyheaders.dtd

 <!-- <!ENTITY modifyheaders.key "A"> -->
 <!ENTITY modifyheaders.label "Header">
 <!ENTITY modifyheaders.extension.name "Modify Headers">
-<!ENTITY modifyheaders.extension.version "0.7.0">
+<!ENTITY modifyheaders.extension.version "0.7.0.2">
 <!ENTITY modifyheaders.author.name "Gareth Hunt">
 
 <!-- Buttons -->
 
 <!-- URLs -->
 <!ENTITY modifyheaders.url.homepage "http://www.garethhunt.com/modifyheaders/">
-<!ENTITY modifyheaders.url.homepage.v "http://www.garethhunt.com/modifyheaders/?v=0.7.0">
+<!ENTITY modifyheaders.url.homepage.v "http://www.garethhunt.com/modifyheaders/?v=0.7.0.2">
 <!ENTITY modifyheaders.url.icons1 "http://cargocollective.com/davidferreira">
 <!ENTITY modifyheaders.url.icons2 "http://www.wpzoom.com/wpzoom/new-freebie-wpzoom-developer-icon-set-154-free-icons/">
 <!ENTITY modifyheaders.url.defects "http://modifyheaders.mozdev.org/bugs.html">
-<!ENTITY modifyheaders.url.defects.v "http://modifyheaders.mozdev.org/bugs.html?v=0.7.0">
+<!ENTITY modifyheaders.url.defects.v "http://modifyheaders.mozdev.org/bugs.html?v=0.7.0.2">
 <!ENTITY modifyheaders.url.twitter "http://twitter.com/modifyheaders">
 <!ENTITY modifyheaders.url.contribute "https://addons.mozilla.org/en-US/firefox/addon/modify-headers/">

chrome/locale/en-US/modifyheaders.properties

 modifyheaders.button.help=Help
-modifyheaders.url.help=http://www.garethhunt.com/modifyheaders/help/?v=0.7.0
+modifyheaders.url.help=http://www.garethhunt.com/modifyheaders/help/?v=0.7.0.2

components/modifyheaders-service.js

 					// TODO Fetch only enabled headers
 					var headers = JSON.parse(this.modifyheadersService.getHeaders());
 					
+					var storageCookes;
+					
 					// TODO See if a foreach is better here
-					for (var i=0; i < headers.length; i++) {
-						if (headers[i].enabled) {
-							var headerName = headers[i].name;
-							
-							// This is the default for action = Modify
-							var headerValue = headers[i].value;
-							var headerAction = headers[i].action;
+					for (var key in headers) {
+						
+						var header = headers[key];
+					
+						if (header.enabled) {
+						
+							var headerName = header.name.toUpperCase();
+							var headerValue = header.value;
+							var headerAction = header.action;
 							var headerAppend = false;
 							
 							if (headerAction == "Add") {
 							}
 							
 							// Handle Cookies separately
-							if (headerName.toLowerCase() == "cookie") {
-								headerAppend = false;
-								if (headerAction == "Add" || headerAction == "Add before") {
+							if (headerName == "COOKIE") {
+								if (headerAction == "Modify") {
+									storageCookes = [];
+								}
+								if (headerAction == "Add before" || headerAction == "Add after") {
+									headerAppend = false;
 									// Throws failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIHttpChannel.getRequestHeader]
 									// if the Cookie is filtered before a new Cookie value is added
-									try {
-										var currentHeaderValue = subject.getRequestHeader(headerName);
+									try {										
+										var cookies = [];
+										
+										if(cookies.length == 0){
+											cookies = subject.getRequestHeader(headerName).split(/;/);
+											//Components.utils.reportError("currentHeaderValue 1");
+										} else {
+											cookies = storageCookes;
+											//Components.utils.reportError("currentHeaderValue 2");
+										}																		
+									
+										//headerValue = headerValue.trim();
+										//headerValue = str.replace(/;+$|^;+/g,"");										
 										
 										if(headerAction == "Add before"){										
-											headerValue = headerValue + "; " + currentHeaderValue + "; ";
-											headerAppend = false;				
+											//headerValue = headerValue + "; " + currentHeaderValue;
+											cookies.unshift(headerValue);
+											//Components.utils.reportError("Cookies unshift");
 										} else {
-											headerValue = currentHeaderValue + "; " + headerValue + "; ";														
+											//headerValue = currentHeaderValue + "; " + headerValue;												
+											cookies.push(headerValue);
+											//Components.utils.reportError("Cookies push");
 										}
+										array_unique(cookies);
+										storageCookes = cookies;
+										
+										//Components.utils.reportError("Cookies length:" + storageCookes.length);
+										
+										headerValue = cookies.join(';');
 										
 									} catch (err) {
 										// Continue after error. Commenting out so the JS console is not spammed 
-										// Components.utils.reportError("Continuing after error: " + err.message);
+										//Components.utils.reportError("Continuing after error: " + err.message);										
 									}
 								}
 							}
 							
+							//Components.utils.reportError("Set header: " + headerName + "=" + headerValue + ", " + headerAppend);
 							subject.setRequestHeader(headerName, headerValue, headerAppend);
-						}
-					}
-					// TODO Add an optional ModifyHeaders header so that users know the tool is active
-					// subject.setRequestHeader("x-modifyheaders", "version 0.4", true)
+							/*Components.classes["@mozilla.org/consoleservice;1"]
+								.getService(Components.interfaces.nsIConsoleService)
+								.logStringMessage("Set header: " + headerAction + " " + headerName + "=" + headerValue + ", " + headerAppend);*/
+						}					
+					}					
 				}
+					
+				// TODO Add an optional ModifyHeaders header so that users know the tool is active
+				// subject.setRequestHeader("x-modifyheaders", "version 0.4", true)
+			
 			} else if (topic == 'profile-after-change') {
 				if ("nsINetModuleMgr" in Components.interfaces) {
 					// Should be an old version of Mozilla (before september 15, 2003
 
 /* Entry point - registers the component with the browser */
 if (XPCOMUtils.generateNSGetFactory) {
+
+function array_unique( array ) {	// Removes duplicate values from an array
+	// 
+	// +   original by: Carlos R. L. Rodrigues
+
+	var p, i, j;
+	for(i = array.length; i;){
+		for(p = --i; p > 0;){
+			if(array[i] === array[--p]){
+				for(j = p; --p && array[i] === array[p];);
+				i -= array.splice(p + 1, j - p).length;
+			}
+		}
+	}
+
+	return true;
+}
+
     var NSGetFactory = XPCOMUtils.generateNSGetFactory([ModifyHeaders.Service,ModifyHeaders.Header,ModifyHeaders.Proxy]);
 } else {
     var NSGetModule = XPCOMUtils.generateNSGetModule([ModifyHeaders.Service,ModifyHeaders.Header,ModifyHeaders.Proxy]);
 var skinFlag            = SKIN | PROFILE_CHROME;
 
 var displayName         = "Modify Headers";
-var version             = "0.7.0";
+var version             = "0.7.0.2";
 
 var name                = "modifyheaders";
 var jarName             = name + ".jar";
         <em:name>Modify Headers</em:name>
         <em:optionsURL>chrome://modifyheaders/content/preferences.xul</em:optionsURL>
         <em:type>2</em:type>
-        <em:version>0.7.0</em:version>
+        <em:version>0.7.0.2</em:version>
         
         <!-- Firefox 3.6.* - 4.0 -->
         <!-- Due to changes in XPCOM, Firefox prior to version 3 is no longer supported -->