energy/cef/aux-viewsource.go

72 lines
2.4 KiB
Go
Raw Normal View History

2022-10-04 13:21:05 +08:00
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
2022-10-04 13:21:05 +08:00
//
//----------------------------------------
// 辅助工具-显示网页源代码
2023-05-31 17:41:14 +08:00
2022-10-04 13:21:05 +08:00
package cef
import (
"fmt"
2023-05-31 18:00:34 +08:00
"github.com/energye/energy/v2/common"
. "github.com/energye/energy/v2/consts"
"github.com/energye/energy/v2/pkgs/assetserve"
2023-01-26 10:27:54 +08:00
"github.com/energye/golcl/lcl"
2022-10-04 13:21:05 +08:00
)
const (
2023-06-15 18:29:23 +08:00
viewSourceName = "view-source"
2022-10-04 13:21:05 +08:00
)
2023-02-26 19:14:49 +08:00
func (m *ICefBrowser) createBrowserViewSource() {
if currentWindowInfo := BrowserWindow.GetWindowInfo(m.Identifier()); currentWindowInfo != nil {
2023-02-26 19:14:49 +08:00
var frame = m.MainFrame()
if currentWindowInfo.IsLCL() {
2023-02-26 19:14:49 +08:00
var viewSourceUrl = fmt.Sprintf("view-source:%s", frame.Url())
wp := NewWindowProperty()
wp.Url = viewSourceUrl
2023-06-15 18:29:23 +08:00
wp.Title = fmt.Sprintf("%s - %s", viewSourceName, frame.Url())
2023-02-26 19:14:49 +08:00
wp.WindowType = WT_VIEW_SOURCE
viewSourceWindow := NewLCLBrowserWindow(nil, wp)
viewSourceWindow.SetWidth(800)
viewSourceWindow.SetHeight(600)
2023-07-20 18:06:26 +08:00
if common.IsDarwin() || common.IsLinux() {
2023-02-26 19:14:49 +08:00
viewSourceWindow.Chromium().SetOnAfterCreated(func(sender lcl.IObject, browser *ICefBrowser) {
viewSourceWindow.Chromium().LoadUrl(viewSourceUrl)
})
}
if assetserve.AssetsServerHeaderKeyValue != "" {
viewSourceWindow.Chromium().SetOnBeforeResourceLoad(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, callback *ICefCallback, result *TCefReturnValue) {
request.SetHeaderByName(assetserve.AssetsServerHeaderKeyName, assetserve.AssetsServerHeaderKeyValue, true)
})
}
2023-07-18 18:03:19 +08:00
viewSourceWindow.Chromium().SetOnBeforePopup(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, beforePopupInfo *BeforePopupInfo, client *ICefClient, noJavascriptAccess *bool) bool {
wp := NewWindowProperty()
wp.Url = beforePopupInfo.TargetUrl
wp.Title = beforePopupInfo.TargetUrl
wp.WindowType = WT_VIEW_SOURCE
bw := NewLCLBrowserWindow(nil, wp)
bw.SetWidth(800)
bw.SetHeight(600)
bw.EnableDefaultCloseEvent()
QueueAsyncCall(func(id int) { //main thread run
bw.Show()
})
return true
})
2023-02-26 19:14:49 +08:00
viewSourceWindow.EnableDefaultCloseEvent()
2023-05-31 17:41:14 +08:00
QueueAsyncCall(func(id int) { //main thread run
viewSourceWindow.Show()
})
} else if currentWindowInfo.IsViewsFramework() {
frame.ViewSource()
2022-10-04 13:21:05 +08:00
}
}
2022-10-04 13:21:05 +08:00
}