2010-10-23 19:00:47 +02:00
|
|
|
// Copyright (c) 2010 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.
|
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/cef_context.h"
|
|
|
|
#include "libcef/browser_impl.h"
|
|
|
|
#include "libcef/browser_settings.h"
|
|
|
|
#include "libcef/browser_webview_mac.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"
|
2010-11-18 22:05:25 +01:00
|
|
|
#include "webkit/glue/webpreferences.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
|
|
|
|
using WebKit::WebRect;
|
|
|
|
using WebKit::WebSize;
|
|
|
|
|
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_View;
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefBrowserImpl::IsWindowRenderingDisabled() {
|
2012-05-16 18:56:38 +02:00
|
|
|
return (window_info_.m_bWindowRenderingDisabled ? true : false);
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::NativeView CefBrowserImpl::UIT_GetMainWndHandle() {
|
2011-01-29 02:42:59 +01:00
|
|
|
REQUIRE_UIT();
|
2012-05-16 18:56:38 +02:00
|
|
|
return window_info_.m_bWindowRenderingDisabled ?
|
|
|
|
window_info_.m_ParentView : window_info_.m_View;
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
void CefBrowserImpl::UIT_ClearMainWndHandle() {
|
|
|
|
REQUIRE_UIT();
|
2012-05-16 18:56:38 +02:00
|
|
|
if (!window_info_.m_bWindowRenderingDisabled)
|
|
|
|
window_info_.m_View = NULL;
|
2011-12-30 21:55:16 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefBrowserImpl::UIT_CreateBrowser(const CefString& url) {
|
2010-10-23 19:00:47 +02:00
|
|
|
REQUIRE_UIT();
|
2011-01-29 02:42:59 +01:00
|
|
|
Lock();
|
|
|
|
|
2010-11-15 16:39:56 +01:00
|
|
|
// Add a reference that will be released in UIT_DestroyBrowser().
|
2010-10-23 19:00:47 +02:00
|
|
|
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());
|
|
|
|
|
2011-02-02 03:25:32 +01:00
|
|
|
NSWindow* newWnd = nil;
|
|
|
|
|
2011-02-02 17:30:24 +01:00
|
|
|
NSView* parentView = window_info_.m_ParentView;
|
2010-11-15 16:39:56 +01:00
|
|
|
gfx::Rect contentRect(window_info_.m_x, window_info_.m_y,
|
|
|
|
window_info_.m_nWidth, window_info_.m_nHeight);
|
2012-05-16 18:56:38 +02:00
|
|
|
if (!window_info_.m_bWindowRenderingDisabled) {
|
|
|
|
if (parentView == nil) {
|
|
|
|
// Create a new window.
|
|
|
|
NSRect screen_rect = [[NSScreen mainScreen] visibleFrame];
|
|
|
|
NSRect window_rect = {{window_info_.m_x,
|
|
|
|
screen_rect.size.height - window_info_.m_y},
|
|
|
|
{window_info_.m_nWidth, window_info_.m_nHeight}};
|
|
|
|
if (window_rect.size.width == 0)
|
|
|
|
window_rect.size.width = 750;
|
|
|
|
if (window_rect.size.height == 0)
|
|
|
|
window_rect.size.height = 750;
|
|
|
|
contentRect.SetRect(0, 0, window_rect.size.width,
|
|
|
|
window_rect.size.height);
|
|
|
|
|
|
|
|
newWnd = [[NSWindow alloc]
|
|
|
|
initWithContentRect:window_rect
|
|
|
|
styleMask:(NSTitledWindowMask |
|
|
|
|
NSClosableWindowMask |
|
|
|
|
NSMiniaturizableWindowMask |
|
|
|
|
NSResizableWindowMask |
|
|
|
|
NSUnifiedTitleAndToolbarWindowMask )
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:NO];
|
|
|
|
parentView = [newWnd contentView];
|
|
|
|
window_info_.m_ParentView = parentView;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Create a new paint delegate.
|
|
|
|
paint_delegate_.reset(new PaintDelegate(this));
|
2011-02-02 03:25:32 +01:00
|
|
|
}
|
2010-10-23 19:00:47 +02:00
|
|
|
|
2012-05-23 21:01:04 +02:00
|
|
|
webkit_glue::WebPreferences prefs;
|
2010-11-18 22:05:25 +01:00
|
|
|
BrowserToWebSettings(settings_, prefs);
|
|
|
|
|
2010-10-23 19:00:47 +02:00
|
|
|
// Create the webview host object
|
|
|
|
webviewhost_.reset(
|
2010-11-15 16:39:56 +01:00
|
|
|
WebViewHost::Create(parentView, contentRect, delegate_.get(),
|
2012-05-16 18:56:38 +02:00
|
|
|
paint_delegate_.get(), dev_tools_agent_.get(),
|
|
|
|
prefs));
|
|
|
|
|
|
|
|
if (window_info_.m_bTransparentPainting)
|
|
|
|
webviewhost_->webview()->setIsTransparent(true);
|
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);
|
|
|
|
|
2010-11-15 16:39:56 +01:00
|
|
|
BrowserWebView* browserView = (BrowserWebView*)webviewhost_->view_handle();
|
|
|
|
browserView.browser = this;
|
2011-02-02 17:30:24 +01:00
|
|
|
window_info_.m_View = browserView;
|
2011-01-29 02:42:59 +01:00
|
|
|
|
2012-05-16 18:56:38 +02:00
|
|
|
if (!window_info_.m_bWindowRenderingDisabled) {
|
|
|
|
if (!settings_.drag_drop_disabled)
|
|
|
|
[browserView registerDragDrop];
|
|
|
|
}
|
2011-08-02 19:30:11 +02:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
Unlock();
|
|
|
|
|
2011-03-08 04:54:50 +01:00
|
|
|
if (newWnd != nil && !window_info_.m_bHidden) {
|
2011-02-02 03:25:32 +01:00
|
|
|
// Show the window.
|
|
|
|
[newWnd makeKeyAndOrderFront: nil];
|
|
|
|
}
|
|
|
|
|
2011-05-21 01:39:33 +02:00
|
|
|
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);
|
|
|
|
}
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
2011-01-29 23:52:34 +01:00
|
|
|
if(url.size() > 0)
|
|
|
|
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) {
|
2010-10-23 19:00:47 +02:00
|
|
|
REQUIRE_UIT();
|
|
|
|
if (!host)
|
|
|
|
return;
|
2011-02-15 19:07:24 +01:00
|
|
|
|
2012-04-02 21:05:42 +02:00
|
|
|
BrowserWebView* browserView = (BrowserWebView*)host->view_handle();
|
|
|
|
if (!browserView)
|
2010-11-15 16:39:56 +01:00
|
|
|
return;
|
2010-10-23 19:00:47 +02:00
|
|
|
|
2012-04-02 21:05:42 +02:00
|
|
|
if (enable) {
|
|
|
|
// Guard against calling OnSetFocus twice.
|
|
|
|
browserView.in_setfocus = true;
|
|
|
|
[[browserView window] makeFirstResponder:browserView];
|
|
|
|
browserView.in_setfocus = false;
|
|
|
|
}
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
2012-05-16 18:56:38 +02:00
|
|
|
bool CefBrowserImpl::UIT_ViewDocumentString(WebKit::WebFrame* frame) {
|
2010-10-23 19:00:47 +02:00
|
|
|
REQUIRE_UIT();
|
2011-02-15 19:07:24 +01:00
|
|
|
|
2012-05-16 18:56:38 +02:00
|
|
|
char sztmp[L_tmpnam+4];
|
|
|
|
if (tmpnam(sztmp)) {
|
|
|
|
strcat(sztmp, ".txt");
|
|
|
|
|
|
|
|
FILE* fp = fopen(sztmp, "wb");
|
|
|
|
if (fp) {
|
|
|
|
std::string markup = frame->contentAsMarkup().utf8();
|
|
|
|
fwrite(markup.c_str(), 1, markup.size(), fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
char szopen[L_tmpnam + 14];
|
|
|
|
snprintf(szopen, sizeof(szopen), "open -t \"%s\"", sztmp);
|
|
|
|
return (system(szopen) >= 0);
|
|
|
|
}
|
|
|
|
}
|
2010-10-23 19:00:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2010-10-23 19:00:47 +02: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-03-08 04:54:50 +01:00
|
|
|
[[view window] performSelector:@selector(performClose:)
|
|
|
|
withObject:nil
|
|
|
|
afterDelay:0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefBrowserImpl::UIT_IsViewVisible(gfx::NativeView view) {
|
2011-03-08 04:54:50 +01:00
|
|
|
return [[view window] isVisible];
|
2011-02-01 16:37:47 +01:00
|
|
|
}
|