diff --git a/cef.gyp b/cef.gyp index 923480f20..6181c48da 100644 --- a/cef.gyp +++ b/cef.gyp @@ -24,34 +24,21 @@ '..', ], 'sources': [ - 'tests/cefclient/Resource.h', 'tests/cefclient/binding_test.cpp', 'tests/cefclient/binding_test.h', 'tests/cefclient/cefclient.cpp', 'tests/cefclient/cefclient.h', - 'tests/cefclient/cefclient.ico', - 'tests/cefclient/cefclient.rc', - 'tests/cefclient/clientplugin.cpp', - 'tests/cefclient/clientplugin.h', 'tests/cefclient/download_handler.cpp', 'tests/cefclient/download_handler.h', 'tests/cefclient/extension_test.cpp', 'tests/cefclient/extension_test.h', 'tests/cefclient/plugin_test.cpp', 'tests/cefclient/plugin_test.h', - 'tests/cefclient/res/cefclient.ico', - 'tests/cefclient/res/logo.jpg', - 'tests/cefclient/res/logoball.jpg', - 'tests/cefclient/res/small.ico', - 'tests/cefclient/res/uiplugin.html', - 'tests/cefclient/resource_util.cpp', 'tests/cefclient/resource_util.h', 'tests/cefclient/scheme_test.cpp', 'tests/cefclient/scheme_test.h', 'tests/cefclient/string_util.cpp', 'tests/cefclient/string_util.h', - 'tests/cefclient/uiplugin.cpp', - 'tests/cefclient/uiplugin.h', 'tests/cefclient/uiplugin_test.cpp', 'tests/cefclient/uiplugin_test.h', 'tests/cefclient/util.h', @@ -74,6 +61,23 @@ '-lglu32.lib', ], }, + 'sources': [ + 'tests/cefclient/cefclient.ico', + 'tests/cefclient/cefclient.rc', + 'tests/cefclient/cefclient_win.cpp', + 'tests/cefclient/clientplugin.cpp', + 'tests/cefclient/clientplugin.h', + 'tests/cefclient/Resource.h', + 'tests/cefclient/res/cefclient.ico', + 'tests/cefclient/res/logo.jpg', + 'tests/cefclient/res/logoball.jpg', + 'tests/cefclient/res/small.ico', + 'tests/cefclient/res/uiplugin.html', + 'tests/cefclient/resource_util_win.cpp', + 'tests/cefclient/string_util_win.cpp', + 'tests/cefclient/uiplugin.cpp', + 'tests/cefclient/uiplugin.h', + ], }], ], }, diff --git a/tests/cefclient/binding_test.h b/tests/cefclient/binding_test.h index 65162466b..57cbf6510 100644 --- a/tests/cefclient/binding_test.h +++ b/tests/cefclient/binding_test.h @@ -2,7 +2,9 @@ // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. -#pragma once +#ifndef _CEFCLIENT_BINDING_TEST_H +#define _CEFCLIENT_BINDING_TEST_H + #include "include/cef.h" // Add the V8 bindings. @@ -12,3 +14,5 @@ void InitBindingTest(CefRefPtr browser, // Run the test. void RunBindingTest(CefRefPtr browser); + +#endif // _CEFCLIENT_BINDING_TEST_H diff --git a/tests/cefclient/cefclient.cpp b/tests/cefclient/cefclient.cpp index c968dcc82..de75b327a 100644 --- a/tests/cefclient/cefclient.cpp +++ b/tests/cefclient/cefclient.cpp @@ -7,760 +7,248 @@ #include "cefclient.h" #include "binding_test.h" #include "download_handler.h" -#include "extension_test.h" -#include "plugin_test.h" -#include "resource_util.h" -#include "scheme_test.h" #include "string_util.h" -#include "uiplugin_test.h" #include "util.h" #include -#include +#include -#define MAX_LOADSTRING 100 -#define MAX_URL_LENGTH 255 -#define BUTTON_WIDTH 72 -#define URLBAR_HEIGHT 24 -// Define this value to run CEF with messages processed using the current -// application's message loop. -#define TEST_SINGLE_THREADED_MESSAGE_LOOP +// ClientHandler::ClientDownloadListener implementation -// Global Variables: -HINSTANCE hInst; // current instance -TCHAR szTitle[MAX_LOADSTRING]; // The title bar text -TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name -TCHAR szWorkingDir[MAX_PATH]; // The current working directory -UINT uFindMsg; // Message identifier for find events. -HWND hFindDlg = NULL; // Handle for the find dialog. - -// Forward declarations of functions included in this code module: -ATOM MyRegisterClass(HINSTANCE hInstance); -BOOL InitInstance(HINSTANCE, int); -LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); -INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); - -#ifdef _WIN32 -// Add Common Controls to the application manifest because it's required to -// support the default tooltip implementation. -#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") -#endif - -// Program entry point function. -int APIENTRY wWinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPTSTR lpCmdLine, - int nCmdShow) +void ClientHandler::ClientDownloadListener::NotifyDownloadComplete( + const std::wstring& fileName) { - UNREFERENCED_PARAMETER(hPrevInstance); - UNREFERENCED_PARAMETER(lpCmdLine); + handler_->SetLastDownloadFile(fileName); + handler_->SendNotification(NOTIFY_DOWNLOAD_COMPLETE); +} - // Retrieve the current working directory. - if(_wgetcwd(szWorkingDir, MAX_PATH) == NULL) - szWorkingDir[0] = 0; +void ClientHandler::ClientDownloadListener::NotifyDownloadError( + const std::wstring& fileName) +{ + handler_->SetLastDownloadFile(fileName); + handler_->SendNotification(NOTIFY_DOWNLOAD_ERROR); +} -#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP - // Initialize the CEF with messages processed using the current application's - // message loop. - CefInitialize(false, std::wstring()); -#else - // Initialize the CEF with messages processed using a separate UI thread. - CefInitialize(true, std::wstring()); -#endif - // Register the internal client plugin. - InitPluginTest(); +// ClientHandler implementation - // Register the internal UI client plugin. - InitUIPluginTest(); +ClientHandler::ClientHandler() + : m_MainHwnd(NULL), m_BrowserHwnd(NULL), m_EditHwnd(NULL), m_bLoading(false), + m_bCanGoBack(false), m_bCanGoForward(false), + ALLOW_THIS_IN_INITIALIZER_LIST( + m_DownloadListener(new ClientDownloadListener(this))) +{ +} - // Register the V8 extension handler. - InitExtensionTest(); +ClientHandler::~ClientHandler() +{ +} - // Register the scheme handler. - InitSchemeTest(); - - MSG msg; - HACCEL hAccelTable; - - // Initialize global strings - LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); - LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING); - MyRegisterClass(hInstance); - - // Perform application initialization - if (!InitInstance (hInstance, nCmdShow)) +CefHandler::RetVal ClientHandler::HandleAfterCreated( + CefRefPtr browser) +{ + Lock(); + if(!browser->IsPopup()) { - return FALSE; + // We need to keep the main child window, but not popup windows + m_Browser = browser; + m_BrowserHwnd = browser->GetWindowHandle(); } - - hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT)); - - // Register the find event message. - uFindMsg = RegisterWindowMessage(FINDMSGSTRING); - - // Main message loop - while (GetMessage(&msg, NULL, 0, 0)) - { -#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP - // Allow the CEF to do its message loop processing. - CefDoMessageLoopWork(); -#endif - - // Allow processing of find dialog messages. - if(hFindDlg && IsDialogMessage(hFindDlg, &msg)) - continue; - - if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - - // Shut down the CEF - CefShutdown(); - - return (int) msg.wParam; + Unlock(); + return RV_CONTINUE; } -// -// FUNCTION: MyRegisterClass() -// -// PURPOSE: Registers the window class. -// -// COMMENTS: -// -// This function and its usage are only necessary if you want this code -// to be compatible with Win32 systems prior to the 'RegisterClassEx' -// function that was added to Windows 95. It is important to call this -// function so that the application will get 'well formed' small icons -// associated with it. -// -ATOM MyRegisterClass(HINSTANCE hInstance) +CefHandler::RetVal ClientHandler::HandleLoadStart(CefRefPtr browser, + CefRefPtr frame) { - WNDCLASSEX wcex; - - wcex.cbSize = sizeof(WNDCLASSEX); - - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = WndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CEFCLIENT)); - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wcex.lpszMenuName = MAKEINTRESOURCE(IDC_CEFCLIENT); - wcex.lpszClassName = szWindowClass; - wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); - - return RegisterClassEx(&wcex); -} - -// -// FUNCTION: InitInstance(HINSTANCE, int) -// -// PURPOSE: Saves instance handle and creates main window -// -// COMMENTS: -// -// In this function, we save the instance handle in a global variable and -// create and display the main program window. -// -BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) -{ - HWND hWnd; - - hInst = hInstance; // Store instance handle in our global variable - - hWnd = CreateWindow(szWindowClass, szTitle, - WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, 0, CW_USEDEFAULT, - 0, NULL, NULL, hInstance, NULL); - - if (!hWnd) - { - return FALSE; - } - - ShowWindow(hWnd, nCmdShow); - UpdateWindow(hWnd); - - return TRUE; -} - - -// Client implementation of the browser handler class -class ClientHandler : public CefThreadSafeBase -{ -public: - // Implements the DownloadListener interface. - class ClientDownloadListener : public CefThreadSafeBase + if(!browser->IsPopup() && !frame.get()) { - public: - ClientDownloadListener(ClientHandler* handler) : handler_(handler) {} - - // Called when the download is complete. - virtual void NotifyDownloadComplete(const std::wstring& fileName) - { - handler_->SetLastDownloadFile(fileName); - PostMessage(handler_->GetMainHwnd(), WM_COMMAND, - ID_WARN_DOWNLOADCOMPLETE, 0); - } - - // Called if the download fails. - virtual void NotifyDownloadError(const std::wstring& fileName) - { - handler_->SetLastDownloadFile(fileName); - PostMessage(handler_->GetMainHwnd(), WM_COMMAND, - ID_WARN_DOWNLOADERROR, 0); - } - - private: - ClientHandler* handler_; - }; - - ClientHandler() - : ALLOW_THIS_IN_INITIALIZER_LIST( - m_DownloadListener(new ClientDownloadListener(this))) - { - m_MainHwnd = NULL; - m_BrowserHwnd = NULL; - m_EditHwnd = NULL; - m_bLoading = false; + Lock(); + // We've just started loading a page + m_bLoading = true; m_bCanGoBack = false; m_bCanGoForward = false; - } - - ~ClientHandler() - { - } - - // Event called before a new window is created. The |parentBrowser| parameter - // will point to the parent browser window, if any. The |popup| parameter - // will be true if the new window is a popup window. If you create the window - // yourself you should populate the window handle member of |createInfo| and - // return RV_HANDLED. Otherwise, return RV_CONTINUE and the framework will - // create the window. By default, a newly created window will recieve the - // same handler as the parent window. To change the handler for the new - // window modify the object that |handler| points to. - virtual RetVal HandleBeforeCreated(CefRefPtr parentBrowser, - CefWindowInfo& createInfo, bool popup, - CefRefPtr& handler, - std::wstring& url) - { - return RV_CONTINUE; - } - - // Event called after a new window is created. The return value is currently - // ignored. - virtual RetVal HandleAfterCreated(CefRefPtr browser) - { - Lock(); - if(!browser->IsPopup()) - { - // We need to keep the main child window, but not popup windows - m_Browser = browser; - m_BrowserHwnd = browser->GetWindowHandle(); - } - Unlock(); - return RV_CONTINUE; - } - - // Event called when the address bar changes. The return value is currently - // ignored. - virtual RetVal HandleAddressChange(CefRefPtr browser, - CefRefPtr frame, - const std::wstring& url) - { - if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) - { - // Set the edit window text - SetWindowText(m_EditHwnd, url.c_str()); - } - return RV_CONTINUE; - } - - // Event called when the page title changes. The return value is currently - // ignored. - virtual RetVal HandleTitleChange(CefRefPtr browser, - const std::wstring& title) - { - // Set the frame window title bar - HWND hwnd = browser->GetWindowHandle(); - if(!browser->IsPopup()) - { - // The frame window will be the parent of the browser window - hwnd = GetParent(hwnd); - } - SetWindowText(hwnd, title.c_str()); - return RV_CONTINUE; - } - - // Event called before browser navigation. The client has an opportunity to - // modify the |request| object if desired. Return RV_HANDLED to cancel - // navigation. - virtual RetVal HandleBeforeBrowse(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request, - NavType navType, bool isRedirect) - { - return RV_CONTINUE; - } - - // Event called when the browser begins loading a page. The |frame| pointer - // will be empty if the event represents the overall load status and not the - // load status for a particular frame. The return value is currently ignored. - virtual RetVal HandleLoadStart(CefRefPtr browser, - CefRefPtr frame) - { - if(!browser->IsPopup() && !frame.get()) - { - Lock(); - // We've just started loading a page - m_bLoading = true; - m_bCanGoBack = false; - m_bCanGoForward = false; - Unlock(); - } - return RV_CONTINUE; - } - - // Event called when the browser is done loading a page. The |frame| pointer - // will be empty if the event represents the overall load status and not the - // load status for a particular frame. This event will be generated - // irrespective of whether the request completes successfully. The return - // value is currently ignored. - virtual RetVal HandleLoadEnd(CefRefPtr browser, - CefRefPtr frame) - { - if(!browser->IsPopup() && !frame.get()) - { - Lock(); - // We've just finished loading a page - m_bLoading = false; - m_bCanGoBack = browser->CanGoBack(); - m_bCanGoForward = browser->CanGoForward(); - Unlock(); - } - return RV_CONTINUE; - } - - // Called when the browser fails to load a resource. |errorCode| is the - // error code number and |failedUrl| is the URL that failed to load. To - // provide custom error text assign the text to |errorText| and return - // RV_HANDLED. Otherwise, return RV_CONTINUE for the default error text. - virtual RetVal HandleLoadError(CefRefPtr browser, - CefRefPtr frame, - ErrorCode errorCode, - const std::wstring& failedUrl, - std::wstring& errorText) - { - if(errorCode == ERR_CACHE_MISS) - { - // Usually caused by navigating to a page with POST data via back or - // forward buttons. - errorText = L"Expired Form Data" - L"

Expired Form Data

" - L"

Your form request has expired. " - L"Click reload to re-submit the form data.

" - L""; - } - else - { - // All other messages. - std::wstringstream ss; - ss << L"Load Failed" - L"

Load Failed

" - L"

Load of URL " << failedUrl << - L"failed with error code " << static_cast(errorCode) << - L".

" - L""; - errorText = ss.str(); - } - return RV_HANDLED; - } - - // Event called before a resource is loaded. To allow the resource to load - // normally return RV_CONTINUE. To redirect the resource to a new url - // populate the |redirectUrl| value and return RV_CONTINUE. To specify - // data for the resource return a CefStream object in |resourceStream|, set - // 'mimeType| to the resource stream's mime type, and return RV_CONTINUE. - // To cancel loading of the resource return RV_HANDLED. - virtual RetVal HandleBeforeResourceLoad(CefRefPtr browser, - CefRefPtr request, - std::wstring& redirectUrl, - CefRefPtr& resourceStream, - std::wstring& mimeType, - int loadFlags) - { - DWORD dwSize; - LPBYTE pBytes; - - std::wstring url = request->GetURL(); - if(url == L"http://tests/request") { - // Show the request contents - std::wstring dump; - DumpRequestContents(request, dump); - resourceStream = CefStreamReader::CreateForData( - (void*)dump.c_str(), dump.size() * sizeof(wchar_t)); - mimeType = L"text/plain"; - } else if(url == L"http://tests/uiapp") { - // Show the uiapp contents - if(LoadBinaryResource(IDS_UIPLUGIN, dwSize, pBytes)) { - resourceStream = CefStreamReader::CreateForHandler( - new CefByteReadHandler(pBytes, dwSize, NULL)); - mimeType = L"text/html"; - } - } else if(wcsstr(url.c_str(), L"/ps_logo2.png") != NULL) { - // Any time we find "ps_logo2.png" in the URL substitute in our own image - if(LoadBinaryResource(IDS_LOGO, dwSize, pBytes)) { - resourceStream = CefStreamReader::CreateForHandler( - new CefByteReadHandler(pBytes, dwSize, NULL)); - mimeType = L"image/png"; - } - } else if(wcsstr(url.c_str(), L"/logoball.png") != NULL) { - // Load the "logoball.png" image resource. - if(LoadBinaryResource(IDS_LOGOBALL, dwSize, pBytes)) { - resourceStream = CefStreamReader::CreateForHandler( - new CefByteReadHandler(pBytes, dwSize, NULL)); - mimeType = L"image/png"; - } - } - return RV_CONTINUE; - } - - // Called when a server indicates via the 'Content-Disposition' header that a - // response represents a file to download. |mime_type| is the mime type for - // the download, |file_name| is the suggested target file name and - // |content_length| is either the value of the 'Content-Size' header or -1 if - // no size was provided. Set |handler| to the CefDownloadHandler instance that - // will recieve the file contents. Return RV_CONTINUE to download the file - // or RV_HANDLED to cancel the file download. - /*--cef()--*/ - virtual RetVal HandleDownloadResponse(CefRefPtr browser, - const std::wstring& mimeType, - const std::wstring& fileName, - int64 contentLength, - CefRefPtr& handler) - { - // Create the handler for the file download. - handler = CreateDownloadHandler(m_DownloadListener, fileName); - return RV_CONTINUE; - } - - // Event called before a context menu is displayed. To cancel display of the - // default context menu return RV_HANDLED. - virtual RetVal HandleBeforeMenu(CefRefPtr browser, - const MenuInfo& menuInfo) - { - return RV_CONTINUE; - } - - // Event called to optionally override the default text for a context menu - // item. |label| contains the default text and may be modified to substitute - // alternate text. The return value is currently ignored. - virtual RetVal HandleGetMenuLabel(CefRefPtr browser, - MenuId menuId, std::wstring& label) - { - return RV_CONTINUE; - } - - // Event called when an option is selected from the default context menu. - // Return RV_HANDLED to cancel default handling of the action. - virtual RetVal HandleMenuAction(CefRefPtr browser, - MenuId menuId) - { - return RV_CONTINUE; - } - - // Event called to allow customization of standard print options before the - // print dialog is displayed. |printOptions| allows specification of paper - // size, orientation and margins. Note that the specified margins may be - // adjusted if they are outside the range supported by the printer. All units - // are in inches. Return RV_CONTINUE to display the default print options or - // RV_HANDLED to display the modified |printOptions|. - virtual RetVal HandlePrintOptions(CefRefPtr browser, - CefPrintOptions& printOptions) - { - return RV_CONTINUE; - } - - // Event called to format print headers and footers. |printInfo| contains - // platform-specific information about the printer context. |url| is the - // URL if the currently printing page, |title| is the title of the currently - // printing page, |currentPage| is the current page number and |maxPages| is - // the total number of pages. Six default header locations are provided - // by the implementation: top left, top center, top right, bottom left, - // bottom center and bottom right. To use one of these default locations - // just assign a string to the appropriate variable. To draw the header - // and footer yourself return RV_HANDLED. Otherwise, populate the approprate - // variables and return RV_CONTINUE. - virtual RetVal HandlePrintHeaderFooter(CefRefPtr browser, - CefRefPtr frame, - CefPrintInfo& printInfo, - const std::wstring& url, - const std::wstring& title, - int currentPage, int maxPages, - std::wstring& topLeft, - std::wstring& topCenter, - std::wstring& topRight, - std::wstring& bottomLeft, - std::wstring& bottomCenter, - std::wstring& bottomRight) - { - // Place the page title at top left - topLeft = title; - // Place the page URL at top right - topRight = url; - - // Place "Page X of Y" at bottom center - std::wstringstream strstream; - strstream << L"Page " << currentPage << L" of " << maxPages; - bottomCenter = strstream.str(); - - return RV_CONTINUE; - } - - // Run a JS alert message. Return RV_CONTINUE to display the default alert - // or RV_HANDLED if you displayed a custom alert. - virtual RetVal HandleJSAlert(CefRefPtr browser, - CefRefPtr frame, - const std::wstring& message) - { - return RV_CONTINUE; - } - - // Run a JS confirm request. Return RV_CONTINUE to display the default alert - // or RV_HANDLED if you displayed a custom alert. If you handled the alert - // set |retval| to true if the user accepted the confirmation. - virtual RetVal HandleJSConfirm(CefRefPtr browser, - CefRefPtr frame, - const std::wstring& message, bool& retval) - { - return RV_CONTINUE; - } - - // Run a JS prompt request. Return RV_CONTINUE to display the default prompt - // or RV_HANDLED if you displayed a custom prompt. If you handled the prompt - // set |retval| to true if the user accepted the prompt and request and - // |result| to the resulting value. - virtual RetVal HandleJSPrompt(CefRefPtr browser, - CefRefPtr frame, - const std::wstring& message, - const std::wstring& defaultValue, - bool& retval, - std::wstring& result) - { - return RV_CONTINUE; - } - - // Event called for binding to a frame's JavaScript global object. The - // return value is currently ignored. - virtual RetVal HandleJSBinding(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr object) - { - // Add the V8 bindings. - InitBindingTest(browser, frame, object); - - return RV_HANDLED; - } - - // Called just before a window is closed. The return value is currently - // ignored. - virtual RetVal HandleBeforeWindowClose(CefRefPtr browser) - { - if(m_BrowserHwnd == browser->GetWindowHandle()) - { - // Free the browser pointer so that the browser can be destroyed - m_Browser = NULL; - } - return RV_CONTINUE; - } - - // Called when the browser component is about to loose focus. For instance, - // if focus was on the last HTML element and the user pressed the TAB key. - // The return value is currently ignored. - virtual RetVal HandleTakeFocus(CefRefPtr browser, bool reverse) - { - return RV_CONTINUE; - } - - // Called when the browser component is requesting focus. |isWidget| will be - // true if the focus is requested for a child widget of the browser window. - // Return RV_CONTINUE to allow the focus to be set or RV_HANDLED to cancel - // setting the focus. - virtual RetVal HandleSetFocus(CefRefPtr browser, - bool isWidget) - { - return RV_CONTINUE; - } - - // Event called when the browser is about to display a tooltip. |text| - // contains the text that will be displayed in the tooltip. To handle - // the display of the tooltip yourself return RV_HANDLED. Otherwise, - // you can optionally modify |text| and then return RV_CONTINUE to allow - // the browser to display the tooltip. - virtual RetVal HandleTooltip(CefRefPtr browser, - std::wstring& text) - { - return RV_CONTINUE; - } - - // Called when the browser component receives a keyboard event. - // |type| is the type of keyboard event (see |KeyEventType|). - // |code| is the windows scan-code for the event. - // |modifiers| is a set of bit-flags describing any pressed modifier keys. - // |isSystemKey| is set if Windows considers this a 'system key' message; - // (see http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx) - // Return RV_HANDLED if the keyboard event was handled or RV_CONTINUE - // to allow the browser component to handle the event. - RetVal HandleKeyEvent(CefRefPtr browser, - KeyEventType type, - int code, - int modifiers, - bool isSystemKey) - { - return RV_CONTINUE; - } - - // Called to display a console message. Return RV_HANDLED to stop the message - // from being output to the console. - RetVal HandleConsoleMessage(CefRefPtr browser, - const std::wstring& message, - const std::wstring& source, int line) - { - Lock(); - bool first_message = m_LogFile.empty(); - if(first_message) { - std::wstringstream ss; - ss << szWorkingDir << L"\\console.log"; - m_LogFile = ss.str(); - } - std::wstring logFile = m_LogFile; - Unlock(); - - FILE* file = NULL; - _wfopen_s(&file, logFile.c_str(), L"a, ccs=UTF-8"); - - if(file) { - std::wstringstream ss; - ss << L"Message: " << message << L"\r\nSource: " << source << - L"\r\nLine: " << line << L"\r\n-----------------------\r\n"; - fputws(ss.str().c_str(), file); - fclose(file); - - if(first_message) { - // Show the message box on the main application thread. - PostMessage(m_MainHwnd, WM_COMMAND, ID_WARN_CONSOLEMESSAGE, 0); - } - } - - return RV_HANDLED; - } - - // Called to report find results returned by CefBrowser::Find(). |identifer| - // is the identifier passed to CefBrowser::Find(), |count| is the number of - // matches currently identified, |selectionRect| is the location of where the - // match was found (in window coordinates), |activeMatchOrdinal| is the - // current position in the search results, and |finalUpdate| is true if this - // is the last find notification. The return value is currently ignored. - virtual RetVal HandleFindResult(CefRefPtr browser, - int identifier, int count, - const CefRect& selectionRect, - int activeMatchOrdinal, bool finalUpdate) - { - return RV_CONTINUE; - } - - // Retrieve the current navigation state flags - void GetNavState(bool &isLoading, bool &canGoBack, bool &canGoForward) - { - Lock(); - isLoading = m_bLoading; - canGoBack = m_bCanGoBack; - canGoForward = m_bCanGoForward; Unlock(); } + return RV_CONTINUE; +} - void SetMainHwnd(HWND hwnd) +CefHandler::RetVal ClientHandler::HandleLoadEnd(CefRefPtr browser, + CefRefPtr frame) +{ + if(!browser->IsPopup() && !frame.get()) { Lock(); - m_MainHwnd = hwnd; + // We've just finished loading a page + m_bLoading = false; + m_bCanGoBack = browser->CanGoBack(); + m_bCanGoForward = browser->CanGoForward(); Unlock(); } - HWND GetMainHwnd() { return m_MainHwnd; } + return RV_CONTINUE; +} - void SetEditHwnd(HWND hwnd) +CefHandler::RetVal ClientHandler::HandleLoadError(CefRefPtr browser, + CefRefPtr frame, ErrorCode errorCode, + const std::wstring& failedUrl, std::wstring& errorText) +{ + if(errorCode == ERR_CACHE_MISS) { - Lock(); - m_EditHwnd = hwnd; - Unlock(); + // Usually caused by navigating to a page with POST data via back or + // forward buttons. + errorText = L"Expired Form Data" + L"

Expired Form Data

" + L"

Your form request has expired. " + L"Click reload to re-submit the form data.

" + L""; + } + else + { + // All other messages. + std::wstringstream ss; + ss << L"Load Failed" + L"

Load Failed

" + L"

Load of URL " << failedUrl << + L"failed with error code " << static_cast(errorCode) << + L".

" + L""; + errorText = ss.str(); + } + return RV_HANDLED; +} + +CefHandler::RetVal ClientHandler::HandleDownloadResponse( + CefRefPtr browser, const std::wstring& mimeType, + const std::wstring& fileName, int64 contentLength, + CefRefPtr& handler) +{ + // Create the handler for the file download. + handler = CreateDownloadHandler(m_DownloadListener, fileName); + return RV_CONTINUE; +} + +CefHandler::RetVal ClientHandler::HandlePrintHeaderFooter( + CefRefPtr browser, CefRefPtr frame, + CefPrintInfo& printInfo, const std::wstring& url, const std::wstring& title, + int currentPage, int maxPages, std::wstring& topLeft, + std::wstring& topCenter, std::wstring& topRight, std::wstring& bottomLeft, + std::wstring& bottomCenter, std::wstring& bottomRight) +{ + // Place the page title at top left + topLeft = title; + // Place the page URL at top right + topRight = url; + + // Place "Page X of Y" at bottom center + std::wstringstream strstream; + strstream << L"Page " << currentPage << L" of " << maxPages; + bottomCenter = strstream.str(); + + return RV_CONTINUE; +} + +CefHandler::RetVal ClientHandler::HandleJSBinding(CefRefPtr browser, + CefRefPtr frame, CefRefPtr object) +{ + // Add the V8 bindings. + InitBindingTest(browser, frame, object); + + return RV_HANDLED; +} + +CefHandler::RetVal ClientHandler::HandleBeforeWindowClose( + CefRefPtr browser) +{ + if(m_BrowserHwnd == browser->GetWindowHandle()) + { + // Free the browser pointer so that the browser can be destroyed + m_Browser = NULL; + } + return RV_CONTINUE; +} + +CefHandler::RetVal ClientHandler::HandleConsoleMessage( + CefRefPtr browser, const std::wstring& message, + const std::wstring& source, int line) +{ + Lock(); + bool first_message = m_LogFile.empty(); + if(first_message) { + std::wstringstream ss; + ss << AppGetWorkingDirectory() << L"\\console.log"; + m_LogFile = ss.str(); + } + std::wstring logFile = m_LogFile; + Unlock(); + + FILE* file = NULL; + _wfopen_s(&file, logFile.c_str(), L"a, ccs=UTF-8"); + + if(file) { + std::wstringstream ss; + ss << L"Message: " << message << L"\r\nSource: " << source << + L"\r\nLine: " << line << L"\r\n-----------------------\r\n"; + fputws(ss.str().c_str(), file); + fclose(file); + + if(first_message) + SendNotification(NOTIFY_CONSOLE_MESSAGE); } - CefRefPtr GetBrowser() - { - return m_Browser; - } + return RV_HANDLED; +} - HWND GetBrowserHwnd() - { - return m_BrowserHwnd; - } +void ClientHandler::GetNavState(bool &isLoading, bool &canGoBack, + bool &canGoForward) +{ + Lock(); + isLoading = m_bLoading; + canGoBack = m_bCanGoBack; + canGoForward = m_bCanGoForward; + Unlock(); +} - std::wstring GetLogFile() - { - Lock(); - std::wstring str = m_LogFile; - Unlock(); - return str; - } +void ClientHandler::SetMainHwnd(CefWindowHandle hwnd) +{ + Lock(); + m_MainHwnd = hwnd; + Unlock(); +} - void SetLastDownloadFile(const std::wstring& fileName) - { - Lock(); - m_LastDownloadFile = fileName; - Unlock(); - } +void ClientHandler::SetEditHwnd(CefWindowHandle hwnd) +{ + Lock(); + m_EditHwnd = hwnd; + Unlock(); +} - std::wstring GetLastDownloadFile() - { - std::wstring str; - Lock(); - str = m_LastDownloadFile; - Unlock(); - return str; - } +std::wstring ClientHandler::GetLogFile() +{ + Lock(); + std::wstring str = m_LogFile; + Unlock(); + return str; +} -protected: - // The child browser window - CefRefPtr m_Browser; +void ClientHandler::SetLastDownloadFile(const std::wstring& fileName) +{ + Lock(); + m_LastDownloadFile = fileName; + Unlock(); +} - // The main frame window handle - HWND m_MainHwnd; +std::wstring ClientHandler::GetLastDownloadFile() +{ + std::wstring str; + Lock(); + str = m_LastDownloadFile; + Unlock(); + return str; +} - // The child browser window handle - HWND m_BrowserHwnd; - // The edit window handle - HWND m_EditHwnd; +// Global functions - // True if the page is currently loading - bool m_bLoading; - // True if the user can navigate backwards - bool m_bCanGoBack; - // True if the user can navigate forwards - bool m_bCanGoForward; - - std::wstring m_LogFile; - - // Support for downloading files. - CefRefPtr m_DownloadListener; - std::wstring m_LastDownloadFile; -}; - -// global handler instance CefRefPtr g_handler; CefRefPtr AppGetBrowser() @@ -770,16 +258,16 @@ CefRefPtr AppGetBrowser() return g_handler->GetBrowser(); } -HWND AppGetMainHwnd() +CefWindowHandle AppGetMainHwnd() { if(!g_handler.get()) return NULL; return g_handler->GetMainHwnd(); } -// Retrieve the current page source and display. -static void RunGetSourceTest(CefRefPtr frame) +void RunGetSourceTest(CefRefPtr frame) { + // Retrieve the current page source and display. std::wstring source = frame->GetSource(); source = StringReplace(source, L"<", L"<"); source = StringReplace(source, L">", L">"); @@ -789,9 +277,9 @@ static void RunGetSourceTest(CefRefPtr frame) frame->LoadString(ss.str(), L"http://tests/getsource"); } -// Retrieve the current page text and display. -static void RunGetTextTest(CefRefPtr frame) +void RunGetTextTest(CefRefPtr frame) { + // Retrieve the current page text and display. std::wstring text = frame->GetText(); text = StringReplace(text, L"<", L"<"); text = StringReplace(text, L">", L">"); @@ -801,454 +289,42 @@ static void RunGetTextTest(CefRefPtr frame) frame->LoadString(ss.str(), L"http://tests/gettext"); } -// -// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) -// -// PURPOSE: Processes messages for the main window. -// -LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +void RunRequestTest(CefRefPtr browser) { - static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL, - stopWnd = NULL, editWnd = NULL; - static WNDPROC editWndOldProc = NULL; - - // Static members used for the find dialog. - static FINDREPLACE fr; - static WCHAR szFindWhat[80] = {0}; - static WCHAR szLastFindWhat[80] = {0}; - static bool findNext = false; - static bool lastMatchCase = false; - - int wmId, wmEvent; - PAINTSTRUCT ps; - HDC hdc; + // Create a new request + CefRefPtr request(CefRequest::CreateRequest()); - if(hWnd == editWnd) - { - // Callback for the edit window - switch (message) - { - case WM_CHAR: - if (wParam == VK_RETURN && g_handler.get()) - { - // When the user hits the enter key load the URL - CefRefPtr browser = g_handler->GetBrowser(); - wchar_t strPtr[MAX_URL_LENGTH] = {0}; - *((LPWORD)strPtr) = MAX_URL_LENGTH; - LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr); - if (strLen > 0) { - strPtr[strLen] = 0; - browser->GetMainFrame()->LoadURL(strPtr); - } + // Set the request URL + request->SetURL(L"http://tests/request"); - return 0; - } - } + // Add post data to the request. The correct method and content- + // type headers will be set by CEF. + CefRefPtr postDataElement( + CefPostDataElement::CreatePostDataElement()); + std::string data = "arg1=val1&arg2=val2"; + postDataElement->SetToBytes(data.length(), data.c_str()); + CefRefPtr postData(CefPostData::CreatePostData()); + postData->AddElement(postDataElement); + request->SetPostData(postData); - return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam, lParam); - } - else if (message == uFindMsg) - { - // Find event. - LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam; + // Add a custom header + CefRequest::HeaderMap headerMap; + headerMap.insert( + std::make_pair(L"X-My-Header", L"My Header Value")); + request->SetHeaderMap(headerMap); - if (lpfr->Flags & FR_DIALOGTERM) - { - // The find dialog box has been dismissed so invalidate the handle and - // reset the search results. - hFindDlg = NULL; - if(g_handler.get()) - { - g_handler->GetBrowser()->StopFinding(true); - szLastFindWhat[0] = 0; - findNext = false; - } - return 0; - } - - if ((lpfr->Flags & FR_FINDNEXT) && g_handler.get()) - { - // Search for the requested string. - bool matchCase = (lpfr->Flags & FR_MATCHCASE?true:false); - if(matchCase != lastMatchCase || - (matchCase && wcsncmp(szFindWhat, szLastFindWhat, - sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0) || - (!matchCase && _wcsnicmp(szFindWhat, szLastFindWhat, - sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0)) - { - // The search string has changed, so reset the search results. - if(szLastFindWhat[0] != 0) { - g_handler->GetBrowser()->StopFinding(true); - findNext = false; - } - lastMatchCase = matchCase; - wcscpy_s(szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR), - szFindWhat); - } - - g_handler->GetBrowser()->Find(0, lpfr->lpstrFindWhat, - (lpfr->Flags & FR_DOWN)?true:false, matchCase, findNext); - if(!findNext) - findNext = true; - } - - return 0; - } - else - { - // Callback for the main window - switch (message) - { - case WM_CREATE: - { - // Create the single static handler class instance - g_handler = new ClientHandler(); - g_handler->SetMainHwnd(hWnd); - - // Create the child windows used for navigation - RECT rect; - int x = 0; - - GetClientRect(hWnd, &rect); - - backWnd = CreateWindow(L"BUTTON", L"Back", - WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON - | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, - hWnd, (HMENU) IDC_NAV_BACK, hInst, 0); - x += BUTTON_WIDTH; - - forwardWnd = CreateWindow(L"BUTTON", L"Forward", - WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON - | WS_DISABLED, x, 0, BUTTON_WIDTH, - URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD, - hInst, 0); - x += BUTTON_WIDTH; - - reloadWnd = CreateWindow(L"BUTTON", L"Reload", - WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON - | WS_DISABLED, x, 0, BUTTON_WIDTH, - URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD, - hInst, 0); - x += BUTTON_WIDTH; - - stopWnd = CreateWindow(L"BUTTON", L"Stop", - WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON - | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, - hWnd, (HMENU) IDC_NAV_STOP, hInst, 0); - x += BUTTON_WIDTH; - - editWnd = CreateWindow(L"EDIT", 0, - WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | - ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED, - x, 0, rect.right - BUTTON_WIDTH * 4, - URLBAR_HEIGHT, hWnd, 0, hInst, 0); - - // Assign the edit window's WNDPROC to this function so that we can - // capture the enter key - editWndOldProc = - reinterpret_cast(GetWindowLongPtr(editWnd, GWLP_WNDPROC)); - SetWindowLongPtr(editWnd, GWLP_WNDPROC, - reinterpret_cast(WndProc)); - g_handler->SetEditHwnd(editWnd); - - rect.top += URLBAR_HEIGHT; - - CefWindowInfo info; - - // Initialize window info to the defaults for a child window - info.SetAsChild(hWnd, rect); - - // Creat the new child child browser window - CefBrowser::CreateBrowser(info, false, - static_cast >(g_handler), - L"http://www.google.com"); - - // Start the timer that will be used to update child window state - SetTimer(hWnd, 1, 250, NULL); - } - return 0; - - case WM_TIMER: - if(g_handler.get() && g_handler->GetBrowserHwnd()) - { - // Retrieve the current navigation state - bool isLoading, canGoBack, canGoForward; - g_handler->GetNavState(isLoading, canGoBack, canGoForward); - - // Update the status of child windows - EnableWindow(editWnd, TRUE); - EnableWindow(backWnd, canGoBack); - EnableWindow(forwardWnd, canGoForward); - EnableWindow(reloadWnd, !isLoading); - EnableWindow(stopWnd, isLoading); - } - return 0; - - case WM_COMMAND: - { - CefRefPtr browser; - if(g_handler.get()) - browser = g_handler->GetBrowser(); - - wmId = LOWORD(wParam); - wmEvent = HIWORD(wParam); - // Parse the menu selections: - switch (wmId) - { - case IDM_ABOUT: - DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); - return 0; - case IDM_EXIT: - DestroyWindow(hWnd); - return 0; - case ID_WARN_CONSOLEMESSAGE: - if(g_handler.get()) { - std::wstringstream ss; - ss << L"Console messages will be written to " - << g_handler->GetLogFile(); - MessageBoxW(hWnd, ss.str().c_str(), L"Console Messages", - MB_OK | MB_ICONINFORMATION); - } - return 0; - case ID_WARN_DOWNLOADCOMPLETE: - case ID_WARN_DOWNLOADERROR: - if(g_handler.get()) { - std::wstringstream ss; - ss << L"File \"" << g_handler->GetLastDownloadFile() << L"\" "; - - if(wmId == ID_WARN_DOWNLOADCOMPLETE) - ss << L"downloaded successfully."; - else - ss << L"failed to download."; - - MessageBoxW(hWnd, ss.str().c_str(), L"File Download", - MB_OK | MB_ICONINFORMATION); - } - return 0; - case ID_FIND: - if(!hFindDlg) - { - // Create the find dialog. - ZeroMemory(&fr, sizeof(fr)); - fr.lStructSize = sizeof(fr); - fr.hwndOwner = hWnd; - fr.lpstrFindWhat = szFindWhat; - fr.wFindWhatLen = sizeof(szFindWhat); - fr.Flags = FR_HIDEWHOLEWORD | FR_DOWN; - - hFindDlg = FindText(&fr); - } - else - { - // Give focus to the existing find dialog. - ::SetFocus(hFindDlg); - } - return 0; - case ID_PRINT: - if(browser.get()) - browser->GetMainFrame()->Print(); - return 0; - case IDC_NAV_BACK: // Back button - if(browser.get()) - browser->GoBack(); - return 0; - case IDC_NAV_FORWARD: // Forward button - if(browser.get()) - browser->GoForward(); - return 0; - case IDC_NAV_RELOAD: // Reload button - if(browser.get()) - browser->Reload(); - return 0; - case IDC_NAV_STOP: // Stop button - if(browser.get()) - browser->StopLoad(); - return 0; - case ID_TESTS_GETSOURCE: // Test the GetSource function - if(browser.get()) { -#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP - RunGetSourceTest(browser->GetMainFrame()); -#else // !TEST_SINGLE_THREADED_MESSAGE_LOOP - // Execute the GetSource() call on the FILE thread to avoid blocking - // the UI thread when using a multi-threaded message loop - // (issue #79). - class ExecTask : public CefThreadSafeBase - { - public: - ExecTask(CefRefPtr frame) : m_Frame(frame) {} - virtual void Execute(CefThreadId threadId) - { - RunGetSourceTest(m_Frame); - } - private: - CefRefPtr m_Frame; - }; - CefPostTask(TID_FILE, new ExecTask(browser->GetMainFrame())); -#endif // !TEST_SINGLE_THREADED_MESSAGE_LOOP - } - return 0; - case ID_TESTS_GETTEXT: // Test the GetText function - if(browser.get()) { -#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP - RunGetTextTest(browser->GetMainFrame()); -#else // !TEST_SINGLE_THREADED_MESSAGE_LOOP - // Execute the GetText() call on the FILE thread to avoid blocking - // the UI thread when using a multi-threaded message loop - // (issue #79). - class ExecTask : public CefThreadSafeBase - { - public: - ExecTask(CefRefPtr frame) : m_Frame(frame) {} - virtual void Execute(CefThreadId threadId) - { - RunGetTextTest(m_Frame); - } - private: - CefRefPtr m_Frame; - }; - CefPostTask(TID_FILE, new ExecTask(browser->GetMainFrame())); -#endif // !TEST_SINGLE_THREADED_MESSAGE_LOOP - } - return 0; - case ID_TESTS_JAVASCRIPT_BINDING: // Test the V8 binding handler - if(browser.get()) - RunBindingTest(browser); - return 0; - case ID_TESTS_JAVASCRIPT_EXTENSION: // Test the V8 extension handler - if(browser.get()) - RunExtensionTest(browser); - return 0; - case ID_TESTS_JAVASCRIPT_EXECUTE: // Test execution of javascript - if(browser.get()) - { - browser->GetMainFrame()->ExecuteJavaScript( - L"alert('JavaScript execute works!');", - L"about:blank", 0); - } - return 0; - case ID_TESTS_PLUGIN: // Test the custom plugin - if(browser.get()) - RunPluginTest(browser); - return 0; - case ID_TESTS_POPUP: // Test a popup window - if(browser.get()) - { - browser->GetMainFrame()->ExecuteJavaScript( - L"window.open('http://www.google.com');", - L"about:blank", 0); - } - return 0; - case ID_TESTS_REQUEST: // Test a request - if(browser.get()) - { - // Create a new request - CefRefPtr request(CefRequest::CreateRequest()); - - // Set the request URL - request->SetURL(L"http://tests/request"); - - // Add post data to the request. The correct method and content- - // type headers will be set by CEF. - CefRefPtr postDataElement( - CefPostDataElement::CreatePostDataElement()); - std::string data = "arg1=val1&arg2=val2"; - postDataElement->SetToBytes(data.length(), data.c_str()); - CefRefPtr postData(CefPostData::CreatePostData()); - postData->AddElement(postDataElement); - request->SetPostData(postData); - - // Add a custom header - CefRequest::HeaderMap headerMap; - headerMap.insert( - std::make_pair(L"X-My-Header", L"My Header Value")); - request->SetHeaderMap(headerMap); - - // Load the request - browser->GetMainFrame()->LoadRequest(request); - } - return 0; - case ID_TESTS_SCHEME_HANDLER: // Test the scheme handler - if(browser.get()) - RunSchemeTest(browser); - return 0; - case ID_TESTS_UIAPP: // Test the UI app - if(browser.get()) - RunUIPluginTest(browser); - return 0; - } - } - break; - - case WM_PAINT: - hdc = BeginPaint(hWnd, &ps); - EndPaint(hWnd, &ps); - return 0; - - case WM_SETFOCUS: - if(g_handler.get() && g_handler->GetBrowserHwnd()) - { - // Pass focus to the browser window - PostMessage(g_handler->GetBrowserHwnd(), WM_SETFOCUS, wParam, NULL); - } - return 0; - - case WM_SIZE: - if(g_handler.get() && g_handler->GetBrowserHwnd()) - { - // Resize the browser window and address bar to match the new frame - // window size - RECT rect; - GetClientRect(hWnd, &rect); - rect.top += URLBAR_HEIGHT; - - int urloffset = rect.left + BUTTON_WIDTH * 4; - - HDWP hdwp = BeginDeferWindowPos(1); - hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset, - 0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER); - hdwp = DeferWindowPos(hdwp, g_handler->GetBrowserHwnd(), NULL, - rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, - SWP_NOZORDER); - EndDeferWindowPos(hdwp); - } - break; - - case WM_ERASEBKGND: - if(g_handler.get() && g_handler->GetBrowserHwnd()) - { - // Dont erase the background if the browser window has been loaded - // (this avoids flashing) - return 0; - } - break; - - case WM_DESTROY: - // The frame window has exited - KillTimer(hWnd, 1); - PostQuitMessage(0); - return 0; - } - - return DefWindowProc(hWnd, message, wParam, lParam); - } + // Load the request + browser->GetMainFrame()->LoadRequest(request); } -// Message handler for about box. -INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +void RunJavaScriptExecuteTest(CefRefPtr browser) { - UNREFERENCED_PARAMETER(lParam); - switch (message) - { - case WM_INITDIALOG: - return (INT_PTR)TRUE; - - case WM_COMMAND: - if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) - { - EndDialog(hDlg, LOWORD(wParam)); - return (INT_PTR)TRUE; - } - break; - } - return (INT_PTR)FALSE; + browser->GetMainFrame()->ExecuteJavaScript( + L"alert('JavaScript execute works!');", L"about:blank", 0); +} + +void RunPopupTest(CefRefPtr browser) +{ + browser->GetMainFrame()->ExecuteJavaScript( + L"window.open('http://www.google.com');", L"about:blank", 0); } diff --git a/tests/cefclient/cefclient.h b/tests/cefclient/cefclient.h index 96cdc9296..607abfdbb 100644 --- a/tests/cefclient/cefclient.h +++ b/tests/cefclient/cefclient.h @@ -2,13 +2,363 @@ // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. -#pragma once +#ifndef _CEFCLIENT_H +#define _CEFCLIENT_H -#include "resource.h" #include "include/cef.h" +#include "download_handler.h" -// Return the main browser window instance. + +// Client implementation of the browser handler class +class ClientHandler : public CefThreadSafeBase +{ +public: + // Implements the DownloadListener interface. + class ClientDownloadListener : public CefThreadSafeBase + { + public: + ClientDownloadListener(ClientHandler* handler) : handler_(handler) {} + + // Called when the download is complete. + virtual void NotifyDownloadComplete(const std::wstring& fileName); + + // Called if the download fails. + virtual void NotifyDownloadError(const std::wstring& fileName); + + private: + ClientHandler* handler_; + }; + + ClientHandler(); + ~ClientHandler(); + + // Event called before a new window is created. The |parentBrowser| parameter + // will point to the parent browser window, if any. The |popup| parameter + // will be true if the new window is a popup window. If you create the window + // yourself you should populate the window handle member of |createInfo| and + // return RV_HANDLED. Otherwise, return RV_CONTINUE and the framework will + // create the window. By default, a newly created window will recieve the + // same handler as the parent window. To change the handler for the new + // window modify the object that |handler| points to. + virtual RetVal HandleBeforeCreated(CefRefPtr parentBrowser, + CefWindowInfo& createInfo, bool popup, + CefRefPtr& handler, + std::wstring& url) + { + return RV_CONTINUE; + } + + // Event called after a new window is created. The return value is currently + // ignored. + virtual RetVal HandleAfterCreated(CefRefPtr browser); + + // Event called when the address bar changes. The return value is currently + // ignored. + virtual RetVal HandleAddressChange(CefRefPtr browser, + CefRefPtr frame, + const std::wstring& url); + + // Event called when the page title changes. The return value is currently + // ignored. + virtual RetVal HandleTitleChange(CefRefPtr browser, + const std::wstring& title); + + // Event called before browser navigation. The client has an opportunity to + // modify the |request| object if desired. Return RV_HANDLED to cancel + // navigation. + virtual RetVal HandleBeforeBrowse(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + NavType navType, bool isRedirect) + { + return RV_CONTINUE; + } + + // Event called when the browser begins loading a page. The |frame| pointer + // will be empty if the event represents the overall load status and not the + // load status for a particular frame. The return value is currently ignored. + virtual RetVal HandleLoadStart(CefRefPtr browser, + CefRefPtr frame); + + // Event called when the browser is done loading a page. The |frame| pointer + // will be empty if the event represents the overall load status and not the + // load status for a particular frame. This event will be generated + // irrespective of whether the request completes successfully. The return + // value is currently ignored. + virtual RetVal HandleLoadEnd(CefRefPtr browser, + CefRefPtr frame); + + // Called when the browser fails to load a resource. |errorCode| is the + // error code number and |failedUrl| is the URL that failed to load. To + // provide custom error text assign the text to |errorText| and return + // RV_HANDLED. Otherwise, return RV_CONTINUE for the default error text. + virtual RetVal HandleLoadError(CefRefPtr browser, + CefRefPtr frame, + ErrorCode errorCode, + const std::wstring& failedUrl, + std::wstring& errorText); + + // Event called before a resource is loaded. To allow the resource to load + // normally return RV_CONTINUE. To redirect the resource to a new url + // populate the |redirectUrl| value and return RV_CONTINUE. To specify + // data for the resource return a CefStream object in |resourceStream|, set + // 'mimeType| to the resource stream's mime type, and return RV_CONTINUE. + // To cancel loading of the resource return RV_HANDLED. + virtual RetVal HandleBeforeResourceLoad(CefRefPtr browser, + CefRefPtr request, + std::wstring& redirectUrl, + CefRefPtr& resourceStream, + std::wstring& mimeType, + int loadFlags); + + // Called when a server indicates via the 'Content-Disposition' header that a + // response represents a file to download. |mime_type| is the mime type for + // the download, |file_name| is the suggested target file name and + // |content_length| is either the value of the 'Content-Size' header or -1 if + // no size was provided. Set |handler| to the CefDownloadHandler instance that + // will recieve the file contents. Return RV_CONTINUE to download the file + // or RV_HANDLED to cancel the file download. + /*--cef()--*/ + virtual RetVal HandleDownloadResponse(CefRefPtr browser, + const std::wstring& mimeType, + const std::wstring& fileName, + int64 contentLength, + CefRefPtr& handler); + + // Event called before a context menu is displayed. To cancel display of the + // default context menu return RV_HANDLED. + virtual RetVal HandleBeforeMenu(CefRefPtr browser, + const MenuInfo& menuInfo) + { + return RV_CONTINUE; + } + + // Event called to optionally override the default text for a context menu + // item. |label| contains the default text and may be modified to substitute + // alternate text. The return value is currently ignored. + virtual RetVal HandleGetMenuLabel(CefRefPtr browser, + MenuId menuId, std::wstring& label) + { + return RV_CONTINUE; + } + + // Event called when an option is selected from the default context menu. + // Return RV_HANDLED to cancel default handling of the action. + virtual RetVal HandleMenuAction(CefRefPtr browser, + MenuId menuId) + { + return RV_CONTINUE; + } + + // Event called to allow customization of standard print options before the + // print dialog is displayed. |printOptions| allows specification of paper + // size, orientation and margins. Note that the specified margins may be + // adjusted if they are outside the range supported by the printer. All units + // are in inches. Return RV_CONTINUE to display the default print options or + // RV_HANDLED to display the modified |printOptions|. + virtual RetVal HandlePrintOptions(CefRefPtr browser, + CefPrintOptions& printOptions) + { + return RV_CONTINUE; + } + + // Event called to format print headers and footers. |printInfo| contains + // platform-specific information about the printer context. |url| is the + // URL if the currently printing page, |title| is the title of the currently + // printing page, |currentPage| is the current page number and |maxPages| is + // the total number of pages. Six default header locations are provided + // by the implementation: top left, top center, top right, bottom left, + // bottom center and bottom right. To use one of these default locations + // just assign a string to the appropriate variable. To draw the header + // and footer yourself return RV_HANDLED. Otherwise, populate the approprate + // variables and return RV_CONTINUE. + virtual RetVal HandlePrintHeaderFooter(CefRefPtr browser, + CefRefPtr frame, + CefPrintInfo& printInfo, + const std::wstring& url, + const std::wstring& title, + int currentPage, int maxPages, + std::wstring& topLeft, + std::wstring& topCenter, + std::wstring& topRight, + std::wstring& bottomLeft, + std::wstring& bottomCenter, + std::wstring& bottomRight); + + // Run a JS alert message. Return RV_CONTINUE to display the default alert + // or RV_HANDLED if you displayed a custom alert. + virtual RetVal HandleJSAlert(CefRefPtr browser, + CefRefPtr frame, + const std::wstring& message) + { + return RV_CONTINUE; + } + + // Run a JS confirm request. Return RV_CONTINUE to display the default alert + // or RV_HANDLED if you displayed a custom alert. If you handled the alert + // set |retval| to true if the user accepted the confirmation. + virtual RetVal HandleJSConfirm(CefRefPtr browser, + CefRefPtr frame, + const std::wstring& message, bool& retval) + { + return RV_CONTINUE; + } + + // Run a JS prompt request. Return RV_CONTINUE to display the default prompt + // or RV_HANDLED if you displayed a custom prompt. If you handled the prompt + // set |retval| to true if the user accepted the prompt and request and + // |result| to the resulting value. + virtual RetVal HandleJSPrompt(CefRefPtr browser, + CefRefPtr frame, + const std::wstring& message, + const std::wstring& defaultValue, + bool& retval, + std::wstring& result) + { + return RV_CONTINUE; + } + + // Event called for binding to a frame's JavaScript global object. The + // return value is currently ignored. + virtual RetVal HandleJSBinding(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr object); + + // Called just before a window is closed. The return value is currently + // ignored. + virtual RetVal HandleBeforeWindowClose(CefRefPtr browser); + + // Called when the browser component is about to loose focus. For instance, + // if focus was on the last HTML element and the user pressed the TAB key. + // The return value is currently ignored. + virtual RetVal HandleTakeFocus(CefRefPtr browser, bool reverse) + { + return RV_CONTINUE; + } + + // Called when the browser component is requesting focus. |isWidget| will be + // true if the focus is requested for a child widget of the browser window. + // Return RV_CONTINUE to allow the focus to be set or RV_HANDLED to cancel + // setting the focus. + virtual RetVal HandleSetFocus(CefRefPtr browser, + bool isWidget) + { + return RV_CONTINUE; + } + + // Event called when the browser is about to display a tooltip. |text| + // contains the text that will be displayed in the tooltip. To handle + // the display of the tooltip yourself return RV_HANDLED. Otherwise, + // you can optionally modify |text| and then return RV_CONTINUE to allow + // the browser to display the tooltip. + virtual RetVal HandleTooltip(CefRefPtr browser, + std::wstring& text) + { + return RV_CONTINUE; + } + + // Called when the browser component receives a keyboard event. + // |type| is the type of keyboard event (see |KeyEventType|). + // |code| is the windows scan-code for the event. + // |modifiers| is a set of bit-flags describing any pressed modifier keys. + // |isSystemKey| is set if Windows considers this a 'system key' message; + // (see http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx) + // Return RV_HANDLED if the keyboard event was handled or RV_CONTINUE + // to allow the browser component to handle the event. + RetVal HandleKeyEvent(CefRefPtr browser, + KeyEventType type, + int code, + int modifiers, + bool isSystemKey) + { + return RV_CONTINUE; + } + + // Called to display a console message. Return RV_HANDLED to stop the message + // from being output to the console. + RetVal HandleConsoleMessage(CefRefPtr browser, + const std::wstring& message, + const std::wstring& source, int line); + + // Called to report find results returned by CefBrowser::Find(). |identifer| + // is the identifier passed to CefBrowser::Find(), |count| is the number of + // matches currently identified, |selectionRect| is the location of where the + // match was found (in window coordinates), |activeMatchOrdinal| is the + // current position in the search results, and |finalUpdate| is true if this + // is the last find notification. The return value is currently ignored. + virtual RetVal HandleFindResult(CefRefPtr browser, + int identifier, int count, + const CefRect& selectionRect, + int activeMatchOrdinal, bool finalUpdate) + { + return RV_CONTINUE; + } + + // Retrieve the current navigation state flags + void GetNavState(bool &isLoading, bool &canGoBack, bool &canGoForward); + void SetMainHwnd(CefWindowHandle hwnd); + CefWindowHandle GetMainHwnd() { return m_MainHwnd; } + void SetEditHwnd(CefWindowHandle hwnd); + CefRefPtr GetBrowser() { return m_Browser; } + CefWindowHandle GetBrowserHwnd() { return m_BrowserHwnd; } + + std::wstring GetLogFile(); + + void SetLastDownloadFile(const std::wstring& fileName); + std::wstring GetLastDownloadFile(); + + // Send a notification to the application. Notifications should not block the + // caller. + enum NotificationType + { + NOTIFY_CONSOLE_MESSAGE, + NOTIFY_DOWNLOAD_COMPLETE, + NOTIFY_DOWNLOAD_ERROR, + }; + void SendNotification(NotificationType type); + +protected: + // The child browser window + CefRefPtr m_Browser; + + // The main frame window handle + CefWindowHandle m_MainHwnd; + + // The child browser window handle + CefWindowHandle m_BrowserHwnd; + + // The edit window handle + CefWindowHandle m_EditHwnd; + + // True if the page is currently loading + bool m_bLoading; + // True if the user can navigate backwards + bool m_bCanGoBack; + // True if the user can navigate forwards + bool m_bCanGoForward; + + std::wstring m_LogFile; + + // Support for downloading files. + CefRefPtr m_DownloadListener; + std::wstring m_LastDownloadFile; +}; + + +// Returns the main browser window instance. CefRefPtr AppGetBrowser(); -// Return the main application window handle. -HWND AppGetMainHwnd(); +// Returns the main application window handle. +CefWindowHandle AppGetMainHwnd(); + +// Returns the application working directory. +std::wstring AppGetWorkingDirectory(); + +// Implementations for various tests. +void RunGetSourceTest(CefRefPtr frame); +void RunGetTextTest(CefRefPtr frame); +void RunRequestTest(CefRefPtr browser); +void RunJavaScriptExecuteTest(CefRefPtr browser); +void RunPopupTest(CefRefPtr browser); + +#endif // _CEFCLIENT_H diff --git a/tests/cefclient/cefclient_win.cpp b/tests/cefclient/cefclient_win.cpp new file mode 100644 index 000000000..45159b5fd --- /dev/null +++ b/tests/cefclient/cefclient_win.cpp @@ -0,0 +1,711 @@ +// Copyright (c) 2010 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 "include/cef.h" +#include "include/cef_wrapper.h" +#include "cefclient.h" +#include "binding_test.h" +#include "extension_test.h" +#include "plugin_test.h" +#include "resource.h" +#include "resource_util.h" +#include "scheme_test.h" +#include "string_util.h" +#include "uiplugin_test.h" +#include +#include + + +#define MAX_LOADSTRING 100 +#define MAX_URL_LENGTH 255 +#define BUTTON_WIDTH 72 +#define URLBAR_HEIGHT 24 + +// Define this value to run CEF with messages processed using the current +// application's message loop. +#define TEST_SINGLE_THREADED_MESSAGE_LOOP + +// Global Variables: +HINSTANCE hInst; // current instance +TCHAR szTitle[MAX_LOADSTRING]; // The title bar text +TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name +TCHAR szWorkingDir[MAX_PATH]; // The current working directory +UINT uFindMsg; // Message identifier for find events. +HWND hFindDlg = NULL; // Handle for the find dialog. + +// Forward declarations of functions included in this code module: +ATOM MyRegisterClass(HINSTANCE hInstance); +BOOL InitInstance(HINSTANCE, int); +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); + +// The global ClientHandler reference. +extern CefRefPtr g_handler; + +#ifdef _WIN32 +// Add Common Controls to the application manifest because it's required to +// support the default tooltip implementation. +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") +#endif + +// Program entry point function. +int APIENTRY wWinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPTSTR lpCmdLine, + int nCmdShow) +{ + UNREFERENCED_PARAMETER(hPrevInstance); + UNREFERENCED_PARAMETER(lpCmdLine); + + // Retrieve the current working directory. + if(_wgetcwd(szWorkingDir, MAX_PATH) == NULL) + szWorkingDir[0] = 0; + +#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP + // Initialize the CEF with messages processed using the current application's + // message loop. + CefInitialize(false, std::wstring()); +#else + // Initialize the CEF with messages processed using a separate UI thread. + CefInitialize(true, std::wstring()); +#endif + + // Register the internal client plugin. + InitPluginTest(); + + // Register the internal UI client plugin. + InitUIPluginTest(); + + // Register the V8 extension handler. + InitExtensionTest(); + + // Register the scheme handler. + InitSchemeTest(); + + MSG msg; + HACCEL hAccelTable; + + // Initialize global strings + LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING); + MyRegisterClass(hInstance); + + // Perform application initialization + if (!InitInstance (hInstance, nCmdShow)) + { + return FALSE; + } + + hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT)); + + // Register the find event message. + uFindMsg = RegisterWindowMessage(FINDMSGSTRING); + + // Main message loop + while (GetMessage(&msg, NULL, 0, 0)) + { +#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP + // Allow the CEF to do its message loop processing. + CefDoMessageLoopWork(); +#endif + + // Allow processing of find dialog messages. + if(hFindDlg && IsDialogMessage(hFindDlg, &msg)) + continue; + + if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + // Shut down the CEF + CefShutdown(); + + return (int) msg.wParam; +} + +// +// FUNCTION: MyRegisterClass() +// +// PURPOSE: Registers the window class. +// +// COMMENTS: +// +// This function and its usage are only necessary if you want this code +// to be compatible with Win32 systems prior to the 'RegisterClassEx' +// function that was added to Windows 95. It is important to call this +// function so that the application will get 'well formed' small icons +// associated with it. +// +ATOM MyRegisterClass(HINSTANCE hInstance) +{ + WNDCLASSEX wcex; + + wcex.cbSize = sizeof(WNDCLASSEX); + + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CEFCLIENT)); + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + wcex.lpszMenuName = MAKEINTRESOURCE(IDC_CEFCLIENT); + wcex.lpszClassName = szWindowClass; + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + + return RegisterClassEx(&wcex); +} + +// +// FUNCTION: InitInstance(HINSTANCE, int) +// +// PURPOSE: Saves instance handle and creates main window +// +// COMMENTS: +// +// In this function, we save the instance handle in a global variable and +// create and display the main program window. +// +BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) +{ + HWND hWnd; + + hInst = hInstance; // Store instance handle in our global variable + + hWnd = CreateWindow(szWindowClass, szTitle, + WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, 0, CW_USEDEFAULT, + 0, NULL, NULL, hInstance, NULL); + + if (!hWnd) + { + return FALSE; + } + + ShowWindow(hWnd, nCmdShow); + UpdateWindow(hWnd); + + return TRUE; +} + +// +// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) +// +// PURPOSE: Processes messages for the main window. +// +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL, + stopWnd = NULL, editWnd = NULL; + static WNDPROC editWndOldProc = NULL; + + // Static members used for the find dialog. + static FINDREPLACE fr; + static WCHAR szFindWhat[80] = {0}; + static WCHAR szLastFindWhat[80] = {0}; + static bool findNext = false; + static bool lastMatchCase = false; + + int wmId, wmEvent; + PAINTSTRUCT ps; + HDC hdc; + + if(hWnd == editWnd) + { + // Callback for the edit window + switch (message) + { + case WM_CHAR: + if (wParam == VK_RETURN && g_handler.get()) + { + // When the user hits the enter key load the URL + CefRefPtr browser = g_handler->GetBrowser(); + wchar_t strPtr[MAX_URL_LENGTH] = {0}; + *((LPWORD)strPtr) = MAX_URL_LENGTH; + LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr); + if (strLen > 0) { + strPtr[strLen] = 0; + browser->GetMainFrame()->LoadURL(strPtr); + } + + return 0; + } + } + + return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam, lParam); + } + else if (message == uFindMsg) + { + // Find event. + LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam; + + if (lpfr->Flags & FR_DIALOGTERM) + { + // The find dialog box has been dismissed so invalidate the handle and + // reset the search results. + hFindDlg = NULL; + if(g_handler.get()) + { + g_handler->GetBrowser()->StopFinding(true); + szLastFindWhat[0] = 0; + findNext = false; + } + return 0; + } + + if ((lpfr->Flags & FR_FINDNEXT) && g_handler.get()) + { + // Search for the requested string. + bool matchCase = (lpfr->Flags & FR_MATCHCASE?true:false); + if(matchCase != lastMatchCase || + (matchCase && wcsncmp(szFindWhat, szLastFindWhat, + sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0) || + (!matchCase && _wcsnicmp(szFindWhat, szLastFindWhat, + sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0)) + { + // The search string has changed, so reset the search results. + if(szLastFindWhat[0] != 0) { + g_handler->GetBrowser()->StopFinding(true); + findNext = false; + } + lastMatchCase = matchCase; + wcscpy_s(szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR), + szFindWhat); + } + + g_handler->GetBrowser()->Find(0, lpfr->lpstrFindWhat, + (lpfr->Flags & FR_DOWN)?true:false, matchCase, findNext); + if(!findNext) + findNext = true; + } + + return 0; + } + else + { + // Callback for the main window + switch (message) + { + case WM_CREATE: + { + // Create the single static handler class instance + g_handler = new ClientHandler(); + g_handler->SetMainHwnd(hWnd); + + // Create the child windows used for navigation + RECT rect; + int x = 0; + + GetClientRect(hWnd, &rect); + + backWnd = CreateWindow(L"BUTTON", L"Back", + WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON + | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, + hWnd, (HMENU) IDC_NAV_BACK, hInst, 0); + x += BUTTON_WIDTH; + + forwardWnd = CreateWindow(L"BUTTON", L"Forward", + WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON + | WS_DISABLED, x, 0, BUTTON_WIDTH, + URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD, + hInst, 0); + x += BUTTON_WIDTH; + + reloadWnd = CreateWindow(L"BUTTON", L"Reload", + WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON + | WS_DISABLED, x, 0, BUTTON_WIDTH, + URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD, + hInst, 0); + x += BUTTON_WIDTH; + + stopWnd = CreateWindow(L"BUTTON", L"Stop", + WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON + | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, + hWnd, (HMENU) IDC_NAV_STOP, hInst, 0); + x += BUTTON_WIDTH; + + editWnd = CreateWindow(L"EDIT", 0, + WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | + ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED, + x, 0, rect.right - BUTTON_WIDTH * 4, + URLBAR_HEIGHT, hWnd, 0, hInst, 0); + + // Assign the edit window's WNDPROC to this function so that we can + // capture the enter key + editWndOldProc = + reinterpret_cast(GetWindowLongPtr(editWnd, GWLP_WNDPROC)); + SetWindowLongPtr(editWnd, GWLP_WNDPROC, + reinterpret_cast(WndProc)); + g_handler->SetEditHwnd(editWnd); + + rect.top += URLBAR_HEIGHT; + + CefWindowInfo info; + + // Initialize window info to the defaults for a child window + info.SetAsChild(hWnd, rect); + + // Creat the new child child browser window + CefBrowser::CreateBrowser(info, false, + static_cast >(g_handler), + L"http://www.google.com"); + + // Start the timer that will be used to update child window state + SetTimer(hWnd, 1, 250, NULL); + } + return 0; + + case WM_TIMER: + if(g_handler.get() && g_handler->GetBrowserHwnd()) + { + // Retrieve the current navigation state + bool isLoading, canGoBack, canGoForward; + g_handler->GetNavState(isLoading, canGoBack, canGoForward); + + // Update the status of child windows + EnableWindow(editWnd, TRUE); + EnableWindow(backWnd, canGoBack); + EnableWindow(forwardWnd, canGoForward); + EnableWindow(reloadWnd, !isLoading); + EnableWindow(stopWnd, isLoading); + } + return 0; + + case WM_COMMAND: + { + CefRefPtr browser; + if(g_handler.get()) + browser = g_handler->GetBrowser(); + + wmId = LOWORD(wParam); + wmEvent = HIWORD(wParam); + // Parse the menu selections: + switch (wmId) + { + case IDM_ABOUT: + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); + return 0; + case IDM_EXIT: + DestroyWindow(hWnd); + return 0; + case ID_WARN_CONSOLEMESSAGE: + if(g_handler.get()) { + std::wstringstream ss; + ss << L"Console messages will be written to " + << g_handler->GetLogFile(); + MessageBoxW(hWnd, ss.str().c_str(), L"Console Messages", + MB_OK | MB_ICONINFORMATION); + } + return 0; + case ID_WARN_DOWNLOADCOMPLETE: + case ID_WARN_DOWNLOADERROR: + if(g_handler.get()) { + std::wstringstream ss; + ss << L"File \"" << g_handler->GetLastDownloadFile() << L"\" "; + + if(wmId == ID_WARN_DOWNLOADCOMPLETE) + ss << L"downloaded successfully."; + else + ss << L"failed to download."; + + MessageBoxW(hWnd, ss.str().c_str(), L"File Download", + MB_OK | MB_ICONINFORMATION); + } + return 0; + case ID_FIND: + if(!hFindDlg) + { + // Create the find dialog. + ZeroMemory(&fr, sizeof(fr)); + fr.lStructSize = sizeof(fr); + fr.hwndOwner = hWnd; + fr.lpstrFindWhat = szFindWhat; + fr.wFindWhatLen = sizeof(szFindWhat); + fr.Flags = FR_HIDEWHOLEWORD | FR_DOWN; + + hFindDlg = FindText(&fr); + } + else + { + // Give focus to the existing find dialog. + ::SetFocus(hFindDlg); + } + return 0; + case ID_PRINT: + if(browser.get()) + browser->GetMainFrame()->Print(); + return 0; + case IDC_NAV_BACK: // Back button + if(browser.get()) + browser->GoBack(); + return 0; + case IDC_NAV_FORWARD: // Forward button + if(browser.get()) + browser->GoForward(); + return 0; + case IDC_NAV_RELOAD: // Reload button + if(browser.get()) + browser->Reload(); + return 0; + case IDC_NAV_STOP: // Stop button + if(browser.get()) + browser->StopLoad(); + return 0; + case ID_TESTS_GETSOURCE: // Test the GetSource function + if(browser.get()) { +#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP + RunGetSourceTest(browser->GetMainFrame()); +#else // !TEST_SINGLE_THREADED_MESSAGE_LOOP + // Execute the GetSource() call on the FILE thread to avoid blocking + // the UI thread when using a multi-threaded message loop + // (issue #79). + class ExecTask : public CefThreadSafeBase + { + public: + ExecTask(CefRefPtr frame) : m_Frame(frame) {} + virtual void Execute(CefThreadId threadId) + { + RunGetSourceTest(m_Frame); + } + private: + CefRefPtr m_Frame; + }; + CefPostTask(TID_FILE, new ExecTask(browser->GetMainFrame())); +#endif // !TEST_SINGLE_THREADED_MESSAGE_LOOP + } + return 0; + case ID_TESTS_GETTEXT: // Test the GetText function + if(browser.get()) { +#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP + RunGetTextTest(browser->GetMainFrame()); +#else // !TEST_SINGLE_THREADED_MESSAGE_LOOP + // Execute the GetText() call on the FILE thread to avoid blocking + // the UI thread when using a multi-threaded message loop + // (issue #79). + class ExecTask : public CefThreadSafeBase + { + public: + ExecTask(CefRefPtr frame) : m_Frame(frame) {} + virtual void Execute(CefThreadId threadId) + { + RunGetTextTest(m_Frame); + } + private: + CefRefPtr m_Frame; + }; + CefPostTask(TID_FILE, new ExecTask(browser->GetMainFrame())); +#endif // !TEST_SINGLE_THREADED_MESSAGE_LOOP + } + return 0; + case ID_TESTS_JAVASCRIPT_BINDING: // Test the V8 binding handler + if(browser.get()) + RunBindingTest(browser); + return 0; + case ID_TESTS_JAVASCRIPT_EXTENSION: // Test the V8 extension handler + if(browser.get()) + RunExtensionTest(browser); + return 0; + case ID_TESTS_JAVASCRIPT_EXECUTE: // Test execution of javascript + if(browser.get()) + RunJavaScriptExecuteTest(browser); + return 0; + case ID_TESTS_PLUGIN: // Test the custom plugin + if(browser.get()) + RunPluginTest(browser); + return 0; + case ID_TESTS_POPUP: // Test a popup window + if(browser.get()) + RunPopupTest(browser); + return 0; + case ID_TESTS_REQUEST: // Test a request + if(browser.get()) + RunRequestTest(browser); + return 0; + case ID_TESTS_SCHEME_HANDLER: // Test the scheme handler + if(browser.get()) + RunSchemeTest(browser); + return 0; + case ID_TESTS_UIAPP: // Test the UI app + if(browser.get()) + RunUIPluginTest(browser); + return 0; + } + } + break; + + case WM_PAINT: + hdc = BeginPaint(hWnd, &ps); + EndPaint(hWnd, &ps); + return 0; + + case WM_SETFOCUS: + if(g_handler.get() && g_handler->GetBrowserHwnd()) + { + // Pass focus to the browser window + PostMessage(g_handler->GetBrowserHwnd(), WM_SETFOCUS, wParam, NULL); + } + return 0; + + case WM_SIZE: + if(g_handler.get() && g_handler->GetBrowserHwnd()) + { + // Resize the browser window and address bar to match the new frame + // window size + RECT rect; + GetClientRect(hWnd, &rect); + rect.top += URLBAR_HEIGHT; + + int urloffset = rect.left + BUTTON_WIDTH * 4; + + HDWP hdwp = BeginDeferWindowPos(1); + hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset, + 0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER); + hdwp = DeferWindowPos(hdwp, g_handler->GetBrowserHwnd(), NULL, + rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, + SWP_NOZORDER); + EndDeferWindowPos(hdwp); + } + break; + + case WM_ERASEBKGND: + if(g_handler.get() && g_handler->GetBrowserHwnd()) + { + // Dont erase the background if the browser window has been loaded + // (this avoids flashing) + return 0; + } + break; + + case WM_DESTROY: + // The frame window has exited + KillTimer(hWnd, 1); + PostQuitMessage(0); + return 0; + } + + return DefWindowProc(hWnd, message, wParam, lParam); + } +} + +// Message handler for about box. +INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + UNREFERENCED_PARAMETER(lParam); + switch (message) + { + case WM_INITDIALOG: + return (INT_PTR)TRUE; + + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) + { + EndDialog(hDlg, LOWORD(wParam)); + return (INT_PTR)TRUE; + } + break; + } + return (INT_PTR)FALSE; +} + + +// ClientHandler implementation + +CefHandler::RetVal ClientHandler::HandleAddressChange( + CefRefPtr browser, CefRefPtr frame, + const std::wstring& url) +{ + if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) + { + // Set the edit window text + SetWindowText(m_EditHwnd, url.c_str()); + } + return RV_CONTINUE; +} + +CefHandler::RetVal ClientHandler::HandleTitleChange( + CefRefPtr browser, const std::wstring& title) +{ + // Set the frame window title bar + CefWindowHandle hwnd = browser->GetWindowHandle(); + if(!browser->IsPopup()) + { + // The frame window will be the parent of the browser window + hwnd = GetParent(hwnd); + } + SetWindowText(hwnd, title.c_str()); + return RV_CONTINUE; +} + +CefHandler::RetVal ClientHandler::HandleBeforeResourceLoad( + CefRefPtr browser, CefRefPtr request, + std::wstring& redirectUrl, CefRefPtr& resourceStream, + std::wstring& mimeType, int loadFlags) +{ + DWORD dwSize; + LPBYTE pBytes; + + std::wstring url = request->GetURL(); + if(url == L"http://tests/request") { + // Show the request contents + std::wstring dump; + DumpRequestContents(request, dump); + resourceStream = CefStreamReader::CreateForData( + (void*)dump.c_str(), dump.size() * sizeof(wchar_t)); + mimeType = L"text/plain"; + } + else if(url == L"http://tests/uiapp") { + // Show the uiapp contents + if(LoadBinaryResource(IDS_UIPLUGIN, dwSize, pBytes)) { + resourceStream = CefStreamReader::CreateForHandler( + new CefByteReadHandler(pBytes, dwSize, NULL)); + mimeType = L"text/html"; + } + } else if(wcsstr(url.c_str(), L"/ps_logo2.png") != NULL) { + // Any time we find "ps_logo2.png" in the URL substitute in our own image + if(LoadBinaryResource(IDS_LOGO, dwSize, pBytes)) { + resourceStream = CefStreamReader::CreateForHandler( + new CefByteReadHandler(pBytes, dwSize, NULL)); + mimeType = L"image/png"; + } + } else if(wcsstr(url.c_str(), L"/logoball.png") != NULL) { + // Load the "logoball.png" image resource. + if(LoadBinaryResource(IDS_LOGOBALL, dwSize, pBytes)) { + resourceStream = CefStreamReader::CreateForHandler( + new CefByteReadHandler(pBytes, dwSize, NULL)); + mimeType = L"image/png"; + } + } + return RV_CONTINUE; +} + +void ClientHandler::SendNotification(NotificationType type) +{ + UINT id; + switch(type) + { + case NOTIFY_CONSOLE_MESSAGE: + id = ID_WARN_DOWNLOADERROR; + break; + case NOTIFY_DOWNLOAD_COMPLETE: + id = ID_WARN_DOWNLOADCOMPLETE; + break; + case NOTIFY_DOWNLOAD_ERROR: + id = ID_WARN_CONSOLEMESSAGE; + break; + default: + return; + } + PostMessage(m_MainHwnd, WM_COMMAND, id, 0); +} + + +// Global functions + +std::wstring AppGetWorkingDirectory() +{ + return szWorkingDir; +} diff --git a/tests/cefclient/clientplugin.cpp b/tests/cefclient/clientplugin.cpp index 9a33d4b2a..44c8b6244 100644 --- a/tests/cefclient/clientplugin.cpp +++ b/tests/cefclient/clientplugin.cpp @@ -5,6 +5,8 @@ #include "clientplugin.h" +#ifdef _WIN32 + // Initialized in NP_Initialize. NPNetscapeFuncs* g_browser = NULL; @@ -184,3 +186,5 @@ void ClientPlugin::RefreshDisplay() { InvalidateRect(NULL, TRUE); UpdateWindow(); } + +#endif // _WIN32 diff --git a/tests/cefclient/clientplugin.h b/tests/cefclient/clientplugin.h index fe46f2ab5..b4e8d0959 100644 --- a/tests/cefclient/clientplugin.h +++ b/tests/cefclient/clientplugin.h @@ -6,7 +6,10 @@ // Portions of this implementation are borrowed from webkit\default_plugin\ // plugin_impl.h -#pragma once +#ifndef _CEFCLIENT_CLIENTPLUGIN_H +#define _CEFCLIENT_CLIENTPLUGIN_H + +#ifdef _WIN32 #include #include @@ -85,4 +88,8 @@ class ClientPlugin : public CWindowImpl { NPP instance_; // The plugin instantiation mode (NP_FULL or NP_EMBED) int16 mode_; -}; \ No newline at end of file +}; + +#endif // _WIN32 + +#endif // _CEFCLIENT_CLIENTPLUGIN_H diff --git a/tests/cefclient/download_handler.cpp b/tests/cefclient/download_handler.cpp index d41e28d1c..3bbc2e110 100644 --- a/tests/cefclient/download_handler.cpp +++ b/tests/cefclient/download_handler.cpp @@ -4,13 +4,15 @@ #include "download_handler.h" #include "util.h" +#include +#include + #ifdef _WIN32 #include #include #include #endif // _WIN32 -#include -#include + namespace { diff --git a/tests/cefclient/download_handler.h b/tests/cefclient/download_handler.h index aef7b69d9..17144f0fc 100644 --- a/tests/cefclient/download_handler.h +++ b/tests/cefclient/download_handler.h @@ -2,7 +2,9 @@ // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. -#pragma once +#ifndef _CEFCLIENT_DOWNLOAD_HANDLER_H +#define _CEFCLIENT_DOWNLOAD_HANDLER_H + #include "include/cef.h" // Implement this interface to receive download notifications. @@ -19,3 +21,5 @@ public: // Create a new download handler to manage download of a single file. CefRefPtr CreateDownloadHandler( CefRefPtr listener, const std::wstring& fileName); + +#endif // _CEFCLIENT_DOWNLOAD_HANDLER_H diff --git a/tests/cefclient/extension_test.h b/tests/cefclient/extension_test.h index cdfcb73a7..154371960 100644 --- a/tests/cefclient/extension_test.h +++ b/tests/cefclient/extension_test.h @@ -2,7 +2,9 @@ // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. -#pragma once +#ifndef _CEFCLIENT_EXTENSION_TEST_H +#define _CEFCLIENT_EXTENSION_TEST_H + #include "include/cef.h" // Register the V8 extension handler. @@ -10,3 +12,5 @@ void InitExtensionTest(); // Run the test. void RunExtensionTest(CefRefPtr browser); + +#endif // _CEFCLIENT_EXTENSION_TEST_H diff --git a/tests/cefclient/plugin_test.h b/tests/cefclient/plugin_test.h index c4ed2ac15..a3a460dfd 100644 --- a/tests/cefclient/plugin_test.h +++ b/tests/cefclient/plugin_test.h @@ -2,7 +2,9 @@ // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. -#pragma once +#ifndef _CEFCLIENT_PLUGIN_TEST_H +#define _CEFCLIENT_PLUGIN_TEST_H + #include "include/cef.h" // Register the internal client plugin. @@ -10,3 +12,5 @@ void InitPluginTest(); // Run the test. void RunPluginTest(CefRefPtr browser); + +#endif // _CEFCLIENT_PLUGIN_TEST_H diff --git a/tests/cefclient/resource_util.h b/tests/cefclient/resource_util.h index 32db5a127..9d473b8d1 100644 --- a/tests/cefclient/resource_util.h +++ b/tests/cefclient/resource_util.h @@ -2,9 +2,16 @@ // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. -#pragma once +#ifndef _CEFCLIENT_RESOURCE_UTIL +#define _CEFCLIENT_RESOURCE_UTIL #include "include/cef.h" +#ifdef _WIN32 + // Load a resource of type BINARY bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes); + +#endif // _WIN32 + +#endif // _CEFCLIENT_RESOURCE_UTIL diff --git a/tests/cefclient/resource_util.cpp b/tests/cefclient/resource_util_win.cpp similarity index 95% rename from tests/cefclient/resource_util.cpp rename to tests/cefclient/resource_util_win.cpp index 3a5b192cc..f09b10b3c 100644 --- a/tests/cefclient/resource_util.cpp +++ b/tests/cefclient/resource_util_win.cpp @@ -4,6 +4,8 @@ #include "resource_util.h" +#ifdef _WIN32 + bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes) { extern HINSTANCE hInst; @@ -23,3 +25,5 @@ bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes) return false; } + +#endif // _WIN32 diff --git a/tests/cefclient/scheme_test.cpp b/tests/cefclient/scheme_test.cpp index 5920257f9..f4a6cd020 100644 --- a/tests/cefclient/scheme_test.cpp +++ b/tests/cefclient/scheme_test.cpp @@ -6,7 +6,10 @@ #include "scheme_test.h" #include "string_util.h" #include "resource_util.h" + +#ifdef _WIN32 #include "resource.h" +#endif // _WIN32 // Implementation of the schema handler for client:// requests. @@ -58,6 +61,7 @@ public: // Set the resulting mime type mime_type = L"text/html"; } +#ifdef _WIN32 else if(wcsstr(url.c_str(), L"client.gif") != NULL) { // Load the response image if(LoadBinaryResource(IDS_LOGO, size_, bytes_)) { @@ -66,6 +70,7 @@ public: mime_type = L"image/jpg"; } } +#endif // _WIN32 // Set the resulting response length *response_length = size_; diff --git a/tests/cefclient/scheme_test.h b/tests/cefclient/scheme_test.h index 2cb192fd3..5655cf90a 100644 --- a/tests/cefclient/scheme_test.h +++ b/tests/cefclient/scheme_test.h @@ -2,7 +2,9 @@ // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. -#pragma once +#ifndef _CEFCLIENT_SCHEME_TEST +#define _CEFCLIENT_SCHEME_TEST + #include "include/cef.h" // Register the scheme handler. @@ -10,3 +12,5 @@ void InitSchemeTest(); // Run the test. void RunSchemeTest(CefRefPtr browser); + +#endif // _CEFCLIENT_SCHEME_TEST diff --git a/tests/cefclient/string_util.cpp b/tests/cefclient/string_util.cpp index 528bdd0ed..d1596fce5 100644 --- a/tests/cefclient/string_util.cpp +++ b/tests/cefclient/string_util.cpp @@ -5,33 +5,6 @@ #include "string_util.h" #include - -std::wstring StringToWString(const std::string& s) -{ - wchar_t* wch; - UINT bytes = MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size()+1, NULL, 0); - wch = new wchar_t[bytes]; - if(wch) - bytes = MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size()+1, wch, bytes); - std::wstring str = wch; - delete [] wch; - return str; -} - -std::string WStringToString(const std::wstring& s) -{ - char* ch; - UINT bytes = WideCharToMultiByte(CP_ACP, 0, s.c_str(), s.size()+1, NULL, 0, - NULL, NULL); - ch = new char[bytes]; - if(ch) - bytes = WideCharToMultiByte(CP_ACP, 0, s.c_str(), s.size()+1, ch, bytes, - NULL, NULL); - std::string str = ch; - delete [] ch; - return str; -} - void DumpRequestContents(CefRefPtr request, std::wstring& str) { std::wstringstream ss; diff --git a/tests/cefclient/string_util.h b/tests/cefclient/string_util.h index 963891c46..c0e7c6cb6 100644 --- a/tests/cefclient/string_util.h +++ b/tests/cefclient/string_util.h @@ -2,7 +2,8 @@ // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. -#pragma once +#ifndef _CEFCLIENT_STRING_UTIL_H +#define _CEFCLIENT_STRING_UTIL_H #include "include/cef.h" #include @@ -19,4 +20,6 @@ void DumpRequestContents(CefRefPtr request, std::wstring& str); // Replace all instances of |from| with |to| in |str|. std::wstring StringReplace(const std::wstring& str, const std::wstring& from, - const std::wstring& to); \ No newline at end of file + const std::wstring& to); + +#endif // _CEFCLIENT_STRING_UTIL_H diff --git a/tests/cefclient/string_util_win.cpp b/tests/cefclient/string_util_win.cpp new file mode 100644 index 000000000..76e2e1e4a --- /dev/null +++ b/tests/cefclient/string_util_win.cpp @@ -0,0 +1,35 @@ +// Copyright (c) 2010 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 "string_util.h" + +#ifdef _WIN32 + +std::wstring StringToWString(const std::string& s) +{ + wchar_t* wch; + UINT bytes = MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size()+1, NULL, 0); + wch = new wchar_t[bytes]; + if(wch) + bytes = MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size()+1, wch, bytes); + std::wstring str = wch; + delete [] wch; + return str; +} + +std::string WStringToString(const std::wstring& s) +{ + char* ch; + UINT bytes = WideCharToMultiByte(CP_ACP, 0, s.c_str(), s.size()+1, NULL, 0, + NULL, NULL); + ch = new char[bytes]; + if(ch) + bytes = WideCharToMultiByte(CP_ACP, 0, s.c_str(), s.size()+1, ch, bytes, + NULL, NULL); + std::string str = ch; + delete [] ch; + return str; +} + +#endif // _WIN32 diff --git a/tests/cefclient/uiplugin.cpp b/tests/cefclient/uiplugin.cpp index 1afc19e31..8a64081f3 100644 --- a/tests/cefclient/uiplugin.cpp +++ b/tests/cefclient/uiplugin.cpp @@ -8,6 +8,7 @@ #include #include +#ifdef _WIN32 // Initialized in NP_Initialize. NPNetscapeFuncs* g_uibrowser = NULL; @@ -281,3 +282,5 @@ void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC) wglDeleteContext(hRC); ReleaseDC(hWnd, hDC); } + +#endif // _WIN32 diff --git a/tests/cefclient/uiplugin.h b/tests/cefclient/uiplugin.h index a42501f78..2f1600449 100644 --- a/tests/cefclient/uiplugin.h +++ b/tests/cefclient/uiplugin.h @@ -6,10 +6,13 @@ // Portions of this implementation are borrowed from webkit\default_plugin\ // plugin_impl.h -#pragma once +#ifndef _CEFCLIENT_UIPLUGIN_H +#define _CEFCLIENT_UIPLUGIN_H #include "include/cef_nplugin.h" +#ifdef _WIN32 + extern NPNetscapeFuncs* g_uibrowser; NPError API_CALL NP_UIGetEntryPoints(NPPluginFuncs* pFuncs); @@ -19,4 +22,8 @@ NPError API_CALL NP_UIShutdown(void); // Function called to modify the rotation value. void ModifyRotation(float value); // Function called to reset the rotation value. -void ResetRotation(); \ No newline at end of file +void ResetRotation(); + +#endif // _WIN32 + +#endif // _CEFCLIENT_UIPLUGIN_H diff --git a/tests/cefclient/uiplugin_test.h b/tests/cefclient/uiplugin_test.h index 1d1579b66..b98229782 100644 --- a/tests/cefclient/uiplugin_test.h +++ b/tests/cefclient/uiplugin_test.h @@ -2,7 +2,9 @@ // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. -#pragma once +#ifndef _CEFCLIENT_UIPLUGIN_TEST_H +#define _CEFCLIENT_UIPLUGIN_TEST_H + #include "include/cef.h" // Register the internal client plugin and V8 extension. @@ -10,3 +12,5 @@ void InitUIPluginTest(); // Run the test. void RunUIPluginTest(CefRefPtr browser); + +#endif // _CEFCLIENT_UIPLUGIN_TEST_H diff --git a/tests/cefclient/util.h b/tests/cefclient/util.h index 42e93fb25..9c46d0f52 100644 --- a/tests/cefclient/util.h +++ b/tests/cefclient/util.h @@ -3,7 +3,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#pragma once +#ifndef _CEFCLIENT_UTIL_H +#define _CEFCLIENT_UTIL_H #ifdef _WIN32 @@ -46,3 +47,5 @@ #ifndef min #define min(a,b) ((a)<(b)?(a):(b)) #endif + +#endif // _CEFCLIENT_UTIL_H