2009-03-05 02:10:06 +01:00
|
|
|
// Copyright (c) 2009 The Chromium Embedded Framework 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 "../precompiled_libcef.h"
|
|
|
|
#include "cpptoc/browser_cpptoc.h"
|
2009-05-28 02:31:21 +02:00
|
|
|
#include "cpptoc/frame_cpptoc.h"
|
2009-03-05 02:10:06 +01:00
|
|
|
#include "ctocpp/handler_ctocpp.h"
|
|
|
|
|
2009-03-08 03:26:16 +01:00
|
|
|
|
2009-03-05 02:10:06 +01:00
|
|
|
int CEF_CALLBACK browser_can_go_back(cef_browser_t* browser)
|
|
|
|
{
|
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
|
|
|
return 0;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return CefBrowserCppToC::Get(browser)->CanGoBack();
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CEF_CALLBACK browser_go_back(cef_browser_t* browser)
|
|
|
|
{
|
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
|
|
|
return;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefBrowserCppToC::Get(browser)->GoBack();
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int CEF_CALLBACK browser_can_go_forward(cef_browser_t* browser)
|
|
|
|
{
|
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
|
|
|
return 0;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return CefBrowserCppToC::Get(browser)->CanGoForward();
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CEF_CALLBACK browser_go_forward(cef_browser_t* browser)
|
|
|
|
{
|
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
|
|
|
return;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefBrowserCppToC::Get(browser)->GoForward();
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CEF_CALLBACK browser_reload(cef_browser_t* browser)
|
|
|
|
{
|
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
|
|
|
return;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefBrowserCppToC::Get(browser)->Reload();
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CEF_CALLBACK browser_stop_load(cef_browser_t* browser)
|
|
|
|
{
|
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
|
|
|
return;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefBrowserCppToC::Get(browser)->StopLoad();
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
2009-03-08 03:26:16 +01:00
|
|
|
void CEF_CALLBACK browser_set_focus(struct _cef_browser_t* browser, int enable)
|
|
|
|
{
|
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
|
|
|
return;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefBrowserCppToC::Get(browser)->SetFocus(enable ? true : false);
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
cef_window_handle_t CEF_CALLBACK browser_get_window_handle(cef_browser_t* browser)
|
|
|
|
{
|
2009-03-05 02:10:06 +01:00
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
|
|
|
return NULL;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return CefBrowserCppToC::Get(browser)->GetWindowHandle();
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
int CEF_CALLBACK browser_is_popup(cef_browser_t* browser)
|
|
|
|
{
|
2009-03-05 02:10:06 +01:00
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
2009-05-28 02:31:21 +02:00
|
|
|
return 0;
|
2009-03-05 02:10:06 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return CefBrowserCppToC::Get(browser)->IsPopup();
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
cef_handler_t* CEF_CALLBACK browser_get_handler(cef_browser_t* browser)
|
|
|
|
{
|
2009-03-05 02:10:06 +01:00
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
2009-05-28 02:31:21 +02:00
|
|
|
return NULL;
|
2009-03-05 02:10:06 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
|
|
|
|
CefRefPtr<CefHandler> handlerPtr = browserPtr->GetHandler();
|
|
|
|
if(handlerPtr.get())
|
|
|
|
return CefHandlerCToCpp::Unwrap(handlerPtr);
|
2009-03-05 02:10:06 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-03-05 02:10:06 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
struct _cef_frame_t* CEF_CALLBACK browser_get_main_frame(
|
|
|
|
struct _cef_browser_t* browser)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
2009-05-28 02:31:21 +02:00
|
|
|
return NULL;
|
2009-03-05 02:10:06 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
|
|
|
|
CefRefPtr<CefFrame> framePtr = browserPtr->GetMainFrame();
|
|
|
|
if(framePtr.get())
|
|
|
|
return CefFrameCppToC::Wrap(framePtr);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-03-05 02:10:06 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
struct _cef_frame_t* CEF_CALLBACK browser_get_focused_frame(
|
|
|
|
struct _cef_browser_t* browser)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
|
|
|
return NULL;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
|
|
|
|
CefRefPtr<CefFrame> framePtr = browserPtr->GetFocusedFrame();
|
|
|
|
if(framePtr.get())
|
|
|
|
return CefFrameCppToC::Wrap(framePtr);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-03-05 02:10:06 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
struct _cef_frame_t* CEF_CALLBACK browser_get_frame(
|
|
|
|
struct _cef_browser_t* browser, const wchar_t* name)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
|
|
|
DCHECK(browser);
|
|
|
|
if(!browser)
|
|
|
|
return NULL;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
std::wstring nameStr;
|
|
|
|
if(name)
|
|
|
|
nameStr = name;
|
|
|
|
if(nameStr.empty())
|
2009-03-05 02:10:06 +01:00
|
|
|
return NULL;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
|
|
|
|
CefRefPtr<CefFrame> framePtr = browserPtr->GetFrame(nameStr);
|
|
|
|
if(framePtr.get())
|
|
|
|
return CefFrameCppToC::Wrap(framePtr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CEF_CALLBACK browser_get_frame_names(struct _cef_browser_t* browser,
|
|
|
|
cef_string_list_t list)
|
|
|
|
{
|
2009-03-05 02:10:06 +01:00
|
|
|
DCHECK(browser);
|
2009-05-28 02:31:21 +02:00
|
|
|
DCHECK(list);
|
|
|
|
if(!browser || !list)
|
2009-03-05 02:10:06 +01:00
|
|
|
return NULL;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
|
|
|
|
std::vector<std::wstring> stringList;
|
|
|
|
browserPtr->GetFrameNames(stringList);
|
|
|
|
size_t size = stringList.size();
|
|
|
|
for(size_t i = 0; i < size; ++i)
|
|
|
|
cef_string_list_append(list, stringList[i].c_str());
|
|
|
|
return size;
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
2009-03-08 03:26:16 +01:00
|
|
|
CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls)
|
2009-05-28 02:31:21 +02:00
|
|
|
: CefCppToC<CefBrowserCppToC, CefBrowser, cef_browser_t>(cls)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
|
|
|
struct_.struct_.can_go_back = browser_can_go_back;
|
|
|
|
struct_.struct_.go_back = browser_go_back;
|
|
|
|
struct_.struct_.can_go_forward = browser_can_go_forward;
|
|
|
|
struct_.struct_.go_forward = browser_go_forward;
|
|
|
|
struct_.struct_.reload = browser_reload;
|
|
|
|
struct_.struct_.stop_load = browser_stop_load;
|
2009-03-08 03:26:16 +01:00
|
|
|
struct_.struct_.set_focus = browser_set_focus;
|
2009-03-05 02:10:06 +01:00
|
|
|
struct_.struct_.get_window_handle = browser_get_window_handle;
|
|
|
|
struct_.struct_.is_popup = browser_is_popup;
|
2009-05-28 02:31:21 +02:00
|
|
|
struct_.struct_.get_handler = browser_get_handler;
|
|
|
|
struct_.struct_.get_main_frame = browser_get_main_frame;
|
|
|
|
struct_.struct_.get_focused_frame = browser_get_focused_frame;
|
|
|
|
struct_.struct_.get_frame = browser_get_frame;
|
|
|
|
struct_.struct_.get_frame_names = browser_get_frame_names;
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
2009-03-08 03:26:16 +01:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2009-05-28 02:31:21 +02:00
|
|
|
long CefCppToC<CefBrowserCppToC, CefBrowser, cef_browser_t>::DebugObjCt = 0;
|
2009-03-08 03:26:16 +01:00
|
|
|
#endif
|