- Remove cefclient dependency on ATL.
- Allow more cefclient tests to work in the off-screen rendering example. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1058 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
26fb351f4a
commit
ee6faa0706
|
@ -1,176 +1,80 @@
|
|||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
// Copyright (c) 2013 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 "cefclient/clientplugin.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
// Initialized in NP_Initialize.
|
||||
NPNetscapeFuncs* g_browser = NULL;
|
||||
#include <windows.h>
|
||||
|
||||
namespace {
|
||||
|
||||
NPError NPP_ClientNew(NPMIMEType plugin_type, NPP instance, uint16_t mode,
|
||||
int16_t argc, char* argn[], char* argv[], NPSavedData* saved) {
|
||||
if (instance == NULL)
|
||||
return NPERR_INVALID_INSTANCE_ERROR;
|
||||
|
||||
ClientPlugin* plugin_impl = new ClientPlugin(mode);
|
||||
plugin_impl->Initialize(GetModuleHandle(NULL), instance, plugin_type, argc,
|
||||
argn, argv);
|
||||
instance->pdata = reinterpret_cast<void*>(plugin_impl);
|
||||
return NPERR_NO_ERROR;
|
||||
// Client plugin window implementation.
|
||||
class ClientPlugin {
|
||||
public:
|
||||
ClientPlugin()
|
||||
: hwnd_(NULL) {
|
||||
}
|
||||
|
||||
NPError NPP_ClientDestroy(NPP instance, NPSavedData** save) {
|
||||
ClientPlugin* plugin_impl = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
|
||||
if (plugin_impl) {
|
||||
plugin_impl->Shutdown();
|
||||
delete plugin_impl;
|
||||
~ClientPlugin() {
|
||||
if (IsWindow(hwnd_))
|
||||
DestroyWindow(hwnd_);
|
||||
}
|
||||
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError NPP_ClientSetWindow(NPP instance, NPWindow* window_info) {
|
||||
if (instance == NULL)
|
||||
return NPERR_INVALID_INSTANCE_ERROR;
|
||||
|
||||
if (window_info == NULL)
|
||||
return NPERR_GENERIC_ERROR;
|
||||
|
||||
ClientPlugin* plugin_impl = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
|
||||
if (plugin_impl == NULL)
|
||||
return NPERR_GENERIC_ERROR;
|
||||
|
||||
HWND window_handle = reinterpret_cast<HWND>(window_info->window);
|
||||
if (!plugin_impl->SetWindow(window_handle)) {
|
||||
delete plugin_impl;
|
||||
return NPERR_GENERIC_ERROR;
|
||||
}
|
||||
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NPError API_CALL NP_ClientGetEntryPoints(NPPluginFuncs* pFuncs) {
|
||||
pFuncs->newp = NPP_ClientNew;
|
||||
pFuncs->destroy = NPP_ClientDestroy;
|
||||
pFuncs->setwindow = NPP_ClientSetWindow;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError API_CALL NP_ClientInitialize(NPNetscapeFuncs* pFuncs) {
|
||||
g_browser = pFuncs;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError API_CALL NP_ClientShutdown(void) {
|
||||
g_browser = NULL;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
// ClientPlugin Implementation
|
||||
|
||||
ClientPlugin::ClientPlugin(int16 mode)
|
||||
: mode_(mode) {
|
||||
}
|
||||
|
||||
ClientPlugin::~ClientPlugin() {
|
||||
}
|
||||
|
||||
bool ClientPlugin::Initialize(HINSTANCE module_handle, NPP instance,
|
||||
NPMIMEType mime_type, int16 argc, char* argn[],
|
||||
char* argv[]) {
|
||||
RefreshDisplay();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ClientPlugin::SetWindow(HWND parent_window) {
|
||||
if (!::IsWindow(parent_window)) {
|
||||
// No window created yet. Ignore this call.
|
||||
if (!IsWindow())
|
||||
return true;
|
||||
// Parent window has been destroyed.
|
||||
Shutdown();
|
||||
return true;
|
||||
}
|
||||
|
||||
RECT parent_rect;
|
||||
|
||||
if (IsWindow()) {
|
||||
::GetClientRect(parent_window, &parent_rect);
|
||||
SetWindowPos(NULL, &parent_rect, SWP_SHOWWINDOW);
|
||||
return true;
|
||||
}
|
||||
// First time in -- no window created by plugin yet.
|
||||
::GetClientRect(parent_window, &parent_rect);
|
||||
Create(parent_window, parent_rect, NULL, WS_CHILD | WS_BORDER);
|
||||
|
||||
UpdateWindow();
|
||||
ShowWindow(SW_SHOW);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClientPlugin::Shutdown() {
|
||||
if (IsWindow()) {
|
||||
DestroyWindow();
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT ClientPlugin::OnPaint(UINT message, WPARAM wparam, LPARAM lparam,
|
||||
BOOL& handled) {
|
||||
PAINTSTRUCT paint_struct;
|
||||
BeginPaint(&paint_struct);
|
||||
Paint(paint_struct.hdc);
|
||||
EndPaint(&paint_struct);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// PrintClient is necessary to support off-screen rendering.
|
||||
LRESULT ClientPlugin::OnPrintClient(UINT message, WPARAM wparam, LPARAM lparam,
|
||||
BOOL& handled) {
|
||||
Paint(reinterpret_cast<HDC>(wparam));
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT ClientPlugin::OnEraseBackGround(UINT message, WPARAM wparam,
|
||||
LPARAM lparam, BOOL& handled) {
|
||||
HDC paint_device_context = reinterpret_cast<HDC>(wparam);
|
||||
RECT erase_rect;
|
||||
GetClipBox(paint_device_context, &erase_rect);
|
||||
HBRUSH brush = CreateSolidBrush(RGB(0, 255, 0));
|
||||
FillRect(paint_device_context, &erase_rect, brush);
|
||||
DeleteObject(brush);
|
||||
return 1;
|
||||
}
|
||||
|
||||
LRESULT ClientPlugin::OnLButtonDown(UINT message, WPARAM wparam, LPARAM lparam,
|
||||
BOOL& handled) {
|
||||
MessageBox(L"You clicked on the client plugin!", L"Client Plugin", MB_OK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ClientPlugin::RefreshDisplay() {
|
||||
if (!IsWindow())
|
||||
void Initialize(HWND parent_hwnd) {
|
||||
if (hwnd_ != NULL)
|
||||
return;
|
||||
|
||||
InvalidateRect(NULL, TRUE);
|
||||
UpdateWindow();
|
||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
|
||||
static bool class_registered = false;
|
||||
if (!class_registered) {
|
||||
// Register the window class.
|
||||
WNDCLASS wc = {0};
|
||||
wc.style = CS_OWNDC;
|
||||
wc.lpfnWndProc = PluginWndProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = hInstance;
|
||||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszClassName = L"ClientPlugin";
|
||||
RegisterClass(&wc);
|
||||
|
||||
class_registered = true;
|
||||
}
|
||||
|
||||
void ClientPlugin::Paint(HDC hdc) {
|
||||
// Create the main window.
|
||||
hwnd_ = CreateWindow(L"ClientPlugin", L"Client Plugin",
|
||||
WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 0, 0, parent_hwnd,
|
||||
NULL, hInstance, NULL);
|
||||
|
||||
SetWindowLongPtr(hwnd_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
|
||||
|
||||
// Size and display the plugin window.
|
||||
RECT parent_rect;
|
||||
GetClientRect(parent_hwnd, &parent_rect);
|
||||
SetWindowPos(hwnd_, NULL, parent_rect.left, parent_rect.top,
|
||||
parent_rect.right - parent_rect.left,
|
||||
parent_rect.bottom - parent_rect.top, SWP_SHOWWINDOW);
|
||||
}
|
||||
|
||||
void EraseBackground(HDC hdc) {
|
||||
RECT erase_rect;
|
||||
GetClipBox(hdc, &erase_rect);
|
||||
HBRUSH brush = CreateSolidBrush(RGB(0, 255, 0));
|
||||
FillRect(hdc, &erase_rect, brush);
|
||||
DeleteObject(brush);
|
||||
}
|
||||
|
||||
void Paint(HDC hdc) {
|
||||
static LPCWSTR text = L"Left click in the green area for a message box!";
|
||||
|
||||
RECT client_rect;
|
||||
GetClientRect(&client_rect);
|
||||
GetClientRect(hwnd_, &client_rect);
|
||||
|
||||
int old_mode = SetBkMode(hdc, TRANSPARENT);
|
||||
COLORREF old_color = SetTextColor(hdc, RGB(0, 0, 255));
|
||||
|
@ -178,12 +82,104 @@ void ClientPlugin::Paint(HDC hdc) {
|
|||
RECT text_rect = client_rect;
|
||||
DrawText(hdc, text, -1, &text_rect, DT_CENTER | DT_CALCRECT);
|
||||
|
||||
client_rect.top = ((client_rect.bottom - client_rect.top)
|
||||
- (text_rect.bottom - text_rect.top)) / 2;
|
||||
client_rect.top = ((client_rect.bottom - client_rect.top) -
|
||||
(text_rect.bottom - text_rect.top)) / 2;
|
||||
DrawText(hdc, text, -1, &client_rect, DT_CENTER);
|
||||
|
||||
SetBkMode(hdc, old_mode);
|
||||
SetTextColor(hdc, old_color);
|
||||
}
|
||||
|
||||
HWND GetWindow() const { return hwnd_; }
|
||||
|
||||
// Plugin window procedure.
|
||||
static LRESULT CALLBACK PluginWndProc(HWND hwnd_, UINT message, WPARAM wParam,
|
||||
LPARAM lParam) {
|
||||
ClientPlugin* plugin =
|
||||
reinterpret_cast<ClientPlugin*>(GetWindowLongPtr(hwnd_, GWLP_USERDATA));
|
||||
|
||||
switch (message) {
|
||||
case WM_DESTROY:
|
||||
return 0;
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
MessageBox(plugin->GetWindow(),
|
||||
L"You clicked on the client plugin!", L"Client Plugin", MB_OK);
|
||||
return 0;
|
||||
|
||||
case WM_PAINT: {
|
||||
PAINTSTRUCT ps;
|
||||
BeginPaint(hwnd_, &ps);
|
||||
plugin->Paint(ps.hdc);
|
||||
EndPaint(hwnd_, &ps);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_PRINTCLIENT:
|
||||
plugin->Paint(reinterpret_cast<HDC>(wParam));
|
||||
return 0;
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
plugin->EraseBackground(reinterpret_cast<HDC>(wParam));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return DefWindowProc(hwnd_, message, wParam, lParam);
|
||||
}
|
||||
|
||||
private:
|
||||
HWND hwnd_;
|
||||
};
|
||||
|
||||
NPError NPP_NewImpl(NPMIMEType plugin_type, NPP instance, uint16 mode,
|
||||
int16 argc, char* argn[], char* argv[],
|
||||
NPSavedData* saved) {
|
||||
if (instance == NULL)
|
||||
return NPERR_INVALID_INSTANCE_ERROR;
|
||||
|
||||
ClientPlugin* plugin = new ClientPlugin();
|
||||
instance->pdata = reinterpret_cast<void*>(plugin);
|
||||
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError NPP_DestroyImpl(NPP instance, NPSavedData** save) {
|
||||
ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
if (plugin)
|
||||
delete plugin;
|
||||
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
|
||||
if (instance == NULL)
|
||||
return NPERR_INVALID_INSTANCE_ERROR;
|
||||
|
||||
if (window_info == NULL)
|
||||
return NPERR_GENERIC_ERROR;
|
||||
|
||||
ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
|
||||
HWND parent_hwnd = reinterpret_cast<HWND>(window_info->window);
|
||||
plugin->Initialize(parent_hwnd);
|
||||
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NPError API_CALL NP_ClientGetEntryPoints(NPPluginFuncs* pFuncs) {
|
||||
pFuncs->newp = NPP_NewImpl;
|
||||
pFuncs->destroy = NPP_DestroyImpl;
|
||||
pFuncs->setwindow = NPP_SetWindowImpl;
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError API_CALL NP_ClientInitialize(NPNetscapeFuncs* pFuncs) {
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
NPError API_CALL NP_ClientShutdown(void) {
|
||||
return NPERR_NO_ERROR;
|
||||
}
|
||||
|
||||
#endif // OS_WIN
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Portions of this implementation are borrowed from webkit\default_plugin\
|
||||
// plugin_impl.h
|
||||
// Copyright (c) 2013 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.
|
||||
|
||||
#ifndef CEF_TESTS_CEFCLIENT_CLIENTPLUGIN_H_
|
||||
#define CEF_TESTS_CEFCLIENT_CLIENTPLUGIN_H_
|
||||
|
@ -14,90 +10,12 @@
|
|||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
#include <atlbase.h> // NOLINT(build/include_order)
|
||||
#include <atlwin.h> // NOLINT(build/include_order)
|
||||
#include "include/cef_nplugin.h"
|
||||
|
||||
extern NPNetscapeFuncs* g_browser;
|
||||
|
||||
NPError API_CALL NP_ClientGetEntryPoints(NPPluginFuncs* pFuncs);
|
||||
NPError API_CALL NP_ClientInitialize(NPNetscapeFuncs* pFuncs);
|
||||
NPError API_CALL NP_ClientShutdown(void);
|
||||
|
||||
|
||||
// Provides the client plugin functionality.
|
||||
class ClientPlugin : public CWindowImpl<ClientPlugin> {
|
||||
public:
|
||||
// mode is the plugin instantiation mode, i.e. whether it is a full
|
||||
// page plugin (NP_FULL) or an embedded plugin (NP_EMBED)
|
||||
explicit ClientPlugin(int16 mode);
|
||||
virtual ~ClientPlugin();
|
||||
|
||||
BEGIN_MSG_MAP(ClientPlugin)
|
||||
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackGround)
|
||||
MESSAGE_HANDLER(WM_PAINT, OnPaint)
|
||||
MESSAGE_HANDLER(WM_PRINTCLIENT, OnPrintClient)
|
||||
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
|
||||
END_MSG_MAP()
|
||||
|
||||
// Initializes the plugin with the instance information, mime type
|
||||
// and the list of parameters passed down to the plugin from the webpage.
|
||||
//
|
||||
// Parameters:
|
||||
// module_handle
|
||||
// The handle to the dll in which this object is instantiated.
|
||||
// instance
|
||||
// The plugins opaque instance handle.
|
||||
// mime_type
|
||||
// Identifies the third party plugin which would be eventually installed.
|
||||
// argc
|
||||
// Indicates the count of arguments passed in from the webpage.
|
||||
// argv
|
||||
// Pointer to the arguments.
|
||||
// Returns true on success.
|
||||
bool Initialize(HINSTANCE module_handle, NPP instance, NPMIMEType mime_type,
|
||||
int16 argc, char* argn[], char* argv[]);
|
||||
|
||||
// Displays the default plugin UI.
|
||||
//
|
||||
// Parameters:
|
||||
// parent_window
|
||||
// Handle to the parent window.
|
||||
bool SetWindow(HWND parent_window);
|
||||
|
||||
// Destroys the install dialog and the plugin window.
|
||||
void Shutdown();
|
||||
|
||||
HWND window() const { return m_hWnd; }
|
||||
|
||||
// Getter for the NPP instance member.
|
||||
const NPP instance() const {
|
||||
return instance_;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Window message handlers.
|
||||
LRESULT OnPaint(UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
|
||||
LRESULT OnPrintClient(UINT message, WPARAM wparam, LPARAM lparam,
|
||||
BOOL& handled);
|
||||
LRESULT OnEraseBackGround(UINT message, WPARAM wparam, LPARAM lparam,
|
||||
BOOL& handled);
|
||||
LRESULT OnLButtonDown(UINT message, WPARAM wparam, LPARAM lparam,
|
||||
BOOL& handled);
|
||||
|
||||
// Enables the plugin window if required and initiates an update of the
|
||||
// the plugin window.
|
||||
void RefreshDisplay();
|
||||
|
||||
void Paint(HDC hdc);
|
||||
|
||||
private:
|
||||
// The plugins opaque instance handle
|
||||
NPP instance_;
|
||||
// The plugin instantiation mode (NP_FULL or NP_EMBED)
|
||||
int16 mode_;
|
||||
};
|
||||
|
||||
#endif // OS_WIN
|
||||
|
||||
#endif // CEF_TESTS_CEFCLIENT_CLIENTPLUGIN_H_
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2011 The Chromium Embedded Framework Authors.
|
||||
// Copyright (c) 2013 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
@ -18,6 +18,7 @@
|
|||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "cefclient/cefclient.h"
|
||||
#include "cefclient/client_handler.h"
|
||||
#include "cefclient/client_popup_handler.h"
|
||||
#include "cefclient/resource.h"
|
||||
#include "cefclient/resource_util.h"
|
||||
|
@ -165,14 +166,12 @@ class ClientOSRHandler : public CefClient,
|
|||
int loadFlags) OVERRIDE {
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
std::string url = request->GetURL();
|
||||
if (url == "http://tests/transparency") {
|
||||
resourceStream = GetBinaryResourceReader(IDS_TRANSPARENCY);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
}
|
||||
|
||||
return false;
|
||||
// Proxy the request to the main ClientHandler.
|
||||
CefRefPtr<CefBrowser> main_browser = AppGetBrowser();
|
||||
CefRefPtr<ClientHandler> handler =
|
||||
static_cast<ClientHandler*>(main_browser->GetClient().get());
|
||||
return handler->OnBeforeResourceLoad(browser, request, redirectUrl,
|
||||
resourceStream, response, loadFlags);
|
||||
}
|
||||
|
||||
// CefDisplayHandler methods
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors. All rights
|
||||
// Copyright (c) 2013 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.
|
||||
|
||||
|
|
|
@ -47,8 +47,6 @@ USAGE
|
|||
|
||||
Visual Studio 2010: Open the cefclient2010.sln solution and build.
|
||||
Visual Studio 2008: Open the cefclient2008.sln solution and build.
|
||||
* If using VS2008 Express Edition add atlthunk.lib to the cefclient
|
||||
Configuration Properties > Linker > Input > Additional Dependencies
|
||||
Visual Studio 2005: Open the cefclient2005.sln solution and build.
|
||||
|
||||
Please visit the CEF Website for additional usage information.
|
||||
|
|
Loading…
Reference in New Issue