Jump to content

CEF: How to deal with it?


Jusonex

Recommended Posts

I made a web browser :) so far it loads a page, back/forward work with history. Source below.

(View in full screen)

M0tatRj.png

Still WIP of course :P

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

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 by Guest
Link to comment
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
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
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
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
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

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
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
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
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
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...