Platforms to show: All Mac Windows Linux Cross-Platform
/Win/HTMLViewer Windows/WebKit - Chromium/Windows WebKit Cookies
Required plugins for this example: MBS Win Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/HTMLViewer Windows/WebKit - Chromium/Windows WebKit Cookies
This example is the version from Sun, 15th Feb 2020.
Project "Windows WebKit Cookies.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
End EventHandler
EventHandler Function UnhandledException(error As RuntimeException) As Boolean
MsgBox Introspection.GetType(error).fullname+EndOfLine+error.Message+_
EndOfLine+EndOfLine+Join(error.Stack, EndOfLine)
Return true
End EventHandler
End Class
Class MainWindow Inherits Window
Control HTMLViewer1 Inherits HTMLViewer
ControlInstance HTMLViewer1 Inherits HTMLViewer
End Control
Control URL Inherits TextField
ControlInstance URL Inherits TextField
EventHandler Function KeyDown(Key As String) As Boolean
if asc(key) = 3 or asc(key) = 13 then
HTMLViewer1.LoadURL me.Text
Return true
end if
End EventHandler
End Control
Control CookieButton Inherits PushButton
ControlInstance CookieButton Inherits PushButton
EventHandler Sub Action()
CookieWindow.show
End EventHandler
End Control
Control OpenButton Inherits PushButton
ControlInstance OpenButton Inherits PushButton
EventHandler Sub Action()
HTMLViewer1.LoadURL URL.Text
End EventHandler
End Control
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class CookieWindow Inherits Window
Control UpdateButton Inherits PushButton
ControlInstance UpdateButton Inherits PushButton
EventHandler Sub Action()
update
End EventHandler
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub Change()
DeleteButton.Enabled = me.ListIndex >= 0
End EventHandler
End Control
Control DeleteButton Inherits PushButton
ControlInstance DeleteButton Inherits PushButton
EventHandler Sub Action()
if List.ListIndex >= 0 then
dim c as ChromiumCookieMBS = List.RowTag(List.ListIndex)
dim URL as string = c.URL
if CookieManager.DeleteCookie(url, c.Name) then
List.RemoveRow List.ListIndex
else
MsgBox "Failed to delete cookie"
end if
end if
End EventHandler
End Control
Control UpdateDomainButton Inherits PushButton
ControlInstance UpdateDomainButton Inherits PushButton
EventHandler Sub Action()
update "http://www.mbsplugins.de/"
End EventHandler
End Control
Control AddButton Inherits PushButton
ControlInstance AddButton Inherits PushButton
EventHandler Sub Action()
dim d as new date
dim c as new ChromiumCookieMBS
c.Domain = "www.mbsplugins.de"
c.Path = "/"
c.CreationDate = d
c.LastAccessDate = d
c.ExpirationDate = nil
c.Value = "test "+d.SQLDateTime
c.Name = "test"
c.Secure = false
c.HTTPonly = false
if CookieManager.SetCookie(c.URL, c) then
update
else
MsgBox "Failed to add cookie"
end if
End EventHandler
End Control
Control DeleteButton1 Inherits PushButton
ControlInstance DeleteButton1 Inherits PushButton
EventHandler Sub Action()
dim URLs() as string
dim Names() as string
for i as integer = 1 to 5
names.Append "test"+str(i)
urls.Append "http://www.mbsplugins.de/"
next
dim n as integer = CookieManager.DeleteCookies(urls, Names)
if n > 0 then
MsgBox "Deleted "+str(n)+" of 5 cookies"
update
else
MsgBox "Failed to delete cookies"
end if
End EventHandler
End Control
Control AddButton1 Inherits PushButton
ControlInstance AddButton1 Inherits PushButton
EventHandler Sub Action()
dim cookies() as ChromiumCookieMBS
dim URLs() as string
for i as integer = 1 to 5
dim d as new date
dim c as new ChromiumCookieMBS
c.Domain = "www.mbsplugins.de"
c.Path = "/"
c.CreationDate = d
c.LastAccessDate = d
c.ExpirationDate = nil
c.Value = "test "+d.SQLDateTime
c.Name = "test"+str(i)
c.Secure = false
c.HTTPonly = false
URLs.Append c.URL
cookies.Append c
next
dim n as integer = CookieManager.SetCookies(URLs, cookies)
if n > 0 then
MsgBox "Created "+str(n)+" of 5 cookies"
update
else
MsgBox "Failed to add cookie"
end if
End EventHandler
End Control
Control DeleteButton2 Inherits PushButton
ControlInstance DeleteButton2 Inherits PushButton
EventHandler Sub Action()
dim n as integer = CookieManager.DeleteURLCookies("http://www.mbsplugins.de/", false)
if n > 0 then
MsgBox "Deleted "+str(n)+" cookies"
update
else
MsgBox "Failed to delete cookies"
end if
End EventHandler
End Control
EventHandler Sub Open()
CookieManager = new ChromiumCookieManagerMBS
update
End EventHandler
Sub update(URL as string = "")
List.DeleteAllRows
dim cookies() as ChromiumCookieMBS
if url = "" then
cookies = CookieManager.AllCookies
else
cookies = CookieManager.URLCookies(url, true)
end if
for each c as ChromiumCookieMBS in cookies
dim cd as string
dim ed as string
dim ad as string
if c.CreationDate <> nil then
cd = c.CreationDate.SQLDateTime
end if
if c.LastAccessDate <> nil then
ad = c.LastAccessDate.SQLDateTime
end if
if c.ExpirationDate <> nil then
ed = c.ExpirationDate.SQLDateTime
end if
dim h,s as string
if c.Secure then
s = "secure"
else
s = ""
end if
if c.HTTPonly then
h = "HTTP only"
else
h = ""
end if
list.AddRow c.Domain, c.Path, c.Name, c.Value, s, h, cd, ad, ed
list.RowTag(List.LastIndex) = c
next
End Sub
Property CookieManager As ChromiumCookieManagerMBS
End Class
Module Module1
Function URL(extends c as ChromiumCookieMBS) As string
if c.Secure then
return "https://"+c.Domain+c.Path
else
return "http://"+c.Domain+c.Path
end if
End Function
End Module
End Project
See also:
- /Win/HTMLViewer Windows/DebugBar
- /Win/HTMLViewer Windows/Eval Javascript Win
- /Win/HTMLViewer Windows/HTML Editor
- /Win/HTMLViewer Windows/HTML Editor Win
- /Win/HTMLViewer Windows/HTMLViewer execCommand
- /Win/HTMLViewer Windows/HTMLViewer HTML Text and Image
- /Win/HTMLViewer Windows/Load HTML Test
- /Win/HTMLViewer Windows/More HTMLViewer Printing
- /Win/HTMLViewer Windows/Reload htmlviewer
- /Win/HTMLViewer Windows/Zoom HMTLViewer
The items on this page are in the following plugins: MBS Win Plugin.