2022-10-04 13:21:05 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
2022-10-04 16:38:43 +08:00
|
|
|
// Licensed under GNU General Public License v3.0
|
2022-10-04 13:21:05 +08:00
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
package cef
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-01-26 10:27:54 +08:00
|
|
|
"github.com/energye/energy/common"
|
2023-01-27 19:20:33 +08:00
|
|
|
"github.com/energye/energy/common/assetserve"
|
2022-10-04 22:34:57 +08:00
|
|
|
. "github.com/energye/energy/consts"
|
2023-01-26 10:27:54 +08:00
|
|
|
"github.com/energye/golcl/lcl"
|
2022-10-04 13:21:05 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-01-24 16:32:28 +08:00
|
|
|
view_source_name = "view-source"
|
2022-10-04 13:21:05 +08:00
|
|
|
)
|
|
|
|
|
2023-01-09 08:53:01 +08:00
|
|
|
func (m *ICefBrowser) createBrowserViewSource(frame *ICefFrame) {
|
2023-01-09 10:09:45 +08:00
|
|
|
if currentWindowInfo := BrowserWindow.GetWindowInfo(m.Identifier()); currentWindowInfo != nil {
|
|
|
|
if currentWindowInfo.IsLCL() {
|
2023-01-24 16:32:28 +08:00
|
|
|
var viewSourceUrl = fmt.Sprintf("view-source:%s", frame.Url)
|
2023-01-09 10:09:45 +08:00
|
|
|
QueueAsyncCall(func(id int) {
|
2023-01-24 16:32:28 +08:00
|
|
|
wp := NewWindowProperty()
|
|
|
|
wp.Url = viewSourceUrl
|
|
|
|
wp.Title = fmt.Sprintf("%s - %s", view_source_name, frame.Url)
|
|
|
|
wp.WindowType = WT_VIEW_SOURCE
|
|
|
|
viewSourceWindow := NewLCLBrowserWindow(nil, wp)
|
|
|
|
viewSourceWindow.SetWidth(800)
|
|
|
|
viewSourceWindow.SetHeight(600)
|
2023-01-26 10:27:54 +08:00
|
|
|
if common.IsDarwin() {
|
|
|
|
viewSourceWindow.Chromium().SetOnAfterCreated(func(sender lcl.IObject, browser *ICefBrowser) {
|
|
|
|
viewSourceWindow.Chromium().LoadUrl(viewSourceUrl)
|
|
|
|
})
|
|
|
|
}
|
2023-01-27 19:20:33 +08:00
|
|
|
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-01-24 16:32:28 +08:00
|
|
|
viewSourceWindow.EnableDefaultCloseEvent()
|
|
|
|
viewSourceWindow.Show()
|
2023-01-09 10:09:45 +08:00
|
|
|
})
|
|
|
|
} else if currentWindowInfo.IsViewsFramework() {
|
|
|
|
frame.ViewSource()
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
2023-01-09 10:09:45 +08:00
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|