Skip to content

Commit

Permalink
Initial support for Mac OS X. Example included.
Browse files Browse the repository at this point in the history
Fixes to CEF structure initialization (Issue #10).
  • Loading branch information
cztomczak committed Feb 14, 2014
1 parent 71cf659 commit ea047c9
Show file tree
Hide file tree
Showing 11 changed files with 710 additions and 61 deletions.
68 changes: 52 additions & 16 deletions Makefile
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
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CEF2go can act as a GUI toolkit, allowing you to create an HTML 5
based GUI in your application. Or you can provide browser
capabilities to your application.

Supported platforms: Windows, Linux (OS X not yet ready).
Supported platforms: Windows, Linux, Mac OSX.

Currently the CEF2go example creates just a simple window with
the Chromium browser embedded. You can set a few options for
Expand All @@ -34,6 +34,9 @@ Windows example: [releases/tag/v0.10]
Linux example: [releases/tag/v0.11]
(https://github.com/CzarekTomczak/cef2go/releases/tag/v0.11)

Mac OSX example: [releases/tag/v0.12]
(https://github.com/CzarekTomczak/cef2go/releases/tag/v0.12)


Support development
-------------------
Expand Down Expand Up @@ -76,3 +79,29 @@ Getting started on Linux
Copy Release/* to cef2go/Release

4. Run "make" command.


Getting started on Mac OS X
---------------------------
1. These instructions work fine with OS X 10.8 Mountain Lion.
May also work with other versions, but were not tested.

2. Install Go 32-bit. Tested with Go 1.2-386 for OSX 10.8.
CEF binaries for OSX 64-bit are still experimental, that's
why we're using 32-bit. Though you can try building with
CEF 64-bit, download binaries from [cefbuilds.com]
(http://cefbuilds.com).

3. Install command line tools (make is required) from:
https://developer.apple.com/downloads/
(In my case command line tools for Mountain Lion from September 2013)

4. Install XCode (gcc that comes with XCode is required).
Use the link above. In my case it was XCode 4.6.3 from June 2013.

5. Download CEF 3 branch 1750 revision 1625 binaries for 32-bit:
[releases/tag/v0.12]
(https://github.com/CzarekTomczak/cef2go/releases/tag/v0.12)
Copy the cef2go.app directory to cef2go/Release.

6. Run "make" command.
90 changes: 90 additions & 0 deletions handlers/cef_app.h
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;
}
73 changes: 73 additions & 0 deletions handlers/cef_base.h
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;
}
Loading

0 comments on commit ea047c9

Please # to comment.