firefox extension saving in preferences - string

I want to save a simple string into preferences in my firefox extension. The string should be accessible between separate browser sessions and after reboot. I found the following code but for some reason it is not working. I tried localStorage before but this was also not working:
Code for saving function:
var prefs = Components.classes["#mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var str = Components.classes["#mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
str.data = window['myglobalvariable'];
prefs.setComplexValue("myglobvar",
Components.interfaces.nsISupportsString, str);
Code for retrieval function:
var prefs = Components.classes["#mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var value = prefs.getComplexValue("myglobvar",
Components.interfaces.nsISupportsString).data;
I cannot figure out why is it not working.

if your preference is a integer or boolean getCharPref wont work you would have to use
getBoolPref() or getIntPref()
http://blog.mozilla.org/addons/2009/01/28/how-to-develop-a-firefox-extension/

Related

Can navigator give you the language/languages in Angular Universal?

My question stems from the fact that navigator works for the browser but we don't have that on the server but in our codebase at work I have seen code like this:
navigator.language.slice(0, 2);
and of course we are using domino to provide these window objects
win.Object = Object;
win.Math = Math;
global["window"] = win;
global["document"] = win.document;
global["branch"] = null;
global["object"] = win.object;
global["HTMLElement"] = win.HTMLElement;
global["navigator"] = win.navigator;```
No it cannot, domino provides a fake DOM server side.
You will need to either use a separate url for each language of your website, and/or save user preferences in cookies so that you can use the right language during SSR.

Acumatica - PXRedirectToFileException not redirecting in 2019R2

We're currently going through upgrading and ran into an issue where we can no longer redirect a user to one of our files. We've tried all of the different redirect methods, but for example purposes this is the easiest to show. If you use the below action and feed it a file it does nothing. However, if you change the "false" to "true" (for forcedownload) it will indeed download the file. This reinforces what we have seen with the other redirect methods. The system will not let you redirect to a URL that has .ashx in the url.
Is this an intentional change or is this a bug? We tried both 19.205.0023 and 19.207.0026
Thanks for your help =)
public PXAction<UsrDesign> viewFile;
[PXUIField(DisplayName = "View File")]
[PXButton()]
protected virtual void ViewFile ()
{
string fileName = Design.Current.ProofFile; // whatever file you want, in our case it comes from custom screen
UploadFile uploadFile = PXSelect<UploadFile, Where<UploadFile.name, Equal<Required<UploadFile.name>>>>.Select(this, fileName);
UploadFileMaintenance fileGraph = PXGraph.CreateInstance<UploadFileMaintenance>();
var file = fileGraph.GetFile((Guid)uploadFile.FileID);
throw new PXRedirectToFileException(file, false);
}

How to change 'new String(Base64.encodeBase64("ABCD".getBytes())); (java)' into Node.js?

In Java, I have below code
String plainCredentials = "ABCD";
String base64Credentials = new String(Base64.encodeBase64(plainCredentials.getBytes()));
I'd like to change it into Node.js
This is how I am trying
var authentication = new Buffer.from("ABCD");
base64Credentials = authentication.toString('base64');
But the result is coming wrong.
How can I change the above Java code into Node.js code ?
Well I think, below code should give you the correct result (Its the same one as yours just one liner).
const base64Credentials = Buffer.from('ABCD').toString('base64');
Output: QUJDRA==
If not then please edit your question and post the string which you are getting in your java program.

NPP_New not getting called in few webpages (Chrome and Safari)

I am trying to access NPAPI plugin from content/inject script of Chrome/Safari extensions.
The code to embed the plugin object and access methods.
var newElement = document.createElement("embed");
newElement.id = "myPluginID";
newElement.type = "application/x-mychrome-plugin";
var newAttr = document.createAttribute("hidden");
newAttr.nodeValue = "true"
newElement.setAttributeNode(newAttr);
newElement.style.zIndex = "-1";
newElement.style.position = "absolute";
newElement.style.top = "0px";
document.documentElement.appendChild(newElement);
plugin = document.getElementById("myPluginID"); //this shows as HTML element when evaluated in JavaScript console.
plugin.myPluginMethod() // this shows as undefined instead of native code(When evaluated in JavaScript console),for pages where NPP_New is not called.
This works for most of the webpages,but for few pages(eg:www.stumbleupon.com),NPP_New is not called(debugging using Xcode 4) and scriptable object is not created and all the plugin methods are undefined.
Any inputs.
Why are you putting your embed as a child of document.documentElement (i.e., <html>) instead of in the body? I wouldn't expect a plugin that's not going to be displayed to be instantiated.

Set Cookie for UIWebView requests

I want to embed an UIWebView into my MonoTouch application for an area that is not yet implemented natively.
In order to authenticate with the website I want to set a cookie containing a key for the current session.
I tried creating a NSDictionary with the properties for the Cookie and then create a new NSHttpCookie and add it to the NSHttpCookieStorage.SharedStorage.
Sadly the cookie seems to be empty and not used for the request.
An example of how to build be cookie with properties and a comment on whether or not this is the simplest way to do this would be greatly appreciated.
Following Anuj's bug report I felt bad about how many lines of code were required to create the cookies. So the next MonoTouch versions will have new constructors for NSHttpCookie, similar to System.Net.Cookie that will allow you do to something like:
// this ctor requires all mandatory parameters
// so you don't have to guess them while coding
var cookie = new NSHttpCookie ("iherd", "ulikecookies", "/", "yodawg.com");
You'll even be able to create a NSHttpCookie from a .NET System.Net.Cookie.
Note: Never hesitate to fill a bug report when an API proves to be way more complicated than it should be :-)
Whenever I need to send cookies and params up to the server I use something like RestSharp or Hammock and then pass the response.Content value into UIWebView's loadHtmlString method:
//setup cookies and params here
var response = client.Execute(req);
_webView = new UIWebView();
_webView.LoadHtmlString(response.Content, new NSUrl(baseUrl));
The NSDictionary API is fairly trivial too:
var props = new NSMutableDictionary ();
props.Add (NSHttpCookie.KeyOriginURL, new
NSString("http://yodawg.com"));
props.Add (NSHttpCookie.KeyName, new NSString("iherd"));
props.Add (NSHttpCookie.KeyValue, new NSString("ulikecookies"));
props.Add (NSHttpCookie.KeyPath, new NSString("/"));
AFAIK every application has its own cookie storage so try to use this code before rendering the page in the UIWebView
NSHttpCookie cookie = new NSHttpCookie()
{
Domain = "yourdomain.com",
Name = "YourName",
Value = "YourValue" //and any other info you need to set
};
NSHttpCookieStorage cookiejar = NSHttpCookieStorage.SharedStorage;
cookiejar.SetCookie(cookie);
I'm not in a MAC right now so im not able to test it hope this helps
okay sorry, i wasn't able to test it before posting, anyways I won't get home until tonight so give this a spin
var objects = new object[] { "http://yoururl.com", "CookieName", "CookieValue", "/" };
var keys = new object[] { "NSHTTPCookieOriginURL", "NSHTTPCookieName", "NSHTTPCookieValue", "NSHTTPCookiePath" };
NSDictionary properties = (NSDictionary) NSDictionary.FromObjectsAndKeys(objects, keys);
NSHttpCookie cookie = NSHttpCookie.CookieFromProperties(properties);
NSHttpCookieStorage.SharedStorage.SetCookie(cookie);
As you stated above, in the case that doesn't work might be a bug on monotouch binding so you can bind it manually by doing this
var objects = new object[] { "http://yoururl.com", "CookieName", "CookieValue", "/" };
var keys = new object[] { "NSHTTPCookieOriginURL", "NSHTTPCookieName", "NSHTTPCookieValue", "NSHTTPCookiePath" };
NSDictionary properties = (NSDictionary) NSDictionary.FromObjectsAndKeys(objects, keys);
NSHttpCookie cookie = (NSHttpCookie) Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend_IntPtr(new Class("NSHTTPCookie").Handle, new Selector("cookieWithProperties:").Handle, properties.Handle))
NSHttpCookieStorage.SharedStorage.SetCookie(cookie);
also don't forget to include using MonoTouch.ObjCRuntime; if manually binding it
if manually binding works please don't forget to post a bug report on https://bugzilla.xamarin.com/
Alex
I’ve wrote the NSMutableURLRequest+XSURLRequest catagory and XSCookie class to do this;-) http://blog.peakji.com/cocoansurlrequest-with-cookies/
This might give you a lead. Previously I used a similar strategy to make a
WebRequest to a site and collect cookies which were stored in the .Net/Mono CookieStore. Then when loading a url in the UIWebView I copied those cookies over to the NSHttpCookieStorage.
public NSHttpCookieStorage _cookieStorage;
/// <summary>
/// Convert the .NET cookie storage to the iOS NSHttpCookieStorage with Login Cookies
/// </summary>
void DotNetCookieStoreToNSHttpCookieStore()
{
foreach (Cookie c in _cookies.GetCookies(new Uri(UrlCollection["Login"], UriKind.Absolute))) {
Console.WriteLine (c);
_cookieStorage.SetCookie(new NSHttpCookie(c));
}
}

Resources