Showing posts with label developer. Show all posts
Showing posts with label developer. Show all posts

Saturday, October 1, 2011

How to load an NPAPI plugin inside a Safari extension, sort of ...


I was recently developing a Safari extension that had to hold an NPAPI plugin inside, but I realized that NPAPI plugins don't work inside the global.html page that runs on the Safari background. I have not seen  anything explaining this behavior in the Safari developer documentation, but I suspect that the problem is that as the global.html page is never displayed, Safari does not even try to load this kind of objects.

The only solution I have found is to put the NPAPI object inside a popover, which is loaded when the application launches and is a common instance inside Safari. The only problem of this is that the object is loaded only when the popover is shown (shit!), although all the javascript is loaded at the beginning. So if your extension has a popover and it must be shown on a common use case, you are good to go, but if not, there is a "crappy" solution that you can try. What I have done (which is veeery tricky...) is assign the popover that holds the NPAPI plugin to a toolbar button, then show the popover programmatically from the global.html page javascript, hide it again and unassign the popover from the toolbar button. The result is that when Safari is launched you momentarily see a popover shown and hidden immediately, but you have access to your NPAPI plugin inside your Safari extension :)

As this solution is a very crappy and unpleasant solution for a developer, please if you find a cleaner one, use that one and share it here ;)

This is the code I have used:

Inside the global.html page:

function deregisterPopover () {
    for (t in safari.extension.toolbarItems) {
        if (safari.extension.toolbarItems[t].identifier === "toolbar-button") {
            safari.extension.toolbarItems[t].popover.hide();
            // Deregister the popover from the toolbar button
            safari.extension.toolbarItems[t].popover = null;
        }
    }
}

// Find the popover that holds the NPAPI plugin
for (t in safari.extension.toolbarItems) {
    if (safari.extension.toolbarItems[t].identifier === "toolbar-button") {
        safari.extension.toolbarItems[t].showPopover();
        safari.extension.toolbarItems[t].popover.hide();
        NpapiPlugin = safari.extension.toolbarItems[t].popover.contentWindow.getPlugin();
    }
}

Inside the popover that holds the NPAPI plugin:

<html>
<head>
    <script>
    function pluginLoaded () {
        safari.extension.globalPage.contentWindow.deregisterPopover();
    }
    function getPlugin() {
        return document.getElementById("npapi-plugin");
    }
    </script>
</head>
<body>
<object type="application/x-test-npapi" id="npapi-plugin">
    <param name="onload" value="pluginLoaded">
</object>
</body>
</html>

Then you will have to register the popover to the toolbar button toolbar-button from the Safari Extension Builder.

More information | StackOverflow

Tuesday, March 29, 2011

3DS Barcelona 2011

Aquest serà un cap de setmana bastant especial, ja que durant els dies 1,2 i 3 d'abril es celebra el 3 Day Startup (3DS) a Technova Barcelona, La Salle. Es tracta d'un accelerador d'empreses que ofereix als estudiants una gran oportunitat de fer realitat les seves idees i ambicions, durant un intens cap de setmana. No ho explicaré millor que els propis organitzadors de l'event, així que deixo un parell de links al final del post.

El diumenge dia 3 d'abril a les 18:00 hi ha portes obertes, per a que la gent pugui venir i veure les presentacions dels diferents projectes. Lloc: C/Lluçanès 41-43, Barcelona.
Pel que tinc entès les places son limitades, així que si voleu ser-hi podeu registrar-vos a través de l'enllaç d'evenbrite de sota. Des d'aquí us convido a que, si teniu un rato el diumenge per la tarda, us hi passeu perquè segur serà molt interessant ;)

Enllaços:
Web oficial | http://www.3daystartup.com/barcelona
Evenbrite | http://3dsbarcelona.eventbrite.com/
Facebook | http://www.facebook.com/home.php?sk=group_176990415667764

Friday, February 11, 2011

Hack U de Yahoo!

Aquest cap de setmana es celebra a la FIB el Hack U de Yahoo! És una 'competició' entre varis equips de màxim 4 persones per resoldre un repte (se suposa que informàtic) en 24 hores. Es tracta d'un esdeveniment que Yahoo! porta fent des de fa 6 anys a diferents universitats d'estats units, com Georgia Tech, University of Washington, etc. I aquest any és el primer que salten el xarco, i ho fan aquí a la UPC, lo qual suposa una gran oportunitat per als FIBers (i no FIBers) d'assistir a un esdeveniment d'aquest tipus.

Avui han fet una petita presentació del funcionament, eines molt útils que ens facilitaran molt la feina (de Yahoo! òbviament... xD), hacks d'altres anys, etc. i una mica de soparet al final de tot. Les 24 hores de hacking comencen demà divendres a les 16h, i pel que sembla seran 24 hores molt entretingudes. Segons ens han dit porten menjar, beure, drogues varies per a que no dormim, música i demés. Encara que també es pot marxar a dormir, menjar, anar a fer unes cerveses,... quan es vulgui.

El que veig més peliagut són els 90 segons de presentació que hem de fer davant de tothom al final de les 24 hores. Si, 90 segons, temps de sobres per fer un powerpoint de 50 pagines, demos, ronda triple de preguntes i un descans pel mig per anar a fer un cafè. :)

Veritablement la xixa comença demà, així que qui es vulgui apuntar encara està a temps. De fet ja ens han animat a portar més gent, que hi ha menjar per tothom. :D

Aclaració: s'ha de diferenciar entre hacker i cracker. Hack no té res a veure amb la pirateria, ni seguretat informàtica, ni virus ni res semblant. Un hack és una aplicació/funcionalitat/xorrada útil que es realitzi en temps i recursos reduïts (en aquest cas 24 hores), i un hacker es la persona que desenvolupa aquest hack.

Intentaré anar publicant una mica de info al llarg d'aquest dos dies.

Altres hacks | http://developer.yahoo.com/hacku/pasthacks.html
Kick Ass | http://erkie.github.com/
TipTheWeb | http://tiptheweb.org/