Firefox, mozilla based browser URL

Just starting out? Need help? Post your questions and find answers here.
jogwang2
New User
New User
Posts: 1
Joined: Sat May 10, 2008 4:16 am
Location: Philippines

Post by jogwang2 »

is there any c# to this code. it would really be helpful.
BigJack
User
User
Posts: 76
Joined: Tue May 16, 2006 6:46 am
Location: Germany
Contact:

Post by BigJack »

Pretty good piece of code - thanks for sharing it.

Is there a way to do it without opening a window? :?:
Greetings Mike
Greetings to all the folks back home in the States...
PB4.2 Windows XP SP3
Little John
Addict
Addict
Posts: 4773
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

On SourceForge there is a project called URLInject. Unfortunately it is abandoned, but the source code (Pascal) might be interesting for you guys anyway.

Regards, Little John
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

@Sparkie: Your excellent code no longer works with the new Firefox 3. :(
Any chance you can revisit it soon and make it both 2 and 3 compatible? ;)
Or even just for Firefox 3 would be great. Thanks, and I hope you can do it.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

BigJack and PB, I'll take a look when I get home tonight. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

As for the Firefox 3 issue, I'm not sure what's going wrong. get_accName (which is the Title of the page) is working fine but get_accValue (the url of the page) is stumbling for some reason. I will continue to look for a fix.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Just to confirm: you're using the normal Firefox 3, and not Firefox Portable or
any other non-official derivative of it?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

That is correct PB
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

See if this works for you and Firefox 3...

Code: Select all

; Code          : Read Browser URL (IE, Firefox) 
; Author(s)     : Sparkie, netmaestro 
; Other credits : PB, rsts 
; Rel Date      : December 21, 2006 7:41 PM 
; Update        : July 26, 2008 10:49 AM
;                 -fix for Firefox 3
; Target OS     : Windows only 
; Target PB     : 4.x 
;...Code converted from VB to PB 
;...Feel free to clean it up and use as you wish. 
; ************************************************ 

;################
; Constants 
;################
#CHILDID_SELF = 0 
#WINEVENT_OUTOFCONTEXT = 0 
#WINEVENT_SKIPOWNPROCESS = $2 
#EVENT_OBJECT_FOCUS = $8005 
#EVENT_OBJECT_VALUECHANGE = $800E
#ROLE_SYSTEM_DOCUMENT = $F
#ROLE_SYSTEM_PANE = $10
#ROLE_SYSTEM_TEXT = $2A

;################
; Convert to BSTR
;################
; Thanks to freak for this one
Procedure.l ASCIItoBSTR(asciiString$)
  Protected result = 0
  CompilerIf #PB_Compiler_Unicode
  result = SysAllocString_(@asciiString$)
  CompilerElse
  Protected *buff = AllocateMemory(Len(asciiString$)*2 + 2)
  If *buff
    PokeS(*buff, asciiString$, -1, #PB_Unicode)
    result = SysAllocString_(*buff)
    FreeMemory(*buff)
  EndIf
  CompilerEndIf
  ProcedureReturn result
EndProcedure 

;################
; Set Hook
;################
Procedure WinEventFunc(HookHandle.l, hEvent.l, hwnd.l, idObject.l, idChild.l, idEventThread.l, dwmsEventTime.l) 
  Protected *objectIa.IAccessible 
  Static previousUrl$ 
  Select hEvent 
    Case #EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE
      className$ = Space(256) 
      GetClassName_(hwnd, @className$, 256) 
      If className$ = "MozillaWindowClass" Or className$ = "Internet Explorer_Server" 
        If CallFunction(0, "AccessibleObjectFromEvent", hwnd, idObject, idChild, @*objectIa, @v.VARIANT) = #S_OK 
          v.VARIANT\vt = #VT_I4 
          v\lVal = #CHILDID_SELF 
          If *objectIa\get_accRole(v, @v) = #S_OK 
            If v\lVal = #ROLE_SYSTEM_PANE Or v\lVal = #ROLE_SYSTEM_DOCUMENT Or v\lVal = #ROLE_SYSTEM_TEXT
              v\vt = #VT_I4 
              v\lVal = #CHILDID_SELF 
              url$ = Space(#MAX_PATH) 
              bstr = ASCIItoBSTR(Space(#MAX_PATH))
              If *objectIa\get_accValue(v, @bstr) = #S_OK 
                len = WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, 0, 0, 0, 0) 
                url$ = Space(len) 
                WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, @url$, len, 0, 0)    
                If previousUrl$ <> url$ And url$ <> ""
                  AddGadgetItem(1, -1, url$) 
                  previousUrl$ = url$ 
                EndIf 
              EndIf 
            EndIf 
            *objectIa\Release() 
          EndIf 
        EndIf 
      EndIf 
  EndSelect 
EndProcedure 

;################
; Main Window 
;################
If OpenWindow(0, 0, 0, 500, 400, "Read Browser URL", #PB_Window_SystemMenu) And CreateGadgetList(WindowID(0)) 
  CoInitialize_(0);
  hdll = OpenLibrary(0, "Oleacc.dll") 
  EditorGadget(1, 10, 15, 480, 380) 
  ;...Set event hook 
  eHook = SetWinEventHook_(#EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE, #Null, @WinEventFunc(), 0, 0, #WINEVENT_OUTOFCONTEXT | #WINEVENT_SKIPOWNPROCESS) 
  Repeat 
    event = WaitWindowEvent() 
  Until event = #PB_Event_CloseWindow 
  ;...Cleanup
  CoUninitialize_()
  If eHook 
    UnhookWinEvent_(eHook) 
  EndIf 
  If hdll 
    CloseLibrary(0) 
  EndIf 
EndIf 
End
Last edited by Sparkie on Sat Aug 02, 2008 12:33 pm, edited 1 time in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> See if this works for you and Firefox 3

Hi Sparkie, it seems to work great so far, so thanks for that! :)

One caveat: if Firefox is running BEFORE you run your code, then it doesn't get
the current URL. In the big scheme of things that won't matter to me because
my app is launched at bootup before Firefox, but if you can make it get the
URL of an already-running Firefox, then it would be 100% perfect. :)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Your request should be no problem PB. I'll get on it later today. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post by Pantcho!! »

Sparkie, damn you are good! :lol:
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

@Sparkie: I was looking closer at your code and saw this:

*value = AllocateMemory(#MAX_PATH *2 + 2)

It doesn't seem to be needed? (The code works fine without it).
And there's no FreeMemory command for it? Is it a leftover? :)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Yes PB, it's a remnant from earlier code. I edited and removed that line. Thanks for spotting that one.

I am still working on getting the URL on startup. It turned out not to be as easy as I had hoped. :evil:

@Pantcho!!: Thanks for the kind words. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
besko
User
User
Posts: 42
Joined: Tue Oct 28, 2008 1:08 pm

Post by besko »

Sparkie
Do you have code for Opera and Google Chrome?




And how can i Hook Url?
and do something when i Hook www.google.com?



tnx for help :)
Post Reply