diff --git a/cef/cef-aux-view-source-window.go b/cef/cef-aux-view-source-window.go index 2a857196..046f3e65 100644 --- a/cef/cef-aux-view-source-window.go +++ b/cef/cef-aux-view-source-window.go @@ -48,7 +48,6 @@ func createBrowserViewSource(browser *ICefBrowser, frame *ICefFrame) { m.SetShowInTaskBar() m.SetWindowType(WT_VIEW_SOURCE) m.ChromiumCreate(nil, viewSourceUrl) - m.chromium.EnableIndependentEvent() m.putChromiumWindowInfo() m.defaultChromiumEvent() m.SetWidth(1024) diff --git a/cef/cef-browser-window.go b/cef/cef-browser-window.go index 7584221e..d850141d 100644 --- a/cef/cef-browser-window.go +++ b/cef/cef-browser-window.go @@ -36,7 +36,7 @@ var ( browserProcessStartAfterCallback browserProcessStartAfterCallbackFunc ) -type browserProcessStartAfterCallbackFunc func(b bool) +type browserProcessStartAfterCallbackFunc func(success bool) // SetBrowserProcessStartAfterCallback 主进程启动之后回调函数 func SetBrowserProcessStartAfterCallback(callback browserProcessStartAfterCallbackFunc) { diff --git a/cef/cef-chromium-events.go b/cef/cef-chromium-events.go index 2da0a772..c38c113f 100644 --- a/cef/cef-chromium-events.go +++ b/cef/cef-chromium-events.go @@ -12,7 +12,6 @@ import ( . "github.com/energye/energy/common" "github.com/energye/golcl/lcl" "github.com/energye/golcl/lcl/api" - "reflect" ) //chromium 事件行为 @@ -65,181 +64,181 @@ type IChromiumEvent interface { // Event func (m *TCEFChromium) SetOnAfterCreated(fn ChromiumEventOnAfterCreated) { - _CEFChromium_SetOnAfterCreated(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnAfterCreated(m.Instance(), fn) } func (m *TCEFChromium) SetOnBeforeBrowser(fn ChromiumEventOnBeforeBrowser) { - _CEFChromium_SetOnBeforeBrowser(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnBeforeBrowser(m.Instance(), fn) } func (m *TCEFChromium) SetOnAddressChange(fn ChromiumEventOnAddressChange) { - _CEFChromium_SetOnAddressChange(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnAddressChange(m.Instance(), fn) } func (m *TCEFChromium) SetOnBeforeClose(fn ChromiumEventOnBeforeClose) { - _CEFChromium_SetOnBeforeClose(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnBeforeClose(m.Instance(), fn) } func (m *TCEFChromium) SetOnClose(fn ChromiumEventOnClose) { - _CEFChromium_SetOnClose(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnClose(m.Instance(), fn) } // pdf func (m *TCEFChromium) SetOnPdfPrintFinished(fn ChromiumEventOnResult) { - _CEFChromium_SetOnPdfPrintFinished(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnPdfPrintFinished(m.Instance(), fn) } // chromiumEvent zoom func (m *TCEFChromium) SetOnZoomPctAvailable(fn ChromiumEventOnResultFloat) { - _CEFChromium_SetOnZoomPctAvailable(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnZoomPctAvailable(m.Instance(), fn) } // load loading func (m *TCEFChromium) SetOnLoadStart(fn ChromiumEventOnLoadStart) { - _CEFChromium_SetOnLoadStart(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnLoadStart(m.Instance(), fn) } func (m *TCEFChromium) SetOnLoadingStateChange(fn ChromiumEventOnLoadingStateChange) { - _CEFChromium_SetOnLoadingStateChange(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnLoadingStateChange(m.Instance(), fn) } func (m *TCEFChromium) SetOnLoadingProgressChange(fn ChromiumEventOnLoadingProgressChange) { - _CEFChromium_SetOnLoadingProgressChange(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnLoadingProgressChange(m.Instance(), fn) } func (m *TCEFChromium) SetOnLoadError(fn ChromiumEventOnLoadError) { - _CEFChromium_SetOnLoadError(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnLoadError(m.Instance(), fn) } func (m *TCEFChromium) SetOnLoadEnd(fn ChromiumEventOnLoadEnd) { - _CEFChromium_SetOnLoadEnd(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnLoadEnd(m.Instance(), fn) } // download func (m *TCEFChromium) SetOnBeforeDownload(fn ChromiumEventOnBeforeDownload) { - _CEFChromium_SetOnBeforeDownload(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnBeforeDownload(m.Instance(), fn) } func (m *TCEFChromium) SetOnDownloadUpdated(fn ChromiumEventOnDownloadUpdated) { - _CEFChromium_SetOnDownloadUpdated(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnDownloadUpdated(m.Instance(), fn) } func (m *TCEFChromium) SetOnFullScreenModeChange(fn ChromiumEventOnFullScreenModeChange) { - _CEFChromium_SetOnFullScreenModeChange(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnFullScreenModeChange(m.Instance(), fn) } func (m *TCEFChromium) SetOnKeyEvent(fn ChromiumEventOnKeyEvent) { - _CEFChromium_SetOnKeyEvent(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnKeyEvent(m.Instance(), fn) } func (m *TCEFChromium) SetOnTitleChange(fn ChromiumEventOnTitleChange) { - _CEFChromium_SetOnTitleChange(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnTitleChange(m.Instance(), fn) } func (m *TCEFChromium) SetOnRenderCompMsg(fn ChromiumEventOnRenderCompMsg) { - _CEFChromium_SetOnRenderCompMsg(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnRenderCompMsg(m.Instance(), fn) } func (m *TCEFChromium) SetOnRenderProcessTerminated(fn ChromiumEventOnRenderProcessTerminated) { - _CEFChromium_SetOnRenderProcessTerminated(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnRenderProcessTerminated(m.Instance(), fn) } func (m *TCEFChromium) SetOnRenderViewReady(fn ChromiumEventOnCefBrowser) { - _CEFChromium_SetOnRenderViewReady(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnRenderViewReady(m.Instance(), fn) } func (m *TCEFChromium) SetOnScrollOffsetChanged(fn ChromiumEventOnScrollOffsetChanged) { - _CEFChromium_SetOnScrollOffsetChanged(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnScrollOffsetChanged(m.Instance(), fn) } // 进程间通信消息接收 func (m *TCEFChromium) SetOnProcessMessageReceived(fn BrowseProcessMessageReceived) { - _CEFChromium_SetOnProcessMessageReceived(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnProcessMessageReceived(m.Instance(), fn) } func (m *TCEFChromium) SetOnFindResult(fn ChromiumEventOnFindResult) { - _CEFChromium_SetOnFindResult(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnFindResult(m.Instance(), fn) } func (m *TCEFChromium) SetOnBeforeResourceLoad(fn ChromiumEventOnBeforeResourceLoad) { - _CEFChromium_SetOnBeforeResourceLoad(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnBeforeResourceLoad(m.Instance(), fn) } func (m *TCEFChromium) SetOnResourceResponse(fn ChromiumEventOnResourceResponse) { - _CEFChromium_SetOnResourceResponse(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnResourceResponse(m.Instance(), fn) } func (m *TCEFChromium) SetOnResourceRedirect(fn ChromiumEventOnResourceRedirect) { - _CEFChromium_SetOnResourceRedirect(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnResourceRedirect(m.Instance(), fn) } func (m *TCEFChromium) SetOnResourceLoadComplete(fn ChromiumEventOnResourceLoadComplete) { - _CEFChromium_SetOnResourceLoadComplete(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnResourceLoadComplete(m.Instance(), fn) } // cookie begin func (m *TCEFChromium) SetOnCookieSet(fn ChromiumEventOnCookieSet) { - _CEFChromium_SetOnCookieSet(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnCookieSet(m.Instance(), fn) } func (m *TCEFChromium) SetOnCookiesDeleted(fn ChromiumEventOnCookiesDeleted) { - _CEFChromium_SetOnCookiesDeleted(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnCookiesDeleted(m.Instance(), fn) } func (m *TCEFChromium) SetOnCookiesFlushed(fn ChromiumEventOnCookiesFlushed) { - _CEFChromium_SetOnCookiesFlushed(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnCookiesFlushed(m.Instance(), fn) } func (m *TCEFChromium) SetOnCookiesVisited(fn ChromiumEventOnCookiesVisited) { - _CEFChromium_SetOnCookiesVisited(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnCookiesVisited(m.Instance(), fn) } func (m *TCEFChromium) SetOnCookieVisitorDestroyed(fn ChromiumEventOnCookieVisitorDestroyed) { - _CEFChromium_SetOnCookieVisitorDestroyed(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnCookieVisitorDestroyed(m.Instance(), fn) } func (m *TCEFChromium) SetOnBeforeContextMenu(fn ChromiumEventOnBeforeContextMenu) { - _CEFChromium_SetOnBeforeContextMenu(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnBeforeContextMenu(m.Instance(), fn) } func (m *TCEFChromium) SetOnContextMenuCommand(fn ChromiumEventOnContextMenuCommand) { if api.GoBool(m.cfg.enableMenu) { - _CEFChromium_SetOnContextMenuCommand(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnContextMenuCommand(m.Instance(), fn) } } func (m *TCEFChromium) SetOnContextMenuDismissed(fn ChromiumEventOnContextMenuDismissed) { if api.GoBool(m.cfg.enableMenu) { - _CEFChromium_SetOnContextMenuDismissed(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnContextMenuDismissed(m.Instance(), fn) } } // frame附加连接 func (m *TCEFChromium) SetOnFrameAttached(fn ChromiumEventOnFrameAttached) { - _CEFChromium_SetOnFrameAttached(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnFrameAttached(m.Instance(), fn) } // frame创建 func (m *TCEFChromium) SetOnFrameCreated(fn ChromiumEventOnFrameCreated) { - _CEFChromium_SetOnFrameCreated(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnFrameCreated(m.Instance(), fn) } // 当前frame离开 func (m *TCEFChromium) SetOnFrameDetached(fn ChromiumEventOnFrameDetached) { - _CEFChromium_SetOnFrameDetached(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnFrameDetached(m.Instance(), fn) } // 主frame被改变 func (m *TCEFChromium) SetOnMainFrameChanged(fn ChromiumEventOnMainFrameChanged) { - _CEFChromium_SetOnMainFrameChanged(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnMainFrameChanged(m.Instance(), fn) } func (m *TCEFChromium) SetOnBeforePopup(fn ChromiumEventOnBeforePopup) { - _CEFChromium_SetOnBeforePopup(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnBeforePopup(m.Instance(), fn) } func (m *TCEFChromium) SetOnOpenUrlFromTab(fn ChromiumEventOnOpenUrlFromTab) { - _CEFChromium_SetOnOpenUrlFromTab(m.Instance(), fn, m.independentEvent) + _CEFChromium_SetOnOpenUrlFromTab(m.Instance(), fn) } // --------TCEFChromium Event proc begin-------- @@ -247,225 +246,226 @@ func (m *TCEFChromium) SetOnOpenUrlFromTab(fn ChromiumEventOnOpenUrlFromTab) { // 解决事件重复 var chromiumOnEventIdMapping = map[string]uintptr{} -func chromiumOnEventNameToId(fn interface{}, independentEvent bool) uintptr { - var eventId uintptr - if independentEvent { - eventId = api.MakeEventDataPtr(fn) - } else { - var ( - name = reflect.ValueOf(fn).Type().Name() - ok bool - ) - if eventId, ok = chromiumOnEventIdMapping[name]; !ok { - eventId = api.MakeEventDataPtr(fn) - chromiumOnEventIdMapping[name] = eventId - } - } - return eventId +func chromiumOnEventNameToId(fn interface{}) uintptr { + return api.MakeEventDataPtr(fn) + //var eventId uintptr + //if independentEvent { + // eventId = api.MakeEventDataPtr(fn) + //} else { + // var ( + // name = reflect.ValueOf(fn).Type().Name() + // ok bool + // ) + // if eventId, ok = chromiumOnEventIdMapping[name]; !ok { + // eventId = api.MakeEventDataPtr(fn) + // chromiumOnEventIdMapping[name] = eventId + // } + //} + //return eventId } -func _CEFChromium_SetOnAfterCreated(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnAfterCreated).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnAfterCreated(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnAfterCreated).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnBeforeClose -func _CEFChromium_SetOnBeforeClose(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnBeforeClose).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnBeforeClose(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnBeforeClose).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnClose -func _CEFChromium_SetOnClose(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnClose).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnClose(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnClose).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnPdfPrintFinished -func _CEFChromium_SetOnPdfPrintFinished(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnPdfPrintFinished).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnPdfPrintFinished(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnPdfPrintFinished).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnZoomPctAvailable -func _CEFChromium_SetOnZoomPctAvailable(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnZoomPctAvailable).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnZoomPctAvailable(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnZoomPctAvailable).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnLoadStart -func _CEFChromium_SetOnLoadStart(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnLoadStart).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnLoadStart(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnLoadStart).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnLoadingStateChange -func _CEFChromium_SetOnLoadingStateChange(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnLoadingStateChange).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnLoadingStateChange(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnLoadingStateChange).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnLoadingProgressChange -func _CEFChromium_SetOnLoadingProgressChange(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnLoadingProgressChange).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnLoadingProgressChange(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnLoadingProgressChange).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnLoadError -func _CEFChromium_SetOnLoadError(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnLoadError).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnLoadError(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnLoadError).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnLoadEnd -func _CEFChromium_SetOnLoadEnd(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnLoadEnd).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnLoadEnd(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnLoadEnd).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnBeforeDownload -func _CEFChromium_SetOnBeforeDownload(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnBeforeDownload).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnBeforeDownload(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnBeforeDownload).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnDownloadUpdated -func _CEFChromium_SetOnDownloadUpdated(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnDownloadUpdated).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnDownloadUpdated(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnDownloadUpdated).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnFullScreenModeChange -func _CEFChromium_SetOnFullScreenModeChange(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnFullScreenModeChange).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnFullScreenModeChange(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnFullScreenModeChange).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnBeforeBrowser -func _CEFChromium_SetOnBeforeBrowser(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnBeforeBrowse).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnBeforeBrowser(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnBeforeBrowse).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnAddressChange -func _CEFChromium_SetOnAddressChange(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnAddressChange).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnAddressChange(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnAddressChange).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnKeyEvent -func _CEFChromium_SetOnKeyEvent(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnKeyEvent).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnKeyEvent(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnKeyEvent).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnTitleChange -func _CEFChromium_SetOnTitleChange(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnTitleChange).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnTitleChange(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnTitleChange).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnRenderCompMsg -func _CEFChromium_SetOnRenderCompMsg(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnRenderCompMsg).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnRenderCompMsg(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnRenderCompMsg).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnRenderProcessTerminated -func _CEFChromium_SetOnRenderProcessTerminated(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnRenderProcessTerminated).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnRenderProcessTerminated(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnRenderProcessTerminated).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnRenderViewReady -func _CEFChromium_SetOnRenderViewReady(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnRenderViewReady).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnRenderViewReady(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnRenderViewReady).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnScrollOffsetChanged -func _CEFChromium_SetOnScrollOffsetChanged(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnScrollOffsetChanged).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnScrollOffsetChanged(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnScrollOffsetChanged).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnProcessMessageReceived -func _CEFChromium_SetOnProcessMessageReceived(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnProcessMessageReceived).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnProcessMessageReceived(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnProcessMessageReceived).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnFindResult -func _CEFChromium_SetOnFindResult(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnFindResult).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnFindResult(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnFindResult).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnCookieSet -func _CEFChromium_SetOnCookieSet(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnCookieSet).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnCookieSet(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnCookieSet).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnCookiesDeleted -func _CEFChromium_SetOnCookiesDeleted(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnCookiesDeleted).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnCookiesDeleted(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnCookiesDeleted).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnCookiesFlushed -func _CEFChromium_SetOnCookiesFlushed(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnCookiesFlushed).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnCookiesFlushed(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnCookiesFlushed).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnCookiesVisited -func _CEFChromium_SetOnCookiesVisited(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnCookiesVisited).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnCookiesVisited(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnCookiesVisited).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnCookieVisitorDestroyed -func _CEFChromium_SetOnCookieVisitorDestroyed(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnCookieVisitorDestroyed).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnCookieVisitorDestroyed(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnCookieVisitorDestroyed).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnBeforeContextMenu -func _CEFChromium_SetOnBeforeContextMenu(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnBeforeContextMenu).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnBeforeContextMenu(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnBeforeContextMenu).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnContextMenuCommand -func _CEFChromium_SetOnContextMenuCommand(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnContextMenuCommand).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnContextMenuCommand(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnContextMenuCommand).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnContextMenuDismissed -func _CEFChromium_SetOnContextMenuDismissed(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnContextMenuDismissed).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnContextMenuDismissed(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnContextMenuDismissed).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnBeforeResourceLoad -func _CEFChromium_SetOnBeforeResourceLoad(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnBeforeResourceLoad).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnBeforeResourceLoad(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnBeforeResourceLoad).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnResourceResponse -func _CEFChromium_SetOnResourceResponse(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnResourceResponse).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnResourceResponse(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnResourceResponse).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnResourceRedirect -func _CEFChromium_SetOnResourceRedirect(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnResourceRedirect).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnResourceRedirect(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnResourceRedirect).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnResourceLoadComplete -func _CEFChromium_SetOnResourceLoadComplete(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnResourceLoadComplete).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnResourceLoadComplete(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnResourceLoadComplete).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnFrameAttached -func _CEFChromium_SetOnFrameAttached(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnFrameAttached).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnFrameAttached(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnFrameAttached).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnFrameCreated -func _CEFChromium_SetOnFrameCreated(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnFrameCreated).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnFrameCreated(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnFrameCreated).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnFrameDetached -func _CEFChromium_SetOnFrameDetached(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnFrameDetached).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnFrameDetached(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnFrameDetached).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnMainFrameChanged -func _CEFChromium_SetOnMainFrameChanged(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnMainFrameChanged).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnMainFrameChanged(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnMainFrameChanged).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnBeforePopup -func _CEFChromium_SetOnBeforePopup(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnBeforePopup).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnBeforePopup(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnBeforePopup).Call(instance, api.MakeEventDataPtr(fn)) } // TCEFChromium _CEFChromium_SetOnOpenUrlFromTab -func _CEFChromium_SetOnOpenUrlFromTab(instance uintptr, fn interface{}, independentEvent bool) { - Proc(internale_CEFChromium_SetOnOpenUrlFromTab).Call(instance, chromiumOnEventNameToId(fn, independentEvent)) +func _CEFChromium_SetOnOpenUrlFromTab(instance uintptr, fn interface{}) { + Proc(internale_CEFChromium_SetOnOpenUrlFromTab).Call(instance, api.MakeEventDataPtr(fn)) } //--------TCEFChromium Event proc end-------- diff --git a/cef/cef-chromium.go b/cef/cef-chromium.go index bb09026b..3ecb0d06 100644 --- a/cef/cef-chromium.go +++ b/cef/cef-chromium.go @@ -32,27 +32,13 @@ type ExecuteJS struct { type IChromium interface { IChromiumProc IChromiumEvent - //启用独立事件 默认禁用, 启用后所有默认事件行为将不在主窗口chromium event执行 - // - //启用后注册的事件才生效 - // - //只对当前chromium对象有效 - EnableIndependentEvent() - - //禁用独立事件 默认禁用, 禁用后所有默认事件行为在主窗口chromium event执行 - // - //禁用后注册的事件才生效 - // - //只对当前chromium对象有效 - DisableIndependentEvent() } type TCEFChromium struct { *lcl.TComponent - instance unsafe.Pointer - cfg *tCefChromiumConfig - independentEvent bool - emitLock *sync.Mutex + instance unsafe.Pointer + cfg *tCefChromiumConfig + emitLock *sync.Mutex } func NewChromium(owner lcl.IComponent, config *tCefChromiumConfig) IChromium { @@ -78,16 +64,6 @@ func (m *TCEFChromium) GetBrowserById(browserId int32) *ICefBrowser { } } -//启用独立事件 默认 false -func (m *TCEFChromium) EnableIndependentEvent() { - m.independentEvent = true -} - -//禁用独立事件 默认 false -func (m *TCEFChromium) DisableIndependentEvent() { - m.independentEvent = false -} - func (m *TCEFChromium) browseEmitJsOnEvent(browseId int32, frameId int64, name string, argumentList ipc.IArgumentList) ProcessMessageError { data := argumentList.Package() r1 := _CEFFrame_SendProcessMessage(browseId, frameId, name, PID_RENDER, int32(argumentList.Size()), uintptr(unsafe.Pointer(&data[0])), uintptr(len(data))) diff --git a/cef/cef-commponent-tray_window.go b/cef/cef-commponent-tray_window.go index 6b182119..11416369 100644 --- a/cef/cef-commponent-tray_window.go +++ b/cef/cef-commponent-tray_window.go @@ -213,8 +213,6 @@ func (m *tCefTrayForm) createCefTrayWindow() { m.windowParent.SetAlign(types.AlClient) m.windowParent.SetAnchors(types.NewSet(types.AkTop, types.AkLeft, types.AkRight, types.AkBottom)) m.chromium = NewChromium(m.windowParent, nil) - //打开独立出事件 - m.chromium.EnableIndependentEvent() m.chromium.SetOnBeforeContextMenu(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, model *ICefMenuModel) { model.Clear() }) diff --git a/cef/cef-events.go b/cef/cef-events.go index 7e4fb4ab..6c549682 100644 --- a/cef/cef-events.go +++ b/cef/cef-events.go @@ -12,7 +12,6 @@ import ( . "github.com/energye/energy/common" . "github.com/energye/energy/consts" "github.com/energye/energy/ipc" - "github.com/energye/energy/logger" t "github.com/energye/energy/types" "github.com/energye/golcl/lcl" "github.com/energye/golcl/lcl/api" @@ -68,11 +67,11 @@ func init() { return lcl.AsObject(senderPtr), browser, frame, request, response } lcl.RegisterExtEventCallback(func(fn interface{}, getVal func(idx int) uintptr) bool { - defer func() { - if err := recover(); err != nil { - logger.Error("CEF Events Error:", err) - } - }() + //defer func() { + // if err := recover(); err != nil { + // logger.Error("CEF Events Error:", err) + // } + //}() var ( instance unsafe.Pointer ) diff --git a/cef/cef-lcl-browser-window.go b/cef/cef-lcl-browser-window.go index d505b755..7d0b0445 100644 --- a/cef/cef-lcl-browser-window.go +++ b/cef/cef-lcl-browser-window.go @@ -67,7 +67,10 @@ func NewBrowserWindow(config *tCefChromiumConfig, windowProperty *WindowProperty window.ChromiumCreate(config, windowProperty.Url) window.putChromiumWindowInfo() //OnBeforeBrowser 是一个必须的默认事件,在浏览器创建时窗口序号会根据browserId生成 - window.Chromium().SetOnBeforeBrowser(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame) bool { return false }) + window.Chromium().SetOnBeforeBrowser(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame) bool { + chromiumOnBeforeBrowser(browser, frame) + return false + }) return window } @@ -527,7 +530,6 @@ func (m *LCLBrowserWindow) registerPopupEvent() { } BrowserWindow.popupWindow.SetWindowType(consts.WT_POPUP_SUB_BROWSER) BrowserWindow.popupWindow.ChromiumCreate(BrowserWindow.Config.chromiumConfig, beforePopupInfo.TargetUrl) - BrowserWindow.popupWindow.chromium.EnableIndependentEvent() BrowserWindow.popupWindow.putChromiumWindowInfo() BrowserWindow.popupWindow.defaultChromiumEvent() var result = false diff --git a/example/mini-browser/src/min-browser.go b/example/mini-browser/src/min-browser.go index 8d4a0ff9..376a43a9 100644 --- a/example/mini-browser/src/min-browser.go +++ b/example/mini-browser/src/min-browser.go @@ -133,7 +133,8 @@ func AppBrowserInit() { var browserWindow *cef.LCLBrowserWindow event.On("js-new-browser-window", func(context ipc.IIPCContext) { fmt.Println("通过 js ipc emit 事件创建新Browser窗口 ProcessType:", common.Args.ProcessType()) - if browserWindow == nil { + + if browserWindow == nil || browserWindow.IsClosing() { wp := cef.NewWindowProperty() wp.Url = "https://www.baidu.com" wp.Title = "Browser新窗口标题" @@ -141,6 +142,10 @@ func AppBrowserInit() { browserWindow.SetWidth(800) browserWindow.SetHeight(600) browserWindow.SetShowInTaskBar() + browserWindow.EnableDefaultClose() + browserWindow.Chromium().SetOnTitleChange(func(sender lcl.IObject, browser *cef.ICefBrowser, title string) { + fmt.Println(wp.Title, title) + }) } fmt.Println("\t|--", browserWindow.IsClosing()) cef.QueueAsyncCall(func(id int) {