Woovie Posted April 10, 2014 Share Posted April 10, 2014 I made a web browser so far it loads a page, back/forward work with history. Source below. (View in full screen) Still WIP of course local browser = {} browser.browsers = {} browser.homepage = "http://google.com/" browser.images = {} browser.tabs = {} browser.buttons = {} browser.history = {} browser.historyPos = {} browser.window = nil browser.tabpanel = nil browser.currentTab = nil browser.pages = requestBrowserPages({"localhost", "facebook.com", "google.com", "youtube.com", "twitch.tv", "pandora.com"}) local sx, sy = guiGetScreenSize() function newTab() for i=1,10 do if browser.tabs[i] == nil then browser.browsers[i] = createBrowser ( 1160, 740 ) browser.history[i] = {} browser.tabs[i] = guiCreateTab ( "Tab #"..i, browser.tabpanel ) browser.buttons[i] = { guiCreateButton ( 0, 5, 20, 20, "X", false, browser.tabs[i] ), guiCreateEdit ( 20, 5, 480, 20, browser.homepage, false, browser.tabs[i] ), guiCreateButton ( 500, 5, 20, 20, "Go", false, browser.tabs[i] ), guiCreateButton ( 520, 5, 20, 20, "<", false, browser.tabs[i] ), guiCreateButton ( 540, 5, 20, 20, ">", false, browser.tabs[i] ) } addEventHandler ( "onClientGUIClick", browser.buttons[i][1], closeTab, false ) addEventHandler ( "onClientGUIClick", browser.buttons[i][3], goPage, false ) addEventHandler ( "onClientGUIClick", browser.buttons[i][4], goBack, false ) addEventHandler ( "onClientGUIClick", browser.buttons[i][5], goForward, false ) addEventHandler ( "onClientCursorMove", root, function ( relx, rely, absx, absy ) local ix, iy = guiGetPosition ( browser.window, false ) ix, iy = ix + 20, iy + 80 injectBrowserMouseMove ( browser.browsers[i], absx-ix, absy-iy ) end ) addEventHandler ( "onClientClick", root, function ( button, state ) local buttons = {left = 0, middle = 1, right = 2} if state == "down" then injectBrowserMouseDown ( browser.browsers[i], buttons[button] ) else injectBrowserMouseUp ( browser.browsers[i], buttons[button] ) end end ) browser.historyPos[i] = 1 browser.currentTab = i loadBrowserURL ( browser.browsers[i], guiGetText ( browser.buttons[i][2] ) ) browser.history[i][1] = guiGetText ( browser.buttons[i][2] ) break end if i == 10 then outputChatBox ( "10 tabs maximum" ) break end end end function closeTab() if #browser.tabs > 1 then destroyElement ( browser.browsers[browser.currentTab] ) browser.browsers[browser.currentTab] = nil for k,v in ipairs ( browser.buttons[browser.currentTab] ) do destroyElement ( v ) end browser.buttons[browser.currentTab] = nil guiDeleteTab ( browser.tabs[browser.currentTab], browser.tabpanel ) browser.tabs[browser.currentTab] = nil else outputChatBox ( "Cannot close tab - at least one tab must be open." ) end end function changeTab() for k,v in ipairs ( browser.tabs ) do if v == source then browser.currentTab = k end end end function goPage() browser.history[browser.currentTab][#browser.history[browser.currentTab]+1] = guiGetText ( browser.buttons[browser.currentTab][2] ) browser.historyPos[browser.currentTab] = #browser.history[browser.currentTab] loadBrowserURL ( browser.browsers[browser.currentTab], guiGetText ( browser.buttons[browser.currentTab][2] ) ) end function stopPage() end function goBack() if browser.historyPos[browser.currentTab] > 1 then browser.historyPos[browser.currentTab] = browser.historyPos[browser.currentTab]-1 loadBrowserURL ( browser.browsers[browser.currentTab], browser.history[browser.currentTab][browser.historyPos[browser.currentTab]] ) guiSetText ( browser.buttons[browser.currentTab][2], browser.history[browser.currentTab][browser.historyPos[browser.currentTab]] ) end end function goForward() if browser.historyPos[browser.currentTab] < #browser.history[browser.currentTab] then browser.historyPos[browser.currentTab] = browser.historyPos[browser.currentTab]+1 loadBrowserURL ( browser.browsers[browser.currentTab], browser.history[browser.currentTab][browser.historyPos[browser.currentTab]] ) guiSetText ( browser.buttons[browser.currentTab][2], browser.history[browser.currentTab][browser.historyPos[browser.currentTab]] ) end end function browserToggle() if guiGetVisible ( browser.window ) then guiSetVisible ( browser.window, false ) showCursor ( false ) else guiSetVisible ( browser.window, true ) showCursor ( true ) end end function clientRender() if guiGetVisible ( browser.window ) then local ix, iy = guiGetPosition ( browser.window, false ) ix, iy, iw, ih = ix + 20, iy + 80, 1160, 700 updateBrowser ( browser.browsers[browser.currentTab] ) dxDrawImage ( ix, iy, iw, ih, browser.browsers[browser.currentTab], 0, 0, 0, tocolor ( 255, 255, 255, 255 ), true ) end end function resourceStart() browser.window = guiCreateWindow ( sx/2-600, sy/2-400, 1200, 800, "Woovie's Browser v0.1", false ) guiSetVisible ( browser.window, false ) browser.tabpanel = guiCreateTabPanel ( 10, 30, 1180, 760, false, browser.window ) addEventHandler ( "onClientGUITabSwitched", browser.tabpanel, changeTab ) newTab() bindKey ( "b", "up", browserToggle ) end addEventHandler ( "onClientRender", root, clientRender ) addEventHandler ( "onClientResourceStart", resourceRoot, resourceStart ) Link to comment
Noki Posted April 10, 2014 Share Posted April 10, 2014 Jusonex... That is purely amazing. I am just stunned for words. You have proven yet again we can do so much in MTA. Great work! I bet this would piss off SAMP players. Link to comment
bradio10 Posted April 10, 2014 Share Posted April 10, 2014 (edited) Holy shit. Nice work dude! Can't wait for keyboard integration. This is the best!! Keep it up man! When I go and play a youtube video, it says I need adobe player. When I go and play Nyan Cat, I can't hear sound. Have I done something wrong? Edited April 10, 2014 by Guest Link to comment
Cobra Posted April 10, 2014 Share Posted April 10, 2014 would that be integrated in MTA 1.4 or any later Versions ? That would be very very cool, if that would be integrated anyway in mta 1.4 Link to comment
lopezloo Posted April 10, 2014 Share Posted April 10, 2014 (edited) When I go and play a youtube video, it says I need adobe player. You need to install Adobe Flash Player for other browsers. https://get.adobe.com/pl/flashplayer/otherversions/ Or just simply play video in HTML5 (add &html5=true to link) but not all videos support it. Edited September 12, 2014 by Guest Link to comment
Woovie Posted April 10, 2014 Share Posted April 10, 2014 would that be integrated in MTA 1.4 or any later Versions ?That would be very very cool, if that would be integrated anyway in mta 1.4 It depends on how fast it's finished. If it's not in 1.4, then it will be in a 1.4.x with a requirement for scripts using it. Link to comment
Castillo Posted April 10, 2014 Share Posted April 10, 2014 I have a question, does this support audio? for example: youtube videos, do they include audio? Apart from that, this is just awesome! Link to comment
beatles1 Posted April 10, 2014 Share Posted April 10, 2014 I have a question, does this support audio? for example: youtube videos, do they include audio?Apart from that, this is just awesome! From my tests you get audio played directly out of the speakers as if you were viewing the webpage normally. Might be nice to have the audio as an element so that we can play it 3D or to speakers as we wish. Link to comment
Castillo Posted April 10, 2014 Share Posted April 10, 2014 That's how I thought it worked, which is amazing. I somehow couldn't get the test build to work. Link to comment
Jusonex Posted April 10, 2014 Author Share Posted April 10, 2014 Might be nice to have the audio as an element so that we can play it 3D or to speakers as we wish. Sounds good, I'll keep it in mind, but don't figure on it next time since the audio is played by the separate, awesomium rendering process (so that I can't use the BASS library to process the sound). I somehow couldn't get the test build to work. Do you get any error? Link to comment
Arnold-1 Posted April 10, 2014 Share Posted April 10, 2014 This would be amazing, so if someone wan't to create something close to facebook or something, he would use HTML and php instead of hardly coding it in lua. Link to comment
Castillo Posted April 10, 2014 Share Posted April 10, 2014 I somehow couldn't get the test build to work. Do you get any error? "The program can't start because MSVCP120.dll is missing from your computer" I installed the x86 VC++ Redist 2013 as it says on the wiki. Link to comment
Woovie Posted April 10, 2014 Share Posted April 10, 2014 I somehow couldn't get the test build to work. Do you get any error? "The program can't start because MSVCP120.dll is missing from your computer" I installed the x86 VC++ Redist 2013 as it says on the wiki. Try a reboot? MSVCP120.dll is most definitely VC++ 2013. Link to comment
Castillo Posted April 10, 2014 Share Posted April 10, 2014 Seems like I had installed the wrong one, now it's working. Link to comment
lopezloo Posted April 10, 2014 Share Posted April 10, 2014 Would be nice to get current URL of specificed browser. For example I create browser with youtube and player could select video and send it to other players. Link to comment
Sergey_Walter Posted April 11, 2014 Share Posted April 11, 2014 Other players also need to install awesomium they worked browser? Link to comment
Woovie Posted April 11, 2014 Share Posted April 11, 2014 Would be nice to get current URL of specificed browser. For example I create browser with youtube and player could select video and send it to other players. That's already planned. Other players also need to install awesomium they worked browser? Of course... Link to comment
Mr.AL#PLaYeR Posted April 11, 2014 Share Posted April 11, 2014 This is a Future ! the script gonna be Nice ..! Link to comment
darkdreamingdan Posted April 11, 2014 Share Posted April 11, 2014 Great job jusonex, this is something I've been wanting to see for years. I think option 1 is fine, with an additional global blacklist from option 3 (and no defaults). I have two questions: 1) How is library filesize looking with Awesomium? What overhead does it add to the overall MTA installer? 2) Can we feel secure over browser exploits that could threaten our clients (regardless of permissions and blacklists)? Link to comment
Jusonex Posted April 11, 2014 Author Share Posted April 11, 2014 How is library filesize looking with Awesomium? Uncompressed 34MB, LZMA-compressed 9,88MB (LZMA is used by the MTA installer, isn't it?) 2) Can we feel secure over browser exploits that could threaten our clients (regardless of permissions and blacklists)? I think so. On the one hand Awesomium is based on Chromium which is currently the securest browser and on the other hand the user has to confirm every website. Those who still don't trust are able to to disable browser plugins, javascript and the entire browser stuff. Missing browser plugin updates are also not an issue since Awesomium uses the globally installed browser plugins. with an additional global blacklist from option 3 (and no defaults) A blacklist that is managed by the MTA team or a blacklist per player? Link to comment
Karuzo Posted April 12, 2014 Share Posted April 12, 2014 Is it normal that if i open MTA again after minimizing it , that the video has stopped ? Link to comment
Noki Posted April 13, 2014 Share Posted April 13, 2014 Yes, KRZO. It happens to me as well. Although, it isn't a serious issue. Link to comment
darkdreamingdan Posted April 13, 2014 Share Posted April 13, 2014 A blacklist that is managed by the MTA team or a blacklist per player? I was going to say per-player would be sufficient. Though a remote killswitch might be useful. One other important question - can the libraries easily be updated? We probably need to be prepared to update as rapidly as Chromium can update, so fast dll switches perhaps? Or can we link the libraries to our source code (I guess it's closed source so can't add a source dependency)? I know it's already implemented, but in that respect it might be worth looking at CEF https://code.google.com/p/chromiumembedded/ Link to comment
Jusonex Posted April 13, 2014 Author Share Posted April 13, 2014 can the libraries easily be updated? We probably need to be prepared to update as rapidly as Chromium can update, so fast dll switches perhaps? Or can we link the libraries to our source code (I guess it's closed source so can't add a source dependency)? We can replace the DLLs as long as the interfaces don't change. Awesomium is closed source unless you pay >2900$. know it's already implemented, but in that respect it might be worth looking at CEF https://code.google.com/p/chromiumembedded/ I already took a look into it some days ago. The API looks very similar to Awesomium even though it's less object-oriented than Awesomium. And the big advantage is - of course - it's open source. CEF is definitely worth a look. Btw: I uploaded my current workspace on GitHub: https://github.com/Jusonex/mtasa-awesomium Link to comment
Recommended Posts