- Move frame-related methods from CefBrowser into a new CefFrame class.

- Add CefBrowser::Get*Frame() methods for retrieving the appropriate CefFrame instance.
- Add a CefFrame attribute to CefHandler callback methods where appropriate.
- Add support for V8 JavaScript extensions and values via CefV8Value and CefV8Handler.  Native C++ and user-defined JavaScript object hierarchies may now be created and accessed using the CEF API.
- Remove the CefHandler and CefVariant classes and related CefBrowser methods that have been obsoleted by the addition of CEF V8 support.
- Add the CefRegisterExtension() function for registering system-wide V8 extensions.
- Add the CefHandler::HandleJSBinding() callback method for attaching V8 values to the global frame JavaScript object.  This method replaces the previous technique of calling CefBrowser::AddJSHandler().
- Add new wrapper template methods for simplifying DLL wrapper implementations.
- Move cef_string* files from libcef_dll to libcef so that projects can link libcef statically without errors.
- Fix crashes when CEF exits due to object constructors being executed on non-UI threads if the application is closed while a page is still loading.
- Update the cefclient project to reflect changes and demonstrate the new APIs.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@26 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2009-05-28 00:31:21 +00:00
parent 94dfad49d9
commit c295931b1e
74 changed files with 5168 additions and 4657 deletions

View File

@ -1,29 +1,29 @@
// Copyright (c) 2008 Marshall A. Greenblatt. Portions Copyright (c)
// 2006-2008 Google Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Copyright (c) 2008-2009 Marshall A. Greenblatt. Portions Copyright (c)
// 2006-2009 Google Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 Marshall A. Greenblatt. All rights reserved.
// Copyright (c) 2008-2009 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@ -37,6 +37,17 @@
#include "cef_ptr.h"
#include "cef_types.h"
class CefBrowser;
class CefFrame;
class CefHandler;
class CefPostData;
class CefPostDataElement;
class CefRequest;
class CefStreamReader;
class CefStreamWriter;
class CefV8Handler;
class CefV8Value;
// This function should only be called once when the application is started.
// Create the thread to host the UI message loop. A return value of true
@ -58,6 +69,66 @@ void CefShutdown();
// running in a separate thread.
void CefDoMessageLoopWork();
// Register a new V8 extension with the specified JavaScript extension code and
// handler. Functions implemented by the handler are prototyped using the
// keyword 'native'. The calling of a native function is restricted to the scope
// in which the prototype of the native function is defined.
//
// Example JavaScript extension code:
//
// // create the 'example' global object if it doesn't already exist.
// if (!example)
// example = {};
// // create the 'example.test' global object if it doesn't already exist.
// if (!example.test)
// example.test = {};
// (function() {
// // Define the function 'example.test.myfunction'.
// example.test.myfunction = function() {
// // Call CefV8Handler::Execute() with the function name 'MyFunction'
// // and no arguments.
// native function MyFunction();
// return MyFunction();
// };
// // Define the getter function for parameter 'example.test.myparam'.
// example.test.__defineGetter__('myparam', function() {
// // Call CefV8Handler::Execute() with the function name 'GetMyParam'
// // and no arguments.
// native function GetMyParam();
// return GetMyParam();
// });
// // Define the setter function for parameter 'example.test.myparam'.
// example.test.__defineSetter__('myparam', function(b) {
// // Call CefV8Handler::Execute() with the function name 'SetMyParam'
// // and a single argument.
// native function SetMyParam();
// if(b) SetMyParam(b);
// });
//
// // Extension definitions can also contain normal JavaScript variables
// // and functions.
// var myint = 0;
// example.test.increment = function() {
// myint += 1;
// return myint;
// };
// })();
//
// Example usage in the page:
//
// // Call the function.
// example.test.myfunction();
// // Set the parameter.
// example.test.myparam = value;
// // Get the parameter.
// value = example.test.myparam;
// // Call another function.
// example.test.increment();
//
bool CefRegisterExtension(const std::wstring& extension_name,
const std::wstring& javascript_code,
CefRefPtr<CefV8Handler> handler);
// Interface defining the the reference count implementation methods. All
// framework classes must implement the CefBase class.
@ -148,18 +219,8 @@ protected:
};
class CefHandler;
class CefRequest;
class CefStreamReader;
class CefStreamWriter;
class CefPostData;
class CefPostDataElement;
class CefJSHandler;
class CefVariant;
// Class used to represent a browser window. All methods exposed by this
// class should be thread safe.
// Class used to represent a browser window. All methods exposed by this class
// should be thread safe.
class CefBrowser : public CefBase
{
public:
@ -194,87 +255,10 @@ public:
// Stop loading the page.
virtual void StopLoad() =0;
// Define frame target types. Using TF_FOCUSED will target the focused
// frame and using TF_MAIN will target the main frame.
typedef cef_targetframe_t TargetFrame;
// Execute undo in the target frame.
virtual void Undo(TargetFrame targetFrame) =0;
// Execute redo in the target frame.
virtual void Redo(TargetFrame targetFrame) =0;
// Execute cut in the target frame.
virtual void Cut(TargetFrame targetFrame) =0;
// Execute copy in the target frame.
virtual void Copy(TargetFrame targetFrame) =0;
// Execute paste in the target frame.
virtual void Paste(TargetFrame targetFrame) =0;
// Execute delete in the target frame.
virtual void Delete(TargetFrame targetFrame) =0;
// Execute select all in the target frame.
virtual void SelectAll(TargetFrame targetFrame) =0;
// Set focus for the browser window. If |enable| is true focus will be set
// to the window. Otherwise, focus will be removed.
virtual void SetFocus(bool enable) =0;
// Execute printing in the target frame. The user will be prompted with
// the print dialog appropriate to the operating system.
virtual void Print(TargetFrame targetFrame) =0;
// Save the target frame's HTML source to a temporary file and open it in
// the default text viewing application.
virtual void ViewSource(TargetFrame targetFrame) =0;
// Returns the target frame's HTML source as a string.
virtual std::wstring GetSource(TargetFrame targetFrame) =0;
// Returns the target frame's display text as a string.
virtual std::wstring GetText(TargetFrame targetFrame) =0;
// Load the request represented by the |request| object.
virtual void LoadRequest(CefRefPtr<CefRequest> request) =0;
// Convenience method for loading the specified |url| in the optional target
// |frame|.
virtual void LoadURL(const std::wstring& url, const std::wstring& frame) =0;
// Load the contents of |string| with the optional dummy target |url|.
virtual void LoadString(const std::wstring& string,
const std::wstring& url) =0;
// Load the contents of |stream| with the optional dummy target |url|.
virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url) =0;
// Execute a string of JavaScript code in the specified target frame. The
// |script_url| parameter is the URL where the script in question can be
// found, if any. The renderer may request this URL to show the developer the
// source of the error. The |start_line| parameter is the base line number
// to use for error reporting.
virtual void ExecuteJavaScript(const std::wstring& jsCode,
const std::wstring& scriptUrl,
int startLine, TargetFrame targetFrame) =0;
// Register a new handler tied to the specified JS object |name|. Returns
// true if the handler is registered successfully.
// A JS handler will be accessible to JavaScript as window.<classname>.
virtual bool AddJSHandler(const std::wstring& classname,
CefRefPtr<CefJSHandler> handler) =0;
// Returns true if a JS handler with the specified |name| is currently
// registered.
virtual bool HasJSHandler(const std::wstring& classname) =0;
// Returns the JS handler registered with the specified |name|.
virtual CefRefPtr<CefJSHandler> GetJSHandler(const std::wstring& classname) =0;
// Unregister the JS handler registered with the specified |name|. Returns
// true if the handler is unregistered successfully.
virtual bool RemoveJSHandler(const std::wstring& classname) =0;
// Unregister all JS handlers that are currently registered.
virtual void RemoveAllJSHandlers() =0;
// Retrieve the window handle for this browser.
virtual CefWindowHandle GetWindowHandle() =0;
@ -284,7 +268,87 @@ public:
// Returns the handler for this browser.
virtual CefRefPtr<CefHandler> GetHandler() =0;
// Return the currently loaded URL.
// Returns the main (top-level) frame for the browser window.
virtual CefRefPtr<CefFrame> GetMainFrame() =0;
// Returns the focused frame for the browser window.
virtual CefRefPtr<CefFrame> GetFocusedFrame() =0;
// Returns the frame with the specified name, or NULL if not found.
virtual CefRefPtr<CefFrame> GetFrame(const std::wstring& name) =0;
// Returns the names of all existing frames.
virtual void GetFrameNames(std::vector<std::wstring>& names) =0;
};
// Class used to represent a frame in the browser window. All methods exposed
// by this class should be thread safe.
class CefFrame : public CefBase
{
public:
// Execute undo in this frame.
virtual void Undo() =0;
// Execute redo in this frame.
virtual void Redo() =0;
// Execute cut in this frame.
virtual void Cut() =0;
// Execute copy in this frame.
virtual void Copy() =0;
// Execute paste in this frame.
virtual void Paste() =0;
// Execute delete in this frame.
virtual void Delete() =0;
// Execute select all in this frame.
virtual void SelectAll() =0;
// Execute printing in the this frame. The user will be prompted with the
// print dialog appropriate to the operating system.
virtual void Print() =0;
// Save this frame's HTML source to a temporary file and open it in the
// default text viewing application.
virtual void ViewSource() =0;
// Returns this frame's HTML source as a string.
virtual std::wstring GetSource() =0;
// Returns this frame's display text as a string.
virtual std::wstring GetText() =0;
// Load the request represented by the |request| object.
virtual void LoadRequest(CefRefPtr<CefRequest> request) =0;
// Load the specified |url|.
virtual void LoadURL(const std::wstring& url) =0;
// Load the contents of |string| with the optional dummy target |url|.
virtual void LoadString(const std::wstring& string,
const std::wstring& url) =0;
// Load the contents of |stream| with the optional dummy target |url|.
virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url) =0;
// Execute a string of JavaScript code in this frame. The |script_url|
// parameter is the URL where the script in question can be found, if any.
// The renderer may request this URL to show the developer the source of the
// error. The |start_line| parameter is the base line number to use for error
// reporting.
virtual void ExecuteJavaScript(const std::wstring& jsCode,
const std::wstring& scriptUrl,
int startLine) =0;
// Returns true if this is the main frame.
virtual bool IsMain() =0;
// Returns true if this is the focused frame.
virtual bool IsFocused() =0;
// Returns this frame's name.
virtual std::wstring GetName() =0;
// Return the URL currently loaded in this frame.
virtual std::wstring GetURL() =0;
};
@ -319,9 +383,10 @@ public:
// ignored.
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser) =0;
// Event called when the address bar changes. The return value is currently
// ignored.
// Event called when a frame's address has changed. The return value is
// currently ignored.
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& url) =0;
// Event called when the page title changes. The return value is currently
@ -336,27 +401,34 @@ public:
// modify the |request| object if desired. Return RV_HANDLED to cancel
// navigation.
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType, bool isRedirect) =0;
// Event called when the browser begins loading a page. The return value is
// currently ignored.
virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser) =0;
// 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<CefBrowser> browser,
CefRefPtr<CefFrame> frame) =0;
// Event called when the browser is done loading a page. This event will
// be generated irrespective of whether the request completes successfully.
// The return value is currently ignored.
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser) =0;
// 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<CefBrowser> browser,
CefRefPtr<CefFrame> frame) =0;
// Supported error code values. See net\base\net_error_list.h for complete
// descriptions of the error codes.
typedef cef_handler_errorcode_t ErrorCode;
// Called when the browser fails to load a resource. |errorCode is the
// 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<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const std::wstring& failedUrl,
std::wstring& errorText) =0;
@ -407,6 +479,7 @@ public:
// and footer yourself return RV_HANDLED. Otherwise, populate the approprate
// variables and return RV_CONTINUE.
virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefPrintInfo& printInfo,
const std::wstring& url,
const std::wstring& title,
@ -421,12 +494,14 @@ public:
// 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<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message) =0;
// 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<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message, bool& retval) =0;
// Run a JS prompt request. Return RV_CONTINUE to display the default prompt
@ -434,6 +509,7 @@ public:
// set |retval| to true if the user accepted the prompt and request and
// |result| to the resulting value.
virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message,
const std::wstring& defaultValue,
bool& retval,
@ -448,6 +524,12 @@ public:
// The return value is currently ignored.
virtual RetVal HandleTakeFocus(CefRefPtr<CefBrowser> browser,
bool reverse) =0;
// Event called for adding values to a frame's JavaScript 'window' object. The
// return value is currently ignored.
virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object) =0;
};
@ -464,10 +546,6 @@ public:
virtual std::wstring GetURL() =0;
virtual void SetURL(const std::wstring& url) =0;
// Optional name of the target frame.
virtual std::wstring GetFrame() =0;
virtual void SetFrame(const std::wstring& frame) =0;
// Optional request method type, defaulting to POST if post data is provided
// and GET otherwise.
virtual std::wstring GetMethod() =0;
@ -483,7 +561,6 @@ public:
// Set all values at one time.
virtual void Set(const std::wstring& url,
const std::wstring& frame,
const std::wstring& method,
CefRefPtr<CefPostData> postData,
const HeaderMap& headerMap) =0;
@ -593,72 +670,108 @@ public:
};
// Class for implementing external JavaScript objects.
class CefJSHandler : public CefBase
typedef std::vector<CefRefPtr<CefV8Value>> CefV8ValueList;
// Interface that should be implemented to handle V8 function calls.
class CefV8Handler : public CefBase
{
public:
typedef std::vector<CefRefPtr<CefVariant> > VariantVector;
// Return true if the specified method exists.
virtual bool HasMethod(CefRefPtr<CefBrowser> browser,
const std::wstring& name) =0;
// Return true if the specified property exists.
virtual bool HasProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name) =0;
// Set the property value. Return true if the property is accepted.
virtual bool SetProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
const CefRefPtr<CefVariant> value) =0;
// Get the property value. Return true if the value is returned.
virtual bool GetProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
CefRefPtr<CefVariant> value) =0;
// Execute a method with the specified argument vector and return
// value. Return true if the method was handled.
virtual bool ExecuteMethod(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
const VariantVector& args,
CefRefPtr<CefVariant> retval) =0;
// Execute with the specified argument list and return value. Return true if
// the method was handled.
virtual bool Execute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception) =0;
};
// Class that represents multiple data types as a single object.
class CefVariant : public CefBase
// Class representing a V8 value.
class CefV8Value : public CefBase
{
public:
typedef cef_variant_type_t Type;
// Create a new value of the specified type. These functions should only be
// called from within the JavaScript context -- either in a
// CefV8Handler::Execute() callback or a CefHandler::HandleScriptBinding()
// callback.
static CefRefPtr<CefV8Value> CreateUndefined();
static CefRefPtr<CefV8Value> CreateNull();
static CefRefPtr<CefV8Value> CreateBool(bool value);
static CefRefPtr<CefV8Value> CreateInt(int value);
static CefRefPtr<CefV8Value> CreateDouble(double value);
static CefRefPtr<CefV8Value> CreateString(const std::wstring& value);
static CefRefPtr<CefV8Value> CreateObject(CefRefPtr<CefBase> user_data);
static CefRefPtr<CefV8Value> CreateArray();
static CefRefPtr<CefV8Value> CreateFunction(const std::wstring& name,
CefRefPtr<CefV8Handler> handler);
// Return the variant data type.
virtual Type GetType() =0;
// Check the value type.
virtual bool IsUndefined() =0;
virtual bool IsNull() =0;
virtual bool IsBool() =0;
virtual bool IsInt() =0;
virtual bool IsDouble() =0;
virtual bool IsString() =0;
virtual bool IsObject() =0;
virtual bool IsArray() =0;
virtual bool IsFunction() =0;
// Return a primitive value type. The underlying data will be converted to
// the requested type if necessary.
virtual bool GetBoolValue() =0;
virtual int GetIntValue() =0;
virtual double GetDoubleValue() =0;
virtual std::wstring GetStringValue() =0;
// Assign various data types.
virtual void SetNull() =0;
virtual void SetBool(bool val) =0;
virtual void SetInt(int val) =0;
virtual void SetDouble(double val) =0;
virtual void SetString(const std::wstring& val) =0;
virtual void SetBoolArray(const std::vector<bool>& val) =0;
virtual void SetIntArray(const std::vector<int>& val) =0;
virtual void SetDoubleArray(const std::vector<double>& val) =0;
virtual void SetStringArray(const std::vector<std::wstring>& val) =0;
// Retrieve various data types.
virtual bool GetBool() =0;
virtual int GetInt() =0;
virtual double GetDouble() =0;
virtual std::wstring GetString() =0;
virtual bool GetBoolArray(std::vector<bool>& val) =0;
virtual bool GetIntArray(std::vector<int>& val) =0;
virtual bool GetDoubleArray(std::vector<double>& val) =0;
virtual bool GetStringArray(std::vector<std::wstring>& val) =0;
// OBJECT METHODS - These methods are only available on objects. Arrays and
// functions are also objects. String- and integer-based keys can be used
// interchangably with the framework converting between them as necessary.
// Keys beginning with "Cef::" and "v8::" are reserved by the system.
// Returns the number of values in the array. Returns -1 if the variant
// is not an array type.
virtual int GetArraySize() =0;
// Returns true if the object has a value with the specified identifier.
virtual bool HasValue(const std::wstring& key) =0;
virtual bool HasValue(int index) =0;
// Delete the value with the specified identifier.
virtual bool DeleteValue(const std::wstring& key) =0;
virtual bool DeleteValue(int index) =0;
// Returns the value with the specified identifier.
virtual CefRefPtr<CefV8Value> GetValue(const std::wstring& key) =0;
virtual CefRefPtr<CefV8Value> GetValue(int index) =0;
// Associate value with the specified identifier.
virtual bool SetValue(const std::wstring& key, CefRefPtr<CefV8Value> value) =0;
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value) =0;
// Read the keys for the object's values into the specified vector. Integer-
// based keys will also be returned as strings.
virtual bool GetKeys(std::vector<std::wstring>& keys) =0;
// Returns the user data, if any, specified when the object was created.
virtual CefRefPtr<CefBase> GetUserData() =0;
// ARRAY METHODS - These methods are only available on arrays.
// Returns the number of elements in the array.
virtual int GetArrayLength() =0;
// FUNCTION METHODS - These methods are only available on functions.
// Returns the function name.
virtual std::wstring GetFunctionName() =0;
// Returns the function handler or NULL if not a CEF-created function.
virtual CefRefPtr<CefV8Handler> GetFunctionHandler() =0;
// Execute the function.
virtual bool ExecuteFunction(CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception) =0;
};
#endif // _CEF_H

View File

@ -37,6 +37,7 @@ extern "C" {
#include "cef_export.h"
#include "cef_string.h"
#include "cef_string_list.h"
#include "cef_string_map.h"
#include "cef_types.h"
@ -62,6 +63,66 @@ CEF_EXPORT void cef_shutdown();
// running in a separate thread.
CEF_EXPORT void cef_do_message_loop_work();
// Register a new V8 extension with the specified JavaScript extension code and
// handler. Functions implemented by the handler are prototyped using the
// keyword 'native'. The calling of a native function is restricted to the scope
// in which the prototype of the native function is defined.
//
// Example JavaScript extension code:
//
// // create the 'example' global object if it doesn't already exist.
// if (!example)
// example = {};
// // create the 'example.test' global object if it doesn't already exist.
// if (!example.test)
// example.test = {};
// (function() {
// // Define the function 'example.test.myfunction'.
// example.test.myfunction = function() {
// // Call CefV8Handler::Execute() with the function name 'MyFunction'
// // and no arguments.
// native function MyFunction();
// return MyFunction();
// };
// // Define the getter function for parameter 'example.test.myparam'.
// example.test.__defineGetter__('myparam', function() {
// // Call CefV8Handler::Execute() with the function name 'GetMyParam'
// // and no arguments.
// native function GetMyParam();
// return GetMyParam();
// });
// // Define the setter function for parameter 'example.test.myparam'.
// example.test.__defineSetter__('myparam', function(b) {
// // Call CefV8Handler::Execute() with the function name 'SetMyParam'
// // and a single argument.
// native function SetMyParam();
// if(b) SetMyParam(b);
// });
//
// // Extension definitions can also contain normal JavaScript variables
// // and functions.
// var myint = 0;
// example.test.increment = function() {
// myint += 1;
// return myint;
// };
// })();
//
// Example usage in the page:
//
// // Call the function.
// example.test.myfunction();
// // Set the parameter.
// example.test.myparam = value;
// // Get the parameter.
// value = example.test.myparam;
// // Call another function.
// example.test.increment();
//
CEF_EXPORT int cef_register_extension(const wchar_t* extension_name,
const wchar_t* javascript_code,
struct _cef_v8handler_t* handler);
typedef struct _cef_base_t
{
@ -85,6 +146,7 @@ typedef struct _cef_base_t
#define CEF_MEMBER_MISSING(s, f) (!CEF_MEMBER_EXISTS(s, f) || !((s)->f))
// Structure used to represent a browser window. All functions exposed by this
// structure should be thread safe.
typedef struct _cef_browser_t
@ -105,101 +167,10 @@ typedef struct _cef_browser_t
// Stop loading the page.
void (CEF_CALLBACK *stop_load)(struct _cef_browser_t* browser);
// Execute undo in the target frame.
void (CEF_CALLBACK *undo)(struct _cef_browser_t* browser,
enum cef_targetframe_t targetFrame);
// Execute redo in the target frame.
void (CEF_CALLBACK *redo)(struct _cef_browser_t* browser,
enum cef_targetframe_t targetFrame);
// Execute cut in the target frame.
void (CEF_CALLBACK *cut)(struct _cef_browser_t* browser,
enum cef_targetframe_t targetFrame);
// Execute copy in the target frame.
void (CEF_CALLBACK *copy)(struct _cef_browser_t* browser,
enum cef_targetframe_t targetFrame);
// Execute paste in the target frame.
void (CEF_CALLBACK *paste)(struct _cef_browser_t* browser,
enum cef_targetframe_t targetFrame);
// Execute delete in the target frame.
void (CEF_CALLBACK *del)(struct _cef_browser_t* browser,
enum cef_targetframe_t targetFrame);
// Execute select all in the target frame.
void (CEF_CALLBACK *select_all)(struct _cef_browser_t* browser,
enum cef_targetframe_t targetFrame);
// Set focus for the browser window. If |enable| is true (1) focus will be
// set to the window. Otherwise, focus will be removed.
void (CEF_CALLBACK *set_focus)(struct _cef_browser_t* browser, int enable);
// Execute printing in the target frame. The user will be prompted with
// the print dialog appropriate to the operating system.
void (CEF_CALLBACK *print)(struct _cef_browser_t* browser,
enum cef_targetframe_t targetFrame);
// Save the target frame's HTML source to a temporary file and open it in
// the default text viewing application.
void (CEF_CALLBACK *view_source)(struct _cef_browser_t* browser,
enum cef_targetframe_t targetFrame);
// Returns the target frame's HTML source as a string. The returned string
// must be released using cef_string_free().
cef_string_t (CEF_CALLBACK *get_source)(struct _cef_browser_t* browser,
enum cef_targetframe_t targetFrame);
// Returns the target frame's display text as a string. The returned string
// must be released using cef_string_free().
cef_string_t (CEF_CALLBACK *get_text)(struct _cef_browser_t* browser,
enum cef_targetframe_t targetFrame);
// Load the request represented by the |request| object.
void (CEF_CALLBACK *load_request)(struct _cef_browser_t* browser,
struct _cef_request_t* request);
// Convenience method for loading the specified |url| in the optional target
// |frame|.
void (CEF_CALLBACK *load_url)(struct _cef_browser_t* browser,
const wchar_t* url, const wchar_t* frame);
// Load the contents of |string| with the optional dummy target |url|.
void (CEF_CALLBACK *load_string)(struct _cef_browser_t* browser,
const wchar_t* string, const wchar_t* url);
// Load the contents of |stream| with the optional dummy target |url|.
void (CEF_CALLBACK *load_stream)(struct _cef_browser_t* browser,
struct _cef_stream_reader_t* stream, const wchar_t* url);
// Execute a string of JavaScript code in the specified target frame. The
// |script_url| parameter is the URL where the script in question can be
// found, if any. The renderer may request this URL to show the developer the
// source of the error. The |start_line| parameter is the base line number
// to use for error reporting.
void (CEF_CALLBACK *execute_javascript)(struct _cef_browser_t* browser,
const wchar_t* jsCode, const wchar_t* scriptUrl, int startLine,
enum cef_targetframe_t targetFrame);
// Register a new handler tied to the specified JS object |name|. Returns
// true if the handler is registered successfully.
// A JS handler will be accessible to JavaScript as window.<classname>.
int (CEF_CALLBACK *add_jshandler)(struct _cef_browser_t* browser,
const wchar_t* classname, struct _cef_jshandler_t* handler);
// Returns true if a JS handler with the specified |name| is currently
// registered.
int (CEF_CALLBACK *has_jshandler)(struct _cef_browser_t* browser,
const wchar_t* classname);
// Returns the JS handler registered with the specified |name|.
struct _cef_jshandler_t* (CEF_CALLBACK *get_jshandler)(
struct _cef_browser_t* browser, const wchar_t* classname);
// Unregister the JS handler registered with the specified |name|. Returns
// true if the handler is unregistered successfully.
int (CEF_CALLBACK *remove_jshandler)(struct _cef_browser_t* browser,
const wchar_t* classname);
// Unregister all JS handlers that are currently registered.
void (CEF_CALLBACK *remove_all_jshandlers)(struct _cef_browser_t* browser);
// Retrieve the window handle for this browser.
cef_window_handle_t (CEF_CALLBACK *get_window_handle)(
struct _cef_browser_t* browser);
@ -209,13 +180,104 @@ typedef struct _cef_browser_t
// Returns the handler for this browser.
struct _cef_handler_t* (CEF_CALLBACK *get_handler)(
struct _cef_browser_t* browser);
// Return the currently loaded URL. The returned string must be released
// using cef_string_free().
cef_string_t (CEF_CALLBACK *get_url)(struct _cef_browser_t* browser);
struct _cef_browser_t* browser);
// Returns the main (top-level) frame for the browser window.
struct _cef_frame_t* (CEF_CALLBACK *get_main_frame)(
struct _cef_browser_t* browser);
// Returns the focused frame for the browser window.
struct _cef_frame_t* (CEF_CALLBACK *get_focused_frame)(
struct _cef_browser_t* browser);
// Returns the frame with the specified name, or NULL if not found.
struct _cef_frame_t* (CEF_CALLBACK *get_frame)(
struct _cef_browser_t* browser,
const wchar_t* name);
// Reads the names of all existing frames into the provided string list.
size_t (CEF_CALLBACK *get_frame_names)(struct _cef_browser_t* browser,
cef_string_list_t list);
} cef_browser_t;
// Structure used to represent a frame in the browser window. All functions
// exposed by this structure should be thread safe.
typedef struct _cef_frame_t
{
// Base structure
cef_base_t base;
// Execute undo in this frame.
void (CEF_CALLBACK *undo)(struct _cef_frame_t* frame);
// Execute redo in this frame.
void (CEF_CALLBACK *redo)(struct _cef_frame_t* frame);
// Execute cut in this frame.
void (CEF_CALLBACK *cut)(struct _cef_frame_t* frame);
// Execute copy in this frame.
void (CEF_CALLBACK *copy)(struct _cef_frame_t* frame);
// Execute paste in this frame.
void (CEF_CALLBACK *paste)(struct _cef_frame_t* frame);
// Execute delete in this frame.
void (CEF_CALLBACK *del)(struct _cef_frame_t* frame);
// Execute select all in this frame.
void (CEF_CALLBACK *select_all)(struct _cef_frame_t* frame);
// Execute printing in the this frame. The user will be prompted with the
// print dialog appropriate to the operating system.
void (CEF_CALLBACK *print)(struct _cef_frame_t* frame);
// Save this frame's HTML source to a temporary file and open it in the
// default text viewing application.
void (CEF_CALLBACK *view_source)(struct _cef_frame_t* frame);
// Returns this frame's HTML source as a string. The returned string must be
// released using cef_string_free().
cef_string_t (CEF_CALLBACK *get_source)(struct _cef_frame_t* frame);
// Returns this frame's display text as a string. The returned string must be
// released using cef_string_free().
cef_string_t (CEF_CALLBACK *get_text)(struct _cef_frame_t* frame);
// Load the request represented by the |request| object.
void (CEF_CALLBACK *load_request)(struct _cef_frame_t* frame,
struct _cef_request_t* request);
// Load the specified |url|.
void (CEF_CALLBACK *load_url)(struct _cef_frame_t* frame,
const wchar_t* url);
// Load the contents of |string| with the optional dummy target |url|.
void (CEF_CALLBACK *load_string)(struct _cef_frame_t* frame,
const wchar_t* string, const wchar_t* url);
// Load the contents of |stream| with the optional dummy target |url|.
void (CEF_CALLBACK *load_stream)(struct _cef_frame_t* frame,
struct _cef_stream_reader_t* stream, const wchar_t* url);
// Execute a string of JavaScript code in this frame. The |script_url|
// parameter is the URL where the script in question can be found, if any.
// The renderer may request this URL to show the developer the source of the
// error. The |start_line| parameter is the base line number to use for error
// reporting.
void (CEF_CALLBACK *execute_javascript)(struct _cef_frame_t* frame,
const wchar_t* jsCode, const wchar_t* scriptUrl, int startLine);
// Returns true (1) if this is the main frame.
int (CEF_CALLBACK *is_main)(struct _cef_frame_t* frame);
// Returns true (1) if this is the focused frame.
int (CEF_CALLBACK *is_focused)(struct _cef_frame_t* frame);
// Returns this frame's name. The returned string must be released using
// cef_string_free().
cef_string_t (CEF_CALLBACK *get_name)(struct _cef_frame_t* frame);
// Returns the currently loaded URL. The returned string must be released
// using cef_string_free().
cef_string_t (CEF_CALLBACK *get_url)(struct _cef_frame_t* frame);
} cef_frame_t;
// Structure used to handle events generated by the browser window. All methods
@ -247,7 +309,7 @@ typedef struct _cef_handler_t
// ignored.
enum cef_retval_t (CEF_CALLBACK *handle_address_change)(
struct _cef_handler_t* handler, cef_browser_t* browser,
const wchar_t* url);
cef_frame_t* frame, const wchar_t* url);
// Event called when the page title changes. The return value is currently
// ignored.
@ -260,19 +322,24 @@ typedef struct _cef_handler_t
// navigation.
enum cef_retval_t (CEF_CALLBACK *handle_before_browse)(
struct _cef_handler_t* handler, cef_browser_t* browser,
struct _cef_request_t* request, cef_handler_navtype_t navType,
int isRedirect);
cef_frame_t* frame, struct _cef_request_t* request,
cef_handler_navtype_t navType, int isRedirect);
// Event called when the browser begins loading a page. The return value is
// currently ignored.
// Event called when the browser begins loading a page. The |frame| pointer
// will be NULL if the event represents the overall load status and not the
// load status for a particular frame. The return value is currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_load_start)(
struct _cef_handler_t* handler, cef_browser_t* browser);
struct _cef_handler_t* handler, cef_browser_t* browser,
cef_frame_t* frame);
// Event called when the browser is done loading a page. This event will
// be generated irrespective of whether the request completes successfully.
// The return value is currently ignored.
// Event called when the browser is done loading a page. The |frame| pointer
// will be NULL 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.
enum cef_retval_t (CEF_CALLBACK *handle_load_end)(
struct _cef_handler_t* handler, cef_browser_t* browser);
struct _cef_handler_t* handler, cef_browser_t* browser,
cef_frame_t* 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
@ -280,8 +347,8 @@ typedef struct _cef_handler_t
// RV_HANDLED. Otherwise, return RV_CONTINUE for the default error text.
enum cef_retval_t (CEF_CALLBACK *handle_load_error)(
struct _cef_handler_t* handler, cef_browser_t* browser,
cef_handler_errorcode_t errorCode, const wchar_t* failedUrl,
cef_string_t* errorText);
cef_frame_t* frame, cef_handler_errorcode_t errorCode,
const wchar_t* failedUrl, cef_string_t* 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
@ -326,9 +393,9 @@ typedef struct _cef_handler_t
// variables and return RV_CONTINUE.
enum cef_retval_t (CEF_CALLBACK *handle_print_header_footer)(
struct _cef_handler_t* handler, cef_browser_t* browser,
cef_print_info_t* printInfo, const wchar_t* url, const wchar_t* title,
int currentPage, int maxPages, cef_string_t* topLeft,
cef_string_t* topCenter, cef_string_t* topRight,
cef_frame_t* frame, cef_print_info_t* printInfo, const wchar_t* url,
const wchar_t* title, int currentPage, int maxPages,
cef_string_t* topLeft, cef_string_t* topCenter, cef_string_t* topRight,
cef_string_t* bottomLeft, cef_string_t* bottomCenter,
cef_string_t* bottomRight);
@ -336,14 +403,14 @@ typedef struct _cef_handler_t
// or RV_HANDLED if you displayed a custom alert.
enum cef_retval_t (CEF_CALLBACK *handle_jsalert)(
struct _cef_handler_t* handler, cef_browser_t* browser,
const wchar_t* message);
cef_frame_t* frame, const wchar_t* message);
// 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 (1) if the user accepted the confirmation.
enum cef_retval_t (CEF_CALLBACK *handle_jsconfirm)(
struct _cef_handler_t* handler, cef_browser_t* browser,
const wchar_t* message, int* retval);
cef_frame_t* frame, const wchar_t* message, int* retval);
// 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
@ -351,8 +418,8 @@ typedef struct _cef_handler_t
// |result| to the resulting value.
enum cef_retval_t (CEF_CALLBACK *handle_jsprompt)(
struct _cef_handler_t* handler, cef_browser_t* browser,
const wchar_t* message, const wchar_t* defaultValue, int* retval,
cef_string_t* result);
cef_frame_t* frame, const wchar_t* message, const wchar_t* defaultValue,
int* retval, cef_string_t* result);
// Called just before a window is closed. The return value is currently
// ignored.
@ -365,6 +432,11 @@ typedef struct _cef_handler_t
enum cef_retval_t (CEF_CALLBACK *handle_take_focus)(
struct _cef_handler_t* handler, cef_browser_t* browser, int reverse);
// Event called for adding values to a frame's JavaScript 'window' object. The
// return value is currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_jsbinding)(
struct _cef_handler_t* handler, cef_browser_t* browser,
cef_frame_t* frame, struct _cef_v8value_t* object);
} cef_handler_t;
@ -379,11 +451,6 @@ typedef struct _cef_request_t
void (CEF_CALLBACK *set_url)(struct _cef_request_t* request,
const wchar_t* url);
// Optional name of the target frame.
cef_string_t (CEF_CALLBACK *get_frame)(struct _cef_request_t* request);
void (CEF_CALLBACK *set_frame)(struct _cef_request_t* request,
const wchar_t* frame);
// Optional request method type, defaulting to POST if post data is provided
// and GET otherwise.
cef_string_t (CEF_CALLBACK *get_method)(struct _cef_request_t* request);
@ -404,8 +471,8 @@ typedef struct _cef_request_t
// Set all values at one time.
void (CEF_CALLBACK *set)(struct _cef_request_t* request, const wchar_t* url,
const wchar_t* frame, const wchar_t* method,
struct _cef_post_data_t* postData, cef_string_map_t headerMap);
const wchar_t* method, struct _cef_post_data_t* postData,
cef_string_map_t headerMap);
} cef_request_t;
@ -527,85 +594,113 @@ typedef struct _cef_stream_writer_t
} cef_stream_writer_t;
// Structure for implementing external JavaScript objects.
typedef struct _cef_jshandler_t
// Structure that should be implemented to handle V8 function calls.
typedef struct _cef_v8handler_t
{
// Base structure
cef_base_t base;
// Return true if the specified method exists.
bool (CEF_CALLBACK *has_method)(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name);
// Return true if the specified property exists.
bool (CEF_CALLBACK *has_property)(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name);
// Set the property value. Return true if the property is accepted.
bool (CEF_CALLBACK *set_property)(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name,
struct _cef_variant_t* value);
// Get the property value. Return true if the value is returned.
bool (CEF_CALLBACK *get_property)(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name,
struct _cef_variant_t* value);
// Execute a method with the specified argument vector and return
// value. Return true if the method was handled.
bool (CEF_CALLBACK *execute_method)(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name, size_t numargs,
struct _cef_variant_t** args, struct _cef_variant_t* retval);
int (CEF_CALLBACK *execute)(struct _cef_v8handler_t* v8handler,
const wchar_t* name, struct _cef_v8value_t* object, size_t numargs,
struct _cef_v8value_t** args, struct _cef_v8value_t** retval,
cef_string_t* exception);
} cef_jshandler_t;
} cef_v8handler_t;
typedef struct _cef_variant_t
// Structure representing a V8 value.
typedef struct _cef_v8value_t
{
// Base structure
cef_base_t base;
// Return the variant data type.
cef_variant_type_t (CEF_CALLBACK *get_type)(struct _cef_variant_t* variant);
// Assign various data types.
void (CEF_CALLBACK *set_null)(struct _cef_variant_t* variant);
void (CEF_CALLBACK *set_bool)(struct _cef_variant_t* variant, int val);
void (CEF_CALLBACK *set_int)(struct _cef_variant_t* variant, int val);
void (CEF_CALLBACK *set_double)(struct _cef_variant_t* variant, double val);
void (CEF_CALLBACK *set_string)(struct _cef_variant_t* variant,
const wchar_t* val);
void (CEF_CALLBACK *set_bool_array)(struct _cef_variant_t* variant,
size_t count, const int* vals);
void (CEF_CALLBACK *set_int_array)(struct _cef_variant_t* variant,
size_t count, const int* vals);
void (CEF_CALLBACK *set_double_array)(struct _cef_variant_t* variant,
size_t count, const double* vals);
void (CEF_CALLBACK *set_string_array)(struct _cef_variant_t* variant,
size_t count, const cef_string_t* vals);
// Retrieve various data types.
int (CEF_CALLBACK *get_bool)(struct _cef_variant_t* variant);
int (CEF_CALLBACK *get_int)(struct _cef_variant_t* variant);
double (CEF_CALLBACK *get_double)(struct _cef_variant_t* variant);
cef_string_t (CEF_CALLBACK *get_string)(struct _cef_variant_t* variant);
// Check the value type.
int (CEF_CALLBACK *is_undefined)(struct _cef_v8value_t* v8value);
int (CEF_CALLBACK *is_null)(struct _cef_v8value_t* v8value);
int (CEF_CALLBACK *is_bool)(struct _cef_v8value_t* v8value);
int (CEF_CALLBACK *is_int)(struct _cef_v8value_t* v8value);
int (CEF_CALLBACK *is_double)(struct _cef_v8value_t* v8value);
int (CEF_CALLBACK *is_string)(struct _cef_v8value_t* v8value);
int (CEF_CALLBACK *is_object)(struct _cef_v8value_t* v8value);
int (CEF_CALLBACK *is_array)(struct _cef_v8value_t* v8value);
int (CEF_CALLBACK *is_function)(struct _cef_v8value_t* v8value);
// Returns the number of values in the array. Returns -1 if the variant
// is not an array type.
int (CEF_CALLBACK *get_array_size)(struct _cef_variant_t* variant);
// Return a primitive value type. The underlying data will be converted to
// the requested type if necessary.
int (CEF_CALLBACK *get_bool_value)(struct _cef_v8value_t* v8value);
int (CEF_CALLBACK *get_int_value)(struct _cef_v8value_t* v8value);
double (CEF_CALLBACK *get_double_value)(struct _cef_v8value_t* v8value);
// The returned string must be released using cef_string_free().
cef_string_t (CEF_CALLBACK *get_string_value)(struct _cef_v8value_t* v8value);
// Reads up to |maxcount| values into the specified |vals| array. Returns
// the number of values actually read in.
size_t (CEF_CALLBACK *get_bool_array)(struct _cef_variant_t* variant,
size_t maxcount, int* vals);
size_t (CEF_CALLBACK *get_int_array)(struct _cef_variant_t* variant,
size_t maxcount, int* vals);
size_t (CEF_CALLBACK *get_double_array)(struct _cef_variant_t* variant,
size_t maxcount, double* vals);
size_t (CEF_CALLBACK *get_string_array)(struct _cef_variant_t* variant,
size_t maxcount, cef_string_t* vals);
// OBJECT METHODS - These methods are only available on objects. Arrays and
// functions are also objects. String- and integer-based keys can be used
// interchangably with the framework converting between them as necessary.
// Keys beginning with "Cef::" and "v8::" are reserved by the system.
// Returns true if the object has a value with the specified identifier.
int (CEF_CALLBACK *has_value_bykey)(struct _cef_v8value_t* v8value,
const wchar_t* key);
int (CEF_CALLBACK *has_value_byindex)(struct _cef_v8value_t* v8value,
int index);
// Delete the value with the specified identifier.
int (CEF_CALLBACK *delete_value_bykey)(struct _cef_v8value_t* v8value,
const wchar_t* key);
int (CEF_CALLBACK *delete_value_byindex)(struct _cef_v8value_t* v8value,
int index);
// Returns the value with the specified identifier.
struct _cef_v8value_t* (CEF_CALLBACK *get_value_bykey)(
struct _cef_v8value_t* v8value,
const wchar_t* key);
struct _cef_v8value_t* (CEF_CALLBACK *get_value_byindex)(
struct _cef_v8value_t* v8value,
int index);
// Associate value with the specified identifier.
int (CEF_CALLBACK *set_value_bykey)(struct _cef_v8value_t* v8value,
const wchar_t* key, struct _cef_v8value_t* new_value);
int (CEF_CALLBACK *set_value_byindex)(struct _cef_v8value_t* v8value,
int index, struct _cef_v8value_t* new_value);
// Read the keys for the object's values into the specified vector. Integer-
// based keys will also be returned as strings.
int (CEF_CALLBACK *get_keys)(struct _cef_v8value_t* v8value,
cef_string_list_t list);
// Returns the user data, if any, specified when the object was created.
struct _cef_base_t* (CEF_CALLBACK *get_user_data)(
struct _cef_v8value_t* v8value);
// ARRAY METHODS - These methods are only available on arrays.
// Returns the number of elements in the array.
int (CEF_CALLBACK *get_array_length)(struct _cef_v8value_t* v8value);
// FUNCTION METHODS - These methods are only available on functions.
// Returns the function name. The returned string must be released using
// cef_string_free().
cef_string_t (CEF_CALLBACK *get_function_name)(
struct _cef_v8value_t* v8value);
// Returns the function handler or NULL if not a CEF-created function.
struct _cef_v8handler_t* (CEF_CALLBACK *get_function_handler)(
struct _cef_v8value_t* v8value);
// Execute the function.
int (CEF_CALLBACK *execute_function)(struct _cef_v8value_t* v8value,
struct _cef_v8value_t* object, size_t numargs,
struct _cef_v8value_t** args, struct _cef_v8value_t** retval,
cef_string_t* exception);
} cef_variant_t;
} cef_v8value_t;
// Create a new browser window using the window parameters specified
@ -642,6 +737,21 @@ CEF_EXPORT cef_stream_reader_t* cef_create_stream_reader_for_file(
CEF_EXPORT cef_stream_reader_t* cef_create_stream_reader_for_data(void *data,
size_t size);
// Create a new value of the specified type. These functions should only be
// called from within the JavaScript context -- either in a
// cef_v8handler_t::execute callback or a cef_handler_t::handle_script_binding
// callback.
CEF_EXPORT cef_v8value_t* cef_create_v8value_undefined();
CEF_EXPORT cef_v8value_t* cef_create_v8value_null();
CEF_EXPORT cef_v8value_t* cef_create_v8value_bool(int value);
CEF_EXPORT cef_v8value_t* cef_create_v8value_int(int value);
CEF_EXPORT cef_v8value_t* cef_create_v8value_double(double value);
CEF_EXPORT cef_v8value_t* cef_create_v8value_string(const wchar_t* value);
CEF_EXPORT cef_v8value_t* cef_create_v8value_object(cef_base_t* user_data);
CEF_EXPORT cef_v8value_t* cef_create_v8value_array();
CEF_EXPORT cef_v8value_t* cef_create_v8value_function(const wchar_t* name,
cef_v8handler_t* handler);
#ifdef __cplusplus
}

67
include/cef_string_list.h Normal file
View File

@ -0,0 +1,67 @@
// Copyright (c) 2009 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef _CEF_STRING_LIST_H
#define _CEF_STRING_LIST_H
#ifdef __cplusplus
extern "C" {
#endif
#include "cef_export.h"
#include "cef_string.h"
#include <wchar.h>
// CEF string maps are a set of key/value string pairs.
typedef void* cef_string_list_t;
// Allocate a new string map.
CEF_EXPORT cef_string_list_t cef_string_list_alloc();
// Return the number of elements in the string list.
CEF_EXPORT int cef_string_list_size(cef_string_list_t list);
// Return the value at the specified zero-based string list index.
CEF_EXPORT cef_string_t cef_string_list_value(cef_string_list_t list, int index);
// Append a new key/value pair at the end of the string list.
CEF_EXPORT void cef_string_list_append(cef_string_list_t list, const wchar_t* value);
// Clear the string list.
CEF_EXPORT void cef_string_list_clear(cef_string_list_t list);
// Free the string list.
CEF_EXPORT void cef_string_list_free(cef_string_list_t list);
#ifdef __cplusplus
}
#endif
#endif // _CEF_STRING_LIST_H

View File

@ -42,14 +42,6 @@ extern "C" {
#endif
// Define frame target types. Using TF_FOCUSED will target the focused
// frame and using TF_MAIN will target the main frame.
enum cef_targetframe_t
{
TF_FOCUSED = 0,
TF_MAIN = 1,
};
// Define handler return value types. Returning RV_HANDLED indicates
// that the implementation completely handled the method and that no further
// processing is required. Returning RV_CONTINUE indicates that the
@ -206,19 +198,6 @@ enum cef_postdataelement_type_t
PDE_TYPE_FILE,
};
enum cef_variant_type_t
{
VARIANT_TYPE_NULL = 0,
VARIANT_TYPE_BOOL,
VARIANT_TYPE_INT,
VARIANT_TYPE_DOUBLE,
VARIANT_TYPE_STRING,
VARIANT_TYPE_BOOL_ARRAY,
VARIANT_TYPE_INT_ARRAY,
VARIANT_TYPE_DOUBLE_ARRAY,
VARIANT_TYPE_STRING_ARRAY,
};
#ifdef __cplusplus
}

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
// Copyright (c) 2008-2009 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.
@ -14,231 +14,60 @@
#include "webkit/api/public/WebURL.h"
#include "webkit/glue/webframe.h"
using WebKit::WebScriptSource;
using WebKit::WebString;
using WebKit::WebURL;
CefBrowserImpl::CefBrowserImpl(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler,
const std::wstring& url)
CefRefPtr<CefHandler> handler)
: window_info_(windowInfo), is_popup_(popup), is_modal_(false),
handler_(handler), webviewhost_(NULL), popuphost_(NULL), url_(url),
unique_id_(0)
handler_(handler), webviewhost_(NULL), popuphost_(NULL), unique_id_(0),
frame_main_(NULL)
{
delegate_ = new BrowserWebViewDelegate(this);
nav_controller_.reset(new BrowserNavigationController(this));
}
CefBrowserImpl::~CefBrowserImpl()
{
RemoveAllJSHandlers();
}
void CefBrowserImpl::GoBack()
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction, MENU_ID_NAV_BACK, TF_MAIN));
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_BACK));
}
void CefBrowserImpl::GoForward()
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction,
MENU_ID_NAV_FORWARD, TF_MAIN));
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_FORWARD));
}
void CefBrowserImpl::Reload()
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction,
MENU_ID_NAV_RELOAD, TF_MAIN));
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_RELOAD));
}
void CefBrowserImpl::StopLoad()
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction,
MENU_ID_NAV_STOP, TF_MAIN));
}
void CefBrowserImpl::Undo(TargetFrame targetFrame)
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction,
MENU_ID_UNDO, targetFrame));
}
void CefBrowserImpl::Redo(TargetFrame targetFrame)
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction,
MENU_ID_REDO, targetFrame));
}
void CefBrowserImpl::Cut(TargetFrame targetFrame)
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction,
MENU_ID_CUT, targetFrame));
}
void CefBrowserImpl::Copy(TargetFrame targetFrame)
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction,
MENU_ID_COPY, targetFrame));
}
void CefBrowserImpl::Paste(TargetFrame targetFrame)
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction,
MENU_ID_PASTE, targetFrame));
}
void CefBrowserImpl::Delete(TargetFrame targetFrame)
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction,
MENU_ID_DELETE, targetFrame));
}
void CefBrowserImpl::SelectAll(TargetFrame targetFrame)
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction,
MENU_ID_SELECTALL, targetFrame));
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_STOP));
}
void CefBrowserImpl::SetFocus(bool enable)
{
if (_Context->RunningOnUIThread())
{
UIT_SetFocus(UIT_GetWebViewHost(), enable);
UIT_SetFocus(GetWebViewHost(), enable);
}
else
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_SetFocus,
UIT_GetWebViewHost(), enable));
GetWebViewHost(), enable));
}
}
void CefBrowserImpl::Print(TargetFrame targetFrame)
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction,
MENU_ID_PRINT, targetFrame));
}
void CefBrowserImpl::ViewSource(TargetFrame targetFrame)
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction,
MENU_ID_VIEWSOURCE, targetFrame));
}
void CefBrowserImpl::LoadRequest(CefRefPtr<CefRequest> request)
{
DCHECK(request.get() != NULL);
request->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_LoadURLForRequestRef, request.get()));
}
void CefBrowserImpl::LoadURL(const std::wstring& url, const std::wstring& frame)
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_LoadURLForFrame, url, frame));
}
void CefBrowserImpl::LoadString(const std::wstring& string,
const std::wstring& url)
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_LoadHTML, string, url));
}
void CefBrowserImpl::LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url)
{
DCHECK(stream.get() != NULL);
stream->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_LoadHTMLForStreamRef, stream.get(), url));
}
void CefBrowserImpl::ExecuteJavaScript(const std::wstring& jsCode,
const std::wstring& scriptUrl,
int startLine,
TargetFrame targetFrame)
{
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_ExecuteJavaScript, jsCode, scriptUrl, startLine,
targetFrame));
}
bool CefBrowserImpl::AddJSHandler(const std::wstring& classname,
CefRefPtr<CefJSHandler> handler)
{
DCHECK(handler.get());
bool rv = false;
Lock();
if(!HasJSHandler(classname)) {
CefRefPtr<CefJSContainer> jscon(new CefJSContainer(this, handler));
jscontainers_.insert(std::make_pair(classname, jscon));
rv = true;
}
Unlock();
return rv;
}
bool CefBrowserImpl::HasJSHandler(const std::wstring& classname)
{
Lock();
bool rv = (jscontainers_.find(classname) != jscontainers_.end());
Unlock();
return rv;
}
CefRefPtr<CefJSHandler> CefBrowserImpl::GetJSHandler(const std::wstring& classname)
{
CefRefPtr<CefJSHandler> handler;
Lock();
JSContainerMap::const_iterator it = jscontainers_.find(classname);
if(it != jscontainers_.end())
handler = it->second->GetHandler();
Unlock();
return handler;
}
bool CefBrowserImpl::RemoveJSHandler(const std::wstring& classname)
{
bool rv = false;
Lock();
JSContainerMap::iterator it = jscontainers_.find(classname);
if(it != jscontainers_.end()) {
jscontainers_.erase(it);
rv = true;
}
Unlock();
return rv;
}
void CefBrowserImpl::RemoveAllJSHandlers()
{
Lock();
jscontainers_.clear();
Unlock();
}
bool CefBrowserImpl::IsPopup()
{
Lock();
@ -252,21 +81,211 @@ CefRefPtr<CefHandler> CefBrowserImpl::GetHandler()
return handler_;
}
std::wstring CefBrowserImpl::GetURL()
CefRefPtr<CefFrame> CefBrowserImpl::GetMainFrame()
{
Lock();
std::wstring url = url_;
Unlock();
return url;
return GetCefFrame(GetWebView()->GetMainFrame());
}
void CefBrowserImpl::SetURL(const std::wstring& url)
CefRefPtr<CefFrame> CefBrowserImpl::GetFocusedFrame()
{
return GetCefFrame(GetWebView()->GetFocusedFrame());
}
CefRefPtr<CefFrame> CefBrowserImpl::GetFrame(const std::wstring& name)
{
WebFrame* frame = GetWebView()->GetFrameWithName(name);
if(frame)
return GetCefFrame(frame);
return NULL;
}
void CefBrowserImpl::GetFrameNames(std::vector<std::wstring>& names)
{
WebView* view = GetWebView();
WebFrame* main_frame = view->GetMainFrame();
WebFrame* it = main_frame;
do {
if(it != main_frame)
names.push_back(it->GetName());
it = view->GetNextFrameAfter(it, true);
} while (it != main_frame);
}
CefRefPtr<CefFrame> CefBrowserImpl::GetCefFrame(WebFrame* frame)
{
CefRefPtr<CefFrame> cef_frame;
Lock();
WebView *view = GetWebView();
if(view) {
if(frame == view->GetMainFrame()) {
// Use or create the single main frame reference.
if(frame_main_ == NULL)
frame_main_ = new CefFrameImpl(this, std::wstring());
cef_frame = frame_main_;
} else {
// Locate or create the appropriate named reference.
std::wstring name = frame->GetName();
DCHECK(!name.empty());
FrameMap::const_iterator it = frames_.find(name);
if(it != frames_.end())
cef_frame = it->second;
else {
cef_frame = new CefFrameImpl(this, name);
frames_.insert(std::make_pair(name, cef_frame.get()));
}
}
}
Unlock();
return cef_frame;
}
void CefBrowserImpl::RemoveCefFrame(const std::wstring& name)
{
Lock();
url_ = url;
if(name.empty())
frame_main_ = NULL;
else {
FrameMap::iterator it = frames_.find(name);
if(it != frames_.end())
frames_.erase(it);
}
Unlock();
}
WebFrame* CefBrowserImpl::GetWebFrame(CefRefPtr<CefFrame> frame)
{
std::wstring name = frame->GetName();
if(name.empty())
return GetWebView()->GetMainFrame();
return GetWebView()->GetFrameWithName(name);
}
void CefBrowserImpl::Undo(CefRefPtr<CefFrame> frame)
{
frame->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction, MENU_ID_UNDO, frame.get()));
}
void CefBrowserImpl::Redo(CefRefPtr<CefFrame> frame)
{
frame->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction, MENU_ID_REDO, frame.get()));
}
void CefBrowserImpl::Cut(CefRefPtr<CefFrame> frame)
{
frame->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction, MENU_ID_CUT, frame.get()));
}
void CefBrowserImpl::Copy(CefRefPtr<CefFrame> frame)
{
frame->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction, MENU_ID_COPY, frame.get()));
}
void CefBrowserImpl::Paste(CefRefPtr<CefFrame> frame)
{
frame->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction, MENU_ID_PASTE, frame.get()));
}
void CefBrowserImpl::Delete(CefRefPtr<CefFrame> frame)
{
frame->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction, MENU_ID_DELETE, frame.get()));
}
void CefBrowserImpl::SelectAll(CefRefPtr<CefFrame> frame)
{
frame->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction, MENU_ID_SELECTALL, frame.get()));
}
void CefBrowserImpl::Print(CefRefPtr<CefFrame> frame)
{
frame->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction, MENU_ID_PRINT, frame.get()));
}
void CefBrowserImpl::ViewSource(CefRefPtr<CefFrame> frame)
{
frame->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleAction, MENU_ID_VIEWSOURCE, frame.get()));
}
void CefBrowserImpl::LoadRequest(CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request)
{
DCHECK(request.get() != NULL);
frame->AddRef();
request->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_LoadURLForRequestRef, frame.get(), request.get()));
}
void CefBrowserImpl::LoadURL(CefRefPtr<CefFrame> frame,
const std::wstring& url)
{
frame->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_LoadURL, frame.get(), url));
}
void CefBrowserImpl::LoadString(CefRefPtr<CefFrame> frame,
const std::wstring& string,
const std::wstring& url)
{
frame->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_LoadHTML, frame.get(), string, url));
}
void CefBrowserImpl::LoadStream(CefRefPtr<CefFrame> frame,
CefRefPtr<CefStreamReader> stream,
const std::wstring& url)
{
DCHECK(stream.get() != NULL);
frame->AddRef();
stream->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_LoadHTMLForStreamRef, frame.get(), stream.get(),
url));
}
void CefBrowserImpl::ExecuteJavaScript(CefRefPtr<CefFrame> frame,
const std::wstring& jsCode,
const std::wstring& scriptUrl,
int startLine)
{
frame->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_ExecuteJavaScript, frame.get(), jsCode, scriptUrl,
startLine));
}
std::wstring CefBrowserImpl::GetURL(CefRefPtr<CefFrame> frame)
{
WebFrame* web_frame = GetWebFrame(frame);
if(web_frame)
return UTF8ToWide(web_frame->GetURL().spec());
return std::wstring();
}
bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler,
const std::wstring& url)
@ -287,9 +306,9 @@ bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
}
CefRefPtr<CefBrowserImpl> browser(
new CefBrowserImpl(windowInfo, popup, handler, newUrl));
new CefBrowserImpl(windowInfo, popup, handler));
PostTask(FROM_HERE, NewRunnableMethod(browser.get(),
&CefBrowserImpl::UIT_CreateBrowser));
&CefBrowserImpl::UIT_CreateBrowser, newUrl));
return true;
}
@ -314,35 +333,23 @@ CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
return false;
}
CefRefPtr<CefBrowser> browser(
new CefBrowserImpl(windowInfo, popup, handler, newUrl));
static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser();
CefRefPtr<CefBrowser> browser(new CefBrowserImpl(windowInfo, popup, handler));
static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser(newUrl);
return browser;
}
void CefBrowserImpl::UIT_LoadURL(const std::wstring& url)
void CefBrowserImpl::UIT_LoadURL(CefFrame* frame,
const std::wstring& url)
{
REQUIRE_UIT();
UIT_LoadURLForRequest(url, std::wstring(), std::wstring(), NULL,
UIT_LoadURLForRequest(frame, url, std::wstring(), NULL,
WebRequest::HeaderMap());
}
void CefBrowserImpl::UIT_LoadURLForFrame(const std::wstring& url,
const std::wstring& frame_name)
void CefBrowserImpl::UIT_LoadURLForRequestRef(CefFrame* frame,
CefRequest* request)
{
REQUIRE_UIT();
UIT_LoadURLForRequest(url, frame_name, std::wstring(), NULL,
WebRequest::HeaderMap());
}
void CefBrowserImpl::UIT_LoadURLForRequestRef(CefRequest* request)
{
REQUIRE_UIT();
std::wstring url = request->GetURL();
std::wstring frame_name = request->GetFrame();
std::wstring method = request->GetMethod();
CefRequestImpl *impl = static_cast<CefRequestImpl*>(request);
@ -358,14 +365,13 @@ void CefBrowserImpl::UIT_LoadURLForRequestRef(CefRequest* request)
WebRequest::HeaderMap headers;
impl->GetHeaderMap(headers);
UIT_LoadURLForRequest(url, frame_name, method, upload_data.get(),
headers);
UIT_LoadURLForRequest(frame, url, method, upload_data.get(), headers);
request->Release();
}
void CefBrowserImpl::UIT_LoadURLForRequest(const std::wstring& url,
const std::wstring& frame_name,
void CefBrowserImpl::UIT_LoadURLForRequest(CefFrame* frame,
const std::wstring& url,
const std::wstring& method,
net::UploadData *upload_data,
const WebRequest::HeaderMap& headers)
@ -384,11 +390,15 @@ void CefBrowserImpl::UIT_LoadURLForRequest(const std::wstring& url,
return;
}
nav_controller_->LoadEntry(new BrowserNavigationEntry(
-1, gurl, std::wstring(), frame_name, method, upload_data, headers));
nav_controller_->LoadEntry(
new BrowserNavigationEntry(-1, gurl, std::wstring(), frame->GetName(),
method, upload_data, headers));
frame->Release();
}
void CefBrowserImpl::UIT_LoadHTML(const std::wstring& html,
void CefBrowserImpl::UIT_LoadHTML(CefFrame* frame,
const std::wstring& html,
const std::wstring& url)
{
REQUIRE_UIT();
@ -402,10 +412,15 @@ void CefBrowserImpl::UIT_LoadHTML(const std::wstring& html,
return;
}
UIT_GetWebView()->GetMainFrame()->LoadHTMLString(WideToUTF8(html), gurl);
WebFrame* web_frame = GetWebFrame(frame);
if(web_frame)
web_frame->LoadHTMLString(WideToUTF8(html), gurl);
frame->Release();
}
void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefStreamReader* stream,
void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefFrame* frame,
CefStreamReader* stream,
const std::wstring& url)
{
REQUIRE_UIT();
@ -432,27 +447,29 @@ void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefStreamReader* stream,
}
while(read > 0);
UIT_GetWebView()->GetMainFrame()->LoadHTMLString(ss.str(), gurl);
WebFrame* web_frame = GetWebFrame(frame);
if(web_frame)
web_frame->LoadHTMLString(ss.str(), gurl);
stream->Release();
frame->Release();
}
void CefBrowserImpl::UIT_ExecuteJavaScript(const std::wstring& js_code,
void CefBrowserImpl::UIT_ExecuteJavaScript(CefFrame* frame,
const std::wstring& js_code,
const std::wstring& script_url,
int start_line,
TargetFrame targetFrame)
int start_line)
{
REQUIRE_UIT();
WebFrame* frame;
if(targetFrame == TF_FOCUSED)
frame = UIT_GetWebView()->GetFocusedFrame();
else
frame = UIT_GetWebView()->GetMainFrame();
WebFrame* web_frame = GetWebFrame(frame);
if(web_frame) {
web_frame->ExecuteScript(
WebScriptSource(WebString(js_code), WebURL(GURL(script_url)),
start_line));
}
frame->ExecuteScript(
WebScriptSource(WebString(js_code), WebURL(GURL(script_url)),
start_line));
frame->Release();
}
void CefBrowserImpl::UIT_GoBackOrForward(int offset)
@ -509,9 +526,9 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
}
// Get the right target frame for the entry.
WebFrame* frame = UIT_GetWebView()->GetMainFrame();
WebFrame* frame = GetWebView()->GetMainFrame();
if (!entry.GetTargetFrame().empty())
frame = UIT_GetWebView()->GetFrameWithName(entry.GetTargetFrame());
frame = GetWebView()->GetFrameWithName(entry.GetTargetFrame());
// TODO(mpcomplete): should we clear the target frame, or should
// back/forward navigations maintain the target frame?
@ -521,23 +538,12 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
// iframe would keep focus when the SetFocus called immediately after
// LoadRequest, thus making some tests fail (see http://b/issue?id=845337
// for more details).
UIT_GetWebView()->SetFocusedFrame(frame);
UIT_SetFocus(UIT_GetWebViewHost(), true);
GetWebView()->SetFocusedFrame(frame);
UIT_SetFocus(GetWebViewHost(), true);
return true;
}
void CefBrowserImpl::UIT_BindJSObjectsToWindow(WebFrame* frame)
{
REQUIRE_UIT();
Lock();
JSContainerMap::const_iterator it = jscontainers_.begin();
for(; it != jscontainers_.end(); ++it)
it->second->BindToJavascript(frame, it->first);
Unlock();
}
CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(const std::wstring& url)
{
REQUIRE_UIT();
@ -557,9 +563,8 @@ CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(const std::wstri
return NULL;
}
CefRefPtr<CefBrowserImpl> browser(
new CefBrowserImpl(info, true, handler, newUrl));
browser->UIT_CreateBrowser();
CefRefPtr<CefBrowserImpl> browser(new CefBrowserImpl(info, true, handler));
browser->UIT_CreateBrowser(newUrl);
return browser;
}
@ -571,16 +576,19 @@ void CefBrowserImpl::UIT_Show(WebView* webview,
delegate_->Show(webview, disposition);
}
void CefBrowserImpl::UIT_HandleActionView(CefHandler::MenuId menuId)
{
return UIT_HandleAction(menuId, NULL);
}
void CefBrowserImpl::UIT_HandleAction(CefHandler::MenuId menuId,
TargetFrame target)
CefFrame* frame)
{
REQUIRE_UIT();
WebFrame* frame;
if(target == TF_FOCUSED)
frame = UIT_GetWebView()->GetFocusedFrame();
else
frame = UIT_GetWebView()->GetMainFrame();
WebFrame* web_frame = NULL;
if(frame)
web_frame = GetWebFrame(frame);
switch(menuId)
{
@ -594,34 +602,46 @@ void CefBrowserImpl::UIT_HandleAction(CefHandler::MenuId menuId,
UIT_Reload();
break;
case MENU_ID_NAV_STOP:
UIT_GetWebView()->StopLoading();
GetWebView()->StopLoading();
break;
case MENU_ID_UNDO:
frame->Undo();
if(web_frame)
web_frame->Undo();
break;
case MENU_ID_REDO:
frame->Redo();
if(web_frame)
web_frame->Redo();
break;
case MENU_ID_CUT:
frame->Cut();
if(web_frame)
web_frame->Cut();
break;
case MENU_ID_COPY:
frame->Copy();
if(web_frame)
web_frame->Copy();
break;
case MENU_ID_PASTE:
frame->Paste();
if(web_frame)
web_frame->Paste();
break;
case MENU_ID_DELETE:
frame->Delete();
if(web_frame)
web_frame->Delete();
break;
case MENU_ID_SELECTALL:
frame->SelectAll();
if(web_frame)
web_frame->SelectAll();
break;
case MENU_ID_PRINT:
UIT_PrintPages(frame);
if(web_frame)
UIT_PrintPages(web_frame);
break;
case MENU_ID_VIEWSOURCE:
UIT_ViewDocumentString(frame);
if(web_frame)
UIT_ViewDocumentString(web_frame);
break;
}
if(frame)
frame->Release();
}

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
// Copyright (c) 2008-2009 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.
@ -6,8 +6,7 @@
#ifndef _BROWSER_IMPL_H
#define _BROWSER_IMPL_H
#include "../include/cef.h"
#include "jscontainer.h"
#include "include/cef.h"
#include "context.h"
#include "webview_host.h"
@ -21,13 +20,14 @@
#define BUFFER_SIZE 32768
// Implementation of CefBrowser.
class CefBrowserImpl : public CefThreadSafeBase<CefBrowser>
{
public:
CefBrowserImpl(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler, const std::wstring& url);
virtual ~CefBrowserImpl();
CefRefPtr<CefHandler> handler);
virtual ~CefBrowserImpl() {}
#if defined(OS_WIN)
static LPCTSTR GetWndClass();
@ -42,72 +42,81 @@ public:
virtual void GoForward();
virtual void Reload();
virtual void StopLoad();
virtual void Undo(TargetFrame targetFrame);
virtual void Redo(TargetFrame targetFrame);
virtual void Cut(TargetFrame targetFrame);
virtual void Copy(TargetFrame targetFrame);
virtual void Paste(TargetFrame targetFrame);
virtual void Delete(TargetFrame targetFrame);
virtual void SelectAll(TargetFrame targetFrame);
virtual void SetFocus(bool enable);
virtual void Print(TargetFrame targetFrame);
virtual void ViewSource(TargetFrame targetFrame);
virtual std::wstring GetSource(TargetFrame targetFrame);
virtual std::wstring GetText(TargetFrame targetFrame);
virtual void LoadRequest(CefRefPtr<CefRequest> request);
virtual void LoadURL(const std::wstring& url, const std::wstring& frame);
virtual void LoadString(const std::wstring& string,
const std::wstring& url);
virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url);
virtual void ExecuteJavaScript(const std::wstring& jsCode,
const std::wstring& scriptUrl,
int startLine, TargetFrame targetFrame);
virtual bool AddJSHandler(const std::wstring& classname,
CefRefPtr<CefJSHandler> handler);
virtual bool HasJSHandler(const std::wstring& classname);
virtual CefRefPtr<CefJSHandler> GetJSHandler(const std::wstring& classname);
virtual bool RemoveJSHandler(const std::wstring& classname);
virtual void RemoveAllJSHandlers();
virtual CefWindowHandle GetWindowHandle();
virtual bool IsPopup();
virtual CefRefPtr<CefHandler> GetHandler();
virtual std::wstring GetURL();
virtual CefRefPtr<CefFrame> GetMainFrame();
virtual CefRefPtr<CefFrame> GetFocusedFrame();
virtual CefRefPtr<CefFrame> GetFrame(const std::wstring& name);
virtual void GetFrameNames(std::vector<std::wstring>& names);
void SetURL(const std::wstring& url);
// CefFrames are light-weight objects managed by the browser and loosely
// coupled to a WebFrame object by name. If a CefFrame object does not
// already exist for the specified WebFrame one will be created. There is no
// guarantee that the same CefFrame object will be returned across different
// calls to this function.
CefRefPtr<CefFrame> GetCefFrame(WebFrame* frame);
void RemoveCefFrame(const std::wstring& name);
// Return the WebFrame object associated with the specified CefFrame. This
// may return NULL if no WebFrame with the CefFrame's name exists.
WebFrame* GetWebFrame(CefRefPtr<CefFrame> frame);
// Frame-related methods
void Undo(CefRefPtr<CefFrame> frame);
void Redo(CefRefPtr<CefFrame> frame);
void Cut(CefRefPtr<CefFrame> frame);
void Copy(CefRefPtr<CefFrame> frame);
void Paste(CefRefPtr<CefFrame> frame);
void Delete(CefRefPtr<CefFrame> frame);
void SelectAll(CefRefPtr<CefFrame> frame);
void Print(CefRefPtr<CefFrame> frame);
void ViewSource(CefRefPtr<CefFrame> frame);
std::wstring GetSource(CefRefPtr<CefFrame> frame);
std::wstring GetText(CefRefPtr<CefFrame> frame);
void LoadRequest(CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request);
void LoadURL(CefRefPtr<CefFrame> frame,
const std::wstring& url);
void LoadString(CefRefPtr<CefFrame> frame,
const std::wstring& string,
const std::wstring& url);
void LoadStream(CefRefPtr<CefFrame> frame,
CefRefPtr<CefStreamReader> stream,
const std::wstring& url);
void ExecuteJavaScript(CefRefPtr<CefFrame> frame,
const std::wstring& jsCode,
const std::wstring& scriptUrl,
int startLine);
virtual std::wstring GetURL(CefRefPtr<CefFrame> frame);
WebView* GetWebView() const {
return webviewhost_.get() ? webviewhost_->webview() : NULL;
}
WebViewHost* GetWebViewHost() const {
return webviewhost_.get();
}
HWND GetWebViewWndHandle() const {
return webviewhost_->window_handle();
}
WebWidget* GetPopup() const {
return popuphost_ ? popuphost_->webwidget() : NULL;
}
WebWidgetHost* GetPopupHost() const {
return popuphost_;
}
HWND GetPopupWndHandle() const {
return popuphost_->window_handle();
}
HWND GetMainWndHandle() const {
return window_info_.m_hWnd;
}
////////////////////////////////////////////////////////////
// ALL UIT_* METHODS MUST ONLY BE CALLED ON THE UI THREAD //
////////////////////////////////////////////////////////////
WebView* UIT_GetWebView() const {
REQUIRE_UIT();
return webviewhost_.get() ? webviewhost_->webview() : NULL;
}
WebViewHost* UIT_GetWebViewHost() const {
REQUIRE_UIT();
return webviewhost_.get();
}
HWND UIT_GetWebViewWndHandle() const {
REQUIRE_UIT();
return webviewhost_->window_handle();
}
WebWidget* UIT_GetPopup() const {
REQUIRE_UIT();
return popuphost_ ? popuphost_->webwidget() : NULL;
}
WebWidgetHost* UIT_GetPopupHost() const {
REQUIRE_UIT();
return popuphost_;
}
HWND UIT_GetPopupWndHandle() const {
REQUIRE_UIT();
return popuphost_->window_handle();
}
HWND UIT_GetMainWndHandle() const {
REQUIRE_UIT();
return window_info_.m_hWnd;
}
BrowserNavigationController* UIT_GetNavigationController() {
REQUIRE_UIT();
return nav_controller_.get();
@ -134,33 +143,32 @@ public:
return title_;
}
// UIThread functions must be executed from the UI thread.
void UIT_CreateBrowser();
void UIT_LoadURL(const std::wstring& url);
void UIT_LoadURLForFrame(const std::wstring& url,
const std::wstring& frame_name);
void UIT_LoadURLForRequest(const std::wstring& url,
const std::wstring& frame_name,
const std::wstring& method,
net::UploadData *upload_data,
const WebRequest::HeaderMap& headers);
void UIT_LoadURLForRequestRef(CefRequest* request);
void UIT_LoadHTML(const std::wstring& html,
const std::wstring& url);
void UIT_LoadHTMLForStreamRef(CefStreamReader* stream,
const std::wstring& url);
void UIT_ExecuteJavaScript(const std::wstring& js_code,
void UIT_CreateBrowser(const std::wstring& url);
void UIT_LoadURL(CefFrame* frame,
const std::wstring& url);
void UIT_LoadURLForRequest(CefFrame* frame,
const std::wstring& url,
const std::wstring& method,
net::UploadData *upload_data,
const WebRequest::HeaderMap& headers);
void UIT_LoadURLForRequestRef(CefFrame* frame,
CefRequest* request);
void UIT_LoadHTML(CefFrame* frame,
const std::wstring& html,
const std::wstring& url);
void UIT_LoadHTMLForStreamRef(CefFrame* frame,
CefStreamReader* stream,
const std::wstring& url);
void UIT_ExecuteJavaScript(CefFrame* frame,
const std::wstring& js_code,
const std::wstring& script_url,
int start_line, TargetFrame targetFrame);
int start_line);
void UIT_GoBackOrForward(int offset);
void UIT_Reload();
bool UIT_Navigate(const BrowserNavigationEntry& entry, bool reload);
void UIT_SetFocus(WebWidgetHost* host, bool enable);
// Called by the WebView delegate WindowObjectCleared() method, this
// binds the C++ controller classes to window JavaScript objects.
void UIT_BindJSObjectsToWindow(WebFrame* frame);
CefRefPtr<CefBrowserImpl> UIT_CreatePopupWindow(const std::wstring& url);
WebWidget* UIT_CreatePopupWidget(WebView* webview);
void UIT_ClosePopupWidget();
@ -168,16 +176,17 @@ public:
void UIT_Show(WebView* webview, WindowOpenDisposition disposition);
// Handles most simple browser actions
void UIT_HandleAction(CefHandler::MenuId menuId, TargetFrame target);
void UIT_HandleActionView(CefHandler::MenuId menuId);
void UIT_HandleAction(CefHandler::MenuId menuId, CefFrame* frame);
// Save the document HTML to a temporary file and open in the default viewing
// application
bool UIT_ViewDocumentString(WebFrame *frame);
#if defined(OS_WIN)
void UIT_GetDocumentStringNotify(TargetFrame targetFrame,
CefStreamWriter* writer, HANDLE hEvent);
void UIT_GetDocumentTextNotify(TargetFrame targetFrame,
CefStreamWriter* writer, HANDLE hEvent);
void UIT_GetDocumentStringNotify(CefFrame* frame,
CefStreamWriter* writer, HANDLE hEvent);
void UIT_GetDocumentTextNotify(CefFrame* frame,
CefStreamWriter* writer, HANDLE hEvent);
void UIT_CanGoBackNotify(bool *retVal, HANDLE hEvent);
void UIT_CanGoForwardNotify(bool *retVal, HANDLE hEvent);
#endif
@ -198,7 +207,6 @@ protected:
CefWindowInfo window_info_;
bool is_popup_;
bool is_modal_;
std::wstring url_;
CefRefPtr<CefHandler> handler_;
scoped_ptr<WebViewHost> webviewhost_;
WebWidgetHost* popuphost_;
@ -210,11 +218,59 @@ protected:
// Context object used to manage printing.
printing::PrintingContext print_context_;
typedef std::map<std::wstring, CefRefPtr<CefJSContainer> > JSContainerMap;
JSContainerMap jscontainers_;
typedef std::map<std::wstring, CefFrame*> FrameMap;
FrameMap frames_;
CefFrame* frame_main_;
// Unique browser ID assigned by the context.
int unique_id_;
};
// Implementation of CefFrame.
class CefFrameImpl : public CefThreadSafeBase<CefFrame>
{
public:
CefFrameImpl(CefBrowserImpl* browser, const std::wstring& name)
: browser_(browser), name_(name) {}
virtual ~CefFrameImpl() { browser_->RemoveCefFrame(name_); }
// CefFrame methods
virtual void Undo() { browser_->Undo(this); }
virtual void Redo() { browser_->Redo(this); }
virtual void Cut() { browser_->Cut(this); }
virtual void Copy() { browser_->Copy(this); }
virtual void Paste() { browser_->Paste(this); }
virtual void Delete() { browser_->Delete(this); }
virtual void SelectAll() { browser_->SelectAll(this); }
virtual void Print() { browser_->Print(this); }
virtual void ViewSource() { browser_->ViewSource(this); }
virtual std::wstring GetSource() { return browser_->GetSource(this); }
virtual std::wstring GetText() { return browser_->GetText(this); }
virtual void LoadRequest(CefRefPtr<CefRequest> request)
{ return browser_->LoadRequest(this, request); }
virtual void LoadURL(const std::wstring& url)
{ return browser_->LoadURL(this, url); }
virtual void LoadString(const std::wstring& string,
const std::wstring& url)
{ return browser_->LoadString(this, string, url); }
virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url)
{ return browser_->LoadStream(this, stream, url); }
virtual void ExecuteJavaScript(const std::wstring& jsCode,
const std::wstring& scriptUrl,
int startLine)
{ return browser_->ExecuteJavaScript(this, jsCode, scriptUrl, startLine); }
virtual bool IsMain() { return name_.empty(); }
virtual bool IsFocused()
{ return (browser_->GetWebFrame(this) ==
browser_->GetWebView()->GetFocusedFrame()); }
virtual std::wstring GetName() { return name_; }
virtual std::wstring GetURL() { return browser_->GetURL(this); }
private:
CefRefPtr<CefBrowserImpl> browser_;
std::wstring name_;
};
#endif // _BROWSER_IMPL_H

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
// Copyright (c) 2008-2009 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.
@ -44,7 +44,7 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
int wmId = LOWORD(wParam);
int wmEvent = HIWORD(wParam);
}
break;
@ -55,34 +55,42 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
// Notify the handler that the window is about to be closed
handler->HandleBeforeWindowClose(browser);
}
RevokeDragDrop(browser->UIT_GetWebViewWndHandle());
RevokeDragDrop(browser->GetWebViewWndHandle());
// Call GC twice to clean up garbage.
browser->GetWebView()->GetMainFrame()->CallJSGC();
browser->GetWebView()->GetMainFrame()->CallJSGC();
// Clean up anything associated with the WebViewHost widget.
browser->GetWebViewHost()->webwidget()->Close();
// Remove the browser from the list maintained by the context
_Context->RemoveBrowser(browser);
}
return 0;
case WM_SIZE:
if (browser && browser->UIT_GetWebView()) {
if (browser && browser->GetWebView()) {
// resize the web view window to the full size of the browser window
RECT rc;
GetClientRect(browser->UIT_GetMainWndHandle(), &rc);
MoveWindow(browser->UIT_GetWebViewWndHandle(), 0, 0, rc.right, rc.bottom,
GetClientRect(browser->GetMainWndHandle(), &rc);
MoveWindow(browser->GetWebViewWndHandle(), 0, 0, rc.right, rc.bottom,
TRUE);
}
return 0;
case WM_SETFOCUS:
if (browser && browser->UIT_GetWebView())
browser->UIT_GetWebView()->SetFocus(true);
return 0;
if (browser && browser->GetWebView())
browser->GetWebView()->SetFocus(true);
return 0;
case WM_KILLFOCUS:
if (browser && browser->UIT_GetWebView())
browser->UIT_GetWebView()->SetFocus(false);
return 0;
case WM_KILLFOCUS:
if (browser && browser->GetWebView())
browser->GetWebView()->SetFocus(false);
return 0;
case WM_ERASEBKGND:
return 0;
case WM_ERASEBKGND:
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
@ -96,7 +104,7 @@ CefWindowHandle CefBrowserImpl::GetWindowHandle()
return handle;
}
std::wstring CefBrowserImpl::GetSource(TargetFrame targetFrame)
std::wstring CefBrowserImpl::GetSource(CefRefPtr<CefFrame> frame)
{
if(!_Context->RunningOnUIThread())
{
@ -110,9 +118,10 @@ std::wstring CefBrowserImpl::GetSource(TargetFrame targetFrame)
CefRefPtr<CefStreamWriter> stream(new CefBytesWriter(BUFFER_SIZE));
// Request the data from the UI thread
frame->AddRef();
stream->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_GetDocumentStringNotify, targetFrame, stream.get(),
&CefBrowserImpl::UIT_GetDocumentStringNotify, frame.get(), stream.get(),
hEvent));
// Wait for the UI thread callback to tell us that the data is available
@ -124,19 +133,15 @@ std::wstring CefBrowserImpl::GetSource(TargetFrame targetFrame)
}
else
{
// Retrieve the frame contents directly
WebFrame* frame;
if(targetFrame == TF_FOCUSED)
frame = UIT_GetWebView()->GetFocusedFrame();
else
frame = UIT_GetWebView()->GetMainFrame();
// Retrieve the document string
return UTF8ToWide(webkit_glue::GetDocumentString(frame));
// Retrieve the document string directly
WebFrame* web_frame = GetWebFrame(frame);
if(web_frame)
return UTF8ToWide(webkit_glue::GetDocumentString(web_frame));
return std::wstring();
}
}
std::wstring CefBrowserImpl::GetText(TargetFrame targetFrame)
std::wstring CefBrowserImpl::GetText(CefRefPtr<CefFrame> frame)
{
if(!_Context->RunningOnUIThread())
{
@ -150,9 +155,10 @@ std::wstring CefBrowserImpl::GetText(TargetFrame targetFrame)
CefRefPtr<CefStreamWriter> stream(new CefBytesWriter(BUFFER_SIZE));
// Request the data from the UI thread
frame->AddRef();
stream->AddRef();
PostTask(FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_GetDocumentTextNotify, targetFrame, stream.get(),
&CefBrowserImpl::UIT_GetDocumentTextNotify, frame.get(), stream.get(),
hEvent));
// Wait for the UI thread callback to tell us that the data is available
@ -164,15 +170,11 @@ std::wstring CefBrowserImpl::GetText(TargetFrame targetFrame)
}
else
{
// Retrieve the frame contents directly
WebFrame* frame;
if(targetFrame == TF_FOCUSED)
frame = UIT_GetWebView()->GetFocusedFrame();
else
frame = UIT_GetWebView()->GetMainFrame();
// Retrieve the document string
return webkit_glue::DumpDocumentText(frame);
// Retrieve the document text directly
WebFrame* web_frame = GetWebFrame(frame);
if(web_frame)
webkit_glue::DumpDocumentText(web_frame);
return std::wstring();
}
}
@ -236,7 +238,7 @@ bool CefBrowserImpl::CanGoForward()
}
}
void CefBrowserImpl::UIT_CreateBrowser()
void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
{
REQUIRE_UIT();
@ -250,22 +252,22 @@ void CefBrowserImpl::UIT_CreateBrowser()
// Set window user data to this object for future reference from the window
// procedure
win_util::SetWindowUserData(window_info_.m_hWnd, this);
win_util::SetWindowUserData(window_info_.m_hWnd, this);
// Add the new browser to the list maintained by the context
_Context->AddBrowser(this);
// Create the webview host object
// Create the webview host object
webviewhost_.reset(
WebViewHost::Create(window_info_.m_hWnd, delegate_.get(),
*_Context->GetWebPreferences()));
UIT_GetWebView()->SetUseEditorDelegate(true);
GetWebView()->SetUseEditorDelegate(true);
delegate_->RegisterDragDrop();
// Size the web view window to the browser window
RECT cr;
GetClientRect(window_info_.m_hWnd, &cr);
SetWindowPos(UIT_GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
RECT cr;
GetClientRect(window_info_.m_hWnd, &cr);
SetWindowPos(GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
cr.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
if(handler_.get()) {
@ -273,8 +275,11 @@ void CefBrowserImpl::UIT_CreateBrowser()
handler_->HandleAfterCreated(this);
}
if(url_.size() > 0)
UIT_LoadURL(url_.c_str());
if(url.size() > 0) {
CefRefPtr<CefFrame> frame = GetMainFrame();
frame->AddRef();
UIT_LoadURL(frame, url.c_str());
}
}
void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable)
@ -293,7 +298,7 @@ WebWidget* CefBrowserImpl::UIT_CreatePopupWidget(WebView* webview)
DCHECK(!popuphost_);
popuphost_ = WebWidgetHost::Create(NULL, delegate_.get());
ShowWindow(UIT_GetPopupWndHandle(), SW_SHOW);
ShowWindow(GetPopupWndHandle(), SW_SHOW);
return popuphost_->webwidget();
}
@ -302,7 +307,7 @@ void CefBrowserImpl::UIT_ClosePopupWidget()
{
REQUIRE_UIT();
PostMessage(UIT_GetPopupWndHandle(), WM_CLOSE, 0, 0);
PostMessage(GetPopupWndHandle(), WM_CLOSE, 0, 0);
popuphost_ = NULL;
}
@ -345,7 +350,7 @@ bool CefBrowserImpl::UIT_ViewDocumentString(WebFrame *frame)
wcscpy(szTempName + len - 3, L"txt");
WriteTextToFile(webkit_glue::GetDocumentString(frame), szTempName);
int errorCode = (int)ShellExecute(UIT_GetMainWndHandle(), L"open", szTempName,
int errorCode = (int)ShellExecute(GetMainWndHandle(), L"open", szTempName,
NULL, NULL, SW_SHOWNORMAL);
if(errorCode <= 32)
return false;
@ -353,51 +358,47 @@ bool CefBrowserImpl::UIT_ViewDocumentString(WebFrame *frame)
return true;
}
void CefBrowserImpl::UIT_GetDocumentStringNotify(TargetFrame targetFrame,
void CefBrowserImpl::UIT_GetDocumentStringNotify(CefFrame* frame,
CefStreamWriter* writer,
HANDLE hEvent)
{
REQUIRE_UIT();
WebFrame* frame;
if(targetFrame == TF_FOCUSED)
frame = UIT_GetWebView()->GetFocusedFrame();
else
frame = UIT_GetWebView()->GetMainFrame();
// Retrieve the document string
std::string str = webkit_glue::GetDocumentString(frame);
// Write the document string to the stream
writer->Write(str.c_str(), str.size(), 1);
WebFrame* web_frame = GetWebFrame(frame);
if(web_frame) {
// Retrieve the document string
std::string str = webkit_glue::GetDocumentString(web_frame);
// Write the document string to the stream
writer->Write(str.c_str(), str.size(), 1);
}
// Notify the calling thread that the data is now available
SetEvent(hEvent);
writer->Release();
frame->Release();
}
void CefBrowserImpl::UIT_GetDocumentTextNotify(TargetFrame targetFrame,
void CefBrowserImpl::UIT_GetDocumentTextNotify(CefFrame* frame,
CefStreamWriter* writer,
HANDLE hEvent)
{
REQUIRE_UIT();
WebFrame* frame;
if(targetFrame == TF_FOCUSED)
frame = UIT_GetWebView()->GetFocusedFrame();
else
frame = UIT_GetWebView()->GetMainFrame();
// Retrieve the document string
std::wstring str = webkit_glue::DumpDocumentText(frame);
std::string cstr = WideToUTF8(str);
// Write the document string to the stream
writer->Write(cstr.c_str(), cstr.size(), 1);
WebFrame* web_frame = GetWebFrame(frame);
if(web_frame) {
// Retrieve the document string
std::wstring str = webkit_glue::DumpDocumentText(web_frame);
std::string cstr = WideToUTF8(str);
// Write the document string to the stream
writer->Write(cstr.c_str(), cstr.size(), 1);
}
// Notify the calling thread that the data is now available
SetEvent(hEvent);
writer->Release();
frame->Release();
}
void CefBrowserImpl::UIT_CanGoBackNotify(bool *retVal, HANDLE hEvent)
@ -500,9 +501,9 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
std::wstring bottomLeft, bottomCenter, bottomRight;
// allow the handler to format print header and/or footer
CefHandler::RetVal rv = handler_->HandlePrintHeaderFooter(this, printInfo,
url, title, page_number+1, total_pages, topLeft, topCenter, topRight,
bottomLeft, bottomCenter, bottomRight);
CefHandler::RetVal rv = handler_->HandlePrintHeaderFooter(this,
GetCefFrame(frame), printInfo, url, title, page_number+1, total_pages,
topLeft, topCenter, topRight, bottomLeft, bottomCenter, bottomRight);
if(rv != RV_HANDLED) {
// Draw handler-defined headers and/or footers.
@ -548,14 +549,14 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
DT_RIGHT | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS
| DT_EXPANDTABS | DT_NOPREFIX);
}
SetTextColor(hDC, hOldColor);
SelectObject(hDC, hOldFont);
DeleteObject(hFont);
SetBkMode(hDC, hOldBkMode);
}
res = RestoreDC(hDC, saved_state);
SetTextColor(hDC, hOldColor);
SelectObject(hDC, hOldFont);
DeleteObject(hFont);
SetBkMode(hDC, hOldBkMode);
}
res = RestoreDC(hDC, saved_state);
DCHECK_NE(res, 0);
}
@ -563,20 +564,20 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
}
void CefBrowserImpl::UIT_PrintPages(WebFrame* frame) {
REQUIRE_UIT();
REQUIRE_UIT();
TCHAR printername[512];
DWORD size = sizeof(printername)-1;
if(GetDefaultPrinter(printername, &size)) {
printing::PrintSettings settings;
settings.set_device_name(printername);
// Initialize it.
print_context_.InitWithSettings(settings);
}
DWORD size = sizeof(printername)-1;
if(GetDefaultPrinter(printername, &size)) {
printing::PrintSettings settings;
settings.set_device_name(printername);
// Initialize it.
print_context_.InitWithSettings(settings);
}
if(print_context_.AskUserForSettings(
UIT_GetMainWndHandle(), UIT_GetPagesCount(frame))
GetMainWndHandle(), UIT_GetPagesCount(frame))
!= printing::PrintingContext::OK)
return;
@ -605,20 +606,20 @@ void CefBrowserImpl::UIT_PrintPages(WebFrame* frame) {
MessageLoop::current()->SetNestableTasksAllowed(false);
// TODO(cef): Use the page title as the document name
print_context_.NewDocument(L"New Document");
if(settings.ranges.size() > 0) {
for (unsigned x = 0; x < settings.ranges.size(); ++x) {
const printing::PageRange& range = settings.ranges[x];
for(int i = range.from; i <= range.to; ++i)
UIT_PrintPage(i, page_count, canvas_size, frame);
}
} else {
for(int i = 0; i < page_count; ++i)
UIT_PrintPage(i, page_count, canvas_size, frame);
}
print_context_.DocumentDone();
print_context_.NewDocument(L"New Document");
if(settings.ranges.size() > 0) {
for (unsigned x = 0; x < settings.ranges.size(); ++x) {
const printing::PageRange& range = settings.ranges[x];
for(int i = range.from; i <= range.to; ++i)
UIT_PrintPage(i, page_count, canvas_size, frame);
}
} else {
for(int i = 0; i < page_count; ++i)
UIT_PrintPage(i, page_count, canvas_size, frame);
}
print_context_.DocumentDone();
MessageLoop::current()->SetNestableTasksAllowed(old_state);
MessageLoop::current()->SetNestableTasksAllowed(old_state);
}
frame->EndPrint();

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
// Copyright (c) 2008-2009 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.
@ -50,8 +50,6 @@ class BrowserNavigationEntry {
const std::wstring& method,
net::UploadData *upload,
const WebRequest::HeaderMap& headers);
// Virtual to allow test_shell to extend the class.
~BrowserNavigationEntry();
// Set / Get the URI

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
// Copyright (c) 2008-2009 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.
@ -10,9 +10,11 @@
#include "config.h"
MSVC_PUSH_WARNING_LEVEL(0);
#include "Frame.h"
#include "Markup.h"
#include "TextEncoding.h"
#include "webkit/glue/webframe_impl.h"
#include "webkit/port/bindings/v8/v8_proxy.h"
MSVC_POP_WARNING();
#include "browser_webkit_glue.h"
@ -190,4 +192,11 @@ void InitializeTextEncoding() {
WebCore::UTF8Encoding();
}
v8::Handle<v8::Context> GetV8Context(WebFrame* frame)
{
WebFrameImpl* webFrameImpl = static_cast<WebFrameImpl*>(frame);
WebCore::Frame* core_frame = webFrameImpl->frame();
return WebCore::V8Proxy::GetContext(core_frame);
}
} // namespace webkit_glue

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors. All rights
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
@ -8,6 +8,7 @@
#include <string>
#include "base/string_piece.h"
#include "v8/include/v8.h"
class WebFrame;
class WebView;
@ -32,4 +33,7 @@ void InitializeTextEncoding();
// This is called indirectly by the network layer to access resources.
StringPiece NetResourceProvider(int key);
// Retrieve the V8 context associated with the frame.
v8::Handle<v8::Context> GetV8Context(WebFrame* frame);
} // namespace webkit_glue

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
// Copyright (c) 2008-2009 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.
@ -14,6 +14,7 @@
#include "browser_navigation_controller.h"
#include "context.h"
#include "request_impl.h"
#include "v8_impl.h"
#include "base/file_util.h"
#include "base/gfx/gdi_util.h"
@ -38,7 +39,8 @@
#include "webkit/glue/plugins/plugin_list.h"
#include "webkit/glue/plugins/webplugin_delegate_impl.h"
#include "webkit/glue/window_open_disposition.h"
#include "browser_webkit_glue.h"
#if defined(OS_WIN)
// TODO(port): make these files work everywhere.
#include "browser_drag_delegate.h"
@ -66,7 +68,7 @@ WebView* BrowserWebViewDelegate::CreateWebView(WebView* webview,
const GURL& creator_url) {
CefRefPtr<CefBrowserImpl> browser =
browser_->UIT_CreatePopupWindow(std::wstring());
return browser.get() ? browser->UIT_GetWebView() : NULL;
return browser.get() ? browser->GetWebView() : NULL;
}
WebWidget* BrowserWebViewDelegate::CreatePopupWidget(WebView* webview,
@ -89,7 +91,7 @@ void BrowserWebViewDelegate::OpenURL(WebView* webview, const GURL& url,
browser_->UIT_CreatePopupWindow(UTF8ToWide(url.spec()));
if(browser.get())
browser->UIT_Show(browser->UIT_GetWebView(), disposition);
browser->UIT_Show(browser->GetWebView(), disposition);
}
void BrowserWebViewDelegate::DidStartLoading(WebView* webview) {
@ -99,7 +101,7 @@ void BrowserWebViewDelegate::DidStartLoading(WebView* webview) {
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
// Notify the handler that loading has started
handler->HandleLoadStart(browser_);
handler->HandleLoadStart(browser_, NULL);
}
}
@ -116,12 +118,24 @@ void BrowserWebViewDelegate::DidStopLoading(WebView* webview) {
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
// Notify the handler that loading has ended
handler->HandleLoadEnd(browser_);
handler->HandleLoadEnd(browser_, NULL);
}
}
void BrowserWebViewDelegate::WindowObjectCleared(WebFrame* webframe) {
browser_->UIT_BindJSObjectsToWindow(webframe);
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
v8::HandleScope handle_scope;
v8::Handle<v8::Context> context = webkit_glue::GetV8Context(webframe);
if(context.IsEmpty())
return;
v8::Context::Scope scope(context);
CefRefPtr<CefFrame> frame(browser_->GetCefFrame(webframe));
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(context->Global());
handler->HandleJSBinding(browser_, frame, object);
}
}
WindowOpenDisposition BrowserWebViewDelegate::DispositionForNavigationAction(
@ -155,8 +169,9 @@ WindowOpenDisposition BrowserWebViewDelegate::DispositionForNavigationAction(
static_cast<CefRequestImpl*>(req.get())->SetHeaderMap(map);
// Notify the handler of a browse request
CefHandler::RetVal rv = handler->HandleBeforeBrowse(browser_, req,
(CefHandler::NavType)type, is_redirect);
CefHandler::RetVal rv = handler->HandleBeforeBrowse(browser_,
browser_->GetCefFrame(frame), req, (CefHandler::NavType)type,
is_redirect);
if(rv == RV_HANDLED)
return IGNORE_ACTION;
}
@ -247,6 +262,7 @@ void BrowserWebViewDelegate::DidFailProvisionalLoadWithError(
// give the handler an opportunity to generate a custom error message
std::wstring error_str;
CefHandler::RetVal rv = handler->HandleLoadError(browser_,
browser_->GetCefFrame(frame),
static_cast<CefHandler::ErrorCode>(error.GetErrorCode()),
UTF8ToWide(error.GetFailedURL().spec()), error_str);
if(rv == RV_HANDLED && !error_str.empty())
@ -263,6 +279,11 @@ void BrowserWebViewDelegate::DidCommitLoadForFrame(WebView* webview,
WebFrame* frame,
bool is_new_navigation) {
UpdateForCommittedLoad(frame, is_new_navigation);
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
// Notify the handler that loading has started
handler->HandleLoadStart(browser_, browser_->GetCefFrame(frame));
}
}
void BrowserWebViewDelegate::DidReceiveTitle(WebView* webview,
@ -280,6 +301,11 @@ void BrowserWebViewDelegate::DidFinishLoadForFrame(WebView* webview,
WebFrame* frame) {
UpdateAddressBar(webview);
LocationChangeDone(frame);
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
// Notify the handler that loading has ended
handler->HandleLoadEnd(browser_, browser_->GetCefFrame(frame));
}
}
void BrowserWebViewDelegate::DidFailLoadWithError(WebView* webview,
@ -335,11 +361,13 @@ void BrowserWebViewDelegate::AddMessageToConsole(WebView* webview,
}
void BrowserWebViewDelegate::RunJavaScriptAlert(WebFrame* webframe,
const std::wstring& message) {
const std::wstring& message) {
CefHandler::RetVal rv = RV_CONTINUE;
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get())
rv = handler->HandleJSAlert(browser_, message);
if(handler.get()) {
rv = handler->HandleJSAlert(browser_, browser_->GetCefFrame(webframe),
message);
}
if(rv != RV_HANDLED)
ShowJavaScriptAlert(webframe, message);
}
@ -349,8 +377,10 @@ bool BrowserWebViewDelegate::RunJavaScriptConfirm(WebFrame* webframe,
CefHandler::RetVal rv = RV_CONTINUE;
bool retval = false;
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get())
rv = handler->HandleJSConfirm(browser_, message, retval);
if(handler.get()) {
rv = handler->HandleJSConfirm(browser_, browser_->GetCefFrame(webframe),
message, retval);
}
if(rv != RV_HANDLED)
retval = ShowJavaScriptConfirm(webframe, message);
return retval;
@ -363,8 +393,8 @@ bool BrowserWebViewDelegate::RunJavaScriptPrompt(WebFrame* webframe,
bool retval = false;
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
rv = handler->HandleJSPrompt(browser_, message, default_value,
retval, *result);
rv = handler->HandleJSPrompt(browser_, browser_->GetCefFrame(webframe),
message, default_value, retval, *result);
}
if(rv != RV_HANDLED)
retval = ShowJavaScriptPrompt(webframe, message, default_value, result);
@ -382,8 +412,8 @@ void BrowserWebViewDelegate::StartDragging(WebView* webview,
// TODO(port): make this work on all platforms.
if (!drag_delegate_) {
drag_delegate_ = new BrowserDragDelegate(
browser_->UIT_GetWebViewWndHandle(),
browser_->UIT_GetWebView());
browser_->GetWebViewWndHandle(),
browser_->GetWebView());
}
// TODO(tc): Drag and drop is disabled in the test shell because we need
// to be able to convert from WebDragData to an IDataObject.
@ -481,14 +511,14 @@ int BrowserWebViewDelegate::GetHistoryForwardListCount() {
void BrowserWebViewDelegate::SetUserStyleSheetEnabled(bool is_enabled) {
WebPreferences* prefs = _Context->GetWebPreferences();
prefs->user_style_sheet_enabled = is_enabled;
browser_->UIT_GetWebView()->SetPreferences(*prefs);
browser_->GetWebView()->SetPreferences(*prefs);
}
void BrowserWebViewDelegate::SetUserStyleSheetLocation(const GURL& location) {
WebPreferences* prefs = _Context->GetWebPreferences();
prefs->user_style_sheet_enabled = true;
prefs->user_style_sheet_location = location;
browser_->UIT_GetWebView()->SetPreferences(*prefs);
browser_->GetWebView()->SetPreferences(*prefs);
}
// WebWidgetDelegate ---------------------------------------------------------
@ -551,8 +581,8 @@ void BrowserWebViewDelegate::RegisterDragDrop() {
#if defined(OS_WIN)
// TODO(port): add me once drag and drop works.
DCHECK(!drop_delegate_);
drop_delegate_ = new BrowserDropDelegate(browser_->UIT_GetWebViewWndHandle(),
browser_->UIT_GetWebView());
drop_delegate_ = new BrowserDropDelegate(browser_->GetWebViewWndHandle(),
browser_->GetWebView());
#endif
}
@ -587,16 +617,16 @@ void BrowserWebViewDelegate::LocationChangeDone(WebFrame* frame) {
}
WebWidgetHost* BrowserWebViewDelegate::GetHostForWidget(WebWidget* webwidget) {
if (webwidget == browser_->UIT_GetWebView())
return browser_->UIT_GetWebViewHost();
if (webwidget == browser_->UIT_GetPopup())
return browser_->UIT_GetPopupHost();
if (webwidget == browser_->GetWebView())
return browser_->GetWebViewHost();
if (webwidget == browser_->GetPopup())
return browser_->GetPopupHost();
return NULL;
}
void BrowserWebViewDelegate::UpdateForCommittedLoad(WebFrame* frame,
bool is_new_navigation) {
WebView* webview = browser_->UIT_GetWebView();
WebView* webview = browser_->GetWebView();
// Code duplicated from RenderView::DidCommitLoadForFrame.
const WebRequest& request =
@ -641,15 +671,11 @@ void BrowserWebViewDelegate::UpdateURL(WebFrame* frame) {
}
std::wstring url = UTF8ToWide(entry->GetURL().spec().c_str());
browser_->SetURL(url);
if(frame->GetView()->GetMainFrame() == frame) {
// only send address changes that originate from the main frame
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
// Notify the handler of an address change
handler->HandleAddressChange(browser_, url);
}
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
// Notify the handler of an address change
handler->HandleAddressChange(browser_, browser_->GetCefFrame(frame), url);
}
browser_->UIT_GetNavigationController()->DidNavigateToEntry(entry.release());
@ -670,7 +696,7 @@ void BrowserWebViewDelegate::UpdateSessionHistory(WebFrame* frame) {
return;
std::string state;
if (!browser_->UIT_GetWebView()->GetMainFrame()->
if (!browser_->GetWebView()->GetMainFrame()->
GetPreviousHistoryState(&state))
return;
@ -680,7 +706,7 @@ void BrowserWebViewDelegate::UpdateSessionHistory(WebFrame* frame) {
std::wstring BrowserWebViewDelegate::GetFrameDescription(WebFrame* webframe) {
std::wstring name = webframe->GetName();
if (webframe == browser_->UIT_GetWebView()->GetMainFrame()) {
if (webframe == browser_->GetWebView()->GetMainFrame()) {
if (name.length())
return L"main frame \"" + name + L"\"";
else

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
// Copyright (c) 2008-2009 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.
@ -35,12 +35,12 @@ class WebDataSource;
class WebWidgetHost;
class BrowserWebViewDelegate : public base::RefCounted<BrowserWebViewDelegate>,
public WebViewDelegate {
public WebViewDelegate {
public:
BrowserWebViewDelegate(CefBrowserImpl* shell)
BrowserWebViewDelegate(CefBrowserImpl* browser)
: policy_delegate_enabled_(false),
policy_delegate_is_permissive_(false),
browser_(shell),
browser_(browser),
top_loading_frame_(NULL),
page_id_(-1),
last_page_id_updated_(-1),
@ -55,7 +55,7 @@ class BrowserWebViewDelegate : public base::RefCounted<BrowserWebViewDelegate>,
#endif
{
}
virtual ~BrowserWebViewDelegate();
virtual ~BrowserWebViewDelegate() {}
// WebViewDelegate
virtual WebView* CreateWebView(WebView* webview,

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
// Copyright (c) 2008-2009 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.
@ -44,9 +44,6 @@ using WebKit::WebRect;
// WebViewDelegate -----------------------------------------------------------
BrowserWebViewDelegate::~BrowserWebViewDelegate() {
}
WebPluginDelegate* BrowserWebViewDelegate::CreatePluginDelegate(
WebView* webview,
const GURL& url,
@ -74,12 +71,12 @@ WebPluginDelegate* BrowserWebViewDelegate::CreatePluginDelegate(
}
void BrowserWebViewDelegate::Show(WebWidget* webwidget, WindowOpenDisposition) {
if (webwidget == browser_->UIT_GetWebView()) {
ShowWindow(browser_->UIT_GetMainWndHandle(), SW_SHOW);
UpdateWindow(browser_->UIT_GetMainWndHandle());
} else if (webwidget == browser_->UIT_GetPopup()) {
ShowWindow(browser_->UIT_GetPopupWndHandle(), SW_SHOW);
UpdateWindow(browser_->UIT_GetPopupWndHandle());
if (webwidget == browser_->GetWebView()) {
ShowWindow(browser_->GetMainWndHandle(), SW_SHOW);
UpdateWindow(browser_->GetMainWndHandle());
} else if (webwidget == browser_->GetPopup()) {
ShowWindow(browser_->GetPopupWndHandle(), SW_SHOW);
UpdateWindow(browser_->GetPopupWndHandle());
}
}
@ -93,9 +90,9 @@ void BrowserWebViewDelegate::ShowAsPopupWithItems(
}
void BrowserWebViewDelegate::CloseWidgetSoon(WebWidget* webwidget) {
if (webwidget == browser_->UIT_GetWebView()) {
PostMessage(browser_->UIT_GetMainWndHandle(), WM_CLOSE, 0, 0);
} else if (webwidget == browser_->UIT_GetPopup()) {
if (webwidget == browser_->GetWebView()) {
PostMessage(browser_->GetMainWndHandle(), WM_CLOSE, 0, 0);
} else if (webwidget == browser_->GetPopup()) {
browser_->UIT_ClosePopupWidget();
}
}
@ -120,10 +117,10 @@ void BrowserWebViewDelegate::GetWindowRect(WebWidget* webwidget,
void BrowserWebViewDelegate::SetWindowRect(WebWidget* webwidget,
const WebRect& rect) {
if (webwidget == browser_->UIT_GetWebView()) {
if (webwidget == browser_->GetWebView()) {
// ignored
} else if (webwidget == browser_->UIT_GetPopup()) {
MoveWindow(browser_->UIT_GetPopupWndHandle(),
} else if (webwidget == browser_->GetPopup()) {
MoveWindow(browser_->GetPopupWndHandle(),
rect.x, rect.y, rect.width, rect.height, FALSE);
}
}
@ -183,7 +180,7 @@ void BrowserWebViewDelegate::RunModal(WebWidget* webwidget) {
i = list->begin();
for (; i != list->end(); ++i) {
if (i->get()->IsPopup())
EnableWindow(i->get()->UIT_GetMainWndHandle(), FALSE);
EnableWindow(i->get()->GetMainWndHandle(), FALSE);
}
_Context->Unlock();
@ -194,7 +191,7 @@ void BrowserWebViewDelegate::RunModal(WebWidget* webwidget) {
list = _Context->GetBrowserList();
i = list->begin();
for (; i != list->end(); ++i)
EnableWindow(i->get()->UIT_GetMainWndHandle(), TRUE);
EnableWindow(i->get()->GetMainWndHandle(), TRUE);
_Context->Unlock();
}
@ -251,7 +248,7 @@ void BrowserWebViewDelegate::ShowContextMenu(WebView* webview,
const std::string& frame_charset) {
POINT screen_pt = { x, y };
MapWindowPoints(browser_->UIT_GetMainWndHandle(), HWND_DESKTOP,
MapWindowPoints(browser_->GetMainWndHandle(), HWND_DESKTOP,
&screen_pt, 1);
HMENU menu = NULL;
@ -337,7 +334,7 @@ void BrowserWebViewDelegate::ShowContextMenu(WebView* webview,
// show the context menu
int selected_id = TrackPopupMenu(menu,
TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_RECURSE,
screen_pt.x, screen_pt.y, 0, browser_->UIT_GetMainWndHandle(), NULL);
screen_pt.x, screen_pt.y, 0, browser_->GetMainWndHandle(), NULL);
if(selected_id != 0) {
// An action was chosen
@ -351,7 +348,9 @@ void BrowserWebViewDelegate::ShowContextMenu(WebView* webview,
if(!handled) {
// Execute the action
browser_->UIT_HandleAction(menuId, TF_FOCUSED);
CefRefPtr<CefFrame> frame = browser_->GetFocusedFrame();
frame->AddRef();
browser_->UIT_HandleAction(menuId, frame.get());
}
}
}
@ -369,7 +368,7 @@ void BrowserWebViewDelegate::ShowJavaScriptAlert(WebFrame* webframe,
const std::wstring& message)
{
// TODO(cef): Think about what we should be showing as the prompt caption
MessageBox(browser_->UIT_GetMainWndHandle(), message.c_str(),
MessageBox(browser_->GetMainWndHandle(), message.c_str(),
browser_->UIT_GetTitle().c_str(), MB_OK | MB_ICONWARNING);
}
@ -377,7 +376,7 @@ bool BrowserWebViewDelegate::ShowJavaScriptConfirm(WebFrame* webframe,
const std::wstring& message)
{
// TODO(cef): Think about what we should be showing as the prompt caption
int rv = MessageBox(browser_->UIT_GetMainWndHandle(), message.c_str(),
int rv = MessageBox(browser_->GetMainWndHandle(), message.c_str(),
browser_->UIT_GetTitle().c_str(),
MB_YESNO | MB_ICONQUESTION);
return (rv == IDYES);

View File

@ -2,7 +2,7 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "cef_string.h"
#include "include/cef_string.h"
#include <limits.h>
#include <malloc.h>
#include <string.h>

56
libcef/cef_string_list.cc Normal file
View File

@ -0,0 +1,56 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "precompiled_libcef.h"
#include "include/cef_string_list.h"
#include "base/logging.h"
#include <vector>
typedef std::vector<std::wstring> StringList;
CEF_EXPORT cef_string_list_t cef_string_list_alloc()
{
return new StringList;
}
CEF_EXPORT int cef_string_list_size(cef_string_list_t list)
{
DCHECK(list);
StringList* impl = (StringList*)list;
return impl->size();
}
CEF_EXPORT cef_string_t cef_string_list_value(cef_string_list_t list, int index)
{
DCHECK(list);
StringList* impl = (StringList*)list;
DCHECK(index >= 0 && index < (int)impl->size());
if(index < 0 || index >= (int)impl->size())
return NULL;
return cef_string_alloc((*impl)[index].c_str());
}
CEF_EXPORT void cef_string_list_append(cef_string_list_t list, const wchar_t* value)
{
DCHECK(list);
StringList* impl = (StringList*)list;
std::wstring valstr;
if(value)
valstr = value;
impl->push_back(valstr);
}
CEF_EXPORT void cef_string_list_clear(cef_string_list_t list)
{
DCHECK(list);
StringList* impl = (StringList*)list;
impl->clear();
}
CEF_EXPORT void cef_string_list_free(cef_string_list_t list)
{
DCHECK(list);
delete (StringList*)list;
}

View File

@ -3,8 +3,8 @@
// can be found in the LICENSE file.
#include "precompiled_libcef.h"
#include "cef_logging.h"
#include "cef_string_map.h"
#include "include/cef_string_map.h"
#include "base/logging.h"
#include <map>

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
// Copyright (c) 2008-2009 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.
@ -19,6 +19,7 @@
#include "base/stats_table.h"
#include "base/string_util.h"
#include "net/base/net_module.h"
#include "webkit/extensions/v8/gc_extension.h"
#include "webkit/glue/webplugin.h"
#include "webkit/glue/plugins/plugin_lib.h"
#include "webkit/glue/plugins/plugin_list.h"
@ -186,6 +187,11 @@ bool CefContext::DoInitialize()
kStatsFileCounters);
StatsTable::set_current(statstable_);
// CEF always exposes the GC.
webkit_glue::SetJavaScriptFlags(L"--expose-gc");
// Expose GCController to JavaScript.
WebKit::registerExtension(extensions_v8::GCExtension::Get());
return true;
}
@ -195,10 +201,10 @@ void CefContext::DoUninitialize()
// Task objects get destroyed before we exit, which avoids noise in
// purify leak-test results.
MessageLoop::current()->RunAllPending();
BrowserResourceLoaderBridge::Shutdown();
// Tear down shared StatsTable; prevents unit_tests from leaking it.
// Tear down the shared StatsTable.
StatsTable::set_current(NULL);
delete statstable_;
statstable_ = NULL;
@ -249,8 +255,6 @@ CefContext::~CefContext()
{
// Just in case CefShutdown() isn't called
Shutdown();
DoUninitialize();
}
bool CefContext::Initialize(bool multi_threaded_message_loop,
@ -422,6 +426,8 @@ void CefContext::Shutdown()
hthreadui_ = NULL;
heventui_ = NULL;
} else {
DoUninitialize();
}
Lock();

View File

@ -1,302 +0,0 @@
// 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.
#include "precompiled_libcef.h"
#include "jscontainer.h"
#include "variant_impl.h"
// Here's the control flow of a JS method getting forwarded to a class.
// - Something calls our NPObject with a function like "Invoke".
// - CefNPObject's static invoke() function forwards it to its attached
// CefJSContainer's Invoke() method.
// - CefJSContainer has then overridden Invoke() to look up the function
// name in its internal map of methods, and then calls the appropriate
// method.
#include "base/compiler_specific.h"
#include "config.h"
// This is required for the KJS build due to an artifact of the
// npruntime_priv.h file from JavaScriptCore/bindings.
MSVC_PUSH_DISABLE_WARNING(4067)
#include "npruntime_priv.h"
MSVC_POP_WARNING()
#if USE(JSC)
MSVC_PUSH_WARNING_LEVEL(0)
#include <runtime/JSLock.h>
MSVC_POP_WARNING()
#endif
#include "base/logging.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "webkit/glue/webframe.h"
#include "webkit/glue/webview.h"
// Our special NPObject type. We extend an NPObject with a pointer to a
// CefJSContainer, which is just a C++ interface that we forward all NPObject
// callbacks to.
struct CefNPObject {
NPObject parent; // This must be the first field in the struct.
CefJSContainer* container;
WebFrame* webframe;
//
// All following objects and functions are static, and just used to interface
// with NPObject/NPClass.
//
// An NPClass associates static functions of CefNPObject with the
// function pointers used by the JS runtime.
static NPClass np_class_;
// Allocate a new NPObject with the specified class.
static NPObject* allocate(NPP npp, NPClass* aClass);
// Free an object.
static void deallocate(NPObject* obj);
// Returns true if the C++ class associated with this NPObject exposes the
// given property. Called by the JS runtime.
static bool hasProperty(NPObject *obj, NPIdentifier ident);
// Returns true if the C++ class associated with this NPObject exposes the
// given method. Called by the JS runtime.
static bool hasMethod(NPObject *obj, NPIdentifier ident);
// If the given method is exposed by the C++ class associated with this
// NPObject, invokes it with the given args and returns a result. Otherwise,
// returns "undefined" (in the JavaScript sense). Called by the JS runtime.
static bool invoke(NPObject *obj, NPIdentifier ident,
const NPVariant *args, uint32_t arg_count,
NPVariant *result);
// If the given property is exposed by the C++ class associated with this
// NPObject, returns its value. Otherwise, returns "undefined" (in the
// JavaScript sense). Called by the JS runtime.
static bool getProperty(NPObject *obj, NPIdentifier ident,
NPVariant *result);
// If the given property is exposed by the C++ class associated with this
// NPObject, sets its value. Otherwise, does nothing. Called by the JS
// runtime.
static bool setProperty(NPObject *obj, NPIdentifier ident,
const NPVariant *value);
};
// Build CefNPObject's static function pointers into an NPClass, for use
// in constructing NPObjects for the C++ classes.
NPClass CefNPObject::np_class_ = {
NP_CLASS_STRUCT_VERSION,
CefNPObject::allocate,
CefNPObject::deallocate,
/* NPInvalidateFunctionPtr */ NULL,
CefNPObject::hasMethod,
CefNPObject::invoke,
/* NPInvokeDefaultFunctionPtr */ NULL,
CefNPObject::hasProperty,
CefNPObject::getProperty,
CefNPObject::setProperty,
/* NPRemovePropertyFunctionPtr */ NULL
};
/* static */ NPObject* CefNPObject::allocate(NPP npp, NPClass* aClass) {
CefNPObject* obj = new CefNPObject;
// obj->parent will be initialized by the NPObject code calling this.
obj->container = NULL;
obj->webframe = NULL;
return &obj->parent;
}
/* static */ void CefNPObject::deallocate(NPObject* np_obj) {
CefNPObject* obj = reinterpret_cast<CefNPObject*>(np_obj);
delete obj;
}
/* static */ bool CefNPObject::hasMethod(NPObject* np_obj,
NPIdentifier ident) {
CefNPObject* obj = reinterpret_cast<CefNPObject*>(np_obj);
return obj->container->HasMethod(ident);
}
/* static */ bool CefNPObject::hasProperty(NPObject* np_obj,
NPIdentifier ident) {
CefNPObject* obj = reinterpret_cast<CefNPObject*>(np_obj);
return obj->container->HasProperty(ident);
}
/* static */ bool CefNPObject::invoke(NPObject* np_obj, NPIdentifier ident,
const NPVariant* args, uint32_t arg_count,
NPVariant* result) {
CefNPObject* obj = reinterpret_cast<CefNPObject*>(np_obj);
return obj->container->Invoke(ident, obj->webframe, args, arg_count, result);
}
/* static */ bool CefNPObject::getProperty(NPObject* np_obj,
NPIdentifier ident,
NPVariant* result) {
CefNPObject* obj = reinterpret_cast<CefNPObject*>(np_obj);
return obj->container->GetProperty(ident, obj->webframe, result);
}
/* static */ bool CefNPObject::setProperty(NPObject* np_obj,
NPIdentifier ident,
const NPVariant* value) {
CefNPObject* obj = reinterpret_cast<CefNPObject*>(np_obj);
return obj->container->SetProperty(ident, obj->webframe, value);
}
CefJSContainer::CefJSContainer(CefBrowser* browser,
CefRefPtr<CefJSHandler> handler)
: browser_(browser), handler_(handler)
{
DCHECK(browser_ != NULL);
DCHECK(handler_.get() != NULL);
}
CefJSContainer::~CefJSContainer()
{
// Unregister objects we created and bound to a frame.
for (BoundObjectList::iterator i = bound_objects_.begin();
i != bound_objects_.end(); ++i) {
#if USE(V8)
_NPN_UnregisterObject(*i);
#endif
NPN_ReleaseObject(*i);
}
}
bool CefJSContainer::HasMethod(NPIdentifier ident)
{
std::wstring name = UTF8ToWide(NPN_UTF8FromIdentifier(ident));
return handler_->HasMethod(browser_, name);
}
bool CefJSContainer::HasProperty(NPIdentifier ident)
{
std::wstring name = UTF8ToWide(NPN_UTF8FromIdentifier(ident));
return handler_->HasProperty(browser_, name);
}
bool CefJSContainer::Invoke(NPIdentifier ident,
WebFrame* frame,
const NPVariant* args,
size_t arg_count,
NPVariant* result)
{
std::wstring name = UTF8ToWide(NPN_UTF8FromIdentifier(ident));
// Build a VariantVector argument vector from the NPVariants coming in.
CefJSHandler::VariantVector cef_args(arg_count);
for (size_t i = 0; i < arg_count; i++) {
cef_args[i] = new CefVariantImpl(frame);
static_cast<CefVariantImpl*>(cef_args[i].get())->Set(args[i]);
}
CefRefPtr<CefVariant> cef_retval(new CefVariantImpl(frame));
// Execute the handler method
bool rv = handler_->ExecuteMethod(browser_, name, cef_args, cef_retval);
if(rv) {
// Assign the return value
static_cast<CefVariantImpl*>(cef_retval.get())->CopyToNPVariant(result);
}
return rv;
}
bool CefJSContainer::GetProperty(NPIdentifier ident,
WebFrame* frame,
NPVariant* result)
{
CefRefPtr<CefVariant> cef_result(new CefVariantImpl(frame));
std::wstring name = UTF8ToWide(NPN_UTF8FromIdentifier(ident));
// Execute the handler method
bool rv = handler_->GetProperty(browser_, name, cef_result);
if(rv) {
// Assign the return value
static_cast<CefVariantImpl*>(cef_result.get())->CopyToNPVariant(result);
}
return rv;
}
bool CefJSContainer::SetProperty(NPIdentifier ident,
WebFrame* frame,
const NPVariant* value)
{
std::wstring name = UTF8ToWide(NPN_UTF8FromIdentifier(ident));
// Assign the input value
CefRefPtr<CefVariant> cef_value(new CefVariantImpl(frame));
static_cast<CefVariantImpl*>(cef_value.get())->Set(*value);
// Execute the handler method
return handler_->SetProperty(browser_, name, cef_value);
}
// Check if the specified frame exists by comparing to all frames currently
// attached to the view.
static bool FrameExists(WebView* view, WebFrame* frame) {
WebFrame* main_frame = view->GetMainFrame();
WebFrame* it = main_frame;
do {
if (it == frame)
return true;
it = view->GetNextFrameAfter(it, true);
} while (it != main_frame);
return false;
}
void CefJSContainer::BindToJavascript(WebFrame* frame,
const std::wstring& classname) {
#if USE(JSC)
JSC::JSLock lock(false);
#endif
NPObject* np_obj = NULL;
CefNPObject* obj = NULL;
Lock();
WebView* view = frame->GetView();
BoundObjectList::iterator it = bound_objects_.begin();
for(; it != bound_objects_.end(); ) {
obj = reinterpret_cast<CefNPObject*>(*it);
if(obj->webframe == frame) {
// An NPObject is already bound to this particular frame.
np_obj = *it;
} else if(!FrameExists(view, obj->webframe)) {
// Remove bindings to non-existent frames.
#if USE(V8)
_NPN_UnregisterObject(*it);
#endif
NPN_ReleaseObject(*it);
it = bound_objects_.erase(it);
continue;
}
++it;
}
Unlock();
if(!np_obj) {
// Create an NPObject using our static NPClass. The first argument (a
// plugin's instance handle) is passed through to the allocate function
// directly, and we don't use it, so it's ok to be 0.
np_obj = NPN_CreateObject(0, &CefNPObject::np_class_);
obj = reinterpret_cast<CefNPObject*>(np_obj);
obj->container = this;
obj->webframe = frame;
Lock();
bound_objects_.push_back(np_obj);
Unlock();
}
// BindToWindowObject will (indirectly) retain the np_object. We save it
// so we can release it when we're destroyed.
frame->BindToWindowObject(classname, np_obj);
}

View File

@ -1,65 +0,0 @@
// 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.
#ifndef _JSCONTAINER_H
#define _JSCONTAINER_H
#include "../include/cef.h"
#include "third_party/npapi/bindings/npruntime.h"
class WebFrame;
// CefJSContainer lets you map Javascript method calls and property accesses
// directly to C++ method calls and CefVariant* variable access.
// Portions of the implementation are borrowed from
// webkit\glue\cpp_bound_class.cc
class CefJSContainer : public CefThreadSafeBase<CefBase>
{
public:
CefJSContainer(CefBrowser* browser,
CefRefPtr<CefJSHandler> handler);
~CefJSContainer();
// Given a WebFrame, BindToJavascript builds the NPObject that will represent
// the class and binds it to the frame's window under the given name. This
// should generally be called from the WebView delegate's
// WindowObjectCleared(). A class so bound will be accessible to JavaScript
// as window.<classname>. The owner of the CefJSContainer is responsible for
// keeping the object around while the frame is alive, and for destroying it
// afterwards.
void BindToJavascript(WebFrame* frame,
const std::wstring& classname);
CefRefPtr<CefJSHandler> GetHandler() { return handler_; }
protected:
bool HasMethod(NPIdentifier ident);
bool HasProperty(NPIdentifier ident);
bool Invoke(NPIdentifier ident,
WebFrame* frame,
const NPVariant* args,
size_t arg_count,
NPVariant* result);
bool GetProperty(NPIdentifier ident,
WebFrame* frame,
NPVariant* result);
bool SetProperty(NPIdentifier ident,
WebFrame* frame,
const NPVariant* value);
friend struct CefNPObject;
protected:
CefBrowser* browser_;
CefRefPtr<CefJSHandler> handler_;
// A list of all NPObjects we created and bound in BindToJavascript(), so we
// can clean them up when we're destroyed.
typedef std::vector<NPObject*> BoundObjectList;
BoundObjectList bound_objects_;
};
#endif // _JSHANDLER_CONTAINER_H

View File

@ -198,6 +198,18 @@
RelativePath="..\include\cef_ptr.h"
>
</File>
<File
RelativePath="..\include\cef_string.h"
>
</File>
<File
RelativePath="..\include\cef_string_list.h"
>
</File>
<File
RelativePath="..\include\cef_string_map.h"
>
</File>
<File
RelativePath="..\include\cef_types.h"
>
@ -291,6 +303,68 @@
RelativePath=".\browser_webview_delegate_win.cc"
>
</File>
<File
RelativePath=".\cef_string.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="BUILDING_CEF_SHARED"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="BUILDING_CEF_SHARED"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\cef_string_list.cc"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="BUILDING_CEF_SHARED"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="BUILDING_CEF_SHARED"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\cef_string_map.cc"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="BUILDING_CEF_SHARED"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="BUILDING_CEF_SHARED"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\context.cc"
>
@ -299,14 +373,6 @@
RelativePath=".\context.h"
>
</File>
<File
RelativePath=".\jscontainer.cc"
>
</File>
<File
RelativePath=".\jscontainer.h"
>
</File>
<File
RelativePath=".\precompiled_libcef.cc"
>
@ -352,19 +418,15 @@
>
</File>
<File
RelativePath=".\variant_impl.cc"
RelativePath=".\tracker.h"
>
</File>
<File
RelativePath=".\variant_impl.h"
RelativePath=".\v8_impl.cc"
>
</File>
<File
RelativePath=".\variant_np_util.cc"
>
</File>
<File
RelativePath=".\variant_np_util.h"
RelativePath=".\v8_impl.h"
>
</File>
<File

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors. All rights
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
@ -20,10 +20,6 @@ CefRequestImpl::CefRequestImpl()
{
}
CefRequestImpl::~CefRequestImpl()
{
}
std::wstring CefRequestImpl::GetURL()
{
Lock();
@ -39,21 +35,6 @@ void CefRequestImpl::SetURL(const std::wstring& url)
Unlock();
}
std::wstring CefRequestImpl::GetFrame()
{
Lock();
std::wstring frame = frame_;
Unlock();
return frame;
}
void CefRequestImpl::SetFrame(const std::wstring& frame)
{
Lock();
frame_ = frame;
Unlock();
}
std::wstring CefRequestImpl::GetMethod()
{
Lock();
@ -99,14 +80,12 @@ void CefRequestImpl::SetHeaderMap(const HeaderMap& headerMap)
}
void CefRequestImpl::Set(const std::wstring& url,
const std::wstring& frame,
const std::wstring& method,
CefRefPtr<CefPostData> postData,
const HeaderMap& headerMap)
const std::wstring& method,
CefRefPtr<CefPostData> postData,
const HeaderMap& headerMap)
{
Lock();
url_ = url;
frame_ = frame;
method_ = method;
postdata_ = postData;
headermap_ = headerMap;
@ -150,11 +129,6 @@ CefPostDataImpl::CefPostDataImpl()
{
}
CefPostDataImpl::~CefPostDataImpl()
{
RemoveElements();
}
size_t CefPostDataImpl::GetElementCount()
{
Lock();

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors. All rights
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
@ -15,12 +15,10 @@ class CefRequestImpl : public CefThreadSafeBase<CefRequest>
{
public:
CefRequestImpl();
~CefRequestImpl();
~CefRequestImpl() {}
virtual std::wstring GetURL();
virtual void SetURL(const std::wstring& url);
virtual std::wstring GetFrame();
virtual void SetFrame(const std::wstring& frame);
virtual std::wstring GetMethod();
virtual void SetMethod(const std::wstring& method);
virtual CefRefPtr<CefPostData> GetPostData();
@ -28,7 +26,6 @@ public:
virtual void GetHeaderMap(HeaderMap& headerMap);
virtual void SetHeaderMap(const HeaderMap& headerMap);
virtual void Set(const std::wstring& url,
const std::wstring& frame,
const std::wstring& method,
CefRefPtr<CefPostData> postData,
const HeaderMap& headerMap);
@ -38,7 +35,6 @@ public:
protected:
std::wstring url_;
std::wstring frame_;
std::wstring method_;
CefRefPtr<CefPostData> postdata_;
HeaderMap headermap_;
@ -49,7 +45,7 @@ class CefPostDataImpl : public CefThreadSafeBase<CefPostData>
{
public:
CefPostDataImpl();
~CefPostDataImpl();
~CefPostDataImpl() {}
virtual size_t GetElementCount();
virtual void GetElements(ElementVector& elements);

136
libcef/tracker.h Normal file
View File

@ -0,0 +1,136 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _TRACKER_H
#define _TRACKER_H
#include "include/cef.h"
// Class extended by objects that must be tracked. After creating a tracked
// object you should add it to the appropriate track manager.
class CefTrackObject
{
public:
CefTrackObject()
{
track_next_ = NULL;
track_prev_ = NULL;
}
virtual ~CefTrackObject()
{
}
// Returns true if the object is currently being tracked.
bool IsTracked() { return (track_prev_ || track_next_); }
private:
CefTrackObject* GetTrackPrev() { return track_prev_; }
void SetTrackPrev(CefTrackObject* base) { track_prev_ = base; }
CefTrackObject* GetTrackNext() { return track_next_; }
void SetTrackNext(CefTrackObject* base) { track_next_ = base; }
// Insert a new object into the tracking list before this object.
void InsertTrackPrev(CefTrackObject* object)
{
if(track_prev_)
track_prev_->SetTrackNext(object);
object->SetTrackNext(this);
object->SetTrackPrev(track_prev_);
track_prev_ = object;
}
// Insert a new object into the tracking list after this object.
void InsertTrackNext(CefTrackObject* object)
{
if(track_next_)
track_next_->SetTrackPrev(object);
object->SetTrackPrev(this);
object->SetTrackNext(track_next_);
track_next_ = object;
}
// Remove this object from the tracking list.
void RemoveTracking()
{
if(track_next_)
track_next_->SetTrackPrev(track_prev_);
if(track_prev_)
track_prev_->SetTrackNext(track_next_);
track_next_ = NULL;
track_prev_ = NULL;
}
private:
CefTrackObject* track_next_;
CefTrackObject* track_prev_;
friend class CefTrackManager;
};
// Class used to manage tracked objects. A single instance of this class
// should be created for each intended usage. Any objects that have not been
// removed by explicit calls to the Destroy() method will be removed when the
// manager object is destroyed. A manager object can be created as either a
// member variable of another class or by using lazy initialization:
// base::LazyInstance<CefTrackManager> g_singleton(base::LINKER_INITIALIZED);
class CefTrackManager : public CefThreadSafeBase<CefBase>
{
public:
CefTrackManager() : object_count_(0) {}
virtual ~CefTrackManager()
{
DeleteAll();
}
// Add an object to be tracked by this manager.
void Add(CefTrackObject* object)
{
Lock();
if(!object->IsTracked()) {
tracker_.InsertTrackNext(object);
++object_count_;
}
Unlock();
}
// Delete an object tracked by this manager.
bool Delete(CefTrackObject* object)
{
bool rv = false;
Lock();
if(object->IsTracked()) {
object->RemoveTracking();
delete object;
--object_count_;
rv = true;
}
Unlock();
return rv;
}
// Delete all objects tracked by this manager.
void DeleteAll()
{
Lock();
CefTrackObject* next;
do {
next = tracker_.GetTrackNext();
if(next) {
next->RemoveTracking();
delete next;
}
} while(next != NULL);
object_count_ = 0;
Unlock();
}
// Returns the number of objects currently being tracked.
long GetCount() { return object_count_; }
private:
CefTrackObject tracker_;
long object_count_;
};
#endif // _TRACKER_H

687
libcef/v8_impl.cc Normal file
View File

@ -0,0 +1,687 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "precompiled_libcef.h"
#include "v8_impl.h"
#include "context.h"
#include "tracker.h"
#include "base/lazy_instance.h"
#include "webkit/api/public/WebKit.h"
// Memory manager.
base::LazyInstance<CefTrackManager> g_v8_tracker(base::LINKER_INITIALIZED);
class TrackBase : public CefTrackObject
{
public:
TrackBase(CefBase* base) { base_ = base; }
protected:
CefRefPtr<CefBase> base_;
};
class TrackString : public CefTrackObject
{
public:
TrackString(const std::string& str) : string_(str) {}
const char* GetString() { return string_.c_str(); }
private:
std::string string_;
};
static void TrackAdd(CefTrackObject* object)
{
g_v8_tracker.Pointer()->Add(object);
}
static void TrackDelete(CefTrackObject* object)
{
g_v8_tracker.Pointer()->Delete(object);
}
// Callback for weak persistent reference destruction.
static void TrackDestructor(v8::Persistent<v8::Value> object,
void* parameter)
{
if(parameter)
TrackDelete(static_cast<CefTrackObject*>(parameter));
}
// Convert a wide string to a V8 string.
static v8::Handle<v8::String> GetV8String(const std::wstring& str)
{
return v8::String::New(
reinterpret_cast<const uint16_t*>(str.c_str()), str.length());
}
// Convert a V8 string to a wide string.
static std::wstring GetWString(v8::Handle<v8::String> str)
{
uint16_t* buf = new uint16_t[str->Length()+1];
str->Write(buf);
std::wstring value = reinterpret_cast<wchar_t*>(buf);
delete [] buf;
return value;
}
// V8 function callback
static v8::Handle<v8::Value> FunctionCallbackImpl(const v8::Arguments& args)
{
v8::HandleScope handle_scope;
CefV8Handler* handler =
static_cast<CefV8Handler*>(v8::External::Unwrap(args.Data()));
CefV8ValueList params;
for(int i = 0; i < args.Length(); i++)
params.push_back(new CefV8ValueImpl(args[i]));
std::wstring func_name =
GetWString(v8::Handle<v8::String>::Cast(args.Callee()->GetName()));
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(args.This());
CefRefPtr<CefV8Value> retval;
std::wstring exception;
v8::Handle<v8::Value> value = v8::Null();
if(handler->Execute(func_name, object, params, retval, exception)) {
if(!exception.empty())
value = v8::ThrowException(GetV8String(exception));
else {
CefV8ValueImpl* rv = static_cast<CefV8ValueImpl*>(retval.get());
if(rv)
value = rv->GetValue();
}
}
return value;
}
// V8 extension registration.
class ExtensionWrapper : public v8::Extension {
public:
ExtensionWrapper(const char* extension_name,
const char* javascript_code,
CefV8Handler* handler)
: v8::Extension(extension_name, javascript_code), handler_(handler)
{
// The reference will be released when the application exits.
TrackAdd(new TrackBase(handler));
}
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
v8::Handle<v8::String> name)
{
return v8::FunctionTemplate::New(FunctionCallbackImpl,
v8::External::New(handler_));
}
void UIT_RegisterExtension()
{
WebKit::registerExtension(this);
}
void AddRef() {}
void Release() {}
private:
CefV8Handler* handler_;
};
bool CefRegisterExtension(const std::wstring& extension_name,
const std::wstring& javascript_code,
CefRefPtr<CefV8Handler> handler)
{
// Verify that the context is already initialized
if(!_Context.get())
return false;
if(!handler.get())
return false;
TrackString* name = new TrackString(WideToUTF8(extension_name));
TrackAdd(name);
TrackString* code = new TrackString(WideToUTF8(javascript_code));
TrackAdd(name);
ExtensionWrapper* wrapper = new ExtensionWrapper(name->GetString(),
code->GetString(), handler.get());
PostTask(FROM_HERE, NewRunnableMethod(wrapper,
&ExtensionWrapper::UIT_RegisterExtension));
return true;
}
// CefV8Value
// static
CefRefPtr<CefV8Value> CefV8Value::CreateUndefined()
{
v8::HandleScope handle_scope;
return new CefV8ValueImpl(v8::Undefined());
}
// static
CefRefPtr<CefV8Value> CefV8Value::CreateNull()
{
v8::HandleScope handle_scope;
return new CefV8ValueImpl(v8::Null());
}
// static
CefRefPtr<CefV8Value> CefV8Value::CreateBool(bool value)
{
v8::HandleScope handle_scope;
return new CefV8ValueImpl(v8::Boolean::New(value));
}
// static
CefRefPtr<CefV8Value> CefV8Value::CreateInt(int value)
{
v8::HandleScope handle_scope;
return new CefV8ValueImpl(v8::Int32::New(value));
}
// static
CefRefPtr<CefV8Value> CefV8Value::CreateDouble(double value)
{
v8::HandleScope handle_scope;
return new CefV8ValueImpl(v8::Number::New(value));
}
// static
CefRefPtr<CefV8Value> CefV8Value::CreateString(const std::wstring& value)
{
v8::HandleScope handle_scope;
return new CefV8ValueImpl(GetV8String(value));
}
// static
CefRefPtr<CefV8Value> CefV8Value::CreateObject(CefRefPtr<CefBase> user_data)
{
v8::HandleScope handle_scope;
CefV8ValueImpl* impl = new CefV8ValueImpl();
// Create the new V8 object.
v8::Local<v8::Object> obj = v8::Object::New();
TrackBase *tracker = NULL;
if(user_data.get()) {
// Attach the user data to the V8 object.
v8::Local<v8::Value> data = v8::External::Wrap(user_data.get());
obj->Set(v8::String::New("Cef::UserData"), data);
// Provide a tracker object that will cause the user data reference to be
// released when the V8 object is destroyed.
tracker = new TrackBase(user_data);
}
// Attach to the CefV8ValueImpl.
impl->Attach(obj, tracker);
return impl;
}
// static
CefRefPtr<CefV8Value> CefV8Value::CreateArray()
{
v8::HandleScope handle_scope;
return new CefV8ValueImpl(v8::Array::New());
}
// static
CefRefPtr<CefV8Value> CefV8Value::CreateFunction(const std::wstring& name,
CefRefPtr<CefV8Handler> handler)
{
v8::HandleScope handle_scope;
CefV8ValueImpl* impl = new CefV8ValueImpl();
// Create a new V8 function template with one internal field.
v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New();
v8::Local<v8::Value> data = v8::External::Wrap(handler.get());
// Set the function handler callback.
tmpl->SetCallHandler(FunctionCallbackImpl, data);
// Retrieve the function object and set the name.
v8::Local<v8::Function> func = tmpl->GetFunction();
func->SetName(GetV8String(name));
// Attach the handler instance to the V8 object.
func->Set(v8::String::New("Cef::Handler"), data);
// Attach to the CefV8ValueImpl and provide a tracker object that will cause
// the handler reference to be released when the V8 object is destroyed.
impl->Attach(func, new TrackBase(handler));
return impl;
}
// CefV8ValueImpl
CefV8ValueImpl::CefV8ValueImpl()
: tracker_(NULL)
{
}
CefV8ValueImpl::CefV8ValueImpl(v8::Handle<v8::Value> value,
CefTrackObject* tracker)
{
Attach(value, tracker);
}
CefV8ValueImpl::~CefV8ValueImpl()
{
Detach();
}
bool CefV8ValueImpl::Attach(v8::Handle<v8::Value> value,
CefTrackObject* tracker)
{
bool rv = false;
Lock();
if(v8_value_.IsEmpty()) {
v8_value_ = v8::Persistent<v8::Value>::New(value);
tracker_ = tracker;
rv = true;
}
Unlock();
return rv;
}
void CefV8ValueImpl::Detach()
{
Lock();
if(tracker_)
TrackAdd(tracker_);
v8_value_.MakeWeak(tracker_, TrackDestructor);
v8_value_.Clear();
tracker_ = NULL;
Unlock();
}
v8::Handle<v8::Value> CefV8ValueImpl::GetValue()
{
v8::HandleScope handle_scope;
v8::Handle<v8::Value> rv;
Lock();
rv = v8_value_;
Unlock();
return rv;
}
bool CefV8ValueImpl::IsReservedKey(const std::wstring& key)
{
return (key.find(L"Cef::") == 0 || key.find(L"v8::") == 0);
}
bool CefV8ValueImpl::IsUndefined()
{
Lock();
bool rv = v8_value_->IsUndefined();
Unlock();
return rv;
}
bool CefV8ValueImpl::IsNull()
{
Lock();
bool rv = v8_value_->IsNull();
Unlock();
return rv;
}
bool CefV8ValueImpl::IsBool()
{
Lock();
bool rv = (v8_value_->IsBoolean() || v8_value_->IsTrue()
|| v8_value_->IsFalse());
Unlock();
return rv;
}
bool CefV8ValueImpl::IsInt()
{
Lock();
bool rv = v8_value_->IsInt32();
Unlock();
return rv;
}
bool CefV8ValueImpl::IsDouble()
{
Lock();
bool rv = (v8_value_->IsNumber() || v8_value_->IsDate());
Unlock();
return rv;
}
bool CefV8ValueImpl::IsString()
{
Lock();
bool rv = v8_value_->IsString();
Unlock();
return rv;
}
bool CefV8ValueImpl::IsObject()
{
Lock();
bool rv = v8_value_->IsObject();
Unlock();
return rv;
}
bool CefV8ValueImpl::IsArray()
{
Lock();
bool rv = v8_value_->IsArray();
Unlock();
return rv;
}
bool CefV8ValueImpl::IsFunction()
{
Lock();
bool rv = v8_value_->IsFunction();
Unlock();
return rv;
}
bool CefV8ValueImpl::GetBoolValue()
{
bool rv = false;
Lock();
if(v8_value_->IsTrue())
rv = true;
else if(v8_value_->IsFalse())
rv = false;
else {
v8::HandleScope handle_scope;
v8::Local<v8::Boolean> val = v8_value_->ToBoolean();
rv = val->Value();
}
Unlock();
return rv;
}
int CefV8ValueImpl::GetIntValue()
{
int rv = 0;
Lock();
v8::HandleScope handle_scope;
v8::Local<v8::Int32> val = v8_value_->ToInt32();
rv = val->Value();
Unlock();
return rv;
}
double CefV8ValueImpl::GetDoubleValue()
{
double rv = 0.;
Lock();
v8::HandleScope handle_scope;
v8::Local<v8::Number> val = v8_value_->ToNumber();
rv = val->Value();
Unlock();
return rv;
}
std::wstring CefV8ValueImpl::GetStringValue()
{
std::wstring rv;
Lock();
v8::HandleScope handle_scope;
rv = GetWString(v8_value_->ToString());
Unlock();
return rv;
}
bool CefV8ValueImpl::HasValue(const std::wstring& key)
{
if(IsReservedKey(key))
return false;
bool rv = false;
Lock();
if(v8_value_->IsObject()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
rv = obj->Has(GetV8String(key));
}
Unlock();
return rv;
}
bool CefV8ValueImpl::HasValue(int index)
{
bool rv = false;
Lock();
if(v8_value_->IsObject()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
rv = obj->Has(index);
}
Unlock();
return rv;
}
bool CefV8ValueImpl::DeleteValue(const std::wstring& key)
{
if(IsReservedKey(key))
return false;
bool rv = false;
Lock();
if(v8_value_->IsObject()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
rv = obj->Delete(GetV8String(key));
}
Unlock();
return rv;
}
bool CefV8ValueImpl::DeleteValue(int index)
{
bool rv = false;
Lock();
if(v8_value_->IsObject()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
rv = obj->Delete(index);
}
Unlock();
return rv;
}
CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(const std::wstring& key)
{
if(IsReservedKey(key))
return false;
CefRefPtr<CefV8Value> rv;
Lock();
if(v8_value_->IsObject()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
rv = new CefV8ValueImpl(obj->Get(GetV8String(key)));
}
Unlock();
return rv;
}
CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(int index)
{
CefRefPtr<CefV8Value> rv;
Lock();
if(v8_value_->IsObject()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
rv = new CefV8ValueImpl(obj->Get(v8::Number::New(index)));
}
Unlock();
return rv;
}
bool CefV8ValueImpl::SetValue(const std::wstring& key,
CefRefPtr<CefV8Value> value)
{
if(IsReservedKey(key))
return false;
bool rv = false;
Lock();
if(v8_value_->IsObject()) {
CefV8ValueImpl *impl = static_cast<CefV8ValueImpl*>(value.get());
if(impl) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
rv = obj->Set(GetV8String(key), impl->GetValue());
}
}
Unlock();
return rv;
}
bool CefV8ValueImpl::SetValue(int index, CefRefPtr<CefV8Value> value)
{
bool rv = false;
Lock();
if(v8_value_->IsObject()) {
CefV8ValueImpl *impl = static_cast<CefV8ValueImpl*>(value.get());
if(impl) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
rv = obj->Set(v8::Number::New(index), impl->GetValue());
}
}
Unlock();
return rv;
}
bool CefV8ValueImpl::GetKeys(std::vector<std::wstring>& keys)
{
bool rv = false;
Lock();
if(v8_value_->IsObject()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
v8::Local<v8::Array> arr_keys = obj->GetPropertyNames();
uint32_t len = arr_keys->Length();
for(uint32_t i = 0; i < len; ++i) {
v8::Local<v8::Value> value = arr_keys->Get(v8::Integer::New(i));
std::wstring str = GetWString(value->ToString());
if(!IsReservedKey(str))
keys.push_back(str);
}
rv = true;
}
Unlock();
return rv;
}
CefRefPtr<CefBase> CefV8ValueImpl::GetUserData()
{
CefRefPtr<CefBase> rv;
Lock();
if(v8_value_->IsObject()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
v8::Local<v8::String> key = v8::String::New("Cef::UserData");
if(obj->Has(key))
rv = static_cast<CefBase*>(v8::External::Unwrap(obj->Get(key)));
}
Unlock();
return rv;
}
int CefV8ValueImpl::GetArrayLength()
{
int rv = 0;
Lock();
if(v8_value_->IsArray()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
v8::Local<v8::Array> arr = v8::Local<v8::Array>::Cast(obj);
rv = arr->Length();
}
Unlock();
return rv;
}
std::wstring CefV8ValueImpl::GetFunctionName()
{
std::wstring rv;
Lock();
if(v8_value_->IsFunction()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(obj);
rv = GetWString(v8::Handle<v8::String>::Cast(func->GetName()));
}
Unlock();
return rv;
}
CefRefPtr<CefV8Handler> CefV8ValueImpl::GetFunctionHandler()
{
CefRefPtr<CefV8Handler> rv;
Lock();
if(v8_value_->IsFunction()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
v8::Local<v8::String> key = v8::String::New("Cef::Handler");
if(obj->Has(key))
rv = static_cast<CefV8Handler*>(v8::External::Unwrap(obj->Get(key)));
}
Unlock();
return rv;
}
bool CefV8ValueImpl::ExecuteFunction(CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
bool rv = false;
Lock();
if(v8_value_->IsFunction() && object.get() && object->IsObject()) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = v8_value_->ToObject();
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(obj);
CefV8ValueImpl* recv_impl = static_cast<CefV8ValueImpl*>(object.get());
v8::Handle<v8::Object> recv =
v8::Handle<v8::Object>::Cast(recv_impl->GetValue());
int argc = arguments.size();
v8::Handle<v8::Value> *argv = NULL;
if(argc > 0) {
argv = new v8::Handle<v8::Value>[argc];
for(int i = 0; i < argc; ++i) {
argv[i] =
static_cast<CefV8ValueImpl*>(arguments[i].get())->GetValue();
}
}
v8::TryCatch try_catch;
v8::Local<v8::Value> func_rv = func->Call(recv, argc, argv);
if (try_catch.HasCaught())
exception = GetWString(try_catch.Message()->Get());
else
retval = new CefV8ValueImpl(func_rv);
rv = true;
}
Unlock();
return rv;
}

61
libcef/v8_impl.h Normal file
View File

@ -0,0 +1,61 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _V8_IMPL_H
#define _V8_IMPL_H
#include "include/cef.h"
#include "v8/include/v8.h"
class CefTrackObject;
class CefV8ValueImpl : public CefThreadSafeBase<CefV8Value>
{
public:
CefV8ValueImpl();
CefV8ValueImpl(v8::Handle<v8::Value> value, CefTrackObject* tracker = NULL);
virtual ~CefV8ValueImpl();
bool Attach(v8::Handle<v8::Value> value, CefTrackObject* tracker = NULL);
void Detach();
v8::Handle<v8::Value> GetValue();
bool IsReservedKey(const std::wstring& key);
virtual bool IsUndefined();
virtual bool IsNull();
virtual bool IsBool();
virtual bool IsInt();
virtual bool IsDouble();
virtual bool IsString();
virtual bool IsObject();
virtual bool IsArray();
virtual bool IsFunction();
virtual bool GetBoolValue();
virtual int GetIntValue();
virtual double GetDoubleValue();
virtual std::wstring GetStringValue();
virtual bool HasValue(const std::wstring& key);
virtual bool HasValue(int index);
virtual bool DeleteValue(const std::wstring& key);
virtual bool DeleteValue(int index);
virtual CefRefPtr<CefV8Value> GetValue(const std::wstring& key);
virtual CefRefPtr<CefV8Value> GetValue(int index);
virtual bool SetValue(const std::wstring& key, CefRefPtr<CefV8Value> value);
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value);
virtual bool GetKeys(std::vector<std::wstring>& keys);
virtual CefRefPtr<CefBase> GetUserData();
virtual int GetArrayLength();
virtual std::wstring GetFunctionName();
virtual CefRefPtr<CefV8Handler> GetFunctionHandler();
virtual bool ExecuteFunction(CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception);
protected:
v8::Persistent<v8::Value> v8_value_;
CefTrackObject* tracker_;
};
#endif //_V8_IMPL_H

View File

@ -1,370 +0,0 @@
// 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.
#include "precompiled_libcef.h"
#include "variant_impl.h"
#include "variant_np_util.h"
#include "base/compiler_specific.h"
#include "config.h"
MSVC_PUSH_WARNING_LEVEL(0);
#include "DOMWindow.h"
#include "Frame.h"
#include "npruntime_priv.h" // for NPN_InitializeVariantWithStringCopy
MSVC_POP_WARNING();
#undef LOG
#include "base/logging.h"
#include "base/string_util.h"
#include "webkit/glue/webframe.h"
CefVariantImpl::CefVariantImpl()
{
variant_.type = NPVariantType_Null;
webframe_ = NULL;
}
CefVariantImpl::CefVariantImpl(WebFrame *webframe)
{
variant_.type = NPVariantType_Null;
webframe_ = webframe;
}
// Note that Set() performs a deep copy, which is necessary to safely
// call SetNull() on the value in the destructor.
CefVariantImpl::CefVariantImpl(const CefVariantImpl& original)
{
Lock();
variant_.type = NPVariantType_Null;
Set(*original.GetNPVariant());
Unlock();
}
// See comment for copy constructor, above.
CefVariantImpl& CefVariantImpl::operator=(const CefVariantImpl& original)
{
if (&original != this) {
Lock();
Set(*original.GetNPVariant());
Unlock();
}
return *this;
}
CefVariantImpl::~CefVariantImpl()
{
SetNull();
}
CefVariant::Type CefVariantImpl::GetType()
{
CefVariant::Type type = VARIANT_TYPE_NULL;
Lock();
// determine the data type of the underlying NPVariant value
switch (variant_.type) {
case NPVariantType_Bool:
type = VARIANT_TYPE_BOOL;
break;
case NPVariantType_Int32:
type = VARIANT_TYPE_INT;
break;
case NPVariantType_Double:
type = VARIANT_TYPE_DOUBLE;
break;
case NPVariantType_String:
type = VARIANT_TYPE_STRING;
break;
case NPVariantType_Object:
{
// determine the most appropriate array type for the NPVariant object
NPVariantType nptype;
if(_NPN_ArrayObjectToVectorTypeHint(variant_.value.objectValue, nptype)) {
switch(nptype) {
case NPVariantType_Bool:
type = VARIANT_TYPE_BOOL_ARRAY;
break;
case NPVariantType_Int32:
type = VARIANT_TYPE_INT_ARRAY;
break;
case NPVariantType_Double:
type = VARIANT_TYPE_DOUBLE_ARRAY;
break;
case NPVariantType_String:
type = VARIANT_TYPE_STRING_ARRAY;
break;
}
}
}
break;
}
Unlock();
return type;
}
void CefVariantImpl::SetNull()
{
Lock();
NPN_ReleaseVariantValue(&variant_);
variant_.type = NPVariantType_Null;
Unlock();
}
void CefVariantImpl::SetBool(bool val)
{
Lock();
if(variant_.type != NPVariantType_Bool) {
SetNull();
variant_.type = NPVariantType_Bool;
}
variant_.value.boolValue = val;
Unlock();
}
void CefVariantImpl::SetInt(int val)
{
Lock();
if(variant_.type != NPVariantType_Int32) {
SetNull();
variant_.type = NPVariantType_Int32;
}
variant_.value.intValue = val;
Unlock();
}
void CefVariantImpl::SetDouble(double val)
{
Lock();
if(variant_.type != NPVariantType_Double) {
SetNull();
variant_.type = NPVariantType_Double;
}
variant_.value.doubleValue = val;
Unlock();
}
void CefVariantImpl::SetString(const std::wstring& val)
{
Lock();
SetNull();
variant_.type = NPVariantType_String;
std::string str = WideToUTF8(val);
NPString new_string = {str.c_str(),
static_cast<uint32_t>(str.size())};
_NPN_InitializeVariantWithStringCopy(&variant_, &new_string);
Unlock();
}
void CefVariantImpl::SetBoolArray(const std::vector<bool>& val)
{
Lock();
DCHECK(webframe_ != NULL);
WebCore::Frame* frame =
static_cast<WebCore::Frame*>(webframe_->GetFrameImplementation());
WebCore::DOMWindow* domwindow = frame->domWindow();
NPObject* npobject = _NPN_BooleanVectorToArrayObject(domwindow, val);
DCHECK(npobject != NULL);
Set(npobject);
Unlock();
}
void CefVariantImpl::SetIntArray(const std::vector<int>& val)
{
Lock();
DCHECK(webframe_ != NULL);
WebCore::Frame* frame =
static_cast<WebCore::Frame*>(webframe_->GetFrameImplementation());
WebCore::DOMWindow* domwindow = frame->domWindow();
NPObject* npobject = _NPN_IntVectorToArrayObject(domwindow, val);
DCHECK(npobject != NULL);
Set(npobject);
Unlock();
}
void CefVariantImpl::SetDoubleArray(const std::vector<double>& val)
{
Lock();
DCHECK(webframe_ != NULL);
WebCore::Frame* frame =
static_cast<WebCore::Frame*>(webframe_->GetFrameImplementation());
WebCore::DOMWindow* domwindow = frame->domWindow();
NPObject* npobject = _NPN_DoubleVectorToArrayObject(domwindow, val);
DCHECK(npobject != NULL);
Set(npobject);
Unlock();
}
void CefVariantImpl::SetStringArray(const std::vector<std::wstring>& val)
{
Lock();
DCHECK(webframe_ != NULL);
WebCore::Frame* frame =
static_cast<WebCore::Frame*>(webframe_->GetFrameImplementation());
WebCore::DOMWindow* domwindow = frame->domWindow();
NPObject* npobject = _NPN_WStringVectorToArrayObject(domwindow, val);
DCHECK(npobject != NULL);
Set(npobject);
Unlock();
}
bool CefVariantImpl::GetBool()
{
Lock();
DCHECK(variant_.type == NPVariantType_Bool);
bool rv = variant_.value.boolValue;
Unlock();
return rv;
}
int CefVariantImpl::GetInt()
{
Lock();
DCHECK(variant_.type == NPVariantType_Int32);
int rv = variant_.value.intValue;
Unlock();
return rv;
}
double CefVariantImpl::GetDouble()
{
Lock();
DCHECK(variant_.type == NPVariantType_Double);
double rv = variant_.value.doubleValue;
Unlock();
return rv;
}
std::wstring CefVariantImpl::GetString()
{
Lock();
DCHECK(variant_.type == NPVariantType_String);
std::wstring rv = UTF8ToWide(
std::string(
variant_.value.stringValue.UTF8Characters,
variant_.value.stringValue.UTF8Length));
Unlock();
return rv;
}
bool CefVariantImpl::GetBoolArray(std::vector<bool>& val)
{
Lock();
DCHECK(variant_.type == NPVariantType_Object);
bool rv = _NPN_ArrayObjectToBooleanVector(variant_.value.objectValue, val);
Unlock();
return rv;
}
bool CefVariantImpl::GetIntArray(std::vector<int>& val)
{
Lock();
DCHECK(variant_.type == NPVariantType_Object);
bool rv = _NPN_ArrayObjectToIntVector(variant_.value.objectValue, val);
Unlock();
return rv;
}
bool CefVariantImpl::GetDoubleArray(std::vector<double>& val)
{
Lock();
DCHECK(variant_.type == NPVariantType_Object);
bool rv = _NPN_ArrayObjectToDoubleVector(variant_.value.objectValue, val);
Unlock();
return rv;
}
bool CefVariantImpl::GetStringArray(std::vector<std::wstring>& val)
{
Lock();
DCHECK(variant_.type == NPVariantType_Object);
bool rv = _NPN_ArrayObjectToWStringVector(variant_.value.objectValue, val);
Unlock();
return rv;
}
int CefVariantImpl::GetArraySize()
{
Lock();
DCHECK(variant_.type == NPVariantType_Object);
int rv = _NPN_ArrayObjectGetVectorSize(variant_.value.objectValue);
Unlock();
return rv;
}
void CefVariantImpl::CopyToNPVariant(NPVariant* result)
{
Lock();
result->type = variant_.type;
switch (variant_.type) {
case NPVariantType_Bool:
result->value.boolValue = variant_.value.boolValue;
break;
case NPVariantType_Int32:
result->value.intValue = variant_.value.intValue;
break;
case NPVariantType_Double:
result->value.doubleValue = variant_.value.doubleValue;
break;
case NPVariantType_String:
_NPN_InitializeVariantWithStringCopy(result, &variant_.value.stringValue);
break;
case NPVariantType_Null:
case NPVariantType_Void:
// Nothing to set.
break;
case NPVariantType_Object:
result->type = NPVariantType_Object;
result->value.objectValue = NPN_RetainObject(variant_.value.objectValue);
break;
}
Unlock();
}
void CefVariantImpl::Set(NPObject* val)
{
Lock();
SetNull();
variant_.type = NPVariantType_Object;
variant_.value.objectValue = NPN_RetainObject(val);
Unlock();
}
void CefVariantImpl::Set(const NPString& val)
{
Lock();
SetNull();
variant_.type = NPVariantType_String;
_NPN_InitializeVariantWithStringCopy(&variant_, &val);
Unlock();
}
void CefVariantImpl::Set(const NPVariant& val)
{
Lock();
SetNull();
switch (val.type) {
case NPVariantType_Bool:
SetBool(val.value.boolValue);
break;
case NPVariantType_Int32:
SetInt(val.value.intValue);
break;
case NPVariantType_Double:
SetDouble(val.value.doubleValue);
break;
case NPVariantType_String:
Set(val.value.stringValue);
break;
case NPVariantType_Object:
Set(val.value.objectValue);
break;
}
Unlock();
}

View File

@ -1,77 +0,0 @@
// 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.
#ifndef _VARIANT_IMPL_H
#define _VARIANT_IMPL_H
#include "../include/cef.h"
#include "third_party/npapi/bindings/npruntime.h"
class WebFrame;
// Implementation of CefPostDataElement that provides a class wrapper for an
// NPVariant structure.
// Portions of the implementation are borrowed from webkit\glue\cpp_variant.cc
class CefVariantImpl : public CefThreadSafeBase<CefVariant>
{
public:
CefVariantImpl();
CefVariantImpl(WebFrame *webframe);
~CefVariantImpl();
virtual Type GetType();
virtual void SetNull();
virtual void SetBool(bool val);
virtual void SetInt(int val);
virtual void SetDouble(double val);
virtual void SetString(const std::wstring& val);
virtual void SetBoolArray(const std::vector<bool>& val);
virtual void SetIntArray(const std::vector<int>& val);
virtual void SetDoubleArray(const std::vector<double>& val);
virtual void SetStringArray(const std::vector<std::wstring>& val);
virtual bool GetBool();
virtual int GetInt();
virtual double GetDouble();
virtual std::wstring GetString();
virtual bool GetBoolArray(std::vector<bool>& val);
virtual bool GetIntArray(std::vector<int>& val);
virtual bool GetDoubleArray(std::vector<double>& val);
virtual bool GetStringArray(std::vector<std::wstring>& val);
virtual int GetArraySize();
// These three methods all perform deep copies of any string data. This
// allows the local CefVariantImpl to be released by the destructor without
// corrupting their sources. In performance-critical code, or when strings
// are very long, avoid creating new CefVariantImpl.
// In case of NPObject as the data, the copying involves ref-counting
// as opposed to deep-copying. The ref-counting ensures that sources don't
// get corrupted when the copies get destroyed.
void CopyToNPVariant(NPVariant* result);
CefVariantImpl& operator=(const CefVariantImpl& original);
CefVariantImpl(const CefVariantImpl& original);
// Note that setting a CefVariant to an NPObject involves ref-counting
// the actual object. SetNull() should only be called if the CefVariant
// is no longer needed. The other Set() methods handle this internally.
// Also, the object's NPClass is expected to be a static object: neither
// the NP runtime nor CefVariant will ever free it.
void Set(NPObject* val);
void Set(const NPString& val);
void Set(const NPVariant& val);
const NPVariant* GetNPVariant() const { return &variant_; }
protected:
// Underlying NPVariant structure.
NPVariant variant_;
// Pointer to the WebFrame that represents the context for this CefVariant
// object. This pointer is used for creating new NPObjects in the Set*()
// methods that accept array arguments.
WebFrame* webframe_;
};
#endif // _VARIANT_IMPL_H

View File

@ -1,227 +0,0 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "precompiled_libcef.h"
#include "variant_np_util.h"
#include "config.h"
#include <v8.h>
#include "NPV8Object.h"
#include "v8_proxy.h"
#undef LOG
#include "base/string_util.h"
#include "bindings/npruntime.h"
// npScriptObjectClass defined in webkit\port\bindings\v8\NPV8Object.cpp
extern NPClass* npScriptObjectClass;
NPObject* _NPN_StringVectorToArrayObject(WebCore::DOMWindow* domwindow,
const std::vector<std::string>& vec) {
v8::Local<v8::Array> array = v8::Array::New();
for (uint32_t index = 0; index < vec.size(); ++index) {
array->Set(v8::Integer::New(index),
v8::String::New(vec[index].c_str(), vec[index].length()));
}
return npCreateV8ScriptObject(0, array, domwindow);
}
NPObject* _NPN_WStringVectorToArrayObject(WebCore::DOMWindow* domwindow,
const std::vector<std::wstring>& vec) {
v8::Local<v8::Array> array = v8::Array::New();
for (uint32_t index = 0; index < vec.size(); ++index) {
std::string str = WideToUTF8(vec[index].c_str());
array->Set(v8::Integer::New(index),
v8::String::New(str.c_str(), str.length()));
}
return npCreateV8ScriptObject(0, array, domwindow);
}
NPObject* _NPN_IntVectorToArrayObject(WebCore::DOMWindow* domwindow,
const std::vector<int>& vec) {
v8::Local<v8::Array> array = v8::Array::New();
for (uint32_t index = 0; index < vec.size(); ++index) {
array->Set(v8::Integer::New(index), v8::Int32::New(vec[index]));
}
return npCreateV8ScriptObject(0, array, domwindow);
}
NPObject* _NPN_DoubleVectorToArrayObject(WebCore::DOMWindow* domwindow,
const std::vector<double>& vec) {
v8::Local<v8::Array> array = v8::Array::New();
for (uint32_t index = 0; index < vec.size(); ++index) {
array->Set(v8::Integer::New(index), v8::Number::New(vec[index]));
}
return npCreateV8ScriptObject(0, array, domwindow);
}
NPObject* _NPN_BooleanVectorToArrayObject(WebCore::DOMWindow* domwindow,
const std::vector<bool>& vec) {
v8::Local<v8::Array> array = v8::Array::New();
for (uint32_t index = 0; index < vec.size(); ++index) {
array->Set(v8::Integer::New(index), v8::Boolean::New(vec[index]));
}
return npCreateV8ScriptObject(0, array, domwindow);
}
bool _NPN_ArrayObjectToStringVector(NPObject* npobject,
std::vector<std::string>& vec) {
if (npobject == NULL || npobject->_class != npScriptObjectClass)
return false;
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
if (!object->v8Object->IsArray())
return false;
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
for (uint32_t i = 0; i < array->Length(); i++) {
v8::Local<v8::Value> value = array->Get(v8::Integer::New(i));
v8::Local<v8::String> sval = value->ToString();
uint16_t* buf = new uint16_t[sval->Length()+1];
sval->Write(buf);
std::string utf8 = WideToUTF8(reinterpret_cast<wchar_t*>(buf));
vec.push_back(utf8);
delete[] buf;
}
return true;
}
bool _NPN_ArrayObjectToWStringVector(NPObject* npobject,
std::vector<std::wstring>& vec) {
if (npobject == NULL || npobject->_class != npScriptObjectClass)
return false;
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
if (!object->v8Object->IsArray())
return false;
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
for (uint32_t i = 0; i < array->Length(); i++) {
v8::Local<v8::Value> value = array->Get(v8::Integer::New(i));
v8::Local<v8::String> sval = value->ToString();
uint16_t* buf = new uint16_t[sval->Length()+1];
sval->Write(buf);
std::wstring utf16 = reinterpret_cast<wchar_t*>(buf);
vec.push_back(utf16);
delete[] buf;
}
return true;
}
bool _NPN_ArrayObjectToIntVector(NPObject* npobject,
std::vector<int>& vec) {
if (npobject == NULL || npobject->_class != npScriptObjectClass)
return false;
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
if (!object->v8Object->IsArray())
return false;
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
for (uint32_t i = 0; i < array->Length(); i++) {
v8::Local<v8::Value> value = array->Get(v8::Integer::New(i));
v8::Local<v8::Int32> ival = value->ToInt32();
vec.push_back(ival->Value());
}
return true;
}
bool _NPN_ArrayObjectToDoubleVector(NPObject* npobject,
std::vector<double>& vec) {
if (npobject == NULL || npobject->_class != npScriptObjectClass)
return false;
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
if (!object->v8Object->IsArray())
return false;
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
for (uint32_t i = 0; i < array->Length(); i++) {
v8::Local<v8::Value> value = array->Get(v8::Integer::New(i));
v8::Local<v8::Number> dval = value->ToNumber();
vec.push_back(dval->Value());
}
return true;
}
bool _NPN_ArrayObjectToBooleanVector(NPObject* npobject,
std::vector<bool>& vec) {
if (npobject == NULL || npobject->_class != npScriptObjectClass)
return false;
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
if (!object->v8Object->IsArray())
return false;
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
for (uint32_t i = 0; i < array->Length(); i++) {
v8::Local<v8::Value> value = array->Get(v8::Integer::New(i));
v8::Local<v8::Boolean> bval = value->ToBoolean();
vec.push_back(bval->Value());
}
return true;
}
int _NPN_ArrayObjectGetVectorSize(NPObject* npobject)
{
if (npobject == NULL || npobject->_class != npScriptObjectClass)
return -1;
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
if (!object->v8Object->IsArray())
return -1;
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
return array->Length();
}
bool _NPN_ArrayObjectToVectorTypeHint(NPObject* npobject,
NPVariantType &typehint)
{
if (npobject == NULL || npobject->_class != npScriptObjectClass)
return false;
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
if (!object->v8Object->IsArray())
return false;
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
if (array->Length() == 0)
return false;
typehint = NPVariantType_Null;
for (uint32_t i = 0; i < array->Length(); i++) {
v8::Local<v8::Value> value = array->Get(v8::Integer::New(i));
if (value->IsBoolean() && typehint <= NPVariantType_Bool) {
if (typehint != NPVariantType_Bool)
typehint = NPVariantType_Bool;
} else if (value->IsInt32() && typehint <= NPVariantType_Int32) {
if (typehint != NPVariantType_Int32)
typehint = NPVariantType_Int32;
} else if (value->IsNumber() && typehint <= NPVariantType_Double) {
if (typehint != NPVariantType_Double)
typehint = NPVariantType_Double;
} else {
typehint = NPVariantType_String;
// String is the least restrictive type, so we don't need to keep looking
break;
}
}
return true;
}

View File

@ -1,69 +0,0 @@
// Copyright (c) 2008 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 _VARIANT_NP_UTIL_H
#define _VARIANT_NP_UTIL_H
#include "third_party/npapi/bindings/npruntime.h"
#include <string>
#include <vector>
#ifdef __cplusplus
extern "C" {
#endif
namespace WebCore {
class DOMWindow;
}
// Convert a vector of values to an NPObject, attached to the specified
// DOM Window, that represents a JavaScript Array of the same values.
NPObject* _NPN_StringVectorToArrayObject(WebCore::DOMWindow* domwindow,
const std::vector<std::string>& vec);
NPObject* _NPN_WStringVectorToArrayObject(WebCore::DOMWindow* domwindow,
const std::vector<std::wstring>& vec);
NPObject* _NPN_IntVectorToArrayObject(WebCore::DOMWindow* domwindow,
const std::vector<int>& vec);
NPObject* _NPN_DoubleVectorToArrayObject(WebCore::DOMWindow* domwindow,
const std::vector<double>& vec);
NPObject* _NPN_BooleanVectorToArrayObject(WebCore::DOMWindow* domwindow,
const std::vector<bool>& vec);
// Convert an NPObject that represents a JavaScript Array to a vector of
// values.
bool _NPN_ArrayObjectToStringVector(NPObject* npobject,
std::vector<std::string>& vec);
bool _NPN_ArrayObjectToWStringVector(NPObject* npobject,
std::vector<std::wstring>& vec);
bool _NPN_ArrayObjectToIntVector(NPObject* npobject,
std::vector<int>& vec);
bool _NPN_ArrayObjectToDoubleVector(NPObject* npobject,
std::vector<double>& vec);
bool _NPN_ArrayObjectToBooleanVector(NPObject* npobject,
std::vector<bool>& vec);
// Return the number of elements in a JavaScript Array. Returns -1 if the
// JavaScript object does not represent an array.
int _NPN_ArrayObjectGetVectorSize(NPObject* npobject);
// Evaluate the types of values contained in an NPObject representing a
// JavaScript Array and suggest the most restrictive type that can safely store
// all of the Array values. For instance, if the Array contains all Int32
// values, the suggested type will be NPVariantType_Int32. If, on the other
// hand, the Array contains a mix of Int32 values and String values, then the
// suggested type will be NPVariantType_String. The supported values, from
// most restrictive to least restrictive, are NPVariantType_Bool,
// NPVariantType_Int32, NPVariantType_Double and NPVariantType_String. Arrays
// that contain values of type NPVariantType_Void, NPVariantType_Null or
// NPVariantType_Object will always result in a suggestion of type
// NPVariantType_String.
bool _NPN_ArrayObjectToVectorTypeHint(NPObject* npobject,
NPVariantType &typehint);
#ifdef __cplusplus
} /* end extern "C" */
#endif
#endif // _VARIANT_NP_UTIL_H

View File

@ -1,4 +1,5 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2008-2009 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.
@ -196,8 +197,6 @@ WebWidgetHost::~WebWidgetHost() {
win_util::SetWindowUserData(view_, 0);
TrackMouseLeave(false);
webwidget_->Close();
}
bool WebWidgetHost::WndProc(UINT message, WPARAM wparam, LPARAM lparam) {

View File

@ -4,10 +4,8 @@
#include "../precompiled_libcef.h"
#include "cpptoc/browser_cpptoc.h"
#include "cpptoc/request_cpptoc.h"
#include "cpptoc/stream_cpptoc.h"
#include "cpptoc/frame_cpptoc.h"
#include "ctocpp/handler_ctocpp.h"
#include "ctocpp/jshandler_ctocpp.h"
int CEF_CALLBACK browser_can_go_back(cef_browser_t* browser)
@ -16,9 +14,7 @@ int CEF_CALLBACK browser_can_go_back(cef_browser_t* browser)
if(!browser)
return 0;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
return impl->class_->GetClass()->CanGoBack();
return CefBrowserCppToC::Get(browser)->CanGoBack();
}
void CEF_CALLBACK browser_go_back(cef_browser_t* browser)
@ -27,9 +23,7 @@ void CEF_CALLBACK browser_go_back(cef_browser_t* browser)
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->GoBack();
CefBrowserCppToC::Get(browser)->GoBack();
}
int CEF_CALLBACK browser_can_go_forward(cef_browser_t* browser)
@ -38,9 +32,7 @@ int CEF_CALLBACK browser_can_go_forward(cef_browser_t* browser)
if(!browser)
return 0;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
return impl->class_->GetClass()->CanGoForward();
return CefBrowserCppToC::Get(browser)->CanGoForward();
}
void CEF_CALLBACK browser_go_forward(cef_browser_t* browser)
@ -49,9 +41,7 @@ void CEF_CALLBACK browser_go_forward(cef_browser_t* browser)
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->GoForward();
CefBrowserCppToC::Get(browser)->GoForward();
}
void CEF_CALLBACK browser_reload(cef_browser_t* browser)
@ -60,9 +50,7 @@ void CEF_CALLBACK browser_reload(cef_browser_t* browser)
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->Reload();
CefBrowserCppToC::Get(browser)->Reload();
}
void CEF_CALLBACK browser_stop_load(cef_browser_t* browser)
@ -71,93 +59,7 @@ void CEF_CALLBACK browser_stop_load(cef_browser_t* browser)
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->StopLoad();
}
void CEF_CALLBACK browser_undo(cef_browser_t* browser,
enum cef_targetframe_t targetFrame)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->Undo(targetFrame);
}
void CEF_CALLBACK browser_redo(cef_browser_t* browser,
enum cef_targetframe_t targetFrame)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->Redo(targetFrame);
}
void CEF_CALLBACK browser_cut(cef_browser_t* browser,
enum cef_targetframe_t targetFrame)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->Cut(targetFrame);
}
void CEF_CALLBACK browser_copy(cef_browser_t* browser,
enum cef_targetframe_t targetFrame)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->Copy(targetFrame);
}
void CEF_CALLBACK browser_paste(cef_browser_t* browser,
enum cef_targetframe_t targetFrame)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->Paste(targetFrame);
}
void CEF_CALLBACK browser_delete(cef_browser_t* browser,
enum cef_targetframe_t targetFrame)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->Delete(targetFrame);
}
void CEF_CALLBACK browser_select_all(cef_browser_t* browser,
enum cef_targetframe_t targetFrame)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->SelectAll(targetFrame);
CefBrowserCppToC::Get(browser)->StopLoad();
}
void CEF_CALLBACK browser_set_focus(struct _cef_browser_t* browser, int enable)
@ -166,254 +68,7 @@ void CEF_CALLBACK browser_set_focus(struct _cef_browser_t* browser, int enable)
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->SetFocus(enable ? true : false);
}
void CEF_CALLBACK browser_print(cef_browser_t* browser,
enum cef_targetframe_t targetFrame)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->Print(targetFrame);
}
void CEF_CALLBACK browser_view_source(cef_browser_t* browser,
enum cef_targetframe_t targetFrame)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->ViewSource(targetFrame);
}
cef_string_t CEF_CALLBACK browser_get_source(cef_browser_t* browser,
enum cef_targetframe_t targetFrame)
{
DCHECK(browser);
if(!browser)
return NULL;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
std::wstring sourceStr = impl->class_->GetClass()->GetSource(targetFrame);
if(sourceStr.empty())
return NULL;
return cef_string_alloc(sourceStr.c_str());
}
cef_string_t CEF_CALLBACK browser_get_text(cef_browser_t* browser,
enum cef_targetframe_t targetFrame)
{
DCHECK(browser);
if(!browser)
return NULL;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
std::wstring textStr = impl->class_->GetClass()->GetText(targetFrame);
if(textStr.empty())
return NULL;
return cef_string_alloc(textStr.c_str());
}
void CEF_CALLBACK browser_load_request(cef_browser_t* browser,
cef_request_t* request)
{
DCHECK(browser);
DCHECK(request);
if(!browser || !request)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
CefRequestCppToC::Struct* structPtr =
reinterpret_cast<CefRequestCppToC::Struct*>(request);
CefRefPtr<CefRequest> requestPtr(structPtr->class_->GetClass());
structPtr->class_->Release();
impl->class_->GetClass()->LoadRequest(requestPtr);
}
void CEF_CALLBACK browser_load_url(cef_browser_t* browser, const wchar_t* url,
const wchar_t* frame)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
std::wstring urlStr, frameStr;
if(url)
urlStr = url;
if(frame)
frameStr = frame;
impl->class_->GetClass()->LoadURL(urlStr, frameStr);
}
void CEF_CALLBACK browser_load_string(cef_browser_t* browser,
const wchar_t* string,
const wchar_t* url)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
std::wstring stringStr, urlStr;
if(string)
stringStr = string;
if(url)
urlStr = url;
impl->class_->GetClass()->LoadString(stringStr, urlStr);
}
void CEF_CALLBACK browser_load_stream(cef_browser_t* browser,
cef_stream_reader_t* stream,
const wchar_t* url)
{
DCHECK(browser);
DCHECK(stream);
if(!browser || !stream)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
CefStreamReaderCppToC::Struct* structPtr =
reinterpret_cast<CefStreamReaderCppToC::Struct*>(stream);
CefRefPtr<CefStreamReader> streamPtr(structPtr->class_->GetClass());
structPtr->class_->Release();
std::wstring urlStr;
if(url)
urlStr = url;
impl->class_->GetClass()->LoadStream(streamPtr, urlStr);
}
void CEF_CALLBACK browser_execute_javascript(cef_browser_t* browser,
const wchar_t* jsCode,
const wchar_t* scriptUrl,
int startLine,
enum cef_targetframe_t targetFrame)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
std::wstring jsCodeStr, scriptUrlStr;
if(jsCode)
jsCodeStr = jsCode;
if(scriptUrl)
scriptUrlStr = scriptUrl;
impl->class_->GetClass()->ExecuteJavaScript(jsCodeStr, scriptUrlStr,
startLine, targetFrame);
}
int CEF_CALLBACK browser_add_jshandler(cef_browser_t* browser,
const wchar_t* classname,
cef_jshandler_t* handler)
{
DCHECK(browser);
DCHECK(handler);
if(!browser || !handler)
return 0;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
CefJSHandlerCToCpp* hp = new CefJSHandlerCToCpp(handler);
CefRefPtr<CefJSHandler> handlerPtr(hp);
hp->UnderlyingRelease();
std::wstring classnameStr;
if(classname)
classnameStr = classname;
return impl->class_->GetClass()->AddJSHandler(classnameStr, handlerPtr);
}
int CEF_CALLBACK browser_has_jshandler(cef_browser_t* browser,
const wchar_t* classname)
{
DCHECK(browser);
if(!browser)
return 0;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
std::wstring classnameStr;
if(classname)
classnameStr = classname;
return impl->class_->GetClass()->HasJSHandler(classnameStr);
}
cef_jshandler_t* CEF_CALLBACK browser_get_jshandler(cef_browser_t* browser,
const wchar_t* classname)
{
DCHECK(browser);
if(!browser)
return NULL;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
std::wstring classnameStr;
if(classname)
classnameStr = classname;
CefRefPtr<CefJSHandler> handler =
impl->class_->GetClass()->GetJSHandler(classnameStr);
if(handler.get()) {
CefJSHandlerCToCpp* hp = static_cast<CefJSHandlerCToCpp*>(handler.get());
hp->UnderlyingAddRef();
return hp->GetStruct();
}
return NULL;
}
int CEF_CALLBACK browser_remove_jshandler(cef_browser_t* browser,
const wchar_t* classname)
{
DCHECK(browser);
if(!browser)
return 0;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
std::wstring classnameStr;
if(classname)
classnameStr = classname;
return impl->class_->GetClass()->RemoveJSHandler(classnameStr);
}
void CEF_CALLBACK browser_remove_all_jshandlers(cef_browser_t* browser)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
return impl->class_->GetClass()->RemoveAllJSHandlers();
CefBrowserCppToC::Get(browser)->SetFocus(enable ? true : false);
}
cef_window_handle_t CEF_CALLBACK browser_get_window_handle(cef_browser_t* browser)
@ -422,9 +77,7 @@ cef_window_handle_t CEF_CALLBACK browser_get_window_handle(cef_browser_t* browse
if(!browser)
return NULL;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
return impl->class_->GetClass()->GetWindowHandle();
return CefBrowserCppToC::Get(browser)->GetWindowHandle();
}
int CEF_CALLBACK browser_is_popup(cef_browser_t* browser)
@ -433,9 +86,7 @@ int CEF_CALLBACK browser_is_popup(cef_browser_t* browser)
if(!browser)
return 0;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
return impl->class_->GetClass()->IsPopup();
return CefBrowserCppToC::Get(browser)->IsPopup();
}
cef_handler_t* CEF_CALLBACK browser_get_handler(cef_browser_t* browser)
@ -444,35 +95,81 @@ cef_handler_t* CEF_CALLBACK browser_get_handler(cef_browser_t* browser)
if(!browser)
return NULL;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
CefRefPtr<CefHandler> handler = impl->class_->GetClass()->GetHandler();
if(handler.get()) {
CefHandlerCToCpp* hp = static_cast<CefHandlerCToCpp*>(handler.get());
hp->UnderlyingAddRef();
return hp->GetStruct();
}
return NULL;
}
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
CefRefPtr<CefHandler> handlerPtr = browserPtr->GetHandler();
if(handlerPtr.get())
return CefHandlerCToCpp::Unwrap(handlerPtr);
cef_string_t CEF_CALLBACK browser_get_url(cef_browser_t* browser)
{
return NULL;
}
struct _cef_frame_t* CEF_CALLBACK browser_get_main_frame(
struct _cef_browser_t* browser)
{
DCHECK(browser);
if(!browser)
return NULL;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
std::wstring urlStr = impl->class_->GetClass()->GetURL();
if(urlStr.empty())
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
CefRefPtr<CefFrame> framePtr = browserPtr->GetMainFrame();
if(framePtr.get())
return CefFrameCppToC::Wrap(framePtr);
return NULL;
}
struct _cef_frame_t* CEF_CALLBACK browser_get_focused_frame(
struct _cef_browser_t* browser)
{
DCHECK(browser);
if(!browser)
return NULL;
return cef_string_alloc(urlStr.c_str());
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
CefRefPtr<CefFrame> framePtr = browserPtr->GetFocusedFrame();
if(framePtr.get())
return CefFrameCppToC::Wrap(framePtr);
return NULL;
}
struct _cef_frame_t* CEF_CALLBACK browser_get_frame(
struct _cef_browser_t* browser, const wchar_t* name)
{
DCHECK(browser);
if(!browser)
return NULL;
std::wstring nameStr;
if(name)
nameStr = name;
if(nameStr.empty())
return NULL;
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
CefRefPtr<CefFrame> framePtr = browserPtr->GetFrame(nameStr);
if(framePtr.get())
return CefFrameCppToC::Wrap(framePtr);
return NULL;
}
size_t CEF_CALLBACK browser_get_frame_names(struct _cef_browser_t* browser,
cef_string_list_t list)
{
DCHECK(browser);
DCHECK(list);
if(!browser || !list)
return NULL;
CefRefPtr<CefBrowser> browserPtr = CefBrowserCppToC::Get(browser);
std::vector<std::wstring> stringList;
browserPtr->GetFrameNames(stringList);
size_t size = stringList.size();
for(size_t i = 0; i < size; ++i)
cef_string_list_append(list, stringList[i].c_str());
return size;
}
CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls)
: CefCppToC<CefBrowser, cef_browser_t>(cls)
: CefCppToC<CefBrowserCppToC, CefBrowser, cef_browser_t>(cls)
{
struct_.struct_.can_go_back = browser_can_go_back;
struct_.struct_.go_back = browser_go_back;
@ -480,34 +177,16 @@ CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls)
struct_.struct_.go_forward = browser_go_forward;
struct_.struct_.reload = browser_reload;
struct_.struct_.stop_load = browser_stop_load;
struct_.struct_.undo = browser_undo;
struct_.struct_.redo = browser_redo;
struct_.struct_.cut = browser_cut;
struct_.struct_.copy = browser_copy;
struct_.struct_.paste = browser_paste;
struct_.struct_.del = browser_delete;
struct_.struct_.select_all = browser_select_all;
struct_.struct_.set_focus = browser_set_focus;
struct_.struct_.print = browser_print;
struct_.struct_.view_source = browser_view_source;
struct_.struct_.get_source = browser_get_source;
struct_.struct_.get_text = browser_get_text;
struct_.struct_.load_request = browser_load_request;
struct_.struct_.load_url = browser_load_url;
struct_.struct_.load_string = browser_load_string;
struct_.struct_.load_stream = browser_load_stream;
struct_.struct_.execute_javascript = browser_execute_javascript;
struct_.struct_.add_jshandler = browser_add_jshandler;
struct_.struct_.has_jshandler = browser_has_jshandler;
struct_.struct_.get_jshandler = browser_get_jshandler;
struct_.struct_.remove_jshandler = browser_remove_jshandler;
struct_.struct_.remove_all_jshandlers = browser_remove_all_jshandlers;
struct_.struct_.get_window_handle = browser_get_window_handle;
struct_.struct_.is_popup = browser_is_popup;
struct_.struct_.get_handler = browser_get_handler;
struct_.struct_.get_url = browser_get_url;
struct_.struct_.get_handler = browser_get_handler;
struct_.struct_.get_main_frame = browser_get_main_frame;
struct_.struct_.get_focused_frame = browser_get_focused_frame;
struct_.struct_.get_frame = browser_get_frame;
struct_.struct_.get_frame_names = browser_get_frame_names;
}
#ifdef _DEBUG
long CefCppToC<CefBrowser, cef_browser_t>::DebugObjCt = 0;
long CefCppToC<CefBrowserCppToC, CefBrowser, cef_browser_t>::DebugObjCt = 0;
#endif

View File

@ -16,7 +16,8 @@
// Wrap a C++ browser class with a C browser structure.
// This class may be instantiated and accessed DLL-side only.
class CefBrowserCppToC : public CefCppToC<CefBrowser, cef_browser_t>
class CefBrowserCppToC
: public CefCppToC<CefBrowserCppToC, CefBrowser, cef_browser_t>
{
public:
CefBrowserCppToC(CefBrowser* cls);

View File

@ -10,19 +10,63 @@
#include "../cef_logging.h"
// Wrap a C++ class with a C structure.
template <class ClassName, class StructName>
// Wrap a C++ class with a C structure. This is used when the class
// implementation exists on this side of the DLL boundary but will have methods
// called from the other side of the DLL boundary.
template <class ClassName, class BaseName, class StructName>
class CefCppToC : public CefThreadSafeBase<CefBase>
{
public:
// Use this method to retrieve the underlying class instance from our
// own structure when the structure is passed as the required first
// parameter of a C API function call. No explicit reference counting
// is done in this case.
static CefRefPtr<BaseName> Get(StructName* s)
{
// Cast our structure to the wrapper structure type.
ClassName::Struct* wrapperStruct =
reinterpret_cast<ClassName::Struct*>(s);
// Return the underlying object instance.
return wrapperStruct->class_->GetClass();
}
// Use this method to create a wrapper structure for passing our class
// instance to the other side.
static StructName* Wrap(CefRefPtr<BaseName> c)
{
// Wrap our object with the CefCppToC class.
ClassName* wrapper = new ClassName(c);
// Add a reference to our wrapper object that will be released once our
// structure arrives on the other side.
wrapper->AddRef();
// Return the structure pointer that can now be passed to the other side.
return wrapper->GetStruct();
}
// Use this method to retrieve the underlying class instance when receiving
// our wrapper structure back from the other side.
static CefRefPtr<BaseName> Unwrap(StructName* s)
{
// Cast our structure to the wrapper structure type.
ClassName::Struct* wrapperStruct =
reinterpret_cast<ClassName::Struct*>(s);
// Add the underlying object instance to a smart pointer.
CefRefPtr<BaseName> objectPtr(wrapperStruct->class_->GetClass());
// Release the reference to our wrapper object that was added before the
// structure was passed back to us.
wrapperStruct->class_->Release();
// Return the underlying object instance.
return objectPtr;
}
// Structure representation with pointer to the C++ class.
struct Struct
{
StructName struct_;
CefCppToC<ClassName, StructName>* class_;
CefCppToC<ClassName,BaseName,StructName>* class_;
};
CefCppToC(ClassName* cls)
CefCppToC(BaseName* cls)
: class_(cls)
{
DCHECK(cls);
@ -47,7 +91,7 @@ public:
#endif
}
ClassName* GetClass() { return class_; }
BaseName* GetClass() { return class_; }
// If returning the structure across the DLL boundary you should call
// AddRef() on this CefCppToC object. On the other side of the DLL boundary,
@ -110,7 +154,137 @@ private:
protected:
Struct struct_;
ClassName* class_;
BaseName* class_;
};
// CefCppToC implementation for CefBase.
class CefBaseCppToC : public CefThreadSafeBase<CefBase>
{
public:
// Use this method to retrieve the underlying class instance from our
// own structure when the structure is passed as the required first
// parameter of a C API function call. No explicit reference counting
// is done in this case.
static CefRefPtr<CefBase> Get(cef_base_t* s)
{
// Cast our structure to the wrapper structure type.
CefBaseCppToC::Struct* wrapperStruct =
reinterpret_cast<CefBaseCppToC::Struct*>(s);
// Return the underlying object instance.
return wrapperStruct->class_->GetClass();
}
// Use this method to create a wrapper structure for passing our class
// instance to the other side.
static cef_base_t* Wrap(CefRefPtr<CefBase> c)
{
// Wrap our object with the CefCppToC class.
CefBaseCppToC* wrapper = new CefBaseCppToC(c);
// Add a reference to our wrapper object that will be released once our
// structure arrives on the other side.
wrapper->AddRef();
// Return the structure pointer that can now be passed to the other side.
return wrapper->GetStruct();
}
// Use this method to retrieve the underlying class instance when receiving
// our wrapper structure back from the other side.
static CefRefPtr<CefBase> Unwrap(cef_base_t* s)
{
// Cast our structure to the wrapper structure type.
CefBaseCppToC::Struct* wrapperStruct =
reinterpret_cast<CefBaseCppToC::Struct*>(s);
// Add the underlying object instance to a smart pointer.
CefRefPtr<CefBase> objectPtr(wrapperStruct->class_->GetClass());
// Release the reference to our wrapper object that was added before the
// structure was passed back to us.
wrapperStruct->class_->Release();
// Return the underlying object instance.
return objectPtr;
}
// Structure representation with pointer to the C++ class.
struct Struct
{
cef_base_t struct_;
CefBaseCppToC* class_;
};
CefBaseCppToC(CefBase* cls)
: class_(cls)
{
DCHECK(cls);
struct_.class_ = this;
// zero the underlying structure and set base members
memset(&struct_.struct_, 0, sizeof(cef_base_t));
struct_.struct_.size = sizeof(cef_base_t);
struct_.struct_.add_ref = struct_add_ref;
struct_.struct_.release = struct_release;
struct_.struct_.get_refct = struct_get_refct;
}
virtual ~CefBaseCppToC() {}
CefBase* GetClass() { return class_; }
// If returning the structure across the DLL boundary you should call
// AddRef() on this CefCppToC object. On the other side of the DLL boundary,
// call UnderlyingRelease() on the wrapping CefCToCpp object.
cef_base_t* GetStruct() { return &struct_.struct_; }
// CefBase methods increment/decrement reference counts on both this object
// and the underlying wrapper class.
virtual int AddRef()
{
UnderlyingAddRef();
return CefThreadSafeBase<CefBase>::AddRef();
}
virtual int Release()
{
UnderlyingRelease();
return CefThreadSafeBase<CefBase>::Release();
}
// Increment/decrement reference counts on only the underlying class.
int UnderlyingAddRef() { return class_->AddRef(); }
int UnderlyingRelease() { return class_->Release(); }
int UnderlyingGetRefCt() { return class_->GetRefCt(); }
private:
static int CEF_CALLBACK struct_add_ref(struct _cef_base_t* base)
{
DCHECK(base);
if(!base)
return 0;
Struct* impl = reinterpret_cast<Struct*>(base);
return impl->class_->AddRef();
}
static int CEF_CALLBACK struct_release(struct _cef_base_t* base)
{
DCHECK(base);
if(!base)
return 0;
Struct* impl = reinterpret_cast<Struct*>(base);
return impl->class_->Release();
}
static int CEF_CALLBACK struct_get_refct(struct _cef_base_t* base)
{
DCHECK(base);
if(!base)
return 0;
Struct* impl = reinterpret_cast<Struct*>(base);
return impl->class_->GetRefCt();
}
protected:
Struct struct_;
CefBase* class_;
};
#endif // _CPPTOC_H

View File

@ -0,0 +1,262 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "../precompiled_libcef.h"
#include "cpptoc/frame_cpptoc.h"
#include "cpptoc/request_cpptoc.h"
#include "cpptoc/stream_cpptoc.h"
void CEF_CALLBACK frame_undo(cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return;
CefFrameCppToC::Get(frame)->Undo();
}
void CEF_CALLBACK frame_redo(cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return;
CefFrameCppToC::Get(frame)->Redo();
}
void CEF_CALLBACK frame_cut(cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return;
CefFrameCppToC::Get(frame)->Cut();
}
void CEF_CALLBACK frame_copy(cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return;
CefFrameCppToC::Get(frame)->Copy();
}
void CEF_CALLBACK frame_paste(cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return;
CefFrameCppToC::Get(frame)->Paste();
}
void CEF_CALLBACK frame_delete(cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return;
CefFrameCppToC::Get(frame)->Delete();
}
void CEF_CALLBACK frame_select_all(cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return;
CefFrameCppToC::Get(frame)->SelectAll();
}
void CEF_CALLBACK frame_print(cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return;
CefFrameCppToC::Get(frame)->Print();
}
void CEF_CALLBACK frame_view_source(cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return;
CefFrameCppToC::Get(frame)->ViewSource();
}
cef_string_t CEF_CALLBACK frame_get_source(cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return NULL;
std::wstring sourceStr = CefFrameCppToC::Get(frame)->GetSource();
if(!sourceStr.empty())
return cef_string_alloc(sourceStr.c_str());
return NULL;
}
cef_string_t CEF_CALLBACK frame_get_text(cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return NULL;
std::wstring textStr = CefFrameCppToC::Get(frame)->GetText();
if(!textStr.empty())
return cef_string_alloc(textStr.c_str());
return NULL;
}
void CEF_CALLBACK frame_load_request(cef_frame_t* frame,
cef_request_t* request)
{
DCHECK(frame);
DCHECK(request);
if(!frame || !request)
return;
CefRefPtr<CefRequest> requestPtr = CefRequestCppToC::Unwrap(request);
CefFrameCppToC::Get(frame)->LoadRequest(requestPtr);
}
void CEF_CALLBACK frame_load_url(cef_frame_t* frame, const wchar_t* url)
{
DCHECK(frame);
if(!frame)
return;
std::wstring urlStr;
if(url)
urlStr = url;
CefFrameCppToC::Get(frame)->LoadURL(urlStr);
}
void CEF_CALLBACK frame_load_string(cef_frame_t* frame,
const wchar_t* string,
const wchar_t* url)
{
DCHECK(frame);
if(!frame)
return;
std::wstring stringStr, urlStr;
if(string)
stringStr = string;
if(url)
urlStr = url;
CefFrameCppToC::Get(frame)->LoadString(stringStr, urlStr);
}
void CEF_CALLBACK frame_load_stream(cef_frame_t* frame,
cef_stream_reader_t* stream,
const wchar_t* url)
{
DCHECK(frame);
DCHECK(stream);
if(!frame || !stream)
return;
CefRefPtr<CefStreamReader> streamPtr = CefStreamReaderCppToC::Unwrap(stream);
std::wstring urlStr;
if(url)
urlStr = url;
CefFrameCppToC::Get(frame)->LoadStream(streamPtr, urlStr);
}
void CEF_CALLBACK frame_execute_javascript(cef_frame_t* frame,
const wchar_t* jsCode,
const wchar_t* scriptUrl,
int startLine)
{
DCHECK(frame);
if(!frame)
return;
std::wstring jsCodeStr, scriptUrlStr;
if(jsCode)
jsCodeStr = jsCode;
if(scriptUrl)
scriptUrlStr = scriptUrl;
CefFrameCppToC::Get(frame)->ExecuteJavaScript(jsCodeStr, scriptUrlStr,
startLine);
}
int CEF_CALLBACK frame_is_main(struct _cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return 0;
return CefFrameCppToC::Get(frame)->IsMain();
}
int CEF_CALLBACK frame_is_focused(struct _cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return 0;
return CefFrameCppToC::Get(frame)->IsFocused();
}
cef_string_t CEF_CALLBACK frame_get_name(struct _cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return 0;
std::wstring nameStr = CefFrameCppToC::Get(frame)->GetName();
if(!nameStr.empty())
return cef_string_alloc(nameStr.c_str());
return NULL;
}
cef_string_t CEF_CALLBACK frame_get_url(cef_frame_t* frame)
{
DCHECK(frame);
if(!frame)
return NULL;
std::wstring urlStr = CefFrameCppToC::Get(frame)->GetURL();
if(!urlStr.empty())
return cef_string_alloc(urlStr.c_str());
return NULL;
}
CefFrameCppToC::CefFrameCppToC(CefFrame* cls)
: CefCppToC<CefFrameCppToC, CefFrame, cef_frame_t>(cls)
{
struct_.struct_.undo = frame_undo;
struct_.struct_.redo = frame_redo;
struct_.struct_.cut = frame_cut;
struct_.struct_.copy = frame_copy;
struct_.struct_.paste = frame_paste;
struct_.struct_.del = frame_delete;
struct_.struct_.select_all = frame_select_all;
struct_.struct_.print = frame_print;
struct_.struct_.view_source = frame_view_source;
struct_.struct_.get_source = frame_get_source;
struct_.struct_.get_text = frame_get_text;
struct_.struct_.load_request = frame_load_request;
struct_.struct_.load_url = frame_load_url;
struct_.struct_.load_string = frame_load_string;
struct_.struct_.load_stream = frame_load_stream;
struct_.struct_.execute_javascript = frame_execute_javascript;
struct_.struct_.is_main = frame_is_main;
struct_.struct_.is_focused = frame_is_focused;
struct_.struct_.get_name = frame_get_name;
struct_.struct_.get_url = frame_get_url;
}
#ifdef _DEBUG
long CefCppToC<CefFrameCppToC, CefFrame, cef_frame_t>::DebugObjCt = 0;
#endif

View File

@ -2,8 +2,8 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _VARIANT_CPPTOC_H
#define _VARIANT_CPPTOC_H
#ifndef _FRAME_CPPTOC_H
#define _FRAME_CPPTOC_H
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
@ -14,15 +14,16 @@
#include "cpptoc.h"
// Wrap a C++ browser class with a C browser structure.
// Wrap a C++ frame class with a C frame structure.
// This class may be instantiated and accessed DLL-side only.
class CefVariantCppToC : public CefCppToC<CefVariant, cef_variant_t>
class CefFrameCppToC
: public CefCppToC<CefFrameCppToC, CefFrame, cef_frame_t>
{
public:
CefVariantCppToC(CefVariant* cls);
virtual ~CefVariantCppToC() {}
CefFrameCppToC(CefFrame* cls);
virtual ~CefFrameCppToC() {}
};
#endif // BUILDING_CEF_SHARED
#endif // _VARIANT_CPPTOC_H
#endif // _FRAME_CPPTOC_H

View File

@ -5,8 +5,10 @@
#include "../precompiled_libcef.h"
#include "cpptoc/handler_cpptoc.h"
#include "ctocpp/browser_ctocpp.h"
#include "ctocpp/frame_ctocpp.h"
#include "ctocpp/request_ctocpp.h"
#include "ctocpp/stream_ctocpp.h"
#include "ctocpp/v8value_ctocpp.h"
#include "transfer_util.h"
@ -22,42 +24,29 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_created(
if(!handler || !windowInfo || !newHandler || !*newHandler || !url)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefWindowInfo wndInfo(*windowInfo);
// |newHandler| will start off pointing to the current handler.
CefHandlerCppToC::Struct* structPtr
= reinterpret_cast<CefHandlerCppToC::Struct*>(*newHandler);
CefWindowInfo wndInfo(*windowInfo);
CefRefPtr<CefBrowser> browserPtr;
CefRefPtr<CefHandler> handlerPtr(structPtr->class_->GetClass());
structPtr->class_->Release();
std::wstring urlStr;
CefRefPtr<CefHandler> handlerPtr = CefHandlerCppToC::Unwrap(*newHandler);
CefHandler* origHandler = handlerPtr.get();
// |parentBrowser| will be NULL if this is a top-level browser window.
CefRefPtr<CefBrowser> browserPtr;
if(parentBrowser)
{
CefBrowserCToCpp* bp = new CefBrowserCToCpp(parentBrowser);
browserPtr = bp;
bp->UnderlyingRelease();
}
browserPtr = CefBrowserCToCpp::Wrap(parentBrowser);
std::wstring urlStr;
if(*url)
urlStr = *url;
enum cef_retval_t rv = impl->class_->GetClass()->HandleBeforeCreated(
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->HandleBeforeCreated(
browserPtr, wndInfo, popup, handlerPtr, urlStr);
transfer_string_contents(urlStr, url);
if(handlerPtr.get() != structPtr->class_->GetClass())
{
if(handlerPtr.get() != origHandler) {
// The handler has been changed.
CefHandlerCppToC* hobj = new CefHandlerCppToC(handlerPtr);
hobj->AddRef();
*newHandler = hobj->GetStruct();
*newHandler = CefHandlerCppToC::Wrap(handlerPtr);
}
// WindowInfo may or may not have changed.
@ -79,37 +68,26 @@ enum cef_retval_t CEF_CALLBACK handler_handle_after_created(
if(!handler || !browser)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
return impl->class_->GetClass()->HandleAfterCreated(browserPtr);
return CefHandlerCppToC::Get(handler)->HandleAfterCreated(
CefBrowserCToCpp::Wrap(browser));
}
enum cef_retval_t CEF_CALLBACK handler_handle_address_change(
struct _cef_handler_t* handler, cef_browser_t* browser,
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
const wchar_t* url)
{
DCHECK(handler);
DCHECK(browser);
if(!handler || !browser)
DCHECK(frame);
if(!handler || !browser || !frame)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring urlStr;
if(url)
urlStr = url;
return impl->class_->GetClass()->HandleAddressChange(browserPtr, urlStr);
return CefHandlerCppToC::Get(handler)->HandleAddressChange(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), urlStr);
}
enum cef_retval_t CEF_CALLBACK handler_handle_title_change(
@ -121,100 +99,75 @@ enum cef_retval_t CEF_CALLBACK handler_handle_title_change(
if(!handler || !browser)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring titleStr;
if(title)
titleStr = title;
return impl->class_->GetClass()->HandleTitleChange(browserPtr, titleStr);
return CefHandlerCppToC::Get(handler)->HandleTitleChange(
CefBrowserCToCpp::Wrap(browser), titleStr);
}
enum cef_retval_t CEF_CALLBACK handler_handle_before_browse(
struct _cef_handler_t* handler, cef_browser_t* browser,
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
struct _cef_request_t* request, cef_handler_navtype_t navType,
int isRedirect)
{
DCHECK(handler);
DCHECK(browser);
DCHECK(frame);
DCHECK(request);
if(!handler || !browser || !request)
if(!handler || !browser || !request || !frame)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
CefRequestCToCpp* rp = new CefRequestCToCpp(request);
CefRefPtr<CefRequest> requestPtr(rp);
rp->UnderlyingRelease();
return impl->class_->GetClass()->HandleBeforeBrowse(browserPtr, requestPtr,
navType, (isRedirect ? true : false));
return CefHandlerCppToC::Get(handler)->HandleBeforeBrowse(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request), navType, (isRedirect ? true : false));
}
enum cef_retval_t CEF_CALLBACK handler_handle_load_start(
struct _cef_handler_t* handler, cef_browser_t* browser)
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame)
{
DCHECK(handler);
DCHECK(browser);
if(!handler || !browser)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
CefRefPtr<CefFrame> framePtr;
if(frame)
framePtr = CefFrameCToCpp::Wrap(frame);
return impl->class_->GetClass()->HandleLoadStart(browserPtr);
return CefHandlerCppToC::Get(handler)->HandleLoadStart(
CefBrowserCToCpp::Wrap(browser), framePtr);
}
enum cef_retval_t CEF_CALLBACK handler_handle_load_end(
struct _cef_handler_t* handler, cef_browser_t* browser)
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame)
{
DCHECK(handler);
DCHECK(browser);
if(!handler || !browser)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
CefRefPtr<CefFrame> framePtr;
if(frame)
framePtr = CefFrameCToCpp::Wrap(frame);
return impl->class_->GetClass()->HandleLoadEnd(browserPtr);
return CefHandlerCppToC::Get(handler)->HandleLoadEnd(
CefBrowserCToCpp::Wrap(browser), framePtr);
}
enum cef_retval_t CEF_CALLBACK handler_handle_load_error(
struct _cef_handler_t* handler, cef_browser_t* browser,
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
cef_handler_errorcode_t errorCode, const wchar_t* failedUrl,
cef_string_t* errorText)
{
DCHECK(handler);
DCHECK(browser);
DCHECK(frame);
DCHECK(errorText);
if(!handler || !browser || !errorText)
if(!handler || !browser || !errorText || !frame)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring failedUrlStr, errorTextStr;
if(failedUrl)
@ -222,8 +175,9 @@ enum cef_retval_t CEF_CALLBACK handler_handle_load_error(
if(*errorText)
errorTextStr = *errorText;
enum cef_retval_t rv = impl->class_->GetClass()->HandleLoadError(browserPtr,
errorCode, failedUrlStr, errorTextStr);
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->HandleLoadError(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), errorCode,
failedUrlStr, errorTextStr);
transfer_string_contents(errorTextStr, errorText);
@ -244,17 +198,6 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_resource_load(
if(!handler || !browser || !redirectUrl || !resourceStream || !mimeType)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
CefRequestCToCpp* rp = new CefRequestCToCpp(request);
CefRefPtr<CefRequest> requestPtr(rp);
rp->UnderlyingRelease();
std::wstring redirectUrlStr, mimeTypeStr;
CefRefPtr<CefStreamReader> streamPtr;
@ -263,20 +206,16 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_resource_load(
if(*mimeType)
mimeTypeStr = *mimeType;
enum cef_retval_t rv = impl->class_->GetClass()->HandleBeforeResourceLoad(
browserPtr, requestPtr, redirectUrlStr, streamPtr, mimeTypeStr,
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->
HandleBeforeResourceLoad(CefBrowserCToCpp::Wrap(browser),
CefRequestCToCpp::Wrap(request), redirectUrlStr, streamPtr, mimeTypeStr,
loadFlags);
transfer_string_contents(redirectUrlStr, redirectUrl);
transfer_string_contents(mimeTypeStr, mimeType);
if(streamPtr.get())
{
CefStreamReaderCToCpp* sp =
static_cast<CefStreamReaderCToCpp*>(streamPtr.get());
sp->UnderlyingAddRef();
*resourceStream = sp->GetStruct();
}
*resourceStream = CefStreamReaderCToCpp::Unwrap(streamPtr);
return rv;
}
@ -291,14 +230,8 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_menu(
if(!handler || !browser || !menuInfo)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
return impl->class_->GetClass()->HandleBeforeMenu(browserPtr, *menuInfo);
return CefHandlerCppToC::Get(handler)->HandleBeforeMenu(
CefBrowserCToCpp::Wrap(browser), *menuInfo);
}
enum cef_retval_t CEF_CALLBACK handler_handle_get_menu_label(
@ -311,19 +244,12 @@ enum cef_retval_t CEF_CALLBACK handler_handle_get_menu_label(
if(!handler || !browser || !label)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring labelStr;
if(*label)
labelStr = *label;
enum cef_retval_t rv = impl->class_->GetClass()->HandleGetMenuLabel(
browserPtr, menuId, labelStr);
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->HandleGetMenuLabel(
CefBrowserCToCpp::Wrap(browser), menuId, labelStr);
transfer_string_contents(labelStr, label);
@ -339,18 +265,12 @@ enum cef_retval_t CEF_CALLBACK handler_handle_menu_action(
if(!handler || !browser)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
return impl->class_->GetClass()->HandleMenuAction(browserPtr, menuId);
return CefHandlerCppToC::Get(handler)->HandleMenuAction(
CefBrowserCToCpp::Wrap(browser), menuId);
}
enum cef_retval_t CEF_CALLBACK handler_handle_print_header_footer(
struct _cef_handler_t* handler, cef_browser_t* browser,
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
cef_print_info_t* printInfo, const wchar_t* url, const wchar_t* title,
int currentPage, int maxPages, cef_string_t* topLeft,
cef_string_t* topCenter, cef_string_t* topRight,
@ -359,20 +279,14 @@ enum cef_retval_t CEF_CALLBACK handler_handle_print_header_footer(
{
DCHECK(handler);
DCHECK(browser);
DCHECK(frame);
DCHECK(printInfo);
DCHECK(topLeft && topCenter && topRight);
DCHECK(bottomLeft && bottomCenter && bottomRight);
if(!handler || !browser || !printInfo || !topLeft || !topCenter || !topRight
|| !bottomLeft || !bottomCenter || !bottomRight)
if(!handler || !browser || !frame || !printInfo || !topLeft || !topCenter
|| !topRight || !bottomLeft || !bottomCenter || !bottomRight)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring urlStr, titleStr;
std::wstring topLeftStr, topCenterStr, topRightStr;
std::wstring bottomLeftStr, bottomCenterStr, bottomRightStr;
@ -395,10 +309,11 @@ enum cef_retval_t CEF_CALLBACK handler_handle_print_header_footer(
if(*bottomRight)
bottomRightStr = *bottomRight;
enum cef_retval_t rv = impl->class_->GetClass()->
HandlePrintHeaderFooter(browserPtr, info, urlStr, titleStr,
currentPage, maxPages, topLeftStr, topCenterStr, topRightStr,
bottomLeftStr, bottomCenterStr, bottomRightStr);
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->
HandlePrintHeaderFooter(CefBrowserCToCpp::Wrap(browser),
CefFrameCToCpp::Wrap(frame), info, urlStr, titleStr, currentPage,
maxPages, topLeftStr, topCenterStr, topRightStr, bottomLeftStr,
bottomCenterStr, bottomRightStr);
transfer_string_contents(topLeftStr, topLeft);
transfer_string_contents(topCenterStr, topCenter);
@ -411,76 +326,60 @@ enum cef_retval_t CEF_CALLBACK handler_handle_print_header_footer(
}
enum cef_retval_t CEF_CALLBACK handler_handle_jsalert(
struct _cef_handler_t* handler, cef_browser_t* browser,
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
const wchar_t* message)
{
DCHECK(handler);
DCHECK(browser);
if(!handler || !browser)
DCHECK(frame);
if(!handler || !browser || !frame)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring messageStr;
if(message)
messageStr = message;
return impl->class_->GetClass()->HandleJSAlert(browserPtr, messageStr);
return CefHandlerCppToC::Get(handler)->HandleJSAlert(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), messageStr);
}
enum cef_retval_t CEF_CALLBACK handler_handle_jsconfirm(
struct _cef_handler_t* handler, cef_browser_t* browser,
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
const wchar_t* message, int* retval)
{
DCHECK(handler);
DCHECK(browser);
DCHECK(frame);
DCHECK(retval);
if(!handler || !browser || !retval)
if(!handler || !browser || !retval || !frame)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring messageStr;
if(message)
messageStr = message;
bool ret = false;
enum cef_retval_t rv = impl->class_->GetClass()->HandleJSConfirm(browserPtr,
messageStr, ret);
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->HandleJSConfirm(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), messageStr,
ret);
*retval = (ret ? 1 : 0);
return rv;
}
enum cef_retval_t CEF_CALLBACK handler_handle_jsprompt(
struct _cef_handler_t* handler, cef_browser_t* browser,
struct _cef_handler_t* handler, cef_browser_t* browser, cef_frame_t* frame,
const wchar_t* message, const wchar_t* defaultValue, int* retval,
cef_string_t* result)
{
DCHECK(handler);
DCHECK(browser);
DCHECK(frame);
DCHECK(retval);
DCHECK(result);
if(!handler || !browser || !retval || !result)
if(!handler || !browser || !frame || !retval || !result)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring messageStr, defaultValueStr, resultStr;
if(message)
@ -491,8 +390,9 @@ enum cef_retval_t CEF_CALLBACK handler_handle_jsprompt(
resultStr = *result;
bool ret = false;
enum cef_retval_t rv = impl->class_->GetClass()->HandleJSPrompt(
browserPtr, messageStr, defaultValueStr, ret, resultStr);
enum cef_retval_t rv = CefHandlerCppToC::Get(handler)->HandleJSPrompt(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), messageStr,
defaultValueStr, ret, resultStr);
*retval = (ret ? 1 : 0);
transfer_string_contents(resultStr, result);
@ -508,14 +408,8 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_window_close(
if(!handler || !browser)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
return impl->class_->GetClass()->HandleBeforeWindowClose(browserPtr);
return CefHandlerCppToC::Get(handler)->HandleBeforeWindowClose(
CefBrowserCToCpp::Wrap(browser));
}
enum cef_retval_t CEF_CALLBACK handler_handle_take_focus(
@ -526,20 +420,29 @@ enum cef_retval_t CEF_CALLBACK handler_handle_take_focus(
if(!handler || !browser)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
return impl->class_->GetClass()->
HandleTakeFocus(browserPtr, (reverse ? true : false));
return CefHandlerCppToC::Get(handler)->HandleTakeFocus(
CefBrowserCToCpp::Wrap(browser), (reverse ? true : false));
}
enum cef_retval_t CEF_CALLBACK handler_handle_jsbinding(
struct _cef_handler_t* handler, cef_browser_t* browser,
cef_frame_t* frame, struct _cef_v8value_t* object)
{
DCHECK(handler);
DCHECK(browser);
DCHECK(frame);
DCHECK(object);
if(!handler || !browser || !frame || !object)
return RV_CONTINUE;
return CefHandlerCppToC::Get(handler)->HandleJSBinding(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefV8ValueCToCpp::Wrap(object));
}
CefHandlerCppToC::CefHandlerCppToC(CefHandler* cls)
: CefCppToC<CefHandler, cef_handler_t>(cls)
: CefCppToC<CefHandlerCppToC, CefHandler, cef_handler_t>(cls)
{
struct_.struct_.handle_before_created = handler_handle_before_created;
struct_.struct_.handle_after_created = handler_handle_after_created;
@ -562,8 +465,9 @@ CefHandlerCppToC::CefHandlerCppToC(CefHandler* cls)
struct_.struct_.handle_before_window_close =
handler_handle_before_window_close;
struct_.struct_.handle_take_focus = handler_handle_take_focus;
struct_.struct_.handle_jsbinding = handler_handle_jsbinding;
}
#ifdef _DEBUG
long CefCppToC<CefHandler, cef_handler_t>::DebugObjCt = 0;
long CefCppToC<CefHandlerCppToC, CefHandler, cef_handler_t>::DebugObjCt = 0;
#endif

View File

@ -16,7 +16,8 @@
// Wrap a C++ handler class with a C handler structure.
// This class may be instantiated and accessed wrapper-side only.
class CefHandlerCppToC : public CefCppToC<CefHandler, cef_handler_t>
class CefHandlerCppToC
: public CefCppToC<CefHandlerCppToC, CefHandler, cef_handler_t>
{
public:
CefHandlerCppToC(CefHandler* cls);

View File

@ -1,158 +0,0 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "../precompiled_libcef.h"
#include "cpptoc/jshandler_cpptoc.h"
#include "ctocpp/browser_ctocpp.h"
#include "ctocpp/variant_ctocpp.h"
bool CEF_CALLBACK jshandler_has_method(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name)
{
DCHECK(jshandler);
DCHECK(browser);
if(!jshandler || !browser)
return RV_CONTINUE;
CefJSHandlerCppToC::Struct* impl =
reinterpret_cast<CefJSHandlerCppToC::Struct*>(jshandler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring nameStr;
if(name)
nameStr = name;
return impl->class_->GetClass()->HasMethod(browserPtr, nameStr);
}
bool CEF_CALLBACK jshandler_has_property(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name)
{
DCHECK(jshandler);
DCHECK(browser);
if(!jshandler || !browser)
return RV_CONTINUE;
CefJSHandlerCppToC::Struct* impl =
reinterpret_cast<CefJSHandlerCppToC::Struct*>(jshandler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring nameStr;
if(name)
nameStr = name;
return impl->class_->GetClass()->HasProperty(browserPtr, nameStr);
}
bool CEF_CALLBACK jshandler_set_property(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name,
struct _cef_variant_t* value)
{
DCHECK(jshandler);
DCHECK(browser);
if(!jshandler || !browser)
return RV_CONTINUE;
CefJSHandlerCppToC::Struct* impl =
reinterpret_cast<CefJSHandlerCppToC::Struct*>(jshandler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring nameStr;
if(name)
nameStr = name;
CefVariantCToCpp* vp = new CefVariantCToCpp(value);
CefRefPtr<CefVariant> valuePtr(vp);
vp->UnderlyingRelease();
return impl->class_->GetClass()->SetProperty(browserPtr, nameStr, valuePtr);
}
bool CEF_CALLBACK jshandler_get_property(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name,
struct _cef_variant_t* value)
{
DCHECK(jshandler);
DCHECK(browser);
if(!jshandler || !browser)
return RV_CONTINUE;
CefJSHandlerCppToC::Struct* impl =
reinterpret_cast<CefJSHandlerCppToC::Struct*>(jshandler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring nameStr;
if(name)
nameStr = name;
CefVariantCToCpp* vp = new CefVariantCToCpp(value);
CefRefPtr<CefVariant> valuePtr(vp);
vp->UnderlyingRelease();
return impl->class_->GetClass()->GetProperty(browserPtr, nameStr, valuePtr);
}
bool CEF_CALLBACK jshandler_execute_method(struct _cef_jshandler_t* jshandler,
cef_browser_t* browser, const wchar_t* name, size_t numargs,
struct _cef_variant_t** args, struct _cef_variant_t* retval)
{
DCHECK(jshandler);
DCHECK(browser);
if(!jshandler || !browser)
return RV_CONTINUE;
CefJSHandlerCppToC::Struct* impl =
reinterpret_cast<CefJSHandlerCppToC::Struct*>(jshandler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
std::wstring nameStr;
if(name)
nameStr = name;
CefVariantCToCpp* vp = new CefVariantCToCpp(retval);
CefRefPtr<CefVariant> retvalPtr(vp);
vp->UnderlyingRelease();
CefJSHandler::VariantVector vec;
for(int i = 0; i < (int)numargs; ++i) {
vp = new CefVariantCToCpp(args[i]);
CefRefPtr<CefVariant> argPtr(vp);
vp->UnderlyingRelease();
vec.push_back(argPtr);
}
return impl->class_->GetClass()->ExecuteMethod(browserPtr, nameStr, vec,
retvalPtr);
}
CefJSHandlerCppToC::CefJSHandlerCppToC(CefJSHandler* cls)
: CefCppToC<CefJSHandler, cef_jshandler_t>(cls)
{
struct_.struct_.has_method = jshandler_has_method;
struct_.struct_.has_property = jshandler_has_property;
struct_.struct_.set_property = jshandler_set_property;
struct_.struct_.get_property = jshandler_get_property;
struct_.struct_.execute_method = jshandler_execute_method;
}
#ifdef _DEBUG
long CefCppToC<CefJSHandler, cef_jshandler_t>::DebugObjCt = 0;
#endif

View File

@ -13,13 +13,10 @@ cef_string_t CEF_CALLBACK request_get_url(struct _cef_request_t* request)
if(!request)
return NULL;
CefRequestCppToC::Struct* impl =
reinterpret_cast<CefRequestCppToC::Struct*>(request);
std::wstring urlStr = impl->class_->GetClass()->GetURL();
if(urlStr.empty())
return NULL;
return cef_string_alloc(urlStr.c_str());
std::wstring urlStr = CefRequestCppToC::Get(request)->GetURL();
if(!urlStr.empty())
return cef_string_alloc(urlStr.c_str());
return NULL;
}
void CEF_CALLBACK request_set_url(struct _cef_request_t* request,
@ -29,44 +26,10 @@ void CEF_CALLBACK request_set_url(struct _cef_request_t* request,
if(!request)
return;
CefRequestCppToC::Struct* impl =
reinterpret_cast<CefRequestCppToC::Struct*>(request);
std::wstring urlStr;
if(url)
urlStr = url;
impl->class_->GetClass()->SetURL(urlStr);
}
cef_string_t CEF_CALLBACK request_get_frame(struct _cef_request_t* request)
{
DCHECK(request);
if(!request)
return NULL;
CefRequestCppToC::Struct* impl =
reinterpret_cast<CefRequestCppToC::Struct*>(request);
std::wstring frameStr = impl->class_->GetClass()->GetFrame();
if(frameStr.empty())
return NULL;
return cef_string_alloc(frameStr.c_str());
}
void CEF_CALLBACK request_set_frame(struct _cef_request_t* request,
const wchar_t* frame)
{
DCHECK(request);
if(!request)
return;
CefRequestCppToC::Struct* impl =
reinterpret_cast<CefRequestCppToC::Struct*>(request);
std::wstring frameStr;
if(frame)
frameStr = frame;
impl->class_->GetClass()->SetFrame(frameStr);
CefRequestCppToC::Get(request)->SetURL(urlStr);
}
cef_string_t CEF_CALLBACK request_get_method(struct _cef_request_t* request)
@ -75,13 +38,10 @@ cef_string_t CEF_CALLBACK request_get_method(struct _cef_request_t* request)
if(!request)
return NULL;
CefRequestCppToC::Struct* impl =
reinterpret_cast<CefRequestCppToC::Struct*>(request);
std::wstring methodStr = impl->class_->GetClass()->GetMethod();
if(methodStr.empty())
return NULL;
return cef_string_alloc(methodStr.c_str());
std::wstring methodStr = CefRequestCppToC::Get(request)->GetMethod();
if(!methodStr.empty())
return cef_string_alloc(methodStr.c_str());
return NULL;
}
void CEF_CALLBACK request_set_method(struct _cef_request_t* request,
@ -91,13 +51,10 @@ void CEF_CALLBACK request_set_method(struct _cef_request_t* request,
if(!request)
return;
CefRequestCppToC::Struct* impl =
reinterpret_cast<CefRequestCppToC::Struct*>(request);
std::wstring methodStr;
if(method)
methodStr = method;
impl->class_->GetClass()->SetMethod(methodStr);
CefRequestCppToC::Get(request)->SetMethod(methodStr);
}
struct _cef_post_data_t* CEF_CALLBACK request_get_post_data(
@ -107,17 +64,12 @@ struct _cef_post_data_t* CEF_CALLBACK request_get_post_data(
if(!request)
return NULL;
CefRequestCppToC::Struct* impl =
reinterpret_cast<CefRequestCppToC::Struct*>(request);
CefRefPtr<CefPostData> postdata =
impl->class_->GetClass()->GetPostData();
if(!postdata.get())
CefRefPtr<CefPostData> postDataPtr =
CefRequestCppToC::Get(request)->GetPostData();
if(!postDataPtr.get())
return NULL;
CefPostDataCppToC* rp = new CefPostDataCppToC(postdata);
rp->AddRef();
return rp->GetStruct();
return CefPostDataCppToC::Wrap(postDataPtr);
}
void CEF_CALLBACK request_set_post_data(struct _cef_request_t* request,
@ -127,16 +79,11 @@ void CEF_CALLBACK request_set_post_data(struct _cef_request_t* request,
if(!request)
return;
CefRequestCppToC::Struct* impl =
reinterpret_cast<CefRequestCppToC::Struct*>(request);
CefPostDataCppToC::Struct* postStructPtr =
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
CefRefPtr<CefPostData> postDataPtr;
if(postStructPtr)
postDataPtr = postStructPtr->class_->GetClass();
if(postData)
postDataPtr = CefPostDataCppToC::Unwrap(postData);
impl->class_->GetClass()->SetPostData(postDataPtr);
CefRequestCppToC::Get(request)->SetPostData(postDataPtr);
}
void CEF_CALLBACK request_get_header_map(struct _cef_request_t* request,
@ -146,12 +93,8 @@ void CEF_CALLBACK request_get_header_map(struct _cef_request_t* request,
if(!request)
return;
CefRequestCppToC::Struct* impl =
reinterpret_cast<CefRequestCppToC::Struct*>(request);
CefRequest::HeaderMap map;
impl->class_->GetClass()->GetHeaderMap(map);
CefRequestCppToC::Get(request)->GetHeaderMap(map);
transfer_string_map_contents(map, headerMap);
}
@ -162,19 +105,15 @@ void CEF_CALLBACK request_set_header_map(struct _cef_request_t* request,
if(!request)
return;
CefRequestCppToC::Struct* impl =
reinterpret_cast<CefRequestCppToC::Struct*>(request);
CefRequest::HeaderMap map;
if(headerMap)
transfer_string_map_contents(headerMap, map);
impl->class_->GetClass()->SetHeaderMap(map);
CefRequestCppToC::Get(request)->SetHeaderMap(map);
}
void CEF_CALLBACK request_set(struct _cef_request_t* request,
const wchar_t* url, const wchar_t* frame,
const wchar_t* method,
const wchar_t* url, const wchar_t* method,
struct _cef_post_data_t* postData,
cef_string_map_t headerMap)
{
@ -182,37 +121,28 @@ void CEF_CALLBACK request_set(struct _cef_request_t* request,
if(!request)
return;
CefRequestCppToC::Struct* impl =
reinterpret_cast<CefRequestCppToC::Struct*>(request);
CefPostDataCppToC::Struct* postStructPtr =
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
std::wstring urlStr, frameStr, methodStr;
CefRefPtr<CefPostData> postPtr;
std::wstring urlStr, methodStr;
CefRefPtr<CefPostData> postDataPtr;
CefRequest::HeaderMap map;
if(url)
urlStr = url;
if(frame)
frameStr = frame;
if(method)
methodStr = method;
if(postStructPtr)
postPtr = postStructPtr->class_->GetClass();
if(postData)
postDataPtr = CefPostDataCppToC::Unwrap(postData);
if(headerMap)
transfer_string_map_contents(headerMap, map);
impl->class_->GetClass()->Set(urlStr, frameStr, methodStr, postPtr, map);
CefRequestCppToC::Get(request)->Set(urlStr, methodStr, postDataPtr, map);
}
CefRequestCppToC::CefRequestCppToC(CefRequest* cls)
: CefCppToC<CefRequest, cef_request_t>(cls)
: CefCppToC<CefRequestCppToC, CefRequest, cef_request_t>(cls)
{
struct_.struct_.get_url = request_get_url;
struct_.struct_.set_url = request_set_url;
struct_.struct_.get_frame = request_get_frame;
struct_.struct_.set_frame = request_set_frame;
struct_.struct_.get_method = request_get_method;
struct_.struct_.set_method = request_set_method;
struct_.struct_.get_post_data = request_get_post_data;
@ -223,7 +153,7 @@ CefRequestCppToC::CefRequestCppToC(CefRequest* cls)
}
#ifdef _DEBUG
long CefCppToC<CefRequest, cef_request_t>::DebugObjCt = 0;
long CefCppToC<CefRequestCppToC, CefRequest, cef_request_t>::DebugObjCt = 0;
#endif
@ -234,9 +164,7 @@ size_t CEF_CALLBACK post_data_get_element_count(
if(!postData)
return 0;
CefPostDataCppToC::Struct* impl =
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
return impl->class_->GetClass()->GetElementCount();
return CefPostDataCppToC::Get(postData)->GetElementCount();
}
struct _cef_post_data_element_t* CEF_CALLBACK post_data_get_element(
@ -246,18 +174,13 @@ struct _cef_post_data_element_t* CEF_CALLBACK post_data_get_element(
if(!postData)
return NULL;
CefPostDataCppToC::Struct* impl =
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
CefPostData::ElementVector elements;
impl->class_->GetClass()->GetElements(elements);
CefPostDataCppToC::Get(postData)->GetElements(elements);
if(index < 0 || index >= (int)elements.size())
return NULL;
CefPostDataElementCppToC* rp = new CefPostDataElementCppToC(elements[index]);
rp->AddRef();
return rp->GetStruct();
return CefPostDataElementCppToC::Wrap(elements[index]);
}
int CEF_CALLBACK post_data_remove_element(struct _cef_post_data_t* postData,
@ -268,12 +191,9 @@ int CEF_CALLBACK post_data_remove_element(struct _cef_post_data_t* postData,
if(!postData || !element)
return 0;
CefPostDataCppToC::Struct* impl =
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
CefPostDataElementCppToC::Struct* structPtr =
reinterpret_cast<CefPostDataElementCppToC::Struct*>(element);
return impl->class_->GetClass()->RemoveElement(structPtr->class_->GetClass());
CefRefPtr<CefPostDataElement> postDataElementPtr =
CefPostDataElementCppToC::Unwrap(element);
return CefPostDataCppToC::Get(postData)->RemoveElement(postDataElementPtr);
}
int CEF_CALLBACK post_data_add_element(struct _cef_post_data_t* postData,
@ -284,12 +204,9 @@ int CEF_CALLBACK post_data_add_element(struct _cef_post_data_t* postData,
if(!postData || !element)
return 0;
CefPostDataCppToC::Struct* impl =
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
CefPostDataElementCppToC::Struct* structPtr =
reinterpret_cast<CefPostDataElementCppToC::Struct*>(element);
return impl->class_->GetClass()->AddElement(structPtr->class_->GetClass());
CefRefPtr<CefPostDataElement> postDataElementPtr =
CefPostDataElementCppToC::Unwrap(element);
return CefPostDataCppToC::Get(postData)->AddElement(postDataElementPtr);
}
void CEF_CALLBACK post_data_remove_elements(struct _cef_post_data_t* postData)
@ -298,15 +215,12 @@ void CEF_CALLBACK post_data_remove_elements(struct _cef_post_data_t* postData)
if(!postData)
return;
CefPostDataCppToC::Struct* impl =
reinterpret_cast<CefPostDataCppToC::Struct*>(postData);
impl->class_->GetClass()->RemoveElements();
CefPostDataCppToC::Get(postData)->RemoveElements();
}
CefPostDataCppToC::CefPostDataCppToC(CefPostData* cls)
: CefCppToC<CefPostData, cef_post_data_t>(cls)
: CefCppToC<CefPostDataCppToC, CefPostData, cef_post_data_t>(cls)
{
struct_.struct_.get_element_count = post_data_get_element_count;
struct_.struct_.get_element = post_data_get_element;
@ -316,7 +230,8 @@ CefPostDataCppToC::CefPostDataCppToC(CefPostData* cls)
}
#ifdef _DEBUG
long CefCppToC<CefPostData, cef_post_data_t>::DebugObjCt = 0;
long CefCppToC<CefPostDataCppToC, CefPostData, cef_post_data_t>::DebugObjCt
= 0;
#endif
@ -327,9 +242,7 @@ void CEF_CALLBACK post_data_element_set_to_empty(
if(!postDataElement)
return;
CefPostDataElementCppToC::Struct* impl =
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
impl->class_->GetClass()->SetToEmpty();
CefPostDataElementCppToC::Get(postDataElement)->SetToEmpty();
}
void CEF_CALLBACK post_data_element_set_to_file(
@ -340,13 +253,11 @@ void CEF_CALLBACK post_data_element_set_to_file(
if(!postDataElement)
return;
CefPostDataElementCppToC::Struct* impl =
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
std::wstring fileNameStr;
if(fileName)
fileNameStr = fileName;
impl->class_->GetClass()->SetToFile(fileNameStr);
CefPostDataElementCppToC::Get(postDataElement)->SetToFile(fileNameStr);
}
void CEF_CALLBACK post_data_element_set_to_bytes(
@ -357,9 +268,7 @@ void CEF_CALLBACK post_data_element_set_to_bytes(
if(!postDataElement)
return;
CefPostDataElementCppToC::Struct* impl =
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
impl->class_->GetClass()->SetToBytes(size, bytes);
CefPostDataElementCppToC::Get(postDataElement)->SetToBytes(size, bytes);
}
cef_postdataelement_type_t CEF_CALLBACK post_data_element_get_type(
@ -369,9 +278,7 @@ cef_postdataelement_type_t CEF_CALLBACK post_data_element_get_type(
if(!postDataElement)
return PDE_TYPE_EMPTY;
CefPostDataElementCppToC::Struct* impl =
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
return impl->class_->GetClass()->GetType();
return CefPostDataElementCppToC::Get(postDataElement)->GetType();
}
cef_string_t CEF_CALLBACK post_data_element_get_file(
@ -381,13 +288,11 @@ cef_string_t CEF_CALLBACK post_data_element_get_file(
if(!postDataElement)
return NULL;
CefPostDataElementCppToC::Struct* impl =
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
std::wstring fileNameStr = impl->class_->GetClass()->GetFile();
if(fileNameStr.empty())
return NULL;
return cef_string_alloc(fileNameStr.c_str());
std::wstring fileNameStr =
CefPostDataElementCppToC::Get(postDataElement)->GetFile();
if(!fileNameStr.empty())
return cef_string_alloc(fileNameStr.c_str());
return NULL;
}
size_t CEF_CALLBACK post_data_element_get_bytes_count(
@ -397,9 +302,7 @@ size_t CEF_CALLBACK post_data_element_get_bytes_count(
if(!postDataElement)
return 0;
CefPostDataElementCppToC::Struct* impl =
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
return impl->class_->GetClass()->GetBytesCount();
return CefPostDataElementCppToC::Get(postDataElement)->GetBytesCount();
}
size_t CEF_CALLBACK post_data_element_get_bytes(
@ -410,14 +313,13 @@ size_t CEF_CALLBACK post_data_element_get_bytes(
if(!postDataElement)
return 0;
CefPostDataElementCppToC::Struct* impl =
reinterpret_cast<CefPostDataElementCppToC::Struct*>(postDataElement);
return impl->class_->GetClass()->GetBytes(size, bytes);
return CefPostDataElementCppToC::Get(postDataElement)->GetBytes(size, bytes);
}
CefPostDataElementCppToC::CefPostDataElementCppToC(CefPostDataElement* cls)
: CefCppToC<CefPostDataElement, cef_post_data_element_t>(cls)
: CefCppToC<CefPostDataElementCppToC, CefPostDataElement,
cef_post_data_element_t>(cls)
{
struct_.struct_.set_to_empty = post_data_element_set_to_empty;
struct_.struct_.set_to_file = post_data_element_set_to_file;
@ -429,5 +331,6 @@ CefPostDataElementCppToC::CefPostDataElementCppToC(CefPostDataElement* cls)
}
#ifdef _DEBUG
long CefCppToC<CefPostDataElement, cef_post_data_element_t>::DebugObjCt = 0;
long CefCppToC<CefPostDataElementCppToC, CefPostDataElement,
cef_post_data_element_t>::DebugObjCt = 0;
#endif

View File

@ -16,7 +16,8 @@
// Wrap a C++ request class with a C request structure.
// This class may be instantiated and accessed DLL-side only.
class CefRequestCppToC : public CefCppToC<CefRequest, cef_request_t>
class CefRequestCppToC
: public CefCppToC<CefRequestCppToC, CefRequest, cef_request_t>
{
public:
CefRequestCppToC(CefRequest* cls);
@ -26,7 +27,8 @@ public:
// Wrap a C++ post data class with a C post data structure.
// This class may be instantiated and accessed DLL-side only.
class CefPostDataCppToC : public CefCppToC<CefPostData, cef_post_data_t>
class CefPostDataCppToC
: public CefCppToC<CefPostDataCppToC, CefPostData, cef_post_data_t>
{
public:
CefPostDataCppToC(CefPostData* cls);
@ -38,8 +40,9 @@ class CefPostDataElementCppToC;
// Wrap a C++ post data element class with a C post data element structure.
// This class may be instantiated and accessed DLL-side only.
class CefPostDataElementCppToC :
public CefCppToC<CefPostDataElement, cef_post_data_element_t>
class CefPostDataElementCppToC
: public CefCppToC<CefPostDataElementCppToC, CefPostDataElement,
cef_post_data_element_t>
{
public:
CefPostDataElementCppToC(CefPostDataElement* cls);

View File

@ -13,9 +13,7 @@ size_t CEF_CALLBACK stream_reader_read(struct _cef_stream_reader_t* stream,
if(!stream)
return 0;
CefStreamReaderCppToC::Struct* impl =
reinterpret_cast<CefStreamReaderCppToC::Struct*>(stream);
return impl->class_->GetClass()->Read(ptr, size, n);
return CefStreamReaderCppToC::Get(stream)->Read(ptr, size, n);
}
int CEF_CALLBACK stream_reader_seek(struct _cef_stream_reader_t* stream,
@ -25,9 +23,7 @@ int CEF_CALLBACK stream_reader_seek(struct _cef_stream_reader_t* stream,
if(!stream)
return 0;
CefStreamReaderCppToC::Struct* impl =
reinterpret_cast<CefStreamReaderCppToC::Struct*>(stream);
return impl->class_->GetClass()->Seek(offset, whence);
return CefStreamReaderCppToC::Get(stream)->Seek(offset, whence);
}
long CEF_CALLBACK stream_reader_tell(struct _cef_stream_reader_t* stream)
@ -36,9 +32,7 @@ long CEF_CALLBACK stream_reader_tell(struct _cef_stream_reader_t* stream)
if(!stream)
return 0;
CefStreamReaderCppToC::Struct* impl =
reinterpret_cast<CefStreamReaderCppToC::Struct*>(stream);
return impl->class_->GetClass()->Tell();
return CefStreamReaderCppToC::Get(stream)->Tell();
}
int CEF_CALLBACK stream_reader_eof(struct _cef_stream_reader_t* stream)
@ -47,14 +41,13 @@ int CEF_CALLBACK stream_reader_eof(struct _cef_stream_reader_t* stream)
if(!stream)
return 0;
CefStreamReaderCppToC::Struct* impl =
reinterpret_cast<CefStreamReaderCppToC::Struct*>(stream);
return impl->class_->GetClass()->Eof();
return CefStreamReaderCppToC::Get(stream)->Eof();
}
CefStreamReaderCppToC::CefStreamReaderCppToC(CefStreamReader* cls)
: CefCppToC<CefStreamReader, cef_stream_reader_t>(cls)
: CefCppToC<CefStreamReaderCppToC, CefStreamReader,
cef_stream_reader_t>(cls)
{
struct_.struct_.read = stream_reader_read;
struct_.struct_.seek = stream_reader_seek;
@ -63,7 +56,8 @@ CefStreamReaderCppToC::CefStreamReaderCppToC(CefStreamReader* cls)
}
#ifdef _DEBUG
long CefCppToC<CefStreamReader, cef_stream_reader_t>::DebugObjCt = 0;
long CefCppToC<CefStreamReaderCppToC, CefStreamReader,
cef_stream_reader_t>::DebugObjCt = 0;
#endif
@ -74,9 +68,7 @@ size_t CEF_CALLBACK stream_writer_write(struct _cef_stream_writer_t* stream,
if(!stream)
return 0;
CefStreamWriterCppToC::Struct* impl =
reinterpret_cast<CefStreamWriterCppToC::Struct*>(stream);
return impl->class_->GetClass()->Write(ptr, size, n);
return CefStreamWriterCppToC::Get(stream)->Write(ptr, size, n);
}
int CEF_CALLBACK stream_writer_seek(struct _cef_stream_writer_t* stream,
@ -86,9 +78,7 @@ int CEF_CALLBACK stream_writer_seek(struct _cef_stream_writer_t* stream,
if(!stream)
return 0;
CefStreamWriterCppToC::Struct* impl =
reinterpret_cast<CefStreamWriterCppToC::Struct*>(stream);
return impl->class_->GetClass()->Seek(offset, whence);
return CefStreamWriterCppToC::Get(stream)->Seek(offset, whence);
}
long CEF_CALLBACK stream_writer_tell(struct _cef_stream_writer_t* stream)
@ -97,9 +87,7 @@ long CEF_CALLBACK stream_writer_tell(struct _cef_stream_writer_t* stream)
if(!stream)
return 0;
CefStreamWriterCppToC::Struct* impl =
reinterpret_cast<CefStreamWriterCppToC::Struct*>(stream);
return impl->class_->GetClass()->Tell();
return CefStreamWriterCppToC::Get(stream)->Tell();
}
int CEF_CALLBACK stream_writer_flush(struct _cef_stream_writer_t* stream)
@ -108,14 +96,13 @@ int CEF_CALLBACK stream_writer_flush(struct _cef_stream_writer_t* stream)
if(!stream)
return 0;
CefStreamWriterCppToC::Struct* impl =
reinterpret_cast<CefStreamWriterCppToC::Struct*>(stream);
return impl->class_->GetClass()->Flush();
return CefStreamWriterCppToC::Get(stream)->Flush();
}
CefStreamWriterCppToC::CefStreamWriterCppToC(CefStreamWriter* cls)
: CefCppToC<CefStreamWriter, cef_stream_writer_t>(cls)
: CefCppToC<CefStreamWriterCppToC, CefStreamWriter,
cef_stream_writer_t>(cls)
{
struct_.struct_.write = stream_writer_write;
struct_.struct_.seek = stream_writer_seek;
@ -124,5 +111,6 @@ CefStreamWriterCppToC::CefStreamWriterCppToC(CefStreamWriter* cls)
}
#ifdef _DEBUG
long CefCppToC<CefStreamWriter, cef_stream_writer_t>::DebugObjCt = 0;
long CefCppToC<CefStreamWriterCppToC, CefStreamWriter,
cef_stream_writer_t>::DebugObjCt = 0;
#endif

View File

@ -16,8 +16,9 @@
// Wrap a C++ stream reader class with a C stream reader structure.
// This class may be instantiated and accessed DLL-side only.
class CefStreamReaderCppToC :
public CefCppToC<CefStreamReader, cef_stream_reader_t>
class CefStreamReaderCppToC
: public CefCppToC<CefStreamReaderCppToC, CefStreamReader,
cef_stream_reader_t>
{
public:
CefStreamReaderCppToC(CefStreamReader* cls);
@ -27,8 +28,9 @@ public:
// Wrap a C++ stream writer class with a C stream writer structure.
// This class may be instantiated and accessed DLL-side only.
class CefStreamWriterCppToC :
public CefCppToC<CefStreamWriter, cef_stream_writer_t>
class CefStreamWriterCppToC
: public CefCppToC<CefStreamWriterCppToC, CefStreamWriter,
cef_stream_writer_t>
{
public:
CefStreamWriterCppToC(CefStreamWriter* cls);

View File

@ -0,0 +1,54 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "../precompiled_libcef.h"
#include "cpptoc/v8handler_cpptoc.h"
#include "ctocpp/v8value_ctocpp.h"
int CEF_CALLBACK v8handler_execute(struct _cef_v8handler_t* v8handler,
const wchar_t* name, struct _cef_v8value_t* object, size_t numargs,
struct _cef_v8value_t** args, struct _cef_v8value_t** retval,
cef_string_t* exception)
{
DCHECK(v8handler);
if(!v8handler)
return RV_CONTINUE;
CefRefPtr<CefV8Value> objectPtr;
if(object)
objectPtr = CefV8ValueCToCpp::Wrap(object);
std::wstring nameStr;
if(name)
nameStr = name;
CefV8ValueList list;
for(size_t i = 0; i < numargs; ++i)
list.push_back(CefV8ValueCToCpp::Wrap(args[i]));
CefRefPtr<CefV8Value> retValPtr;
std::wstring exceptionStr;
bool rv = CefV8HandlerCppToC::Get(v8handler)->Execute(nameStr, objectPtr,
list, retValPtr, exceptionStr);
if(rv) {
if(!exceptionStr.empty() && exception)
*exception = cef_string_alloc(exceptionStr.c_str());
if(retValPtr.get() && retval)
*retval = CefV8ValueCToCpp::Unwrap(retValPtr);
}
return rv;
}
CefV8HandlerCppToC::CefV8HandlerCppToC(CefV8Handler* cls)
: CefCppToC<CefV8HandlerCppToC, CefV8Handler, cef_v8handler_t>(cls)
{
struct_.struct_.execute = v8handler_execute;
}
#ifdef _DEBUG
long CefCppToC<CefV8HandlerCppToC, CefV8Handler, cef_v8handler_t>::DebugObjCt
= 0;
#endif

View File

@ -2,8 +2,8 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _JSHANDLER_CPPTOC_H
#define _JSHANDLER_CPPTOC_H
#ifndef _V8HANDLER_CPPTOC_H
#define _V8HANDLER_CPPTOC_H
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
@ -14,15 +14,16 @@
#include "cpptoc.h"
// Wrap a C++ jshandler class with a C jshandler structure.
// Wrap a C++ v8handler class with a C v8handler structure.
// This class may be instantiated and accessed wrapper-side only.
class CefJSHandlerCppToC : public CefCppToC<CefJSHandler, cef_jshandler_t>
class CefV8HandlerCppToC
: public CefCppToC<CefV8HandlerCppToC, CefV8Handler, cef_v8handler_t>
{
public:
CefJSHandlerCppToC(CefJSHandler* cls);
virtual ~CefJSHandlerCppToC() {}
CefV8HandlerCppToC(CefV8Handler* cls);
virtual ~CefV8HandlerCppToC() {}
};
#endif // USING_CEF_SHARED
#endif // _JSHANDLER_CPPTOC_H
#endif // _V8HANDLER_CPPTOC_H

View File

@ -0,0 +1,359 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "../precompiled_libcef.h"
#include "cpptoc/v8value_cpptoc.h"
#include "ctocpp/v8handler_ctocpp.h"
int CEF_CALLBACK v8value_is_undefined(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->IsUndefined();
}
int CEF_CALLBACK v8value_is_null(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->IsNull();
}
int CEF_CALLBACK v8value_is_bool(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->IsBool();
}
int CEF_CALLBACK v8value_is_int(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->IsInt();
}
int CEF_CALLBACK v8value_is_double(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->IsDouble();
}
int CEF_CALLBACK v8value_is_string(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->IsString();
}
int CEF_CALLBACK v8value_is_object(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->IsObject();
}
int CEF_CALLBACK v8value_is_array(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->IsArray();
}
int CEF_CALLBACK v8value_is_function(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->IsFunction();
}
int CEF_CALLBACK v8value_get_bool_value(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->GetBoolValue();
}
int CEF_CALLBACK v8value_get_int_value(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->GetIntValue();
}
double CEF_CALLBACK v8value_get_double_value(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->GetDoubleValue();
}
cef_string_t CEF_CALLBACK v8value_get_string_value(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
std::wstring valueStr = CefV8ValueCppToC::Get(v8value)->GetStringValue();
if(!valueStr.empty())
return cef_string_alloc(valueStr.c_str());
return NULL;
}
int CEF_CALLBACK v8value_has_value_bykey(struct _cef_v8value_t* v8value,
const wchar_t* key)
{
DCHECK(v8value);
if(!v8value)
return 0;
std::wstring keyStr;
if(key)
keyStr = key;
return CefV8ValueCppToC::Get(v8value)->HasValue(keyStr);
}
int CEF_CALLBACK v8value_has_value_byindex(struct _cef_v8value_t* v8value,
int index)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->HasValue(index);
}
int CEF_CALLBACK v8value_delete_value_bykey(struct _cef_v8value_t* v8value,
const wchar_t* key)
{
DCHECK(v8value);
if(!v8value)
return 0;
std::wstring keyStr;
if(key)
keyStr = key;
return CefV8ValueCppToC::Get(v8value)->DeleteValue(keyStr);
}
int CEF_CALLBACK v8value_delete_value_byindex(struct _cef_v8value_t* v8value,
int index)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->DeleteValue(index);
}
struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_bykey(
struct _cef_v8value_t* v8value, const wchar_t* key)
{
DCHECK(v8value);
if(!v8value)
return 0;
std::wstring keyStr;
if(key)
keyStr = key;
CefRefPtr<CefV8Value> valuePtr =
CefV8ValueCppToC::Get(v8value)->GetValue(keyStr);
return CefV8ValueCppToC::Wrap(valuePtr);
}
struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_byindex(
struct _cef_v8value_t* v8value, int index)
{
DCHECK(v8value);
if(!v8value)
return 0;
CefRefPtr<CefV8Value> valuePtr =
CefV8ValueCppToC::Get(v8value)->GetValue(index);
return CefV8ValueCppToC::Wrap(valuePtr);
}
int CEF_CALLBACK v8value_set_value_bykey(struct _cef_v8value_t* v8value,
const wchar_t* key, struct _cef_v8value_t* new_value)
{
DCHECK(v8value);
if(!v8value)
return 0;
std::wstring keyStr;
if(key)
keyStr = key;
CefRefPtr<CefV8Value> valuePtr = CefV8ValueCppToC::Unwrap(new_value);
return CefV8ValueCppToC::Get(v8value)->SetValue(keyStr, valuePtr);
}
int CEF_CALLBACK v8value_set_value_byindex(struct _cef_v8value_t* v8value,
int index, struct _cef_v8value_t* new_value)
{
DCHECK(v8value);
if(!v8value)
return 0;
CefRefPtr<CefV8Value> valuePtr = CefV8ValueCppToC::Unwrap(new_value);
return CefV8ValueCppToC::Get(v8value)->SetValue(index, valuePtr);
}
int CEF_CALLBACK v8value_get_keys(struct _cef_v8value_t* v8value,
cef_string_list_t list)
{
DCHECK(v8value);
if(!v8value)
return 0;
std::vector<std::wstring> keysList;
CefV8ValueCppToC::Get(v8value)->GetKeys(keysList);
size_t size = keysList.size();
for(size_t i = 0; i < size; ++i)
cef_string_list_append(list, keysList[i].c_str());
return size;
}
struct _cef_base_t* CEF_CALLBACK v8value_get_user_data(
struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
CefRefPtr<CefBase> base = CefV8ValueCppToC::Get(v8value)->GetUserData();
if(base.get())
return CefBaseCToCpp::Unwrap(base);
return NULL;
}
int CEF_CALLBACK v8value_get_array_length(struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
return CefV8ValueCppToC::Get(v8value)->GetArrayLength();
}
cef_string_t CEF_CALLBACK v8value_get_function_name(
struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
std::wstring functionNameStr =
CefV8ValueCppToC::Get(v8value)->GetFunctionName();
if(!functionNameStr.empty())
return cef_string_alloc(functionNameStr.c_str());
return NULL;
}
struct _cef_v8handler_t* CEF_CALLBACK v8value_get_function_handler(
struct _cef_v8value_t* v8value)
{
DCHECK(v8value);
if(!v8value)
return 0;
CefRefPtr<CefV8Handler> handlerPtr =
CefV8ValueCppToC::Get(v8value)->GetFunctionHandler();
if(handlerPtr.get())
return CefV8HandlerCToCpp::Unwrap(handlerPtr);
return NULL;
}
int CEF_CALLBACK v8value_execute_function(struct _cef_v8value_t* v8value,
struct _cef_v8value_t* object, size_t numargs,
struct _cef_v8value_t** args, struct _cef_v8value_t** retval,
cef_string_t* exception)
{
DCHECK(v8value);
DCHECK(object);
if(!v8value || !object)
return 0;
CefRefPtr<CefV8Value> objectPtr = CefV8ValueCppToC::Unwrap(object);
CefV8ValueList argsList;
for(size_t i = 0; i < numargs; i++)
argsList.push_back(CefV8ValueCppToC::Unwrap(args[i]));
CefRefPtr<CefV8Value> retvalPtr;
std::wstring exceptionStr;
bool rv = CefV8ValueCppToC::Get(v8value)->ExecuteFunction(objectPtr,
argsList, retvalPtr, exceptionStr);
if(retvalPtr.get() && retval)
*retval = CefV8ValueCppToC::Wrap(retvalPtr);
if(!exceptionStr.empty() && exception)
*exception = cef_string_alloc(exceptionStr.c_str());
return rv;
}
CefV8ValueCppToC::CefV8ValueCppToC(CefV8Value* cls)
: CefCppToC<CefV8ValueCppToC, CefV8Value, cef_v8value_t>(cls)
{
struct_.struct_.is_undefined = v8value_is_undefined;
struct_.struct_.is_null = v8value_is_null;
struct_.struct_.is_bool = v8value_is_bool;
struct_.struct_.is_int = v8value_is_int;
struct_.struct_.is_double = v8value_is_double;
struct_.struct_.is_string = v8value_is_string;
struct_.struct_.is_object = v8value_is_object;
struct_.struct_.is_array = v8value_is_array;
struct_.struct_.is_function = v8value_is_function;
struct_.struct_.get_bool_value = v8value_get_bool_value;
struct_.struct_.get_int_value = v8value_get_int_value;
struct_.struct_.get_double_value = v8value_get_double_value;
struct_.struct_.get_string_value = v8value_get_string_value;
struct_.struct_.has_value_bykey = v8value_has_value_bykey;
struct_.struct_.has_value_byindex = v8value_has_value_byindex;
struct_.struct_.delete_value_bykey = v8value_delete_value_bykey;
struct_.struct_.delete_value_byindex = v8value_delete_value_byindex;
struct_.struct_.get_value_bykey = v8value_get_value_bykey;
struct_.struct_.get_value_byindex = v8value_get_value_byindex;
struct_.struct_.set_value_bykey = v8value_set_value_bykey;
struct_.struct_.set_value_byindex = v8value_set_value_byindex;
struct_.struct_.get_keys = v8value_get_keys;
struct_.struct_.get_user_data = v8value_get_user_data;
struct_.struct_.get_array_length = v8value_get_array_length;
struct_.struct_.get_function_name = v8value_get_function_name;
struct_.struct_.get_function_handler = v8value_get_function_handler;
struct_.struct_.execute_function = v8value_execute_function;
}
#ifdef _DEBUG
long CefCppToC<CefV8ValueCppToC, CefV8Value, cef_v8value_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,29 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _V8VALUE_CPPTOC_H
#define _V8VALUE_CPPTOC_H
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "cpptoc.h"
// Wrap a C++ v8value class with a C v8value structure.
// This class may be instantiated and accessed wrapper-side only.
class CefV8ValueCppToC
: public CefCppToC<CefV8ValueCppToC, CefV8Value, cef_v8value_t>
{
public:
CefV8ValueCppToC(CefV8Value* cls);
virtual ~CefV8ValueCppToC() {}
};
#endif // BUILDING_CEF_SHARED
#endif // _V8VALUE_CPPTOC_H

View File

@ -1,310 +0,0 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "../precompiled_libcef.h"
#include "cpptoc/variant_cpptoc.h"
cef_variant_type_t CEF_CALLBACK variant_get_type(struct _cef_variant_t* variant)
{
DCHECK(variant);
if(!variant)
return VARIANT_TYPE_NULL;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
return impl->class_->GetClass()->GetType();
}
void CEF_CALLBACK variant_set_null(struct _cef_variant_t* variant)
{
DCHECK(variant);
if(!variant)
return;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
impl->class_->GetClass()->SetNull();
}
void CEF_CALLBACK variant_set_bool(struct _cef_variant_t* variant, int val)
{
DCHECK(variant);
if(!variant)
return;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
impl->class_->GetClass()->SetBool(val ? true : false);
}
void CEF_CALLBACK variant_set_int(struct _cef_variant_t* variant, int val)
{
DCHECK(variant);
if(!variant)
return;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
impl->class_->GetClass()->SetInt(val);
}
void CEF_CALLBACK variant_set_double(struct _cef_variant_t* variant, double val)
{
DCHECK(variant);
if(!variant)
return;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
impl->class_->GetClass()->SetDouble(val);
}
void CEF_CALLBACK variant_set_string(struct _cef_variant_t* variant,
const wchar_t* val)
{
DCHECK(variant);
if(!variant)
return;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
impl->class_->GetClass()->SetString(val);
}
void CEF_CALLBACK variant_set_bool_array(struct _cef_variant_t* variant,
size_t count, const int* vals)
{
DCHECK(variant);
if(!variant)
return;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
std::vector<bool> vec;
for(size_t i = 0; i < count; ++i)
vec.push_back(vals[i] ? true : false);
impl->class_->GetClass()->SetBoolArray(vec);
}
void CEF_CALLBACK variant_set_int_array(struct _cef_variant_t* variant,
size_t count, const int* vals)
{
DCHECK(variant);
if(!variant)
return;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
std::vector<int> vec;
for(size_t i = 0; i < count; ++i)
vec.push_back(vals[i]);
impl->class_->GetClass()->SetIntArray(vec);
}
void CEF_CALLBACK variant_set_double_array(struct _cef_variant_t* variant,
size_t count, const double* vals)
{
DCHECK(variant);
if(!variant)
return;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
std::vector<double> vec;
for(size_t i = 0; i < count; ++i)
vec.push_back(vals[i]);
impl->class_->GetClass()->SetDoubleArray(vec);
}
void CEF_CALLBACK variant_set_string_array(struct _cef_variant_t* variant,
size_t count,
const cef_string_t* vals)
{
DCHECK(variant);
if(!variant)
return;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
std::vector<std::wstring> vec;
for(size_t i = 0; i < count; ++i)
vec.push_back(vals[i] ? vals[i] : std::wstring());
impl->class_->GetClass()->SetStringArray(vec);
}
int CEF_CALLBACK variant_get_bool(struct _cef_variant_t* variant)
{
DCHECK(variant);
if(!variant)
return 0;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
return impl->class_->GetClass()->GetBool();
}
int CEF_CALLBACK variant_get_int(struct _cef_variant_t* variant)
{
DCHECK(variant);
if(!variant)
return 0;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
return impl->class_->GetClass()->GetInt();
}
double CEF_CALLBACK variant_get_double(struct _cef_variant_t* variant)
{
DCHECK(variant);
if(!variant)
return 0;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
return impl->class_->GetClass()->GetDouble();
}
cef_string_t CEF_CALLBACK variant_get_string(struct _cef_variant_t* variant)
{
DCHECK(variant);
if(!variant)
return NULL;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
std::wstring str;
str = impl->class_->GetClass()->GetString();
if(str.empty())
return NULL;
return cef_string_alloc(str.c_str());
}
int CEF_CALLBACK variant_get_array_size(struct _cef_variant_t* variant)
{
DCHECK(variant);
if(!variant)
return 0;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
return impl->class_->GetClass()->GetArraySize();
}
size_t CEF_CALLBACK variant_get_bool_array(struct _cef_variant_t* variant,
size_t maxcount, int* vals)
{
DCHECK(variant);
if(!variant)
return 0;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
std::vector<bool> vec;
impl->class_->GetClass()->GetBoolArray(vec);
size_t ct = 0;
for(; ct < maxcount && ct < vec.size(); ++ct)
vals[ct] = vec[ct];
return ct;
}
size_t CEF_CALLBACK variant_get_int_array(struct _cef_variant_t* variant,
size_t maxcount, int* vals)
{
DCHECK(variant);
if(!variant)
return 0;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
std::vector<int> vec;
impl->class_->GetClass()->GetIntArray(vec);
size_t ct = 0;
for(; ct < maxcount && ct < vec.size(); ++ct)
vals[ct] = vec[ct];
return ct;
}
size_t CEF_CALLBACK variant_get_double_array(struct _cef_variant_t* variant,
size_t maxcount, double* vals)
{
DCHECK(variant);
if(!variant)
return 0;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
std::vector<double> vec;
impl->class_->GetClass()->GetDoubleArray(vec);
size_t ct = 0;
for(; ct < maxcount && ct < vec.size(); ++ct)
vals[ct] = vec[ct];
return ct;
}
size_t CEF_CALLBACK variant_get_string_array(struct _cef_variant_t* variant,
size_t maxcount,
cef_string_t* vals)
{
DCHECK(variant);
if(!variant)
return 0;
CefVariantCppToC::Struct* impl =
reinterpret_cast<CefVariantCppToC::Struct*>(variant);
std::vector<std::wstring> vec;
impl->class_->GetClass()->GetStringArray(vec);
size_t ct = 0;
for(; ct < maxcount && ct < vec.size(); ++ct)
vals[ct] = cef_string_alloc(vec[ct].c_str());
return ct;
}
CefVariantCppToC::CefVariantCppToC(CefVariant* cls)
: CefCppToC<CefVariant, cef_variant_t>(cls)
{
struct_.struct_.get_type = variant_get_type;
struct_.struct_.set_null = variant_set_null;
struct_.struct_.set_bool = variant_set_bool;
struct_.struct_.set_int = variant_set_int;
struct_.struct_.set_double = variant_set_double;
struct_.struct_.set_string = variant_set_string;
struct_.struct_.set_bool_array = variant_set_bool_array;
struct_.struct_.set_int_array = variant_set_int_array;
struct_.struct_.set_double_array = variant_set_double_array;
struct_.struct_.set_string_array = variant_set_string_array;
struct_.struct_.get_bool = variant_get_bool;
struct_.struct_.get_int = variant_get_int;
struct_.struct_.get_double = variant_get_double;
struct_.struct_.get_string = variant_get_string;
struct_.struct_.get_array_size = variant_get_array_size;
struct_.struct_.get_bool_array = variant_get_bool_array;
struct_.struct_.get_int_array = variant_get_int_array;
struct_.struct_.get_double_array = variant_get_double_array;
struct_.struct_.get_string_array = variant_get_string_array;
}
#ifdef _DEBUG
long CefCppToC<CefVariant, cef_variant_t>::DebugObjCt = 0;
#endif

View File

@ -4,10 +4,8 @@
#include "../precompiled_libcef.h"
#include "ctocpp/browser_ctocpp.h"
#include "ctocpp/request_ctocpp.h"
#include "ctocpp/stream_ctocpp.h"
#include "cpptoc/handler_cpptoc.h"
#include "cpptoc/jshandler_cpptoc.h"
#include "ctocpp/frame_ctocpp.h"
bool CefBrowserCToCpp::CanGoBack()
@ -58,62 +56,6 @@ void CefBrowserCToCpp::StopLoad()
struct_->stop_load(struct_);
}
void CefBrowserCToCpp::Undo(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, undo))
return;
struct_->undo(struct_, targetFrame);
}
void CefBrowserCToCpp::Redo(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, redo))
return;
struct_->redo(struct_, targetFrame);
}
void CefBrowserCToCpp::Cut(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, cut))
return;
struct_->cut(struct_, targetFrame);
}
void CefBrowserCToCpp::Copy(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, copy))
return;
struct_->copy(struct_, targetFrame);
}
void CefBrowserCToCpp::Paste(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, paste))
return;
struct_->paste(struct_, targetFrame);
}
void CefBrowserCToCpp::Delete(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, del))
return;
struct_->del(struct_, targetFrame);
}
void CefBrowserCToCpp::SelectAll(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, select_all))
return;
struct_->select_all(struct_, targetFrame);
}
void CefBrowserCToCpp::SetFocus(bool enable)
{
if(CEF_MEMBER_MISSING(struct_, set_focus))
@ -122,155 +64,6 @@ void CefBrowserCToCpp::SetFocus(bool enable)
struct_->set_focus(struct_, enable);
}
void CefBrowserCToCpp::Print(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, print))
return;
struct_->print(struct_, targetFrame);
}
void CefBrowserCToCpp::ViewSource(TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, view_source))
return;
struct_->view_source(struct_, targetFrame);
}
std::wstring CefBrowserCToCpp::GetSource(TargetFrame targetFrame)
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_source))
return str;
cef_string_t cef_str = struct_->get_source(struct_, targetFrame);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
std::wstring CefBrowserCToCpp::GetText(TargetFrame targetFrame)
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_text))
return str;
cef_string_t cef_str = struct_->get_text(struct_, targetFrame);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
void CefBrowserCToCpp::LoadRequest(CefRefPtr<CefRequest> request)
{
if(CEF_MEMBER_MISSING(struct_, load_request))
return;
CefRequestCToCpp* rp = static_cast<CefRequestCToCpp*>(request.get());
rp->UnderlyingAddRef();
struct_->load_request(struct_, rp->GetStruct());
}
void CefBrowserCToCpp::LoadURL(const std::wstring& url,
const std::wstring& frame)
{
if(CEF_MEMBER_MISSING(struct_, load_url))
return;
struct_->load_url(struct_, url.c_str(), frame.c_str());
}
void CefBrowserCToCpp::LoadString(const std::wstring& string,
const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, load_string))
return;
struct_->load_string(struct_, string.c_str(), url.c_str());
}
void CefBrowserCToCpp::LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, load_stream))
return;
CefStreamReaderCToCpp* sp =
static_cast<CefStreamReaderCToCpp*>(stream.get());
sp->UnderlyingAddRef();
struct_->load_stream(struct_, sp->GetStruct(), url.c_str());
}
void CefBrowserCToCpp::ExecuteJavaScript(const std::wstring& js_code,
const std::wstring& script_url,
int start_line,
TargetFrame targetFrame)
{
if(CEF_MEMBER_MISSING(struct_, execute_javascript))
return;
struct_->execute_javascript(struct_, js_code.c_str(), script_url.c_str(),
start_line, targetFrame);
}
bool CefBrowserCToCpp::AddJSHandler(const std::wstring& classname,
CefRefPtr<CefJSHandler> handler)
{
if(CEF_MEMBER_MISSING(struct_, add_jshandler))
return false;
CefJSHandlerCppToC* hp = new CefJSHandlerCppToC(handler);
hp->AddRef();
return struct_->add_jshandler(struct_, classname.c_str(), hp->GetStruct());
return true;
}
bool CefBrowserCToCpp::HasJSHandler(const std::wstring& classname)
{
if(CEF_MEMBER_MISSING(struct_, has_jshandler))
return false;
return struct_->has_jshandler(struct_, classname.c_str());
}
CefRefPtr<CefJSHandler> CefBrowserCToCpp::GetJSHandler(const std::wstring& classname)
{
if(CEF_MEMBER_MISSING(struct_, get_jshandler))
return NULL;
CefJSHandlerCppToC::Struct* hp =
reinterpret_cast<CefJSHandlerCppToC::Struct*>(
struct_->get_jshandler(struct_, classname.c_str()));
if(hp) {
CefRefPtr<CefJSHandler> handlerPtr(hp->class_->GetClass());
hp->class_->UnderlyingRelease();
return handlerPtr;
}
return NULL;
}
bool CefBrowserCToCpp::RemoveJSHandler(const std::wstring& classname)
{
if(CEF_MEMBER_MISSING(struct_, remove_jshandler))
return false;
return struct_->remove_jshandler(struct_, classname.c_str());
}
void CefBrowserCToCpp::RemoveAllJSHandlers()
{
if(CEF_MEMBER_MISSING(struct_, remove_all_jshandlers))
return;
struct_->remove_all_jshandlers(struct_);
}
CefWindowHandle CefBrowserCToCpp::GetWindowHandle()
{
if(CEF_MEMBER_MISSING(struct_, get_window_handle))
@ -291,33 +84,69 @@ CefRefPtr<CefHandler> CefBrowserCToCpp::GetHandler()
{
if(CEF_MEMBER_MISSING(struct_, get_handler))
return NULL;
CefHandlerCppToC::Struct* hp =
reinterpret_cast<CefHandlerCppToC::Struct*>(
struct_->get_handler(struct_));
if(hp) {
CefRefPtr<CefHandler> handlerPtr(hp->class_->GetClass());
hp->class_->UnderlyingRelease();
return handlerPtr;
}
cef_handler_t* handlerStruct = struct_->get_handler(struct_);
if(handlerStruct)
return CefHandlerCppToC::Unwrap(handlerStruct);
return NULL;
}
std::wstring CefBrowserCToCpp::GetURL()
CefRefPtr<CefFrame> CefBrowserCToCpp::GetMainFrame()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_url))
return str;
if(CEF_MEMBER_MISSING(struct_, get_main_frame))
return NULL;
cef_string_t cef_str = struct_->get_url(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
cef_frame_t* frameStruct = struct_->get_main_frame(struct_);
if(frameStruct)
return CefFrameCToCpp::Wrap(frameStruct);
return NULL;
}
CefRefPtr<CefFrame> CefBrowserCToCpp::GetFocusedFrame()
{
if(CEF_MEMBER_MISSING(struct_, get_main_frame))
return NULL;
cef_frame_t* frameStruct = struct_->get_focused_frame(struct_);
if(frameStruct)
return CefFrameCToCpp::Wrap(frameStruct);
return NULL;
}
CefRefPtr<CefFrame> CefBrowserCToCpp::GetFrame(const std::wstring& name)
{
if(CEF_MEMBER_MISSING(struct_, get_main_frame))
return NULL;
cef_frame_t* frameStruct = struct_->get_frame(struct_, name.c_str());
if(frameStruct)
return CefFrameCToCpp::Wrap(frameStruct);
return NULL;
}
void CefBrowserCToCpp::GetFrameNames(std::vector<std::wstring>& names)
{
if(CEF_MEMBER_MISSING(struct_, get_frame_names))
return;
cef_string_list_t list = cef_string_list_alloc();
struct_->get_frame_names(struct_, list);
cef_string_t str;
int size = cef_string_list_size(list);
for(int i = 0; i < size; ++i) {
str = cef_string_list_value(list, i);
names.push_back(str);
cef_string_free(str);
}
return str;
cef_string_list_free(list);
}
#ifdef _DEBUG
long CefCToCpp<CefBrowser, cef_browser_t>::DebugObjCt = 0;
long CefCToCpp<CefBrowserCToCpp, CefBrowser, cef_browser_t>::DebugObjCt = 0;
#endif

View File

@ -16,11 +16,12 @@
// Wrap a C browser structure with a C++ browser class.
// This class may be instantiated and accessed wrapper-side only.
class CefBrowserCToCpp : public CefCToCpp<CefBrowser, cef_browser_t>
class CefBrowserCToCpp
: public CefCToCpp<CefBrowserCToCpp, CefBrowser, cef_browser_t>
{
public:
CefBrowserCToCpp(cef_browser_t* str)
: CefCToCpp<CefBrowser, cef_browser_t>(str) {}
: CefCToCpp<CefBrowserCToCpp, CefBrowser, cef_browser_t>(str) {}
virtual ~CefBrowserCToCpp() {}
// CefBrowser methods
@ -30,37 +31,14 @@ public:
virtual void GoForward();
virtual void Reload();
virtual void StopLoad();
virtual void Undo(TargetFrame targetFrame);
virtual void Redo(TargetFrame targetFrame);
virtual void Cut(TargetFrame targetFrame);
virtual void Copy(TargetFrame targetFrame);
virtual void Paste(TargetFrame targetFrame);
virtual void Delete(TargetFrame targetFrame);
virtual void SelectAll(TargetFrame targetFrame);
virtual void SetFocus(bool enable);
virtual void Print(TargetFrame targetFrame);
virtual void ViewSource(TargetFrame targetFrame);
virtual std::wstring GetSource(TargetFrame targetFrame);
virtual std::wstring GetText(TargetFrame targetFrame);
virtual void LoadRequest(CefRefPtr<CefRequest> request);
virtual void LoadURL(const std::wstring& url, const std::wstring& frame);
virtual void LoadString(const std::wstring& string,
const std::wstring& url);
virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url);
virtual void ExecuteJavaScript(const std::wstring& js_code,
const std::wstring& script_url,
int start_line, TargetFrame targetFrame);
virtual bool AddJSHandler(const std::wstring& classname,
CefRefPtr<CefJSHandler> handler);
virtual bool HasJSHandler(const std::wstring& classname);
virtual CefRefPtr<CefJSHandler> GetJSHandler(const std::wstring& classname);
virtual bool RemoveJSHandler(const std::wstring& classname);
virtual void RemoveAllJSHandlers();
virtual CefWindowHandle GetWindowHandle();
virtual bool IsPopup();
virtual CefRefPtr<CefHandler> GetHandler();
virtual std::wstring GetURL();
virtual CefRefPtr<CefFrame> GetMainFrame();
virtual CefRefPtr<CefFrame> GetFocusedFrame();
virtual CefRefPtr<CefFrame> GetFrame(const std::wstring& name);
virtual void GetFrameNames(std::vector<std::wstring>& names);
};

View File

@ -10,11 +10,41 @@
#include "../cef_logging.h"
// Wrap a C structure with a C++ class.
template <class ClassName, class StructName>
class CefCToCpp : public CefThreadSafeBase<ClassName>
// Wrap a C structure with a C++ class. This is used when the implementation
// exists on the other side of the DLL boundary but will have methods called on
// this side of the DLL boundary.
template <class ClassName, class BaseName, class StructName>
class CefCToCpp : public CefThreadSafeBase<BaseName>
{
public:
// Use this method to create a wrapper class instance for a structure
// received from the other side.
static CefRefPtr<BaseName> Wrap(StructName* s)
{
// Wrap their structure with the CefCToCpp object.
ClassName* wrapper = new ClassName(s);
// Put the wrapper object in a smart pointer.
CefRefPtr<BaseName> wrapperPtr(wrapper);
// Release the reference that was added to the CefCppToC wrapper object on
// the other side before their structure was passed to us.
wrapper->UnderlyingRelease();
// Return the smart pointer.
return wrapperPtr;
}
// Use this method to retrieve the underlying structure from a wrapper class
// instance for return back to the other side.
static StructName* Unwrap(CefRefPtr<BaseName> c)
{
// Cast the object to our wrapper class type.
ClassName* wrapper = static_cast<ClassName*>(c.get());
// Add a reference to the CefCppToC wrapper object on the other side that
// will be released once the structure is received.
wrapper->UnderlyingAddRef();
// Return their original structure.
return wrapper->GetStruct();
}
CefCToCpp(StructName* str)
: struct_(str)
{
@ -41,12 +71,12 @@ public:
virtual int AddRef()
{
UnderlyingAddRef();
return CefThreadSafeBase<ClassName>::AddRef();
return CefThreadSafeBase<BaseName>::AddRef();
}
virtual int Release()
{
UnderlyingRelease();
return CefThreadSafeBase<ClassName>::Release();
return CefThreadSafeBase<BaseName>::Release();
}
// Increment/decrement reference counts on only the underlying class.
@ -77,6 +107,87 @@ public:
protected:
StructName* struct_;
};
// CefCToCpp implementation for CefBase.
class CefBaseCToCpp : public CefThreadSafeBase<CefBase>
{
public:
// Use this method to create a wrapper class instance for a structure
// received from the other side.
static CefRefPtr<CefBase> Wrap(cef_base_t* s)
{
// Wrap their structure with the CefCToCpp object.
CefBaseCToCpp* wrapper = new CefBaseCToCpp(s);
// Put the wrapper object in a smart pointer.
CefRefPtr<CefBase> wrapperPtr(wrapper);
// Release the reference that was added to the CefCppToC wrapper object on
// the other side before their structure was passed to us.
wrapper->UnderlyingRelease();
// Return the smart pointer.
return wrapperPtr;
}
// Use this method to retrieve the underlying structure from a wrapper class
// instance for return back to the other side.
static cef_base_t* Unwrap(CefRefPtr<CefBase> c)
{
// Cast the object to our wrapper class type.
CefBaseCToCpp* wrapper = static_cast<CefBaseCToCpp*>(c.get());
// Add a reference to the CefCppToC wrapper object on the other side that
// will be released once the structure is received.
wrapper->UnderlyingAddRef();
// Return their original structure.
return wrapper->GetStruct();
}
CefBaseCToCpp(cef_base_t* str)
: struct_(str)
{
DCHECK(str);
}
virtual ~CefBaseCToCpp() {}
// If returning the structure across the DLL boundary you should call
// UnderlyingAddRef() on this wrapping CefCToCpp object. On the other side of
// the DLL boundary, call Release() on the CefCppToC object.
cef_base_t* GetStruct() { return struct_; }
// CefBase methods increment/decrement reference counts on both this object
// and the underlying wrapped structure.
virtual int AddRef()
{
UnderlyingAddRef();
return CefThreadSafeBase<CefBase>::AddRef();
}
virtual int Release()
{
UnderlyingRelease();
return CefThreadSafeBase<CefBase>::Release();
}
// Increment/decrement reference counts on only the underlying class.
int UnderlyingAddRef()
{
if(!struct_->add_ref)
return 0;
return struct_->add_ref(struct_);
}
int UnderlyingRelease()
{
if(!struct_->release)
return 0;
return struct_->release(struct_);
}
int UnderlyingGetRefCt()
{
if(!struct_->get_refct)
return 0;
return struct_->get_refct(struct_);
}
protected:
cef_base_t* struct_;
};
#endif // _CTOCPP_H

View File

@ -0,0 +1,203 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "../precompiled_libcef.h"
#include "ctocpp/frame_ctocpp.h"
#include "ctocpp/request_ctocpp.h"
#include "ctocpp/stream_ctocpp.h"
void CefFrameCToCpp::Undo()
{
if(CEF_MEMBER_MISSING(struct_, undo))
return;
struct_->undo(struct_);
}
void CefFrameCToCpp::Redo()
{
if(CEF_MEMBER_MISSING(struct_, redo))
return;
struct_->redo(struct_);
}
void CefFrameCToCpp::Cut()
{
if(CEF_MEMBER_MISSING(struct_, cut))
return;
struct_->cut(struct_);
}
void CefFrameCToCpp::Copy()
{
if(CEF_MEMBER_MISSING(struct_, copy))
return;
struct_->copy(struct_);
}
void CefFrameCToCpp::Paste()
{
if(CEF_MEMBER_MISSING(struct_, paste))
return;
struct_->paste(struct_);
}
void CefFrameCToCpp::Delete()
{
if(CEF_MEMBER_MISSING(struct_, del))
return;
struct_->del(struct_);
}
void CefFrameCToCpp::SelectAll()
{
if(CEF_MEMBER_MISSING(struct_, select_all))
return;
struct_->select_all(struct_);
}
void CefFrameCToCpp::Print()
{
if(CEF_MEMBER_MISSING(struct_, print))
return;
struct_->print(struct_);
}
void CefFrameCToCpp::ViewSource()
{
if(CEF_MEMBER_MISSING(struct_, view_source))
return;
struct_->view_source(struct_);
}
std::wstring CefFrameCToCpp::GetSource()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_source))
return str;
cef_string_t cef_str = struct_->get_source(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
std::wstring CefFrameCToCpp::GetText()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_text))
return str;
cef_string_t cef_str = struct_->get_text(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
void CefFrameCToCpp::LoadRequest(CefRefPtr<CefRequest> request)
{
if(CEF_MEMBER_MISSING(struct_, load_request))
return;
struct_->load_request(struct_, CefRequestCToCpp::Unwrap(request));
}
void CefFrameCToCpp::LoadURL(const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, load_url))
return;
struct_->load_url(struct_, url.c_str());
}
void CefFrameCToCpp::LoadString(const std::wstring& string,
const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, load_string))
return;
struct_->load_string(struct_, string.c_str(), url.c_str());
}
void CefFrameCToCpp::LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, load_stream))
return;
struct_->load_stream(struct_, CefStreamReaderCToCpp::Unwrap(stream),
url.c_str());
}
void CefFrameCToCpp::ExecuteJavaScript(const std::wstring& js_code,
const std::wstring& script_url,
int start_line)
{
if(CEF_MEMBER_MISSING(struct_, execute_javascript))
return;
struct_->execute_javascript(struct_, js_code.c_str(), script_url.c_str(),
start_line);
}
bool CefFrameCToCpp::IsMain()
{
if(CEF_MEMBER_MISSING(struct_, is_main))
return false;
return struct_->is_main(struct_);
}
bool CefFrameCToCpp::IsFocused()
{
if(CEF_MEMBER_MISSING(struct_, is_focused))
return false;
return struct_->is_focused(struct_);
}
std::wstring CefFrameCToCpp::GetName()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_name))
return str;
cef_string_t cef_str = struct_->get_name(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
std::wstring CefFrameCToCpp::GetURL()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_url))
return str;
cef_string_t cef_str = struct_->get_url(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
#ifdef _DEBUG
long CefCToCpp<CefFrameCToCpp, CefFrame, cef_frame_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,55 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _FRAME_CTOCPP_H
#define _FRAME_CTOCPP_H
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "ctocpp.h"
// Wrap a C frame structure with a C++ frame class.
// This class may be instantiated and accessed wrapper-side only.
class CefFrameCToCpp : public CefCToCpp<CefFrameCToCpp, CefFrame, cef_frame_t>
{
public:
CefFrameCToCpp(cef_frame_t* str)
: CefCToCpp<CefFrameCToCpp, CefFrame, cef_frame_t>(str) {}
virtual ~CefFrameCToCpp() {}
// CefFrame methods
virtual void Undo();
virtual void Redo();
virtual void Cut();
virtual void Copy();
virtual void Paste();
virtual void Delete();
virtual void SelectAll();
virtual void Print();
virtual void ViewSource();
virtual std::wstring GetSource();
virtual std::wstring GetText();
virtual void LoadRequest(CefRefPtr<CefRequest> request);
virtual void LoadURL(const std::wstring& url);
virtual void LoadString(const std::wstring& string,
const std::wstring& url);
virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
const std::wstring& url);
virtual void ExecuteJavaScript(const std::wstring& jsCode,
const std::wstring& scriptUrl,
int startLine);
virtual bool IsMain();
virtual bool IsFocused();
virtual std::wstring GetName();
virtual std::wstring GetURL();
};
#endif // USING_CEF_SHARED
#endif // _FRAME_CTOCPP_H

View File

@ -4,8 +4,10 @@
#include "../precompiled_libcef.h"
#include "cpptoc/browser_cpptoc.h"
#include "cpptoc/frame_cpptoc.h"
#include "cpptoc/request_cpptoc.h"
#include "cpptoc/stream_cpptoc.h"
#include "cpptoc/v8value_cpptoc.h"
#include "ctocpp/handler_ctocpp.h"
#include "transfer_util.h"
@ -17,38 +19,28 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeCreated(
if(CEF_MEMBER_MISSING(struct_, handle_before_created))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = NULL;
cef_browser_t* browserStructPtr = NULL;
if(parentBrowser.get()) {
browserPtr = new CefBrowserCppToC(parentBrowser);
browserPtr->AddRef();
browserStructPtr = browserPtr->GetStruct();
}
cef_browser_t* browserStruct = NULL;
if(parentBrowser.get())
browserStruct = CefBrowserCppToC::Wrap(parentBrowser);
CefHandlerCToCpp* handlerPtr = NULL;
cef_handler_t* handlerRet = NULL;
if(handler.get()) {
handlerPtr = static_cast<CefHandlerCToCpp*>(handler.get());
handlerPtr->UnderlyingAddRef();
handlerRet = handlerPtr->GetStruct();
}
cef_handler_t* handlerStruct = NULL;
if(handler.get())
handlerStruct = CefHandlerCToCpp::Unwrap(handler);
cef_handler_t *origHandlerStruct = handlerStruct;
cef_string_t urlRet = NULL;
if(!url.empty())
urlRet = cef_string_alloc(url.c_str());
cef_retval_t rv = struct_->handle_before_created(struct_,
browserStructPtr, &windowInfo, popup, &handlerRet, &urlRet);
browserStruct, &windowInfo, popup, &handlerStruct, &urlRet);
if(handlerPtr && handlerRet != handlerPtr->GetStruct()) {
if(handlerStruct && handlerStruct != origHandlerStruct) {
// The handler was changed.
if(handlerRet) {
CefHandlerCToCpp* hp = new CefHandlerCToCpp(handlerRet);
handler = hp;
hp->UnderlyingRelease();
} else {
if(handlerStruct)
handler = CefHandlerCToCpp::Wrap(handlerStruct);
else
handler = NULL;
}
}
transfer_string_contents(urlRet, url, true);
@ -62,20 +54,19 @@ CefHandler::RetVal CefHandlerCToCpp::HandleAfterCreated(
if(CEF_MEMBER_MISSING(struct_, handle_after_created))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_after_created(struct_, browserPtr->GetStruct());
return struct_->handle_after_created(struct_,
CefBrowserCppToC::Wrap(browser));
}
CefHandler::RetVal CefHandlerCToCpp::HandleAddressChange(
CefRefPtr<CefBrowser> browser, const std::wstring& url)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, handle_address_change))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_address_change(struct_, browserPtr->GetStruct(),
return struct_->handle_address_change(struct_,
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
url.c_str());
}
@ -85,69 +76,64 @@ CefHandler::RetVal CefHandlerCToCpp::HandleTitleChange(
if(CEF_MEMBER_MISSING(struct_, handle_title_change))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_title_change(struct_, browserPtr->GetStruct(),
return struct_->handle_title_change(struct_, CefBrowserCppToC::Wrap(browser),
title.c_str());
}
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeBrowse(
CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request,
NavType navType, bool isRedirect)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request, NavType navType, bool isRedirect)
{
if(CEF_MEMBER_MISSING(struct_, handle_before_browse))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
CefRequestCppToC* requestPtr = new CefRequestCppToC(request);
requestPtr->AddRef();
return struct_->handle_before_browse(struct_, browserPtr->GetStruct(),
requestPtr->GetStruct(), navType, isRedirect);
return struct_->handle_before_browse(struct_, CefBrowserCppToC::Wrap(browser),
CefFrameCppToC::Wrap(frame), CefRequestCppToC::Wrap(request),
navType, isRedirect);
}
CefHandler::RetVal CefHandlerCToCpp::HandleLoadStart(
CefRefPtr<CefBrowser> browser)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame)
{
if(CEF_MEMBER_MISSING(struct_, handle_load_start))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
cef_frame_t* frameStruct = NULL;
if(frame.get())
frameStruct = CefFrameCppToC::Wrap(frame);
return struct_->handle_load_start(struct_, browserPtr->GetStruct());
return struct_->handle_load_start(struct_, CefBrowserCppToC::Wrap(browser),
frameStruct);
}
CefHandler::RetVal CefHandlerCToCpp::HandleLoadEnd(
CefRefPtr<CefBrowser> browser)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame)
{
if(CEF_MEMBER_MISSING(struct_, handle_load_end))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
cef_frame_t* frameStruct = NULL;
if(frame.get())
frameStruct = CefFrameCppToC::Wrap(frame);
return struct_->handle_load_end(struct_, browserPtr->GetStruct());
return struct_->handle_load_end(struct_, CefBrowserCppToC::Wrap(browser),
frameStruct);
}
CefHandler::RetVal CefHandlerCToCpp::HandleLoadError(
CefRefPtr<CefBrowser> browser, ErrorCode errorCode,
const std::wstring& failedUrl, std::wstring& errorText)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
ErrorCode errorCode, const std::wstring& failedUrl, std::wstring& errorText)
{
if(CEF_MEMBER_MISSING(struct_, handle_load_error))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
cef_string_t errorTextRet = NULL;
if(!errorText.empty())
errorTextRet = cef_string_alloc(errorText.c_str());
cef_retval_t rv = struct_->handle_load_error(struct_, browserPtr->GetStruct(),
errorCode, failedUrl.c_str(), &errorTextRet);
cef_retval_t rv = struct_->handle_load_error(struct_,
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame), errorCode,
failedUrl.c_str(), &errorTextRet);
transfer_string_contents(errorTextRet, errorText, true);
@ -162,12 +148,6 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeResourceLoad(
if(CEF_MEMBER_MISSING(struct_, handle_before_resource_load))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
CefRequestCppToC* requestPtr = new CefRequestCppToC(request);
requestPtr->AddRef();
cef_string_t redirectUrlRet = NULL;
cef_string_t mimeTypeRet = NULL;
cef_stream_reader_t* streamRet = NULL;
@ -176,18 +156,14 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeResourceLoad(
redirectUrlRet = cef_string_alloc(redirectUrl.c_str());
cef_retval_t rv = struct_->handle_before_resource_load(struct_,
browserPtr->GetStruct(), requestPtr->GetStruct(), &redirectUrlRet,
&streamRet, &mimeTypeRet, loadFlags);
CefBrowserCppToC::Wrap(browser), CefRequestCppToC::Wrap(request),
&redirectUrlRet, &streamRet, &mimeTypeRet, loadFlags);
transfer_string_contents(redirectUrlRet, redirectUrl, true);
transfer_string_contents(mimeTypeRet, mimeType, true);
if(streamRet) {
CefStreamReaderCppToC::Struct* sp =
reinterpret_cast<CefStreamReaderCppToC::Struct*>(streamRet);
resourceStream = sp->class_->GetClass();
sp->class_->Release();
}
if(streamRet)
resourceStream = CefStreamReaderCppToC::Unwrap(streamRet);
return rv;
}
@ -198,10 +174,7 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeMenu(
if(CEF_MEMBER_MISSING(struct_, handle_before_menu))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_before_menu(struct_, browserPtr->GetStruct(),
return struct_->handle_before_menu(struct_, CefBrowserCppToC::Wrap(browser),
&menuInfo);
}
@ -211,15 +184,12 @@ CefHandler::RetVal CefHandlerCToCpp::HandleGetMenuLabel(
if(CEF_MEMBER_MISSING(struct_, handle_get_menu_label))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
cef_string_t labelRet = NULL;
if(!label.empty())
labelRet = cef_string_alloc(label.c_str());
cef_retval_t rv = struct_->handle_get_menu_label(struct_,
browserPtr->GetStruct(), menuId, &labelRet);
CefBrowserCppToC::Wrap(browser), menuId, &labelRet);
transfer_string_contents(labelRet, label, true);
@ -232,25 +202,20 @@ CefHandler::RetVal CefHandlerCToCpp::HandleMenuAction(
if(CEF_MEMBER_MISSING(struct_, handle_menu_action))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_menu_action(struct_, browserPtr->GetStruct(), menuId);
return struct_->handle_menu_action(struct_, CefBrowserCppToC::Wrap(browser),
menuId);
}
CefHandler::RetVal CefHandlerCToCpp::HandlePrintHeaderFooter(
CefRefPtr<CefBrowser> browser, 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,
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> 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)
{
if(CEF_MEMBER_MISSING(struct_, handle_print_header_footer))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
cef_string_t topLeftRet = NULL, topCenterRet = NULL, topRightRet = NULL,
bottomLeftRet = NULL, bottomCenterRet = NULL, bottomRightRet = NULL;
@ -268,9 +233,10 @@ CefHandler::RetVal CefHandlerCToCpp::HandlePrintHeaderFooter(
bottomRightRet = cef_string_alloc(bottomRight.c_str());
cef_retval_t rv = struct_->handle_print_header_footer(struct_,
browserPtr->GetStruct(), &printInfo, url.c_str(), title.c_str(),
currentPage, maxPages, &topLeftRet, &topCenterRet, &topRightRet,
&bottomLeftRet, &bottomCenterRet, &bottomRightRet);
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
&printInfo, url.c_str(), title.c_str(), currentPage, maxPages,
&topLeftRet, &topCenterRet, &topRightRet, &bottomLeftRet,
&bottomCenterRet, &bottomRightRet);
transfer_string_contents(topLeftRet, topLeft, true);
transfer_string_contents(topCenterRet, topCenter, true);
@ -283,50 +249,46 @@ CefHandler::RetVal CefHandlerCToCpp::HandlePrintHeaderFooter(
}
CefHandler::RetVal CefHandlerCToCpp::HandleJSAlert(
CefRefPtr<CefBrowser> browser, const std::wstring& message)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
const std::wstring& message)
{
if(CEF_MEMBER_MISSING(struct_, handle_jsalert))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_jsalert(struct_, browserPtr->GetStruct(),
message.c_str());
return struct_->handle_jsalert(struct_, CefBrowserCppToC::Wrap(browser),
CefFrameCppToC::Wrap(frame), message.c_str());
}
CefHandler::RetVal CefHandlerCToCpp::HandleJSConfirm(
CefRefPtr<CefBrowser> browser, const std::wstring& message, bool& retval)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
const std::wstring& message, bool& retval)
{
if(CEF_MEMBER_MISSING(struct_, handle_jsconfirm))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
int ret = 0;
cef_retval_t rv = struct_->handle_jsconfirm(struct_, browserPtr->GetStruct(),
cef_retval_t rv = struct_->handle_jsconfirm(struct_,
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
message.c_str(), &ret);
retval = (ret ? true : false);
return rv;
}
CefHandler::RetVal CefHandlerCToCpp::HandleJSPrompt(
CefRefPtr<CefBrowser> browser, const std::wstring& message,
const std::wstring& defaultValue, bool& retval, std::wstring& result)
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
const std::wstring& message, const std::wstring& defaultValue, bool& retval,
std::wstring& result)
{
if(CEF_MEMBER_MISSING(struct_, handle_jsprompt))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
cef_string_t resultRet = NULL;
if(!result.empty())
resultRet = cef_string_alloc(result.c_str());
int ret = 0;
cef_retval_t rv = struct_->handle_jsprompt(struct_, browserPtr->GetStruct(),
cef_retval_t rv = struct_->handle_jsprompt(struct_,
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
message.c_str(), defaultValue.c_str(), &ret, &resultRet);
retval = (ret ? true : false);
@ -341,10 +303,8 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeWindowClose(
if(CEF_MEMBER_MISSING(struct_, handle_before_window_close))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_before_window_close(struct_, browserPtr->GetStruct());
return struct_->handle_before_window_close(struct_,
CefBrowserCppToC::Wrap(browser));
}
CefHandler::RetVal CefHandlerCToCpp::HandleTakeFocus(
@ -353,12 +313,21 @@ CefHandler::RetVal CefHandlerCToCpp::HandleTakeFocus(
if(CEF_MEMBER_MISSING(struct_, handle_take_focus))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->handle_take_focus(struct_, CefBrowserCppToC::Wrap(browser),
reverse);
}
return struct_->handle_take_focus(struct_, browserPtr->GetStruct(), reverse);
CefHandler::RetVal CefHandlerCToCpp::HandleJSBinding(
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object)
{
if(CEF_MEMBER_MISSING(struct_, handle_jsbinding))
return RV_CONTINUE;
return struct_->handle_jsbinding(struct_, CefBrowserCppToC::Wrap(browser),
CefFrameCppToC::Wrap(frame), CefV8ValueCppToC::Wrap(object));
}
#ifdef _DEBUG
long CefCToCpp<CefHandler, cef_handler_t>::DebugObjCt = 0;
long CefCToCpp<CefHandlerCToCpp, CefHandler, cef_handler_t>::DebugObjCt = 0;
#endif

View File

@ -16,11 +16,12 @@
// Wrap a C handler structure with a C++ handler class.
// This class may be instantiated and accessed DLL-side only.
class CefHandlerCToCpp : public CefCToCpp<CefHandler, cef_handler_t>
class CefHandlerCToCpp
: public CefCToCpp<CefHandlerCToCpp, CefHandler, cef_handler_t>
{
public:
CefHandlerCToCpp(cef_handler_t* str)
: CefCToCpp<CefHandler, cef_handler_t>(str) {}
: CefCToCpp<CefHandlerCToCpp, CefHandler, cef_handler_t>(str) {}
virtual ~CefHandlerCToCpp() {}
// CefHandler methods
@ -30,15 +31,20 @@ public:
std::wstring& url);
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser);
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& url);
virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser,
const std::wstring& title);
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType, bool isRedirect);
virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser);
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser);
virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame);
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame);
virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const std::wstring& failedUrl,
std::wstring& errorText);
@ -55,6 +61,7 @@ public:
virtual RetVal HandleMenuAction(CefRefPtr<CefBrowser> browser,
MenuId menuId);
virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefPrintInfo& printInfo,
const std::wstring& url,
const std::wstring& title,
@ -66,10 +73,13 @@ public:
std::wstring& bottomCenter,
std::wstring& bottomRight);
virtual RetVal HandleJSAlert(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message);
virtual RetVal HandleJSConfirm(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message, bool& retval);
virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message,
const std::wstring& default_value,
bool& retval,
@ -77,6 +87,9 @@ public:
virtual RetVal HandleBeforeWindowClose(CefRefPtr<CefBrowser> browser);
virtual RetVal HandleTakeFocus(CefRefPtr<CefBrowser> browser,
bool reverse);
virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object);
};

View File

@ -1,106 +0,0 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "../precompiled_libcef.h"
#include "cpptoc/browser_cpptoc.h"
#include "cpptoc/variant_cpptoc.h"
#include "ctocpp/jshandler_ctocpp.h"
bool CefJSHandlerCToCpp::HasMethod(CefRefPtr<CefBrowser> browser,
const std::wstring& name)
{
if(CEF_MEMBER_MISSING(struct_, has_method))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->has_method(struct_, browserPtr->GetStruct(), name.c_str());
}
bool CefJSHandlerCToCpp::HasProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name)
{
if(CEF_MEMBER_MISSING(struct_, has_method))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
return struct_->has_property(struct_, browserPtr->GetStruct(), name.c_str());
}
bool CefJSHandlerCToCpp::SetProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
const CefRefPtr<CefVariant> value)
{
if(CEF_MEMBER_MISSING(struct_, has_method))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
CefVariantCppToC* valuePtr = new CefVariantCppToC(value);
valuePtr->AddRef();
return struct_->set_property(struct_, browserPtr->GetStruct(), name.c_str(),
valuePtr->GetStruct());
}
bool CefJSHandlerCToCpp::GetProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
CefRefPtr<CefVariant> value)
{
if(CEF_MEMBER_MISSING(struct_, has_method))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
CefVariantCppToC* valuePtr = new CefVariantCppToC(value);
valuePtr->AddRef();
return struct_->get_property(struct_, browserPtr->GetStruct(), name.c_str(),
valuePtr->GetStruct());
}
bool CefJSHandlerCToCpp::ExecuteMethod(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
const VariantVector& args,
CefRefPtr<CefVariant> retval)
{
if(CEF_MEMBER_MISSING(struct_, has_method))
return RV_CONTINUE;
CefBrowserCppToC* browserPtr = new CefBrowserCppToC(browser);
browserPtr->AddRef();
CefVariantCppToC* retvalPtr = new CefVariantCppToC(retval);
retvalPtr->AddRef();
cef_variant_t** argsStructPtr = NULL;
int argsSize = args.size();
if(argsSize > 0) {
CefVariantCppToC* vPtr;
argsStructPtr = new cef_variant_t*[argsSize];
for(int i = 0; i < argsSize; ++i) {
vPtr = new CefVariantCppToC(args[i]);
vPtr->AddRef();
argsStructPtr[i] = vPtr->GetStruct();
}
}
int rv = struct_->execute_method(struct_, browserPtr->GetStruct(),
name.c_str(), argsSize, argsStructPtr, retvalPtr->GetStruct());
if(argsStructPtr)
delete [] argsStructPtr;
return rv;
}
#ifdef _DEBUG
long CefCToCpp<CefJSHandler, cef_jshandler_t>::DebugObjCt = 0;
#endif

View File

@ -1,45 +0,0 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _JSHANDLER_CTOCPP_H
#define _JSHANDLER_CTOCPP_H
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "ctocpp.h"
// Wrap a C jshandler structure with a C++ jshandler class.
// This class may be instantiated and accessed DLL-side only.
class CefJSHandlerCToCpp : public CefCToCpp<CefJSHandler, cef_jshandler_t>
{
public:
CefJSHandlerCToCpp(cef_jshandler_t* str)
: CefCToCpp<CefJSHandler, cef_jshandler_t>(str) {}
virtual ~CefJSHandlerCToCpp() {}
// CefJSHandler methods
virtual bool HasMethod(CefRefPtr<CefBrowser> browser,
const std::wstring& name);
virtual bool HasProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name);
virtual bool SetProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
const CefRefPtr<CefVariant> value);
virtual bool GetProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
CefRefPtr<CefVariant> value);
virtual bool ExecuteMethod(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
const VariantVector& args,
CefRefPtr<CefVariant> retval);
};
#endif // BUILDING_CEF_SHARED
#endif // _JSHANDLER_CTOCPP_H

View File

@ -28,28 +28,6 @@ void CefRequestCToCpp::SetURL(const std::wstring& url)
struct_->set_url(struct_, url.c_str());
}
std::wstring CefRequestCToCpp::GetFrame()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_frame))
return str;
cef_string_t cef_str = struct_->get_frame(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
void CefRequestCToCpp::SetFrame(const std::wstring& frame)
{
if(CEF_MEMBER_MISSING(struct_, set_frame))
return;
struct_->set_frame(struct_, frame.c_str());
}
std::wstring CefRequestCToCpp::GetMethod()
{
std::wstring str;
@ -78,14 +56,9 @@ CefRefPtr<CefPostData> CefRequestCToCpp::GetPostData()
return NULL;
cef_post_data_t* postDataStruct = struct_->get_post_data(struct_);
if(!postDataStruct)
return NULL;
CefPostDataCToCpp* pdp = new CefPostDataCToCpp(postDataStruct);
CefRefPtr<CefPostData> postDataPtr(pdp);
pdp->UnderlyingRelease();
return postDataPtr;
if(postDataStruct)
return CefPostDataCToCpp::Wrap(postDataStruct);
return NULL;
}
void CefRequestCToCpp::SetPostData(CefRefPtr<CefPostData> postData)
@ -94,11 +67,9 @@ void CefRequestCToCpp::SetPostData(CefRefPtr<CefPostData> postData)
return;
cef_post_data_t* postDataStruct = NULL;
if(postData.get()) {
CefPostDataCToCpp* pdp = static_cast<CefPostDataCToCpp*>(postData.get());
pdp->UnderlyingAddRef();
postDataStruct = pdp->GetStruct();
}
if(postData.get())
postDataStruct = CefPostDataCToCpp::Unwrap(postData);
struct_->set_post_data(struct_, postDataStruct);
}
@ -136,7 +107,6 @@ void CefRequestCToCpp::SetHeaderMap(const HeaderMap& headerMap)
}
void CefRequestCToCpp::Set(const std::wstring& url,
const std::wstring& frame,
const std::wstring& method,
CefRefPtr<CefPostData> postData,
const HeaderMap& headerMap)
@ -145,11 +115,8 @@ void CefRequestCToCpp::Set(const std::wstring& url,
return;
cef_post_data_t* postDataStruct = NULL;
if(postData.get()) {
CefPostDataCToCpp* pdp = static_cast<CefPostDataCToCpp*>(postData.get());
pdp->UnderlyingAddRef();
postDataStruct = pdp->GetStruct();
}
if(postData.get())
postDataStruct = CefPostDataCToCpp::Unwrap(postData);
cef_string_map_t map = NULL;
if(!headerMap.empty()) {
@ -159,15 +126,14 @@ void CefRequestCToCpp::Set(const std::wstring& url,
transfer_string_map_contents(headerMap, map);
}
struct_->set(struct_, url.c_str(), frame.c_str(), method.c_str(),
postDataStruct, map);
struct_->set(struct_, url.c_str(), method.c_str(), postDataStruct, map);
if(map)
cef_string_map_free(map);
}
#ifdef _DEBUG
long CefCToCpp<CefRequest, cef_request_t>::DebugObjCt = 0;
long CefCToCpp<CefRequestCToCpp, CefRequest, cef_request_t>::DebugObjCt = 0;
#endif
@ -188,16 +154,10 @@ void CefPostDataCToCpp::GetElements(ElementVector& elements)
int count = (int)GetElementCount();
cef_post_data_element_t* structPtr;
CefPostDataElementCToCpp* pdep;
for(int i = 0; i < count; ++i) {
structPtr = struct_->get_element(struct_, i);
if(!structPtr)
continue;
pdep = new CefPostDataElementCToCpp(structPtr);
CefRefPtr<CefPostDataElement> elementPtr(pdep);
pdep->UnderlyingRelease();
elements.push_back(elementPtr);
if(structPtr)
elements.push_back(CefPostDataElementCToCpp::Wrap(structPtr));
}
}
@ -207,10 +167,8 @@ bool CefPostDataCToCpp::RemoveElement(CefRefPtr<CefPostDataElement> element)
if(CEF_MEMBER_MISSING(struct_, remove_element) || !element.get())
return false;
CefPostDataElementCToCpp* pdep =
static_cast<CefPostDataElementCToCpp*>(element.get());
pdep->UnderlyingAddRef();
return struct_->remove_element(struct_, pdep->GetStruct());
return struct_->remove_element(struct_,
CefPostDataElementCToCpp::Unwrap(element));
}
bool CefPostDataCToCpp::AddElement(CefRefPtr<CefPostDataElement> element)
@ -219,10 +177,8 @@ bool CefPostDataCToCpp::AddElement(CefRefPtr<CefPostDataElement> element)
if(CEF_MEMBER_MISSING(struct_, add_element) || !element.get())
return false;
CefPostDataElementCToCpp* pdep =
static_cast<CefPostDataElementCToCpp*>(element.get());
pdep->UnderlyingAddRef();
return struct_->add_element(struct_, pdep->GetStruct());
return struct_->add_element(struct_,
CefPostDataElementCToCpp::Unwrap(element));
}
void CefPostDataCToCpp::RemoveElements()
@ -234,7 +190,7 @@ void CefPostDataCToCpp::RemoveElements()
}
#ifdef _DEBUG
long CefCToCpp<CefPostData, cef_post_data_t>::DebugObjCt = 0;
long CefCToCpp<CefPostDataCToCpp, CefPostData, cef_post_data_t>::DebugObjCt = 0;
#endif
@ -302,5 +258,6 @@ size_t CefPostDataElementCToCpp::GetBytes(size_t size, void *bytes)
}
#ifdef _DEBUG
long CefCToCpp<CefPostDataElement, cef_post_data_element_t>::DebugObjCt = 0;
long CefCToCpp<CefPostDataElementCToCpp, CefPostDataElement,
cef_post_data_element_t>::DebugObjCt = 0;
#endif

View File

@ -16,18 +16,17 @@
// Wrap a C request structure with a C++ request class.
// This class may be instantiated and accessed wrapper-side only.
class CefRequestCToCpp : public CefCToCpp<CefRequest, cef_request_t>
class CefRequestCToCpp
: public CefCToCpp<CefRequestCToCpp, CefRequest, cef_request_t>
{
public:
CefRequestCToCpp(cef_request_t* str)
: CefCToCpp<CefRequest, cef_request_t>(str) {}
: CefCToCpp<CefRequestCToCpp, CefRequest, cef_request_t>(str) {}
virtual ~CefRequestCToCpp() {}
// CefRequest methods
virtual std::wstring GetURL();
virtual void SetURL(const std::wstring& url);
virtual std::wstring GetFrame();
virtual void SetFrame(const std::wstring& url);
virtual std::wstring GetMethod();
virtual void SetMethod(const std::wstring& method);
virtual CefRefPtr<CefPostData> GetPostData();
@ -35,7 +34,6 @@ public:
virtual void GetHeaderMap(HeaderMap& headerMap);
virtual void SetHeaderMap(const HeaderMap& headerMap);
virtual void Set(const std::wstring& url,
const std::wstring& frame,
const std::wstring& method,
CefRefPtr<CefPostData> postData,
const HeaderMap& headerMap);
@ -44,11 +42,12 @@ public:
// Wrap a C post data structure with a C++ post data class.
// This class may be instantiated and accessed wrapper-side only.
class CefPostDataCToCpp : public CefCToCpp<CefPostData, cef_post_data_t>
class CefPostDataCToCpp
: public CefCToCpp<CefPostDataCToCpp, CefPostData, cef_post_data_t>
{
public:
CefPostDataCToCpp(cef_post_data_t* str)
: CefCToCpp<CefPostData, cef_post_data_t>(str) {}
: CefCToCpp<CefPostDataCToCpp, CefPostData, cef_post_data_t>(str) {}
virtual ~CefPostDataCToCpp() {}
// CefPostData methods
@ -62,12 +61,14 @@ public:
// Wrap a C post data element structure with a C++ post data element class.
// This class may be instantiated and accessed wrapper-side only.
class CefPostDataElementCToCpp :
public CefCToCpp<CefPostDataElement, cef_post_data_element_t>
class CefPostDataElementCToCpp
: public CefCToCpp<CefPostDataElementCToCpp, CefPostDataElement,
cef_post_data_element_t>
{
public:
CefPostDataElementCToCpp(cef_post_data_element_t* str)
: CefCToCpp<CefPostDataElement, cef_post_data_element_t>(str) {}
: CefCToCpp<CefPostDataElementCToCpp, CefPostDataElement,
cef_post_data_element_t>(str) {}
virtual ~CefPostDataElementCToCpp() {}
// CefPostDataElement methods

View File

@ -39,7 +39,8 @@ int CefStreamReaderCToCpp::Eof()
}
#ifdef _DEBUG
long CefCToCpp<CefStreamReader, cef_stream_reader_t>::DebugObjCt = 0;
long CefCToCpp<CefStreamReaderCToCpp, CefStreamReader,
cef_stream_reader_t>::DebugObjCt = 0;
#endif
@ -76,5 +77,6 @@ int CefStreamWriterCToCpp::Flush()
}
#ifdef _DEBUG
long CefCToCpp<CefStreamWriter, cef_stream_writer_t>::DebugObjCt = 0;
long CefCToCpp<CefStreamWriterCToCpp, CefStreamWriter,
cef_stream_writer_t>::DebugObjCt = 0;
#endif

View File

@ -16,12 +16,14 @@
// Wrap a C stream reader structure with a C++ stream reader class.
// This class may be instantiated and accessed wrapper-side only.
class CefStreamReaderCToCpp :
public CefCToCpp<CefStreamReader, cef_stream_reader_t>
class CefStreamReaderCToCpp
: public CefCToCpp<CefStreamReaderCToCpp, CefStreamReader,
cef_stream_reader_t>
{
public:
CefStreamReaderCToCpp(cef_stream_reader_t* str)
: CefCToCpp<CefStreamReader, cef_stream_reader_t>(str) {}
: CefCToCpp<CefStreamReaderCToCpp, CefStreamReader,
cef_stream_reader_t>(str) {}
virtual ~CefStreamReaderCToCpp() {}
// CefStreamReader methods
@ -34,12 +36,14 @@ public:
// Wrap a C stream writer structure with a C++ stream writer class.
// This class may be instantiated and accessed wrapper-side only.
class CefStreamWriterCToCpp :
public CefCToCpp<CefStreamWriter, cef_stream_writer_t>
class CefStreamWriterCToCpp
: public CefCToCpp<CefStreamWriterCToCpp, CefStreamWriter,
cef_stream_writer_t>
{
public:
CefStreamWriterCToCpp(cef_stream_writer_t* str)
: CefCToCpp<CefStreamWriter, cef_stream_writer_t>(str) {}
: CefCToCpp<CefStreamWriterCToCpp, CefStreamWriter,
cef_stream_writer_t>(str) {}
virtual ~CefStreamWriterCToCpp() {}
// CefStreamWriter methods

View File

@ -0,0 +1,49 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "../precompiled_libcef.h"
#include "ctocpp/v8handler_ctocpp.h"
#include "cpptoc/v8value_cpptoc.h"
bool CefV8HandlerCToCpp::Execute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
if(CEF_MEMBER_MISSING(struct_, execute))
return RV_CONTINUE;
cef_v8value_t** argsStructPtr = NULL;
int argsSize = arguments.size();
if(argsSize > 0) {
argsStructPtr = new cef_v8value_t*[argsSize];
for(int i = 0; i < argsSize; ++i)
argsStructPtr[i] = CefV8ValueCppToC::Wrap(arguments[i]);
}
cef_v8value_t* retvalStruct = NULL;
cef_string_t exceptionStr = NULL;
int rv = struct_->execute(struct_, name.c_str(),
CefV8ValueCppToC::Wrap(object), argsSize, argsStructPtr, &retvalStruct,
&exceptionStr);
if(retvalStruct)
retval = CefV8ValueCppToC::Unwrap(retvalStruct);
if(exceptionStr) {
exception = exceptionStr;
cef_string_free(exceptionStr);
}
if(argsStructPtr)
delete [] argsStructPtr;
return rv;
}
#ifdef _DEBUG
long CefCToCpp<CefV8HandlerCToCpp, CefV8Handler, cef_v8handler_t>::DebugObjCt
= 0;
#endif

View File

@ -0,0 +1,37 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _V8HANDLER_CTOCPP_H
#define _V8HANDLER_CTOCPP_H
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "ctocpp.h"
// Wrap a C v8handler structure with a C++ v8handler class.
// This class may be instantiated and accessed DLL-side only.
class CefV8HandlerCToCpp
: public CefCToCpp<CefV8HandlerCToCpp, CefV8Handler, cef_v8handler_t>
{
public:
CefV8HandlerCToCpp(cef_v8handler_t* str)
: CefCToCpp<CefV8HandlerCToCpp, CefV8Handler, cef_v8handler_t>(str) {}
virtual ~CefV8HandlerCToCpp() {}
// CefV8Handler methods
virtual bool Execute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception);
};
#endif // BUILDING_CEF_SHARED
#endif // _V8HANDLER_CTOCPP_H

View File

@ -0,0 +1,293 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "../precompiled_libcef.h"
#include "cpptoc/v8handler_cpptoc.h"
#include "ctocpp/v8value_ctocpp.h"
bool CefV8ValueCToCpp::IsUndefined()
{
if(CEF_MEMBER_MISSING(struct_, is_undefined))
return false;
return struct_->is_undefined(struct_);
}
bool CefV8ValueCToCpp::IsNull()
{
if(CEF_MEMBER_MISSING(struct_, is_null))
return false;
return struct_->is_null(struct_);
}
bool CefV8ValueCToCpp::IsBool()
{
if(CEF_MEMBER_MISSING(struct_, is_bool))
return false;
return struct_->is_bool(struct_);
}
bool CefV8ValueCToCpp::IsInt()
{
if(CEF_MEMBER_MISSING(struct_, is_int))
return false;
return struct_->is_int(struct_);
}
bool CefV8ValueCToCpp::IsDouble()
{
if(CEF_MEMBER_MISSING(struct_, is_double))
return false;
return struct_->is_double(struct_);
}
bool CefV8ValueCToCpp::IsString()
{
if(CEF_MEMBER_MISSING(struct_, is_string))
return false;
return struct_->is_string(struct_);
}
bool CefV8ValueCToCpp::IsObject()
{
if(CEF_MEMBER_MISSING(struct_, is_object))
return false;
return struct_->is_object(struct_);
}
bool CefV8ValueCToCpp::IsArray()
{
if(CEF_MEMBER_MISSING(struct_, is_array))
return false;
return struct_->is_array(struct_);
}
bool CefV8ValueCToCpp::IsFunction()
{
if(CEF_MEMBER_MISSING(struct_, is_function))
return false;
return struct_->is_function(struct_);
}
bool CefV8ValueCToCpp::GetBoolValue()
{
if(CEF_MEMBER_MISSING(struct_, get_bool_value))
return false;
return struct_->get_bool_value(struct_);
}
int CefV8ValueCToCpp::GetIntValue()
{
if(CEF_MEMBER_MISSING(struct_, get_int_value))
return 0;
return struct_->get_int_value(struct_);
}
double CefV8ValueCToCpp::GetDoubleValue()
{
if(CEF_MEMBER_MISSING(struct_, get_double_value))
return 0.;
return struct_->get_double_value(struct_);
}
std::wstring CefV8ValueCToCpp::GetStringValue()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_string_value))
return str;
cef_string_t cef_str = struct_->get_string_value(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
bool CefV8ValueCToCpp::HasValue(const std::wstring& key)
{
if(CEF_MEMBER_MISSING(struct_, has_value_bykey))
return false;
return struct_->has_value_bykey(struct_, key.c_str());
}
bool CefV8ValueCToCpp::HasValue(int index)
{
if(CEF_MEMBER_MISSING(struct_, has_value_byindex))
return false;
return struct_->has_value_byindex(struct_, index);
}
bool CefV8ValueCToCpp::DeleteValue(const std::wstring& key)
{
if(CEF_MEMBER_MISSING(struct_, delete_value_bykey))
return false;
return struct_->delete_value_bykey(struct_, key.c_str());
}
bool CefV8ValueCToCpp::DeleteValue(int index)
{
if(CEF_MEMBER_MISSING(struct_, delete_value_byindex))
return false;
return struct_->delete_value_byindex(struct_, index);
}
CefRefPtr<CefV8Value> CefV8ValueCToCpp::GetValue(const std::wstring& key)
{
if(CEF_MEMBER_MISSING(struct_, get_value_bykey))
return false;
cef_v8value_t* valueStruct = struct_->get_value_bykey(struct_, key.c_str());
if(valueStruct)
return CefV8ValueCToCpp::Wrap(valueStruct);
return NULL;
}
CefRefPtr<CefV8Value> CefV8ValueCToCpp::GetValue(int index)
{
if(CEF_MEMBER_MISSING(struct_, get_value_byindex))
return false;
cef_v8value_t* valueStruct = struct_->get_value_byindex(struct_, index);
if(valueStruct)
return CefV8ValueCToCpp::Wrap(valueStruct);
return NULL;
}
bool CefV8ValueCToCpp::SetValue(const std::wstring& key, CefRefPtr<CefV8Value> value)
{
if(CEF_MEMBER_MISSING(struct_, set_value_bykey))
return false;
return struct_->set_value_bykey(struct_, key.c_str(),
CefV8ValueCToCpp::Unwrap(value));
}
bool CefV8ValueCToCpp::SetValue(int index, CefRefPtr<CefV8Value> value)
{
if(CEF_MEMBER_MISSING(struct_, set_value_byindex))
return false;
return struct_->set_value_byindex(struct_, index,
CefV8ValueCToCpp::Unwrap(value));
}
bool CefV8ValueCToCpp::GetKeys(std::vector<std::wstring>& keys)
{
if(CEF_MEMBER_MISSING(struct_, get_keys))
return false;
cef_string_list_t list = cef_string_list_alloc();
if(struct_->get_keys(struct_, list)) {
cef_string_t str;
int size = cef_string_list_size(list);
for(int i = 0; i < size; ++i) {
str = cef_string_list_value(list, i);
keys.push_back(str);
cef_string_free(str);
}
cef_string_list_free(list);
return true;
}
return false;
}
CefRefPtr<CefBase> CefV8ValueCToCpp::GetUserData()
{
if(CEF_MEMBER_MISSING(struct_, get_user_data))
return false;
cef_base_t* baseStruct = struct_->get_user_data(struct_);
if(baseStruct)
return CefBaseCppToC::Unwrap(baseStruct);
return NULL;
}
int CefV8ValueCToCpp::GetArrayLength()
{
if(CEF_MEMBER_MISSING(struct_, get_array_length))
return 0;
return struct_->get_array_length(struct_);
}
std::wstring CefV8ValueCToCpp::GetFunctionName()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_function_name))
return str;
cef_string_t cef_str = struct_->get_function_name(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
CefRefPtr<CefV8Handler> CefV8ValueCToCpp::GetFunctionHandler()
{
if(CEF_MEMBER_MISSING(struct_, get_function_handler))
return false;
cef_v8handler_t* handlerStruct = struct_->get_function_handler(struct_);
if(handlerStruct)
return CefV8HandlerCppToC::Unwrap(handlerStruct);
return NULL;
}
bool CefV8ValueCToCpp::ExecuteFunction(CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
if(CEF_MEMBER_MISSING(struct_, execute_function))
return RV_CONTINUE;
cef_v8value_t** argsStructPtr = NULL;
int argsSize = arguments.size();
if(argsSize > 0) {
argsStructPtr = new cef_v8value_t*[argsSize];
for(int i = 0; i < argsSize; ++i)
argsStructPtr[i] = CefV8ValueCToCpp::Unwrap(arguments[i]);
}
cef_v8value_t* retvalStruct = NULL;
cef_string_t exceptionStr = NULL;
int rv = struct_->execute_function(struct_, CefV8ValueCToCpp::Unwrap(object),
argsSize, argsStructPtr, &retvalStruct, &exceptionStr);
if(retvalStruct)
retval = CefV8ValueCToCpp::Wrap(retvalStruct);
if(exceptionStr) {
exception = exceptionStr;
cef_string_free(exceptionStr);
}
if(argsStructPtr)
delete [] argsStructPtr;
return rv;
}
#ifdef _DEBUG
long CefCToCpp<CefV8ValueCToCpp, CefV8Value, cef_v8value_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,62 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _V8VALUE_CTOCPP_H
#define _V8VALUE_CTOCPP_H
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "ctocpp.h"
// Wrap a C v8value structure with a C++ v8value class.
// This class may be instantiated and accessed DLL-side only.
class CefV8ValueCToCpp
: public CefCToCpp<CefV8ValueCToCpp, CefV8Value, cef_v8value_t>
{
public:
CefV8ValueCToCpp(cef_v8value_t* str)
: CefCToCpp<CefV8ValueCToCpp, CefV8Value, cef_v8value_t>(str) {}
virtual ~CefV8ValueCToCpp() {}
// CefV8Value methods
virtual bool IsUndefined();
virtual bool IsNull();
virtual bool IsBool();
virtual bool IsInt();
virtual bool IsDouble();
virtual bool IsString();
virtual bool IsObject();
virtual bool IsArray();
virtual bool IsFunction();
virtual bool GetBoolValue();
virtual int GetIntValue();
virtual double GetDoubleValue();
virtual std::wstring GetStringValue();
virtual bool HasValue(const std::wstring& key);
virtual bool HasValue(int index);
virtual bool DeleteValue(const std::wstring& key);
virtual bool DeleteValue(int index);
virtual CefRefPtr<CefV8Value> GetValue(const std::wstring& key);
virtual CefRefPtr<CefV8Value> GetValue(int index);
virtual bool SetValue(const std::wstring& key, CefRefPtr<CefV8Value> value);
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value);
virtual bool GetKeys(std::vector<std::wstring>& keys);
virtual CefRefPtr<CefBase> GetUserData();
virtual int GetArrayLength();
virtual std::wstring GetFunctionName();
virtual CefRefPtr<CefV8Handler> GetFunctionHandler();
virtual bool ExecuteFunction(CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception);
};
#endif // USING_CEF_SHARED
#endif // _V8VALUE_CTOCPP_H

View File

@ -1,300 +0,0 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "../precompiled_libcef.h"
#include "ctocpp/variant_ctocpp.h"
CefVariant::Type CefVariantCToCpp::GetType()
{
if(CEF_MEMBER_MISSING(struct_, get_type))
return VARIANT_TYPE_NULL;
return struct_->get_type(struct_);
}
void CefVariantCToCpp::SetNull()
{
if(CEF_MEMBER_MISSING(struct_, set_null))
return;
return struct_->set_null(struct_);
}
void CefVariantCToCpp::SetBool(bool val)
{
if(CEF_MEMBER_MISSING(struct_, set_bool))
return;
return struct_->set_bool(struct_, val);
}
void CefVariantCToCpp::SetInt(int val)
{
if(CEF_MEMBER_MISSING(struct_, set_int))
return;
return struct_->set_int(struct_, val);
}
void CefVariantCToCpp::SetDouble(double val)
{
if(CEF_MEMBER_MISSING(struct_, set_double))
return;
return struct_->set_double(struct_, val);
}
void CefVariantCToCpp::SetString(const std::wstring& val)
{
if(CEF_MEMBER_MISSING(struct_, set_string))
return;
return struct_->set_string(struct_, val.c_str());
}
void CefVariantCToCpp::SetBoolArray(const std::vector<bool>& val)
{
if(CEF_MEMBER_MISSING(struct_, set_bool_array))
return;
int valSize = (int)val.size();
int* valArray = NULL;
if(valSize > 0) {
valArray = new int[valSize];
if(!valArray)
return;
for(int i = 0; i < valSize; ++i) {
valArray[i] = val[i];
}
}
struct_->set_bool_array(struct_, valSize, valArray);
if(valArray)
delete [] valArray;
}
void CefVariantCToCpp::SetIntArray(const std::vector<int>& val)
{
if(CEF_MEMBER_MISSING(struct_, set_int_array))
return;
int valSize = (int)val.size();
int* valArray = NULL;
if(valSize > 0) {
valArray = new int[valSize];
if(!valArray)
return;
for(int i = 0; i < valSize; ++i) {
valArray[i] = val[i];
}
}
struct_->set_int_array(struct_, valSize, valArray);
if(valArray)
delete [] valArray;
}
void CefVariantCToCpp::SetDoubleArray(const std::vector<double>& val)
{
if(CEF_MEMBER_MISSING(struct_, set_double_array))
return;
int valSize = (int)val.size();
double* valArray = NULL;
if(valSize > 0) {
valArray = new double[valSize];
if(!valArray)
return;
for(int i = 0; i < valSize; ++i) {
valArray[i] = val[i];
}
}
struct_->set_double_array(struct_, valSize, valArray);
if(valArray)
delete [] valArray;
}
void CefVariantCToCpp::SetStringArray(const std::vector<std::wstring>& val)
{
if(CEF_MEMBER_MISSING(struct_, set_string_array))
return;
int valSize = (int)val.size();
cef_string_t* valArray = NULL;
if(valSize > 0) {
valArray = new cef_string_t[valSize];
if(!valArray)
return;
for(int i = 0; i < valSize; ++i) {
valArray[i] = cef_string_alloc(val[i].c_str());
}
}
struct_->set_string_array(struct_, valSize, valArray);
if(valArray) {
for(int i = 0; i < valSize; ++i) {
cef_string_free(valArray[i]);
}
delete [] valArray;
}
}
bool CefVariantCToCpp::GetBool()
{
if(CEF_MEMBER_MISSING(struct_, get_bool))
return false;
return struct_->get_bool(struct_);
}
int CefVariantCToCpp::GetInt()
{
if(CEF_MEMBER_MISSING(struct_, get_int))
return 0;
return struct_->get_int(struct_);
}
double CefVariantCToCpp::GetDouble()
{
if(CEF_MEMBER_MISSING(struct_, get_double))
return 0;
return struct_->get_double(struct_);
}
std::wstring CefVariantCToCpp::GetString()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_string))
return str;
cef_string_t cef_str = struct_->get_string(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
bool CefVariantCToCpp::GetBoolArray(std::vector<bool>& val)
{
if(CEF_MEMBER_MISSING(struct_, get_bool_array))
return false;
int valSize = GetArraySize();
if(valSize < 0)
return false;
if(valSize == 0)
return true;
int* valArray = new int[valSize];
if(!valArray)
return false;
bool rv = struct_->get_bool_array(struct_, valSize, valArray);
if(rv) {
for(int i = 0; i < valSize; ++i)
val.push_back(valArray[i] ? true : false);
}
delete [] valArray;
return rv;
}
bool CefVariantCToCpp::GetIntArray(std::vector<int>& val)
{
if(CEF_MEMBER_MISSING(struct_, get_int_array))
return false;
int valSize = GetArraySize();
if(valSize < 0)
return false;
if(valSize == 0)
return true;
int* valArray = new int[valSize];
if(!valArray)
return false;
bool rv = struct_->get_int_array(struct_, valSize, valArray);
if(rv) {
for(int i = 0; i < valSize; ++i)
val.push_back(valArray[i]);
}
delete [] valArray;
return rv;
}
bool CefVariantCToCpp::GetDoubleArray(std::vector<double>& val)
{
if(CEF_MEMBER_MISSING(struct_, get_double_array))
return false;
int valSize = GetArraySize();
if(valSize < 0)
return false;
if(valSize == 0)
return true;
double* valArray = new double[valSize];
if(!valArray)
return false;
bool rv = struct_->get_double_array(struct_, valSize, valArray);
if(rv) {
for(int i = 0; i < valSize; ++i)
val.push_back(valArray[i]);
}
delete [] valArray;
return rv;
}
bool CefVariantCToCpp::GetStringArray(std::vector<std::wstring>& val)
{
if(CEF_MEMBER_MISSING(struct_, get_string_array))
return false;
int valSize = GetArraySize();
if(valSize < 0)
return false;
if(valSize == 0)
return true;
cef_string_t* valArray = new cef_string_t[valSize];
if(!valArray)
return false;
bool rv = struct_->get_string_array(struct_, valSize, valArray);
if(rv) {
for(int i = 0; i < valSize; ++i) {
val.push_back(valArray[i]);
cef_string_free(valArray[i]);
}
}
delete [] valArray;
return rv;
}
int CefVariantCToCpp::GetArraySize()
{
if(CEF_MEMBER_MISSING(struct_, get_array_size))
return -1;
return struct_->get_array_size(struct_);
}
#ifdef _DEBUG
long CefCToCpp<CefVariant, cef_variant_t>::DebugObjCt = 0;
#endif

View File

@ -1,50 +0,0 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _VARIANT_CTOCPP_H
#define _VARIANT_CTOCPP_H
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "ctocpp.h"
// Wrap a C variant structure with a C++ variant class.
// This class may be instantiated and accessed wrapper-side only.
class CefVariantCToCpp : public CefCToCpp<CefVariant, cef_variant_t>
{
public:
CefVariantCToCpp(cef_variant_t* str)
: CefCToCpp<CefVariant, cef_variant_t>(str) {}
virtual ~CefVariantCToCpp() {}
// CefVariant methods
virtual Type GetType();
virtual void SetNull();
virtual void SetBool(bool val);
virtual void SetInt(int val);
virtual void SetDouble(double val);
virtual void SetString(const std::wstring& val);
virtual void SetBoolArray(const std::vector<bool>& val);
virtual void SetIntArray(const std::vector<int>& val);
virtual void SetDoubleArray(const std::vector<double>& val);
virtual void SetStringArray(const std::vector<std::wstring>& val);
virtual bool GetBool();
virtual int GetInt();
virtual double GetDouble();
virtual std::wstring GetString();
virtual bool GetBoolArray(std::vector<bool>& val);
virtual bool GetIntArray(std::vector<int>& val);
virtual bool GetDoubleArray(std::vector<double>& val);
virtual bool GetStringArray(std::vector<std::wstring>& val);
virtual int GetArraySize();
};
#endif // USING_CEF_SHARED
#endif // _VARIANT_CTOCPP_H

View File

@ -10,10 +10,10 @@
#include "cef_nplugin_capi.h"
#include "cpptoc/browser_cpptoc.h"
#include "cpptoc/request_cpptoc.h"
#include "cpptoc/variant_cpptoc.h"
#include "cpptoc/stream_cpptoc.h"
#include "cpptoc/v8value_cpptoc.h"
#include "ctocpp/handler_ctocpp.h"
#include "ctocpp/jshandler_ctocpp.h"
#include "ctocpp/v8handler_ctocpp.h"
#include "base/string_util.h"
@ -38,9 +38,9 @@ CEF_EXPORT void cef_shutdown()
DCHECK(CefPostDataElementCppToC::DebugObjCt == 0);
DCHECK(CefStreamReaderCppToC::DebugObjCt == 0);
DCHECK(CefStreamWriterCppToC::DebugObjCt == 0);
DCHECK(CefVariantCppToC::DebugObjCt == 0);
DCHECK(CefV8ValueCppToC::DebugObjCt == 0);
DCHECK(CefHandlerCToCpp::DebugObjCt == 0);
DCHECK(CefJSHandlerCToCpp::DebugObjCt == 0);
DCHECK(CefV8HandlerCToCpp::DebugObjCt == 0);
#endif // _DEBUG
}
@ -49,6 +49,26 @@ CEF_EXPORT void cef_do_message_loop_work()
CefDoMessageLoopWork();
}
CEF_EXPORT int cef_register_extension(const wchar_t* extension_name,
const wchar_t* javascript_code,
struct _cef_v8handler_t* handler)
{
DCHECK(extension_name);
DCHECK(javascript_code);
CefRefPtr<CefV8Handler> handlerPtr;
std::wstring nameStr, codeStr;
if(handler)
handlerPtr = CefV8HandlerCToCpp::Wrap(handler);
if(extension_name)
nameStr = extension_name;
if(javascript_code)
codeStr = javascript_code;
return CefRegisterExtension(nameStr, codeStr, handlerPtr);
}
CEF_EXPORT int cef_create_browser(cef_window_info_t* windowInfo, int popup,
cef_handler_t* handler, const wchar_t* url)
{
@ -58,11 +78,8 @@ CEF_EXPORT int cef_create_browser(cef_window_info_t* windowInfo, int popup,
std::wstring urlStr;
CefWindowInfo wi = *windowInfo;
if(handler) {
CefHandlerCToCpp* hp = new CefHandlerCToCpp(handler);
handlerPtr = hp;
hp->UnderlyingRelease();
}
if(handler)
handlerPtr = CefHandlerCToCpp::Wrap(handler);
if(url)
urlStr = url;
@ -80,54 +97,41 @@ CEF_EXPORT cef_browser_t* cef_create_browser_sync(cef_window_info_t* windowInfo,
std::wstring urlStr;
CefWindowInfo wi = *windowInfo;
if(handler) {
CefHandlerCToCpp* hp = new CefHandlerCToCpp(handler);
handlerPtr = hp;
hp->UnderlyingRelease();
}
if(handler)
handlerPtr = CefHandlerCToCpp::Wrap(handler);
if(url)
urlStr = url;
cef_browser_t* browserStruct = NULL;
CefRefPtr<CefBrowser> browserPtr(
CefBrowser::CreateBrowserSync(wi, popup, handlerPtr, urlStr));
if(!browserPtr.get())
return NULL;
CefBrowserCppToC* bp = new CefBrowserCppToC(browserPtr);
bp->AddRef();
return bp->GetStruct();
if(browserPtr.get())
return CefBrowserCppToC::Wrap(browserPtr);
return NULL;
}
CEF_EXPORT cef_request_t* cef_create_request()
{
CefRefPtr<CefRequest> impl = CefRequest::CreateRequest();
if(!impl.get())
return NULL;
CefRequestCppToC* rp = new CefRequestCppToC(impl);
rp->AddRef();
return rp->GetStruct();
if(impl.get())
return CefRequestCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_post_data_t* cef_create_post_data()
{
CefRefPtr<CefPostData> impl = CefPostData::CreatePostData();
if(!impl.get())
return NULL;
CefPostDataCppToC* rp = new CefPostDataCppToC(impl);
rp->AddRef();
return rp->GetStruct();
if(impl.get())
return CefPostDataCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_post_data_element_t* cef_create_post_data_element()
{
CefRefPtr<CefPostDataElement> impl =
CefPostDataElement::CreatePostDataElement();
if(!impl.get())
return NULL;
CefPostDataElementCppToC* rp = new CefPostDataElementCppToC(impl);
rp->AddRef();
return rp->GetStruct();
if(impl.get())
return CefPostDataElementCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_stream_reader_t* cef_create_stream_reader_for_file(
@ -137,22 +141,106 @@ CEF_EXPORT cef_stream_reader_t* cef_create_stream_reader_for_file(
if(fileName)
filenamestr = fileName;
CefRefPtr<CefStreamReader> impl = CefStreamReader::CreateForFile(filenamestr);
if(!impl.get())
return NULL;
CefStreamReaderCppToC* rp = new CefStreamReaderCppToC(impl);
rp->AddRef();
return rp->GetStruct();
if(impl.get())
return CefStreamReaderCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_stream_reader_t* cef_create_stream_reader_for_data(void *data,
size_t size)
{
CefRefPtr<CefStreamReader> impl = CefStreamReader::CreateForData(data, size);
if(!impl.get())
return NULL;
CefStreamReaderCppToC* rp = new CefStreamReaderCppToC(impl);
rp->AddRef();
return rp->GetStruct();
if(impl.get())
return CefStreamReaderCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_v8value_t* cef_create_v8value_undefined()
{
CefRefPtr<CefV8Value> impl = CefV8Value::CreateUndefined();
if(impl.get())
return CefV8ValueCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_v8value_t* cef_create_v8value_null()
{
CefRefPtr<CefV8Value> impl = CefV8Value::CreateNull();
if(impl.get())
return CefV8ValueCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_v8value_t* cef_create_v8value_bool(int value)
{
CefRefPtr<CefV8Value> impl = CefV8Value::CreateBool(value?true:false);
if(impl.get())
return CefV8ValueCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_v8value_t* cef_create_v8value_int(int value)
{
CefRefPtr<CefV8Value> impl = CefV8Value::CreateInt(value);
if(impl.get())
return CefV8ValueCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_v8value_t* cef_create_v8value_double(double value)
{
CefRefPtr<CefV8Value> impl = CefV8Value::CreateDouble(value);
if(impl.get())
return CefV8ValueCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_v8value_t* cef_create_v8value_string(const wchar_t* value)
{
std::wstring valueStr;
if(value)
valueStr = value;
CefRefPtr<CefV8Value> impl = CefV8Value::CreateString(valueStr);
if(impl.get())
return CefV8ValueCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_v8value_t* cef_create_v8value_object(cef_base_t* user_data)
{
CefRefPtr<CefBase> basePtr;
if(user_data)
basePtr = CefBaseCToCpp::Wrap(user_data);
CefRefPtr<CefV8Value> impl = CefV8Value::CreateObject(basePtr);
if(impl.get())
return CefV8ValueCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_v8value_t* cef_create_v8value_array()
{
CefRefPtr<CefV8Value> impl = CefV8Value::CreateArray();
if(impl.get())
return CefV8ValueCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_v8value_t* cef_create_v8value_function(const wchar_t* name,
cef_v8handler_t* handler)
{
std::wstring nameStr;
if(name)
nameStr = name;
CefRefPtr<CefV8Handler> handlerPtr;
if(handler)
handlerPtr = CefV8HandlerCToCpp::Wrap(handler);
CefRefPtr<CefV8Value> impl = CefV8Value::CreateFunction(nameStr, handlerPtr);
if(impl.get())
return CefV8ValueCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT int cef_register_plugin(const cef_plugin_info_t* plugin_info)

View File

@ -178,6 +178,10 @@
RelativePath="..\include\cef_string.h"
>
</File>
<File
RelativePath="..\include\cef_string_list.h"
>
</File>
<File
RelativePath="..\include\cef_string_map.h"
>
@ -226,6 +230,30 @@
RelativePath=".\cpptoc\cpptoc.h"
>
</File>
<File
RelativePath=".\cpptoc\frame_cpptoc.cc"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PrecompiledHeaderThrough="../precompiled_libcef.h"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PrecompiledHeaderThrough="../precompiled_libcef.h"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\cpptoc\frame_cpptoc.h"
>
</File>
<File
RelativePath=".\cpptoc\request_cpptoc.cc"
>
@ -275,7 +303,7 @@
>
</File>
<File
RelativePath=".\cpptoc\variant_cpptoc.cc"
RelativePath=".\cpptoc\v8value_cpptoc.cc"
>
<FileConfiguration
Name="Debug|Win32"
@ -295,7 +323,7 @@
</FileConfiguration>
</File>
<File
RelativePath=".\cpptoc\variant_cpptoc.h"
RelativePath=".\cpptoc\v8value_cpptoc.h"
>
</File>
</Filter>
@ -331,7 +359,7 @@
>
</File>
<File
RelativePath=".\ctocpp\jshandler_ctocpp.cc"
RelativePath=".\ctocpp\v8handler_ctocpp.cc"
>
<FileConfiguration
Name="Debug|Win32"
@ -351,7 +379,7 @@
</FileConfiguration>
</File>
<File
RelativePath=".\ctocpp\jshandler_ctocpp.h"
RelativePath=".\ctocpp\v8handler_ctocpp.h"
>
</File>
</Filter>
@ -375,30 +403,6 @@
RelativePath=".\cef_logging.h"
>
</File>
<File
RelativePath=".\cef_string.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\cef_string_map.cc"
>
</File>
<File
RelativePath=".\libcef_dll.cc"
>

View File

@ -8,11 +8,11 @@
#include "cef_nplugin.h"
#include "cef_nplugin_capi.h"
#include "../cpptoc/handler_cpptoc.h"
#include "../cpptoc/jshandler_cpptoc.h"
#include "../cpptoc/v8handler_cpptoc.h"
#include "../ctocpp/browser_ctocpp.h"
#include "../ctocpp/request_ctocpp.h"
#include "../ctocpp/variant_ctocpp.h"
#include "../ctocpp/stream_ctocpp.h"
#include "../ctocpp/v8value_ctocpp.h"
bool CefInitialize(bool multi_threaded_message_loop,
@ -28,14 +28,14 @@ void CefShutdown()
#ifdef _DEBUG
// Check that all wrapper objects have been destroyed
DCHECK(CefHandlerCppToC::DebugObjCt == 0);
DCHECK(CefJSHandlerCppToC::DebugObjCt == 0);
DCHECK(CefV8HandlerCppToC::DebugObjCt == 0);
DCHECK(CefBrowserCToCpp::DebugObjCt == 0);
DCHECK(CefRequestCToCpp::DebugObjCt == 0);
DCHECK(CefPostDataCToCpp::DebugObjCt == 0);
DCHECK(CefPostDataElementCToCpp::DebugObjCt == 0);
DCHECK(CefStreamReaderCToCpp::DebugObjCt == 0);
DCHECK(CefStreamWriterCToCpp::DebugObjCt == 0);
DCHECK(CefVariantCToCpp::DebugObjCt == 0);
DCHECK(CefV8ValueCToCpp::DebugObjCt == 0);
#endif // _DEBUG
}
@ -44,13 +44,20 @@ void CefDoMessageLoopWork()
cef_do_message_loop_work();
}
bool CefRegisterExtension(const std::wstring& extension_name,
const std::wstring& javascript_code,
CefRefPtr<CefV8Handler> handler)
{
return cef_register_extension(extension_name.c_str(), javascript_code.c_str(),
CefV8HandlerCppToC::Wrap(handler));
}
bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler,
const std::wstring& url)
{
CefHandlerCppToC* hp = new CefHandlerCppToC(handler);
hp->AddRef();
return cef_create_browser(&windowInfo, popup, hp->GetStruct(), url.c_str());
return cef_create_browser(&windowInfo, popup, CefHandlerCppToC::Wrap(handler),
url.c_str());
}
CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
@ -58,75 +65,134 @@ CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
CefRefPtr<CefHandler> handler,
const std::wstring& url)
{
CefHandlerCppToC* hp = new CefHandlerCppToC(handler);
hp->AddRef();
cef_browser_t* browserStruct = cef_create_browser_sync(&windowInfo, popup,
hp->GetStruct(), url.c_str());
if(!browserStruct)
return NULL;
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browserStruct);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
return browserPtr;
cef_browser_t* impl = cef_create_browser_sync(&windowInfo, popup,
CefHandlerCppToC::Wrap(handler), url.c_str());
if(impl)
return CefBrowserCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefRequest> CreateRequest()
{
cef_request_t* impl = cef_create_request();
if(!impl)
return NULL;
CefRequestCToCpp* ptr = new CefRequestCToCpp(impl);
CefRefPtr<CefRequest> rp(ptr);
ptr->UnderlyingRelease();
return rp;
if(impl)
return CefRequestCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefPostData> CreatePostData()
{
cef_post_data_t* impl = cef_create_post_data();
if(!impl)
return NULL;
CefPostDataCToCpp* ptr = new CefPostDataCToCpp(impl);
CefRefPtr<CefPostData> rp(ptr);
ptr->UnderlyingRelease();
return rp;
if(impl)
return CefPostDataCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefPostDataElement> CreatePostDataElement()
{
cef_post_data_element_t* impl = cef_create_post_data_element();
if(!impl)
return NULL;
CefPostDataElementCToCpp* ptr = new CefPostDataElementCToCpp(impl);
CefRefPtr<CefPostDataElement> rp(ptr);
ptr->UnderlyingRelease();
return rp;
if(impl)
return CefPostDataElementCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefStreamReader> CefStreamReader::CreateForFile(const std::wstring& fileName)
{
cef_stream_reader_t* impl =
cef_create_stream_reader_for_file(fileName.c_str());
if(!impl)
return NULL;
CefStreamReaderCToCpp* ptr = new CefStreamReaderCToCpp(impl);
CefRefPtr<CefStreamReader> rp(ptr);
ptr->UnderlyingRelease();
return rp;
if(impl)
return CefStreamReaderCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefStreamReader> CefStreamReader::CreateForData(void *data, size_t size)
{
cef_stream_reader_t* impl = cef_create_stream_reader_for_data(data, size);
if(!impl)
return NULL;
CefStreamReaderCToCpp* ptr = new CefStreamReaderCToCpp(impl);
CefRefPtr<CefStreamReader> rp(ptr);
ptr->UnderlyingRelease();
return rp;
if(impl)
return CefStreamReaderCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefV8Value> CefV8Value::CreateUndefined()
{
cef_v8value_t* impl = cef_create_v8value_undefined();
if(impl)
return CefV8ValueCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefV8Value> CefV8Value::CreateNull()
{
cef_v8value_t* impl = cef_create_v8value_null();
if(impl)
return CefV8ValueCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefV8Value> CefV8Value::CreateBool(bool value)
{
cef_v8value_t* impl = cef_create_v8value_bool(value);
if(impl)
return CefV8ValueCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefV8Value> CefV8Value::CreateInt(int value)
{
cef_v8value_t* impl = cef_create_v8value_int(value);
if(impl)
return CefV8ValueCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefV8Value> CefV8Value::CreateDouble(double value)
{
cef_v8value_t* impl = cef_create_v8value_double(value);
if(impl)
return CefV8ValueCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefV8Value> CefV8Value::CreateString(const std::wstring& value)
{
cef_v8value_t* impl = cef_create_v8value_string(value.c_str());
if(impl)
return CefV8ValueCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefV8Value> CefV8Value::CreateObject(CefRefPtr<CefBase> user_data)
{
cef_base_t* baseStruct = NULL;
if(user_data)
baseStruct = CefBaseCppToC::Wrap(user_data);
cef_v8value_t* impl = cef_create_v8value_object(baseStruct);
if(impl)
return CefV8ValueCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefV8Value> CefV8Value::CreateArray()
{
cef_v8value_t* impl = cef_create_v8value_array();
if(impl)
return CefV8ValueCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefV8Value> CefV8Value::CreateFunction(const std::wstring& name,
CefRefPtr<CefV8Handler> handler)
{
cef_v8handler_t* handlerStruct = NULL;
if(handler.get())
handlerStruct = CefV8HandlerCppToC::Wrap(handler);
cef_v8value_t* impl = cef_create_v8value_function(name.c_str(),
handlerStruct);
if(impl)
return CefV8ValueCToCpp::Wrap(impl);
return NULL;
}
bool CefRegisterPlugin(const struct CefPluginInfo& plugin_info)

View File

@ -142,11 +142,11 @@
>
</File>
<File
RelativePath="..\cpptoc\jshandler_cpptoc.cc"
RelativePath="..\cpptoc\v8handler_cpptoc.cc"
>
</File>
<File
RelativePath="..\cpptoc\jshandler_cpptoc.h"
RelativePath="..\cpptoc\v8handler_cpptoc.h"
>
</File>
</Filter>
@ -165,6 +165,14 @@
RelativePath="..\ctocpp\ctocpp.h"
>
</File>
<File
RelativePath="..\ctocpp\frame_ctocpp.cc"
>
</File>
<File
RelativePath="..\ctocpp\frame_ctocpp.h"
>
</File>
<File
RelativePath="..\ctocpp\request_ctocpp.cc"
>
@ -182,11 +190,11 @@
>
</File>
<File
RelativePath="..\ctocpp\variant_ctocpp.cc"
RelativePath="..\ctocpp\v8value_ctocpp.cc"
>
</File>
<File
RelativePath="..\ctocpp\variant_ctocpp.h"
RelativePath="..\ctocpp\v8value_ctocpp.h"
>
</File>
</Filter>

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Embedded Framework Authors. All rights
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
@ -7,9 +7,9 @@
#include "cefclient.h"
#include "clientplugin.h"
#include "cef.h"
#include <sstream>
#define MAX_LOADSTRING 100
#define MAX_URL_LENGTH 255
#define BUTTON_WIDTH 72
@ -30,6 +30,66 @@ BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
// Implementation of the V8 handler class for the "cef.test" extension.
class ClientV8ExtensionHandler : public CefThreadSafeBase<CefV8Handler>
{
public:
ClientV8ExtensionHandler() : test_param_(L"An initial string value.") {}
virtual ~ClientV8ExtensionHandler() {}
// Execute with the specified argument list and return value. Return true if
// the method was handled.
virtual bool Execute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
if(name == L"SetTestParam")
{
// Handle the SetTestParam native function by saving the string argument
// into the local member.
if(arguments.size() != 1 || !arguments[0]->IsString())
return false;
test_param_ = arguments[0]->GetStringValue();
return true;
}
else if(name == L"GetTestParam")
{
// Handle the GetTestParam native function by returning the local member
// value.
retval = CefV8Value::CreateString(test_param_);
return true;
}
else if(name == L"GetTestObject")
{
// Handle the GetTestObject native function by creating and returning a
// new V8 object.
retval = CefV8Value::CreateObject(NULL);
// Add a string parameter to the new V8 object.
retval->SetValue(L"param", CefV8Value::CreateString(
L"Retrieving a parameter on a native object succeeded."));
// Add a function to the new V8 object.
retval->SetValue(L"GetMessage",
CefV8Value::CreateFunction(L"GetMessage", this));
return true;
}
else if(name == L"GetMessage")
{
// Handle the GetMessage object function by returning a string.
retval = CefV8Value::CreateString(
L"Calling a function on a native object succeeded.");
return true;
}
return false;
}
private:
std::wstring test_param_;
};
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
@ -66,6 +126,29 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
// Register the internal client plugin
CefRegisterPlugin(plugin_info);
// Register a V8 extension with the below JavaScript code that calls native
// methods implemented in ClientV8ExtensionHandler.
std::wstring code = L"var cef;"
L"if (!cef)"
L" cef = {};"
L"if (!cef.test)"
L" cef.test = {};"
L"(function() {"
L" cef.test.__defineGetter__('test_param', function() {"
L" native function GetTestParam();"
L" return GetTestParam();"
L" });"
L" cef.test.__defineSetter__('test_param', function(b) {"
L" native function SetTestParam();"
L" if(b) SetTestParam(b);"
L" });"
L" cef.test.test_object = function() {"
L" native function GetTestObject();"
L" return GetTestObject();"
L" };"
L"})();";
CefRegisterExtension(L"v8/test", code, new ClientV8ExtensionHandler());
MSG msg;
HACCEL hAccelTable;
@ -170,144 +253,6 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
return TRUE;
}
// Client implementation of the JS handler class
// Select the "JavaScript" option from the "Tests" menu for an example
class ClientJSHandler : public CefThreadSafeBase<CefJSHandler>
{
public:
ClientJSHandler()
{
}
~ClientJSHandler()
{
}
// Return true if the specified method exists.
virtual bool HasMethod(CefRefPtr<CefBrowser> browser,
const std::wstring& name)
{
// We have a method called "mymethod"
return (name.compare(L"mymethod") == 0);
}
// Return true if the specified property exists.
virtual bool HasProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name)
{
return false;
}
// Set the property value. Return true if the property is accepted.
virtual bool SetProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
const CefRefPtr<CefVariant> value)
{
return false;
}
// Get the property value. Return true if the value is returned.
virtual bool GetProperty(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
CefRefPtr<CefVariant> value)
{
return false;
}
// Execute a method with the specified argument vector and return
// value. Return true if the method was handled.
virtual bool ExecuteMethod(CefRefPtr<CefBrowser> browser,
const std::wstring& name,
const VariantVector& args,
CefRefPtr<CefVariant> retval)
{
// We only handle the "mymethod" method
if(name.compare(L"mymethod") != 0)
return false;
// Return a description of the input arguments
std::wstringstream ss;
for(size_t i = 0; i < args.size(); i++)
{
ss << L"arg" << i;
switch(args[i]->GetType())
{
case VARIANT_TYPE_NULL:
ss << L" null";
break;
case VARIANT_TYPE_BOOL:
ss << L" bool = " << args[i]->GetBool();
break;
case VARIANT_TYPE_INT:
ss << L" int = " << args[i]->GetInt();
break;
case VARIANT_TYPE_DOUBLE:
ss << L" double = " << args[i]->GetDouble();
break;
case VARIANT_TYPE_STRING:
ss << L" string = " << args[i]->GetString().c_str();
break;
case VARIANT_TYPE_BOOL_ARRAY:
ss << L" bool array = ";
{
std::vector<bool> vec;
args[i]->GetBoolArray(vec);
for(size_t x = 0; x < vec.size(); x++)
{
ss << vec[x];
if(x < vec.size()-1)
ss << L",";
}
}
break;
case VARIANT_TYPE_INT_ARRAY:
ss << L" int array = ";
{
std::vector<int> vec;
args[i]->GetIntArray(vec);
for(size_t x = 0; x < vec.size(); x++)
{
ss << vec[x];
if(x < vec.size()-1)
ss << L",";
}
}
break;
case VARIANT_TYPE_DOUBLE_ARRAY:
ss << L" double array = ";
{
std::vector<double> vec;
args[i]->GetDoubleArray(vec);
for(size_t x = 0; x < vec.size(); x++)
{
ss << vec[x];
if(x < vec.size()-1)
ss << L",";
}
}
break;
case VARIANT_TYPE_STRING_ARRAY:
ss << L" string array = ";
{
std::vector<std::wstring> vec;
args[i]->GetStringArray(vec);
for(size_t x = 0; x < vec.size(); x++)
{
ss << vec[x].c_str();
if(x < vec.size()-1)
ss << L",";
}
}
break;
}
ss << L"\n<br>";
}
retval->SetString(ss.str());
return true;
}
};
// Load a resource of type BINARY
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes)
{
@ -328,6 +273,124 @@ bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes)
return false;
}
// Implementation of the V8 handler class for the "window.cef_test.Dump"
// function.
class ClientV8FunctionHandler : public CefThreadSafeBase<CefV8Handler>
{
public:
ClientV8FunctionHandler() {}
virtual ~ClientV8FunctionHandler() {}
// Execute with the specified argument list and return value. Return true if
// the method was handled.
virtual bool Execute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
if(name == L"Dump")
{
// The "Dump" function will return a human-readable dump of the input
// arguments.
std::wstringstream stream;
size_t i;
for(i = 0; i < arguments.size(); ++i)
{
stream << L"arg[" << i << L"] = ";
PrintValue(arguments[i], stream, 0);
stream << L"\n";
}
retval = CefV8Value::CreateString(stream.str());
return true;
}
else if(name == L"Call")
{
// The "Call" function will execute a function to get an object and then
// return the result of calling a function belonging to that object. The
// first arument is the function that will return an object and the second
// argument is the function that will be called on that returned object.
int argSize = arguments.size();
if(argSize < 2 || !arguments[0]->IsFunction()
|| !arguments[1]->IsString())
return false;
CefV8ValueList argList;
// Execute the function stored in the first argument to retrieve an
// object.
CefRefPtr<CefV8Value> objectPtr;
if(!arguments[0]->ExecuteFunction(object, argList, objectPtr, exception))
return false;
// Verify that the returned value is an object.
if(!objectPtr.get() || !objectPtr->IsObject())
return false;
// Retrieve the member function specified by name in the second argument
// from the object.
CefRefPtr<CefV8Value> funcPtr =
objectPtr->GetValue(arguments[1]->GetStringValue());
// Verify that the returned value is a function.
if(!funcPtr.get() || !funcPtr->IsFunction())
return false;
// Pass any additional arguments on to the member function.
for(int i = 2; i < argSize; ++i)
argList.push_back(arguments[i]);
// Execute the member function.
return funcPtr->ExecuteFunction(arguments[0], argList, retval, exception);
}
return false;
}
// Simple function for formatted output of a V8 value.
void PrintValue(CefRefPtr<CefV8Value> value, std::wstringstream &stream,
int indent)
{
std::wstringstream indent_stream;
for(int i = 0; i < indent; ++i)
indent_stream << L" ";
std::wstring indent_str = indent_stream.str();
if(value->IsUndefined())
stream << L"(undefined)";
else if(value->IsNull())
stream << L"(null)";
else if(value->IsBool())
stream << L"(bool) " << (value->GetBoolValue() ? L"true" : L"false");
else if(value->IsInt())
stream << L"(int) " << value->GetIntValue();
else if(value->IsDouble())
stream << L"(double) " << value->GetDoubleValue();
else if(value->IsString())
stream << L"(string) " << value->GetStringValue().c_str();
else if(value->IsFunction())
stream << L"(function) " << value->GetFunctionName().c_str();
else if(value->IsArray()) {
stream << L"(array) [";
int len = value->GetArrayLength();
for(int i = 0; i < len; ++i) {
stream << L"\n " << indent_str.c_str() << i << L" = ";
PrintValue(value->GetValue(i), stream, indent+1);
}
stream << L"\n" << indent_str.c_str() << L"]";
} else if(value->IsObject()) {
stream << L"(object) [";
std::vector<std::wstring> keys;
if(value->GetKeys(keys)) {
for(size_t i = 0; i < keys.size(); ++i) {
stream << L"\n " << indent_str.c_str() << keys[i].c_str() << L" = ";
PrintValue(value->GetValue(keys[i]), stream, indent+1);
}
}
stream << L"\n" << indent_str.c_str() << L"]";
}
}
};
// Client implementation of the browser handler class
class ClientHandler : public CefThreadSafeBase<CefHandler>
{
@ -373,8 +436,6 @@ public:
m_Browser = browser;
m_BrowserHwnd = browser->GetWindowHandle();
}
// Register our JavaScript "myclass" object
browser->AddJSHandler(L"myclass", new ClientJSHandler());
Unlock();
return RV_CONTINUE;
}
@ -382,9 +443,10 @@ public:
// Event called when the address bar changes. The return value is currently
// ignored.
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& url)
{
if(m_BrowserHwnd == browser->GetWindowHandle())
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain())
{
// Set the edit window text
SetWindowText(m_EditHwnd, url.c_str());
@ -412,44 +474,57 @@ public:
// modify the |request| object if desired. Return RV_HANDLED to cancel
// navigation.
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType, bool isRedirect)
{
return RV_CONTINUE;
}
// Event called when the browser begins loading a page. The return value is
// currently ignored.
virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser)
// 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<CefBrowser> browser,
CefRefPtr<CefFrame> frame)
{
Lock();
// We've just started loading a page
m_bLoading = true;
m_bCanGoBack = false;
m_bCanGoForward = false;
Unlock();
if(!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. This event will
// be generated irrespective of whether the request completes successfully.
// The return value is currently ignored.
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser)
// 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<CefBrowser> browser,
CefRefPtr<CefFrame> frame)
{
Lock();
// We've just finished loading a page
m_bLoading = false;
m_bCanGoBack = browser->CanGoBack();
m_bCanGoForward = browser->CanGoForward();
Unlock();
if(!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
// 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<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const std::wstring& failedUrl,
std::wstring& errorText)
@ -542,6 +617,7 @@ public:
// and footer yourself return RV_HANDLED. Otherwise, populate the approprate
// variables and return RV_CONTINUE.
virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefPrintInfo& printInfo,
const std::wstring& url,
const std::wstring& title,
@ -569,6 +645,7 @@ public:
// 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<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message)
{
return RV_CONTINUE;
@ -578,6 +655,7 @@ public:
// 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<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message, bool& retval)
{
return RV_CONTINUE;
@ -588,6 +666,7 @@ public:
// set |retval| to true if the user accepted the prompt and request and
// |result| to the resulting value.
virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message,
const std::wstring& defaultValue,
bool& retval,
@ -616,6 +695,31 @@ public:
return RV_CONTINUE;
}
// Event called for binding to a frame's JavaScript global object. The
// return value is currently ignored.
virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object)
{
// Create the new V8 object.
CefRefPtr<CefV8Value> testObjPtr = CefV8Value::CreateObject(NULL);
// Add the new V8 object to the global window object with the name
// "cef_test".
object->SetValue(L"cef_test", testObjPtr);
// Create an instance of ClientV8FunctionHandler as the V8 handler.
CefRefPtr<CefV8Handler> handlerPtr = new ClientV8FunctionHandler();
// Add a new V8 function to the cef_test object with the name "Dump".
testObjPtr->SetValue(L"Dump",
CefV8Value::CreateFunction(L"Dump", handlerPtr));
// Add a new V8 function to the cef_test object with the name "Call".
testObjPtr->SetValue(L"Call",
CefV8Value::CreateFunction(L"Call", handlerPtr));
return RV_HANDLED;
}
// Retrieve the current navigation state flags
void GetNavState(bool &isLoading, bool &canGoBack, bool &canGoForward)
{
@ -702,7 +806,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
*((LPWORD)strPtr) = MAX_URL_LENGTH;
LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr);
if (strLen > 0)
browser->LoadURL(strPtr, std::wstring());
browser->GetMainFrame()->LoadURL(strPtr);
return 0;
}
@ -833,28 +937,62 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if(browser.get())
browser->StopLoad();
return 0;
case ID_TESTS_JAVASCRIPT_HANDLER: // Test our javascript handler
case ID_TESTS_JAVASCRIPT_HANDLER: // Test the V8 function handler
if(browser.get())
{
std::wstring html =
L"<html><body>ClientJSHandler says:<br>"
L"<html><body>ClientV8FunctionHandler says:<br><pre>"
L"<script language=\"JavaScript\">"
L"document.writeln(window.myclass.mymethod(false, 1, 7.6654,"
L"'bar',[false,true],[5, 6, 1, 8],[4.54,10.032,.054],"
L"['one','two']));"
L"document.writeln(window.cef_test.Dump(false, 1, 7.6654,'bar',"
L" [false,true],[5, 7.654, 1, 'foo', [true, 'bar'], 8]));"
L"document.writeln(window.cef_test.Dump(cef));"
L"document.writeln("
L" window.cef_test.Call(cef.test.test_object, 'GetMessage'));"
L"function my_object() {"
L" var obj = {};"
L" (function() {"
L" obj.GetMessage = function(a) {"
L" return 'Calling a function with value '+a+' on a user object succeeded.';"
L" };"
L" })();"
L" return obj;"
L"};"
L"document.writeln("
L" window.cef_test.Call(my_object, 'GetMessage', 'foobar'));"
L"</script>"
L"</body></html>";
browser->LoadString(html, L"about:blank");
L"</pre></body></html>";
browser->GetMainFrame()->LoadString(html, L"about:blank");
}
return 0;
case ID_TESTS_JAVASCRIPT_HANDLER2: // Test the V8 extension handler
if(browser.get())
{
std::wstring html =
L"<html><body>ClientV8ExtensionHandler says:<br><pre>"
L"<script language=\"JavaScript\">"
L"cef.test.test_param ="
L" 'Assign and retrieve a value succeeded the first time.';"
L"document.writeln(cef.test.test_param);"
L"cef.test.test_param ="
L" 'Assign and retrieve a value succeeded the second time.';"
L"document.writeln(cef.test.test_param);"
L"var obj = cef.test.test_object();"
L"document.writeln(obj.param);"
L"document.writeln(obj.GetMessage());"
L"</script>"
L"</pre></body></html>";
browser->GetMainFrame()->LoadString(html, L"about:blank");
}
return 0;
case ID_TESTS_JAVASCRIPT_EXECUTE: // Test execution of javascript
if(browser.get())
{
browser->ExecuteJavaScript(L"alert('JavaScript execute works!');",
L"about:blank", 0, TF_MAIN);
browser->GetMainFrame()->ExecuteJavaScript(
L"alert('JavaScript execute works!');",
L"about:blank", 0);
}
return 0;
case ID_TESTS_PLUGIN: // Test our custom plugin
case ID_TESTS_PLUGIN: // Test the custom plugin
if(browser.get())
{
std::wstring html =
@ -862,14 +1000,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
L"<embed type=\"application/x-client-plugin\""
L"width=600 height=40>"
L"</body></html>";
browser->LoadString(html, L"about:blank");
browser->GetMainFrame()->LoadString(html, L"about:blank");
}
return 0;
case ID_TESTS_POPUP: // Test a popup window
if(browser.get())
{
browser->ExecuteJavaScript(L"window.open('http://www.google.com');",
L"about:blank", 0, TF_MAIN);
browser->GetMainFrame()->ExecuteJavaScript(
L"window.open('http://www.google.com');",
L"about:blank", 0);
}
return 0;
}

View File

@ -57,7 +57,8 @@ BEGIN
END
POPUP "Tests"
BEGIN
MENUITEM "JavaScript Handler", ID_TESTS_JAVASCRIPT_HANDLER
MENUITEM "JavaScript Function Handler", ID_TESTS_JAVASCRIPT_HANDLER
MENUITEM "JavaScript Extension Handler",ID_TESTS_JAVASCRIPT_HANDLER2
MENUITEM "JavaScript Execute", ID_TESTS_JAVASCRIPT_EXECUTE
MENUITEM "Plugin", ID_TESTS_PLUGIN
MENUITEM "Popup Window", ID_TESTS_POPUP

View File

@ -22,9 +22,10 @@
#define IDC_NAV_RELOAD 202
#define IDC_NAV_STOP 203
#define ID_TESTS_JAVASCRIPT_HANDLER 32771
#define ID_TESTS_JAVASCRIPT_EXECUTE 32772
#define ID_TESTS_PLUGIN 32773
#define ID_TESTS_POPUP 32774
#define ID_TESTS_JAVASCRIPT_HANDLER2 32772
#define ID_TESTS_JAVASCRIPT_EXECUTE 32773
#define ID_TESTS_PLUGIN 32774
#define ID_TESTS_POPUP 32775
#define IDC_STATIC -1
#define IDS_LOGO 1000