Ruby in the Browserwhy, how, and how do we get there?Ilya Grigorik@igrigorik
How many languages are you proficient in?take a few seconds…
…………
JavaScriptCSSDOMActionScriptJava AppletsActiveX…
Don’t know it, therefore don’t like itMiserable experience with the DOM, hated it(long pause)Prototype + JQuery: hey, this is not badWriting pure JS FF extension – fun!Maintaining extension + debug: it’s ok…(personal) conclusion: it’s a great language (personal) JavaScript retrospectivein 6 acts…
JavaScript as a monopoly?they (ECMA) are colluding against us!
………Diversity is good!experimentation leads to innovation…
50+ Ruby implementationscredit to Konstantin Haase - @rkh
Case in point…
Disclaimer: I work for Google. I have no affiliation to NaCl, Chrome, … teams. All opinions are my own, etc… :-)
Ruby in the browser?that would be nice…
Ruby/Python/X/Y/Z in the browserwould be even better!
http://tryruby.org/
require 'em-synchrony'require 'em-synchrony/em-http'require 'em-http/middleware/json_response'TRYRUBY = 'http://tryruby.org/levels/1/challenges/0/play’EM::HttpRequest.use EM::Middleware::JSONResponseEM.synchrony do  r =EM::HttpRequest.new(TRYRUBY).put :body => {:cmd => '1+1'}  puts r.response['output'] # => 2  r =EM::HttpRequest.new(TRYRUBY).put :body => {:cmd => 'RUBY_VERSION'}  puts r.response['output'] # => 1.9.2endServer-side sessionsnot really in your browser…
require 'em-synchrony'require 'em-synchrony/em-http'require 'em-http/middleware/json_response'TRYRUBY = 'http://tryruby.org/levels/1/challenges/0/play’EM::HttpRequest.use EM::Middleware::JSONResponseEM.synchrony do  r =EM::HttpRequest.new(TRYRUBY).put :body => {:cmd => ’”a” * (2**25)’}  puts r.response['output'] # => ...endSo, how much RAM can we claim?security is always an issue…
In the browser, for real..anyone crazy enough to try?
http://visitmix.com/work/gestalt/
<script type="text/ruby">defonclick(s,e)window.alert"Hello, World!"  enddocument.say_hello.attach_event('onclick',    System::EventHandler [    System::Windows::Browser::HtmlEventArgs    ].new(method(:onclick)))</script>How awesome is that?IronRuby, IronPython, …Micorosoft’s Silverlight + DLRsweet!
JavaScriptCSSDOMGestaltIronPythonIronRubyC#F#Dynamic Language Runtime
Is there a future for Silverlight?How about IronRuby?I hope so.. x2
Browser pluginsa brief detour…
Setting: Live demo to Jim Clark (CEO of Netscape)Links to any file other than an image cause the user to be prompted to download the file.. However, when a user clicked on a link to a PDF file, the file instantly opened within the browser window, seamlessly blending HTML and PDF consumption!Clark: wow, who provided the support on our side?Adobe:  we reverse-engineered it… Inception
Implemented in Netscape 2
Implemented / in-use by most browsers to this day
Plugin registers a content-type, ex: music/mp3
Browser encounters the file, delegates to plugin
Ex: Flash, Silverlight, Quicktime, Acrobat, etc..NPAPI is bornNetscape Plugin API
JavaScriptCSSDOMNPAPIFlashSilverlight…External binaries
NPAPIStandalone process
Full access to your OS
Full access to your filesystem
…
Full access to wreck havocSecurity nightmareor we why we love to hate pluginsFlashSilverlight…External binaries
Google ChromeWebKit, V8, NaCl, speed…* soon to be #2
Process#1Process#2Process#3Tabs are:Isolated processes
Own security sandbox per tabFlash MovieSecurity ???Security & Isolationare a big focus in Chrome
JavaScriptCSSDOMNPAPIFlashSilverlight…External binaries
JavaScriptCSSDOMPepper (PPAPI)Pepper bridgeSandboxed pluginNaClNaClPluginPluginNaClNative ClientSandboxing technology for safe execution of native code
Native machine code runs on the client CPU
Not an interpreterCompile code using specialized toolchain
Modified GCC compiler, etc
Build for different CPU architectures
NaCl runtime verifies untrusted code (static analysis)
NaCl executes verified code
No fork, process control, file system access, etc.http://code.google.com/chrome/nativeclient/
receive messagefunctionmoduleDidLoad() {HelloTutorialModule=document.getElementById('hello_tutorial');HelloTutorialModule.addEventListener('message', handleMessage, false);// Send a message to the NaCl moduleHelloTutorialModule.postMessage('hello');}send messageTalking to NaClvia Pepper API
virtualvoidHandleMessage(constpp::Var& var_message) {if (!var_message.is_string())return;std::string message = var_message.AsString();pp::Varvar_reply;var_reply = pp::Var(kReplyString);PostMessage(var_reply);}dispatch responseTalking to the Browservia Pepper API
<embedname="nacl_module"id="hello_tutorial"width=0 height=0src="hello_tutorial.nmf"type="application/x-nacl" />Connecting the Pipes: NaCl, Pepperexecuting native code in the browser
http://code.google.com/chrome/nativeclient/docs/reference/peppercpp/Audio
FileIO
Graphics2D
ImageData

Ruby in the Browser - RubyConf 2011