-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for Mac OS X. Example included.
Fixes to CEF structure initialization (Issue #10).
- Loading branch information
Showing
11 changed files
with
710 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,65 @@ | ||
.PHONY: all test clean | ||
.PHONY: detect_os Linux Darwin clean | ||
|
||
export GOPATH=$(PWD) | ||
INC = -I/usr/include/gtk-2.0 \ | ||
-I/usr/include/glib-2.0 \ | ||
-I/usr/include/cairo \ | ||
-I/usr/include/pango-1.0 \ | ||
-I/usr/include/gdk-pixbuf-2.0 \ | ||
-I/usr/include/atk-1.0 \ | ||
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include \ | ||
-I/usr/lib/x86_64-linux-gnu/gtk-2.0/include \ | ||
-I/usr/lib/i386-linux-gnu/gtk-2.0/include \ | ||
-I/usr/lib/i386-linux-gnu/glib-2.0/include \ | ||
-I/usr/lib64/glib-2.0/include \ | ||
-I/usr/lib64/gtk-2.0/include | ||
export CC=gcc $(INC) | ||
export CGO_LDFLAGS=-L $(PWD)/Release -lcef | ||
UNAME_S = $(shell uname -s) | ||
|
||
all: | ||
ifeq ($(UNAME_S), Linux) | ||
INC=-I. \ | ||
-I/usr/include/gtk-2.0 \ | ||
-I/usr/include/glib-2.0 \ | ||
-I/usr/include/cairo \ | ||
-I/usr/include/pango-1.0 \ | ||
-I/usr/include/gdk-pixbuf-2.0 \ | ||
-I/usr/include/atk-1.0 \ | ||
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include \ | ||
-I/usr/lib/x86_64-linux-gnu/gtk-2.0/include \ | ||
-I/usr/lib/i386-linux-gnu/gtk-2.0/include \ | ||
-I/usr/lib/i386-linux-gnu/glib-2.0/include \ | ||
-I/usr/lib64/glib-2.0/include \ | ||
-I/usr/lib64/gtk-2.0/include | ||
export CC=gcc $(INC) | ||
export CGO_LDFLAGS=-L $(PWD)/Release -lcef | ||
else ifeq($(UNAME_S), Darwin) | ||
INC=-I. | ||
export CGO_ENABLED=1 | ||
export CC=clang $(INC) | ||
export CGO_LDFLAGS=-F$(PWD)/Release/tmp -framework Cocoa -framework cef | ||
endif | ||
|
||
detect_os: | ||
make $(UNAME_S) | ||
|
||
Linux: | ||
clear | ||
go install gtk | ||
go install cef | ||
go test -ldflags "-r $(PWD)/Release" src/tests/cef_test.go | ||
go build -ldflags "-r ." -o Release/cef2go src/main_linux.go | ||
cd Release && ./cef2go && cd ../ | ||
|
||
Darwin: | ||
clear | ||
|
||
@# Required for linking. Go doesn't allow framework name | ||
@# to contain spaces, so we're making a copy of the framework | ||
@# without spaces. | ||
@if [ ! -d Release/tmp ]; then \ | ||
echo Copying CEF framework directory to Release/tmp ;\ | ||
mkdir -p Release/tmp ;\ | ||
cp -rf Release/cef2go.app/Contents/Frameworks/Chromium\ Embedded\ Framework.framework Release/tmp/cef.framework ;\ | ||
mv Release/tmp/cef.framework/Chromium\ Embedded\ Framework Release/tmp/cef.framework/cef ;\ | ||
fi | ||
go install -x cef | ||
@# CEF requires specific app bundle / directory structure | ||
@# on OSX, but Go doesn't allow for such thing when | ||
@# running test. So turning off test. | ||
@# go test -ldflags "-r $(PWD)/Release" src/tests/cef_test.go | ||
rm -f Release/cef2go.app/Contents/MacOS/cef2go | ||
go build -x -ldflags "-r ." -o Release/cef2go.app/Contents/MacOS/cef2go src/main_darwin.go | ||
install_name_tool -change @executable_path/Chromium\ Embedded\ Framework @executable_path/../Frameworks/Chromium\ Embedded\ Framework.framework/Chromium\ Embedded\ Framework Release/cef2go.app/Contents/MacOS/cef2go | ||
cp -f Release/example.html Release/cef2go.app/Contents/MacOS/example.html | ||
cd Release/cef2go.app/Contents/MacOS && ./cef2go && cd ../../../../ | ||
|
||
clean: | ||
clear | ||
go clean -i cef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) 2014 The cefcapi authors. All rights reserved. | ||
// License: BSD 3-clause. | ||
// Website: https://github.com/CzarekTomczak/cefcapi | ||
|
||
#pragma once | ||
|
||
#include "handlers/cef_base.h" | ||
#include "include/capi/cef_app_capi.h" | ||
|
||
// ---------------------------------------------------------------------------- | ||
// cef_app_t | ||
// ---------------------------------------------------------------------------- | ||
|
||
/// | ||
// Implement this structure to provide handler implementations. Methods will be | ||
// called by the process and/or thread indicated. | ||
/// | ||
|
||
/// | ||
// Provides an opportunity to view and/or modify command-line arguments before | ||
// processing by CEF and Chromium. The |process_type| value will be NULL for | ||
// the browser process. Do not keep a reference to the cef_command_line_t | ||
// object passed to this function. The CefSettings.command_line_args_disabled | ||
// value can be used to start with an NULL command-line object. Any values | ||
// specified in CefSettings that equate to command-line arguments will be set | ||
// before this function is called. Be cautious when using this function to | ||
// modify command-line arguments for non-browser processes as this may result | ||
// in undefined behavior including crashes. | ||
/// | ||
void CEF_CALLBACK on_before_command_line_processing( | ||
struct _cef_app_t* self, const cef_string_t* process_type, | ||
struct _cef_command_line_t* command_line) { | ||
DEBUG_CALLBACK("on_before_command_line_processing\n"); | ||
} | ||
|
||
/// | ||
// Provides an opportunity to register custom schemes. Do not keep a reference | ||
// to the |registrar| object. This function is called on the main thread for | ||
// each process and the registered schemes should be the same across all | ||
// processes. | ||
/// | ||
void CEF_CALLBACK on_register_custom_schemes( | ||
struct _cef_app_t* self, | ||
struct _cef_scheme_registrar_t* registrar) { | ||
DEBUG_CALLBACK("on_register_custom_schemes\n"); | ||
} | ||
|
||
/// | ||
// Return the handler for resource bundle events. If | ||
// CefSettings.pack_loading_disabled is true (1) a handler must be returned. | ||
// If no handler is returned resources will be loaded from pack files. This | ||
// function is called by the browser and render processes on multiple threads. | ||
/// | ||
struct CEF_CALLBACK _cef_resource_bundle_handler_t* | ||
get_resource_bundle_handler(struct _cef_app_t* self) { | ||
DEBUG_CALLBACK("get_resource_bundle_handler\n"); | ||
return NULL; | ||
} | ||
|
||
/// | ||
// Return the handler for functionality specific to the browser process. This | ||
// function is called on multiple threads in the browser process. | ||
/// | ||
struct CEF_CALLBACK _cef_browser_process_handler_t* | ||
get_browser_process_handler(struct _cef_app_t* self) { | ||
DEBUG_CALLBACK("get_browser_process_handler\n"); | ||
return NULL; | ||
} | ||
|
||
/// | ||
// Return the handler for functionality specific to the render process. This | ||
// function is called on the render process main thread. | ||
/// | ||
struct CEF_CALLBACK _cef_render_process_handler_t* get_render_process_handler( | ||
struct _cef_app_t* self) { | ||
DEBUG_CALLBACK("get_render_process_handler\n"); | ||
return NULL; | ||
} | ||
|
||
void initialize_app_handler(cef_app_t* app) { | ||
printf("initialize_app_handler\n"); | ||
app->base.size = sizeof(cef_app_t); | ||
initialize_cef_base((cef_base_t*)app); | ||
// callbacks | ||
app->on_before_command_line_processing = on_before_command_line_processing; | ||
app->on_register_custom_schemes = on_register_custom_schemes; | ||
app->get_resource_bundle_handler = get_resource_bundle_handler; | ||
app->get_browser_process_handler = get_browser_process_handler; | ||
app->get_render_process_handler = get_render_process_handler; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) 2014 The cefcapi authors. All rights reserved. | ||
// License: BSD 3-clause. | ||
// Website: https://github.com/CzarekTomczak/cefcapi | ||
|
||
#pragma once | ||
|
||
#include "include/capi/cef_base_capi.h" | ||
|
||
// Set to 1 to check if add_ref() and release() | ||
// are called and to track the total number of calls. | ||
// add_ref will be printed as "+", release as "-". | ||
#define DEBUG_REFERENCE_COUNTING 0 | ||
|
||
// Print only the first execution of the callback, | ||
// ignore the subsequent. | ||
#define DEBUG_CALLBACK(x) { static int first_call = 1; if (first_call == 1) { first_call = 0; printf(x); } } | ||
|
||
// ---------------------------------------------------------------------------- | ||
// cef_base_t | ||
// ---------------------------------------------------------------------------- | ||
|
||
/// | ||
// Structure defining the reference count implementation functions. All | ||
// framework structures must include the cef_base_t structure first. | ||
/// | ||
|
||
/// | ||
// Increment the reference count. | ||
/// | ||
int CEF_CALLBACK add_ref(cef_base_t* self) { | ||
DEBUG_CALLBACK("cef_base_t.add_ref\n"); | ||
if (DEBUG_REFERENCE_COUNTING) | ||
printf("+"); | ||
return 1; | ||
} | ||
|
||
/// | ||
// Decrement the reference count. Delete this object when no references | ||
// remain. | ||
/// | ||
int CEF_CALLBACK release(cef_base_t* self) { | ||
DEBUG_CALLBACK("cef_base_t.release\n"); | ||
if (DEBUG_REFERENCE_COUNTING) | ||
printf("-"); | ||
return 1; | ||
} | ||
|
||
/// | ||
// Returns the current number of references. | ||
/// | ||
int CEF_CALLBACK get_refct(cef_base_t* self) { | ||
DEBUG_CALLBACK("cef_base_t.get_refct\n"); | ||
if (DEBUG_REFERENCE_COUNTING) | ||
printf("="); | ||
return 1; | ||
} | ||
|
||
void initialize_cef_base(cef_base_t* base) { | ||
printf("initialize_cef_base\n"); | ||
// Check if "size" member was set. | ||
size_t size = base->size; | ||
// Let's print the size in case sizeof was used | ||
// on a pointer instead of a structure. In such | ||
// case the number will be very high. | ||
printf("cef_base_t.size = %lu\n", size); | ||
if (size <= 0) { | ||
printf("FATAL: initialize_cef_base failed, size member not set\n"); | ||
_exit(1); | ||
} | ||
base->add_ref = add_ref; | ||
base->release = release; | ||
base->get_refct = get_refct; | ||
} |
Oops, something went wrong.