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.
|
|
|
|
|
|
|
|
#include "cef_context.h"
|
|
|
|
#include "browser_impl.h"
|
2010-11-15 16:39:56 +01:00
|
|
|
#include "browser_webview_mac.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#include "base/utf_string_conversions.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
|
|
|
|
|
|
|
|
using WebKit::WebRect;
|
|
|
|
using WebKit::WebSize;
|
|
|
|
|
|
|
|
CefWindowHandle CefBrowserImpl::GetWindowHandle()
|
|
|
|
{
|
|
|
|
Lock();
|
2010-11-15 16:39:56 +01:00
|
|
|
CefWindowHandle handle = window_info_.m_View;
|
2010-10-23 19:00:47 +02:00
|
|
|
Unlock();
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::NativeWindow CefBrowserImpl::GetMainWndHandle() const {
|
2010-11-15 16:39:56 +01:00
|
|
|
return (NSWindow*)window_info_.m_View;
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
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);
|
2010-11-15 16:39:56 +01:00
|
|
|
|
|
|
|
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);
|
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(),
|
|
|
|
NULL, *_Context->web_preferences()));
|
2010-10-23 19:00:47 +02:00
|
|
|
delegate_->RegisterDragDrop();
|
2010-11-15 16:39:56 +01:00
|
|
|
|
|
|
|
BrowserWebView* browserView = (BrowserWebView*)webviewhost_->view_handle();
|
|
|
|
browserView.browser = this;
|
|
|
|
window_info_.m_View = (void*)browserView;
|
2010-10-23 19:00:47 +02:00
|
|
|
|
|
|
|
if(handler_.get()) {
|
|
|
|
// Notify the handler that we're done creating the new window
|
|
|
|
handler_->HandleAfterCreated(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(url.size() > 0) {
|
|
|
|
CefRefPtr<CefFrame> frame = GetMainFrame();
|
|
|
|
frame->AddRef();
|
|
|
|
UIT_LoadURL(frame, url.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
if (!host)
|
|
|
|
return;
|
2010-11-15 16:39:56 +01:00
|
|
|
|
|
|
|
NSView* view = host->view_handle();
|
|
|
|
if (!view)
|
|
|
|
return;
|
2010-10-23 19:00:47 +02:00
|
|
|
|
2010-11-15 16:39:56 +01:00
|
|
|
if (enable)
|
|
|
|
[[view window] makeFirstResponder:view];
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WebKit::WebWidget* CefBrowserImpl::UIT_CreatePopupWidget()
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
DCHECK(!popuphost_);
|
|
|
|
popuphost_ = WebWidgetHost::Create(NULL, popup_delegate_.get());
|
|
|
|
|
|
|
|
// TODO(port): Show window.
|
|
|
|
|
|
|
|
return popuphost_->webwidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_ClosePopupWidget()
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
// TODO(port): Close window.
|
|
|
|
popuphost_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserImpl::UIT_ViewDocumentString(WebKit::WebFrame *frame)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
// TODO(port): Add implementation.
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefBrowserImpl::UIT_GetPagesCount(WebKit::WebFrame* frame)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
// TODO(port): Add implementation.
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
return 0;
|
|
|
|
}
|