diff --git a/.gitignore b/.gitignore index c680a6c..d7bdf16 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ pkg/ .DS_Store +test.log +debug.log +*webcache* +cef2go +main_linux diff --git a/cef/cef.go b/cef/cef.go index f330d39..42dc5e1 100644 --- a/cef/cef.go +++ b/cef/cef.go @@ -33,6 +33,7 @@ import "C" import ( "log" "os" + "time" "unsafe" ) @@ -99,16 +100,7 @@ func _InitializeGlobalCStructures() { C.initialize_client_handler(_ClientHandler) } -var args []string - -// Appends args that get attached to each subprocess. Must be -// called before ExecuteProcess -func AppendArgToSubprocess(arg string) { - args = append(args, arg) -} - func ExecuteProcess(appHandle unsafe.Pointer) int { - os.Args = append(os.Args, args...) Logger.Println("ExecuteProcess, args=", os.Args) _InitializeGlobalCStructures() @@ -165,8 +157,10 @@ func Initialize(settings Settings) int { globalLifespanHandler = &LifeSpanHandler{make(chan *Browser)} ret := C.cef_initialize(_MainArgs, settings.ToCStruct(), _AppHandler, _SandboxInfo) - Logger.Println("Waiting for onContextInitialized") - WaitForContextInitialized() + // Sleep for 500ms to let cef _really_ initialize + // https://code.google.com/p/cefpython/issues/detail?id=131#c2 + time.Sleep(500 * time.Millisecond) + return int(ret) } @@ -186,11 +180,6 @@ func Shutdown() { // OFF: cef_sandbox_info_destroy(_SandboxInfo) } -func WaitForContextInitialized() { - Logger.Println("WaitForContextInitialized") - // <-contextInitialized -} - func OnUIThread() bool { return C.cef_currently_on(C.TID_UI) == 1 } diff --git a/cef/cef_callbacks.go b/cef/cef_callbacks.go index 060fd89..ba18910 100644 --- a/cef/cef_callbacks.go +++ b/cef/cef_callbacks.go @@ -8,12 +8,6 @@ package cef */ import "C" -//export go_OnContextInitialized -func go_OnContextInitialized() { - Logger.Println("go_OnContextInitialized") - contextInitialized <- 1 -} - //export go_OnAfterCreated func go_OnAfterCreated(self *C.struct__cef_life_span_handler_t, browser *C.cef_browser_t) { if globalLifespanHandler != nil { diff --git a/cef/cef_life_span_handler.go b/cef/cef_life_span_handler.go index 590719f..bb08169 100644 --- a/cef/cef_life_span_handler.go +++ b/cef/cef_life_span_handler.go @@ -25,7 +25,7 @@ func (l *LifeSpanHandler) RegisterAndWaitForBrowser(url string) (browser *Browse case b := <-l.browser: return b, nil // browser couldnt be created - case <-time.After(10 * time.Second): + case <-time.After(5 * time.Second): return nil, errors.New("Timedout waiting for browser to be created") } } diff --git a/debug.log b/debug.log deleted file mode 100644 index a099c80..0000000 --- a/debug.log +++ /dev/null @@ -1,32 +0,0 @@ -[0812/205457:VERBOSE1:pulse_stubs.cc(623)] dlopen(libpulse.so.0) failed, dlerror() says: - -[0812/205457:VERBOSE1:pref_proxy_config_tracker_impl.cc(148)] 0x7f7bc4051450: set chrome proxy config service to 0x7f7bc40837e0 -[0812/205457:VERBOSE1:pref_proxy_config_tracker_impl.cc(274)] 0x7f7bc4051450: Done pushing proxy to UpdateProxyConfig -[0812/205752:VERBOSE1:pulse_stubs.cc(623)] dlopen(libpulse.so.0) failed, dlerror() says: - -[0812/205752:VERBOSE1:pref_proxy_config_tracker_impl.cc(148)] 0x7f771c051450: set chrome proxy config service to 0x7f771c06d990 -[0812/205752:VERBOSE1:pref_proxy_config_tracker_impl.cc(274)] 0x7f771c051450: Done pushing proxy to UpdateProxyConfig -[0812/210224:VERBOSE1:pulse_stubs.cc(623)] dlopen(libpulse.so.0) failed, dlerror() says: - -[0812/210224:VERBOSE1:pref_proxy_config_tracker_impl.cc(148)] 0x7fc9e0051570: set chrome proxy config service to 0x7fc9e0084850 -[0812/210224:VERBOSE1:ffmpeg_stubs.cc(713)] dlopen(/tmp/go-build688935704/command-line-arguments/_obj/exe/libffmpegsumo.so) failed, dlerror() says: -/tmp/go-build688935704/command-line-arguments/_obj/exe/libffmpegsumo.so: cannot open shared object file: No such file or directory -[0812/210224:VERBOSE1:pref_proxy_config_tracker_impl.cc(274)] 0x7fc9e0051570: Done pushing proxy to UpdateProxyConfig -[0812/210224:VERBOSE1:ffmpeg_stubs.cc(713)] dlopen(/tmp/go-build688935704/command-line-arguments/_obj/exe/libavutil.so.52) failed, dlerror() says: -/tmp/go-build688935704/command-line-arguments/_obj/exe/libavutil.so.52: cannot open shared object file: No such file or directory -[0812/210224:VERBOSE1:ffmpeg_stubs.cc(713)] dlopen(/tmp/go-build688935704/command-line-arguments/_obj/exe/libavcodec.so.55) failed, dlerror() says: -/tmp/go-build688935704/command-line-arguments/_obj/exe/libavcodec.so.55: cannot open shared object file: No such file or directory -[0812/210224:VERBOSE1:ffmpeg_stubs.cc(713)] dlopen(/tmp/go-build688935704/command-line-arguments/_obj/exe/libavformat.so.55) failed, dlerror() says: -/tmp/go-build688935704/command-line-arguments/_obj/exe/libavformat.so.55: cannot open shared object file: No such file or directory -[0812/210224:VERBOSE1:zygote_main_linux.cc(413)] ZygoteMain: fork delegate is NULL -[0812/210224:ERROR:renderer_main.cc(226)] Running without renderer sandbox -[0812/210224:VERBOSE1:resource_loader.cc(304)] OnResponseStarted: file:///opt/src/paperlesspost/go/src/github.com/paperlesspost/cef2go/example.html -[0812/210224:VERBOSE1:resource_loader.cc(608)] ResponseCompleted: file:///opt/src/paperlesspost/go/src/github.com/paperlesspost/cef2go/example.html -[0812/210224:INFO:CONSOLE(1)] "we outchea", source: (1) -[0812/210224:VERBOSE1:transport_dib_gtk.cc(52)] Created SysV shared memory region 1343488 -[0812/210224:VERBOSE1:x11_util.cc(309)] Got shared memory segment 1376257 -[0812/210224:VERBOSE1:x11_util.cc(323)] X got shared memory segment 1376257 -[0812/210224:VERBOSE1:x11_util.cc(334)] X attached to shared memory segment 1376257 -[0812/210224:VERBOSE1:x11_util.cc(1125)] X attached to shared memory segment 1343488 -[0812/210224:VERBOSE1:web_contents_impl.cc(2130)] Failed Provisional Load: file:///opt/src/paperlesspost/go/src/github.com/paperlesspost/cef2go/example.html, error_code: -6, error_description: , is_main_frame: 1, showing_repost_interstitial: 0, frame_id: 1 -[0100/000000:VERBOSE1:ipc_sync_channel.cc(385)] Canceling pending sends diff --git a/lib/handlers/cef_app.h b/lib/handlers/cef_app.h index 968ba8d..8152257 100644 --- a/lib/handlers/cef_app.h +++ b/lib/handlers/cef_app.h @@ -48,7 +48,6 @@ void CEF_CALLBACK on_register_custom_schemes( void CEF_CALLBACK on_context_initialized( struct _cef_browser_process_handler_t* self) { - go_OnContextInitialized(); DEBUG_CALLBACK("on_context_initialized!\n"); } diff --git a/main_linux.go b/main_linux.go index 8496ac7..1b06ff3 100644 --- a/main_linux.go +++ b/main_linux.go @@ -14,9 +14,14 @@ import ( ) func main() { + cwd, _ := os.Getwd() + var releasePath = os.Getenv("RELEASE_PATH") + if releasePath == "" { + releasePath = cwd + } + fmt.Printf("RELEASE PATH %s", releasePath) // TODO: It should be executable's directory use // rather than working directory. - cwd, _ := os.Getwd() logger := log.New(os.Stdout, fmt.Sprintf("[%d] ", os.Getpid()), log.Lshortfile) cef.SetLogger(logger) // CEF subprocesses. @@ -24,10 +29,10 @@ func main() { // CEF initialize. settings := cef.Settings{} - settings.ResourcesDirPath = cwd + "/Release" - settings.LocalesDirPath = cwd + "/Release/locales" - settings.CachePath = cwd + "/webcache" // Set to empty to disable - settings.LogSeverity = cef.LOGSEVERITY_VERBOSE // LOGSEVERITY_VERBOSE + settings.ResourcesDirPath = releasePath + settings.LocalesDirPath = releasePath + "/locales" + settings.CachePath = cwd + "/webcache" // Set to empty to disable + settings.LogSeverity = cef.LOGSEVERITY_INFO // LOGSEVERITY_VERBOSE settings.LogFile = cwd + "/debug.log" settings.RemoteDebuggingPort = 7000 cef.Initialize(settings) @@ -39,7 +44,7 @@ func main() { // Create browser. browserSettings := &cef.BrowserSettings{} - url := "file://" + cwd + "/example.html" + url := "file://" + cwd + "/Release/example.html" go func() { browser := cef.CreateBrowser(window, browserSettings, url) browser.ExecuteJavaScript("console.log('we outchea');", "sup.js", 1)