Add initial Linux support (issue #40).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@338 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2011-10-24 20:20:52 +00:00
parent becadcfd16
commit 7a91ff899f
25 changed files with 986 additions and 51 deletions

View File

@ -35,11 +35,9 @@ bool CefBrowserImpl::IsWindowRenderingDisabled()
return false;
}
gfx::NativeWindow CefBrowserImpl::UIT_GetMainWndHandle() {
gfx::NativeView CefBrowserImpl::UIT_GetMainWndHandle() {
REQUIRE_UIT();
GtkWidget* toplevel = gtk_widget_get_ancestor(window_info_.m_Widget,
GTK_TYPE_WINDOW);
return GTK_IS_WINDOW(toplevel) ? GTK_WINDOW(toplevel) : NULL;
return window_info_.m_Widget;
}
bool CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
@ -56,6 +54,23 @@ bool CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
if (!settings_.developer_tools_disabled)
dev_tools_agent_.reset(new BrowserDevToolsAgent());
GtkWidget *window;
GtkWidget* parentView = window_info_.m_ParentWidget;
if(parentView == NULL) {
// Create a new window.
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
parentView = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), parentView);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_widget_show_all(GTK_WIDGET(window));
window_info_.m_ParentWidget = parentView;
}
WebPreferences prefs;
BrowserToWebSettings(settings_, prefs);
@ -72,9 +87,12 @@ bool CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
Unlock();
if(handler_.get()) {
// Notify the handler that we're done creating the new window
handler_->HandleAfterCreated(this);
if (client_.get()) {
CefRefPtr<CefLifeSpanHandler> handler = client_->GetLifeSpanHandler();
if(handler.get()) {
// Notify the handler that we're done creating the new window
handler->OnAfterCreated(this);
}
}
if(url.size() > 0)
@ -97,9 +115,37 @@ bool CefBrowserImpl::UIT_ViewDocumentString(WebKit::WebFrame *frame)
{
REQUIRE_UIT();
// TODO(port): Add implementation.
NOTIMPLEMENTED();
return false;
char buff[] = "/tmp/CEFSourceXXXXXX";
int fd = mkstemp(buff);
if (fd == -1)
return false;
FILE* srcOutput;
srcOutput = fdopen(fd, "w+");
if (!srcOutput)
return false;
std::string markup = frame->contentAsMarkup().utf8();
if (fputs(markup.c_str(), srcOutput) < 0) {
fclose(srcOutput);
return false;
}
fclose(srcOutput);
std::string newName(buff);
newName.append(".txt");
if (rename(buff, newName.c_str()) != 0)
return false;
std::string openCommand("xdg-open ");
openCommand += newName;
if (system(openCommand.c_str()) != 0)
return false;
return true;
}
void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
@ -130,6 +176,21 @@ int CefBrowserImpl::UIT_GetPagesCount(WebKit::WebFrame* frame)
// static
void CefBrowserImpl::UIT_CloseView(gfx::NativeView view)
{
GtkWidget* window =
gtk_widget_get_parent(gtk_widget_get_parent(GTK_WIDGET(view)));
MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction(
&gtk_widget_destroy, GTK_WIDGET(view)));
&gtk_widget_destroy, GTK_WIDGET(window)));
}
// static
bool CefBrowserImpl::UIT_IsViewVisible(gfx::NativeView view)
{
if (!view)
return false;
if (view->window)
return (bool)gdk_window_is_visible(view->window);
else
return false;
}