Awesomium - Chromium based Framework

Share your advanced PureBasic knowledge/code with the community.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Awesomium - Chromium based Framework

Post by PMV »

I'm using this include in my own project. Because i don't need
much more functionality as it has, i don't plan to make much
more updates. I think the next one will be with Awesomium 1.7
It will contain the newest Chromium-Version. But if there is a big
bug in my include, i can make an update in between. So if you
find something, just ask or post your fix.

I use it as a standalone Window for a game(menu) and are now
trying to get it working as a in-game-menu, too. But as it is
not threadsafe ... i'm in trouble and now testing what is the best
way to not break everything. :lol:

MFG PMV
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: Awesomium - Chromium based Framework

Post by Perkin »

I'm trying to use a AwesomiumGadget inside a window, but the display is skewed and unusable.
Any solutions?

If I uncomment the debug lines in Awesomium.pbi->AwesomiumGadget the Debugs for DrawingBufferPixelFormat() and the constant #PB_PixelFormat_ReversedY don't match - should they?

Save and run this in same folder as your examples (where Awesomium.pbi is)

Code: Select all

IncludeFile "Awesomium.pbi"

; change this if you want to point to self downloaded installation of Awesomium
;Define Awesomium_Path.s = "<Awesomium SDK>\<Version>\build\bin\release\Awesomium.dll"
Define Awesomium_Path.s = GetPathPart(ProgramFilename()) + "Data\Awesomium\Awesomium.dll"

SetCurrentDirectory(GetPathPart(ProgramFilename()))
InitAwesomium(Awesomium_Path, "Awesomium - Test", #True, GetCurrentDirectory() + "Data")

Define Awesomium.i, Gadget.i, Event.i

OpenWindow(0,0,0,870,820,"VIEWER",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
Awesomium = AwesomiumGadget(10, 10, 850, 800, "")
Awesomium_LoadFile(Awesomium, "Main.html")

Repeat
  Awesomium_Update()

  Event =  WaitWindowEvent(10)
  Select Event
    Case #PB_Event_CloseWindow
      QUIT = #True
  EndSelect
Until QUIT
Awesomium_Shutdown()
End
%101010 = $2A = 42
User avatar
ultralazor
Enthusiast
Enthusiast
Posts: 186
Joined: Sun Jun 27, 2010 9:00 am

Re: Awesomium - Chromium based Framework

Post by ultralazor »

Awesonium has functions for getting javascript variable values, cookie data, abstract cache handling, and getting DOM data based on ids. These are all in high-level public class calls in the C API too. It's pretty bulky though, and doesn't execute flash.
so many ideas so little time..
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Awesomium - Chromium based Framework

Post by PMV »

@Perkin
Thanks, i waited for width/ height that have this strange
result ... and now i have found out why this happens.
In some special cases DrawingPufferPitch() has more Bytes
then it should, so it needs to use DrawingBufferPitch()
instead of calculating the width manually. Just replace
the function with this working code:

Code: Select all

; #PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY
Procedure Awe_RedrawAwesomium_BGR24Y(*Awesomium.Awesomium, DrawAll.i = #False)
  Protected Width.i, Height.i
  Protected *Buffer, *RenderBuffer, *srcPixel.BGRA, *destPixel.BGR
  Protected X.i, Y.i
  Protected rect.awe_rect 
  Protected DrawingBufferPitch.i, *DrawingBuffer

  
  If Not DrawAll
    awe_webview_get_dirty_bounds(*Awesomium\WebView, @rect)
  EndIf  
  *RenderBuffer = awe_webview_render(*Awesomium\WebView)
  *Buffer = awe_renderbuffer_get_buffer(*RenderBuffer)
  Width = awe_renderbuffer_get_width(*RenderBuffer)
  Height = awe_renderbuffer_get_height(*RenderBuffer)  
  If DrawAll
    rect\width = Width
    rect\height = Height
  EndIf
  
  StartDrawing(CanvasOutput(*Awesomium\Gadget))
    rect\height + rect\y - 1
    DrawingBufferPitch = DrawingBufferPitch()
    *DrawingBuffer = DrawingBuffer()
    For y = rect\y To rect\height
      *srcPixel = *Buffer + (y * Width + rect\x) * SizeOf(BGRA)
      *destPixel = *DrawingBuffer + (Height - y - 1) * DrawingBufferPitch + rect\x * SizeOf(BGR)
      For x = 1 To rect\width
        CopyMemory(*srcPixel, *destPixel, SizeOf(BGR))
        *srcPixel + SizeOf(BGRA)
        *destPixel + SizeOf(BGR)
      Next
    Next
  StopDrawing()
EndProcedure
I don't know when i can update the code in first post to get
this fix into the source. Could take some days.


ultralazor wrote:..., and doesn't execute flash.
It can execute flash, but i does not have tried it. :)

MFG PMV
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: Awesomium - Chromium based Framework

Post by Perkin »

Thanks PMV, just one more thing ;)

I'm missing something obvious, I know I am...

Using my last small example, how do I enable scrolling/links etc?
The Gadget displays the html, but I can't scroll or use a link on it.

I've looked at your examples and have tried but I can never get the 'Gadget' to be able to scroll (as in your examples).

EDIT:
If I change the main event loop to the following, scrolling now works, but if I hover over a link, the cursor changes back to a normal one too quickly and I can't press the link.
Any ideas as how to rectify that?

(lifted/adapted from AWE_Browser example)

Code: Select all

Repeat
	Awesomium_Update()
	
	Event =  WaitWindowEvent(10)
	Select Event
		Case #PB_Event_CloseWindow
			QUIT = #True
		Default
			*AwesomiumGE = Awesomium_GetAwesomium(EventGadget(), #Awe_Type_Gadget) 
			If *AwesomiumGE
				Awesomium_GadgetEvent(*AwesomiumGE, EventType())
			EndIf
	EndSelect
Until QUIT
Awesomium_Shutdown()
End
EDIT2:
Typical, realised moments after I posted above what I'd (not) done (wasn't checking the PB_Event_Gadget in loop)

Changed to this and now works perfectly.

Code: Select all

Repeat
	Awesomium_Update()
	
	Event =  WaitWindowEvent(10)
	Select Event
		Case #PB_Event_CloseWindow
			QUIT = #True
		Case #PB_Event_Gadget
			Select EventGadget()
				Case Dummy
				Default
					*AwesomiumGE = Awesomium_GetAwesomium(EventGadget(), #Awe_Type_Gadget) 
					If *AwesomiumGE
						Awesomium_GadgetEvent(*AwesomiumGE, EventType())
					EndIf
			EndSelect
	EndSelect
Until QUIT
Awesomium_Shutdown()
End
(Dummy is a hidden button gadget, just to aid the Select/Case test, will be 'proper' gadgets in actual program.)
%101010 = $2A = 42
User avatar
ultralazor
Enthusiast
Enthusiast
Posts: 186
Joined: Sun Jun 27, 2010 9:00 am

Re: Awesomium - Chromium based Framework

Post by ultralazor »

PMV wrote:
ultralazor wrote:..., and doesn't execute flash.
It can execute flash, but i does not have tried it. :)
how so? it has the plugin framework embedded?

Also, does licensing prevent you from distributing this as a wrapper dll and pbi? It looks like they charge money.
so many ideas so little time..
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Awesomium - Chromium based Framework

Post by PMV »

ultralazor wrote:
PMV wrote:It can execute flash, but i does not have tried it. :)
how so? it has the plugin framework embedded?
answer from me:
PMV wrote:Flash needs to be activated separate through the plugin-system of this, but i
doesn't have looked what is needed for that. Could be just to be one value
set to "true" :lol: ... it needs to be set at initialization in awe_webcore_initialize(),...
I call this function in InitAwesomium(), you will find this parameter very fast.

ultralazor wrote:Also, does licensing prevent you from distributing this as a wrapper dll and pbi? It looks like they charge money.
just read yourself:
http://support.awesomium.com/kb/licensi ... g-overview
PMV wrote:And as i remember (no guarantee) the license says,
statical linking is forbidden. But as i have written: SDK
available for all 3 platforms. Full cross-platform support. :wink:
No problem with dynamical linking, just try it. :)
User avatar
ultralazor
Enthusiast
Enthusiast
Posts: 186
Joined: Sun Jun 27, 2010 9:00 am

Re: Awesomium - Chromium based Framework

Post by ultralazor »

You probably can't pack the dll with the main binary.

It looks like the cleanest you can make it is ~3 dlls and 1 pbi. I would help with documentation but have to work on a contract currently. I looked through the pbi, it'll probably need clean up.
so many ideas so little time..
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Awesomium - Chromium based Framework

Post by PMV »

I don't think you can cut out something from Awesomium itself.
I have the feeling that it could be disallowed, too :lol:
I count 6 dll, an exe ... all needed and a file without extension,
probably needed.

But feel free to document what ever you want, write examples
or extend the include ... i have no time to do much more on that.
Now i'm working with it and when i have time, i will update the
include with a few bugfixes.


Still lots of work. :D
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: Awesomium - Chromium based Framework

Post by Perkin »

Found a new problem :mrgreen:
When using WinXP, Error crops up on line 1523 of the pbi, when using any of examples or own code
When altering process to have parent's name rather than AweProcess.
(Does work on Win7)

That is also where Linux bombs out when trying examples.

Could you fix that? (or have it so it doesn't need to re-assign the process name?)
(If I comment out those lines - OH NO!)
%101010 = $2A = 42
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Awesomium - Chromium based Framework

Post by PMV »

Perkin wrote:Found a new problem :mrgreen:
When using WinXP, Error crops up on line 1523 of the pbi, when using any of examples or own code
When altering process to have parent's name rather than AweProcess.
(Does work on Win7)

That is also where Linux bombs out when trying examples.

Could you fix that? (or have it so it doesn't need to re-assign the process name?)
(If I comment out those lines - OH NO!)
Oh yes ... there is a problem. I have just found this thread:
http://support.awesomium.com/discussion ... ss-enabled
And the answer seems to be ... as you expect, to not use this
feature for Windows XP. I will investigate this problem, but it
will took some time as it needs testing.

Short-fix is just to use this line instead of the "self" in
the InitAwesomium() function:

Code: Select all

*child_process_path = awe_string_empty()
and a litte bit under it remove the line

Code: Select all

awe_string_destroy(*child_process_path)
If needed 2. solution: you could rename the awesomium-process
and set the child-process-path to that named exe :) (not tested)

Edit: same fix should be possible for linux

MFG PMV
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: Awesomium - Chromium based Framework

Post by Perkin »

PMV wrote:Short-fix is just to use this line instead of the "self" in
the InitAwesomium() function:

Code: Select all

*child_process_path = awe_string_empty()
and a litte bit under it remove the line

Code: Select all

awe_string_destroy(*child_process_path)
Edit: same fix should be possible for linux

MFG PMV
Tried the fix, commented out lines 1520-1528, the rename child processes lines, altered the lines as above (just commented out 2nd altered line).

Worked great on WinXP, I'll try on linux later.

Thanks PMV
%101010 = $2A = 42
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Awesomium - Chromium based Framework

Post by PMV »

To bad, there is no function to know if running OS can handle this
feature or not, so it is up to the programmer to test this. :x
I will add a OSVersion() check for windows, that will disable this
feature for older versions then Vista.

But for linux ... of course this feature can't work because there are
missing lines! I have added an CompilerError, do you have missed it? :?
Please improve it by adding the missing lines and tell them to me :D
Otherwise i will deactivate this feature, too and replace the CompilerError
with Debug-Output. :lol:

MFG PMV
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: Awesomium - Chromium based Framework

Post by Perkin »

There's also loads that needs altering/adapting for use on linux... (and possibly Mac?)

Constants missing/undefined. (Windows only?)
In Awe_CursorChangeCallback -> Window type, Loads of WinAPI calls (SetClassLong_ + LoadCursor_)
In AweTooltipCallback, SendMessage_ calls
(that's as far as I looked)

Seeing as the Webgadget in Linux works better than Win version (more features), I'll use that for now.

When I can, I'll see if this can be adapted, so it'll be cross-platform.
I've barely started using linux, so updating the include for linux stuff is likely to be slow.

Thanks PMV
%101010 = $2A = 42
User avatar
ultralazor
Enthusiast
Enthusiast
Posts: 186
Joined: Sun Jun 27, 2010 9:00 am

Re: Awesomium - Chromium based Framework

Post by ultralazor »

Perkin wrote:There's also loads that needs altering/adapting for use on linux... (and possibly Mac?)

Constants missing/undefined. (Windows only?)
In Awe_CursorChangeCallback -> Window type, Loads of WinAPI calls (SetClassLong_ + LoadCursor_)
In AweTooltipCallback, SendMessage_ calls
(that's as far as I looked)

Seeing as the Webgadget in Linux works better than Win version (more features), I'll use that for now.

When I can, I'll see if this can be adapted, so it'll be cross-platform.
I've barely started using linux, so updating the include for linux stuff is likely to be slow.

Thanks PMV

The builds are generic and documented across supported platforms. The PBI just needs adjusted for import and struct handling..

The licensing and bulkiness of this will drive most capable devs away..
so many ideas so little time..
Post Reply