B2G/gecko/testing/marionette/marionette-listener.js
/**
  * Add a cookie to the document
  */
Add a cookie to the document
Add a cookie to the document
function addCookie(msg) {
  cookie = msg.json.cookie;
  if (!cookie.expiry) {
    var date = new Date();
    var thePresent = new Date(Date.now());
    date.setYear(thePresent.getFullYear() + 20);
    cookie.expiry = date.getTime() / 1000;  
  }
  if (!cookie.domain) {
    var location = curWindow.document.location;
    cookie.domain = location.hostname;
  }
  else {
    var currLocation = curWindow.location;
    var currDomain = currLocation.host;
    if (currDomain.indexOf(cookie.domain) == -1) {
      sendError("You may only set cookies for the current domain", 24, null, msg.json.command_id);
    }
  }
  if (cookie.domain.match(/:\d+$/)) {
    cookie.domain = cookie.domain.replace(/:\d+$/, '');
  }
  var document = curWindow.document;
  if (!document || !document.contentType.match(/html/i)) {
    sendError('You may only set cookies on html documents', 25, null, msg.json.command_id);
  }
  var cookieManager = Cc['@mozilla.org/cookiemanager;1'].
                        getService(Ci.nsICookieManager2);
  cookieManager.add(cookie.domain, cookie.path, cookie.name, cookie.value,
                   cookie.secure, false, false, cookie.expiry);
  sendOk(msg.json.command_id);
}
function addCookie ( msg ) { cookie = msg . json . cookie ; if ( ! cookie . expiry ) { var date = new Date ( ) ; var thePresent = new Date ( Date . now ( ) ) ; date . setYear ( thePresent . getFullYear ( ) + 20 ) ; cookie . expiry = date . getTime ( ) / 1000 ; } if ( ! cookie . domain ) { var location = curWindow . document . location ; cookie . domain = location . hostname ; } else { var currLocation = curWindow . location ; var currDomain = currLocation . host ; if ( currDomain . indexOf ( cookie . domain ) == - 1 ) { sendError ( "You may only set cookies for the current domain" , 24 , null , msg . json . command_id ) ; } } if ( cookie . domain . match ( / :\d+$ / ) ) { cookie . domain = cookie . domain . replace ( / :\d+$ / , '' ) ; } var document = curWindow . document ; if ( ! document || ! document . contentType . match ( / html / i ) ) { sendError ( 'You may only set cookies on html documents' , 25 , null , msg . json . command_id ) ; } var cookieManager = Cc [ '@mozilla.org/cookiemanager;1' ] . getService ( Ci . nsICookieManager2 ) ; cookieManager . add ( cookie . domain , cookie . path , cookie . name , cookie . value , cookie . secure , false , false , cookie . expiry ) ; sendOk ( msg . json . command_id ) ; }
Add a cookie to the document
Add a cookie to the document
// Stored in seconds. // The cookie's domain may include a port. Which is bad. Remove it // We'll catch ip6 addresses by mistake. Since no-one uses those // this will be okay for now. See Bug 814416