types-cookie-manager.go 3.3 KB
Newer Older
yanghye's avatar
yanghye 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------

package cef

import (
yanghye's avatar
yanghye 已提交
14 15 16
	"github.com/energye/energy/v2/common"
	"github.com/energye/energy/v2/common/imports"
	"github.com/energye/energy/v2/consts"
yanghye's avatar
yanghye 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
	"github.com/energye/golcl/lcl/api"
	"time"
	"unsafe"
)

// Instance 实例
func (m *ICefCookieManager) Instance() uintptr {
	if m == nil {
		return 0
	}
	return uintptr(m.instance)
}

func (m *ICefCookieManager) Free() {
	if m.instance != nil {
		m.base.Free(m.Instance())
		m.instance = nil
	}
}

func (m *ICefCookieManager) IsValid() bool {
	if m == nil || m.instance == nil {
		return false
	}
	return m.instance != nil
}

func (m *ICefCookieManager) VisitAllCookies(visitor *ICefCookieVisitor) {
	if !m.IsValid() {
		return
	}
	imports.Proc(internale_CefCookieManager_VisitAllCookies).Call(m.Instance(), visitor.Instance())
}

func (m *ICefCookieManager) VisitUrlCookies(url string, includeHttpOnly bool, visitor *ICefCookieVisitor) bool {
	if !m.IsValid() {
		return false
	}
	r1, _, _ := imports.Proc(internale_CefCookieManager_VisitUrlCookies).Call(m.Instance(), api.PascalStr(url), api.PascalBool(includeHttpOnly), visitor.Instance())
	return api.GoBool(r1)
}

func (m *ICefCookieManager) SetCookie(url, name, value, domain, path string,
	secure, httponly, hasExpires bool, creation, lastAccess, expires time.Time,
	sameSite consts.TCefCookieSameSite, priority consts.TCefCookiePriority, callback *ICefSetCookieCallback) bool {
	if !m.IsValid() {
		return false
	}
	creationPtr := common.GoDateTimeToDDateTime(creation)
	lastAccessPtr := common.GoDateTimeToDDateTime(lastAccess)
	expiresPtr := common.GoDateTimeToDDateTime(expires)
	cCookie := &iCefCookiePtr{
		url:             api.PascalStr(url),
		name:            api.PascalStr(name),
		value:           api.PascalStr(value),
		domain:          api.PascalStr(domain),
		path:            api.PascalStr(path),
		secure:          api.PascalBool(secure),
		httponly:        api.PascalBool(httponly),
		hasExpires:      api.PascalBool(hasExpires),
		creation:        uintptr(unsafe.Pointer(&creationPtr)),
		lastAccess:      uintptr(unsafe.Pointer(&lastAccessPtr)),
		expires:         uintptr(unsafe.Pointer(&expiresPtr)),
		sameSite:        uintptr(sameSite),
		priority:        uintptr(priority),
		aSetImmediately: uintptr(0),
		aID:             uintptr(0),
		aDeleteCookie:   uintptr(0),
		aResult:         uintptr(0),
		count:           uintptr(0),
		total:           uintptr(0),
	}
	r1, _, _ := imports.Proc(internale_CefCookieManager_SetCookie).Call(m.Instance(), uintptr(unsafe.Pointer(cCookie)), callback.Instance())
	return api.GoBool(r1)
}

func (m *ICefCookieManager) DeleteCookies(url, cookieName string, callback *ICefDeleteCookiesCallback) bool {
	if !m.IsValid() {
		return false
	}
	r1, _, _ := imports.Proc(internale_CefCookieManager_DeleteCookies).Call(m.Instance(), api.PascalStr(url), api.PascalStr(cookieName), callback.Instance())
	return api.GoBool(r1)
}

func (m *ICefCookieManager) FlushStore(callback *ICefCompletionCallback) bool {
	if !m.IsValid() {
		return false
	}
	r1, _, _ := imports.Proc(internale_CefCookieManager_FlushStore).Call(m.Instance(), callback.Instance())
	return api.GoBool(r1)
}