- Complete basic functionality in libcef.
- Port cefclient and unittests.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@135 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2010-11-15 15:39:56 +00:00
parent 54e0a2db9a
commit c629ac966f
40 changed files with 931 additions and 216 deletions

View File

@@ -539,6 +539,25 @@ CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
return browser;
}
void CefBrowserImpl::UIT_DestroyBrowser()
{
if(handler_.get()) {
// Notify the handler that the window is about to be closed.
handler_->HandleBeforeWindowClose(this);
}
GetWebViewDelegate()->RevokeDragDrop();
// Clean up anything associated with the WebViewHost widget.
GetWebViewHost()->webwidget()->close();
webviewhost_.reset();
// Remove the reference added in UIT_CreateBrowser().
Release();
// Remove the browser from the list maintained by the context.
_Context->RemoveBrowser(this);
}
void CefBrowserImpl::UIT_LoadURL(CefFrame* frame,
const std::wstring& url)
{

View File

@@ -160,6 +160,7 @@ public:
}
void UIT_CreateBrowser(const std::wstring& url);
void UIT_DestroyBrowser();
void UIT_LoadURL(CefFrame* frame,
const std::wstring& url);

View File

@@ -5,6 +5,7 @@
#include "cef_context.h"
#include "browser_impl.h"
#include "browser_webview_mac.h"
#import <Cocoa/Cocoa.h>
@@ -20,36 +21,38 @@ using WebKit::WebSize;
CefWindowHandle CefBrowserImpl::GetWindowHandle()
{
Lock();
CefWindowHandle handle = window_info_.m_Window;
CefWindowHandle handle = window_info_.m_View;
Unlock();
return handle;
}
gfx::NativeWindow CefBrowserImpl::GetMainWndHandle() const {
return (NSWindow*)window_info_.m_Window;
return (NSWindow*)window_info_.m_View;
}
void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
{
REQUIRE_UIT();
// Create the new browser window
// TODO(port): Add implementation.
// Add a reference that will be released on WM_DESTROY.
// 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);
NSView* parentView = (NSView*)window_info_.m_ParentView;
gfx::Rect contentRect(window_info_.m_x, window_info_.m_y,
window_info_.m_nWidth, window_info_.m_nHeight);
// Create the webview host object
webviewhost_.reset(
WebViewHost::Create([GetMainWndHandle() contentView], delegate_.get(),
NULL, *_Context->web_preferences()));
WebViewHost::Create(parentView, contentRect, delegate_.get(),
NULL, *_Context->web_preferences()));
delegate_->RegisterDragDrop();
// Size the web view window to the browser window
// TODO(port): Add implementation.
BrowserWebView* browserView = (BrowserWebView*)webviewhost_->view_handle();
browserView.browser = this;
window_info_.m_View = (void*)browserView;
if(handler_.get()) {
// Notify the handler that we're done creating the new window
@@ -68,8 +71,13 @@ void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable)
REQUIRE_UIT();
if (!host)
return;
NSView* view = host->view_handle();
if (!view)
return;
// TODO(port): Add implementation.
if (enable)
[[view window] makeFirstResponder:view];
}
WebKit::WebWidget* CefBrowserImpl::UIT_CreatePopupWidget()

View File

@@ -46,26 +46,12 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
break;
case WM_DESTROY:
if (browser)
{
CefRefPtr<CefHandler> handler = browser->GetHandler();
if(handler.get()) {
// Notify the handler that the window is about to be closed
handler->HandleBeforeWindowClose(browser);
}
browser->GetWebViewDelegate()->RevokeDragDrop();
// Clean up anything associated with the WebViewHost widget.
browser->GetWebViewHost()->webwidget()->close();
browser->webviewhost_.reset();
if (browser) {
// Clear the user data pointer.
win_util::SetWindowUserData(hwnd, NULL);
// Remove the reference added in UIT_CreateBrowser().
browser->Release();
// Remove the browser from the list maintained by the context
_Context->RemoveBrowser(browser);
// Destroy the browser.
browser->UIT_DestroyBrowser();
}
return 0;
@@ -123,7 +109,8 @@ void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
// Set window user data to this object for future reference from the window
// procedure
win_util::SetWindowUserData(window_info_.m_hWnd, this);
// Add a reference that will be released on WM_DESTROY.
// Add a reference that will be released in UIT_DestroyBrowser().
AddRef();
// Add the new browser to the list maintained by the context
@@ -131,8 +118,8 @@ void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
// Create the webview host object
webviewhost_.reset(
WebViewHost::Create(window_info_.m_hWnd, delegate_.get(), NULL,
*_Context->web_preferences()));
WebViewHost::Create(window_info_.m_hWnd, gfx::Rect(), delegate_.get(),
NULL, *_Context->web_preferences()));
delegate_->RegisterDragDrop();
// Size the web view window to the browser window

View File

@@ -26,6 +26,10 @@ void CaptureWebViewBitmap(HWND mainWnd, WebKit::WebView* webview,
// Save a bitmap image to file, providing optional alternative data in |lpBits|
BOOL SaveBitmapToFile(HBITMAP hBmp, HDC hDC, LPCTSTR file, LPBYTE lpBits);
#endif
#if defined(OS_MACOSX)
void InitializeDataPak();
#endif
// Text encoding objects must be initialized on the main thread.
void InitializeTextEncoding();

View File

@@ -24,6 +24,17 @@ namespace webkit_glue {
// Data pack resource. This is a pointer to the mmapped resources file.
static base::DataPack* g_resource_data_pack = NULL;
void InitializeDataPak() {
// mmap the data pack which holds strings used by WebCore.
// TODO(port): Allow the embedder to customize the pak name.
g_resource_data_pack = new base::DataPack;
NSString *resource_path =
[mac_util::MainAppBundle() pathForResource:@"cefclient" ofType:@"pak"];
FilePath resources_pak_path([resource_path fileSystemRepresentation]);
if (!g_resource_data_pack->Load(resources_pak_path))
LOG(FATAL) << "failed to load cefclient.pak";
}
// Helper method for getting the path to the CEF resources directory.
FilePath GetResourcesFilePath() {
FilePath path;
@@ -33,10 +44,13 @@ FilePath GetResourcesFilePath() {
path = path.Append(FilePath::kParentDirectory);
return path.AppendASCII("Resources");
} else {
// TODO(port): Allow the embedder to customize the resource path.
PathService::Get(base::DIR_SOURCE_ROOT, &path);
path = path.AppendASCII("src");
path = path.AppendASCII("cef");
return path.AppendASCII("resources");
path = path.AppendASCII("tests");
path = path.AppendASCII("cefclient");
return path.AppendASCII("res");
}
}

View File

@@ -198,13 +198,14 @@ void BrowserWebViewDelegate::DidMovePlugin(
void BrowserWebViewDelegate::ShowJavaScriptAlert(
WebKit::WebFrame* webframe, const std::wstring& message) {
NSString *text =
[NSString stringWithUTF8String:WideToUTF8(message).c_str()];
[NSString stringWithUTF8String:WideToUTF8(message).c_str()];
NSAlert *alert = [NSAlert alertWithMessageText:@"JavaScript Alert"
defaultButton:@"OK"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:text];
[alert runModal];
[text release];
}
bool BrowserWebViewDelegate::ShowJavaScriptConfirm(

View File

@@ -15,12 +15,6 @@ class CefBrowserImpl;
NSTrackingArea *trackingArea_;
}
- (IBAction)goBack:(id)sender;
- (IBAction)goForward:(id)sender;
- (IBAction)reload:(id)sender;
- (IBAction)stopLoading:(id)sender;
- (IBAction)takeURLStringValueFrom:(NSTextField *)sender;
- (void)mouseDown:(NSEvent *)theEvent;
- (void)rightMouseDown:(NSEvent *)theEvent;
- (void)otherMouseDown:(NSEvent *)theEvent;
@@ -38,7 +32,6 @@ class CefBrowserImpl;
- (void)keyUp:(NSEvent *)theEvent;
- (BOOL)isOpaque;
- (void)setFrame:(NSRect)frameRect;
- (void)setIsActive:(BOOL)active;
@property (nonatomic, assign) CefBrowserImpl *browser;

View File

@@ -7,6 +7,7 @@
#import <Cocoa/Cocoa.h>
#include "browser_impl.h"
#include "cef_context.h"
#include "webwidget_host.h"
#include "base/scoped_ptr.h"
@@ -35,9 +36,11 @@
}
- (void) dealloc {
browser_->UIT_DestroyBrowser();
[self removeTrackingArea:trackingArea_];
[trackingArea_ release];
[super dealloc];
}
@@ -61,37 +64,6 @@
}
}
- (IBAction)goBack:(id)sender {
if (browser_)
browser_->UIT_GoBackOrForward(-1);
}
- (IBAction)goForward:(id)sender {
if (browser_)
browser_->UIT_GoBackOrForward(1);
}
- (IBAction)reload:(id)sender {
if (browser_)
browser_->UIT_Reload(false);
}
- (IBAction)stopLoading:(id)sender {
if (browser_ && browser_->GetWebView())
browser_->GetWebView()->mainFrame()->stopLoading();
}
- (IBAction)takeURLStringValueFrom:(NSTextField *)sender {
NSString *url = [sender stringValue];
// if it doesn't already have a prefix, add http. If we can't parse it,
// just don't bother rather than making things worse.
NSURL* tempUrl = [NSURL URLWithString:url];
if (tempUrl && ![tempUrl scheme])
url = [@"http://" stringByAppendingString:url];
browser_->LoadURL(browser_->GetMainFrame(), UTF8ToWide([url UTF8String]));
}
- (void)mouseDown:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
@@ -197,11 +169,6 @@
return NO;
}
- (void)setIsActive:(BOOL)active {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->SetIsActive(active ? true : false);
}
- (void)setFrame:(NSRect)frameRect {
[super setFrame:frameRect];
if (browser_ && browser_->GetWebView())

View File

@@ -4,9 +4,6 @@
// found in the LICENSE file.
#include "cef_process_ui_thread.h"
#include "browser_impl.h"
#include "browser_resource_loader_bridge.h"
#include "browser_request_context.h"
#include "browser_webkit_glue.h"
#include "browser_webkit_init.h"
#include "cef_context.h"
@@ -66,38 +63,7 @@ CefProcessUIThread::~CefProcessUIThread() {
}
void CefProcessUIThread::Init() {
#if defined(OS_WIN)
HRESULT res;
// Initialize common controls
res = CoInitialize(NULL);
DCHECK(SUCCEEDED(res));
INITCOMMONCONTROLSEX InitCtrlEx;
InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCtrlEx.dwICC = ICC_STANDARD_CLASSES;
InitCommonControlsEx(&InitCtrlEx);
// Start COM stuff
res = OleInitialize(NULL);
DCHECK(SUCCEEDED(res));
// Register the window class
WNDCLASSEX wcex = {
/* cbSize = */ sizeof(WNDCLASSEX),
/* style = */ CS_HREDRAW | CS_VREDRAW,
/* lpfnWndProc = */ CefBrowserImpl::WndProc,
/* cbClsExtra = */ 0,
/* cbWndExtra = */ 0,
/* hInstance = */ ::GetModuleHandle(NULL),
/* hIcon = */ NULL,
/* hCursor = */ LoadCursor(NULL, IDC_ARROW),
/* hbrBackground = */ 0,
/* lpszMenuName = */ NULL,
/* lpszClassName = */ CefBrowserImpl::GetWndClass(),
/* hIconSm = */ NULL,
};
RegisterClassEx(&wcex);
#endif
PlatformInit();
#ifndef _DEBUG
// Only log error messages and above in release build.
@@ -167,12 +133,5 @@ void CefProcessUIThread::CleanUp() {
delete webkit_init_;
webkit_init_ = NULL;
#if defined(OS_WIN)
// Uninitialize COM stuff
OleUninitialize();
// Closes the COM library on the current thread. CoInitialize must
// be balanced by a corresponding call to CoUninitialize.
CoUninitialize();
#endif
PlatformCleanUp();
}

View File

@@ -33,6 +33,9 @@ class CefProcessUIThread : public CefThread {
virtual void CleanUp();
private:
void PlatformInit();
void PlatformCleanUp();
base::StatsTable* statstable_;
// WebKit implementation class.

View File

@@ -0,0 +1,51 @@
// Copyright (c) 2010 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2010 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 "include/cef.h"
#include "cef_process_ui_thread.h"
#include "browser_webkit_glue.h"
#include "base/chrome_application_mac.h"
#include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h"
namespace {
// Memory autorelease pool.
NSAutoreleasePool* g_autopool;
void RunLoopObserver(CFRunLoopObserverRef observer, CFRunLoopActivity activity,
void* info)
{
CefDoMessageLoopWork();
}
} // namespace
void CefProcessUIThread::PlatformInit() {
// Initialize the CrApplication instance.
[CrApplication sharedApplication];
g_autopool = [[NSAutoreleasePool alloc] init];
InitWebCoreSystemInterface();
// Register the run loop observer.
CFRunLoopObserverRef observer =
CFRunLoopObserverCreate(NULL,
kCFRunLoopBeforeTimers | kCFRunLoopBeforeWaiting,
YES, /* repeat */
0,
&RunLoopObserver,
NULL);
if (observer) {
CFRunLoopAddObserver(CFRunLoopGetCurrent(), observer,
kCFRunLoopCommonModes);
}
webkit_glue::InitializeDataPak();
}
void CefProcessUIThread::PlatformCleanUp() {
[g_autopool release];
}

View File

@@ -0,0 +1,52 @@
// Copyright (c) 2010 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2010 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 "cef_process_ui_thread.h"
#include "browser_impl.h"
#include <commctrl.h>
#include <Objbase.h>
void CefProcessUIThread::PlatformInit() {
HRESULT res;
// Initialize common controls
res = CoInitialize(NULL);
DCHECK(SUCCEEDED(res));
INITCOMMONCONTROLSEX InitCtrlEx;
InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCtrlEx.dwICC = ICC_STANDARD_CLASSES;
InitCommonControlsEx(&InitCtrlEx);
// Start COM stuff
res = OleInitialize(NULL);
DCHECK(SUCCEEDED(res));
// Register the window class
WNDCLASSEX wcex = {
/* cbSize = */ sizeof(WNDCLASSEX),
/* style = */ CS_HREDRAW | CS_VREDRAW,
/* lpfnWndProc = */ CefBrowserImpl::WndProc,
/* cbClsExtra = */ 0,
/* cbWndExtra = */ 0,
/* hInstance = */ ::GetModuleHandle(NULL),
/* hIcon = */ NULL,
/* hCursor = */ LoadCursor(NULL, IDC_ARROW),
/* hbrBackground = */ 0,
/* lpszMenuName = */ NULL,
/* lpszClassName = */ CefBrowserImpl::GetWndClass(),
/* hIconSm = */ NULL,
};
RegisterClassEx(&wcex);
}
void CefProcessUIThread::PlatformCleanUp() {
// Uninitialize COM stuff
OleUninitialize();
// Closes the COM library on the current thread. CoInitialize must
// be balanced by a corresponding call to CoUninitialize.
CoUninitialize();
}

View File

@@ -58,16 +58,19 @@ static void TrackDestructor(v8::Persistent<v8::Value> object,
// Convert a wide string to a V8 string.
static v8::Handle<v8::String> GetV8String(const std::wstring& str)
{
return v8::String::New(
reinterpret_cast<const uint16_t*>(str.c_str()), str.length());
std::string tmpStr = WideToUTF8(str);
return v8::String::New(tmpStr.c_str(), tmpStr.length());
}
// Convert a V8 string to a wide string.
static std::wstring GetWString(v8::Handle<v8::String> str)
{
uint16_t* buf = new uint16_t[str->Length()+1];
str->Write(buf);
std::wstring value = reinterpret_cast<wchar_t*>(buf);
// Allocate enough space for a worst-case conversion.
size_t len = str->Length()*4;
char* buf = new char[len];
int newlen = str->WriteUtf8(buf, len);
std::wstring value;
UTF8ToWide(buf, newlen, &value);
delete [] buf;
return value;
}

View File

@@ -6,7 +6,6 @@
#define _WEBVIEW_HOST_H
#include "base/basictypes.h"
#include "gfx/rect.h"
#include "gfx/native_widget_types.h"
#include "webwidget_host.h"
@@ -29,6 +28,7 @@ class WebViewHost : public WebWidgetHost {
// The newly created window should be resized after it is created, using the
// MoveWindow (or equivalent) function.
static WebViewHost* Create(gfx::NativeView parent_view,
const gfx::Rect& rect,
BrowserWebViewDelegate* delegate,
WebKit::WebDevToolsAgentClient* devtools_client,
const WebPreferences& prefs);

View File

@@ -21,17 +21,13 @@ using WebKit::WebView;
// static
WebViewHost* WebViewHost::Create(NSView* parent_view,
const gfx::Rect& rect,
BrowserWebViewDelegate* delegate,
WebDevToolsAgentClient* dev_tools_client,
const WebPreferences& prefs) {
WebViewHost* host = new WebViewHost();
NSRect content_rect = [parent_view frame];
// bump down the top of the view so that it doesn't overlap the buttons
// and URL field. 32 is an ad hoc constant.
// TODO(awalker): replace explicit view layout with a little nib file
// and use that for view geometry.
content_rect.size.height -= 32;
NSRect content_rect = {{rect.x(), rect.y()}, {rect.width(), rect.height()}};
host->view_ = [[BrowserWebView alloc] initWithFrame:content_rect];
// make the height and width track the window size.
[host->view_ setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];

View File

@@ -17,6 +17,7 @@ static const wchar_t kWindowClassName[] = L"WebViewHost";
/*static*/
WebViewHost* WebViewHost::Create(HWND parent_view,
const gfx::Rect&,
BrowserWebViewDelegate* delegate,
WebDevToolsAgentClient* dev_tools_client,
const WebPreferences& prefs) {

View File

@@ -14,6 +14,7 @@
#include <string>
namespace gfx {
class Rect;
class Size;
}

View File

@@ -35,13 +35,9 @@ WebWidgetHost* WebWidgetHost::Create(NSView* parent_view,
WebWidgetHost* host = new WebWidgetHost();
NSRect content_rect = [parent_view frame];
content_rect.origin.y += 64;
content_rect.size.height -= 64;
host->view_ = [[NSView alloc] initWithFrame:content_rect];
[parent_view addSubview:host->view_];
// win_util::SetWindowUserData(host->hwnd_, host);
host->webwidget_ = WebPopupMenu::create(client);
host->webwidget_->resize(WebSize(content_rect.size.width,
content_rect.size.height));
@@ -137,9 +133,6 @@ void WebWidgetHost::ScheduleComposite() {
[view_ setNeedsDisplayInRect:r];
}
// void WebWidgetHost::SetCursor(HCURSOR cursor) {
// }
void WebWidgetHost::DiscardBackingStore() {
canvas_.reset();
}
@@ -153,9 +146,6 @@ WebWidgetHost::WebWidgetHost()
}
WebWidgetHost::~WebWidgetHost() {
// win_util::SetWindowUserData(hwnd_, 0);
webwidget_->close();
}
void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) {
@@ -225,7 +215,7 @@ void WebWidgetHost::Paint() {
}
void WebWidgetHost::SetTooltipText(const std::wstring& tooltip_text) {
NOTIMPLEMENTED();
// TODO(port): Implement this method.
}
WebScreenInfo WebWidgetHost::GetScreenInfo() {

View File

@@ -40,13 +40,13 @@ public:
bool VerifyContext();
protected:
PlatformThreadId supported_thread_id_;
unzFile reader_;
bool has_fileopen_;
bool has_fileinfo_;
std::wstring filename_;
long filesize_;
time_t filemodified_;
PlatformThreadId supported_thread_id_;
};
#endif // _ZIP_READER_IMPL_H