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

@@ -1111,6 +1111,7 @@ CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(
info.SetAsPopup(NULL, CefString());
#endif
#if (defined(OS_WIN) || defined(OS_MACOSX))
// Default to the size from the popup features.
if(features.xSet)
info.m_x = features.x;
@@ -1120,6 +1121,7 @@ CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(
info.m_nWidth = features.width;
if(features.heightSet)
info.m_nHeight = features.height;
#endif
CefRefPtr<CefClient> client = client_;

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;
}

View File

@@ -129,10 +129,24 @@ void BrowserRequestContext::Init(
#endif // defined(OS_WIN)
if (!proxy_service()) {
// Use the system proxy resolver.
#if defined(OS_POSIX) && !defined(OS_MACOSX)
// Use no proxy to avoid ProxyConfigServiceLinux.
// Enabling use of the ProxyConfigServiceLinux requires:
// -Calling from a thread with a TYPE_UI MessageLoop,
// -If at all possible, passing in a pointer to the IO thread's MessageLoop,
// -Keep in mind that proxy auto configuration is also
// non-functional on linux in this context because of v8 threading
// issues.
// TODO(port): rename "linux" to some nonspecific unix.
scoped_ptr<net::ProxyConfigService> proxy_config_service(
new net::ProxyConfigServiceFixed(net::ProxyConfig()));
#else
// Use the system proxy settings.
scoped_ptr<net::ProxyConfigService> proxy_config_service(
net::ProxyService::CreateSystemProxyConfigService(
MessageLoop::current(), NULL));
#endif
storage_.set_proxy_service(net::ProxyService::CreateUsingSystemProxyResolver(
proxy_config_service.release(), 0, NULL));
}

View File

@@ -0,0 +1,22 @@
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
// 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 "browser_webkit_glue.h"
#include "cef_context.h"
#include "ui/base/resource/resource_bundle.h"
namespace webkit_glue {
base::StringPiece GetDataResource(int resource_id) {
base::StringPiece piece;
// Try to load the resource from the resource pack.
if (piece.empty())
piece = ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id);
DCHECK(!piece.empty()) << "Resource "<<resource_id<<" could not be loaded";
return piece;
}
}

View File

@@ -259,6 +259,10 @@ class BrowserWebViewDelegate : public WebKit::WebViewClient,
void ClosePopupMenu();
#endif
#ifdef OS_LINUX
void HandleContextMenu(int selected_id);
#endif
protected:
// Default handling of JavaScript messages.
void ShowJavaScriptAlert(WebKit::WebFrame* webframe,

View File

@@ -10,25 +10,41 @@
#include <gtk/gtk.h>
#include "base/message_loop.h"
#include "base/string_util.h"
#include "net/base/net_errors.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/gtk_util.h"
#include "ui/gfx/point.h"
#include "webkit/glue/webcursor.h"
#include "webkit/glue/webdropdata.h"
#include "webkit/glue/webpreferences.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/window_open_disposition.h"
#include "webkit/plugins/npapi/gtk_plugin_container_manager.h"
#include "webkit/plugins/npapi/plugin_list.h"
#include "webkit/plugins/npapi/webplugin.h"
#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
#include "include/internal/cef_types.h"
using webkit::npapi::WebPluginDelegateImpl;
using WebKit::WebContextMenuData;
using WebKit::WebCursorInfo;
using WebKit::WebDragData;
using WebKit::WebDragOperationsMask;
using WebKit::WebExternalPopupMenu;
using WebKit::WebExternalPopupMenuClient;
using WebKit::WebFrame;
using WebKit::WebImage;
using WebKit::WebNavigationPolicy;
using WebKit::WebPoint;
using WebKit::WebPopupMenuInfo;
using WebKit::WebRect;
using WebKit::WebWidget;
@@ -59,11 +75,11 @@ void SelectionClipboardGetContents(GtkClipboard* clipboard,
DCHECK(frame);
std::string selection;
if (TEXT_HTML == info) {
if (TEXT_HTML == info)
selection = frame->selectionAsMarkup().utf8();
} else {
else
selection = frame->selectionAsText().utf8();
}
if (TEXT_HTML == info) {
gtk_selection_data_set(selection_data,
GetTextHtmlAtom(),
@@ -78,17 +94,112 @@ void SelectionClipboardGetContents(GtkClipboard* clipboard,
} // namespace
// WebViewClient --------------------------------------------------------------
// WebViewClient ----------------------------------s----------------------------
WebWidget* BrowserWebViewDelegate::createPopupMenu(
const WebPopupMenuInfo& info) {
NOTREACHED();
WebKit::WebExternalPopupMenu* BrowserWebViewDelegate::createExternalPopupMenu(
const WebKit::WebPopupMenuInfo& info,
WebKit::WebExternalPopupMenuClient* client) {
NOTIMPLEMENTED();
return NULL;
}
void BrowserWebViewDelegate::showContextMenu(
WebKit::WebFrame* frame, const WebKit::WebContextMenuData& data) {
NOTIMPLEMENTED();
static gboolean MenuItemHandle(GtkWidget* menu_item, gpointer data)
{
if (!data)
return FALSE;
BrowserWebViewDelegate* webViewDelegate = (BrowserWebViewDelegate*)data;
int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menu_item), "menu_id"));
webViewDelegate->HandleContextMenu(id);
return FALSE;
}
static GtkWidget* MenuItemCreate(GtkWidget* parent_menu, const char* name,
int id, bool is_enabled, BrowserWebViewDelegate* webViewDelegate)
{
GtkWidget* menu_item = gtk_menu_item_new_with_label(name);
g_object_set_data(G_OBJECT(menu_item), "menu_id", (gpointer)id);
g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(MenuItemHandle),
(gpointer)webViewDelegate);
gtk_menu_shell_append(GTK_MENU_SHELL(parent_menu), menu_item);
gtk_widget_set_sensitive(menu_item, is_enabled);
gtk_widget_show(menu_item);
return menu_item;
}
static GtkWidget* MenuItemCreateSeperator(GtkWidget* parent_menu)
{
GtkWidget* menu_item = gtk_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(parent_menu), menu_item);
gtk_widget_show(menu_item);
return menu_item;
}
void BrowserWebViewDelegate::showContextMenu(WebKit::WebFrame* frame,
const WebKit::WebContextMenuData& data) {
GtkWidget* menu = NULL;
GdkPoint mouse_pt = { data.mousePosition.x, data.mousePosition.y };
int edit_flags = 0;
int type_flags = 0;
// Make sure events can be pumped while the menu is up.
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
// Give the client a chance to handle the menu.
if (OnBeforeMenu(data, mouse_pt.x, mouse_pt.y, edit_flags, type_flags))
return;
CefRefPtr<CefClient> client = browser_->GetClient();
CefRefPtr<CefMenuHandler> handler;
if (client.get())
handler = client->GetMenuHandler();
// Build the correct default context menu
if (type_flags & MENUTYPE_EDITABLE) {
menu = gtk_menu_new();
MenuItemCreate(menu, "Undo", MENU_ID_UNDO,
!!(edit_flags & MENU_CAN_UNDO), this);
MenuItemCreate(menu, "Redo", MENU_ID_REDO,
!!(edit_flags & MENU_CAN_REDO), this);
MenuItemCreate(menu, "Cut", MENU_ID_CUT,
!!(edit_flags & MENU_CAN_CUT), this);
MenuItemCreate(menu, "Copy", MENU_ID_COPY,
!!(edit_flags & MENU_CAN_COPY), this);
MenuItemCreate(menu, "Paste", MENU_ID_PASTE,
!!(edit_flags & MENU_CAN_PASTE), this);
MenuItemCreate(menu, "Delete", MENU_ID_DELETE,
!!(edit_flags & MENU_CAN_DELETE), this);
MenuItemCreateSeperator(menu);
MenuItemCreate(menu, "Select All", MENU_ID_SELECTALL,
!!(edit_flags & MENU_CAN_SELECT_ALL), this);
} else if(type_flags & MENUTYPE_SELECTION) {
menu = gtk_menu_new();
MenuItemCreate(menu, "Copy", MENU_ID_COPY,
!!(edit_flags & MENU_CAN_COPY), this);
} else if(type_flags & (MENUTYPE_PAGE | MENUTYPE_FRAME)) {
menu = gtk_menu_new();
MenuItemCreate(menu, "Back", MENU_ID_NAV_BACK,
!!(edit_flags & MENU_CAN_GO_BACK), this);
MenuItemCreate(menu, "Forward", MENU_ID_NAV_FORWARD,
!!(edit_flags & MENU_CAN_GO_FORWARD), this);
MenuItemCreateSeperator(menu);
// TODO(port): Enable the print item when supported.
// MenuItemCreate(menu, "Print", MENU_ID_PRINT, true, this);
MenuItemCreate(menu, "View Source", MENU_ID_VIEWSOURCE, true, this);
}
if (menu) {
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3,
gtk_get_current_event_time());
}
}
// WebWidgetClient ------------------------------------------------------------
@@ -123,7 +234,8 @@ void BrowserWebViewDelegate::didChangeCursor(const WebCursorInfo& cursor_info) {
gdk_cursor = gfx::GetCursor(cursor_type);
}
cursor_type_ = cursor_type;
gdk_window_set_cursor(browser_->UIT_GetWebViewWndHandle()->window, gdk_cursor);
gdk_window_set_cursor(browser_->UIT_GetWebViewWndHandle()->window,
gdk_cursor);
}
WebRect BrowserWebViewDelegate::windowRect() {
@@ -161,9 +273,9 @@ WebRect BrowserWebViewDelegate::rootWindowRect() {
// window. This means the x/y is the distance from the corner of the
// screen, and the width/height is the size of the entire browser window.
// For example, this is used to implement window.screenX and window.screenY.
GtkWidget* drawing_area = host->view_handle();
GtkWidget* window =
gtk_widget_get_parent(gtk_widget_get_parent(drawing_area));
GtkWidget* window = gtk_widget_get_ancestor(GTK_WIDGET(host->view_handle()),
GTK_TYPE_WINDOW);
gint x, y, width, height;
gtk_window_get_position(GTK_WINDOW(window), &x, &y);
gtk_window_get_size(GTK_WINDOW(window), &width, &height);
@@ -222,6 +334,30 @@ void BrowserWebViewDelegate::DidMovePlugin(
plugin_container_manager->MovePluginContainer(move);
}
void BrowserWebViewDelegate::HandleContextMenu(int selected_id)
{
if (selected_id != 0) {
CefRefPtr<CefClient> client = browser_->GetClient();
CefRefPtr<CefMenuHandler> handler;
if (client.get())
handler = client->GetMenuHandler();
// An action was chosen
cef_handler_menuid_t menuId =
static_cast<cef_handler_menuid_t>(selected_id);
bool handled = false;
if (handler.get()) {
// Ask the handler if it wants to handle the action
handled = handler->OnMenuAction(browser_, menuId);
}
if(!handled) {
// Execute the action
browser_->UIT_HandleAction(menuId, browser_->GetFocusedFrame());
}
}
}
// Protected methods ----------------------------------------------------------
void BrowserWebViewDelegate::ShowJavaScriptAlert(

View File

@@ -6,7 +6,7 @@
#include "browser_impl.h"
void CefProcessUIThread::PlatformInit() {
}
void CefProcessUIThread::PlatformCleanUp() {

View File

@@ -30,7 +30,7 @@ CEF_EXPORT int cef_string_map_find(cef_string_map_t map,
StringMap* impl = (StringMap*)map;
StringMap::const_iterator it = impl->find(CefString(key));
if(it == impl->end())
return NULL;
return 0;
const CefString& val = it->second;
return cef_string_set(val.c_str(), val.length(), value, true);
}
@@ -43,7 +43,7 @@ CEF_EXPORT int cef_string_map_key(cef_string_map_t map, int index,
StringMap* impl = (StringMap*)map;
DCHECK(index >= 0 && index < (int)impl->size());
if(index < 0 || index >= (int)impl->size())
return NULL;
return 0;
StringMap::const_iterator it = impl->begin();
for(int ct = 0; it != impl->end(); ++it, ct++) {
if(ct == index)
@@ -60,7 +60,7 @@ CEF_EXPORT int cef_string_map_value(cef_string_map_t map, int index,
StringMap* impl = (StringMap*)map;
DCHECK(index >= 0 && index < (int)impl->size());
if(index < 0 || index >= (int)impl->size())
return NULL;
return 0;
StringMap::const_iterator it = impl->begin();
for(int ct = 0; it != impl->end(); ++it, ct++) {
if(ct == index) {

View File

@@ -303,7 +303,7 @@ private:
job_->NotifyReadComplete(bytes_read);
dest_ = NULL;
dest_size_ = NULL;
dest_size_ = 0;
}
} else {
// All done.

View File

@@ -73,7 +73,7 @@ gfx::PluginWindowHandle WebWidgetHost::GetWindowedPluginAt(int x, int y)
}
}
return NULL;
return gfx::kNullPluginWindow;
}
void WebWidgetHost::DoPaint() {

View File

@@ -227,6 +227,9 @@ class WebWidgetHostGtkWidget {
return FALSE; // We do not forward any other buttons to the renderer.
if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS)
return FALSE;
gtk_widget_grab_focus(widget);
host->webwidget()->handleInputEvent(
WebInputEventFactory::mouseEvent(event));
return FALSE;
@@ -346,7 +349,8 @@ WebWidgetHost::~WebWidgetHost() {
g_object_set_data(G_OBJECT(view_), kWebWidgetHostKey, NULL);
g_signal_handlers_disconnect_matched(view_,
G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, this);
webwidget_->close();
// TODO(port): Figure out why we can't do this without crashing.
// webwidget_->close();
}
void WebWidgetHost::Resize(const gfx::Size &newsize) {