2012-01-23 20:04:54 +01:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
|
2011-01-10 02:31:12 +01:00
|
|
|
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/cef_context.h"
|
|
|
|
#include "libcef/browser_impl.h"
|
|
|
|
#include "libcef/browser_settings.h"
|
|
|
|
|
2013-02-26 00:44:37 +01:00
|
|
|
#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
|
|
|
|
#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
2011-01-10 02:31:12 +01:00
|
|
|
#include "webkit/glue/webpreferences.h"
|
|
|
|
|
|
|
|
using WebKit::WebRect;
|
|
|
|
using WebKit::WebSize;
|
|
|
|
|
2011-12-31 01:57:52 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void window_destroyed(GtkWidget* widget, CefBrowserImpl* browser) {
|
|
|
|
browser->UIT_DestroyBrowser();
|
|
|
|
}
|
|
|
|
|
2013-02-01 18:54:45 +01:00
|
|
|
gboolean button_press_event(
|
|
|
|
GtkWidget* widget,
|
|
|
|
GdkEventButton* event,
|
|
|
|
CefBrowserImpl* browser) {
|
|
|
|
browser->set_last_mouse_down(event);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean focus_out_event(
|
|
|
|
GtkWidget* widget,
|
|
|
|
GdkEventFocus* focus,
|
|
|
|
CefBrowserImpl* browser) {
|
|
|
|
browser->set_last_mouse_down(NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
} // namespace
|
2011-12-31 01:57:52 +01:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::ParentWindowWillClose() {
|
2011-08-03 17:35:51 +02:00
|
|
|
// TODO(port): Implement this method if necessary.
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefWindowHandle CefBrowserImpl::GetWindowHandle() {
|
2011-01-29 02:42:59 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return window_info_.m_Widget;
|
2011-01-10 02:31:12 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefBrowserImpl::IsWindowRenderingDisabled() {
|
2011-03-24 21:36:47 +01:00
|
|
|
// TODO(port): Add support for off-screen rendering.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:20:52 +02:00
|
|
|
gfx::NativeView CefBrowserImpl::UIT_GetMainWndHandle() {
|
2011-01-29 02:42:59 +01:00
|
|
|
REQUIRE_UIT();
|
2011-10-24 22:20:52 +02:00
|
|
|
return window_info_.m_Widget;
|
2011-01-10 02:31:12 +01:00
|
|
|
}
|
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
void CefBrowserImpl::UIT_ClearMainWndHandle() {
|
|
|
|
REQUIRE_UIT();
|
|
|
|
window_info_.m_Widget = NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefBrowserImpl::UIT_CreateBrowser(const CefString& url) {
|
2011-01-10 02:31:12 +01:00
|
|
|
REQUIRE_UIT();
|
2011-01-29 02:42:59 +01:00
|
|
|
Lock();
|
|
|
|
|
2011-01-10 02:31:12 +01:00
|
|
|
// Add a reference that will be released in UIT_DestroyBrowser().
|
|
|
|
AddRef();
|
|
|
|
|
|
|
|
// Add the new browser to the list maintained by the context
|
|
|
|
_Context->AddBrowser(this);
|
2011-01-25 19:37:27 +01:00
|
|
|
|
|
|
|
if (!settings_.developer_tools_disabled)
|
|
|
|
dev_tools_agent_.reset(new BrowserDevToolsAgent());
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
GtkWidget* window;
|
2011-10-24 22:20:52 +02:00
|
|
|
GtkWidget* parentView = window_info_.m_ParentWidget;
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (parentView == NULL) {
|
2011-10-24 22:20:52 +02:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2012-05-23 21:01:04 +02:00
|
|
|
webkit_glue::WebPreferences prefs;
|
2011-01-10 02:31:12 +01:00
|
|
|
BrowserToWebSettings(settings_, prefs);
|
|
|
|
|
|
|
|
// Create the webview host object
|
|
|
|
webviewhost_.reset(
|
|
|
|
WebViewHost::Create(window_info_.m_ParentWidget, gfx::Rect(),
|
2011-03-24 21:36:47 +01:00
|
|
|
delegate_.get(), NULL, dev_tools_agent_.get(),
|
|
|
|
prefs));
|
2011-01-25 19:37:27 +01:00
|
|
|
|
|
|
|
if (!settings_.developer_tools_disabled)
|
|
|
|
dev_tools_agent_->SetWebView(webviewhost_->webview());
|
|
|
|
|
2012-08-15 01:33:57 +02:00
|
|
|
webviewhost_->SetFrameRate(settings_.animation_frame_rate);
|
|
|
|
|
2011-01-10 02:31:12 +01:00
|
|
|
window_info_.m_Widget = webviewhost_->view_handle();
|
2011-12-31 01:57:52 +01:00
|
|
|
g_signal_connect(G_OBJECT(window_info_.m_Widget), "destroy",
|
|
|
|
G_CALLBACK(window_destroyed), this);
|
2011-01-29 02:42:59 +01:00
|
|
|
|
2013-02-01 18:54:45 +01:00
|
|
|
if (!settings_.drag_drop_disabled) {
|
|
|
|
g_signal_connect(G_OBJECT(window_info_.m_Widget), "button-press-event",
|
|
|
|
G_CALLBACK(button_press_event), this);
|
|
|
|
g_signal_connect(G_OBJECT(window_info_.m_Widget), "focus-out-event",
|
|
|
|
G_CALLBACK(focus_out_event), this);
|
|
|
|
|
2012-01-23 20:04:54 +01:00
|
|
|
delegate_->RegisterDragDrop();
|
2013-02-01 18:54:45 +01:00
|
|
|
}
|
2012-01-23 20:04:54 +01:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
Unlock();
|
|
|
|
|
2011-10-24 22:20:52 +02:00
|
|
|
if (client_.get()) {
|
|
|
|
CefRefPtr<CefLifeSpanHandler> handler = client_->GetLifeSpanHandler();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (handler.get()) {
|
2011-10-24 22:20:52 +02:00
|
|
|
// Notify the handler that we're done creating the new window
|
|
|
|
handler->OnAfterCreated(this);
|
|
|
|
}
|
2011-01-10 02:31:12 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (url.size() > 0)
|
2011-01-29 23:52:34 +01:00
|
|
|
UIT_LoadURL(GetMainFrame(), url);
|
2011-10-21 23:00:59 +02:00
|
|
|
|
|
|
|
return true;
|
2011-01-29 23:52:34 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable) {
|
2011-01-10 02:31:12 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
if (!host)
|
|
|
|
return;
|
2011-02-15 19:07:24 +01:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (enable)
|
2011-01-10 02:31:12 +01:00
|
|
|
gtk_widget_grab_focus(host->view_handle());
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefBrowserImpl::UIT_ViewDocumentString(WebKit::WebFrame *frame) {
|
2011-01-10 02:31:12 +01:00
|
|
|
REQUIRE_UIT();
|
2011-02-15 19:07:24 +01:00
|
|
|
|
2011-10-24 22:20:52 +02:00
|
|
|
char buff[] = "/tmp/CEFSourceXXXXXX";
|
|
|
|
int fd = mkstemp(buff);
|
|
|
|
|
|
|
|
if (fd == -1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
FILE* srcOutput;
|
|
|
|
srcOutput = fdopen(fd, "w+");
|
|
|
|
|
|
|
|
if (!srcOutput)
|
|
|
|
return false;
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-10-24 22:20:52 +02:00
|
|
|
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;
|
2011-01-10 02:31:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
|
|
|
|
const gfx::Size& canvas_size,
|
|
|
|
WebKit::WebFrame* frame) {
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
// TODO(port): Add implementation.
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_PrintPages(WebKit::WebFrame* frame) {
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
// TODO(port): Add implementation.
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
int CefBrowserImpl::UIT_GetPagesCount(WebKit::WebFrame* frame) {
|
2011-02-15 19:07:24 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
|
2011-01-10 02:31:12 +01:00
|
|
|
// TODO(port): Add implementation.
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
return 0;
|
|
|
|
}
|
2011-02-01 16:37:47 +01:00
|
|
|
|
|
|
|
// static
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_CloseView(gfx::NativeView view) {
|
2011-12-31 01:57:52 +01:00
|
|
|
GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(view));
|
2013-01-18 21:18:03 +01:00
|
|
|
gtk_signal_emit_by_name(GTK_OBJECT(window), "delete_event");
|
2011-10-24 22:20:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefBrowserImpl::UIT_IsViewVisible(gfx::NativeView view) {
|
2011-10-24 22:20:52 +02:00
|
|
|
if (!view)
|
|
|
|
return false;
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-10-24 22:20:52 +02:00
|
|
|
if (view->window)
|
2012-01-10 00:46:23 +01:00
|
|
|
return gdk_window_is_visible(view->window)?true:false;
|
2011-10-24 22:20:52 +02:00
|
|
|
else
|
|
|
|
return false;
|
2011-02-01 16:37:47 +01:00
|
|
|
}
|
2013-02-01 18:54:45 +01:00
|
|
|
|
|
|
|
void CefBrowserImpl::set_last_mouse_down(GdkEventButton* event) {
|
|
|
|
GdkEventButton* temp = NULL;
|
|
|
|
if (event) {
|
|
|
|
temp = reinterpret_cast<GdkEventButton*>(
|
|
|
|
gdk_event_copy(reinterpret_cast<GdkEvent*>(event)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_mouse_down_)
|
|
|
|
gdk_event_free(reinterpret_cast<GdkEvent*>(last_mouse_down_));
|
|
|
|
|
|
|
|
last_mouse_down_ = temp;
|
|
|
|
}
|