diff --git a/cef1/CHROMIUM_BUILD_COMPATIBILITY.txt b/cef1/CHROMIUM_BUILD_COMPATIBILITY.txt index 1f5da7df9..b40442aae 100644 --- a/cef1/CHROMIUM_BUILD_COMPATIBILITY.txt +++ b/cef1/CHROMIUM_BUILD_COMPATIBILITY.txt @@ -17,5 +17,5 @@ { 'chromium_url': 'http://src.chromium.org/svn/trunk/src', - 'chromium_revision': '131752', + 'chromium_revision': '138235', } diff --git a/cef1/cef.gyp b/cef1/cef.gyp index 7af5ccffc..854f91155 100644 --- a/cef1/cef.gyp +++ b/cef1/cef.gyp @@ -177,7 +177,7 @@ 'pak_inputs': [ '<(grit_out_dir)/devtools_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak', - '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.pak', + '<(SHARED_INTERMEDIATE_DIR)/ui/native_theme/native_theme_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_chromium_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_resources.pak', ], @@ -257,7 +257,7 @@ 'pak_inputs': [ '<(grit_out_dir)/devtools_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak', - '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.pak', + '<(SHARED_INTERMEDIATE_DIR)/ui/native_theme/native_theme_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_chromium_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_resources.pak', ], @@ -323,14 +323,12 @@ 'tests/unittests/scheme_handler_unittest.cc', 'tests/unittests/stream_unittest.cc', 'tests/unittests/string_unittest.cc', - 'tests/unittests/storage_unittest.cc', 'tests/unittests/test_handler.cc', 'tests/unittests/test_handler.h', 'tests/unittests/test_suite.cc', 'tests/unittests/test_suite.h', 'tests/unittests/url_unittest.cc', 'tests/unittests/v8_unittest.cc', - 'tests/unittests/v8_unittest_legacy.cc', 'tests/unittests/web_urlrequest_unittest.cc', 'tests/unittests/xml_reader_unittest.cc', 'tests/unittests/zip_reader_unittest.cc', @@ -393,7 +391,7 @@ 'pak_inputs': [ '<(grit_out_dir)/devtools_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak', - '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.pak', + '<(SHARED_INTERMEDIATE_DIR)/ui/native_theme/native_theme_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_chromium_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_resources.pak', ], @@ -456,7 +454,7 @@ '<(DEPTH)/third_party/WebKit/Source/WebCore/WebCore.gyp/WebCore.gyp:webcore', '<(DEPTH)/third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit', '<(DEPTH)/third_party/zlib/zlib.gyp:zlib', - '<(DEPTH)/ui/ui.gyp:gfx_resources', + '<(DEPTH)/ui/ui.gyp:native_theme_resources', '<(DEPTH)/ui/ui.gyp:ui', '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', '<(DEPTH)/webkit/support/webkit_support.gyp:appcache', @@ -501,6 +499,7 @@ 'conditions': [ ['OS=="win"', { 'dependencies': [ + '<(DEPTH)/base/allocator/allocator.gyp:allocator', '<(DEPTH)/breakpad/breakpad.gyp:breakpad_handler', '<(DEPTH)/third_party/angle/src/build_angle.gyp:libEGL', '<(DEPTH)/third_party/angle/src/build_angle.gyp:libGLESv2', @@ -640,7 +639,7 @@ '<(DEPTH)/third_party/WebKit/Source/WebCore/WebCore.gyp/WebCore.gyp:webcore', '<(DEPTH)/third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit', '<(DEPTH)/third_party/zlib/zlib.gyp:zlib', - '<(DEPTH)/ui/ui.gyp:gfx_resources', + '<(DEPTH)/ui/ui.gyp:native_theme_resources', '<(DEPTH)/ui/ui.gyp:ui', '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', '<(DEPTH)/webkit/support/webkit_support.gyp:appcache', @@ -669,6 +668,8 @@ 'libcef/browser_devtools_client.h', 'libcef/browser_devtools_scheme_handler.cc', 'libcef/browser_devtools_scheme_handler.h', + 'libcef/browser_dom_storage_system.cc', + 'libcef/browser_dom_storage_system.h', 'libcef/browser_file_system.cc', 'libcef/browser_file_system.h', 'libcef/browser_file_writer.cc', @@ -679,8 +680,6 @@ 'libcef/browser_navigation_controller.h', 'libcef/browser_network_delegate.cc', 'libcef/browser_network_delegate.h', - 'libcef/browser_persistent_cookie_store.cc', - 'libcef/browser_persistent_cookie_store.h', 'libcef/browser_request_context.cc', 'libcef/browser_request_context.h', 'libcef/browser_request_context_proxy.cc', @@ -691,14 +690,11 @@ 'libcef/browser_settings.h', 'libcef/browser_socket_stream_bridge.cc', 'libcef/browser_socket_stream_bridge.h', + 'libcef/browser_thread_stub.cc', 'libcef/browser_webcookiejar_impl.cc', 'libcef/browser_webcookiejar_impl.h', 'libcef/browser_webblobregistry_impl.cc', 'libcef/browser_webblobregistry_impl.h', - 'libcef/browser_webstoragearea_impl.cc', - 'libcef/browser_webstoragearea_impl.h', - 'libcef/browser_webstoragenamespace_impl.cc', - 'libcef/browser_webstoragenamespace_impl.h', 'libcef/browser_webkit_glue.cc', 'libcef/browser_webkit_glue.h', 'libcef/browser_webkit_init.cc', @@ -736,13 +732,6 @@ 'libcef/drag_download_file.h', 'libcef/drag_download_util.cc', 'libcef/drag_download_util.h', - 'libcef/dom_storage_area.cc', - 'libcef/dom_storage_area.h', - 'libcef/dom_storage_common.h', - 'libcef/dom_storage_context.cc', - 'libcef/dom_storage_context.h', - 'libcef/dom_storage_namespace.cc', - 'libcef/dom_storage_namespace.h', 'libcef/dom_document_impl.cc', 'libcef/dom_document_impl.h', 'libcef/dom_event_impl.cc', @@ -763,7 +752,7 @@ 'libcef/scheme_impl.cc', 'libcef/simple_clipboard_impl.cc', 'libcef/simple_clipboard_impl.h', - 'libcef/storage_impl.cc', + 'libcef/sqlite_diagnostics_stub.cc', 'libcef/stream_impl.cc', 'libcef/stream_impl.h', 'libcef/task_impl.cc', @@ -782,6 +771,8 @@ 'libcef/xml_reader_impl.h', 'libcef/zip_reader_impl.cc', 'libcef/zip_reader_impl.h', + '<(DEPTH)/chrome/browser/net/sqlite_persistent_cookie_store.cc', + '<(DEPTH)/chrome/browser/net/sqlite_persistent_cookie_store.h', # DevTools resource IDs generated by grit '<(grit_out_dir)/grit/devtools_resources_map.cc', ], diff --git a/cef1/cef_paths.gypi b/cef1/cef_paths.gypi index 13b2f1ad7..e719e56dd 100644 --- a/cef1/cef_paths.gypi +++ b/cef1/cef_paths.gypi @@ -41,7 +41,6 @@ 'include/cef_resource_bundle_handler.h', 'include/cef_response.h', 'include/cef_scheme.h', - 'include/cef_storage.h', 'include/cef_stream.h', 'include/cef_task.h', 'include/cef_url.h', @@ -82,7 +81,6 @@ 'include/capi/cef_resource_bundle_handler_capi.h', 'include/capi/cef_response_capi.h', 'include/capi/cef_scheme_capi.h', - 'include/capi/cef_storage_capi.h', 'include/capi/cef_stream_capi.h', 'include/capi/cef_task_capi.h', 'include/capi/cef_url_capi.h', @@ -170,8 +168,6 @@ 'libcef_dll/cpptoc/scheme_handler_callback_cpptoc.h', 'libcef_dll/ctocpp/scheme_handler_factory_ctocpp.cc', 'libcef_dll/ctocpp/scheme_handler_factory_ctocpp.h', - 'libcef_dll/ctocpp/storage_visitor_ctocpp.cc', - 'libcef_dll/ctocpp/storage_visitor_ctocpp.h', 'libcef_dll/cpptoc/stream_reader_cpptoc.cc', 'libcef_dll/cpptoc/stream_reader_cpptoc.h', 'libcef_dll/cpptoc/stream_writer_cpptoc.cc', @@ -280,8 +276,6 @@ 'libcef_dll/ctocpp/scheme_handler_callback_ctocpp.h', 'libcef_dll/cpptoc/scheme_handler_factory_cpptoc.cc', 'libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h', - 'libcef_dll/cpptoc/storage_visitor_cpptoc.cc', - 'libcef_dll/cpptoc/storage_visitor_cpptoc.h', 'libcef_dll/ctocpp/stream_reader_ctocpp.cc', 'libcef_dll/ctocpp/stream_reader_ctocpp.h', 'libcef_dll/ctocpp/stream_writer_ctocpp.cc', diff --git a/cef1/include/capi/cef_storage_capi.h b/cef1/include/capi/cef_storage_capi.h deleted file mode 100644 index d04a6684b..000000000 --- a/cef1/include/capi/cef_storage_capi.h +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) 2012 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. -// -// --------------------------------------------------------------------------- -// -// This file was generated by the CEF translator tool and should not edited -// by hand. See the translator.README.txt file in the tools directory for -// more information. -// - -#ifndef CEF_INCLUDE_CAPI_CEF_STORAGE_CAPI_H_ -#define CEF_INCLUDE_CAPI_CEF_STORAGE_CAPI_H_ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#include "include/capi/cef_base_capi.h" - - -/// -// Visit storage of the specified type. If |origin| is non-NULL only data -// matching that origin will be visited. If |key| is non-NULL only data matching -// that key will be visited. Otherwise, all data for the storage type will be -// visited. Origin should be of the form scheme://domain. If no origin is -// specified only data currently in memory will be returned. Returns false (0) -// if the storage cannot be accessed. -/// -CEF_EXPORT int cef_visit_storage(enum cef_storage_type_t type, - const cef_string_t* origin, const cef_string_t* key, - struct _cef_storage_visitor_t* visitor); - -/// -// Sets storage of the specified type, origin, key and value. Returns false (0) -// if storage cannot be accessed. This function must be called on the UI thread. -/// -CEF_EXPORT int cef_set_storage(enum cef_storage_type_t type, - const cef_string_t* origin, const cef_string_t* key, - const cef_string_t* value); - -/// -// Deletes all storage of the specified type. If |origin| is non-NULL only data -// matching that origin will be cleared. If |key| is non-NULL only data matching -// that key will be cleared. Otherwise, all data for the storage type will be -// cleared. Returns false (0) if storage cannot be accessed. This function must -// be called on the UI thread. -/// -CEF_EXPORT int cef_delete_storage(enum cef_storage_type_t type, - const cef_string_t* origin, const cef_string_t* key); - -/// -// Sets the directory path that will be used for storing data of the specified -// type. Currently only the ST_LOCALSTORAGE type is supported by this function. -// If |path| is NULL data will be stored in memory only. By default the storage -// path is the same as the cache path. Returns false (0) if the storage cannot -// be accessed. -/// -CEF_EXPORT int cef_set_storage_path(enum cef_storage_type_t type, - const cef_string_t* path); - -/// -// Structure to implement for visiting storage. The functions of this structure -// will always be called on the UI thread. -/// -typedef struct _cef_storage_visitor_t { - /// - // Base structure. - /// - cef_base_t base; - - /// - // Method that will be called once for each key/value data pair in storage. - // |count| is the 0-based index for the current pair. |total| is the total - // number of pairs. Set |deleteData| to true (1) to delete the pair currently - // being visited. Return false (0) to stop visiting pairs. This function may - // never be called if no data is found. - /// - int (CEF_CALLBACK *visit)(struct _cef_storage_visitor_t* self, - enum cef_storage_type_t type, const cef_string_t* origin, - const cef_string_t* key, const cef_string_t* value, int count, int total, - int* deleteData); -} cef_storage_visitor_t; - - -#ifdef __cplusplus -} -#endif - -#endif // CEF_INCLUDE_CAPI_CEF_STORAGE_CAPI_H_ diff --git a/cef1/include/capi/cef_v8_capi.h b/cef1/include/capi/cef_v8_capi.h index f0113dbf9..c0facab62 100644 --- a/cef1/include/capi/cef_v8_capi.h +++ b/cef1/include/capi/cef_v8_capi.h @@ -105,7 +105,8 @@ CEF_EXPORT int cef_register_extension(const cef_string_t* extension_name, const cef_string_t* javascript_code, struct _cef_v8handler_t* handler); /// -// Structure that encapsulates a V8 context handle. +// Structure that encapsulates a V8 context handle. The functions of this +// structure may only be called on the UI thread. /// typedef struct _cef_v8context_t { /// @@ -125,17 +126,18 @@ typedef struct _cef_v8context_t { struct _cef_frame_t* (CEF_CALLBACK *get_frame)(struct _cef_v8context_t* self); /// - // Returns the global object for this context. + // Returns the global object for this context. The context must be entered + // before calling this function. /// struct _cef_v8value_t* (CEF_CALLBACK *get_global)( struct _cef_v8context_t* self); /// // Enter this context. A context must be explicitly entered before creating a - // V8 Object, Array or Function asynchronously. exit() must be called the same - // number of times as enter() before releasing this context. V8 objects belong - // to the context in which they are created. Returns true (1) if the scope was - // entered successfully. + // V8 Object, Array, Function or Date asynchronously. exit() must be called + // the same number of times as enter() before releasing this context. V8 + // objects belong to the context in which they are created. Returns true (1) + // if the scope was entered successfully. /// int (CEF_CALLBACK *enter)(struct _cef_v8context_t* self); @@ -151,6 +153,16 @@ typedef struct _cef_v8context_t { /// int (CEF_CALLBACK *is_same)(struct _cef_v8context_t* self, struct _cef_v8context_t* that); + + /// + // Evaluates the specified JavaScript code using this context's global object. + // On success |retval| will be set to the return value, if any, and the + // function will return true (1). On failure |exception| will be set to the + // exception, if any, and the function will return false (0). + /// + int (CEF_CALLBACK *eval)(struct _cef_v8context_t* self, + const cef_string_t* code, struct _cef_v8value_t** retval, + struct _cef_v8exception_t** exception); } cef_v8context_t; @@ -293,8 +305,8 @@ typedef struct _cef_v8exception_t { /// -// Structure representing a V8 value. The functions of this structure should -// only be called on the UI thread. +// Structure representing a V8 value. The functions of this structure may only +// be called on the UI thread. /// typedef struct _cef_v8value_t { /// @@ -322,6 +334,11 @@ typedef struct _cef_v8value_t { /// int (CEF_CALLBACK *is_int)(struct _cef_v8value_t* self); + /// + // True if the value type is unsigned int. + /// + int (CEF_CALLBACK *is_uint)(struct _cef_v8value_t* self); + /// // True if the value type is double. /// @@ -369,7 +386,13 @@ typedef struct _cef_v8value_t { // Return an int value. The underlying data will be converted to if // necessary. /// - int (CEF_CALLBACK *get_int_value)(struct _cef_v8value_t* self); + int32 (CEF_CALLBACK *get_int_value)(struct _cef_v8value_t* self); + + /// + // Return an unisgned int value. The underlying data will be converted to if + // necessary. + /// + uint32 (CEF_CALLBACK *get_uint_value)(struct _cef_v8value_t* self); /// // Return a double value. The underlying data will be converted to if @@ -396,6 +419,45 @@ typedef struct _cef_v8value_t { // functions are also objects. String- and integer-based keys can be used // interchangably with the framework converting between them as necessary. + /// + // Returns true (1) if this is a user created object. + /// + int (CEF_CALLBACK *is_user_created)(struct _cef_v8value_t* self); + + /// + // Returns true (1) if the last function call resulted in an exception. This + // attribute exists only in the scope of the current CEF value object. + /// + int (CEF_CALLBACK *has_exception)(struct _cef_v8value_t* self); + + /// + // Returns the exception resulting from the last function call. This attribute + // exists only in the scope of the current CEF value object. + /// + struct _cef_v8exception_t* (CEF_CALLBACK *get_exception)( + struct _cef_v8value_t* self); + + /// + // Clears the last exception and returns true (1) on success. + /// + int (CEF_CALLBACK *clear_exception)(struct _cef_v8value_t* self); + + /// + // Returns true (1) if this object will re-throw future exceptions. This + // attribute exists only in the scope of the current CEF value object. + /// + int (CEF_CALLBACK *will_rethrow_exceptions)(struct _cef_v8value_t* self); + + /// + // Set whether this object will re-throw future exceptions. By default + // exceptions are not re-thrown. If a exception is re-thrown the current + // context should not be accessed again until after the exception has been + // caught and not re-thrown. Returns true (1) on success. This attribute + // exists only in the scope of the current CEF value object. + /// + int (CEF_CALLBACK *set_rethrow_exceptions)(struct _cef_v8value_t* self, + int rethrow); + /// // Returns true (1) if the object has a value with the specified identifier. /// @@ -408,46 +470,62 @@ typedef struct _cef_v8value_t { int (CEF_CALLBACK *has_value_byindex)(struct _cef_v8value_t* self, int index); /// - // Delete the value with the specified identifier. + // Deletes the value with the specified identifier and returns true (1) on + // success. Returns false (0) if this function is called incorrectly or an + // exception is thrown. For read-only and don't-delete values this function + // will return true (1) even though deletion failed. /// int (CEF_CALLBACK *delete_value_bykey)(struct _cef_v8value_t* self, const cef_string_t* key); /// - // Delete the value with the specified identifier. + // Deletes the value with the specified identifier and returns true (1) on + // success. Returns false (0) if this function is called incorrectly, deletion + // fails or an exception is thrown. For read-only and don't-delete values this + // function will return true (1) even though deletion failed. /// int (CEF_CALLBACK *delete_value_byindex)(struct _cef_v8value_t* self, int index); /// - // Returns the value with the specified identifier. + // Returns the value with the specified identifier on success. Returns NULL if + // this function is called incorrectly or an exception is thrown. /// struct _cef_v8value_t* (CEF_CALLBACK *get_value_bykey)( struct _cef_v8value_t* self, const cef_string_t* key); /// - // Returns the value with the specified identifier. + // Returns the value with the specified identifier on success. Returns NULL if + // this function is called incorrectly or an exception is thrown. /// struct _cef_v8value_t* (CEF_CALLBACK *get_value_byindex)( struct _cef_v8value_t* self, int index); /// - // Associate a value with the specified identifier. + // Associates a value with the specified identifier and returns true (1) on + // success. Returns false (0) if this function is called incorrectly or an + // exception is thrown. For read-only values this function will return true + // (1) even though assignment failed. /// int (CEF_CALLBACK *set_value_bykey)(struct _cef_v8value_t* self, const cef_string_t* key, struct _cef_v8value_t* value, enum cef_v8_propertyattribute_t attribute); /// - // Associate a value with the specified identifier. + // Associates a value with the specified identifier and returns true (1) on + // success. Returns false (0) if this function is called incorrectly or an + // exception is thrown. For read-only values this function will return true + // (1) even though assignment failed. /// int (CEF_CALLBACK *set_value_byindex)(struct _cef_v8value_t* self, int index, struct _cef_v8value_t* value); /// - // Register an identifier whose access will be forwarded to the - // cef_v8accessor_t instance passed to - // cef_v8value_t::cef_v8value_create_object_with_accessor(). + // Registers an identifier and returns true (1) on success. Access to the + // identifier will be forwarded to the cef_v8accessor_t instance passed to + // cef_v8value_t::cef_v8value_create_object(). Returns false (0) if this + // function is called incorrectly or an exception is thrown. For read-only + // values this function will return true (1) even though assignment failed. /// int (CEF_CALLBACK *set_value_byaccessor)(struct _cef_v8value_t* self, const cef_string_t* key, enum cef_v8_accesscontrol_t settings, @@ -461,7 +539,15 @@ typedef struct _cef_v8value_t { cef_string_list_t keys); /// - // Returns the user data, if any, specified when the object was created. + // Sets the user data for this object and returns true (1) on success. Returns + // false (0) if this function is called incorrectly. This function can only be + // called on user created objects. + /// + int (CEF_CALLBACK *set_user_data)(struct _cef_v8value_t* self, + struct _cef_base_t* user_data); + + /// + // Returns the user data, if any, assigned to this object. /// struct _cef_base_t* (CEF_CALLBACK *get_user_data)( struct _cef_v8value_t* self); @@ -482,7 +568,7 @@ typedef struct _cef_v8value_t { // global total by the appropriate amount on its destruction. // |change_in_bytes| specifies the number of bytes to adjust by. This function // returns the number of bytes associated with the object after the - // adjustment. + // adjustment. This function can only be called on user created objects. /// int (CEF_CALLBACK *adjust_externally_allocated_memory)( struct _cef_v8value_t* self, int change_in_bytes); @@ -516,32 +602,28 @@ typedef struct _cef_v8value_t { // only be called from within the scope of a cef_v8handler_t or // cef_v8accessor_t callback, or in combination with calling enter() and // exit() on a stored cef_v8context_t reference. |object| is the receiver - // ('this' object) of the function. |arguments| is the list of arguments that - // will be passed to the function. If execution succeeds |retval| will be set - // to the function return value. If execution fails |exception| will be set to - // the exception that was thrown. If |rethrow_exception| is true (1) any - // exception will also be re- thrown. This function returns false (0) if - // called incorrectly. + // ('this' object) of the function. If |object| is NULL the current context's + // global object will be used. |arguments| is the list of arguments that will + // be passed to the function. Returns the function return value on success. + // Returns NULL if this function is called incorrectly or an exception is + // thrown. /// - int (CEF_CALLBACK *execute_function)(struct _cef_v8value_t* self, - struct _cef_v8value_t* object, size_t argumentsCount, - struct _cef_v8value_t* const* arguments, struct _cef_v8value_t** retval, - struct _cef_v8exception_t** exception, int rethrow_exception); + struct _cef_v8value_t* (CEF_CALLBACK *execute_function)( + struct _cef_v8value_t* self, struct _cef_v8value_t* object, + size_t argumentsCount, struct _cef_v8value_t* const* arguments); /// // Execute the function using the specified V8 context. |object| is the - // receiver ('this' object) of the function. |arguments| is the list of - // arguments that will be passed to the function. If execution succeeds - // |retval| will be set to the function return value. If execution fails - // |exception| will be set to the exception that was thrown. If - // |rethrow_exception| is true (1) any exception will also be re-thrown. This - // function returns false (0) if called incorrectly. + // receiver ('this' object) of the function. If |object| is NULL the specified + // context's global object will be used. |arguments| is the list of arguments + // that will be passed to the function. Returns the function return value on + // success. Returns NULL if this function is called incorrectly or an + // exception is thrown. /// - int (CEF_CALLBACK *execute_function_with_context)(struct _cef_v8value_t* self, - struct _cef_v8context_t* context, struct _cef_v8value_t* object, - size_t argumentsCount, struct _cef_v8value_t* const* arguments, - struct _cef_v8value_t** retval, struct _cef_v8exception_t** exception, - int rethrow_exception); + struct _cef_v8value_t* (CEF_CALLBACK *execute_function_with_context)( + struct _cef_v8value_t* self, struct _cef_v8context_t* context, + struct _cef_v8value_t* object, size_t argumentsCount, + struct _cef_v8value_t* const* arguments); } cef_v8value_t; @@ -563,7 +645,12 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_bool(int value); /// // Create a new cef_v8value_t object of type int. /// -CEF_EXPORT cef_v8value_t* cef_v8value_create_int(int value); +CEF_EXPORT cef_v8value_t* cef_v8value_create_int(int32 value); + +/// +// Create a new cef_v8value_t object of type unsigned int. +/// +CEF_EXPORT cef_v8value_t* cef_v8value_create_uint(uint32 value); /// // Create a new cef_v8value_t object of type double. @@ -571,7 +658,10 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_int(int value); CEF_EXPORT cef_v8value_t* cef_v8value_create_double(double value); /// -// Create a new cef_v8value_t object of type Date. +// Create a new cef_v8value_t object of type Date. This function should only be +// called from within the scope of a cef_v8context_tHandler, cef_v8handler_t or +// cef_v8accessor_t callback, or in combination with calling enter() and exit() +// on a stored cef_v8context_t reference. /// CEF_EXPORT cef_v8value_t* cef_v8value_create_date(const cef_time_t* date); @@ -581,22 +671,22 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_date(const cef_time_t* date); CEF_EXPORT cef_v8value_t* cef_v8value_create_string(const cef_string_t* value); /// -// Create a new cef_v8value_t object of type object with optional user data and -// accessor. This function should only be called from within the scope of a +// Create a new cef_v8value_t object of type object with optional accessor. This +// function should only be called from within the scope of a // cef_v8context_tHandler, cef_v8handler_t or cef_v8accessor_t callback, or in // combination with calling enter() and exit() on a stored cef_v8context_t // reference. /// -CEF_EXPORT cef_v8value_t* cef_v8value_create_object_with_accessor( - cef_base_t* user_data, cef_v8accessor_t* accessor); +CEF_EXPORT cef_v8value_t* cef_v8value_create_object(cef_v8accessor_t* accessor); /// -// Create a new cef_v8value_t object of type array. This function should only be -// called from within the scope of a cef_v8context_tHandler, cef_v8handler_t or -// cef_v8accessor_t callback, or in combination with calling enter() and exit() -// on a stored cef_v8context_t reference. +// Create a new cef_v8value_t object of type array with the specified |length|. +// If |length| is negative the returned array will have length 0. This function +// should only be called from within the scope of a cef_v8context_tHandler, +// cef_v8handler_t or cef_v8accessor_t callback, or in combination with calling +// enter() and exit() on a stored cef_v8context_t reference. /// -CEF_EXPORT cef_v8value_t* cef_v8value_create_array(); +CEF_EXPORT cef_v8value_t* cef_v8value_create_array(int length); /// // Create a new cef_v8value_t object of type function. This function should only diff --git a/cef1/include/cef_storage.h b/cef1/include/cef_storage.h deleted file mode 100644 index 869595159..000000000 --- a/cef1/include/cef_storage.h +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2011 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. -// -// --------------------------------------------------------------------------- -// -// The contents of this file must follow a specific format in order to -// support the CEF translator tool. See the translator.README.txt file in the -// tools directory for more information. -// - -#ifndef CEF_INCLUDE_CEF_STORAGE_H_ -#define CEF_INCLUDE_CEF_STORAGE_H_ -#pragma once - -#include "include/cef_base.h" - -class CefStorageVisitor; - -typedef cef_storage_type_t CefStorageType; - -/// -// Visit storage of the specified type. If |origin| is non-empty only data -// matching that origin will be visited. If |key| is non-empty only data -// matching that key will be visited. Otherwise, all data for the storage -// type will be visited. Origin should be of the form scheme://domain. If no -// origin is specified only data currently in memory will be returned. Returns -// false if the storage cannot be accessed. -/// -/*--cef(optional_param=origin,optional_param=key)--*/ -bool CefVisitStorage(CefStorageType type, const CefString& origin, - const CefString& key, - CefRefPtr visitor); - -/// -// Sets storage of the specified type, origin, key and value. Returns false if -// storage cannot be accessed. This method must be called on the UI thread. -/// -/*--cef()--*/ -bool CefSetStorage(CefStorageType type, const CefString& origin, - const CefString& key, const CefString& value); - -/// -// Deletes all storage of the specified type. If |origin| is non-empty only data -// matching that origin will be cleared. If |key| is non-empty only data -// matching that key will be cleared. Otherwise, all data for the storage type -// will be cleared. Returns false if storage cannot be accessed. This method -// must be called on the UI thread. -/// -/*--cef(optional_param=origin,optional_param=key)--*/ -bool CefDeleteStorage(CefStorageType type, const CefString& origin, - const CefString& key); - -/// -// Sets the directory path that will be used for storing data of the specified -// type. Currently only the ST_LOCALSTORAGE type is supported by this method. -// If |path| is empty data will be stored in memory only. By default the storage -// path is the same as the cache path. Returns false if the storage cannot be -// accessed. -/// -/*--cef(optional_param=path)--*/ -bool CefSetStoragePath(CefStorageType type, const CefString& path); - - -/// -// Interface to implement for visiting storage. The methods of this class will -// always be called on the UI thread. -/// -/*--cef(source=client)--*/ -class CefStorageVisitor : public virtual CefBase { - public: - /// - // Method that will be called once for each key/value data pair in storage. - // |count| is the 0-based index for the current pair. |total| is the total - // number of pairs. Set |deleteData| to true to delete the pair currently - // being visited. Return false to stop visiting pairs. This method may never - // be called if no data is found. - /// - /*--cef()--*/ - virtual bool Visit(CefStorageType type, const CefString& origin, - const CefString& key, const CefString& value, int count, - int total, bool& deleteData) =0; -}; - -#endif // CEF_INCLUDE_CEF_STORAGE_H_ diff --git a/cef1/include/cef_v8.h b/cef1/include/cef_v8.h index 6024ce4a9..9f6e198ec 100644 --- a/cef1/include/cef_v8.h +++ b/cef1/include/cef_v8.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 Marshall A. Greenblatt. All rights reserved. +// Copyright (c) 2012 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 @@ -44,6 +44,7 @@ #include "include/cef_frame.h" #include +class CefV8Exception; class CefV8Handler; class CefV8Value; @@ -114,7 +115,8 @@ bool CefRegisterExtension(const CefString& extension_name, /// -// Class that encapsulates a V8 context handle. +// Class that encapsulates a V8 context handle. The methods of this class may +// only be called on the UI thread. /// /*--cef(source=library)--*/ class CefV8Context : public virtual CefBase { @@ -150,17 +152,18 @@ class CefV8Context : public virtual CefBase { virtual CefRefPtr GetFrame() =0; /// - // Returns the global object for this context. + // Returns the global object for this context. The context must be entered + // before calling this method. /// /*--cef()--*/ virtual CefRefPtr GetGlobal() =0; /// // Enter this context. A context must be explicitly entered before creating a - // V8 Object, Array or Function asynchronously. Exit() must be called the same - // number of times as Enter() before releasing this context. V8 objects belong - // to the context in which they are created. Returns true if the scope was - // entered successfully. + // V8 Object, Array, Function or Date asynchronously. Exit() must be called + // the same number of times as Enter() before releasing this context. V8 + // objects belong to the context in which they are created. Returns true if + // the scope was entered successfully. /// /*--cef()--*/ virtual bool Enter() =0; @@ -178,6 +181,17 @@ class CefV8Context : public virtual CefBase { /// /*--cef()--*/ virtual bool IsSame(CefRefPtr that) =0; + + /// + // Evaluates the specified JavaScript code using this context's global object. + // On success |retval| will be set to the return value, if any, and the + // function will return true. On failure |exception| will be set to the + // exception, if any, and the function will return false. + /// + /*--cef()--*/ + virtual bool Eval(const CefString& code, + CefRefPtr& retval, + CefRefPtr& exception) =0; }; @@ -302,8 +316,8 @@ class CefV8Exception : public virtual CefBase { }; /// -// Class representing a V8 value. The methods of this class should only be -// called on the UI thread. +// Class representing a V8 value. The methods of this class may only be called +// on the UI thread. /// /*--cef(source=library)--*/ class CefV8Value : public virtual CefBase { @@ -316,55 +330,72 @@ class CefV8Value : public virtual CefBase { /// /*--cef()--*/ static CefRefPtr CreateUndefined(); + /// // Create a new CefV8Value object of type null. /// /*--cef()--*/ static CefRefPtr CreateNull(); + /// // Create a new CefV8Value object of type bool. /// /*--cef()--*/ static CefRefPtr CreateBool(bool value); + /// // Create a new CefV8Value object of type int. /// /*--cef()--*/ - static CefRefPtr CreateInt(int value); + static CefRefPtr CreateInt(int32 value); + + /// + // Create a new CefV8Value object of type unsigned int. + /// + /*--cef()--*/ + static CefRefPtr CreateUInt(uint32 value); + /// // Create a new CefV8Value object of type double. /// /*--cef()--*/ static CefRefPtr CreateDouble(double value); + /// - // Create a new CefV8Value object of type Date. - /// - /*--cef()--*/ - static CefRefPtr CreateDate(const CefTime& date); - /// - // Create a new CefV8Value object of type string. - /// - /*--cef(optional_param=value)--*/ - static CefRefPtr CreateString(const CefString& value); - /// - // Create a new CefV8Value object of type object with optional user data and - // accessor. This method should only be called from within the scope of a - // CefV8ContextHandler, CefV8Handler or CefV8Accessor callback, or in - // combination with calling Enter() and Exit() on a stored CefV8Context - // reference. - /// - /*--cef(capi_name=cef_v8value_create_object_with_accessor, - optional_param=user_data,optional_param=accessor)--*/ - static CefRefPtr CreateObject(CefRefPtr user_data, - CefRefPtr accessor); - /// - // Create a new CefV8Value object of type array. This method should only be + // Create a new CefV8Value object of type Date. This method should only be // called from within the scope of a CefV8ContextHandler, CefV8Handler or // CefV8Accessor callback, or in combination with calling Enter() and Exit() // on a stored CefV8Context reference. /// /*--cef()--*/ - static CefRefPtr CreateArray(); + static CefRefPtr CreateDate(const CefTime& date); + + /// + // Create a new CefV8Value object of type string. + /// + /*--cef(optional_param=value)--*/ + static CefRefPtr CreateString(const CefString& value); + + /// + // Create a new CefV8Value object of type object with optional accessor. This + // method should only be called from within the scope of a + // CefV8ContextHandler, CefV8Handler or CefV8Accessor callback, or in + // combination with calling Enter() and Exit() on a stored CefV8Context + // reference. + /// + /*--cef(optional_param=accessor)--*/ + static CefRefPtr CreateObject(CefRefPtr accessor); + + /// + // Create a new CefV8Value object of type array with the specified |length|. + // If |length| is negative the returned array will have length 0. This method + // should only be called from within the scope of a CefV8ContextHandler, + // CefV8Handler or CefV8Accessor callback, or in combination with calling + // Enter() and Exit() on a stored CefV8Context reference. + /// + /*--cef()--*/ + static CefRefPtr CreateArray(int length); + /// // Create a new CefV8Value object of type function. This method should only be // called from within the scope of a CefV8ContextHandler, CefV8Handler or @@ -380,46 +411,61 @@ class CefV8Value : public virtual CefBase { /// /*--cef()--*/ virtual bool IsUndefined() =0; + /// // True if the value type is null. /// /*--cef()--*/ virtual bool IsNull() =0; + /// // True if the value type is bool. /// /*--cef()--*/ virtual bool IsBool() =0; + /// // True if the value type is int. /// /*--cef()--*/ virtual bool IsInt() =0; + + /// + // True if the value type is unsigned int. + /// + /*--cef()--*/ + virtual bool IsUInt() =0; + /// // True if the value type is double. /// /*--cef()--*/ virtual bool IsDouble() =0; + /// // True if the value type is Date. /// /*--cef()--*/ virtual bool IsDate() =0; + /// // True if the value type is string. /// /*--cef()--*/ virtual bool IsString() =0; + /// // True if the value type is object. /// /*--cef()--*/ virtual bool IsObject() =0; + /// // True if the value type is array. /// /*--cef()--*/ virtual bool IsArray() =0; + /// // True if the value type is function. /// @@ -439,24 +485,35 @@ class CefV8Value : public virtual CefBase { /// /*--cef()--*/ virtual bool GetBoolValue() =0; + /// // Return an int value. The underlying data will be converted to if // necessary. /// /*--cef()--*/ - virtual int GetIntValue() =0; + virtual int32 GetIntValue() =0; + + /// + // Return an unisgned int value. The underlying data will be converted to if + // necessary. + /// + /*--cef()--*/ + virtual uint32 GetUIntValue() =0; + /// // Return a double value. The underlying data will be converted to if // necessary. /// /*--cef()--*/ virtual double GetDoubleValue() =0; + /// // Return a Date value. The underlying data will be converted to if // necessary. /// /*--cef()--*/ virtual CefTime GetDateValue() =0; + /// // Return a string value. The underlying data will be converted to if // necessary. @@ -469,11 +526,55 @@ class CefV8Value : public virtual CefBase { // functions are also objects. String- and integer-based keys can be used // interchangably with the framework converting between them as necessary. + /// + // Returns true if this is a user created object. + /// + /*--cef()--*/ + virtual bool IsUserCreated() =0; + + /// + // Returns true if the last method call resulted in an exception. This + // attribute exists only in the scope of the current CEF value object. + /// + /*--cef()--*/ + virtual bool HasException() =0; + + /// + // Returns the exception resulting from the last method call. This attribute + // exists only in the scope of the current CEF value object. + /// + /*--cef()--*/ + virtual CefRefPtr GetException() =0; + + /// + // Clears the last exception and returns true on success. + /// + /*--cef()--*/ + virtual bool ClearException() =0; + + /// + // Returns true if this object will re-throw future exceptions. This attribute + // exists only in the scope of the current CEF value object. + /// + /*--cef()--*/ + virtual bool WillRethrowExceptions() =0; + + /// + // Set whether this object will re-throw future exceptions. By default + // exceptions are not re-thrown. If a exception is re-thrown the current + // context should not be accessed again until after the exception has been + // caught and not re-thrown. Returns true on success. This attribute exists + // only in the scope of the current CEF value object. + /// + /*--cef()--*/ + virtual bool SetRethrowExceptions(bool rethrow) =0; + /// // Returns true if the object has a value with the specified identifier. /// /*--cef(capi_name=has_value_bykey)--*/ virtual bool HasValue(const CefString& key) =0; + /// // Returns true if the object has a value with the specified identifier. /// @@ -481,42 +582,62 @@ class CefV8Value : public virtual CefBase { virtual bool HasValue(int index) =0; /// - // Delete the value with the specified identifier. + // Deletes the value with the specified identifier and returns true on + // success. Returns false if this method is called incorrectly or an exception + // is thrown. For read-only and don't-delete values this method will return + // true even though deletion failed. /// /*--cef(capi_name=delete_value_bykey)--*/ virtual bool DeleteValue(const CefString& key) =0; + /// - // Delete the value with the specified identifier. + // Deletes the value with the specified identifier and returns true on + // success. Returns false if this method is called incorrectly, deletion fails + // or an exception is thrown. For read-only and don't-delete values this + // method will return true even though deletion failed. /// /*--cef(capi_name=delete_value_byindex,index_param=index)--*/ virtual bool DeleteValue(int index) =0; /// - // Returns the value with the specified identifier. + // Returns the value with the specified identifier on success. Returns NULL + // if this method is called incorrectly or an exception is thrown. /// /*--cef(capi_name=get_value_bykey)--*/ virtual CefRefPtr GetValue(const CefString& key) =0; + /// - // Returns the value with the specified identifier. + // Returns the value with the specified identifier on success. Returns NULL + // if this method is called incorrectly or an exception is thrown. /// /*--cef(capi_name=get_value_byindex,index_param=index)--*/ virtual CefRefPtr GetValue(int index) =0; /// - // Associate a value with the specified identifier. + // Associates a value with the specified identifier and returns true on + // success. Returns false if this method is called incorrectly or an exception + // is thrown. For read-only values this method will return true even though + // assignment failed. /// /*--cef(capi_name=set_value_bykey)--*/ virtual bool SetValue(const CefString& key, CefRefPtr value, PropertyAttribute attribute) =0; + /// - // Associate a value with the specified identifier. + // Associates a value with the specified identifier and returns true on + // success. Returns false if this method is called incorrectly or an exception + // is thrown. For read-only values this method will return true even though + // assignment failed. /// /*--cef(capi_name=set_value_byindex,index_param=index)--*/ virtual bool SetValue(int index, CefRefPtr value) =0; /// - // Register an identifier whose access will be forwarded to the CefV8Accessor - // instance passed to CefV8Value::CreateObject(). + // Registers an identifier and returns true on success. Access to the + // identifier will be forwarded to the CefV8Accessor instance passed to + // CefV8Value::CreateObject(). Returns false if this method is called + // incorrectly or an exception is thrown. For read-only values this method + // will return true even though assignment failed. /// /*--cef(capi_name=set_value_byaccessor)--*/ virtual bool SetValue(const CefString& key, AccessControl settings, @@ -530,7 +651,15 @@ class CefV8Value : public virtual CefBase { virtual bool GetKeys(std::vector& keys) =0; /// - // Returns the user data, if any, specified when the object was created. + // Sets the user data for this object and returns true on success. Returns + // false if this method is called incorrectly. This method can only be called + // on user created objects. + /// + /*--cef(optional_param=user_data)--*/ + virtual bool SetUserData(CefRefPtr user_data) =0; + + /// + // Returns the user data, if any, assigned to this object. /// /*--cef()--*/ virtual CefRefPtr GetUserData() =0; @@ -550,7 +679,8 @@ class CefV8Value : public virtual CefBase { // external memory associated with it and automatically decreases the global // total by the appropriate amount on its destruction. |change_in_bytes| // specifies the number of bytes to adjust by. This method returns the number - // of bytes associated with the object after the adjustment. + // of bytes associated with the object after the adjustment. This method can + // only be called on user created objects. /// /*--cef()--*/ virtual int AdjustExternallyAllocatedMemory(int change_in_bytes) =0; @@ -584,35 +714,29 @@ class CefV8Value : public virtual CefBase { // be called from within the scope of a CefV8Handler or CefV8Accessor // callback, or in combination with calling Enter() and Exit() on a stored // CefV8Context reference. |object| is the receiver ('this' object) of the - // function. |arguments| is the list of arguments that will be passed to the - // function. If execution succeeds |retval| will be set to the function return - // value. If execution fails |exception| will be set to the exception that was - // thrown. If |rethrow_exception| is true any exception will also be re- - // thrown. This method returns false if called incorrectly. + // function. If |object| is empty the current context's global object will be + // used. |arguments| is the list of arguments that will be passed to the + // function. Returns the function return value on success. Returns NULL if + // this method is called incorrectly or an exception is thrown. /// /*--cef(optional_param=object)--*/ - virtual bool ExecuteFunction(CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefRefPtr& exception, - bool rethrow_exception) =0; + virtual CefRefPtr ExecuteFunction( + CefRefPtr object, + const CefV8ValueList& arguments) =0; /// // Execute the function using the specified V8 context. |object| is the - // receiver ('this' object) of the function. |arguments| is the list of - // arguments that will be passed to the function. If execution succeeds - // |retval| will be set to the function return value. If execution fails - // |exception| will be set to the exception that was thrown. If - // |rethrow_exception| is true any exception will also be re-thrown. This - // method returns false if called incorrectly. + // receiver ('this' object) of the function. If |object| is empty the + // specified context's global object will be used. |arguments| is the list of + // arguments that will be passed to the function. Returns the function return + // value on success. Returns NULL if this method is called incorrectly or an + // exception is thrown. /// /*--cef(optional_param=object)--*/ - virtual bool ExecuteFunctionWithContext(CefRefPtr context, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefRefPtr& exception, - bool rethrow_exception) =0; + virtual CefRefPtr ExecuteFunctionWithContext( + CefRefPtr context, + CefRefPtr object, + const CefV8ValueList& arguments) =0; }; #endif // CEF_INCLUDE_CEF_V8_H_ diff --git a/cef1/include/internal/cef_types.h b/cef1/include/internal/cef_types.h index 2e11a20ae..f2ee43852 100644 --- a/cef1/include/internal/cef_types.h +++ b/cef1/include/internal/cef_types.h @@ -61,6 +61,20 @@ typedef long long int64; // NOLINT(runtime/int) typedef unsigned long long uint64; // NOLINT(runtime/int) #endif +// TODO: Remove these type guards. These are to avoid conflicts with +// obsolete/protypes.h in the Gecko SDK. +#ifndef _INT32 +#define _INT32 +typedef int int32; +#endif + +// TODO: Remove these type guards. These are to avoid conflicts with +// obsolete/protypes.h in the Gecko SDK. +#ifndef _UINT32 +#define _UINT32 +typedef unsigned int uint32; +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/cef1/libcef/browser_dom_storage_system.cc b/cef1/libcef/browser_dom_storage_system.cc new file mode 100644 index 000000000..c2de1823b --- /dev/null +++ b/cef1/libcef/browser_dom_storage_system.cc @@ -0,0 +1,291 @@ +// Copyright (c) 2012 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 "libcef/browser_dom_storage_system.h" + +#include "base/auto_reset.h" +#include "googleurl/src/gurl.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h" +#include "webkit/database/database_util.h" +#include "webkit/dom_storage/dom_storage_area.h" +#include "webkit/dom_storage/dom_storage_host.h" + +using dom_storage::DomStorageContext; +using dom_storage::DomStorageHost; +using dom_storage::DomStorageSession; +using webkit_database::DatabaseUtil; +using WebKit::WebStorageArea; +using WebKit::WebStorageNamespace; +using WebKit::WebStorageEventDispatcher; +using WebKit::WebString; +using WebKit::WebURL; + +namespace { +const int kInvalidNamespaceId = -1; +} + +class BrowserDomStorageSystem::NamespaceImpl : public WebStorageNamespace { + public: + explicit NamespaceImpl(const base::WeakPtr& parent); + NamespaceImpl(const base::WeakPtr& parent, + int session_namespace_id); + virtual ~NamespaceImpl(); + virtual WebStorageArea* createStorageArea(const WebString& origin) OVERRIDE; + virtual WebStorageNamespace* copy() OVERRIDE; + virtual bool isSameNamespace(const WebStorageNamespace&) const OVERRIDE; + + private: + DomStorageContext* Context() { + if (!parent_.get()) + return NULL; + return parent_->context_.get(); + } + + base::WeakPtr parent_; + int namespace_id_; +}; + +class BrowserDomStorageSystem::AreaImpl : public WebStorageArea { + public: + AreaImpl(const base::WeakPtr& parent, + int namespace_id, const GURL& origin); + virtual ~AreaImpl(); + virtual unsigned length() OVERRIDE; + virtual WebString key(unsigned index) OVERRIDE; + virtual WebString getItem(const WebString& key) OVERRIDE; + virtual void setItem(const WebString& key, const WebString& newValue, + const WebURL&, Result&, WebString& oldValue) OVERRIDE; + virtual void removeItem(const WebString& key, const WebURL& url, + WebString& oldValue) OVERRIDE; + virtual void clear(const WebURL& url, bool& somethingCleared) OVERRIDE; + + private: + DomStorageHost* Host() { + if (!parent_.get()) + return NULL; + return parent_->host_.get(); + } + + base::WeakPtr parent_; + int connection_id_; +}; + +// NamespaceImpl ----------------------------- + +BrowserDomStorageSystem::NamespaceImpl::NamespaceImpl( + const base::WeakPtr& parent) + : parent_(parent), + namespace_id_(dom_storage::kLocalStorageNamespaceId) { +} + +BrowserDomStorageSystem::NamespaceImpl::NamespaceImpl( + const base::WeakPtr& parent, + int session_namespace_id) + : parent_(parent), + namespace_id_(session_namespace_id) { +} + +BrowserDomStorageSystem::NamespaceImpl::~NamespaceImpl() { + if (namespace_id_ == dom_storage::kLocalStorageNamespaceId || + namespace_id_ == kInvalidNamespaceId || !Context()) { + return; + } + Context()->DeleteSessionNamespace(namespace_id_); +} + +WebStorageArea* BrowserDomStorageSystem::NamespaceImpl::createStorageArea( + const WebString& origin) { + return new AreaImpl(parent_, namespace_id_, GURL(origin)); +} + +WebStorageNamespace* BrowserDomStorageSystem::NamespaceImpl::copy() { + DCHECK_NE(dom_storage::kLocalStorageNamespaceId, namespace_id_); + int new_id = kInvalidNamespaceId; + if (Context()) { + new_id = Context()->AllocateSessionId(); + Context()->CloneSessionNamespace(namespace_id_, new_id); + } + return new NamespaceImpl(parent_, new_id); +} + +bool BrowserDomStorageSystem::NamespaceImpl::isSameNamespace( + const WebStorageNamespace& other) const { + const NamespaceImpl* other_impl = static_cast(&other); + return namespace_id_ == other_impl->namespace_id_; +} + +// AreaImpl ----------------------------- + +BrowserDomStorageSystem::AreaImpl::AreaImpl( + const base::WeakPtr& parent, + int namespace_id, const GURL& origin) + : parent_(parent), + connection_id_(0) { + if (Host()) { + connection_id_ = (parent_->next_connection_id_)++; + Host()->OpenStorageArea(connection_id_, namespace_id, origin); + } +} + +BrowserDomStorageSystem::AreaImpl::~AreaImpl() { + if (Host()) + Host()->CloseStorageArea(connection_id_); +} + +unsigned BrowserDomStorageSystem::AreaImpl::length() { + if (Host()) + return Host()->GetAreaLength(connection_id_); + return 0; +} + +WebString BrowserDomStorageSystem::AreaImpl::key(unsigned index) { + if (Host()) + return Host()->GetAreaKey(connection_id_, index); + return NullableString16(true); +} + +WebString BrowserDomStorageSystem::AreaImpl::getItem(const WebString& key) { + if (Host()) + return Host()->GetAreaItem(connection_id_, key); + return NullableString16(true); +} + +void BrowserDomStorageSystem::AreaImpl::setItem( + const WebString& key, const WebString& newValue, + const WebURL& pageUrl, Result& result, WebString& oldValue) { + result = ResultBlockedByQuota; + oldValue = NullableString16(true); + if (!Host()) + return; + + AutoReset auto_reset(&parent_->area_being_processed_, this); + NullableString16 old_value; + if (!Host()->SetAreaItem(connection_id_, key, newValue, pageUrl, + &old_value)) + return; + + result = ResultOK; + oldValue = old_value; +} + +void BrowserDomStorageSystem::AreaImpl::removeItem( + const WebString& key, const WebURL& pageUrl, WebString& oldValue) { + oldValue = NullableString16(true); + if (!Host()) + return; + + AutoReset auto_reset(&parent_->area_being_processed_, this); + string16 old_value; + if (!Host()->RemoveAreaItem(connection_id_, key, pageUrl, &old_value)) + return; + + oldValue = old_value; +} + +void BrowserDomStorageSystem::AreaImpl::clear( + const WebURL& pageUrl, bool& somethingCleared) { + if (Host()) { + AutoReset auto_reset(&parent_->area_being_processed_, this); + somethingCleared = Host()->ClearArea(connection_id_, pageUrl); + return; + } + somethingCleared = false; +} + +// BrowserDomStorageSystem ----------------------------- + +BrowserDomStorageSystem* BrowserDomStorageSystem::g_instance_; + +BrowserDomStorageSystem::BrowserDomStorageSystem() + : weak_factory_(this), + context_(new DomStorageContext(FilePath(), FilePath(), NULL, NULL)), + host_(new DomStorageHost(context_)), + area_being_processed_(NULL), + next_connection_id_(1) { + DCHECK(!g_instance_); + g_instance_ = this; + context_->AddEventObserver(this); +} + +BrowserDomStorageSystem::~BrowserDomStorageSystem() { + g_instance_ = NULL; + host_.reset(); + context_->RemoveEventObserver(this); +} + +WebStorageNamespace* BrowserDomStorageSystem::CreateLocalStorageNamespace() { + return new NamespaceImpl(weak_factory_.GetWeakPtr()); +} + +WebStorageNamespace* BrowserDomStorageSystem::CreateSessionStorageNamespace() { + int id = context_->AllocateSessionId(); + context_->CreateSessionNamespace(id); + return new NamespaceImpl(weak_factory_.GetWeakPtr(), id); +} + +void BrowserDomStorageSystem::OnDomStorageItemSet( + const dom_storage::DomStorageArea* area, + const string16& key, + const string16& new_value, + const NullableString16& old_value, + const GURL& page_url) { + DispatchDomStorageEvent(area, page_url, + NullableString16(key, false), + NullableString16(new_value, false), + old_value); +} + +void BrowserDomStorageSystem::OnDomStorageItemRemoved( + const dom_storage::DomStorageArea* area, + const string16& key, + const string16& old_value, + const GURL& page_url) { + DispatchDomStorageEvent(area, page_url, + NullableString16(key, false), + NullableString16(true), + NullableString16(old_value, false)); +} + +void BrowserDomStorageSystem::OnDomStorageAreaCleared( + const dom_storage::DomStorageArea* area, + const GURL& page_url) { + DispatchDomStorageEvent(area, page_url, + NullableString16(true), + NullableString16(true), + NullableString16(true)); +} + +void BrowserDomStorageSystem::DispatchDomStorageEvent( + const dom_storage::DomStorageArea* area, + const GURL& page_url, + const NullableString16& key, + const NullableString16& new_value, + const NullableString16& old_value) { + DCHECK(area_being_processed_); + if (area->namespace_id() == dom_storage::kLocalStorageNamespaceId) { + WebStorageEventDispatcher::dispatchLocalStorageEvent( + key, + old_value, + new_value, + area->origin(), + page_url, + area_being_processed_, + true /* originatedInProcess */); + } else { + NamespaceImpl session_namespace_for_event_dispatch( + base::WeakPtr(), area->namespace_id()); + WebStorageEventDispatcher::dispatchSessionStorageEvent( + key, + old_value, + new_value, + area->origin(), + page_url, + session_namespace_for_event_dispatch, + area_being_processed_, + true /* originatedInProcess */); + } +} diff --git a/cef1/libcef/browser_dom_storage_system.h b/cef1/libcef/browser_dom_storage_system.h new file mode 100644 index 000000000..0bcdb0a60 --- /dev/null +++ b/cef1/libcef/browser_dom_storage_system.h @@ -0,0 +1,80 @@ +// Copyright (c) 2012 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 CEF_LIBCEF_BROWSER_DOM_STORAGE_SYSTEM_H_ +#define CEF_LIBCEF_BROWSER_DOM_STORAGE_SYSTEM_H_ +#pragma once + +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "webkit/dom_storage/dom_storage_context.h" + +namespace dom_storage { +class DomStorageHost; +} +namespace WebKit { +class WebStorageNamespace; +} + +// Class that composes dom_storage classes together for use +// in simple single process environments like test_shell and DRT. +class BrowserDomStorageSystem + : public dom_storage::DomStorageContext::EventObserver { + public: + static BrowserDomStorageSystem& instance() { return *g_instance_; } + + BrowserDomStorageSystem(); + virtual ~BrowserDomStorageSystem(); + + // The Create<<>> calls are bound to WebKit api that the embedder + // is responsible for implementing. These factories are called strictly + // on the 'main' webkit thread. Ditto the methods on the returned + // objects. SimplDomStorageSystem manufactures implementations of the + // WebStorageNamespace and WebStorageArea interfaces that ultimately + // plumb Get, Set, Remove, and Clear javascript calls to the dom_storage + // classes. The caller (webkit/webcore) takes ownership of the returned + // instances and will delete them when done. + WebKit::WebStorageNamespace* CreateLocalStorageNamespace(); + WebKit::WebStorageNamespace* CreateSessionStorageNamespace(); + + private: + // Inner classes that implement the WebKit WebStorageNamespace and + // WebStorageArea interfaces in terms of dom_storage classes. + class NamespaceImpl; + class AreaImpl; + + // DomStorageContext::EventObserver implementation which + // calls into webkit/webcore to dispatch events. + virtual void OnDomStorageItemSet( + const dom_storage::DomStorageArea* area, + const string16& key, + const string16& new_value, + const NullableString16& old_value, + const GURL& page_url) OVERRIDE; + virtual void OnDomStorageItemRemoved( + const dom_storage::DomStorageArea* area, + const string16& key, + const string16& old_value, + const GURL& page_url) OVERRIDE; + virtual void OnDomStorageAreaCleared( + const dom_storage::DomStorageArea* area, + const GURL& page_url) OVERRIDE; + + void DispatchDomStorageEvent( + const dom_storage::DomStorageArea* area, + const GURL& page_url, + const NullableString16& key, + const NullableString16& new_value, + const NullableString16& old_value); + + base::WeakPtrFactory weak_factory_; + scoped_refptr context_; + scoped_ptr host_; + AreaImpl* area_being_processed_; + int next_connection_id_; + + static BrowserDomStorageSystem* g_instance_; +}; + +#endif // CEF_LIBCEF_BROWSER_DOM_STORAGE_SYSTEM_H_ diff --git a/cef1/libcef/browser_file_system.cc b/cef1/libcef/browser_file_system.cc index 8a188fd3c..25a6351dc 100644 --- a/cef1/libcef/browser_file_system.cc +++ b/cef1/libcef/browser_file_system.cc @@ -210,9 +210,7 @@ void BrowserFileSystem::CleanupOnIOThread() { FileSystemOperationInterface* BrowserFileSystem::GetNewOperation( const WebURL& url) { - return file_system_context_->CreateFileSystemOperation( - GURL(url), - base::MessageLoopProxy::current()); + return file_system_context_->CreateFileSystemOperation(GURL(url)); } FileSystemOperationInterface::StatusCallback diff --git a/cef1/libcef/browser_file_writer.cc b/cef1/libcef/browser_file_writer.cc index 39f577728..9acff66fe 100644 --- a/cef1/libcef/browser_file_writer.cc +++ b/cef1/libcef/browser_file_writer.cc @@ -37,9 +37,6 @@ class BrowserFileWriter::IOThreadProxy main_thread_ = base::MessageLoopProxy::current(); } - virtual ~IOThreadProxy() { - } - void Truncate(const GURL& path, int64 offset) { if (!io_thread_->BelongsToCurrentThread()) { io_thread_->PostTask( @@ -82,8 +79,11 @@ class BrowserFileWriter::IOThreadProxy } private: + friend class base::RefCountedThreadSafe; + virtual ~IOThreadProxy() {} + FileSystemOperationInterface* GetNewOperation(const GURL& path) { - return file_system_context_->CreateFileSystemOperation(path, io_thread_); + return file_system_context_->CreateFileSystemOperation(path); } void DidSucceedOnMainThread() { diff --git a/cef1/libcef/browser_impl.cc b/cef1/libcef/browser_impl.cc index 14a44bc9f..a4e25242a 100644 --- a/cef1/libcef/browser_impl.cc +++ b/cef1/libcef/browser_impl.cc @@ -180,8 +180,8 @@ CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo, popup_delegate_.reset(new BrowserWebViewDelegate(this)); nav_controller_.reset(new BrowserNavigationController(this)); - request_context_proxy_ = - new BrowserRequestContextProxy(_Context->request_context(), this); + request_context_proxy_.reset( + new BrowserRequestContextProxy(_Context->request_context(), this)); if (!file_system_root_.CreateUniqueTempDir()) { LOG(WARNING) << "Failed to create a temp dir for the filesystem." @@ -785,7 +785,7 @@ void CefBrowserImpl::UIT_DestroyBrowser() { UIT_ClearMainWndHandle(); main_frame_ = NULL; - request_context_proxy_ = NULL; + request_context_proxy_.reset(NULL); // Remove the reference added in UIT_CreateBrowser(). Release(); diff --git a/cef1/libcef/browser_impl.h b/cef1/libcef/browser_impl.h index 2fcb0b3e0..9211ddc7b 100644 --- a/cef1/libcef/browser_impl.h +++ b/cef1/libcef/browser_impl.h @@ -357,7 +357,7 @@ class CefBrowserImpl : public CefBrowser { void set_popup_rect(const gfx::Rect& rect) { popup_rect_ = rect; } net::URLRequestContext* request_context_proxy() { - return request_context_proxy_; + return request_context_proxy_.get(); } static bool ImplementsThreadSafeReferenceCounting() { return true; } @@ -386,7 +386,7 @@ class CefBrowserImpl : public CefBrowser { scoped_ptr dev_tools_agent_; scoped_ptr dev_tools_client_; - scoped_refptr request_context_proxy_; + scoped_ptr request_context_proxy_; CefString title_; diff --git a/cef1/libcef/browser_impl_gtk.cc b/cef1/libcef/browser_impl_gtk.cc index 28fa2cd0e..cc69ad4a9 100644 --- a/cef1/libcef/browser_impl_gtk.cc +++ b/cef1/libcef/browser_impl_gtk.cc @@ -80,7 +80,7 @@ bool CefBrowserImpl::UIT_CreateBrowser(const CefString& url) { window_info_.m_ParentWidget = parentView; } - WebPreferences prefs; + webkit_glue::WebPreferences prefs; BrowserToWebSettings(settings_, prefs); // Create the webview host object diff --git a/cef1/libcef/browser_impl_mac.mm b/cef1/libcef/browser_impl_mac.mm index f8054ff91..df8736e67 100644 --- a/cef1/libcef/browser_impl_mac.mm +++ b/cef1/libcef/browser_impl_mac.mm @@ -93,7 +93,7 @@ bool CefBrowserImpl::UIT_CreateBrowser(const CefString& url) { paint_delegate_.reset(new PaintDelegate(this)); } - WebPreferences prefs; + webkit_glue::WebPreferences prefs; BrowserToWebSettings(settings_, prefs); // Create the webview host object diff --git a/cef1/libcef/browser_impl_win.cc b/cef1/libcef/browser_impl_win.cc index 909e0c35b..c74f21781 100644 --- a/cef1/libcef/browser_impl_win.cc +++ b/cef1/libcef/browser_impl_win.cc @@ -197,7 +197,7 @@ bool CefBrowserImpl::UIT_CreateBrowser(const CefString& url) { // Add the new browser to the list maintained by the context _Context->AddBrowser(this); - WebPreferences prefs; + webkit_glue::WebPreferences prefs; BrowserToWebSettings(settings_, prefs); // Create the webview host object diff --git a/cef1/libcef/browser_network_delegate.cc b/cef1/libcef/browser_network_delegate.cc index 598a7d320..9d8d67422 100644 --- a/cef1/libcef/browser_network_delegate.cc +++ b/cef1/libcef/browser_network_delegate.cc @@ -73,8 +73,8 @@ net::NetworkDelegate::AuthRequiredResponse return AUTH_REQUIRED_RESPONSE_NO_ACTION; } -bool BrowserNetworkDelegate::CanGetCookies( - const net::URLRequest* request, +bool BrowserNetworkDelegate::OnCanGetCookies( + const net::URLRequest& request, const net::CookieList& cookie_list) { net::StaticCookiePolicy::Type policy_type = accept_all_cookies_ ? net::StaticCookiePolicy::ALLOW_ALL_COOKIES : @@ -82,19 +82,25 @@ bool BrowserNetworkDelegate::CanGetCookies( net::StaticCookiePolicy policy(policy_type); int rv = policy.CanGetCookies( - request->url(), request->first_party_for_cookies()); + request.url(), request.first_party_for_cookies()); return rv == net::OK; } -bool BrowserNetworkDelegate::CanSetCookie(const net::URLRequest* request, - const std::string& cookie_line, - net::CookieOptions* options) { +bool BrowserNetworkDelegate::OnCanSetCookie( + const net::URLRequest& request, + const std::string& cookie_line, + net::CookieOptions* options) { net::StaticCookiePolicy::Type policy_type = accept_all_cookies_ ? net::StaticCookiePolicy::ALLOW_ALL_COOKIES : net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES; net::StaticCookiePolicy policy(policy_type); int rv = policy.CanSetCookie( - request->url(), request->first_party_for_cookies()); + request.url(), request.first_party_for_cookies()); return rv == net::OK; } + +bool BrowserNetworkDelegate::OnCanAccessFile(const net::URLRequest& request, + const FilePath& path) const { + return true; +} diff --git a/cef1/libcef/browser_network_delegate.h b/cef1/libcef/browser_network_delegate.h index 149d2db39..3e9311cb9 100644 --- a/cef1/libcef/browser_network_delegate.h +++ b/cef1/libcef/browser_network_delegate.h @@ -44,12 +44,13 @@ class BrowserNetworkDelegate : public net::NetworkDelegate { const net::AuthChallengeInfo& auth_info, const AuthCallback& callback, net::AuthCredentials* credentials) OVERRIDE; - virtual bool CanGetCookies( - const net::URLRequest* request, - const net::CookieList& cookie_list) OVERRIDE; - virtual bool CanSetCookie(const net::URLRequest* request, - const std::string& cookie_line, - net::CookieOptions* options) OVERRIDE; + virtual bool OnCanGetCookies(const net::URLRequest& request, + const net::CookieList& cookie_list) OVERRIDE; + virtual bool OnCanSetCookie(const net::URLRequest& request, + const std::string& cookie_line, + net::CookieOptions* options) OVERRIDE; + virtual bool OnCanAccessFile(const net::URLRequest& request, + const FilePath& path) const OVERRIDE; bool accept_all_cookies_; }; diff --git a/cef1/libcef/browser_persistent_cookie_store.cc b/cef1/libcef/browser_persistent_cookie_store.cc deleted file mode 100644 index 4bbf6d48d..000000000 --- a/cef1/libcef/browser_persistent_cookie_store.cc +++ /dev/null @@ -1,792 +0,0 @@ -// Copyright (c) 2012 The Chromium Embedded Framework Authors. -// Portions copyright (c) 2011 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 "libcef/browser_persistent_cookie_store.h" - -#include -#include -#include -#include -#include - -#include "libcef/cef_thread.h" - -#include "base/basictypes.h" -#include "base/bind.h" -#include "base/callback.h" -#include "base/file_path.h" -#include "base/file_util.h" -#include "base/logging.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/metrics/histogram.h" -#include "base/string_util.h" -#include "base/synchronization/lock.h" -#include "base/threading/thread.h" -#include "base/threading/thread_restrictions.h" -#include "googleurl/src/gurl.h" -#include "net/base/registry_controlled_domain.h" -#include "sql/meta_table.h" -#include "sql/statement.h" -#include "sql/transaction.h" - -using base::Time; - -// This class is designed to be shared between any calling threads and the -// database thread. It batches operations and commits them on a timer. -// -// BrowserPersistentCookieStore::Load is called to load all cookies. It -// delegates to Backend::Load, which posts a Backend::LoadAndNotifyOnDBThread -// task to the DB thread. This task calls Backend::ChainLoadCookies(), which -// repeatedly posts itself to the DB thread to load each eTLD+1's cookies in -// separate tasks. When this is complete, Backend::NotifyOnIOThread is posted -// to the IO thread, which notifies the caller of BrowserPersistentCookieStore:: -// Load that the load is complete. -// -// If a priority load request is invoked via BrowserPersistentCookieStore:: -// LoadCookiesForKey, it is delegated to Backend::LoadCookiesForKey, which posts -// Backend::LoadKeyAndNotifyOnDBThread to the DB thread. That routine loads just -// that single domain key (eTLD+1)'s cookies, and posts a Backend:: -// NotifyOnIOThread to the IO thread to notify the caller of -// BrowserPersistentCookieStore::LoadCookiesForKey that that load is complete. -// -// Subsequent to loading, mutations may be queued by any thread using -// AddCookie, UpdateCookieAccessTime, and DeleteCookie. These are flushed to -// disk on the DB thread every 30 seconds, 512 operations, or call to Flush(), -// whichever occurs first. -class BrowserPersistentCookieStore::Backend - : public base::RefCountedThreadSafe { - public: - Backend(const FilePath& path, bool restore_old_session_cookies) - : path_(path), - db_(NULL), - num_pending_(0), - clear_local_state_on_exit_(false), - initialized_(false), - restore_old_session_cookies_(restore_old_session_cookies) { - } - - // Creates or loads the SQLite database. - void Load(const LoadedCallback& loaded_callback); - - // Loads cookies for the domain key (eTLD+1). - void LoadCookiesForKey(const std::string& domain, - const LoadedCallback& loaded_callback); - - // Batch a cookie addition. - void AddCookie(const net::CookieMonster::CanonicalCookie& cc); - - // Batch a cookie access time update. - void UpdateCookieAccessTime(const net::CookieMonster::CanonicalCookie& cc); - - // Batch a cookie deletion. - void DeleteCookie(const net::CookieMonster::CanonicalCookie& cc); - - // Commit pending operations as soon as possible. - void Flush(const base::Closure& callback); - - // Commit any pending operations and close the database. This must be called - // before the object is destructed. - void Close(); - - void SetClearLocalStateOnExit(bool clear_local_state); - - private: - friend class base::RefCountedThreadSafe< - BrowserPersistentCookieStore::Backend>; - - // You should call Close() before destructing this object. - ~Backend() { - DCHECK(!db_.get()) << "Close should have already been called."; - DCHECK(num_pending_ == 0 && pending_.empty()); - } - - // Database upgrade statements. - bool EnsureDatabaseVersion(); - - class PendingOperation { - public: - typedef enum { - COOKIE_ADD, - COOKIE_UPDATEACCESS, - COOKIE_DELETE, - } OperationType; - - PendingOperation(OperationType op, - const net::CookieMonster::CanonicalCookie& cc) - : op_(op), cc_(cc) { } - - OperationType op() const { return op_; } - const net::CookieMonster::CanonicalCookie& cc() const { return cc_; } - - private: - OperationType op_; - net::CookieMonster::CanonicalCookie cc_; - }; - - private: - // Creates or loads the SQLite database on DB thread. - void LoadAndNotifyOnDBThread(const LoadedCallback& loaded_callback); - - // Loads cookies for the domain key (eTLD+1) on DB thread. - void LoadKeyAndNotifyOnDBThread(const std::string& domains, - const LoadedCallback& loaded_callback); - - // Notifies the CookieMonster when loading completes for a specific domain key - // or for all domain keys. Triggers the callback and passes it all cookies - // that have been loaded from DB since last IO notification. - void NotifyOnIOThread( - const LoadedCallback& loaded_callback, - bool load_success); - - // Initialize the data base. - bool InitializeDatabase(); - - // Loads cookies for the next domain key from the DB, then either reschedules - // itself or schedules the provided callback to run on the IO thread (if all - // domains are loaded). - void ChainLoadCookies(const LoadedCallback& loaded_callback); - - // Load all cookies for a set of domains/hosts - bool LoadCookiesForDomains(const std::set& key); - - // Batch a cookie operation (add or delete) - void BatchOperation(PendingOperation::OperationType op, - const net::CookieMonster::CanonicalCookie& cc); - // Commit our pending operations to the database. - void Commit(); - // Close() executed on the background thread. - void InternalBackgroundClose(); - - void DeleteSessionCookies(); - - FilePath path_; - scoped_ptr db_; - sql::MetaTable meta_table_; - - typedef std::list PendingOperationsList; - PendingOperationsList pending_; - PendingOperationsList::size_type num_pending_; - // True if the persistent store should be deleted upon destruction. - bool clear_local_state_on_exit_; - // Guard |cookies_|, |pending_|, |num_pending_|, |clear_local_state_on_exit_| - base::Lock lock_; - - // Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce - // the number of messages sent to the IO thread. Sent back in response to - // individual load requests for domain keys or when all loading completes. - std::vector cookies_; - - // Map of domain keys(eTLD+1) to domains/hosts that are to be loaded from DB. - std::map > keys_to_load_; - - // Indicates if DB has been initialized. - bool initialized_; - - // If false, we should filter out session cookies when reading the DB. - bool restore_old_session_cookies_; - DISALLOW_COPY_AND_ASSIGN(Backend); -}; - -// Version number of the database. -// -// Version 5 adds the columns has_expires and is_persistent, so that the -// database can store session cookies as well as persistent cookies. Databases -// of version 5 are incompatible with older versions of code. If a database of -// version 5 is read by older code, session cookies will be treated as normal -// cookies. -// -// In version 4, we migrated the time epoch. If you open the DB with an older -// version on Mac or Linux, the times will look wonky, but the file will likely -// be usable. On Windows version 3 and 4 are the same. -// -// Version 3 updated the database to include the last access time, so we can -// expire them in decreasing order of use when we've reached the maximum -// number of cookies. -static const int kCurrentVersionNumber = 5; -static const int kCompatibleVersionNumber = 5; - -namespace { - -// Initializes the cookies table, returning true on success. -bool InitTable(sql::Connection* db) { - if (!db->DoesTableExist("cookies")) { - if (!db->Execute("CREATE TABLE cookies (" - "creation_utc INTEGER NOT NULL UNIQUE PRIMARY KEY," - "host_key TEXT NOT NULL," - "name TEXT NOT NULL," - "value TEXT NOT NULL," - "path TEXT NOT NULL," - "expires_utc INTEGER NOT NULL," - "secure INTEGER NOT NULL," - "httponly INTEGER NOT NULL," - "last_access_utc INTEGER NOT NULL, " - "has_expires INTEGER NOT NULL DEFAULT 1, " - "persistent INTEGER NOT NULL DEFAULT 1)")) - return false; - } - - // Older code created an index on creation_utc, which is already - // primary key for the table. - if (!db->Execute("DROP INDEX IF EXISTS cookie_times")) - return false; - - if (!db->Execute("CREATE INDEX IF NOT EXISTS domain ON cookies(host_key)")) - return false; - - return true; -} - -} // namespace - -void BrowserPersistentCookieStore::Backend::Load( - const LoadedCallback& loaded_callback) { - // This function should be called only once per instance. - DCHECK(!db_.get()); - CefThread::PostTask( - CefThread::FILE, FROM_HERE, - base::Bind(&Backend::LoadAndNotifyOnDBThread, this, loaded_callback)); -} - -void BrowserPersistentCookieStore::Backend::LoadCookiesForKey( - const std::string& key, - const LoadedCallback& loaded_callback) { - CefThread::PostTask( - CefThread::FILE, FROM_HERE, - base::Bind(&Backend::LoadKeyAndNotifyOnDBThread, this, - key, - loaded_callback)); -} - -void BrowserPersistentCookieStore::Backend::LoadAndNotifyOnDBThread( - const LoadedCallback& loaded_callback) { - DCHECK(CefThread::CurrentlyOn(CefThread::FILE)); - - if (!InitializeDatabase()) { - CefThread::PostTask( - CefThread::IO, FROM_HERE, - base::Bind(&BrowserPersistentCookieStore::Backend::NotifyOnIOThread, - this, loaded_callback, false)); - } else { - ChainLoadCookies(loaded_callback); - } -} - -void BrowserPersistentCookieStore::Backend::LoadKeyAndNotifyOnDBThread( - const std::string& key, - const LoadedCallback& loaded_callback) { - DCHECK(CefThread::CurrentlyOn(CefThread::FILE)); - - bool success = false; - if (InitializeDatabase()) { - std::map >::iterator - it = keys_to_load_.find(key); - if (it != keys_to_load_.end()) { - success = LoadCookiesForDomains(it->second); - keys_to_load_.erase(it); - } else { - success = true; - } - } - - CefThread::PostTask( - CefThread::IO, FROM_HERE, - base::Bind(&BrowserPersistentCookieStore::Backend::NotifyOnIOThread, - this, loaded_callback, success)); -} - -void BrowserPersistentCookieStore::Backend::NotifyOnIOThread( - const LoadedCallback& loaded_callback, - bool load_success) { - DCHECK(CefThread::CurrentlyOn(CefThread::IO)); - - std::vector cookies; - { - base::AutoLock locked(lock_); - cookies.swap(cookies_); - } - - loaded_callback.Run(cookies); -} - -bool BrowserPersistentCookieStore::Backend::InitializeDatabase() { - DCHECK(CefThread::CurrentlyOn(CefThread::FILE)); - - if (initialized_) { - // Return false if we were previously initialized but the DB has since been - // closed. - return db_.get() ? true : false; - } - - const FilePath dir = path_.DirName(); - if (!file_util::PathExists(dir) && !file_util::CreateDirectory(dir)) { - return false; - } - - db_.reset(new sql::Connection); - if (!db_->Open(path_)) { - NOTREACHED() << "Unable to open cookie DB."; - db_.reset(); - return false; - } - - // db_->set_error_delegate(GetErrorHandlerForCookieDb()); - - if (!EnsureDatabaseVersion() || !InitTable(db_.get())) { - NOTREACHED() << "Unable to open cookie DB."; - db_.reset(); - return false; - } - - // Retrieve all the domains - sql::Statement smt(db_->GetUniqueStatement( - "SELECT DISTINCT host_key FROM cookies")); - - if (!smt.is_valid()) { - smt.Clear(); // Disconnect smt_ref from db_. - db_.reset(); - return false; - } - - // Build a map of domain keys (always eTLD+1) to domains. - while (smt.Step()) { - std::string domain = smt.ColumnString(0); - std::string key = - net::RegistryControlledDomainService::GetDomainAndRegistry(domain); - - std::map >::iterator it = - keys_to_load_.find(key); - if (it == keys_to_load_.end()) - it = keys_to_load_.insert(std::make_pair - (key, std::set())).first; - it->second.insert(domain); - } - - initialized_ = true; - return true; -} - -void BrowserPersistentCookieStore::Backend::ChainLoadCookies( - const LoadedCallback& loaded_callback) { - DCHECK(CefThread::CurrentlyOn(CefThread::FILE)); - - bool load_success = true; - - if (!db_.get()) { - // Close() has been called on this store. - load_success = false; - } else if (keys_to_load_.size() > 0) { - // Load cookies for the first domain key. - std::map >::iterator - it = keys_to_load_.begin(); - load_success = LoadCookiesForDomains(it->second); - keys_to_load_.erase(it); - } - - // If load is successful and there are more domain keys to be loaded, - // then post a DB task to continue chain-load; - // Otherwise notify on IO thread. - if (load_success && keys_to_load_.size() > 0) { - CefThread::PostTask( - CefThread::FILE, FROM_HERE, - base::Bind(&Backend::ChainLoadCookies, this, loaded_callback)); - } else { - CefThread::PostTask( - CefThread::IO, FROM_HERE, - base::Bind(&BrowserPersistentCookieStore::Backend::NotifyOnIOThread, - this, loaded_callback, load_success)); - if (load_success && !restore_old_session_cookies_) - DeleteSessionCookies(); - } -} - -bool BrowserPersistentCookieStore::Backend::LoadCookiesForDomains( - const std::set& domains) { - DCHECK(CefThread::CurrentlyOn(CefThread::FILE)); - - sql::Statement smt; - if (restore_old_session_cookies_) { - smt.Assign(db_->GetCachedStatement( - SQL_FROM_HERE, - "SELECT creation_utc, host_key, name, value, path, expires_utc, " - "secure, httponly, last_access_utc, has_expires, persistent " - "FROM cookies WHERE host_key = ?")); - } else { - smt.Assign(db_->GetCachedStatement( - SQL_FROM_HERE, - "SELECT creation_utc, host_key, name, value, path, expires_utc, " - "secure, httponly, last_access_utc, has_expires, persistent " - "FROM cookies WHERE host_key = ? AND persistent = 1")); - } - if (!smt.is_valid()) { - NOTREACHED() << "select statement prep failed"; - smt.Clear(); // Disconnect smt_ref from db_. - db_.reset(); - return false; - } - - std::vector cookies; - std::set::const_iterator it = domains.begin(); - for (; it != domains.end(); ++it) { - smt.BindString(0, *it); - while (smt.Step()) { - scoped_ptr cc( - new net::CookieMonster::CanonicalCookie( - // The "source" URL is not used with persisted cookies. - GURL(), // Source - smt.ColumnString(2), // name - smt.ColumnString(3), // value - smt.ColumnString(1), // domain - smt.ColumnString(4), // path - std::string(), // TODO(abarth): Persist mac_key - std::string(), // TODO(abarth): Persist mac_algorithm - Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc - Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc - Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc - smt.ColumnInt(6) != 0, // secure - smt.ColumnInt(7) != 0, // httponly - smt.ColumnInt(9) != 0, // has_expires - smt.ColumnInt(10) != 0)); // is_persistent - DLOG_IF(WARNING, - cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; - cookies.push_back(cc.release()); - } - smt.Reset(); - } - { - base::AutoLock locked(lock_); - cookies_.insert(cookies_.end(), cookies.begin(), cookies.end()); - } - return true; -} - -bool BrowserPersistentCookieStore::Backend::EnsureDatabaseVersion() { - // Version check. - if (!meta_table_.Init( - db_.get(), kCurrentVersionNumber, kCompatibleVersionNumber)) { - return false; - } - - if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { - LOG(WARNING) << "Cookie database is too new."; - return false; - } - - int cur_version = meta_table_.GetVersionNumber(); - if (cur_version == 2) { - sql::Transaction transaction(db_.get()); - if (!transaction.Begin()) - return false; - if (!db_->Execute("ALTER TABLE cookies ADD COLUMN last_access_utc " - "INTEGER DEFAULT 0") || - !db_->Execute("UPDATE cookies SET last_access_utc = creation_utc")) { - LOG(WARNING) << "Unable to update cookie database to version 3."; - return false; - } - ++cur_version; - meta_table_.SetVersionNumber(cur_version); - meta_table_.SetCompatibleVersionNumber( - std::min(cur_version, kCompatibleVersionNumber)); - transaction.Commit(); - } - - if (cur_version == 3) { - // The time epoch changed for Mac & Linux in this version to match Windows. - // This patch came after the main epoch change happened, so some - // developers have "good" times for cookies added by the more recent - // versions. So we have to be careful to only update times that are under - // the old system (which will appear to be from before 1970 in the new - // system). The magic number used below is 1970 in our time units. - sql::Transaction transaction(db_.get()); - transaction.Begin(); -#if !defined(OS_WIN) - ignore_result(db_->Execute( - "UPDATE cookies " - "SET creation_utc = creation_utc + 11644473600000000 " - "WHERE rowid IN " - "(SELECT rowid FROM cookies WHERE " - "creation_utc > 0 AND creation_utc < 11644473600000000)")); - ignore_result(db_->Execute( - "UPDATE cookies " - "SET expires_utc = expires_utc + 11644473600000000 " - "WHERE rowid IN " - "(SELECT rowid FROM cookies WHERE " - "expires_utc > 0 AND expires_utc < 11644473600000000)")); - ignore_result(db_->Execute( - "UPDATE cookies " - "SET last_access_utc = last_access_utc + 11644473600000000 " - "WHERE rowid IN " - "(SELECT rowid FROM cookies WHERE " - "last_access_utc > 0 AND last_access_utc < 11644473600000000)")); -#endif - ++cur_version; - meta_table_.SetVersionNumber(cur_version); - transaction.Commit(); - } - - if (cur_version == 4) { - sql::Transaction transaction(db_.get()); - if (!transaction.Begin()) - return false; - if (!db_->Execute("ALTER TABLE cookies " - "ADD COLUMN has_expires INTEGER DEFAULT 1") || - !db_->Execute("ALTER TABLE cookies " - "ADD COLUMN persistent INTEGER DEFAULT 1")) { - LOG(WARNING) << "Unable to update cookie database to version 5."; - return false; - } - ++cur_version; - meta_table_.SetVersionNumber(cur_version); - meta_table_.SetCompatibleVersionNumber( - std::min(cur_version, kCompatibleVersionNumber)); - transaction.Commit(); - } - - // Put future migration cases here. - - // When the version is too old, we just try to continue anyway, there should - // not be a released product that makes a database too old for us to handle. - LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << - "Cookie database version " << cur_version << " is too old to handle."; - - return true; -} - -void BrowserPersistentCookieStore::Backend::AddCookie( - const net::CookieMonster::CanonicalCookie& cc) { - BatchOperation(PendingOperation::COOKIE_ADD, cc); -} - -void BrowserPersistentCookieStore::Backend::UpdateCookieAccessTime( - const net::CookieMonster::CanonicalCookie& cc) { - BatchOperation(PendingOperation::COOKIE_UPDATEACCESS, cc); -} - -void BrowserPersistentCookieStore::Backend::DeleteCookie( - const net::CookieMonster::CanonicalCookie& cc) { - BatchOperation(PendingOperation::COOKIE_DELETE, cc); -} - -void BrowserPersistentCookieStore::Backend::BatchOperation( - PendingOperation::OperationType op, - const net::CookieMonster::CanonicalCookie& cc) { - // Commit every 30 seconds. - static const int kCommitIntervalMs = 30 * 1000; - // Commit right away if we have more than 512 outstanding operations. - static const size_t kCommitAfterBatchSize = 512; - DCHECK(!CefThread::CurrentlyOn(CefThread::FILE)); - - // We do a full copy of the cookie here, and hopefully just here. - scoped_ptr po(new PendingOperation(op, cc)); - - PendingOperationsList::size_type num_pending; - { - base::AutoLock locked(lock_); - pending_.push_back(po.release()); - num_pending = ++num_pending_; - } - - if (num_pending == 1) { - // We've gotten our first entry for this batch, fire off the timer. - CefThread::PostDelayedTask( - CefThread::FILE, FROM_HERE, - base::Bind(&Backend::Commit, this), - base::TimeDelta::FromMilliseconds(kCommitIntervalMs)); - } else if (num_pending == kCommitAfterBatchSize) { - // We've reached a big enough batch, fire off a commit now. - CefThread::PostTask( - CefThread::FILE, FROM_HERE, - base::Bind(&Backend::Commit, this)); - } -} - -void BrowserPersistentCookieStore::Backend::Commit() { - DCHECK(CefThread::CurrentlyOn(CefThread::FILE)); - - PendingOperationsList ops; - { - base::AutoLock locked(lock_); - pending_.swap(ops); - num_pending_ = 0; - } - - // Maybe an old timer fired or we are already Close()'ed. - if (!db_.get() || ops.empty()) - return; - - sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, - "INSERT INTO cookies (creation_utc, host_key, name, value, path, " - "expires_utc, secure, httponly, last_access_utc, has_expires, " - "persistent) " - "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); - if (!add_smt.is_valid()) - return; - - sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, - "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); - if (!update_access_smt.is_valid()) - return; - - sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE, - "DELETE FROM cookies WHERE creation_utc=?")); - if (!del_smt.is_valid()) - return; - - sql::Transaction transaction(db_.get()); - if (!transaction.Begin()) - return; - - for (PendingOperationsList::iterator it = ops.begin(); - it != ops.end(); ++it) { - // Free the cookies as we commit them to the database. - scoped_ptr po(*it); - switch (po->op()) { - case PendingOperation::COOKIE_ADD: - add_smt.Reset(); - add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); - add_smt.BindString(1, po->cc().Domain()); - add_smt.BindString(2, po->cc().Name()); - add_smt.BindString(3, po->cc().Value()); - add_smt.BindString(4, po->cc().Path()); - add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue()); - add_smt.BindInt(6, po->cc().IsSecure()); - add_smt.BindInt(7, po->cc().IsHttpOnly()); - add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue()); - add_smt.BindInt(9, po->cc().DoesExpire()); - add_smt.BindInt(10, po->cc().IsPersistent()); - if (!add_smt.Run()) - NOTREACHED() << "Could not add a cookie to the DB."; - break; - - case PendingOperation::COOKIE_UPDATEACCESS: - update_access_smt.Reset(); - update_access_smt.BindInt64(0, - po->cc().LastAccessDate().ToInternalValue()); - update_access_smt.BindInt64(1, - po->cc().CreationDate().ToInternalValue()); - if (!update_access_smt.Run()) - NOTREACHED() << "Could not update cookie last access time in the DB."; - break; - - case PendingOperation::COOKIE_DELETE: - del_smt.Reset(); - del_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); - if (!del_smt.Run()) - NOTREACHED() << "Could not delete a cookie from the DB."; - break; - - default: - NOTREACHED(); - break; - } - } - transaction.Commit(); -} - -void BrowserPersistentCookieStore::Backend::Flush( - const base::Closure& callback) { - DCHECK(!CefThread::CurrentlyOn(CefThread::FILE)); - CefThread::PostTask( - CefThread::FILE, FROM_HERE, base::Bind(&Backend::Commit, this)); - if (!callback.is_null()) { - // We want the completion task to run immediately after Commit() returns. - // Posting it from here means there is less chance of another task getting - // onto the message queue first, than if we posted it from Commit() itself. - CefThread::PostTask(CefThread::FILE, FROM_HERE, callback); - } -} - -// Fire off a close message to the background thread. We could still have a -// pending commit timer or Load operations holding references on us, but if/when -// this fires we will already have been cleaned up and it will be ignored. -void BrowserPersistentCookieStore::Backend::Close() { - if (CefThread::CurrentlyOn(CefThread::FILE)) { - InternalBackgroundClose(); - } else { - // Must close the backend on the background thread. - CefThread::PostTask( - CefThread::FILE, FROM_HERE, - base::Bind(&Backend::InternalBackgroundClose, this)); - } -} - -void BrowserPersistentCookieStore::Backend::InternalBackgroundClose() { - DCHECK(CefThread::CurrentlyOn(CefThread::FILE)); - // Commit any pending operations - Commit(); - - db_.reset(); - - if (clear_local_state_on_exit_) - file_util::Delete(path_, false); -} - -void BrowserPersistentCookieStore::Backend::SetClearLocalStateOnExit( - bool clear_local_state) { - base::AutoLock locked(lock_); - clear_local_state_on_exit_ = clear_local_state; -} - -void BrowserPersistentCookieStore::Backend::DeleteSessionCookies() { - DCHECK(CefThread::CurrentlyOn(CefThread::FILE)); - if (!db_->Execute("DELETE FROM cookies WHERE persistent == 0")) - LOG(WARNING) << "Unable to delete session cookies."; -} - -BrowserPersistentCookieStore::BrowserPersistentCookieStore( - const FilePath& path, - bool restore_old_session_cookies) - : backend_(new Backend(path, restore_old_session_cookies)) { -} - -BrowserPersistentCookieStore::~BrowserPersistentCookieStore() { - if (backend_.get()) { - backend_->Close(); - // Release our reference, it will probably still have a reference if the - // background thread has not run Close() yet. - backend_ = NULL; - } -} - -void BrowserPersistentCookieStore::Load(const LoadedCallback& loaded_callback) { - backend_->Load(loaded_callback); -} - -void BrowserPersistentCookieStore::LoadCookiesForKey( - const std::string& key, - const LoadedCallback& loaded_callback) { - backend_->LoadCookiesForKey(key, loaded_callback); -} - -void BrowserPersistentCookieStore::AddCookie( - const net::CookieMonster::CanonicalCookie& cc) { - if (backend_.get()) - backend_->AddCookie(cc); -} - -void BrowserPersistentCookieStore::UpdateCookieAccessTime( - const net::CookieMonster::CanonicalCookie& cc) { - if (backend_.get()) - backend_->UpdateCookieAccessTime(cc); -} - -void BrowserPersistentCookieStore::DeleteCookie( - const net::CookieMonster::CanonicalCookie& cc) { - if (backend_.get()) - backend_->DeleteCookie(cc); -} - -void BrowserPersistentCookieStore::SetClearLocalStateOnExit( - bool clear_local_state) { - if (backend_.get()) - backend_->SetClearLocalStateOnExit(clear_local_state); -} - -void BrowserPersistentCookieStore::Flush(const base::Closure& callback) { - if (backend_.get()) - backend_->Flush(callback); - else if (!callback.is_null()) - MessageLoop::current()->PostTask(FROM_HERE, callback); -} diff --git a/cef1/libcef/browser_persistent_cookie_store.h b/cef1/libcef/browser_persistent_cookie_store.h deleted file mode 100644 index 4f3d77179..000000000 --- a/cef1/libcef/browser_persistent_cookie_store.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2011 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. - -// A sqlite implementation of a cookie monster persistent store. - -// This class is based on src/chrome/browser/net/ -// sqlite_persistent_cookie_store.h -// with the following modifications for use in the cef: -// - BrowserThread has been replaced with CefThread -// - Performance diagnostic code has been removed (UMA_HISTOGRAM_ENUMERATION) - -#ifndef CEF_LIBCEF_BROWSER_PERSISTENT_COOKIE_STORE_H_ -#define CEF_LIBCEF_BROWSER_PERSISTENT_COOKIE_STORE_H_ -#pragma once - -#include -#include - -#include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" -#include "net/cookies/cookie_monster.h" - -class FilePath; -class Task; - -// Implements the PersistentCookieStore interface in terms of a SQLite database. -// For documentation about the actual member functions consult the documentation -// of the parent class |net::CookieMonster::PersistentCookieStore|. -class BrowserPersistentCookieStore - : public net::CookieMonster::PersistentCookieStore { - public: - BrowserPersistentCookieStore(const FilePath& path, - bool restore_old_session_cookies); - virtual ~BrowserPersistentCookieStore(); - - virtual void Load(const LoadedCallback& loaded_callback) OVERRIDE; - - virtual void LoadCookiesForKey(const std::string& key, - const LoadedCallback& callback) OVERRIDE; - - virtual void AddCookie( - const net::CookieMonster::CanonicalCookie& cc) OVERRIDE; - - virtual void UpdateCookieAccessTime( - const net::CookieMonster::CanonicalCookie& cc) OVERRIDE; - - virtual void DeleteCookie( - const net::CookieMonster::CanonicalCookie& cc) OVERRIDE; - - virtual void SetClearLocalStateOnExit(bool clear_local_state) OVERRIDE; - - virtual void Flush(const base::Closure& callback) OVERRIDE; - - private: - class Backend; - - scoped_refptr backend_; - - DISALLOW_COPY_AND_ASSIGN(BrowserPersistentCookieStore); -}; - -#endif // CEF_LIBCEF_BROWSER_PERSISTENT_COOKIE_STORE_H_ diff --git a/cef1/libcef/browser_request_context.cc b/cef1/libcef/browser_request_context.cc index e503aa8e9..eee742045 100644 --- a/cef1/libcef/browser_request_context.cc +++ b/cef1/libcef/browser_request_context.cc @@ -10,7 +10,6 @@ #endif #include "libcef/browser_file_system.h" -#include "libcef/browser_persistent_cookie_store.h" #include "libcef/browser_resource_loader_bridge.h" #include "libcef/cef_context.h" #include "libcef/cef_thread.h" @@ -18,7 +17,9 @@ #include "base/compiler_specific.h" #include "base/file_path.h" #include "base/file_util.h" +#include "base/threading/worker_pool.h" #include "build/build_config.h" +#include "chrome/browser/net/sqlite_persistent_cookie_store.h" #include "net/base/cert_verifier.h" #include "net/cookies/cookie_monster.h" #include "net/base/default_server_bound_cert_store.h" @@ -157,7 +158,8 @@ void BrowserRequestContext::Init( SetCookieStoragePath(cache_path); storage_.set_server_bound_cert_service(new net::ServerBoundCertService( - new net::DefaultServerBoundCertStore(NULL))); + new net::DefaultServerBoundCertStore(NULL), + base::WorkerPool::GetTaskRunner(true))); // hard-code A-L and A-C for test shells set_accept_language("en-us,en"); @@ -243,15 +245,16 @@ void BrowserRequestContext::Init( new net::HttpCache(host_resolver(), cert_verifier(), server_bound_cert_service(), - NULL, // transport_security_state + NULL, /* transport_security_state */ proxy_service(), - "", // ssl_session_cache_shard + "", /* ssl_session_cache_shard */ ssl_config_service(), http_auth_handler_factory(), - NULL, // network_delegate + NULL, /* network_delegate */ http_server_properties(), - NULL, // netlog - backend); + NULL, /* netlog */ + backend, + "" /* trusted_spdy_proxy */ ); cache->set_mode(cache_mode); storage_.set_http_transaction_factory(cache); @@ -275,8 +278,7 @@ void BrowserRequestContext::Init( job_factory->SetProtocolHandler( "filesystem", fileapi::CreateFileSystemProtocolHandler( - file_system->file_system_context(), - CefThread::GetMessageLoopProxyForThread(CefThread::FILE))); + file_system->file_system_context())); } storage_.set_job_factory(job_factory); @@ -297,11 +299,11 @@ void BrowserRequestContext::SetCookieStoragePath(const FilePath& path) { return; } - scoped_refptr persistent_store; + scoped_refptr persistent_store; if (!path.empty()) { if (file_util::CreateDirectory(path)) { const FilePath& cookie_path = path.AppendASCII("Cookies"); - persistent_store = new BrowserPersistentCookieStore(cookie_path, false); + persistent_store = new SQLitePersistentCookieStore(cookie_path, false); } else { NOTREACHED() << "The cookie storage directory could not be created"; } diff --git a/cef1/libcef/browser_resource_loader_bridge.cc b/cef1/libcef/browser_resource_loader_bridge.cc index 4940676c3..b69b9b434 100644 --- a/cef1/libcef/browser_resource_loader_bridge.cc +++ b/cef1/libcef/browser_resource_loader_bridge.cc @@ -73,6 +73,7 @@ #include "webkit/fileapi/file_system_dir_url_request_job.h" #include "webkit/fileapi/file_system_url_request_job.h" #include "webkit/glue/resource_loader_bridge.h" +#include "webkit/glue/webkit_glue.h" #if defined(OS_MACOSX) || defined(OS_WIN) #include "crypto/nss_util.h" @@ -95,6 +96,7 @@ struct RequestParams { GURL url; GURL first_party_for_cookies; GURL referrer; + WebKit::WebReferrerPolicy referrer_policy; std::string headers; int load_flags; ResourceType::Type request_type; @@ -562,6 +564,8 @@ class RequestProxy : public net::URLRequest::Delegate, request_->set_method(params->method); request_->set_first_party_for_cookies(params->first_party_for_cookies); request_->set_referrer(params->referrer.spec()); + webkit_glue::ConfigureURLRequestForReferrerPolicy( + request_.get(), params->referrer_policy); net::HttpRequestHeaders headers; headers.AddHeadersFromString(params->headers); request_->SetExtraRequestHeaders(headers); @@ -982,6 +986,7 @@ class ResourceLoaderBridgeImpl : public ResourceLoaderBridge { params_->url = request_info.url; params_->first_party_for_cookies = request_info.first_party_for_cookies; params_->referrer = request_info.referrer; + params_->referrer_policy = request_info.referrer_policy; params_->headers = request_info.headers; params_->load_flags = request_info.load_flags; params_->request_type = request_info.request_type; diff --git a/cef1/libcef/browser_settings.cc b/cef1/libcef/browser_settings.cc index ea0da05a7..f208e0236 100644 --- a/cef1/libcef/browser_settings.cc +++ b/cef1/libcef/browser_settings.cc @@ -7,26 +7,40 @@ #include "base/utf_string_conversions.h" #include "webkit/glue/webpreferences.h" +using webkit_glue::WebPreferences; + void BrowserToWebSettings(const CefBrowserSettings& cef, WebPreferences& web) { - if (cef.standard_font_family.length > 0) - web.standard_font_family = CefString(&cef.standard_font_family); - else - web.standard_font_family = ASCIIToUTF16("Times"); + if (cef.standard_font_family.length > 0) { + web.standard_font_family_map[WebPreferences::kCommonScript] = + CefString(&cef.standard_font_family); + } else { + web.standard_font_family_map[WebPreferences::kCommonScript] = + ASCIIToUTF16("Times"); + } - if (cef.fixed_font_family.length > 0) - web.fixed_font_family = CefString(&cef.fixed_font_family); - else - web.fixed_font_family = ASCIIToUTF16("Courier"); + if (cef.fixed_font_family.length > 0) { + web.fixed_font_family_map[WebPreferences::kCommonScript] = + CefString(&cef.fixed_font_family); + } else { + web.fixed_font_family_map[WebPreferences::kCommonScript] = + ASCIIToUTF16("Courier"); + } - if (cef.serif_font_family.length > 0) - web.serif_font_family = CefString(&cef.serif_font_family); - else - web.serif_font_family = ASCIIToUTF16("Times"); + if (cef.serif_font_family.length > 0) { + web.serif_font_family_map[WebPreferences::kCommonScript] = + CefString(&cef.serif_font_family); + } else { + web.serif_font_family_map[WebPreferences::kCommonScript] = + ASCIIToUTF16("Times"); + } - if (cef.sans_serif_font_family.length > 0) - web.sans_serif_font_family = CefString(&cef.sans_serif_font_family); - else - web.sans_serif_font_family = ASCIIToUTF16("Helvetica"); + if (cef.sans_serif_font_family.length > 0) { + web.sans_serif_font_family_map[WebPreferences::kCommonScript] = + CefString(&cef.sans_serif_font_family); + } else { + web.sans_serif_font_family_map[WebPreferences::kCommonScript] = + ASCIIToUTF16("Helvetica"); + } // These two fonts below are picked from the intersection of // Win XP font list and Vista font list : @@ -40,22 +54,26 @@ void BrowserToWebSettings(const CefBrowserSettings& cef, WebPreferences& web) { // as long as they're available. if (cef.cursive_font_family.length > 0) { - web.cursive_font_family = CefString(&cef.cursive_font_family); + web.cursive_font_family_map[WebPreferences::kCommonScript] = + CefString(&cef.cursive_font_family); } else { + web.cursive_font_family_map[WebPreferences::kCommonScript] = #if defined(OS_MACOSX) - web.cursive_font_family = ASCIIToUTF16("Apple Chancery"); + ASCIIToUTF16("Apple Chancery"); #else - web.cursive_font_family = ASCIIToUTF16("Comic Sans MS"); + ASCIIToUTF16("Comic Sans MS"); #endif } if (cef.fantasy_font_family.length > 0) { - web.fantasy_font_family = CefString(&cef.fantasy_font_family); + web.fantasy_font_family_map[WebPreferences::kCommonScript] = + CefString(&cef.fantasy_font_family); } else { + web.fantasy_font_family_map[WebPreferences::kCommonScript] = #if defined(OS_MACOSX) - web.fantasy_font_family = ASCIIToUTF16("Papyrus"); + ASCIIToUTF16("Papyrus"); #else - web.fantasy_font_family = ASCIIToUTF16("Impact"); + ASCIIToUTF16("Impact"); #endif } diff --git a/cef1/libcef/browser_settings.h b/cef1/libcef/browser_settings.h index 722009dbe..7a04da48f 100644 --- a/cef1/libcef/browser_settings.h +++ b/cef1/libcef/browser_settings.h @@ -7,8 +7,12 @@ #pragma once #include "include/internal/cef_types_wrappers.h" -struct WebPreferences; -void BrowserToWebSettings(const CefBrowserSettings& cef, WebPreferences& web); +namespace webkit_glue { +struct WebPreferences; +} + +void BrowserToWebSettings(const CefBrowserSettings& cef, + webkit_glue::WebPreferences& web); #endif // CEF_LIBCEF_BROWSER_SETTINGS_H_ diff --git a/cef1/libcef/browser_socket_stream_bridge.cc b/cef1/libcef/browser_socket_stream_bridge.cc index 53ffe7c27..0d96d8ee1 100644 --- a/cef1/libcef/browser_socket_stream_bridge.cc +++ b/cef1/libcef/browser_socket_stream_bridge.cc @@ -223,14 +223,11 @@ void WebSocketStreamHandleBridgeImpl::DoOnClose() { void BrowserSocketStreamBridge::InitializeOnIOThread( net::URLRequestContext* request_context) { g_io_thread = MessageLoop::current(); - if ((g_request_context = request_context)) - g_request_context->AddRef(); + g_request_context = request_context; } void BrowserSocketStreamBridge::Cleanup() { g_io_thread = NULL; - if (g_request_context) - g_request_context->Release(); g_request_context = NULL; } diff --git a/cef1/libcef/browser_thread_stub.cc b/cef1/libcef/browser_thread_stub.cc new file mode 100644 index 000000000..7aff3e4d1 --- /dev/null +++ b/cef1/libcef/browser_thread_stub.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2012 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 "content/public/browser/browser_thread.h" +#include "libcef/cef_thread.h" + +// Stub implementations to convert BrowserThread calls to CefThread. + +namespace content { + +namespace { + +int GetCefId(BrowserThread::ID browser_id) { + switch (browser_id) { + case BrowserThread::UI: + return CefThread::UI; + case BrowserThread::IO: + return CefThread::IO; + case BrowserThread::DB: + case BrowserThread::FILE: + return CefThread::FILE; + default: + break; + } + + // The specified BrowserThread ID is not supported. + NOTREACHED(); + return -1; +} + +} // namespace + +// static +bool BrowserThread::PostTask(ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task) { + int cef_id = GetCefId(identifier); + if (cef_id < 0) + return false; + + return CefThread::PostTask(static_cast(cef_id), from_here, + task); +} + +// static +bool BrowserThread::PostDelayedTask(ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task, + base::TimeDelta delay) { + int cef_id = GetCefId(identifier); + if (cef_id < 0) + return false; + + return CefThread::PostDelayedTask(static_cast(cef_id), + from_here, task, delay); +} + +// static +bool BrowserThread::CurrentlyOn(ID identifier) { + int cef_id = GetCefId(identifier); + if (cef_id < 0) + return false; + + return CefThread::CurrentlyOn(static_cast(cef_id)); +} + +} // namespace content diff --git a/cef1/libcef/browser_webblobregistry_impl.cc b/cef1/libcef/browser_webblobregistry_impl.cc index 56257f384..626f64b82 100644 --- a/cef1/libcef/browser_webblobregistry_impl.cc +++ b/cef1/libcef/browser_webblobregistry_impl.cc @@ -66,6 +66,9 @@ void BrowserWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { thread_safe_url)); } +BrowserWebBlobRegistryImpl::~BrowserWebBlobRegistryImpl() { +} + void BrowserWebBlobRegistryImpl::AddFinishedBlob( const GURL& url, BlobData* blob_data) { DCHECK(g_blob_storage_controller); diff --git a/cef1/libcef/browser_webblobregistry_impl.h b/cef1/libcef/browser_webblobregistry_impl.h index 5aa7a6706..09f92bd6f 100644 --- a/cef1/libcef/browser_webblobregistry_impl.h +++ b/cef1/libcef/browser_webblobregistry_impl.h @@ -33,6 +33,9 @@ class BrowserWebBlobRegistryImpl const WebKit::WebURL& src_url); virtual void unregisterBlobURL(const WebKit::WebURL& url); + protected: + virtual ~BrowserWebBlobRegistryImpl(); + private: friend class base::RefCountedThreadSafe; diff --git a/cef1/libcef/browser_webkit_init.cc b/cef1/libcef/browser_webkit_init.cc index 2463329c0..ccfa443ab 100644 --- a/cef1/libcef/browser_webkit_init.cc +++ b/cef1/libcef/browser_webkit_init.cc @@ -7,7 +7,6 @@ #include "libcef/browser_resource_loader_bridge.h" #include "libcef/browser_socket_stream_bridge.h" #include "libcef/browser_webkit_glue.h" -#include "libcef/browser_webstoragenamespace_impl.h" #include "libcef/cef_context.h" #include "base/metrics/stats_counters.h" @@ -198,22 +197,7 @@ WebKit::WebString BrowserWebKitInit::defaultLocale() { WebKit::WebStorageNamespace* BrowserWebKitInit::createLocalStorageNamespace( const WebKit::WebString& path, unsigned quota) { -#ifdef ENABLE_NEW_DOM_STORAGE_BACKEND - NOTREACHED(); -#else - return new BrowserWebStorageNamespaceImpl(DOM_STORAGE_LOCAL); -#endif -} - -void BrowserWebKitInit::dispatchStorageEvent(const WebKit::WebString& key, - const WebKit::WebString& old_value, const WebKit::WebString& new_value, - const WebKit::WebString& origin, const WebKit::WebURL& url, - bool is_local_storage) { - // All events are dispatched by the WebCore::StorageAreaProxy in the - // simple single process case. -#ifdef ENABLE_NEW_DOM_STORAGE_BACKEND - NOTREACHED(); -#endif + return dom_storage_system_.CreateLocalStorageNamespace(); } WebKit::WebIDBFactory* BrowserWebKitInit::idbFactory() { @@ -222,13 +206,11 @@ WebKit::WebIDBFactory* BrowserWebKitInit::idbFactory() { void BrowserWebKitInit::createIDBKeysFromSerializedValuesAndKeyPath( const WebKit::WebVector& values, - const WebKit::WebString& keyPath, + const WebKit::WebIDBKeyPath& keyPath, WebKit::WebVector& keys_out) { WebKit::WebVector keys(values.size()); - for (size_t i = 0; i < values.size(); ++i) { - keys[i] = WebKit::WebIDBKey::createFromValueAndKeyPath( - values[i], WebKit::WebIDBKeyPath::create(keyPath)); - } + for (size_t i = 0; i < values.size(); ++i) + keys[i] = WebKit::WebIDBKey::createFromValueAndKeyPath(values[i], keyPath); keys_out.swap(keys); } @@ -236,9 +218,9 @@ WebKit::WebSerializedScriptValue BrowserWebKitInit::injectIDBKeyIntoSerializedValue( const WebKit::WebIDBKey& key, const WebKit::WebSerializedScriptValue& value, - const WebKit::WebString& keyPath) { + const WebKit::WebIDBKeyPath& keyPath) { return WebKit::WebIDBKey::injectIDBKeyIntoSerializedValue( - key, value, WebKit::WebIDBKeyPath::create(keyPath)); + key, value, keyPath); } WebKit::WebGraphicsContext3D* @@ -264,6 +246,11 @@ base::StringPiece BrowserWebKitInit::GetDataResource(int resource_id) { return _Context->GetDataResource(resource_id); } +base::StringPiece BrowserWebKitInit::GetImageResource(int resource_id, + float scale_factor) { + return GetDataResource(resource_id); +} + webkit_glue::ResourceLoaderBridge* BrowserWebKitInit::CreateResourceLoader( const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { return BrowserResourceLoaderBridge::Create(request_info); diff --git a/cef1/libcef/browser_webkit_init.h b/cef1/libcef/browser_webkit_init.h index 08c6b8dbc..246306e3b 100644 --- a/cef1/libcef/browser_webkit_init.h +++ b/cef1/libcef/browser_webkit_init.h @@ -11,6 +11,7 @@ #include "libcef/browser_appcache_system.h" #include "libcef/browser_database_system.h" +#include "libcef/browser_dom_storage_system.h" #include "libcef/browser_file_system.h" #include "libcef/browser_webblobregistry_impl.h" #include "libcef/browser_webcookiejar_impl.h" @@ -63,23 +64,21 @@ class BrowserWebKitInit : public webkit_glue::WebKitPlatformSupportImpl { virtual WebKit::WebString defaultLocale() OVERRIDE; virtual WebKit::WebStorageNamespace* createLocalStorageNamespace( const WebKit::WebString& path, unsigned quota) OVERRIDE; - void dispatchStorageEvent(const WebKit::WebString& key, - const WebKit::WebString& old_value, const WebKit::WebString& new_value, - const WebKit::WebString& origin, const WebKit::WebURL& url, - bool is_local_storage) OVERRIDE; virtual WebKit::WebIDBFactory* idbFactory() OVERRIDE; virtual void createIDBKeysFromSerializedValuesAndKeyPath( const WebKit::WebVector& values, - const WebKit::WebString& keyPath, + const WebKit::WebIDBKeyPath& keyPath, WebKit::WebVector& keys_out) OVERRIDE; virtual WebKit::WebSerializedScriptValue injectIDBKeyIntoSerializedValue( const WebKit::WebIDBKey& key, const WebKit::WebSerializedScriptValue& value, - const WebKit::WebString& keyPath) OVERRIDE; + const WebKit::WebIDBKeyPath& keyPath) OVERRIDE; virtual WebKit::WebGraphicsContext3D* createOffscreenGraphicsContext3D( const WebKit::WebGraphicsContext3D::Attributes& attributes) OVERRIDE; virtual string16 GetLocalizedString(int message_id) OVERRIDE; virtual base::StringPiece GetDataResource(int resource_id) OVERRIDE; + virtual base::StringPiece GetImageResource(int resource_id, + float scale_factor) OVERRIDE; virtual void GetPlugins(bool refresh, std::vector* plugins) OVERRIDE; virtual webkit_glue::ResourceLoaderBridge* CreateResourceLoader( @@ -106,6 +105,7 @@ class BrowserWebKitInit : public webkit_glue::WebKitPlatformSupportImpl { ScopedTempDir appcache_dir_; BrowserAppCacheSystem appcache_system_; BrowserDatabaseSystem database_system_; + BrowserDomStorageSystem dom_storage_system_; BrowserWebCookieJarImpl cookie_jar_; scoped_refptr blob_registry_; }; diff --git a/cef1/libcef/browser_webstoragearea_impl.cc b/cef1/libcef/browser_webstoragearea_impl.cc deleted file mode 100644 index 11f2235b5..000000000 --- a/cef1/libcef/browser_webstoragearea_impl.cc +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that can -// be found in the LICENSE file. - -#include "libcef/browser_webstoragearea_impl.h" -#include "libcef/cef_context.h" -#include "libcef/dom_storage_area.h" -#include "libcef/dom_storage_namespace.h" - -#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" - -using WebKit::WebFrame; -using WebKit::WebString; -using WebKit::WebURL; -using WebKit::WebView; - -BrowserWebStorageAreaImpl::BrowserWebStorageAreaImpl( - int64 namespace_id, const WebString& origin) { - area_ = - _Context->storage_context()->GetStorageArea(namespace_id, origin, true); - DCHECK(area_ != NULL); -} - -BrowserWebStorageAreaImpl::~BrowserWebStorageAreaImpl() { -} - -unsigned BrowserWebStorageAreaImpl::length() { - return area_->Length(); -} - -WebString BrowserWebStorageAreaImpl::key(unsigned index) { - return area_->Key(index); -} - -WebString BrowserWebStorageAreaImpl::getItem(const WebString& key) { - return area_->GetItem(key); -} - -void BrowserWebStorageAreaImpl::setItem( - const WebString& key, const WebString& value, const WebURL& url, - WebStorageArea::Result& result, WebString& old_value_webkit) { - old_value_webkit = area_->SetItem(key, value, &result); -} - -void BrowserWebStorageAreaImpl::removeItem( - const WebString& key, const WebURL& url, WebString& old_value_webkit) { - old_value_webkit = area_->RemoveItem(key); -} - -void BrowserWebStorageAreaImpl::clear( - const WebURL& url, bool& cleared_something) { - cleared_something = area_->Clear(); -} diff --git a/cef1/libcef/browser_webstoragearea_impl.h b/cef1/libcef/browser_webstoragearea_impl.h deleted file mode 100644 index 961f3b590..000000000 --- a/cef1/libcef/browser_webstoragearea_impl.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that can -// be found in the LICENSE file. - -#ifndef CEF_LIBCEF_BROWSER_WEBSTORAGEAREA_IMPL_H_ -#define CEF_LIBCEF_BROWSER_WEBSTORAGEAREA_IMPL_H_ -#pragma once - -#include "base/basictypes.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" - -class DOMStorageArea; - -class BrowserWebStorageAreaImpl : public WebKit::WebStorageArea { - public: - BrowserWebStorageAreaImpl(int64 namespace_id, - const WebKit::WebString& origin); - virtual ~BrowserWebStorageAreaImpl(); - - // See WebStorageArea.h for documentation on these functions. - virtual unsigned length(); - virtual WebKit::WebString key(unsigned index); - virtual WebKit::WebString getItem(const WebKit::WebString& key); - virtual void setItem( - const WebKit::WebString& key, const WebKit::WebString& value, - const WebKit::WebURL& url, WebStorageArea::Result& result, - WebKit::WebString& old_value); - virtual void removeItem( - const WebKit::WebString& key, const WebKit::WebURL& url, - WebKit::WebString& old_value); - virtual void clear(const WebKit::WebURL& url, bool& cleared_something); - - private: - // The object is owned by DOMStorageNamespace. - DOMStorageArea* area_; -}; - -#endif // CEF_LIBCEF_BROWSER_WEBSTORAGEAREA_IMPL_H_ diff --git a/cef1/libcef/browser_webstoragenamespace_impl.cc b/cef1/libcef/browser_webstoragenamespace_impl.cc deleted file mode 100644 index 5a8d5314a..000000000 --- a/cef1/libcef/browser_webstoragenamespace_impl.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2010 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 "libcef/browser_webstoragenamespace_impl.h" -#include "libcef/browser_webstoragearea_impl.h" -#include "libcef/cef_context.h" - -#include "base/logging.h" - -using WebKit::WebStorageArea; -using WebKit::WebStorageNamespace; -using WebKit::WebString; - -BrowserWebStorageNamespaceImpl::BrowserWebStorageNamespaceImpl( - DOMStorageType storage_type) - : storage_type_(storage_type), - namespace_id_(kLocalStorageNamespaceId) { -} - -BrowserWebStorageNamespaceImpl::BrowserWebStorageNamespaceImpl( - DOMStorageType storage_type, int64 namespace_id) - : storage_type_(storage_type), - namespace_id_(namespace_id) { -} - -BrowserWebStorageNamespaceImpl::~BrowserWebStorageNamespaceImpl() { -} - -WebStorageArea* BrowserWebStorageNamespaceImpl::createStorageArea( - const WebString& origin) { - // Ideally, we'd keep a hash map of origin to these objects. Unfortunately - // this doesn't seem practical because there's no good way to ref-count these - // objects, and it'd be unclear who owned them. So, instead, we'll pay the - // price in terms of wasted memory. - return new BrowserWebStorageAreaImpl(namespace_id_, origin); -} - -WebStorageNamespace* BrowserWebStorageNamespaceImpl::copy() { - // By returning NULL, we're telling WebKit to lazily fetch it the next time - // session storage is used. In the WebViewClient::createView, we do the - // book-keeping necessary to make it a true copy-on-write despite not doing - // anything here, now. - return NULL; -} - -void BrowserWebStorageNamespaceImpl::close() { - // This is called only on LocalStorage namespaces when WebKit thinks its - // shutting down. This has no impact on Chromium. -} diff --git a/cef1/libcef/browser_webstoragenamespace_impl.h b/cef1/libcef/browser_webstoragenamespace_impl.h deleted file mode 100644 index 03aaa85db..000000000 --- a/cef1/libcef/browser_webstoragenamespace_impl.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2010 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 CEF_LIBCEF_BROWSER_WEBSTORAGENAMESPACE_IMPL_H_ -#define CEF_LIBCEF_BROWSER_WEBSTORAGENAMESPACE_IMPL_H_ -#pragma once - -#include "libcef/dom_storage_common.h" - -#include "base/basictypes.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h" - -class BrowserWebStorageNamespaceImpl : public WebKit::WebStorageNamespace { - public: - explicit BrowserWebStorageNamespaceImpl(DOMStorageType storage_type); - BrowserWebStorageNamespaceImpl(DOMStorageType storage_type, - int64 namespace_id); - - // See WebStorageNamespace.h for documentation on these functions. - virtual ~BrowserWebStorageNamespaceImpl(); - virtual WebKit::WebStorageArea* createStorageArea( - const WebKit::WebString& origin); - virtual WebKit::WebStorageNamespace* copy(); - virtual void close(); - - private: - // Used during lazy initialization of namespace_id_. - const DOMStorageType storage_type_; - - // Our namespace ID. - int64 namespace_id_; -}; - -#endif // CEF_LIBCEF_BROWSER_WEBSTORAGENAMESPACE_IMPL_H_ diff --git a/cef1/libcef/browser_webview_delegate.cc b/cef1/libcef/browser_webview_delegate.cc index 7338b7ee2..0e7b0f852 100644 --- a/cef1/libcef/browser_webview_delegate.cc +++ b/cef1/libcef/browser_webview_delegate.cc @@ -12,11 +12,11 @@ #include #include "libcef/browser_appcache_system.h" +#include "libcef/browser_dom_storage_system.h" #include "libcef/browser_file_system.h" #include "libcef/browser_impl.h" #include "libcef/browser_navigation_controller.h" #include "libcef/browser_webkit_glue.h" -#include "libcef/browser_webstoragenamespace_impl.h" #include "libcef/browser_zoom_map.h" #include "libcef/cef_context.h" #include "libcef/cef_process_ui_thread.h" @@ -188,13 +188,7 @@ WebWidget* BrowserWebViewDelegate::createPopupMenu(WebPopupType popup_type) { WebStorageNamespace* BrowserWebViewDelegate::createSessionStorageNamespace( unsigned quota) { -#ifdef ENABLE_NEW_DOM_STORAGE_BACKEND - NOTREACHED(); -#else - // Ignore the quota parameter from WebCore as in Chrome. - return new BrowserWebStorageNamespaceImpl(DOM_STORAGE_SESSION, - kLocalStorageNamespaceId + 1); -#endif + return BrowserDomStorageSystem::instance().CreateSessionStorageNamespace(); } WebKit::WebGraphicsContext3D* BrowserWebViewDelegate::createGraphicsContext3D( @@ -517,6 +511,11 @@ bool BrowserWebViewDelegate::allowScriptExtension( // WebPluginPageDelegate ----------------------------------------------------- +WebKit::WebPlugin* BrowserWebViewDelegate::CreatePluginReplacement( + const FilePath& file_path) { + return NULL; +} + WebCookieJar* BrowserWebViewDelegate::GetCookieJar() { return &cookie_jar_; } diff --git a/cef1/libcef/browser_webview_delegate.h b/cef1/libcef/browser_webview_delegate.h index 69c919c03..fca031d0e 100644 --- a/cef1/libcef/browser_webview_delegate.h +++ b/cef1/libcef/browser_webview_delegate.h @@ -119,8 +119,9 @@ class BrowserWebViewDelegate : public WebKit::WebViewClient, virtual void setToolTipText( const WebKit::WebString& text, WebKit::WebTextDirection hint) OVERRIDE; virtual void startDragging( + WebKit::WebFrame* frame, const WebKit::WebDragData& data, - WebKit::WebDragOperationsMask mask, + WebKit::WebDragOperationsMask mask, const WebKit::WebImage& image, const WebKit::WebPoint& image_offset) OVERRIDE; virtual bool acceptsLoadDrops() OVERRIDE; @@ -221,6 +222,8 @@ class BrowserWebViewDelegate : public WebKit::WebViewClient, virtual webkit::npapi::WebPluginDelegate* CreatePluginDelegate( const FilePath& file_path, const std::string& mime_type) OVERRIDE; + virtual WebKit::WebPlugin* CreatePluginReplacement( + const FilePath& file_path) OVERRIDE; virtual void CreatedPluginWindow( gfx::PluginWindowHandle handle) OVERRIDE; virtual void WillDestroyPluginWindow( diff --git a/cef1/libcef/browser_webview_delegate_gtk.cc b/cef1/libcef/browser_webview_delegate_gtk.cc index d6e07d316..f79b1c22d 100644 --- a/cef1/libcef/browser_webview_delegate_gtk.cc +++ b/cef1/libcef/browser_webview_delegate_gtk.cc @@ -291,11 +291,11 @@ WebRect BrowserWebViewDelegate::windowResizerRect() { } void BrowserWebViewDelegate::startDragging( + WebFrame* frame, const WebDragData& data, WebDragOperationsMask mask, const WebImage& image, const WebPoint& image_offset) { - if (browser_->settings().drag_drop_disabled) { browser_->UIT_GetWebView()->dragSourceSystemDragEnded(); return; diff --git a/cef1/libcef/browser_webview_delegate_mac.mm b/cef1/libcef/browser_webview_delegate_mac.mm index 2ad0dde34..ff62efacf 100644 --- a/cef1/libcef/browser_webview_delegate_mac.mm +++ b/cef1/libcef/browser_webview_delegate_mac.mm @@ -348,10 +348,12 @@ WebRect BrowserWebViewDelegate::windowResizerRect() { return gfx::Rect(NSRectToCGRect(resize_rect)); } -void BrowserWebViewDelegate::startDragging(const WebDragData& data, - WebDragOperationsMask mask, - const WebImage& image, - const WebPoint& image_offset) { +void BrowserWebViewDelegate::startDragging( + WebFrame* frame, + const WebDragData& data, + WebDragOperationsMask mask, + const WebImage& image, + const WebPoint& image_offset) { if (browser_->settings().drag_drop_disabled || browser_->IsWindowRenderingDisabled()) { browser_->UIT_GetWebView()->dragSourceSystemDragEnded(); diff --git a/cef1/libcef/browser_webview_delegate_win.cc b/cef1/libcef/browser_webview_delegate_win.cc index de0f779f6..5f1b731a2 100644 --- a/cef1/libcef/browser_webview_delegate_win.cc +++ b/cef1/libcef/browser_webview_delegate_win.cc @@ -224,6 +224,7 @@ WebRect BrowserWebViewDelegate::windowResizerRect() { } void BrowserWebViewDelegate::startDragging( + WebFrame* frame, const WebDragData& data, WebDragOperationsMask mask, const WebImage& image, diff --git a/cef1/libcef/cef_context.cc b/cef1/libcef/cef_context.cc index 872c12d00..fbda4d188 100644 --- a/cef1/libcef/cef_context.cc +++ b/cef1/libcef/cef_context.cc @@ -12,6 +12,7 @@ #include "base/path_service.h" #include "base/synchronization/waitable_event.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/base/resource/resource_handle.h" #include "ui/base/ui_base_paths.h" #if defined(OS_MACOSX) || defined(OS_WIN) @@ -19,6 +20,7 @@ #endif #if defined(OS_MACOSX) +#include "base/mac/foundation_util.h" #include "base/mac/mac_util.h" #include "grit/webkit_resources.h" #endif @@ -27,15 +29,33 @@ #include "base/win/resource_util.h" #endif -// Both the CefContext constuctor and the CefContext::RemoveBrowser method need -// to initialize or reset to the same value. -const int kNextBrowserIdReset = 1; - // Global CefContext pointer CefRefPtr _Context; namespace { +// Both the CefContext constuctor and the CefContext::RemoveBrowser method need +// to initialize or reset to the same value. +const int kNextBrowserIdReset = 1; + +#if defined(OS_MACOSX) + +FilePath GetDefaultPackPath() { + FilePath bundlePath = base::mac::GetAppBundlePath(execPath); + return bundlePath.Append(FILE_PATH_LITERAL("Contents")) + .Append(FILE_PATH_LITERAL("Resources")); +} + +#else // !defined(OS_MACOSX) + +FilePath GetDefaultPackPath() { + FilePath pak_dir; + PathService::Get(base::DIR_MODULE, &pak_dir); + return pak_dir; +} + +#endif // !defined(OS_MACOSX) + // Used in multi-threaded message loop mode to observe shutdown of the UI // thread. class DestructionObserver : public MessageLoop::DestructionObserver { @@ -66,6 +86,69 @@ base::StringPiece GetRawDataResource(HMODULE module, int resource_id) { } // namespace + +class CefResourceBundleDelegate : public ui::ResourceBundle::Delegate { + public: + CefResourceBundleDelegate(CefContext* context) + : context_(context), + allow_pack_file_load_(false) { + } + + void set_allow_pack_file_load(bool val) { allow_pack_file_load_ = val; } + + private: + virtual FilePath GetPathForResourcePack(const FilePath& pack_path, + float scale_factor) OVERRIDE { + // Only allow the cef pack file to load. + if (!context_->settings().pack_loading_disabled && allow_pack_file_load_) + return pack_path; + return FilePath(); + } + + virtual FilePath GetPathForLocalePack(const FilePath& pack_path, + const std::string& locale) OVERRIDE { + if (!context_->settings().pack_loading_disabled) + return pack_path; + return FilePath(); + } + + virtual gfx::Image GetImageNamed(int resource_id) OVERRIDE { + return gfx::Image(); + } + + virtual gfx::Image GetNativeImageNamed( + int resource_id, + ui::ResourceBundle::ImageRTL rtl) OVERRIDE { + return gfx::Image(); + } + + virtual base::RefCountedStaticMemory* LoadDataResourceBytes( + int resource_id) OVERRIDE { + return NULL; + } + + virtual bool GetRawDataResource(int resource_id, + base::StringPiece* value) OVERRIDE { + return false; + } + + virtual bool GetLocalizedString(int message_id, string16* value) OVERRIDE { + return false; + } + + virtual scoped_ptr GetFont( + ui::ResourceBundle::FontStyle style) OVERRIDE { + return scoped_ptr(); + } + + // CefContext pointer is guaranteed to outlive this object. + CefContext* context_; + bool allow_pack_file_load_; + + DISALLOW_COPY_AND_ASSIGN(CefResourceBundleDelegate); +}; + + bool CefInitialize(const CefSettings& settings, CefRefPtr application) { // Return true if the global context already exists. if (_Context.get()) @@ -157,6 +240,7 @@ void CefQuitMessageLoop() { CefContext::CefContext() : initialized_(false), shutting_down_(false), + request_context_(NULL), next_browser_id_(kNextBrowserIdReset), current_webviewhost_(NULL) { } @@ -293,47 +377,48 @@ CefRefPtr CefContext::GetBrowserByID(int id) { } void CefContext::InitializeResourceBundle() { - if (settings_.pack_loading_disabled) - return; - FilePath pak_file, locales_dir; - if (settings_.pack_file_path.length > 0) - pak_file = FilePath(CefString(&settings_.pack_file_path)); + if (!settings_.pack_loading_disabled) { + if (settings_.pack_file_path.length > 0) + pak_file = FilePath(CefString(&settings_.pack_file_path)); - if (pak_file.empty()) { - FilePath pak_dir; - PathService::Get(base::DIR_MODULE, &pak_dir); - pak_file = pak_dir.Append(FILE_PATH_LITERAL("chrome.pak")); + if (pak_file.empty()) + pak_file = GetDefaultPackPath().Append(FILE_PATH_LITERAL("chrome.pak")); + + if (settings_.locales_dir_path.length > 0) + locales_dir = FilePath(CefString(&settings_.locales_dir_path)); + + if (!locales_dir.empty()) + PathService::Override(ui::DIR_LOCALES, locales_dir); } - if (!pak_file.empty()) - PathService::Override(ui::FILE_RESOURCES_PAK, pak_file); - - if (settings_.locales_dir_path.length > 0) - locales_dir = FilePath(CefString(&settings_.locales_dir_path)); - - if (!locales_dir.empty()) - PathService::Override(ui::DIR_LOCALES, locales_dir); - std::string locale_str = locale(); - const std::string loaded_locale = - ui::ResourceBundle::InitSharedInstanceWithLocale(locale_str); - CHECK(!loaded_locale.empty()) << "Locale could not be found for " << - locale_str; + if (locale_str.empty()) + locale_str = "en-US"; -#if defined(OS_WIN) - // Explicitly load chrome.pak on Windows. - if (file_util::PathExists(pak_file)) - ResourceBundle::AddDataPackToSharedInstance(pak_file); - else - NOTREACHED() << "Could not load chrome.pak"; -#endif + resource_bundle_delegate_.reset(new CefResourceBundleDelegate(this)); + const std::string loaded_locale = + ui::ResourceBundle::InitSharedInstanceWithLocale( + locale_str, resource_bundle_delegate_.get()); + if (!settings_.pack_loading_disabled) { + CHECK(!loaded_locale.empty()) << "Locale could not be found for " + << locale_str; + + if (file_util::PathExists(pak_file)) { + resource_bundle_delegate_->set_allow_pack_file_load(true); + ResourceBundle::GetSharedInstance().AddDataPack( + pak_file, ui::ResourceHandle::kScaleFactor100x); + resource_bundle_delegate_->set_allow_pack_file_load(false); + } else { + NOTREACHED() << "Could not load chrome.pak"; + } + } } void CefContext::CleanupResourceBundle() { - if (!settings_.pack_loading_disabled) - ResourceBundle::CleanupSharedInstance(); + ResourceBundle::CleanupSharedInstance(); + resource_bundle_delegate_.reset(NULL); } string16 CefContext::GetLocalizedString(int message_id) const { @@ -382,7 +467,7 @@ base::StringPiece CefContext::GetDataResource(int resource_id) const { hModule = ::GetModuleHandle(file_path.value().c_str()); if (!hModule) hModule = ::GetModuleHandle(NULL); - value = GetRawDataResource(hModule, resource_id); + value = ::GetRawDataResource(hModule, resource_id); } #elif defined(OS_MACOSX) if (value.empty()) { diff --git a/cef1/libcef/cef_context.h b/cef1/libcef/cef_context.h index beca3cca5..9c7179155 100644 --- a/cef1/libcef/cef_context.h +++ b/cef1/libcef/cef_context.h @@ -15,13 +15,13 @@ #include "libcef/browser_file_system.h" #include "libcef/browser_request_context.h" #include "libcef/cef_process.h" -#include "libcef/dom_storage_context.h" #include "base/at_exit.h" #include "base/file_path.h" #include "base/memory/ref_counted.h" class CefBrowserImpl; +class CefResourceBundleDelegate; class WebViewHost; namespace base { @@ -78,12 +78,6 @@ class CefContext : public CefBase { } BrowserRequestContext* request_context() { return request_context_; } - // The DOMStorageContext object is managed by CefProcessUIThread. - void set_storage_context(DOMStorageContext* storage_context) { - storage_context_.reset(storage_context); - } - DOMStorageContext* storage_context() { return storage_context_.get(); } - BrowserFileSystem* file_system() { return &file_system_; } // Used to keep track of the web view host we're dragging over. WARNING: @@ -116,9 +110,9 @@ class CefContext : public CefBase { CefSettings settings_; CefRefPtr application_; FilePath cache_path_; - scoped_refptr request_context_; - scoped_ptr storage_context_; + BrowserRequestContext* request_context_; BrowserFileSystem file_system_; + scoped_ptr resource_bundle_delegate_; // Map of browsers that currently exist. BrowserList browserlist_; diff --git a/cef1/libcef/cef_process_io_thread.cc b/cef1/libcef/cef_process_io_thread.cc index 4195239ca..b25e8a32c 100644 --- a/cef1/libcef/cef_process_io_thread.cc +++ b/cef1/libcef/cef_process_io_thread.cc @@ -37,18 +37,18 @@ void CefProcessIOThread::Init() { CefThread::Init(); FilePath cache_path(_Context->cache_path()); - request_context_ = new BrowserRequestContext(cache_path, - net::HttpCache::NORMAL, false); - _Context->set_request_context(request_context_); + request_context_.reset(new BrowserRequestContext(cache_path, + net::HttpCache::NORMAL, false)); + _Context->set_request_context(request_context_.get()); network_delegate_.reset(new BrowserNetworkDelegate()); request_context_->set_network_delegate(network_delegate_.get()); - BrowserAppCacheSystem::InitializeOnIOThread(request_context_); - BrowserFileWriter::InitializeOnIOThread(request_context_); + BrowserAppCacheSystem::InitializeOnIOThread(request_context_.get()); + BrowserFileWriter::InitializeOnIOThread(request_context_.get()); BrowserFileSystem::InitializeOnIOThread( request_context_->blob_storage_controller()); - BrowserSocketStreamBridge::InitializeOnIOThread(request_context_); + BrowserSocketStreamBridge::InitializeOnIOThread(request_context_.get()); BrowserWebBlobRegistryImpl::InitializeOnIOThread( request_context_->blob_storage_controller()); } @@ -71,7 +71,8 @@ void CefProcessIOThread::CleanUp() { request_context_->set_network_delegate(NULL); network_delegate_.reset(NULL); - request_context_ = NULL; + _Context->set_request_context(NULL); + request_context_.reset(NULL); CefThread::Cleanup(); } diff --git a/cef1/libcef/cef_process_io_thread.h b/cef1/libcef/cef_process_io_thread.h index 7d971cb94..61341b052 100644 --- a/cef1/libcef/cef_process_io_thread.h +++ b/cef1/libcef/cef_process_io_thread.h @@ -31,15 +31,13 @@ class CefProcessIOThread : public CefThread { explicit CefProcessIOThread(MessageLoop* message_loop); virtual ~CefProcessIOThread(); - scoped_refptr request_context() { - return request_context_; - } + BrowserRequestContext* request_context() { return request_context_.get(); } protected: virtual void Init(); virtual void CleanUp(); - scoped_refptr request_context_; + scoped_ptr request_context_; scoped_ptr network_delegate_; DISALLOW_COPY_AND_ASSIGN(CefProcessIOThread); diff --git a/cef1/libcef/cef_process_ui_thread.cc b/cef1/libcef/cef_process_ui_thread.cc index 55108776a..5b9e35e8f 100644 --- a/cef1/libcef/cef_process_ui_thread.cc +++ b/cef1/libcef/cef_process_ui_thread.cc @@ -24,7 +24,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h" #include "ui/base/ui_base_paths.h" -#include "ui/gfx/gl/gl_implementation.h" +#include "ui/gl/gl_implementation.h" #include "webkit/glue/user_agent.h" #include "webkit/glue/webkit_glue.h" #include "webkit/plugins/npapi/plugin_list.h" @@ -133,17 +133,6 @@ void CefProcessUIThread::Init() { gfx::InitializeGLBindings(gfx::kGLImplementationDesktopGL); #endif - // Set storage quota limits. - if (settings.local_storage_quota != 0) - DOMStorageContext::set_local_storage_quota(settings.local_storage_quota); - if (settings.session_storage_quota != 0) { - DOMStorageContext::set_session_storage_quota( - settings.session_storage_quota); - } - - // Create the storage context object. - _Context->set_storage_context(new DOMStorageContext(_Context->cache_path())); - if (settings.user_agent.length > 0) { webkit_glue::SetUserAgent(CefString(&settings.user_agent), false); } else { @@ -192,9 +181,6 @@ void CefProcessUIThread::CleanUp() { // purify leak-test results. MessageLoop::current()->RunAllPending(); - // Destroy the storage context object. - _Context->set_storage_context(NULL); - // Tear down the shared StatsTable. base::StatsTable::set_current(NULL); delete statstable_; diff --git a/cef1/libcef/cookie_manager_impl.cc b/cef1/libcef/cookie_manager_impl.cc index f6004d665..3044c83a0 100644 --- a/cef1/libcef/cookie_manager_impl.cc +++ b/cef1/libcef/cookie_manager_impl.cc @@ -6,13 +6,13 @@ #include -#include "libcef/browser_persistent_cookie_store.h" #include "libcef/cef_context.h" #include "libcef/cef_thread.h" #include "libcef/cef_time_util.h" #include "base/bind.h" #include "base/logging.h" +#include "chrome/browser/net/sqlite_persistent_cookie_store.h" namespace { @@ -225,11 +225,11 @@ bool CefCookieManagerImpl::SetStoragePath(const CefString& path) { return true; } - scoped_refptr persistent_store; + scoped_refptr persistent_store; if (!new_path.empty()) { if (file_util::CreateDirectory(new_path)) { const FilePath& cookie_path = new_path.AppendASCII("Cookies"); - persistent_store = new BrowserPersistentCookieStore(cookie_path, false); + persistent_store = new SQLitePersistentCookieStore(cookie_path, false); } else { NOTREACHED() << "The cookie storage directory could not be created"; storage_path_.clear(); diff --git a/cef1/libcef/cookie_store_proxy.cc b/cef1/libcef/cookie_store_proxy.cc index c5313f8d1..6fca65928 100644 --- a/cef1/libcef/cookie_store_proxy.cc +++ b/cef1/libcef/cookie_store_proxy.cc @@ -59,6 +59,12 @@ void CefCookieStoreProxy::DeleteAllCreatedBetweenAsync( callback); } +void CefCookieStoreProxy::DeleteSessionCookiesAsync( + const DeleteCallback& callback) { + scoped_refptr cookie_store = GetCookieStore(); + cookie_store->DeleteSessionCookiesAsync(callback); +} + net::CookieMonster* CefCookieStoreProxy::GetCookieMonster() { scoped_refptr cookie_store = GetCookieStore(); return cookie_store->GetCookieMonster(); diff --git a/cef1/libcef/cookie_store_proxy.h b/cef1/libcef/cookie_store_proxy.h index 0b1b215d8..5a8bd79b3 100644 --- a/cef1/libcef/cookie_store_proxy.h +++ b/cef1/libcef/cookie_store_proxy.h @@ -35,6 +35,8 @@ class CefCookieStoreProxy : public net::CookieStore { const base::Time& delete_end, const DeleteCallback& callback) OVERRIDE; + virtual void DeleteSessionCookiesAsync(const DeleteCallback& callback) + OVERRIDE; virtual net::CookieMonster* GetCookieMonster() OVERRIDE; private: diff --git a/cef1/libcef/dom_node_impl.cc b/cef1/libcef/dom_node_impl.cc index 01f4eb307..73fdf78cf 100644 --- a/cef1/libcef/dom_node_impl.cc +++ b/cef1/libcef/dom_node_impl.cc @@ -12,7 +12,6 @@ #include "base/logging.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebAttribute.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEventListener.h" @@ -20,12 +19,10 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebNamedNodeMap.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebSelectElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" -using WebKit::WebAttribute; using WebKit::WebDocument; using WebKit::WebDOMEvent; using WebKit::WebDOMEventListener; @@ -33,7 +30,6 @@ using WebKit::WebElement; using WebKit::WebFrame; using WebKit::WebFormControlElement; using WebKit::WebInputElement; -using WebKit::WebNamedNodeMap; using WebKit::WebNode; using WebKit::WebSelectElement; using WebKit::WebString; @@ -356,7 +352,7 @@ bool CefDOMNodeImpl::HasElementAttributes() { } const WebElement& element = node_.toConst(); - return (element.attributes().length() > 0); + return (element.attributeCount() > 0); } bool CefDOMNodeImpl::HasElementAttribute(const CefString& attrName) { @@ -400,24 +396,14 @@ void CefDOMNodeImpl::GetElementAttributes(AttributeMap& attrMap) { } const WebElement& element = node_.toConst(); - const WebNamedNodeMap& map = element.attributes(); - unsigned int len = map.length(); + unsigned int len = element.attributeCount(); if (len == 0) return; - string16 nameStr, valueStr; - for (unsigned int i = 0; i < len; ++i) { - const WebAttribute& attrib = map.attributeItem(i); - string16 nameStr, valueStr; - const WebString& name = attrib.localName(); - if (!name.isNull()) - nameStr = name; - const WebString& value = attrib.value(); - if (!value.isNull()) - valueStr = value; - - attrMap.insert(std::make_pair(nameStr, valueStr)); + string16 name = element.attributeLocalName(i); + string16 value = element.attributeValue(i); + attrMap.insert(std::make_pair(name, value)); } } diff --git a/cef1/libcef/dom_storage_area.cc b/cef1/libcef/dom_storage_area.cc deleted file mode 100644 index 33fd438a3..000000000 --- a/cef1/libcef/dom_storage_area.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2011 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 "libcef/dom_storage_area.h" -#include "libcef/dom_storage_context.h" -#include "libcef/dom_storage_namespace.h" - -#include "base/logging.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" -#include "webkit/glue/webkit_glue.h" - -using WebKit::WebSecurityOrigin; -using WebKit::WebStorageArea; -using WebKit::WebString; -using WebKit::WebURL; - -DOMStorageArea::DOMStorageArea( - const string16& origin, - int64 id, - DOMStorageNamespace* owner) - : origin_(origin), - origin_url_(origin), - id_(id), - owner_(owner) { - DCHECK(owner_); -} - -DOMStorageArea::~DOMStorageArea() { -} - -unsigned DOMStorageArea::Length() { - CreateWebStorageAreaIfNecessary(); - return storage_area_->length(); -} - -NullableString16 DOMStorageArea::Key(unsigned index) { - CreateWebStorageAreaIfNecessary(); - return storage_area_->key(index); -} - -NullableString16 DOMStorageArea::GetItem(const string16& key) { - CreateWebStorageAreaIfNecessary(); - return storage_area_->getItem(key); -} - -NullableString16 DOMStorageArea::SetItem( - const string16& key, const string16& value, - WebStorageArea::Result* result) { - CreateWebStorageAreaIfNecessary(); - WebString old_value; - storage_area_->setItem(key, value, WebURL(), *result, old_value); - return old_value; -} - -NullableString16 DOMStorageArea::RemoveItem(const string16& key) { - CreateWebStorageAreaIfNecessary(); - WebString old_value; - storage_area_->removeItem(key, WebURL(), old_value); - return old_value; -} - -bool DOMStorageArea::Clear() { - CreateWebStorageAreaIfNecessary(); - bool somethingCleared; - storage_area_->clear(WebURL(), somethingCleared); - return somethingCleared; -} - -void DOMStorageArea::PurgeMemory() { - storage_area_.reset(); -} - -void DOMStorageArea::CreateWebStorageAreaIfNecessary() { - if (!storage_area_.get()) - storage_area_.reset(owner_->CreateWebStorageArea(origin_)); -} diff --git a/cef1/libcef/dom_storage_area.h b/cef1/libcef/dom_storage_area.h deleted file mode 100644 index 797ad4fa1..000000000 --- a/cef1/libcef/dom_storage_area.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2011 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 CEF_LIBCEF_DOM_STORAGE_AREA_H_ -#define CEF_LIBCEF_DOM_STORAGE_AREA_H_ -#pragma once - -#include "base/hash_tables.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/nullable_string16.h" -#include "base/string16.h" -#include "googleurl/src/gurl.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" - -class DOMStorageNamespace; -// Only use on the WebKit thread. DOMStorageNamespace manages our registration -// with DOMStorageContext. -class DOMStorageArea { - public: - DOMStorageArea(const string16& origin, - int64 id, - DOMStorageNamespace* owner); - ~DOMStorageArea(); - - unsigned Length(); - NullableString16 Key(unsigned index); - NullableString16 GetItem(const string16& key); - NullableString16 SetItem( - const string16& key, const string16& value, - WebKit::WebStorageArea::Result* result); - NullableString16 RemoveItem(const string16& key); - bool Clear(); - void PurgeMemory(); - - int64 id() const { return id_; } - - DOMStorageNamespace* owner() const { return owner_; } - const string16& origin() const { return origin_; } - - private: - // Creates the underlying WebStorageArea on demand. - void CreateWebStorageAreaIfNecessary(); - - // The origin this storage area represents. - string16 origin_; - GURL origin_url_; - - // The storage area we wrap. - scoped_ptr storage_area_; - - // Our storage area id. Unique to our parent context. - int64 id_; - - // The DOMStorageNamespace that owns us. - DOMStorageNamespace* owner_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageArea); -}; - -#if defined(COMPILER_GCC) -#if defined(OS_ANDROID) -// Android stlport uses std namespace -namespace std { -#else -namespace __gnu_cxx { -#endif - -template<> -struct hash { - std::size_t operator()(DOMStorageArea* const& p) const { - return reinterpret_cast(p); - } -}; - -} // namespace __gnu_cxx -#endif - -#endif // CEF_LIBCEF_DOM_STORAGE_AREA_H_ diff --git a/cef1/libcef/dom_storage_common.h b/cef1/libcef/dom_storage_common.h deleted file mode 100644 index 609129c5a..000000000 --- a/cef1/libcef/dom_storage_common.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2010 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 CEF_LIBCEF_DOM_STORAGE_COMMON_H_ -#define CEF_LIBCEF_DOM_STORAGE_COMMON_H_ -#pragma once - -#include "base/basictypes.h" - -const int64 kLocalStorageNamespaceId = 0; -const int64 kInvalidSessionStorageNamespaceId = kLocalStorageNamespaceId; - -enum DOMStorageType { - DOM_STORAGE_LOCAL = 0, - DOM_STORAGE_SESSION -}; - -#endif // CEF_LIBCEF_DOM_STORAGE_COMMON_H_ diff --git a/cef1/libcef/dom_storage_context.cc b/cef1/libcef/dom_storage_context.cc deleted file mode 100644 index aa27106e4..000000000 --- a/cef1/libcef/dom_storage_context.cc +++ /dev/null @@ -1,305 +0,0 @@ -// Copyright (c) 2010 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 "libcef/dom_storage_context.h" - -#include - -#include "libcef/cef_thread.h" -#include "libcef/dom_storage_area.h" -#include "libcef/dom_storage_namespace.h" - -#include "base/bind.h" -#include "base/file_path.h" -#include "base/file_util.h" -#include "base/string_util.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" -#include "webkit/database/database_util.h" -#include "webkit/glue/webkit_glue.h" - -const FilePath::CharType DOMStorageContext::kLocalStorageDirectory[] = - FILE_PATH_LITERAL("Local Storage"); - -const FilePath::CharType DOMStorageContext::kLocalStorageExtension[] = - FILE_PATH_LITERAL(".localstorage"); - -// Use WebStorageNamespace quota sizes as the default. -unsigned int DOMStorageContext::local_storage_quota_ = - WebKit::WebStorageNamespace::m_localStorageQuota; -unsigned int DOMStorageContext::session_storage_quota_ = - WebKit::WebStorageNamespace::m_sessionStorageQuota; - -DOMStorageContext::DOMStorageContext(const FilePath& local_storage_path) - : local_storage_path_(local_storage_path), - last_storage_area_id_(0), - last_session_storage_namespace_id_on_ui_thread_(kLocalStorageNamespaceId), - last_session_storage_namespace_id_on_io_thread_( - kLocalStorageNamespaceId) { -} - -DOMStorageContext::~DOMStorageContext() { - for (StorageNamespaceMap::iterator iter(storage_namespace_map_.begin()); - iter != storage_namespace_map_.end(); ++iter) { - delete iter->second; - } -} - -int64 DOMStorageContext::AllocateStorageAreaId() { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - return ++last_storage_area_id_; -} - -int64 DOMStorageContext::AllocateSessionStorageNamespaceId() { - if (CefThread::CurrentlyOn(CefThread::UI)) - return ++last_session_storage_namespace_id_on_ui_thread_; - return --last_session_storage_namespace_id_on_io_thread_; -} - -int64 DOMStorageContext::CloneSessionStorage(int64 original_id) { - DCHECK(!CefThread::CurrentlyOn(CefThread::UI)); - int64 clone_id = AllocateSessionStorageNamespaceId(); - CefThread::PostTask( - CefThread::UI, FROM_HERE, - base::Bind(&DOMStorageContext::CompleteCloningSessionStorage, this, - original_id, clone_id)); - return clone_id; -} - -void DOMStorageContext::RegisterStorageArea(DOMStorageArea* storage_area) { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - int64 id = storage_area->id(); - DCHECK(!GetStorageArea(id)); - storage_area_map_[id] = storage_area; -} - -void DOMStorageContext::UnregisterStorageArea(DOMStorageArea* storage_area) { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - int64 id = storage_area->id(); - DCHECK(GetStorageArea(id)); - storage_area_map_.erase(id); -} - -DOMStorageArea* DOMStorageContext::GetStorageArea(int64 id) { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - StorageAreaMap::iterator iter = storage_area_map_.find(id); - if (iter == storage_area_map_.end()) - return NULL; - return iter->second; -} - -void DOMStorageContext::DeleteSessionStorageNamespace(int64 namespace_id) { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - StorageNamespaceMap::iterator iter = - storage_namespace_map_.find(namespace_id); - if (iter == storage_namespace_map_.end()) - return; - DCHECK(iter->second->dom_storage_type() == DOM_STORAGE_SESSION); - delete iter->second; - storage_namespace_map_.erase(iter); -} - -void DOMStorageContext::DeleteLocalStorageNamespace() { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - StorageNamespaceMap::iterator iter = - storage_namespace_map_.find(kLocalStorageNamespaceId); - if (iter == storage_namespace_map_.end()) - return; - DCHECK(iter->second->dom_storage_type() == DOM_STORAGE_LOCAL); - delete iter->second; - storage_namespace_map_.erase(iter); -} - -DOMStorageNamespace* DOMStorageContext::GetStorageNamespace( - int64 id, bool allocation_allowed) { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - StorageNamespaceMap::iterator iter = storage_namespace_map_.find(id); - if (iter != storage_namespace_map_.end()) - return iter->second; - if (!allocation_allowed) - return NULL; - if (id == kLocalStorageNamespaceId) - return CreateLocalStorage(); - return CreateSessionStorage(id); -} - -DOMStorageArea* DOMStorageContext::GetStorageArea(int64 namespace_id, - const string16& origin, bool allocation_allowed) { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - DOMStorageNamespace* ns = - GetStorageNamespace(namespace_id, allocation_allowed); - if (ns) - return ns->GetStorageArea(origin, allocation_allowed); - return NULL; -} - -void DOMStorageContext::PurgeMemory(int64 namespace_id) { - DOMStorageNamespace* ns = GetStorageNamespace(namespace_id, false); - if (ns) - ns->PurgeMemory(); -} - -void DOMStorageContext::DeleteDataModifiedSince( - const base::Time& cutoff, - const char* url_scheme_to_be_skipped, - const std::vector& protected_origins) { - // Make sure that we don't delete a database that's currently being accessed - // by unloading all of the databases temporarily. - PurgeMemory(kLocalStorageNamespaceId); - - if (local_storage_path_.empty()) - return; - - file_util::FileEnumerator file_enumerator( - local_storage_path_.Append(kLocalStorageDirectory), false, - file_util::FileEnumerator::FILES); - for (FilePath path = file_enumerator.Next(); !path.value().empty(); - path = file_enumerator.Next()) { - WebKit::WebSecurityOrigin web_security_origin = - WebKit::WebSecurityOrigin::createFromDatabaseIdentifier( - webkit_glue::FilePathToWebString(path.BaseName())); - if (EqualsASCII(web_security_origin.protocol(), url_scheme_to_be_skipped)) - continue; - - std::vector::const_iterator find_iter = - std::find(protected_origins.begin(), protected_origins.end(), - web_security_origin.databaseIdentifier()); - if (find_iter != protected_origins.end()) - continue; - - file_util::FileEnumerator::FindInfo find_info; - file_enumerator.GetFindInfo(&find_info); - if (file_util::HasFileBeenModifiedSince(find_info, cutoff)) - file_util::Delete(path, false); - } -} - -void DOMStorageContext::DeleteLocalStorageForOrigin(const string16& origin) { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - - DOMStorageArea* area = - GetStorageArea(kLocalStorageNamespaceId, origin, false); - if (!area) - return; - - // Calling Clear() is necessary to remove the data from the namespace. - area->Clear(); - area->PurgeMemory(); - - if (local_storage_path_.empty()) - return; - - FilePath file_path = GetLocalStorageFilePath(origin); - if (!file_path.empty()) - file_util::Delete(file_path, false); -} - -void DOMStorageContext::DeleteAllLocalStorageFiles() { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - - // Make sure that we don't delete a database that's currently being accessed - // by unloading all of the databases temporarily. - PurgeMemory(kLocalStorageNamespaceId); - - if (local_storage_path_.empty()) - return; - - file_util::FileEnumerator file_enumerator( - local_storage_path_.Append(kLocalStorageDirectory), false, - file_util::FileEnumerator::FILES); - for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); - file_path = file_enumerator.Next()) { - if (file_path.Extension() == kLocalStorageExtension) - file_util::Delete(file_path, false); - } -} - -void DOMStorageContext::SetLocalStoragePath( - const FilePath& local_storage_path) { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - - if ((local_storage_path.empty() && local_storage_path_.empty()) || - local_storage_path == local_storage_path_) - return; - - // Make sure that we don't swap out a database that's currently being accessed - // by unloading all of the databases temporarily. - PurgeMemory(kLocalStorageNamespaceId); - - // Delete the current namespace, if any. It will be recreated using the new - // path when needed. - DeleteLocalStorageNamespace(); - - local_storage_path_ = local_storage_path; -} - -DOMStorageNamespace* DOMStorageContext::CreateLocalStorage() { - FilePath dir_path; - if (!local_storage_path_.empty()) - dir_path = local_storage_path_.Append(kLocalStorageDirectory); - DOMStorageNamespace* new_namespace = - DOMStorageNamespace::CreateLocalStorageNamespace(this, dir_path); - RegisterStorageNamespace(new_namespace); - return new_namespace; -} - -DOMStorageNamespace* DOMStorageContext::CreateSessionStorage( - int64 namespace_id) { - DOMStorageNamespace* new_namespace = - DOMStorageNamespace::CreateSessionStorageNamespace(this, namespace_id); - RegisterStorageNamespace(new_namespace); - return new_namespace; -} - -void DOMStorageContext::RegisterStorageNamespace( - DOMStorageNamespace* storage_namespace) { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - int64 id = storage_namespace->id(); - DCHECK(!GetStorageNamespace(id, false)); - storage_namespace_map_[id] = storage_namespace; -} - -/* static */ -void DOMStorageContext::CompleteCloningSessionStorage( - DOMStorageContext* context, int64 existing_id, int64 clone_id) { - DCHECK(CefThread::CurrentlyOn(CefThread::UI)); - DOMStorageNamespace* existing_namespace = - context->GetStorageNamespace(existing_id, false); - // If nothing exists, then there's nothing to clone. - if (existing_namespace) - context->RegisterStorageNamespace(existing_namespace->Copy(clone_id)); -} - -// static -void DOMStorageContext::ClearLocalState(const FilePath& profile_path, - const char* url_scheme_to_be_skipped) { - file_util::FileEnumerator file_enumerator(profile_path.Append( - kLocalStorageDirectory), false, file_util::FileEnumerator::FILES); - for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); - file_path = file_enumerator.Next()) { - if (file_path.Extension() == kLocalStorageExtension) { - WebKit::WebSecurityOrigin web_security_origin = - WebKit::WebSecurityOrigin::createFromDatabaseIdentifier( - webkit_glue::FilePathToWebString(file_path.BaseName())); - if (!EqualsASCII(web_security_origin.protocol(), - url_scheme_to_be_skipped)) - file_util::Delete(file_path, false); - } - } -} - -FilePath DOMStorageContext::GetLocalStorageFilePath( - const string16& origin) const { - DCHECK(!local_storage_path_.empty()); - - string16 origin_id = - webkit_database::DatabaseUtil::GetOriginIdentifier(GURL(origin)); - - FilePath storageDir = local_storage_path_.Append( - DOMStorageContext::kLocalStorageDirectory); - FilePath::StringType id = - webkit_glue::WebStringToFilePathString(origin_id); - return storageDir.Append(id.append(kLocalStorageExtension)); -} diff --git a/cef1/libcef/dom_storage_context.h b/cef1/libcef/dom_storage_context.h deleted file mode 100644 index 819f5a7c6..000000000 --- a/cef1/libcef/dom_storage_context.h +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (c) 2010 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 CEF_LIBCEF_DOM_STORAGE_CONTEXT_H_ -#define CEF_LIBCEF_DOM_STORAGE_CONTEXT_H_ -#pragma once - -#include -#include -#include - -#include "base/file_path.h" -#include "base/string16.h" -#include "base/time.h" - -class DOMStorageArea; -class DOMStorageNamespace; - -// This is owned by CefContext and is all the dom storage information that's -// shared by all of the browser windows. The specifics of responsibilities are -// fairly well documented here and in StorageNamespace and StorageArea. -// Everything is only to be accessed on the WebKit thread unless noted -// otherwise. -// -// NOTE: Virtual methods facilitate mocking functions for testing. -class DOMStorageContext { - public: - explicit DOMStorageContext(const FilePath& local_storage_path); - virtual ~DOMStorageContext(); - - // Allocate a new storage area id. Only call on the WebKit thread. - int64 AllocateStorageAreaId(); - - // Allocate a new session storage id. Only call on the UI or IO thread. - int64 AllocateSessionStorageNamespaceId(); - - // Clones a session storage namespace and returns the cloned namespaces' id. - // Only call on the IO thread. - int64 CloneSessionStorage(int64 original_id); - - // Various storage area methods. The storage area is owned by one of the - // namespaces that's owned by this class. - void RegisterStorageArea(DOMStorageArea* storage_area); - void UnregisterStorageArea(DOMStorageArea* storage_area); - DOMStorageArea* GetStorageArea(int64 id); - - // Called on WebKit thread when a session storage namespace can be deleted. - void DeleteSessionStorageNamespace(int64 namespace_id); - - // Called on WebKit thread when the local storage namespace can be deleted. - void DeleteLocalStorageNamespace(); - - // Get a namespace from an id. What's returned is owned by this class. If - // allocation_allowed is true, then this function will create the storage - // namespace if it hasn't been already. - DOMStorageNamespace* GetStorageNamespace(int64 id, bool allocation_allowed); - - // Get a storage area with the specified namespace_id and origin. If - // allocation_allowed is true this function will create a new namespace and/or - // storage area if it doesn't already exist. - DOMStorageArea* GetStorageArea(int64 namespace_id, const string16& origin, - bool allocation_allowed); - - // Tells storage namespaces to purge any memory they do not need. - virtual void PurgeMemory(int64 namespace_id); - - // Delete any local storage files that have been touched since the cutoff - // date that's supplied. - void DeleteDataModifiedSince(const base::Time& cutoff, - const char* url_scheme_to_be_skipped, - const std::vector& protected_origins); - - // Deletes the local storage file for the given origin. - void DeleteLocalStorageForOrigin(const string16& origin); - - // Deletes all local storage files. - void DeleteAllLocalStorageFiles(); - - // Sets the path that will be used for local storage. If |local_storage_path| - // is empty in-memory storage will be used. - void SetLocalStoragePath(const FilePath& local_storage_path); - - // The local storage directory. - static const FilePath::CharType kLocalStorageDirectory[]; - - // The local storage file extension. - static const FilePath::CharType kLocalStorageExtension[]; - - // Delete all non-extension local storage files. - static void ClearLocalState(const FilePath& profile_path, - const char* url_scheme_to_be_skipped); - - // Get the file name of the local storage file for the given origin. - FilePath GetLocalStorageFilePath(const string16& origin) const; - - // Set the quota limits for localStorage and sessionStorage respectively. - // Changes will only take affect if made before creation of the namespaces. - static void set_local_storage_quota(unsigned int quota) - { local_storage_quota_ = quota; } - static void set_session_storage_quota(unsigned int quota) - { session_storage_quota_ = quota; } - static unsigned int local_storage_quota() { return local_storage_quota_; } - static unsigned int session_storage_quota() { return session_storage_quota_; } - - private: - // Get the local storage instance. The object is owned by this class. - DOMStorageNamespace* CreateLocalStorage(); - - // Get a new session storage namespace. The object is owned by this class. - DOMStorageNamespace* CreateSessionStorage(int64 namespace_id); - - // Used internally to register storage namespaces we create. - void RegisterStorageNamespace(DOMStorageNamespace* storage_namespace); - - // The WebKit thread half of CloneSessionStorage above. Static because - // DOMStorageContext isn't ref counted thus we can't use a runnable method. - // That said, we know this is safe because this class is destroyed on the - // WebKit thread, so there's no way it could be destroyed before this is run. - static void CompleteCloningSessionStorage(DOMStorageContext* context, - int64 existing_id, int64 clone_id); - - // Location where localStorage files will be stored on disk. This may be empty - // in which case localStorage data will be stored in-memory only. - FilePath local_storage_path_; - - // The last used storage_area_id and storage_namespace_id's. For the storage - // namespaces, IDs allocated on the UI thread are positive and count up while - // IDs allocated on the IO thread are negative and count down. This allows us - // to allocate unique IDs on both without any locking. All storage area ids - // are allocated on the WebKit thread. - int64 last_storage_area_id_; - int64 last_session_storage_namespace_id_on_ui_thread_; - int64 last_session_storage_namespace_id_on_io_thread_; - - // Maps ids to StorageAreas. We do NOT own these objects. StorageNamespace - // (which does own them) will notify us when we should remove the entries. - typedef std::map StorageAreaMap; - StorageAreaMap storage_area_map_; - - // Maps ids to StorageNamespaces. We own these objects. - typedef std::map StorageNamespaceMap; - StorageNamespaceMap storage_namespace_map_; - - // Quota limits for localStorage and sessionStorage respectively. - static unsigned int local_storage_quota_; - static unsigned int session_storage_quota_; -}; - -#endif // CEF_LIBCEF_DOM_STORAGE_CONTEXT_H_ diff --git a/cef1/libcef/dom_storage_namespace.cc b/cef1/libcef/dom_storage_namespace.cc deleted file mode 100644 index 1f140202e..000000000 --- a/cef1/libcef/dom_storage_namespace.cc +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright (c) 2010 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 "libcef/dom_storage_namespace.h" -#include "libcef/dom_storage_area.h" -#include "libcef/dom_storage_context.h" - -#include "base/file_path.h" -#include "base/logging.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h" -#include "webkit/glue/webkit_glue.h" - -using WebKit::WebStorageArea; -using WebKit::WebStorageNamespace; -using WebKit::WebString; - -/* static */ -DOMStorageNamespace* DOMStorageNamespace::CreateLocalStorageNamespace( - DOMStorageContext* dom_storage_context, const FilePath& data_dir_path) { - int64 id = kLocalStorageNamespaceId; - DCHECK(!dom_storage_context->GetStorageNamespace(id, false)); - WebString path; - if (!data_dir_path.empty()) - path = webkit_glue::FilePathToWebString(data_dir_path); - return new DOMStorageNamespace(dom_storage_context, id, path, - DOM_STORAGE_LOCAL); -} - -/* static */ -DOMStorageNamespace* DOMStorageNamespace::CreateSessionStorageNamespace( - DOMStorageContext* dom_storage_context, int64 id) { - DCHECK(!dom_storage_context->GetStorageNamespace(id, false)); - return new DOMStorageNamespace(dom_storage_context, id, WebString(), - DOM_STORAGE_SESSION); -} - -DOMStorageNamespace::DOMStorageNamespace(DOMStorageContext* dom_storage_context, - int64 id, - const WebString& data_dir_path, - DOMStorageType dom_storage_type) - : dom_storage_context_(dom_storage_context), - id_(id), - data_dir_path_(data_dir_path), - dom_storage_type_(dom_storage_type) { - DCHECK(dom_storage_context_); -} - -DOMStorageNamespace::~DOMStorageNamespace() { - // TODO(jorlow): If the DOMStorageContext is being destructed, there's no need - // to do these calls. Maybe we should add a fast path? - for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); - iter != origin_to_storage_area_.end(); ++iter) { - dom_storage_context_->UnregisterStorageArea(iter->second); - delete iter->second; - } -} - -DOMStorageArea* DOMStorageNamespace::GetStorageArea( - const string16& origin, bool allocation_allowed) { - // We may have already created it for another dispatcher host. - OriginToStorageAreaMap::iterator iter = origin_to_storage_area_.find(origin); - if (iter != origin_to_storage_area_.end()) - return iter->second; - - if (!allocation_allowed) - return NULL; - - // We need to create a new one. - int64 id = dom_storage_context_->AllocateStorageAreaId(); - DCHECK(!dom_storage_context_->GetStorageArea(id)); - DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this); - origin_to_storage_area_[origin] = storage_area; - dom_storage_context_->RegisterStorageArea(storage_area); - return storage_area; -} - -DOMStorageNamespace* DOMStorageNamespace::Copy(int64 id) { - DCHECK(dom_storage_type_ == DOM_STORAGE_SESSION); - DCHECK(!dom_storage_context_->GetStorageNamespace(id, false)); - DOMStorageNamespace* new_storage_namespace = new DOMStorageNamespace( - dom_storage_context_, id, data_dir_path_, dom_storage_type_); - // If we haven't used the namespace yet, there's nothing to copy. - if (storage_namespace_.get()) - new_storage_namespace->storage_namespace_.reset(storage_namespace_->copy()); - return new_storage_namespace; -} - -void DOMStorageNamespace::GetStorageAreas(std::vector& areas, - bool skip_empty) const { - OriginToStorageAreaMap::const_iterator iter = origin_to_storage_area_.begin(); - for (; iter != origin_to_storage_area_.end(); ++iter) { - if (!skip_empty || iter->second->Length() > 0) - areas.push_back(iter->second); - } -} - -void DOMStorageNamespace::PurgeMemory() { - for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); - iter != origin_to_storage_area_.end(); ++iter) - iter->second->PurgeMemory(); - storage_namespace_.reset(); -} - -WebStorageArea* DOMStorageNamespace::CreateWebStorageArea( - const string16& origin) { - CreateWebStorageNamespaceIfNecessary(); - return storage_namespace_->createStorageArea(origin); -} - -void DOMStorageNamespace::CreateWebStorageNamespaceIfNecessary() { - if (storage_namespace_.get()) - return; - - if (dom_storage_type_ == DOM_STORAGE_LOCAL) { - storage_namespace_.reset( - WebStorageNamespace::createLocalStorageNamespace(data_dir_path_, - DOMStorageContext::local_storage_quota())); - } else { - storage_namespace_.reset(WebStorageNamespace::createSessionStorageNamespace( - DOMStorageContext::session_storage_quota())); - } -} diff --git a/cef1/libcef/dom_storage_namespace.h b/cef1/libcef/dom_storage_namespace.h deleted file mode 100644 index 406d7db84..000000000 --- a/cef1/libcef/dom_storage_namespace.h +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) 2010 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 CEF_LIBCEF_DOM_STORAGE_NAMESPACE_H_ -#define CEF_LIBCEF_DOM_STORAGE_NAMESPACE_H_ -#pragma once - -#include "libcef/dom_storage_common.h" - -#include - -#include "base/hash_tables.h" -#include "base/memory/scoped_ptr.h" -#include "base/string16.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" - -class DOMStorageArea; -class DOMStorageContext; -class FilePath; - -namespace WebKit { -class WebStorageArea; -class WebStorageNamespace; -} - -// Only to be used on the WebKit thread. -class DOMStorageNamespace { - public: - static DOMStorageNamespace* CreateLocalStorageNamespace( - DOMStorageContext* dom_storage_context, const FilePath& data_dir_path); - static DOMStorageNamespace* CreateSessionStorageNamespace( - DOMStorageContext* dom_storage_context, int64 namespace_id); - - ~DOMStorageNamespace(); - - DOMStorageArea* GetStorageArea(const string16& origin, - bool allocation_allowed); - DOMStorageNamespace* Copy(int64 clone_namespace_id); - - void GetStorageAreas(std::vector& areas, - bool skip_empty) const; - - void PurgeMemory(); - - const DOMStorageContext* dom_storage_context() const { - return dom_storage_context_; - } - int64 id() const { return id_; } - const WebKit::WebString& data_dir_path() const { return data_dir_path_; } - DOMStorageType dom_storage_type() const { return dom_storage_type_; } - - // Creates a WebStorageArea for the given origin. This should only be called - // by an owned DOMStorageArea. - WebKit::WebStorageArea* CreateWebStorageArea(const string16& origin); - - private: - // Called by the static factory methods above. - DOMStorageNamespace(DOMStorageContext* dom_storage_context, - int64 id, - const WebKit::WebString& data_dir_path, - DOMStorageType storage_type); - - // Creates the underlying WebStorageNamespace on demand. - void CreateWebStorageNamespaceIfNecessary(); - - // All the storage areas we own. - typedef base::hash_map OriginToStorageAreaMap; - OriginToStorageAreaMap origin_to_storage_area_; - - // The DOMStorageContext that owns us. - DOMStorageContext* dom_storage_context_; - - // The WebKit storage namespace we manage. - scoped_ptr storage_namespace_; - - // Our id. Unique to our parent context class. - int64 id_; - - // The path used to create us, so we can recreate our WebStorageNamespace on - // demand. - WebKit::WebString data_dir_path_; - - // SessionStorage vs. LocalStorage. - const DOMStorageType dom_storage_type_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageNamespace); -}; - -#endif // CEF_LIBCEF_DOM_STORAGE_NAMESPACE_H_ diff --git a/cef1/libcef/drag_data_impl.cc b/cef1/libcef/drag_data_impl.cc index ecc197edb..07dc1cb1f 100644 --- a/cef1/libcef/drag_data_impl.cc +++ b/cef1/libcef/drag_data_impl.cc @@ -54,9 +54,10 @@ bool CefDragDataImpl::GetFileNames(std::vector& names) { if (data_.filenames.empty()) return false; - std::vector::const_iterator it = data_.filenames.begin(); + std::vector::const_iterator it = + data_.filenames.begin(); for (; it != data_.filenames.end(); ++it) - names.push_back(*it); + names.push_back(it->path); return true; } diff --git a/cef1/libcef/sqlite_diagnostics_stub.cc b/cef1/libcef/sqlite_diagnostics_stub.cc new file mode 100644 index 000000000..128913b69 --- /dev/null +++ b/cef1/libcef/sqlite_diagnostics_stub.cc @@ -0,0 +1,10 @@ +// Copyright (c) 2012 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 "chrome/browser/diagnostics/sqlite_diagnostics.h" + +// Used by SQLitePersistentCookieStore +sql::ErrorDelegate* GetErrorHandlerForCookieDb() { + return NULL; +} diff --git a/cef1/libcef/storage_impl.cc b/cef1/libcef/storage_impl.cc deleted file mode 100644 index 8417c84c6..000000000 --- a/cef1/libcef/storage_impl.cc +++ /dev/null @@ -1,304 +0,0 @@ -// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that can -// be found in the LICENSE file. - -#include "include/cef_storage.h" -#include "libcef/cef_context.h" -#include "libcef/cef_thread.h" -#include "libcef/dom_storage_common.h" -#include "libcef/dom_storage_namespace.h" -#include "libcef/dom_storage_area.h" - -namespace { - -void UIT_VisitStorage(int64 namespace_id, const CefString& origin, - const CefString& key, - CefRefPtr visitor) { - REQUIRE_UIT(); - - DOMStorageContext* context = _Context->storage_context(); - - // Allow storage to be allocated for localStorage so that on-disk data, if - // any, will be available. - bool allocation_allowed = (namespace_id == kLocalStorageNamespaceId); - - DOMStorageNamespace* ns = - context->GetStorageNamespace(namespace_id, allocation_allowed); - if (!ns) - return; - - typedef std::vector AreaList; - AreaList areas; - - if (!origin.empty()) { - // Visit only the area with the specified origin. - DOMStorageArea* area = ns->GetStorageArea(origin, allocation_allowed); - if (area) - areas.push_back(area); - } else { - // Visit all areas. - ns->GetStorageAreas(areas, true); - } - - if (areas.empty()) - return; - - // Count the total number of matching keys. - unsigned int total = 0; - { - NullableString16 value; - AreaList::iterator it = areas.begin(); - for (; it != areas.end(); ) { - DOMStorageArea* area = (*it); - if (!key.empty()) { - value = area->GetItem(key); - if (value.is_null()) { - it = areas.erase(it); - // Don't increment the iterator. - continue; - } else { - total++; - } - } else { - total += area->Length(); - } - ++it; - } - } - - if (total == 0) - return; - - DOMStorageArea* area; - bool stop = false, deleteData; - unsigned int count = 0, i, len; - NullableString16 keyVal, valueVal; - string16 keyStr, valueStr; - typedef std::vector String16List; - String16List delete_keys; - - // Visit all matching pairs. - AreaList::iterator it = areas.begin(); - for (; it != areas.end() && !stop; ++it) { - // Each area. - area = *(it); - if (!key.empty()) { - // Visit only the matching key. - valueVal = area->GetItem(key); - if (valueVal.is_null()) - valueStr.clear(); - else - valueStr = valueVal.string(); - - deleteData = false; - stop = !visitor->Visit(static_cast(namespace_id), - area->origin(), key, valueStr, count, total, deleteData); - if (deleteData) - area->RemoveItem(key); - count++; - } else { - // Visit all keys. - len = area->Length(); - for (i = 0; i < len && !stop; ++i) { - keyVal = area->Key(i); - if (keyVal.is_null()) { - keyStr.clear(); - valueStr.clear(); - } else { - keyStr = keyVal.string(); - valueVal = area->GetItem(keyStr); - if (valueVal.is_null()) - valueStr.clear(); - else - valueStr = valueVal.string(); - } - - deleteData = false; - stop = !visitor->Visit(static_cast(namespace_id), - area->origin(), keyStr, valueStr, count, total, deleteData); - if (deleteData) - delete_keys.push_back(keyStr); - count++; - } - - // Delete the requested keys. - if (!delete_keys.empty()) { - String16List::const_iterator it = delete_keys.begin(); - for (; it != delete_keys.end(); ++it) - area->RemoveItem(*it); - delete_keys.clear(); - } - } - } -} - -void UIT_SetStoragePath(int64 namespace_id, const CefString& path) { - REQUIRE_UIT(); - - if (namespace_id != kLocalStorageNamespaceId) - return; - - FilePath file_path; - if (!path.empty()) - file_path = FilePath(path); - - DOMStorageContext* context = _Context->storage_context(); - DCHECK(context); - if (context) - context->SetLocalStoragePath(file_path); -} - -} // namespace - -bool CefVisitStorage(CefStorageType type, const CefString& origin, - const CefString& key, - CefRefPtr visitor) { - // Verify that the context is in a valid state. - if (!CONTEXT_STATE_VALID()) { - NOTREACHED() << "context not valid"; - return false; - } - - int64 namespace_id; - if (type == ST_LOCALSTORAGE) { - namespace_id = kLocalStorageNamespaceId; - } else if (type == ST_SESSIONSTORAGE) { - namespace_id = kLocalStorageNamespaceId + 1; - } else { - NOTREACHED() << "invalid type"; - return false; - } - - if (CefThread::CurrentlyOn(CefThread::UI)) { - UIT_VisitStorage(namespace_id, origin, key, visitor); - } else { - CefThread::PostTask(CefThread::UI, FROM_HERE, - base::Bind(&UIT_VisitStorage, namespace_id, origin, key, visitor)); - } - - return true; -} - -bool CefSetStorage(CefStorageType type, const CefString& origin, - const CefString& key, const CefString& value) { - // Verify that the context is in a valid state. - if (!CONTEXT_STATE_VALID()) { - NOTREACHED() << "context not valid"; - return false; - } - - // Verify that this function is being called on the UI thread. - if (!CefThread::CurrentlyOn(CefThread::UI)) { - NOTREACHED() << "called on invalid thread"; - return false; - } - - int64 namespace_id; - if (type == ST_LOCALSTORAGE) { - namespace_id = kLocalStorageNamespaceId; - } else if (type == ST_SESSIONSTORAGE) { - namespace_id = kLocalStorageNamespaceId + 1; - } else { - NOTREACHED() << "invalid type"; - return false; - } - - if (origin.empty()) { - NOTREACHED() << "invalid origin"; - return false; - } - - DOMStorageArea* area = - _Context->storage_context()->GetStorageArea(namespace_id, origin, true); - if (!area) - return false; - - WebKit::WebStorageArea::Result result; - area->SetItem(key, value, &result); - return (result == WebKit::WebStorageArea::ResultOK); -} - -bool CefDeleteStorage(CefStorageType type, const CefString& origin, - const CefString& key) { - // Verify that the context is in a valid state. - if (!CONTEXT_STATE_VALID()) { - NOTREACHED() << "context not valid"; - return false; - } - - // Verify that this function is being called on the UI thread. - if (!CefThread::CurrentlyOn(CefThread::UI)) { - NOTREACHED() << "called on invalid thread"; - return false; - } - - int64 namespace_id; - if (type == ST_LOCALSTORAGE) { - namespace_id = kLocalStorageNamespaceId; - } else if (type == ST_SESSIONSTORAGE) { - namespace_id = kLocalStorageNamespaceId + 1; - } else { - NOTREACHED() << "invalid type"; - return false; - } - - DOMStorageContext* context = _Context->storage_context(); - - // Allow storage to be allocated for localStorage so that on-disk data, if - // any, will be available. - bool allocation_allowed = (namespace_id == kLocalStorageNamespaceId); - - if (origin.empty()) { - // Delete all storage for the namespace. - if (namespace_id == kLocalStorageNamespaceId) - context->DeleteAllLocalStorageFiles(); - else - context->PurgeMemory(namespace_id); - } else if (key.empty()) { - // Clear the storage area for the specified origin. - if (namespace_id == kLocalStorageNamespaceId) { - context->DeleteLocalStorageForOrigin(origin); - } else { - DOMStorageArea* area = - context->GetStorageArea(namespace_id, origin, allocation_allowed); - if (area) { - // Calling Clear() is necessary to remove the data from the namespace. - area->Clear(); - area->PurgeMemory(); - } - } - } else { - // Delete the specified key. - DOMStorageArea* area = - context->GetStorageArea(namespace_id, origin, allocation_allowed); - if (area) - area->RemoveItem(key); - } - - return true; -} - -bool CefSetStoragePath(CefStorageType type, const CefString& path) { - // Verify that the context is in a valid state. - if (!CONTEXT_STATE_VALID()) { - NOTREACHED() << "context not valid"; - return false; - } - - int64 namespace_id; - if (type == ST_LOCALSTORAGE) { - namespace_id = kLocalStorageNamespaceId; - } else { - NOTREACHED() << "invalid type"; - return false; - } - - if (CefThread::CurrentlyOn(CefThread::UI)) { - UIT_SetStoragePath(namespace_id, path); - } else { - CefThread::PostTask(CefThread::UI, FROM_HERE, - base::Bind(&UIT_SetStoragePath, namespace_id, path)); - } - - return true; -} diff --git a/cef1/libcef/v8_impl.cc b/cef1/libcef/v8_impl.cc index e7dc8b3e6..e2cdf6d26 100644 --- a/cef1/libcef/v8_impl.cc +++ b/cef1/libcef/v8_impl.cc @@ -2,10 +2,19 @@ // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. -#include "libcef/v8_impl.h" - #include +#include "base/compiler_specific.h" + +#include "third_party/WebKit/Source/WebCore/config.h" +MSVC_PUSH_WARNING_LEVEL(0); +#include "V8Proxy.h" // NOLINT(build/include) +#include "V8RecursionScope.h" // NOLINT(build/include) +MSVC_POP_WARNING(); +#undef LOG + +#include "libcef/v8_impl.h" + #include "libcef/browser_impl.h" #include "libcef/cef_context.h" #include "libcef/tracker.h" @@ -30,10 +39,7 @@ namespace { -static const char kCefAccessor[] = "Cef::Accessor"; -static const char kCefHandler[] = "Cef::Handler"; -static const char kCefUserData[] = "Cef::UserData"; -static const char kCefExternalMemory[] = "Cef::ExternalMemory"; +static const char kCefTrackObject[] = "Cef::TrackObject"; // Memory manager. @@ -41,20 +47,78 @@ base::LazyInstance g_v8_tracker = LAZY_INSTANCE_INITIALIZER; class V8TrackObject : public CefTrackNode { public: - V8TrackObject(CefBase* object = NULL, CefBase* user_data = NULL) - : object_(object), - user_data_(user_data), - external_memory_counter_(0) { + V8TrackObject() + : external_memory_(0) { + } + ~V8TrackObject() { + if (external_memory_ != 0) + v8::V8::AdjustAmountOfExternalAllocatedMemory(-external_memory_); } - int* GetMemoryCounter() { - return &external_memory_counter_; + inline int GetExternallyAllocatedMemory() { + return external_memory_; + } + + int AdjustExternallyAllocatedMemory(int change_in_bytes) { + int new_value = external_memory_ + change_in_bytes; + if (new_value < 0) { + NOTREACHED() << "External memory usage cannot be less than 0 bytes"; + change_in_bytes = -(external_memory_); + new_value = 0; + } + + if (change_in_bytes != 0) + v8::V8::AdjustAmountOfExternalAllocatedMemory(change_in_bytes); + external_memory_ = new_value; + + return new_value; + } + + inline void SetAccessor(CefRefPtr accessor) { + accessor_ = accessor; + } + + inline CefRefPtr GetAccessor() { + return accessor_; + } + + inline void SetHandler(CefRefPtr handler) { + handler_ = handler; + } + + inline CefRefPtr GetHandler() { + return handler_; + } + + inline void SetUserData(CefRefPtr user_data) { + user_data_ = user_data; + } + + inline CefRefPtr GetUserData() { + return user_data_; + } + + // Attach this track object to the specified V8 object. + void AttachTo(v8::Handle object) { + object->SetHiddenValue(v8::String::New(kCefTrackObject), + v8::External::Wrap(this)); + } + + // Retrieve the track object for the specified V8 object. + static V8TrackObject* Unwrap(v8::Handle object) { + v8::Local value = + object->GetHiddenValue(v8::String::New(kCefTrackObject)); + if (!value.IsEmpty()) + return static_cast(v8::External::Unwrap(value)); + + return NULL; } private: - CefRefPtr object_; + CefRefPtr accessor_; + CefRefPtr handler_; CefRefPtr user_data_; - int external_memory_counter_; + int external_memory_; }; class V8TrackString : public CefTrackNode { @@ -76,16 +140,9 @@ void TrackDelete(CefTrackNode* object) { // Callback for weak persistent reference destruction. void TrackDestructor(v8::Persistent object, void* parameter) { - if (parameter) { - if (object->IsObject()) { - V8TrackObject* tracker = static_cast(parameter); - DCHECK(tracker); - int adjustment = -(*tracker->GetMemoryCounter()); - if (adjustment != 0) - v8::V8::AdjustAmountOfExternalAllocatedMemory(adjustment); - } + if (parameter) TrackDelete(static_cast(parameter)); - } + object.Dispose(); object.Clear(); } @@ -213,8 +270,13 @@ v8::Handle AccessorGetterCallbackImpl(v8::Local property, v8::Handle obj = info.This(); - CefV8Accessor* accessorPtr = CefV8ValueImpl::GetAccessor(obj); - if (accessorPtr) { + CefRefPtr accessorPtr; + + V8TrackObject* tracker = V8TrackObject::Unwrap(obj); + if (tracker) + accessorPtr = tracker->GetAccessor(); + + if (accessorPtr.get()) { CefRefPtr retval; CefRefPtr object = new CefV8ValueImpl(obj); CefString name, exception; @@ -241,8 +303,13 @@ void AccessorSetterCallbackImpl(v8::Local property, v8::Handle obj = info.This(); - CefV8Accessor* accessorPtr = CefV8ValueImpl::GetAccessor(obj); - if (accessorPtr) { + CefRefPtr accessorPtr; + + V8TrackObject* tracker = V8TrackObject::Unwrap(obj); + if (tracker) + accessorPtr = tracker->GetAccessor(); + + if (accessorPtr.get()) { CefRefPtr object = new CefV8ValueImpl(obj); CefRefPtr cefValue = new CefV8ValueImpl(value); CefString name, exception; @@ -264,8 +331,10 @@ class ExtensionWrapper : public v8::Extension { CefV8Handler* handler) : v8::Extension(extension_name, javascript_code), handler_(handler) { if (handler) { - // The reference will be released when the application exits. - TrackAdd(new V8TrackObject(handler)); + // The reference will be released when the process exits. + V8TrackObject* object = new V8TrackObject; + object->SetHandler(handler); + TrackAdd(object); } } @@ -339,6 +408,9 @@ class CefV8ExceptionImpl : public CefV8Exception { } // namespace + +// Global functions. + bool CefRegisterExtension(const CefString& extension_name, const CefString& javascript_code, CefRefPtr handler) { @@ -359,7 +431,7 @@ bool CefRegisterExtension(const CefString& extension_name, } -// CefV8Context +// CefV8Context implementation. // static CefRefPtr CefV8Context::GetCurrentContext() { @@ -393,7 +465,25 @@ bool CefV8Context::InContext() { } -// CefV8ContextImpl +// CefV8ContextImpl implementation. + +#define CEF_V8_REQUIRE_OBJECT_RETURN(ret) \ + if (!GetHandle()->IsObject()) { \ + NOTREACHED() << "V8 value is not an object"; \ + return ret; \ + } + +#define CEF_V8_REQUIRE_ARRAY_RETURN(ret) \ + if (!GetHandle()->IsArray()) { \ + NOTREACHED() << "V8 value is not an array"; \ + return ret; \ + } + +#define CEF_V8_REQUIRE_FUNCTION_RETURN(ret) \ + if (!GetHandle()->IsFunction()) { \ + NOTREACHED() << "V8 value is not a function"; \ + return ret; \ + } CefV8ContextImpl::CefV8ContextImpl(v8::Handle context) #ifndef NDEBUG @@ -475,6 +565,51 @@ bool CefV8ContextImpl::IsSame(CefRefPtr that) { return (thisHandle == thatHandle); } +bool CefV8ContextImpl::Eval(const CefString& code, + CefRefPtr& retval, + CefRefPtr& exception) { + CEF_REQUIRE_UI_THREAD(NULL); + + if (code.empty()) { + NOTREACHED() << "invalid input parameter"; + return false; + } + + v8::HandleScope handle_scope; + v8::Context::Scope context_scope(v8_context_->GetHandle()); + v8::Local obj = v8_context_->GetHandle()->Global(); + + // Retrieve the eval function. + v8::Local val = obj->Get(v8::String::New("eval")); + if (val.IsEmpty() || !val->IsFunction()) + return false; + + v8::Local func = v8::Local::Cast(val); + v8::Handle code_val = GetV8String(code); + + v8::TryCatch try_catch; + try_catch.SetVerbose(true); + v8::Local func_rv; + + retval = NULL; + exception = NULL; + + // Execute the function call using the V8Proxy so that inspector + // instrumentation works. + WebCore::V8Proxy* proxy = WebCore::V8Proxy::retrieve(); + DCHECK(proxy); + if (proxy) + func_rv = proxy->callFunction(func, obj, 1, &code_val); + + if (try_catch.HasCaught()) { + exception = new CefV8ExceptionImpl(try_catch.Message()); + return false; + } else if (!func_rv.IsEmpty()) { + retval = new CefV8ValueImpl(func_rv); + } + return true; +} + v8::Local CefV8ContextImpl::GetContext() { return v8::Local::New(v8_context_->GetHandle()); } @@ -530,13 +665,21 @@ CefRefPtr CefV8Value::CreateBool(bool value) { } // static -CefRefPtr CefV8Value::CreateInt(int value) { +CefRefPtr CefV8Value::CreateInt(int32 value) { CEF_REQUIRE_VALID_CONTEXT(NULL); CEF_REQUIRE_UI_THREAD(NULL); v8::HandleScope handle_scope; return new CefV8ValueImpl(v8::Int32::New(value)); } +// static +CefRefPtr CefV8Value::CreateUInt(uint32 value) { + CEF_REQUIRE_VALID_CONTEXT(NULL); + CEF_REQUIRE_UI_THREAD(NULL); + v8::HandleScope handle_scope; + return new CefV8ValueImpl(v8::Int32::NewFromUnsigned(value)); +} + // static CefRefPtr CefV8Value::CreateDouble(double value) { CEF_REQUIRE_VALID_CONTEXT(NULL); @@ -564,7 +707,7 @@ CefRefPtr CefV8Value::CreateString(const CefString& value) { // static CefRefPtr CefV8Value::CreateObject( - CefRefPtr user_data, CefRefPtr accessor) { + CefRefPtr accessor) { CEF_REQUIRE_VALID_CONTEXT(NULL); CEF_REQUIRE_UI_THREAD(NULL); @@ -579,39 +722,19 @@ CefRefPtr CefV8Value::CreateObject( // Create the new V8 object. v8::Local obj = v8::Object::New(); - // Provide a tracker object that will cause the user data and/or accessor + // Create a tracker object that will cause the user data and/or accessor // reference to be released when the V8 object is destroyed. - V8TrackObject* tracker = NULL; - if (user_data.get() && accessor.get()) { - tracker = new V8TrackObject(accessor, user_data); - } else if (user_data.get() || accessor.get()) { - CefBase* object = user_data.get() ? user_data.get() : accessor.get(); - tracker = new V8TrackObject(object); - } else { - tracker = new V8TrackObject(); - } + V8TrackObject* tracker = new V8TrackObject; + tracker->SetAccessor(accessor); - // Attach the memory counter. - obj->SetHiddenValue(v8::String::New(kCefExternalMemory), - v8::External::Wrap(tracker->GetMemoryCounter())); - - // Attach the user data to the V8 object. - if (user_data.get()) { - v8::Local data = v8::External::Wrap(user_data.get()); - obj->SetHiddenValue(v8::String::New(kCefUserData), data); - } - - // Attach the accessor to the V8 object. - if (accessor.get()) { - v8::Local data = v8::External::Wrap(accessor.get()); - obj->SetHiddenValue(v8::String::New(kCefAccessor), data); - } + // Attach the tracker object. + tracker->AttachTo(obj); return new CefV8ValueImpl(obj, tracker); } // static -CefRefPtr CefV8Value::CreateArray() { +CefRefPtr CefV8Value::CreateArray(int length) { CEF_REQUIRE_VALID_CONTEXT(NULL); CEF_REQUIRE_UI_THREAD(NULL); @@ -623,12 +746,23 @@ CefRefPtr CefV8Value::CreateArray() { return NULL; } - return new CefV8ValueImpl(v8::Array::New()); + // Create a tracker object that will cause the user data reference to be + // released when the V8 object is destroyed. + V8TrackObject* tracker = new V8TrackObject; + + // Create the new V8 array. + v8::Local arr = v8::Array::New(length); + + // Attach the tracker object. + tracker->AttachTo(arr); + + return new CefV8ValueImpl(arr, tracker); } // static CefRefPtr CefV8Value::CreateFunction( - const CefString& name, CefRefPtr handler) { + const CefString& name, + CefRefPtr handler) { CEF_REQUIRE_VALID_CONTEXT(NULL); CEF_REQUIRE_UI_THREAD(NULL); @@ -645,7 +779,7 @@ CefRefPtr CefV8Value::CreateFunction( return NULL; } - // Create a new V8 function template with one internal field. + // Create a new V8 function template. v8::Local tmpl = v8::FunctionTemplate::New(); v8::Local data = v8::External::Wrap(handler.get()); @@ -662,14 +796,13 @@ CefRefPtr CefV8Value::CreateFunction( func->SetName(GetV8String(name)); - V8TrackObject* tracker = new V8TrackObject(handler.get()); + // Create a tracker object that will cause the user data and/or handler + // reference to be released when the V8 object is destroyed. + V8TrackObject* tracker = new V8TrackObject; + tracker->SetHandler(handler); - // Attach the memory counter. - func->SetHiddenValue(v8::String::New(kCefExternalMemory), - v8::External::Wrap(tracker->GetMemoryCounter())); - - // Attach the handler instance to the V8 object. - func->SetHiddenValue(v8::String::New(kCefHandler), data); + // Attach the tracker object. + tracker->AttachTo(func); // Create the CefV8ValueImpl and provide a tracker object that will cause // the handler reference to be released when the V8 object is destroyed. @@ -680,7 +813,8 @@ CefRefPtr CefV8Value::CreateFunction( // CefV8ValueImpl CefV8ValueImpl::CefV8ValueImpl(v8::Handle value, - CefTrackNode* tracker) { + CefTrackNode* tracker) + : rethrow_exceptions_(false) { v8_value_ = new CefV8ValueHandle(value, tracker); } @@ -708,6 +842,11 @@ bool CefV8ValueImpl::IsInt() { return GetHandle()->IsInt32(); } +bool CefV8ValueImpl::IsUInt() { + CEF_REQUIRE_UI_THREAD(false); + return GetHandle()->IsUint32(); +} + bool CefV8ValueImpl::IsDouble() { CEF_REQUIRE_UI_THREAD(false); return GetHandle()->IsNumber(); @@ -766,13 +905,20 @@ bool CefV8ValueImpl::GetBoolValue() { } } -int CefV8ValueImpl::GetIntValue() { +int32 CefV8ValueImpl::GetIntValue() { CEF_REQUIRE_UI_THREAD(0); v8::HandleScope handle_scope; v8::Local val = GetHandle()->ToInt32(); return val->Value(); } +uint32 CefV8ValueImpl::GetUIntValue() { + CEF_REQUIRE_UI_THREAD(0); + v8::HandleScope handle_scope; + v8::Local val = GetHandle()->ToUint32(); + return val->Value(); +} + double CefV8ValueImpl::GetDoubleValue() { CEF_REQUIRE_UI_THREAD(0.); v8::HandleScope handle_scope; @@ -796,12 +942,57 @@ CefString CefV8ValueImpl::GetStringValue() { return rv; } +bool CefV8ValueImpl::IsUserCreated() { + CEF_REQUIRE_UI_THREAD(false); + CEF_V8_REQUIRE_OBJECT_RETURN(false); + + v8::HandleScope handle_scope; + v8::Local obj = GetHandle()->ToObject(); + + V8TrackObject* tracker = V8TrackObject::Unwrap(obj); + return (tracker != NULL); +} + +bool CefV8ValueImpl::HasException() { + CEF_REQUIRE_UI_THREAD(false); + CEF_V8_REQUIRE_OBJECT_RETURN(false); + + return (last_exception_.get() != NULL); +} + +CefRefPtr CefV8ValueImpl::GetException() { + CEF_REQUIRE_UI_THREAD(NULL); + CEF_V8_REQUIRE_OBJECT_RETURN(NULL); + + return last_exception_; +} + +bool CefV8ValueImpl::ClearException() { + CEF_REQUIRE_UI_THREAD(NULL); + CEF_V8_REQUIRE_OBJECT_RETURN(NULL); + + last_exception_ = NULL; + return true; +} + +bool CefV8ValueImpl::WillRethrowExceptions() { + CEF_REQUIRE_UI_THREAD(false); + CEF_V8_REQUIRE_OBJECT_RETURN(false); + + return rethrow_exceptions_; +} + +bool CefV8ValueImpl::SetRethrowExceptions(bool rethrow) { + CEF_REQUIRE_UI_THREAD(false); + CEF_V8_REQUIRE_OBJECT_RETURN(false); + + rethrow_exceptions_ = rethrow; + return true; +} + bool CefV8ValueImpl::HasValue(const CefString& key) { CEF_REQUIRE_UI_THREAD(false); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return false; - } + CEF_V8_REQUIRE_OBJECT_RETURN(false); if (key.empty()) { NOTREACHED() << "invalid input parameter"; @@ -815,10 +1006,8 @@ bool CefV8ValueImpl::HasValue(const CefString& key) { bool CefV8ValueImpl::HasValue(int index) { CEF_REQUIRE_UI_THREAD(false); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return false; - } + CEF_V8_REQUIRE_OBJECT_RETURN(false); + if (index < 0) { NOTREACHED() << "invalid input parameter"; return false; @@ -831,10 +1020,7 @@ bool CefV8ValueImpl::HasValue(int index) { bool CefV8ValueImpl::DeleteValue(const CefString& key) { CEF_REQUIRE_UI_THREAD(false); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return false; - } + CEF_V8_REQUIRE_OBJECT_RETURN(false); if (key.empty()) { NOTREACHED() << "invalid input parameter"; @@ -843,15 +1029,17 @@ bool CefV8ValueImpl::DeleteValue(const CefString& key) { v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); - return obj->Delete(GetV8String(key)); + + v8::TryCatch try_catch; + try_catch.SetVerbose(true); + bool del = obj->Delete(GetV8String(key)); + return (!HasCaught(try_catch) && del); } bool CefV8ValueImpl::DeleteValue(int index) { CEF_REQUIRE_UI_THREAD(false); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return false; - } + CEF_V8_REQUIRE_OBJECT_RETURN(false); + if (index < 0) { NOTREACHED() << "invalid input parameter"; return false; @@ -859,15 +1047,16 @@ bool CefV8ValueImpl::DeleteValue(int index) { v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); - return obj->Delete(index); + + v8::TryCatch try_catch; + try_catch.SetVerbose(true); + bool del = obj->Delete(index); + return (!HasCaught(try_catch) && del); } CefRefPtr CefV8ValueImpl::GetValue(const CefString& key) { CEF_REQUIRE_UI_THREAD(NULL); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return NULL; - } + CEF_V8_REQUIRE_OBJECT_RETURN(NULL); if (key.empty()) { NOTREACHED() << "invalid input parameter"; @@ -876,15 +1065,19 @@ CefRefPtr CefV8ValueImpl::GetValue(const CefString& key) { v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); - return new CefV8ValueImpl(obj->Get(GetV8String(key))); + + v8::TryCatch try_catch; + try_catch.SetVerbose(true); + v8::Local value = obj->Get(GetV8String(key)); + if (!HasCaught(try_catch) && !value.IsEmpty()) + return new CefV8ValueImpl(value); + return NULL; } CefRefPtr CefV8ValueImpl::GetValue(int index) { CEF_REQUIRE_UI_THREAD(NULL); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return NULL; - } + CEF_V8_REQUIRE_OBJECT_RETURN(NULL); + if (index < 0) { NOTREACHED() << "invalid input parameter"; return NULL; @@ -892,24 +1085,31 @@ CefRefPtr CefV8ValueImpl::GetValue(int index) { v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); - return new CefV8ValueImpl(obj->Get(v8::Number::New(index))); + + v8::TryCatch try_catch; + try_catch.SetVerbose(true); + v8::Local value = obj->Get(v8::Number::New(index)); + if (!HasCaught(try_catch) && !value.IsEmpty()) + return new CefV8ValueImpl(value); + return NULL; } bool CefV8ValueImpl::SetValue(const CefString& key, CefRefPtr value, PropertyAttribute attribute) { CEF_REQUIRE_UI_THREAD(false); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return false; - } + CEF_V8_REQUIRE_OBJECT_RETURN(false); CefV8ValueImpl* impl = static_cast(value.get()); if (impl && !key.empty()) { v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); - return obj->Set(GetV8String(key), impl->GetHandle(), - static_cast(attribute)); + + v8::TryCatch try_catch; + try_catch.SetVerbose(true); + bool set = obj->Set(GetV8String(key), impl->GetHandle(), + static_cast(attribute)); + return (!HasCaught(try_catch) && set); } else { NOTREACHED() << "invalid input parameter"; return false; @@ -918,11 +1118,8 @@ bool CefV8ValueImpl::SetValue(const CefString& key, bool CefV8ValueImpl::SetValue(int index, CefRefPtr value) { CEF_REQUIRE_UI_THREAD(false); + CEF_V8_REQUIRE_OBJECT_RETURN(false); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return false; - } if (index < 0) { NOTREACHED() << "invalid input parameter"; return false; @@ -932,7 +1129,11 @@ bool CefV8ValueImpl::SetValue(int index, CefRefPtr value) { if (impl) { v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); - return obj->Set(index, impl->GetHandle()); + + v8::TryCatch try_catch; + try_catch.SetVerbose(true); + bool set = obj->Set(index, impl->GetHandle()); + return (!HasCaught(try_catch) && set); } else { NOTREACHED() << "invalid input parameter"; return false; @@ -942,10 +1143,7 @@ bool CefV8ValueImpl::SetValue(int index, CefRefPtr value) { bool CefV8ValueImpl::SetValue(const CefString& key, AccessControl settings, PropertyAttribute attribute) { CEF_REQUIRE_UI_THREAD(false); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return false; - } + CEF_V8_REQUIRE_OBJECT_RETURN(false); if (key.empty()) { NOTREACHED() << "invalid input parameter"; @@ -955,26 +1153,31 @@ bool CefV8ValueImpl::SetValue(const CefString& key, AccessControl settings, v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); + CefRefPtr accessorPtr; + + V8TrackObject* tracker = V8TrackObject::Unwrap(obj); + if (tracker) + accessorPtr = tracker->GetAccessor(); + // Verify that an accessor exists for this object. - if (!GetAccessor(obj)) + if (!accessorPtr.get()) return false; v8::AccessorGetter getter = AccessorGetterCallbackImpl; v8::AccessorSetter setter = (attribute & V8_PROPERTY_ATTRIBUTE_READONLY) ? NULL : AccessorSetterCallbackImpl; - bool rv = obj->SetAccessor(GetV8String(key), getter, setter, obj, - static_cast(settings), - static_cast(attribute)); - return rv; + v8::TryCatch try_catch; + try_catch.SetVerbose(true); + bool set = obj->SetAccessor(GetV8String(key), getter, setter, obj, + static_cast(settings), + static_cast(attribute)); + return (!HasCaught(try_catch) && set); } bool CefV8ValueImpl::GetKeys(std::vector& keys) { CEF_REQUIRE_UI_THREAD(false); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return false; - } + CEF_V8_REQUIRE_OBJECT_RETURN(false); v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); @@ -989,66 +1192,67 @@ bool CefV8ValueImpl::GetKeys(std::vector& keys) { return true; } -CefRefPtr CefV8ValueImpl::GetUserData() { - CEF_REQUIRE_UI_THREAD(NULL); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return NULL; - } +bool CefV8ValueImpl::SetUserData(CefRefPtr user_data) { + CEF_REQUIRE_UI_THREAD(false); + CEF_V8_REQUIRE_OBJECT_RETURN(false); v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); - v8::Local value = - obj->GetHiddenValue(v8::String::New(kCefUserData)); - if (!value.IsEmpty()) - return static_cast(v8::External::Unwrap(value)); + V8TrackObject* tracker = V8TrackObject::Unwrap(obj); + if (tracker) { + tracker->SetUserData(user_data); + return true; + } + + return false; +} + +CefRefPtr CefV8ValueImpl::GetUserData() { + CEF_REQUIRE_UI_THREAD(NULL); + CEF_V8_REQUIRE_OBJECT_RETURN(NULL); + + v8::HandleScope handle_scope; + v8::Local obj = GetHandle()->ToObject(); + + V8TrackObject* tracker = V8TrackObject::Unwrap(obj); + if (tracker) + return tracker->GetUserData(); return NULL; } int CefV8ValueImpl::GetExternallyAllocatedMemory() { CEF_REQUIRE_UI_THREAD(0); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return 0; - } + CEF_V8_REQUIRE_OBJECT_RETURN(0); - int* counter = GetExternallyAllocatedMemoryCounter(); - return counter != NULL ? *counter : 0; + v8::HandleScope handle_scope; + v8::Local obj = GetHandle()->ToObject(); + + V8TrackObject* tracker = V8TrackObject::Unwrap(obj); + if (tracker) + return tracker->GetExternallyAllocatedMemory(); + + return 0; } int CefV8ValueImpl::AdjustExternallyAllocatedMemory(int change_in_bytes) { CEF_REQUIRE_UI_THREAD(0); - if (!GetHandle()->IsObject()) { - NOTREACHED() << "V8 value is not an object"; - return 0; - } + CEF_V8_REQUIRE_OBJECT_RETURN(0); - int* counter = GetExternallyAllocatedMemoryCounter(); - if (counter == NULL) - return 0; + v8::HandleScope handle_scope; + v8::Local obj = GetHandle()->ToObject(); - int new_value = *counter + change_in_bytes; - if (new_value < 0) { - NOTREACHED() << "External memory usage cannot be less than 0 bytes"; - change_in_bytes = -(*counter); - new_value = 0; - } + V8TrackObject* tracker = V8TrackObject::Unwrap(obj); + if (tracker) + return tracker->AdjustExternallyAllocatedMemory(change_in_bytes); - if (change_in_bytes != 0) - v8::V8::AdjustAmountOfExternalAllocatedMemory(change_in_bytes); - *counter = new_value; - - return new_value; + return 0; } int CefV8ValueImpl::GetArrayLength() { CEF_REQUIRE_UI_THREAD(0); - if (!GetHandle()->IsArray()) { - NOTREACHED() << "V8 value is not an array"; - return 0; - } + CEF_V8_REQUIRE_ARRAY_RETURN(0); v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); @@ -1059,10 +1263,7 @@ int CefV8ValueImpl::GetArrayLength() { CefString CefV8ValueImpl::GetFunctionName() { CefString rv; CEF_REQUIRE_UI_THREAD(rv); - if (!GetHandle()->IsFunction()) { - NOTREACHED() << "V8 value is not a function"; - return rv; - } + CEF_V8_REQUIRE_FUNCTION_RETURN(rv); v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); @@ -1073,45 +1274,32 @@ CefString CefV8ValueImpl::GetFunctionName() { CefRefPtr CefV8ValueImpl::GetFunctionHandler() { CEF_REQUIRE_UI_THREAD(NULL); - if (!GetHandle()->IsFunction()) { - NOTREACHED() << "V8 value is not a function"; - return NULL; - } + CEF_V8_REQUIRE_FUNCTION_RETURN(NULL); v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); - v8::Local value = - obj->GetHiddenValue(v8::String::New(kCefHandler)); - if (!value.IsEmpty()) - return static_cast(v8::External::Unwrap(value)); + V8TrackObject* tracker = V8TrackObject::Unwrap(obj); + if (tracker) + return tracker->GetHandler(); return NULL; } -bool CefV8ValueImpl::ExecuteFunction(CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefRefPtr& exception, - bool rethrow_exception) { +CefRefPtr CefV8ValueImpl::ExecuteFunction( + CefRefPtr object, + const CefV8ValueList& arguments) { // An empty context value defaults to the current context. CefRefPtr context; - return ExecuteFunctionWithContext(context, object, arguments, retval, - exception, rethrow_exception); + return ExecuteFunctionWithContext(context, object, arguments); } -bool CefV8ValueImpl::ExecuteFunctionWithContext( - CefRefPtr context, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefRefPtr& exception, - bool rethrow_exception) { - CEF_REQUIRE_UI_THREAD(false); - if (!GetHandle()->IsFunction()) { - NOTREACHED() << "V8 value is not a function"; - return false; - } +CefRefPtr CefV8ValueImpl::ExecuteFunctionWithContext( + CefRefPtr context, + CefRefPtr object, + const CefV8ValueList& arguments) { + CEF_REQUIRE_UI_THREAD(NULL); + CEF_V8_REQUIRE_FUNCTION_RETURN(NULL); v8::HandleScope handle_scope; @@ -1146,38 +1334,39 @@ bool CefV8ValueImpl::ExecuteFunctionWithContext( argv[i] = static_cast(arguments[i].get())->GetHandle(); } - v8::TryCatch try_catch; - v8::Local func_rv = func->Call(recv, argc, argv); - if (try_catch.HasCaught()) { - exception = new CefV8ExceptionImpl(try_catch.Message()); - if (rethrow_exception) - try_catch.ReThrow(); - } else { - retval = new CefV8ValueImpl(func_rv); + CefRefPtr retval; + + { + v8::TryCatch try_catch; + try_catch.SetVerbose(true); + v8::Local func_rv; + + // Execute the function call using the V8Proxy so that inspector + // instrumentation works. + WebCore::V8Proxy* proxy = WebCore::V8Proxy::retrieve(); + DCHECK(proxy); + if (proxy) + func_rv = proxy->callFunction(func, recv, argc, argv); + + if (!HasCaught(try_catch) && !func_rv.IsEmpty()) + retval = new CefV8ValueImpl(func_rv); } if (argv) delete [] argv; - return true; + return retval; } -// static -CefV8Accessor* CefV8ValueImpl::GetAccessor(v8::Handle object) { - v8::Local value = - object->GetHiddenValue(v8::String::New(kCefAccessor)); - if (!value.IsEmpty()) - return static_cast(v8::External::Unwrap(value)); - - return NULL; -} - -int* CefV8ValueImpl::GetExternallyAllocatedMemoryCounter() { - v8::HandleScope handle_scope; - v8::Local obj = GetHandle()->ToObject(); - v8::Local value = - obj->GetHiddenValue(v8::String::New(kCefExternalMemory)); - - return value.IsEmpty() ? NULL : static_cast( - v8::External::Unwrap(value)); +bool CefV8ValueImpl::HasCaught(v8::TryCatch& try_catch) { + if (try_catch.HasCaught()) { + last_exception_ = new CefV8ExceptionImpl(try_catch.Message()); + if (rethrow_exceptions_) + try_catch.ReThrow(); + return true; + } else { + if (last_exception_.get()) + last_exception_ = NULL; + return false; + } } diff --git a/cef1/libcef/v8_impl.h b/cef1/libcef/v8_impl.h index 85af47b44..ca42909c9 100644 --- a/cef1/libcef/v8_impl.h +++ b/cef1/libcef/v8_impl.h @@ -7,6 +7,7 @@ #pragma once #include + #include "include/cef_v8.h" #include "v8/include/v8.h" #include "libcef/cef_thread.h" @@ -68,6 +69,9 @@ class CefV8ContextImpl : public CefV8Context { virtual bool Enter() OVERRIDE; virtual bool Exit() OVERRIDE; virtual bool IsSame(CefRefPtr that) OVERRIDE; + virtual bool Eval(const CefString& code, + CefRefPtr& retval, + CefRefPtr& exception) OVERRIDE; v8::Local GetContext(); WebKit::WebFrame* GetWebFrame(); @@ -115,6 +119,7 @@ class CefV8ValueImpl : public CefV8Value { virtual bool IsNull() OVERRIDE; virtual bool IsBool() OVERRIDE; virtual bool IsInt() OVERRIDE; + virtual bool IsUInt() OVERRIDE; virtual bool IsDouble() OVERRIDE; virtual bool IsDate() OVERRIDE; virtual bool IsString() OVERRIDE; @@ -123,10 +128,17 @@ class CefV8ValueImpl : public CefV8Value { virtual bool IsFunction() OVERRIDE; virtual bool IsSame(CefRefPtr value) OVERRIDE; virtual bool GetBoolValue() OVERRIDE; - virtual int GetIntValue() OVERRIDE; + virtual int32 GetIntValue() OVERRIDE; + virtual uint32 GetUIntValue() OVERRIDE; virtual double GetDoubleValue() OVERRIDE; virtual CefTime GetDateValue() OVERRIDE; virtual CefString GetStringValue() OVERRIDE; + virtual bool IsUserCreated() OVERRIDE; + virtual bool HasException() OVERRIDE; + virtual CefRefPtr GetException() OVERRIDE; + virtual bool ClearException() OVERRIDE; + virtual bool WillRethrowExceptions() OVERRIDE; + virtual bool SetRethrowExceptions(bool rethrow) OVERRIDE; virtual bool HasValue(const CefString& key) OVERRIDE; virtual bool HasValue(int index) OVERRIDE; virtual bool DeleteValue(const CefString& key) OVERRIDE; @@ -139,38 +151,33 @@ class CefV8ValueImpl : public CefV8Value { virtual bool SetValue(const CefString& key, AccessControl settings, PropertyAttribute attribute) OVERRIDE; virtual bool GetKeys(std::vector& keys) OVERRIDE; + virtual bool SetUserData(CefRefPtr user_data) OVERRIDE; virtual CefRefPtr GetUserData() OVERRIDE; virtual int GetExternallyAllocatedMemory() OVERRIDE; virtual int AdjustExternallyAllocatedMemory(int change_in_bytes) OVERRIDE; virtual int GetArrayLength() OVERRIDE; virtual CefString GetFunctionName() OVERRIDE; virtual CefRefPtr GetFunctionHandler() OVERRIDE; - virtual bool ExecuteFunction(CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefRefPtr& exception, - bool rethrow_exception) OVERRIDE; - virtual bool ExecuteFunctionWithContext( - CefRefPtr context, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefRefPtr& exception, - bool rethrow_exception) OVERRIDE; + virtual CefRefPtr ExecuteFunction( + CefRefPtr object, + const CefV8ValueList& arguments) OVERRIDE; + virtual CefRefPtr ExecuteFunctionWithContext( + CefRefPtr context, + CefRefPtr object, + const CefV8ValueList& arguments) OVERRIDE; inline v8::Handle GetHandle() { DCHECK(v8_value_.get()); return v8_value_->GetHandle(); } - // Returns the accessor assigned for the specified object, if any. - static CefV8Accessor* GetAccessor(v8::Handle object); - - private: - int* GetExternallyAllocatedMemoryCounter(); - protected: + // Test for and record any exception. + bool HasCaught(v8::TryCatch& try_catch); + scoped_refptr v8_value_; + CefRefPtr last_exception_; + bool rethrow_exceptions_; IMPLEMENT_REFCOUNTING(CefV8ValueImpl); DISALLOW_COPY_AND_ASSIGN(CefV8ValueImpl); diff --git a/cef1/libcef/webview_host.h b/cef1/libcef/webview_host.h index dc9537c95..d4acf7462 100644 --- a/cef1/libcef/webview_host.h +++ b/cef1/libcef/webview_host.h @@ -14,9 +14,12 @@ #include "webkit/plugins/npapi/gtk_plugin_container_manager.h" #endif -struct WebPreferences; class BrowserWebViewDelegate; +namespace webkit_glue { +struct WebPreferences; +} + namespace WebKit { class WebDevToolsAgentClient; class WebView; @@ -33,7 +36,7 @@ class WebViewHost : public WebWidgetHost { BrowserWebViewDelegate* delegate, PaintDelegate* paint_delegate, WebKit::WebDevToolsAgentClient* devtools_client, - const WebPreferences& prefs); + const webkit_glue::WebPreferences& prefs); virtual ~WebViewHost(); diff --git a/cef1/libcef/webview_host_gtk.cc b/cef1/libcef/webview_host_gtk.cc index f7d12c82d..4c78980ee 100644 --- a/cef1/libcef/webview_host_gtk.cc +++ b/cef1/libcef/webview_host_gtk.cc @@ -28,7 +28,7 @@ WebViewHost* WebViewHost::Create(GtkWidget* parent_view, BrowserWebViewDelegate* delegate, PaintDelegate* paint_delegate, WebDevToolsAgentClient* dev_tools_client, - const WebPreferences& prefs) { + const webkit_glue::WebPreferences& prefs) { WebViewHost* host = new WebViewHost(delegate); host->view_ = WebWidgetHost::CreateWidget(parent_view, host); diff --git a/cef1/libcef/webview_host_mac.mm b/cef1/libcef/webview_host_mac.mm index 79924a35e..d22a2108f 100644 --- a/cef1/libcef/webview_host_mac.mm +++ b/cef1/libcef/webview_host_mac.mm @@ -31,7 +31,7 @@ WebViewHost* WebViewHost::Create(NSView* parent_view, BrowserWebViewDelegate* delegate, PaintDelegate* paint_delegate, WebDevToolsAgentClient* dev_tools_client, - const WebPreferences& prefs) { + const webkit_glue::WebPreferences& prefs) { WebViewHost* host = new WebViewHost(delegate); NSRect content_rect = {{rect.x(), rect.y()}, {rect.width(), rect.height()}}; diff --git a/cef1/libcef/webview_host_win.cc b/cef1/libcef/webview_host_win.cc index 0daf8c3c1..9b7d22050 100644 --- a/cef1/libcef/webview_host_win.cc +++ b/cef1/libcef/webview_host_win.cc @@ -28,7 +28,7 @@ WebViewHost* WebViewHost::Create(HWND parent_view, BrowserWebViewDelegate* delegate, PaintDelegate* paint_delegate, WebDevToolsAgentClient* dev_tools_client, - const WebPreferences& prefs) { + const webkit_glue::WebPreferences& prefs) { WebViewHost* host = new WebViewHost(delegate); if (!paint_delegate) { diff --git a/cef1/libcef_dll/cpptoc/storage_visitor_cpptoc.cc b/cef1/libcef_dll/cpptoc/storage_visitor_cpptoc.cc deleted file mode 100644 index b5c4a42ac..000000000 --- a/cef1/libcef_dll/cpptoc/storage_visitor_cpptoc.cc +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2012 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. -// -// --------------------------------------------------------------------------- -// -// This file was generated by the CEF translator tool. If making changes by -// hand only do so within the body of existing method and function -// implementations. See the translator.README.txt file in the tools directory -// for more information. -// - -#include "libcef_dll/cpptoc/storage_visitor_cpptoc.h" - - -// MEMBER FUNCTIONS - Body may be edited by hand. - -int CEF_CALLBACK storage_visitor_visit(struct _cef_storage_visitor_t* self, - enum cef_storage_type_t type, const cef_string_t* origin, - const cef_string_t* key, const cef_string_t* value, int count, int total, - int* deleteData) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - DCHECK(self); - if (!self) - return 0; - // Verify param: origin; type: string_byref_const - DCHECK(origin); - if (!origin) - return 0; - // Verify param: key; type: string_byref_const - DCHECK(key); - if (!key) - return 0; - // Verify param: value; type: string_byref_const - DCHECK(value); - if (!value) - return 0; - // Verify param: deleteData; type: bool_byref - DCHECK(deleteData); - if (!deleteData) - return 0; - - // Translate param: deleteData; type: bool_byref - bool deleteDataBool = (deleteData && *deleteData)?true:false; - - // Execute - bool _retval = CefStorageVisitorCppToC::Get(self)->Visit( - type, - CefString(origin), - CefString(key), - CefString(value), - count, - total, - deleteDataBool); - - // Restore param: deleteData; type: bool_byref - if (deleteData) - *deleteData = deleteDataBool?true:false; - - // Return type: bool - return _retval; -} - - -// CONSTRUCTOR - Do not edit by hand. - -CefStorageVisitorCppToC::CefStorageVisitorCppToC(CefStorageVisitor* cls) - : CefCppToC(cls) { - struct_.struct_.visit = storage_visitor_visit; -} - -#ifndef NDEBUG -template<> long CefCppToC::DebugObjCt = 0; -#endif - diff --git a/cef1/libcef_dll/cpptoc/storage_visitor_cpptoc.h b/cef1/libcef_dll/cpptoc/storage_visitor_cpptoc.h deleted file mode 100644 index af8569853..000000000 --- a/cef1/libcef_dll/cpptoc/storage_visitor_cpptoc.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2012 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. -// -// --------------------------------------------------------------------------- -// -// This file was generated by the CEF translator tool. If making changes by -// hand only do so within the body of existing method and function -// implementations. See the translator.README.txt file in the tools directory -// for more information. -// - -#ifndef CEF_LIBCEF_DLL_CPPTOC_STORAGE_VISITOR_CPPTOC_H_ -#define CEF_LIBCEF_DLL_CPPTOC_STORAGE_VISITOR_CPPTOC_H_ -#pragma once - -#ifndef USING_CEF_SHARED -#pragma message("Warning: "__FILE__" may be accessed wrapper-side only") -#else // USING_CEF_SHARED - -#include "include/cef_storage.h" -#include "include/capi/cef_storage_capi.h" -#include "libcef_dll/cpptoc/cpptoc.h" - -// Wrap a C++ class with a C structure. -// This class may be instantiated and accessed wrapper-side only. -class CefStorageVisitorCppToC - : public CefCppToC { - public: - explicit CefStorageVisitorCppToC(CefStorageVisitor* cls); - virtual ~CefStorageVisitorCppToC() {} -}; - -#endif // USING_CEF_SHARED -#endif // CEF_LIBCEF_DLL_CPPTOC_STORAGE_VISITOR_CPPTOC_H_ - diff --git a/cef1/libcef_dll/cpptoc/v8context_cpptoc.cc b/cef1/libcef_dll/cpptoc/v8context_cpptoc.cc index 8643ea7a4..6aa3149ee 100644 --- a/cef1/libcef_dll/cpptoc/v8context_cpptoc.cc +++ b/cef1/libcef_dll/cpptoc/v8context_cpptoc.cc @@ -13,6 +13,7 @@ #include "libcef_dll/cpptoc/browser_cpptoc.h" #include "libcef_dll/cpptoc/frame_cpptoc.h" #include "libcef_dll/cpptoc/v8context_cpptoc.h" +#include "libcef_dll/cpptoc/v8exception_cpptoc.h" #include "libcef_dll/cpptoc/v8value_cpptoc.h" @@ -143,6 +144,69 @@ int CEF_CALLBACK v8context_is_same(struct _cef_v8context_t* self, return _retval; } +int CEF_CALLBACK v8context_eval(struct _cef_v8context_t* self, + const cef_string_t* code, struct _cef_v8value_t** retval, + struct _cef_v8exception_t** exception) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + // Verify param: code; type: string_byref_const + DCHECK(code); + if (!code) + return 0; + // Verify param: retval; type: refptr_same_byref + DCHECK(retval); + if (!retval) + return 0; + // Verify param: exception; type: refptr_same_byref + DCHECK(exception); + if (!exception) + return 0; + + // Translate param: retval; type: refptr_same_byref + CefRefPtr retvalPtr; + if (retval && *retval) + retvalPtr = CefV8ValueCppToC::Unwrap(*retval); + CefV8Value* retvalOrig = retvalPtr.get(); + // Translate param: exception; type: refptr_same_byref + CefRefPtr exceptionPtr; + if (exception && *exception) + exceptionPtr = CefV8ExceptionCppToC::Unwrap(*exception); + CefV8Exception* exceptionOrig = exceptionPtr.get(); + + // Execute + bool _retval = CefV8ContextCppToC::Get(self)->Eval( + CefString(code), + retvalPtr, + exceptionPtr); + + // Restore param: retval; type: refptr_same_byref + if (retval) { + if (retvalPtr.get()) { + if (retvalPtr.get() != retvalOrig) { + *retval = CefV8ValueCppToC::Wrap(retvalPtr); + } + } else { + *retval = NULL; + } + } + // Restore param: exception; type: refptr_same_byref + if (exception) { + if (exceptionPtr.get()) { + if (exceptionPtr.get() != exceptionOrig) { + *exception = CefV8ExceptionCppToC::Wrap(exceptionPtr); + } + } else { + *exception = NULL; + } + } + + // Return type: bool + return _retval; +} + // CONSTRUCTOR - Do not edit by hand. @@ -154,6 +218,7 @@ CefV8ContextCppToC::CefV8ContextCppToC(CefV8Context* cls) struct_.struct_.enter = v8context_enter; struct_.struct_.exit = v8context_exit; struct_.struct_.is_same = v8context_is_same; + struct_.struct_.eval = v8context_eval; } #ifndef NDEBUG diff --git a/cef1/libcef_dll/cpptoc/v8value_cpptoc.cc b/cef1/libcef_dll/cpptoc/v8value_cpptoc.cc index 7d545d514..0ebed8c85 100644 --- a/cef1/libcef_dll/cpptoc/v8value_cpptoc.cc +++ b/cef1/libcef_dll/cpptoc/v8value_cpptoc.cc @@ -52,7 +52,7 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_bool(int value) { return CefV8ValueCppToC::Wrap(_retval); } -CEF_EXPORT cef_v8value_t* cef_v8value_create_int(int value) { +CEF_EXPORT cef_v8value_t* cef_v8value_create_int(int32 value) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // Execute @@ -63,6 +63,17 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_int(int value) { return CefV8ValueCppToC::Wrap(_retval); } +CEF_EXPORT cef_v8value_t* cef_v8value_create_uint(uint32 value) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + CefRefPtr _retval = CefV8Value::CreateUInt( + value); + + // Return type: refptr_same + return CefV8ValueCppToC::Wrap(_retval); +} + CEF_EXPORT cef_v8value_t* cef_v8value_create_double(double value) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -106,26 +117,26 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_string(const cef_string_t* value) { return CefV8ValueCppToC::Wrap(_retval); } -CEF_EXPORT cef_v8value_t* cef_v8value_create_object_with_accessor( - cef_base_t* user_data, cef_v8accessor_t* accessor) { +CEF_EXPORT cef_v8value_t* cef_v8value_create_object( + cef_v8accessor_t* accessor) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - // Unverified params: user_data, accessor + // Unverified params: accessor // Execute CefRefPtr _retval = CefV8Value::CreateObject( - CefBaseCToCpp::Wrap(user_data), CefV8AccessorCToCpp::Wrap(accessor)); // Return type: refptr_same return CefV8ValueCppToC::Wrap(_retval); } -CEF_EXPORT cef_v8value_t* cef_v8value_create_array() { +CEF_EXPORT cef_v8value_t* cef_v8value_create_array(int length) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // Execute - CefRefPtr _retval = CefV8Value::CreateArray(); + CefRefPtr _retval = CefV8Value::CreateArray( + length); // Return type: refptr_same return CefV8ValueCppToC::Wrap(_retval); @@ -212,6 +223,20 @@ int CEF_CALLBACK v8value_is_int(struct _cef_v8value_t* self) { return _retval; } +int CEF_CALLBACK v8value_is_uint(struct _cef_v8value_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + bool _retval = CefV8ValueCppToC::Get(self)->IsUInt(); + + // Return type: bool + return _retval; +} + int CEF_CALLBACK v8value_is_double(struct _cef_v8value_t* self) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -330,7 +355,7 @@ int CEF_CALLBACK v8value_get_bool_value(struct _cef_v8value_t* self) { return _retval; } -int CEF_CALLBACK v8value_get_int_value(struct _cef_v8value_t* self) { +int32 CEF_CALLBACK v8value_get_int_value(struct _cef_v8value_t* self) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); @@ -338,7 +363,21 @@ int CEF_CALLBACK v8value_get_int_value(struct _cef_v8value_t* self) { return 0; // Execute - int _retval = CefV8ValueCppToC::Get(self)->GetIntValue(); + int32 _retval = CefV8ValueCppToC::Get(self)->GetIntValue(); + + // Return type: simple + return _retval; +} + +uint32 CEF_CALLBACK v8value_get_uint_value(struct _cef_v8value_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + uint32 _retval = CefV8ValueCppToC::Get(self)->GetUIntValue(); // Return type: simple return _retval; @@ -387,6 +426,94 @@ cef_string_userfree_t CEF_CALLBACK v8value_get_string_value( return _retval.DetachToUserFree(); } +int CEF_CALLBACK v8value_is_user_created(struct _cef_v8value_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + bool _retval = CefV8ValueCppToC::Get(self)->IsUserCreated(); + + // Return type: bool + return _retval; +} + +int CEF_CALLBACK v8value_has_exception(struct _cef_v8value_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + bool _retval = CefV8ValueCppToC::Get(self)->HasException(); + + // Return type: bool + return _retval; +} + +cef_v8exception_t* CEF_CALLBACK v8value_get_exception( + struct _cef_v8value_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefRefPtr _retval = CefV8ValueCppToC::Get(self)->GetException( + ); + + // Return type: refptr_same + return CefV8ExceptionCppToC::Wrap(_retval); +} + +int CEF_CALLBACK v8value_clear_exception(struct _cef_v8value_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + bool _retval = CefV8ValueCppToC::Get(self)->ClearException(); + + // Return type: bool + return _retval; +} + +int CEF_CALLBACK v8value_will_rethrow_exceptions(struct _cef_v8value_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + bool _retval = CefV8ValueCppToC::Get(self)->WillRethrowExceptions(); + + // Return type: bool + return _retval; +} + +int CEF_CALLBACK v8value_set_rethrow_exceptions(struct _cef_v8value_t* self, + int rethrow) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + bool _retval = CefV8ValueCppToC::Get(self)->SetRethrowExceptions( + rethrow?true:false); + + // Return type: bool + return _retval; +} + int CEF_CALLBACK v8value_has_value_bykey(struct _cef_v8value_t* self, const cef_string_t* key) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -610,6 +737,23 @@ int CEF_CALLBACK v8value_get_keys(struct _cef_v8value_t* self, return _retval; } +int CEF_CALLBACK v8value_set_user_data(struct _cef_v8value_t* self, + cef_base_t* user_data) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + // Unverified params: user_data + + // Execute + bool _retval = CefV8ValueCppToC::Get(self)->SetUserData( + CefBaseCToCpp::Wrap(user_data)); + + // Return type: bool + return _retval; +} + cef_base_t* CEF_CALLBACK v8value_get_user_data(struct _cef_v8value_t* self) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -700,27 +844,18 @@ cef_v8handler_t* CEF_CALLBACK v8value_get_function_handler( return CefV8HandlerCToCpp::Unwrap(_retval); } -int CEF_CALLBACK v8value_execute_function(struct _cef_v8value_t* self, - struct _cef_v8value_t* object, size_t argumentsCount, - struct _cef_v8value_t* const* arguments, struct _cef_v8value_t** retval, - cef_v8exception_t** exception, int rethrow_exception) { +struct _cef_v8value_t* CEF_CALLBACK v8value_execute_function( + struct _cef_v8value_t* self, struct _cef_v8value_t* object, + size_t argumentsCount, struct _cef_v8value_t* const* arguments) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); if (!self) - return 0; + return NULL; // Verify param: arguments; type: refptr_vec_same_byref_const DCHECK(argumentsCount == 0 || arguments); if (argumentsCount > 0 && !arguments) - return 0; - // Verify param: retval; type: refptr_same_byref - DCHECK(retval); - if (!retval) - return 0; - // Verify param: exception; type: refptr_same_byref - DCHECK(exception); - if (!exception) - return 0; + return NULL; // Unverified params: object // Translate param: arguments; type: refptr_vec_same_byref_const @@ -730,76 +865,33 @@ int CEF_CALLBACK v8value_execute_function(struct _cef_v8value_t* self, argumentsList.push_back(CefV8ValueCppToC::Unwrap(arguments[i])); } } - // Translate param: retval; type: refptr_same_byref - CefRefPtr retvalPtr; - if (retval && *retval) - retvalPtr = CefV8ValueCppToC::Unwrap(*retval); - CefV8Value* retvalOrig = retvalPtr.get(); - // Translate param: exception; type: refptr_same_byref - CefRefPtr exceptionPtr; - if (exception && *exception) - exceptionPtr = CefV8ExceptionCppToC::Unwrap(*exception); - CefV8Exception* exceptionOrig = exceptionPtr.get(); // Execute - bool _retval = CefV8ValueCppToC::Get(self)->ExecuteFunction( + CefRefPtr _retval = CefV8ValueCppToC::Get(self)->ExecuteFunction( CefV8ValueCppToC::Unwrap(object), - argumentsList, - retvalPtr, - exceptionPtr, - rethrow_exception?true:false); + argumentsList); - // Restore param: retval; type: refptr_same_byref - if (retval) { - if (retvalPtr.get()) { - if (retvalPtr.get() != retvalOrig) { - *retval = CefV8ValueCppToC::Wrap(retvalPtr); - } - } else { - *retval = NULL; - } - } - // Restore param: exception; type: refptr_same_byref - if (exception) { - if (exceptionPtr.get()) { - if (exceptionPtr.get() != exceptionOrig) { - *exception = CefV8ExceptionCppToC::Wrap(exceptionPtr); - } - } else { - *exception = NULL; - } - } - - // Return type: bool - return _retval; + // Return type: refptr_same + return CefV8ValueCppToC::Wrap(_retval); } -int CEF_CALLBACK v8value_execute_function_with_context( +struct _cef_v8value_t* CEF_CALLBACK v8value_execute_function_with_context( struct _cef_v8value_t* self, cef_v8context_t* context, struct _cef_v8value_t* object, size_t argumentsCount, - struct _cef_v8value_t* const* arguments, struct _cef_v8value_t** retval, - cef_v8exception_t** exception, int rethrow_exception) { + struct _cef_v8value_t* const* arguments) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); if (!self) - return 0; + return NULL; // Verify param: context; type: refptr_same DCHECK(context); if (!context) - return 0; + return NULL; // Verify param: arguments; type: refptr_vec_same_byref_const DCHECK(argumentsCount == 0 || arguments); if (argumentsCount > 0 && !arguments) - return 0; - // Verify param: retval; type: refptr_same_byref - DCHECK(retval); - if (!retval) - return 0; - // Verify param: exception; type: refptr_same_byref - DCHECK(exception); - if (!exception) - return 0; + return NULL; // Unverified params: object // Translate param: arguments; type: refptr_vec_same_byref_const @@ -809,49 +901,16 @@ int CEF_CALLBACK v8value_execute_function_with_context( argumentsList.push_back(CefV8ValueCppToC::Unwrap(arguments[i])); } } - // Translate param: retval; type: refptr_same_byref - CefRefPtr retvalPtr; - if (retval && *retval) - retvalPtr = CefV8ValueCppToC::Unwrap(*retval); - CefV8Value* retvalOrig = retvalPtr.get(); - // Translate param: exception; type: refptr_same_byref - CefRefPtr exceptionPtr; - if (exception && *exception) - exceptionPtr = CefV8ExceptionCppToC::Unwrap(*exception); - CefV8Exception* exceptionOrig = exceptionPtr.get(); // Execute - bool _retval = CefV8ValueCppToC::Get(self)->ExecuteFunctionWithContext( + CefRefPtr _retval = CefV8ValueCppToC::Get( + self)->ExecuteFunctionWithContext( CefV8ContextCppToC::Unwrap(context), CefV8ValueCppToC::Unwrap(object), - argumentsList, - retvalPtr, - exceptionPtr, - rethrow_exception?true:false); + argumentsList); - // Restore param: retval; type: refptr_same_byref - if (retval) { - if (retvalPtr.get()) { - if (retvalPtr.get() != retvalOrig) { - *retval = CefV8ValueCppToC::Wrap(retvalPtr); - } - } else { - *retval = NULL; - } - } - // Restore param: exception; type: refptr_same_byref - if (exception) { - if (exceptionPtr.get()) { - if (exceptionPtr.get() != exceptionOrig) { - *exception = CefV8ExceptionCppToC::Wrap(exceptionPtr); - } - } else { - *exception = NULL; - } - } - - // Return type: bool - return _retval; + // Return type: refptr_same + return CefV8ValueCppToC::Wrap(_retval); } @@ -863,6 +922,7 @@ CefV8ValueCppToC::CefV8ValueCppToC(CefV8Value* cls) struct_.struct_.is_null = v8value_is_null; struct_.struct_.is_bool = v8value_is_bool; struct_.struct_.is_int = v8value_is_int; + struct_.struct_.is_uint = v8value_is_uint; struct_.struct_.is_double = v8value_is_double; struct_.struct_.is_date = v8value_is_date; struct_.struct_.is_string = v8value_is_string; @@ -872,9 +932,16 @@ CefV8ValueCppToC::CefV8ValueCppToC(CefV8Value* cls) struct_.struct_.is_same = v8value_is_same; struct_.struct_.get_bool_value = v8value_get_bool_value; struct_.struct_.get_int_value = v8value_get_int_value; + struct_.struct_.get_uint_value = v8value_get_uint_value; struct_.struct_.get_double_value = v8value_get_double_value; struct_.struct_.get_date_value = v8value_get_date_value; struct_.struct_.get_string_value = v8value_get_string_value; + struct_.struct_.is_user_created = v8value_is_user_created; + struct_.struct_.has_exception = v8value_has_exception; + struct_.struct_.get_exception = v8value_get_exception; + struct_.struct_.clear_exception = v8value_clear_exception; + struct_.struct_.will_rethrow_exceptions = v8value_will_rethrow_exceptions; + struct_.struct_.set_rethrow_exceptions = v8value_set_rethrow_exceptions; 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; @@ -885,6 +952,7 @@ CefV8ValueCppToC::CefV8ValueCppToC(CefV8Value* cls) struct_.struct_.set_value_byindex = v8value_set_value_byindex; struct_.struct_.set_value_byaccessor = v8value_set_value_byaccessor; struct_.struct_.get_keys = v8value_get_keys; + struct_.struct_.set_user_data = v8value_set_user_data; struct_.struct_.get_user_data = v8value_get_user_data; struct_.struct_.get_externally_allocated_memory = v8value_get_externally_allocated_memory; diff --git a/cef1/libcef_dll/ctocpp/storage_visitor_ctocpp.cc b/cef1/libcef_dll/ctocpp/storage_visitor_ctocpp.cc deleted file mode 100644 index 414f5b82f..000000000 --- a/cef1/libcef_dll/ctocpp/storage_visitor_ctocpp.cc +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2012 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. -// -// --------------------------------------------------------------------------- -// -// This file was generated by the CEF translator tool. If making changes by -// hand only do so within the body of existing method and function -// implementations. See the translator.README.txt file in the tools directory -// for more information. -// - -#include "libcef_dll/ctocpp/storage_visitor_ctocpp.h" - - -// VIRTUAL METHODS - Body may be edited by hand. - -bool CefStorageVisitorCToCpp::Visit(CefStorageType type, - const CefString& origin, const CefString& key, const CefString& value, - int count, int total, bool& deleteData) { - if (CEF_MEMBER_MISSING(struct_, visit)) - return false; - - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Verify param: origin; type: string_byref_const - DCHECK(!origin.empty()); - if (origin.empty()) - return false; - // Verify param: key; type: string_byref_const - DCHECK(!key.empty()); - if (key.empty()) - return false; - // Verify param: value; type: string_byref_const - DCHECK(!value.empty()); - if (value.empty()) - return false; - - // Translate param: deleteData; type: bool_byref - int deleteDataInt = deleteData; - - // Execute - int _retval = struct_->visit(struct_, - type, - origin.GetStruct(), - key.GetStruct(), - value.GetStruct(), - count, - total, - &deleteDataInt); - - // Restore param:deleteData; type: bool_byref - deleteData = deleteDataInt?true:false; - - // Return type: bool - return _retval?true:false; -} - - -#ifndef NDEBUG -template<> long CefCToCpp::DebugObjCt = 0; -#endif - diff --git a/cef1/libcef_dll/ctocpp/storage_visitor_ctocpp.h b/cef1/libcef_dll/ctocpp/storage_visitor_ctocpp.h deleted file mode 100644 index 5ce43d827..000000000 --- a/cef1/libcef_dll/ctocpp/storage_visitor_ctocpp.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2012 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. -// -// --------------------------------------------------------------------------- -// -// This file was generated by the CEF translator tool. If making changes by -// hand only do so within the body of existing method and function -// implementations. See the translator.README.txt file in the tools directory -// for more information. -// - -#ifndef CEF_LIBCEF_DLL_CTOCPP_STORAGE_VISITOR_CTOCPP_H_ -#define CEF_LIBCEF_DLL_CTOCPP_STORAGE_VISITOR_CTOCPP_H_ -#pragma once - -#ifndef BUILDING_CEF_SHARED -#pragma message("Warning: "__FILE__" may be accessed DLL-side only") -#else // BUILDING_CEF_SHARED - -#include "include/cef_storage.h" -#include "include/capi/cef_storage_capi.h" -#include "libcef_dll/ctocpp/ctocpp.h" - -// Wrap a C structure with a C++ class. -// This class may be instantiated and accessed DLL-side only. -class CefStorageVisitorCToCpp - : public CefCToCpp { - public: - explicit CefStorageVisitorCToCpp(cef_storage_visitor_t* str) - : CefCToCpp(str) {} - virtual ~CefStorageVisitorCToCpp() {} - - // CefStorageVisitor methods - virtual bool Visit(CefStorageType type, const CefString& origin, - const CefString& key, const CefString& value, int count, int total, - bool& deleteData) OVERRIDE; -}; - -#endif // BUILDING_CEF_SHARED -#endif // CEF_LIBCEF_DLL_CTOCPP_STORAGE_VISITOR_CTOCPP_H_ - diff --git a/cef1/libcef_dll/ctocpp/v8context_ctocpp.cc b/cef1/libcef_dll/ctocpp/v8context_ctocpp.cc index ec2eca20b..bc1e0559b 100644 --- a/cef1/libcef_dll/ctocpp/v8context_ctocpp.cc +++ b/cef1/libcef_dll/ctocpp/v8context_ctocpp.cc @@ -13,6 +13,7 @@ #include "libcef_dll/ctocpp/browser_ctocpp.h" #include "libcef_dll/ctocpp/frame_ctocpp.h" #include "libcef_dll/ctocpp/v8context_ctocpp.h" +#include "libcef_dll/ctocpp/v8exception_ctocpp.h" #include "libcef_dll/ctocpp/v8value_ctocpp.h" @@ -135,6 +136,56 @@ bool CefV8ContextCToCpp::IsSame(CefRefPtr that) { return _retval?true:false; } +bool CefV8ContextCToCpp::Eval(const CefString& code, + CefRefPtr& retval, CefRefPtr& exception) { + if (CEF_MEMBER_MISSING(struct_, eval)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: code; type: string_byref_const + DCHECK(!code.empty()); + if (code.empty()) + return false; + + // Translate param: retval; type: refptr_same_byref + cef_v8value_t* retvalStruct = NULL; + if (retval.get()) + retvalStruct = CefV8ValueCToCpp::Unwrap(retval); + cef_v8value_t* retvalOrig = retvalStruct; + // Translate param: exception; type: refptr_same_byref + cef_v8exception_t* exceptionStruct = NULL; + if (exception.get()) + exceptionStruct = CefV8ExceptionCToCpp::Unwrap(exception); + cef_v8exception_t* exceptionOrig = exceptionStruct; + + // Execute + int _retval = struct_->eval(struct_, + code.GetStruct(), + &retvalStruct, + &exceptionStruct); + + // Restore param:retval; type: refptr_same_byref + if (retvalStruct) { + if (retvalStruct != retvalOrig) { + retval = CefV8ValueCToCpp::Wrap(retvalStruct); + } + } else { + retval = NULL; + } + // Restore param:exception; type: refptr_same_byref + if (exceptionStruct) { + if (exceptionStruct != exceptionOrig) { + exception = CefV8ExceptionCToCpp::Wrap(exceptionStruct); + } + } else { + exception = NULL; + } + + // Return type: bool + return _retval?true:false; +} + #ifndef NDEBUG template<> long CefCToCpp that) OVERRIDE; + virtual bool Eval(const CefString& code, CefRefPtr& retval, + CefRefPtr& exception) OVERRIDE; }; #endif // USING_CEF_SHARED diff --git a/cef1/libcef_dll/ctocpp/v8value_ctocpp.cc b/cef1/libcef_dll/ctocpp/v8value_ctocpp.cc index a1ea37c4a..39076c824 100644 --- a/cef1/libcef_dll/ctocpp/v8value_ctocpp.cc +++ b/cef1/libcef_dll/ctocpp/v8value_ctocpp.cc @@ -52,7 +52,7 @@ CefRefPtr CefV8Value::CreateBool(bool value) { return CefV8ValueCToCpp::Wrap(_retval); } -CefRefPtr CefV8Value::CreateInt(int value) { +CefRefPtr CefV8Value::CreateInt(int32 value) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // Execute @@ -63,6 +63,17 @@ CefRefPtr CefV8Value::CreateInt(int value) { return CefV8ValueCToCpp::Wrap(_retval); } +CefRefPtr CefV8Value::CreateUInt(uint32 value) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_v8value_t* _retval = cef_v8value_create_uint( + value); + + // Return type: refptr_same + return CefV8ValueCToCpp::Wrap(_retval); +} + CefRefPtr CefV8Value::CreateDouble(double value) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -98,26 +109,26 @@ CefRefPtr CefV8Value::CreateString(const CefString& value) { return CefV8ValueCToCpp::Wrap(_retval); } -CefRefPtr CefV8Value::CreateObject(CefRefPtr user_data, +CefRefPtr CefV8Value::CreateObject( CefRefPtr accessor) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - // Unverified params: user_data, accessor + // Unverified params: accessor // Execute - cef_v8value_t* _retval = cef_v8value_create_object_with_accessor( - CefBaseCppToC::Wrap(user_data), + cef_v8value_t* _retval = cef_v8value_create_object( CefV8AccessorCppToC::Wrap(accessor)); // Return type: refptr_same return CefV8ValueCToCpp::Wrap(_retval); } -CefRefPtr CefV8Value::CreateArray() { +CefRefPtr CefV8Value::CreateArray(int length) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // Execute - cef_v8value_t* _retval = cef_v8value_create_array(); + cef_v8value_t* _retval = cef_v8value_create_array( + length); // Return type: refptr_same return CefV8ValueCToCpp::Wrap(_retval); @@ -200,6 +211,19 @@ bool CefV8ValueCToCpp::IsInt() { return _retval?true:false; } +bool CefV8ValueCToCpp::IsUInt() { + if (CEF_MEMBER_MISSING(struct_, is_uint)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = struct_->is_uint(struct_); + + // Return type: bool + return _retval?true:false; +} + bool CefV8ValueCToCpp::IsDouble() { if (CEF_MEMBER_MISSING(struct_, is_double)) return false; @@ -310,14 +334,27 @@ bool CefV8ValueCToCpp::GetBoolValue() { return _retval?true:false; } -int CefV8ValueCToCpp::GetIntValue() { +int32 CefV8ValueCToCpp::GetIntValue() { if (CEF_MEMBER_MISSING(struct_, get_int_value)) return 0; // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // Execute - int _retval = struct_->get_int_value(struct_); + int32 _retval = struct_->get_int_value(struct_); + + // Return type: simple + return _retval; +} + +uint32 CefV8ValueCToCpp::GetUIntValue() { + if (CEF_MEMBER_MISSING(struct_, get_uint_value)) + return 0; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + uint32 _retval = struct_->get_uint_value(struct_); // Return type: simple return _retval; @@ -364,6 +401,85 @@ CefString CefV8ValueCToCpp::GetStringValue() { return _retvalStr; } +bool CefV8ValueCToCpp::IsUserCreated() { + if (CEF_MEMBER_MISSING(struct_, is_user_created)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = struct_->is_user_created(struct_); + + // Return type: bool + return _retval?true:false; +} + +bool CefV8ValueCToCpp::HasException() { + if (CEF_MEMBER_MISSING(struct_, has_exception)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = struct_->has_exception(struct_); + + // Return type: bool + return _retval?true:false; +} + +CefRefPtr CefV8ValueCToCpp::GetException() { + if (CEF_MEMBER_MISSING(struct_, get_exception)) + return NULL; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_v8exception_t* _retval = struct_->get_exception(struct_); + + // Return type: refptr_same + return CefV8ExceptionCToCpp::Wrap(_retval); +} + +bool CefV8ValueCToCpp::ClearException() { + if (CEF_MEMBER_MISSING(struct_, clear_exception)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = struct_->clear_exception(struct_); + + // Return type: bool + return _retval?true:false; +} + +bool CefV8ValueCToCpp::WillRethrowExceptions() { + if (CEF_MEMBER_MISSING(struct_, will_rethrow_exceptions)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = struct_->will_rethrow_exceptions(struct_); + + // Return type: bool + return _retval?true:false; +} + +bool CefV8ValueCToCpp::SetRethrowExceptions(bool rethrow) { + if (CEF_MEMBER_MISSING(struct_, set_rethrow_exceptions)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = struct_->set_rethrow_exceptions(struct_, + rethrow); + + // Return type: bool + return _retval?true:false; +} + bool CefV8ValueCToCpp::HasValue(const CefString& key) { if (CEF_MEMBER_MISSING(struct_, has_value_bykey)) return false; @@ -577,6 +693,22 @@ bool CefV8ValueCToCpp::GetKeys(std::vector& keys) { return _retval?true:false; } +bool CefV8ValueCToCpp::SetUserData(CefRefPtr user_data) { + if (CEF_MEMBER_MISSING(struct_, set_user_data)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Unverified params: user_data + + // Execute + int _retval = struct_->set_user_data(struct_, + CefBaseCppToC::Wrap(user_data)); + + // Return type: bool + return _retval?true:false; +} + CefRefPtr CefV8ValueCToCpp::GetUserData() { if (CEF_MEMBER_MISSING(struct_, get_user_data)) return NULL; @@ -658,11 +790,10 @@ CefRefPtr CefV8ValueCToCpp::GetFunctionHandler() { return CefV8HandlerCppToC::Unwrap(_retval); } -bool CefV8ValueCToCpp::ExecuteFunction(CefRefPtr object, - const CefV8ValueList& arguments, CefRefPtr& retval, - CefRefPtr& exception, bool rethrow_exception) { +CefRefPtr CefV8ValueCToCpp::ExecuteFunction( + CefRefPtr object, const CefV8ValueList& arguments) { if (CEF_MEMBER_MISSING(struct_, execute_function)) - return false; + return NULL; // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -680,63 +811,33 @@ bool CefV8ValueCToCpp::ExecuteFunction(CefRefPtr object, } } } - // Translate param: retval; type: refptr_same_byref - cef_v8value_t* retvalStruct = NULL; - if (retval.get()) - retvalStruct = CefV8ValueCToCpp::Unwrap(retval); - cef_v8value_t* retvalOrig = retvalStruct; - // Translate param: exception; type: refptr_same_byref - cef_v8exception_t* exceptionStruct = NULL; - if (exception.get()) - exceptionStruct = CefV8ExceptionCToCpp::Unwrap(exception); - cef_v8exception_t* exceptionOrig = exceptionStruct; // Execute - int _retval = struct_->execute_function(struct_, + cef_v8value_t* _retval = struct_->execute_function(struct_, CefV8ValueCToCpp::Unwrap(object), argumentsCount, - argumentsList, - &retvalStruct, - &exceptionStruct, - rethrow_exception); + argumentsList); // Restore param:arguments; type: refptr_vec_same_byref_const if (argumentsList) delete [] argumentsList; - // Restore param:retval; type: refptr_same_byref - if (retvalStruct) { - if (retvalStruct != retvalOrig) { - retval = CefV8ValueCToCpp::Wrap(retvalStruct); - } - } else { - retval = NULL; - } - // Restore param:exception; type: refptr_same_byref - if (exceptionStruct) { - if (exceptionStruct != exceptionOrig) { - exception = CefV8ExceptionCToCpp::Wrap(exceptionStruct); - } - } else { - exception = NULL; - } - // Return type: bool - return _retval?true:false; + // Return type: refptr_same + return CefV8ValueCToCpp::Wrap(_retval); } -bool CefV8ValueCToCpp::ExecuteFunctionWithContext( +CefRefPtr CefV8ValueCToCpp::ExecuteFunctionWithContext( CefRefPtr context, CefRefPtr object, - const CefV8ValueList& arguments, CefRefPtr& retval, - CefRefPtr& exception, bool rethrow_exception) { + const CefV8ValueList& arguments) { if (CEF_MEMBER_MISSING(struct_, execute_function_with_context)) - return false; + return NULL; // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // Verify param: context; type: refptr_same DCHECK(context.get()); if (!context.get()) - return false; + return NULL; // Unverified params: object // Translate param: arguments; type: refptr_vec_same_byref_const @@ -751,49 +852,20 @@ bool CefV8ValueCToCpp::ExecuteFunctionWithContext( } } } - // Translate param: retval; type: refptr_same_byref - cef_v8value_t* retvalStruct = NULL; - if (retval.get()) - retvalStruct = CefV8ValueCToCpp::Unwrap(retval); - cef_v8value_t* retvalOrig = retvalStruct; - // Translate param: exception; type: refptr_same_byref - cef_v8exception_t* exceptionStruct = NULL; - if (exception.get()) - exceptionStruct = CefV8ExceptionCToCpp::Unwrap(exception); - cef_v8exception_t* exceptionOrig = exceptionStruct; // Execute - int _retval = struct_->execute_function_with_context(struct_, + cef_v8value_t* _retval = struct_->execute_function_with_context(struct_, CefV8ContextCToCpp::Unwrap(context), CefV8ValueCToCpp::Unwrap(object), argumentsCount, - argumentsList, - &retvalStruct, - &exceptionStruct, - rethrow_exception); + argumentsList); // Restore param:arguments; type: refptr_vec_same_byref_const if (argumentsList) delete [] argumentsList; - // Restore param:retval; type: refptr_same_byref - if (retvalStruct) { - if (retvalStruct != retvalOrig) { - retval = CefV8ValueCToCpp::Wrap(retvalStruct); - } - } else { - retval = NULL; - } - // Restore param:exception; type: refptr_same_byref - if (exceptionStruct) { - if (exceptionStruct != exceptionOrig) { - exception = CefV8ExceptionCToCpp::Wrap(exceptionStruct); - } - } else { - exception = NULL; - } - // Return type: bool - return _retval?true:false; + // Return type: refptr_same + return CefV8ValueCToCpp::Wrap(_retval); } diff --git a/cef1/libcef_dll/ctocpp/v8value_ctocpp.h b/cef1/libcef_dll/ctocpp/v8value_ctocpp.h index 80766b72a..15efb7941 100644 --- a/cef1/libcef_dll/ctocpp/v8value_ctocpp.h +++ b/cef1/libcef_dll/ctocpp/v8value_ctocpp.h @@ -37,6 +37,7 @@ class CefV8ValueCToCpp virtual bool IsNull() OVERRIDE; virtual bool IsBool() OVERRIDE; virtual bool IsInt() OVERRIDE; + virtual bool IsUInt() OVERRIDE; virtual bool IsDouble() OVERRIDE; virtual bool IsDate() OVERRIDE; virtual bool IsString() OVERRIDE; @@ -45,10 +46,17 @@ class CefV8ValueCToCpp virtual bool IsFunction() OVERRIDE; virtual bool IsSame(CefRefPtr that) OVERRIDE; virtual bool GetBoolValue() OVERRIDE; - virtual int GetIntValue() OVERRIDE; + virtual int32 GetIntValue() OVERRIDE; + virtual uint32 GetUIntValue() OVERRIDE; virtual double GetDoubleValue() OVERRIDE; virtual CefTime GetDateValue() OVERRIDE; virtual CefString GetStringValue() OVERRIDE; + virtual bool IsUserCreated() OVERRIDE; + virtual bool HasException() OVERRIDE; + virtual CefRefPtr GetException() OVERRIDE; + virtual bool ClearException() OVERRIDE; + virtual bool WillRethrowExceptions() OVERRIDE; + virtual bool SetRethrowExceptions(bool rethrow) OVERRIDE; virtual bool HasValue(const CefString& key) OVERRIDE; virtual bool HasValue(int index) OVERRIDE; virtual bool DeleteValue(const CefString& key) OVERRIDE; @@ -61,19 +69,18 @@ class CefV8ValueCToCpp virtual bool SetValue(const CefString& key, AccessControl settings, PropertyAttribute attribute) OVERRIDE; virtual bool GetKeys(std::vector& keys) OVERRIDE; + virtual bool SetUserData(CefRefPtr user_data) OVERRIDE; virtual CefRefPtr GetUserData() OVERRIDE; virtual int GetExternallyAllocatedMemory() OVERRIDE; virtual int AdjustExternallyAllocatedMemory(int change_in_bytes) OVERRIDE; virtual int GetArrayLength() OVERRIDE; virtual CefString GetFunctionName() OVERRIDE; virtual CefRefPtr GetFunctionHandler() OVERRIDE; - virtual bool ExecuteFunction(CefRefPtr object, - const CefV8ValueList& arguments, CefRefPtr& retval, - CefRefPtr& exception, bool rethrow_exception) OVERRIDE; - virtual bool ExecuteFunctionWithContext(CefRefPtr context, - CefRefPtr object, const CefV8ValueList& arguments, - CefRefPtr& retval, CefRefPtr& exception, - bool rethrow_exception) OVERRIDE; + virtual CefRefPtr ExecuteFunction(CefRefPtr object, + const CefV8ValueList& arguments) OVERRIDE; + virtual CefRefPtr ExecuteFunctionWithContext( + CefRefPtr context, CefRefPtr object, + const CefV8ValueList& arguments) OVERRIDE; }; #endif // USING_CEF_SHARED diff --git a/cef1/libcef_dll/libcef_dll.cc b/cef1/libcef_dll/libcef_dll.cc index 0089d5c64..a0a883fc6 100644 --- a/cef1/libcef_dll/libcef_dll.cc +++ b/cef1/libcef_dll/libcef_dll.cc @@ -16,8 +16,6 @@ #include "include/capi/cef_origin_whitelist_capi.h" #include "include/cef_scheme.h" #include "include/capi/cef_scheme_capi.h" -#include "include/cef_storage.h" -#include "include/capi/cef_storage_capi.h" #include "include/cef_task.h" #include "include/capi/cef_task_capi.h" #include "include/cef_url.h" @@ -71,7 +69,6 @@ #include "libcef_dll/ctocpp/resource_bundle_handler_ctocpp.h" #include "libcef_dll/ctocpp/scheme_handler_ctocpp.h" #include "libcef_dll/ctocpp/scheme_handler_factory_ctocpp.h" -#include "libcef_dll/ctocpp/storage_visitor_ctocpp.h" #include "libcef_dll/ctocpp/task_ctocpp.h" #include "libcef_dll/ctocpp/v8accessor_ctocpp.h" #include "libcef_dll/ctocpp/v8context_handler_ctocpp.h" @@ -149,7 +146,6 @@ CEF_EXPORT void cef_shutdown() { DCHECK_EQ(CefSchemeHandlerCToCpp::DebugObjCt, 0); DCHECK_EQ(CefSchemeHandlerCallbackCppToC::DebugObjCt, 0); DCHECK_EQ(CefSchemeHandlerFactoryCToCpp::DebugObjCt, 0); - DCHECK_EQ(CefStorageVisitorCToCpp::DebugObjCt, 0); DCHECK_EQ(CefStreamReaderCppToC::DebugObjCt, 0); DCHECK_EQ(CefStreamWriterCppToC::DebugObjCt, 0); DCHECK_EQ(CefTaskCToCpp::DebugObjCt, 0); @@ -308,88 +304,6 @@ CEF_EXPORT int cef_clear_scheme_handler_factories() { return _retval; } -CEF_EXPORT int cef_visit_storage(enum cef_storage_type_t type, - const cef_string_t* origin, const cef_string_t* key, - struct _cef_storage_visitor_t* visitor) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Verify param: visitor; type: refptr_diff - DCHECK(visitor); - if (!visitor) - return 0; - // Unverified params: origin, key - - // Execute - bool _retval = CefVisitStorage( - type, - CefString(origin), - CefString(key), - CefStorageVisitorCToCpp::Wrap(visitor)); - - // Return type: bool - return _retval; -} - -CEF_EXPORT int cef_set_storage(enum cef_storage_type_t type, - const cef_string_t* origin, const cef_string_t* key, - const cef_string_t* value) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Verify param: origin; type: string_byref_const - DCHECK(origin); - if (!origin) - return 0; - // Verify param: key; type: string_byref_const - DCHECK(key); - if (!key) - return 0; - // Verify param: value; type: string_byref_const - DCHECK(value); - if (!value) - return 0; - - // Execute - bool _retval = CefSetStorage( - type, - CefString(origin), - CefString(key), - CefString(value)); - - // Return type: bool - return _retval; -} - -CEF_EXPORT int cef_delete_storage(enum cef_storage_type_t type, - const cef_string_t* origin, const cef_string_t* key) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Unverified params: origin, key - - // Execute - bool _retval = CefDeleteStorage( - type, - CefString(origin), - CefString(key)); - - // Return type: bool - return _retval; -} - -CEF_EXPORT int cef_set_storage_path(enum cef_storage_type_t type, - const cef_string_t* path) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Unverified params: path - - // Execute - bool _retval = CefSetStoragePath( - type, - CefString(path)); - - // Return type: bool - return _retval; -} - CEF_EXPORT int cef_currently_on(cef_thread_id_t threadId) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING diff --git a/cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc b/cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc index 2b6d63da5..81e11ba55 100644 --- a/cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc +++ b/cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc @@ -16,8 +16,6 @@ #include "include/capi/cef_origin_whitelist_capi.h" #include "include/cef_scheme.h" #include "include/capi/cef_scheme_capi.h" -#include "include/cef_storage.h" -#include "include/capi/cef_storage_capi.h" #include "include/cef_task.h" #include "include/capi/cef_task_capi.h" #include "include/cef_url.h" @@ -51,7 +49,6 @@ #include "libcef_dll/cpptoc/resource_bundle_handler_cpptoc.h" #include "libcef_dll/cpptoc/scheme_handler_cpptoc.h" #include "libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h" -#include "libcef_dll/cpptoc/storage_visitor_cpptoc.h" #include "libcef_dll/cpptoc/task_cpptoc.h" #include "libcef_dll/cpptoc/v8accessor_cpptoc.h" #include "libcef_dll/cpptoc/v8context_handler_cpptoc.h" @@ -151,7 +148,6 @@ CEF_GLOBAL void CefShutdown() { DCHECK_EQ(CefSchemeHandlerCallbackCToCpp::DebugObjCt, 0); DCHECK_EQ(CefSchemeHandlerCppToC::DebugObjCt, 0); DCHECK_EQ(CefSchemeHandlerFactoryCppToC::DebugObjCt, 0); - DCHECK_EQ(CefStorageVisitorCppToC::DebugObjCt, 0); DCHECK_EQ(CefStreamReaderCToCpp::DebugObjCt, 0); DCHECK_EQ(CefStreamWriterCToCpp::DebugObjCt, 0); DCHECK_EQ(CefTaskCppToC::DebugObjCt, 0); @@ -310,85 +306,6 @@ CEF_GLOBAL bool CefClearSchemeHandlerFactories() { return _retval?true:false; } -CEF_GLOBAL bool CefVisitStorage(CefStorageType type, const CefString& origin, - const CefString& key, CefRefPtr visitor) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Verify param: visitor; type: refptr_diff - DCHECK(visitor.get()); - if (!visitor.get()) - return false; - // Unverified params: origin, key - - // Execute - int _retval = cef_visit_storage( - type, - origin.GetStruct(), - key.GetStruct(), - CefStorageVisitorCppToC::Wrap(visitor)); - - // Return type: bool - return _retval?true:false; -} - -CEF_GLOBAL bool CefSetStorage(CefStorageType type, const CefString& origin, - const CefString& key, const CefString& value) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Verify param: origin; type: string_byref_const - DCHECK(!origin.empty()); - if (origin.empty()) - return false; - // Verify param: key; type: string_byref_const - DCHECK(!key.empty()); - if (key.empty()) - return false; - // Verify param: value; type: string_byref_const - DCHECK(!value.empty()); - if (value.empty()) - return false; - - // Execute - int _retval = cef_set_storage( - type, - origin.GetStruct(), - key.GetStruct(), - value.GetStruct()); - - // Return type: bool - return _retval?true:false; -} - -CEF_GLOBAL bool CefDeleteStorage(CefStorageType type, const CefString& origin, - const CefString& key) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Unverified params: origin, key - - // Execute - int _retval = cef_delete_storage( - type, - origin.GetStruct(), - key.GetStruct()); - - // Return type: bool - return _retval?true:false; -} - -CEF_GLOBAL bool CefSetStoragePath(CefStorageType type, const CefString& path) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Unverified params: path - - // Execute - int _retval = cef_set_storage_path( - type, - path.GetStruct()); - - // Return type: bool - return _retval?true:false; -} - CEF_GLOBAL bool CefCurrentlyOn(CefThreadId threadId) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING diff --git a/cef1/patch/patch.cfg b/cef1/patch/patch.cfg index 0a1e6a961..f4122f7ec 100644 --- a/cef1/patch/patch.cfg +++ b/cef1/patch/patch.cfg @@ -18,7 +18,6 @@ patches = [ }, { # http://code.google.com/p/gyp/issues/detail?id=223 - # http://codereview.chromium.org/10383117/ 'name': 'tools_gyp', 'path': '../tools/gyp/', }, diff --git a/cef1/patch/patches/base.patch b/cef1/patch/patches/base.patch index 5140c57a9..50c749f8b 100644 --- a/cef1/patch/patches/base.patch +++ b/cef1/patch/patches/base.patch @@ -1,8 +1,8 @@ Index: message_loop.cc =================================================================== ---- message_loop.cc (revision 131752) +--- message_loop.cc (revision 138235) +++ message_loop.cc (working copy) -@@ -362,9 +362,13 @@ +@@ -367,9 +367,13 @@ } void MessageLoop::AssertIdle() const { @@ -19,9 +19,9 @@ Index: message_loop.cc bool MessageLoop::is_running() const { Index: message_loop.h =================================================================== ---- message_loop.h (revision 131752) +--- message_loop.h (revision 138235) +++ message_loop.h (working copy) -@@ -346,6 +346,9 @@ +@@ -347,6 +347,9 @@ // Asserts that the MessageLoop is "idle". void AssertIdle() const; diff --git a/cef1/patch/patches/tools_gyp.patch b/cef1/patch/patches/tools_gyp.patch index ba7b91051..a56189f33 100644 --- a/cef1/patch/patches/tools_gyp.patch +++ b/cef1/patch/patches/tools_gyp.patch @@ -1,8 +1,8 @@ Index: pylib/gyp/input.py =================================================================== ---- pylib/gyp/input.py (revision 1323) +--- pylib/gyp/input.py (revision 1386) +++ pylib/gyp/input.py (working copy) -@@ -666,7 +666,8 @@ +@@ -683,7 +683,8 @@ # that don't load quickly, this can be faster than # objectPtr; - CefRefPtr exceptionPtr; - result = arguments[0]->ExecuteFunction(object, argList, objectPtr, - exceptionPtr, false); - if (exceptionPtr.get()) - exception = exceptionPtr->GetMessage(); - if (!result) - return false; + CefRefPtr objectPtr = + arguments[0]->ExecuteFunction(object, argList); + if (arguments[0]->HasException()) + exception = arguments[0]->GetException()->GetMessage(); // Verify that the returned value is an object. if (!objectPtr.get() || !objectPtr->IsObject()) @@ -80,11 +75,10 @@ class ClientV8FunctionHandler : public CefV8Handler { argList.push_back(arguments[i]); // Execute the member function. - result = funcPtr->ExecuteFunction(arguments[0], argList, retval, - exceptionPtr, false); - if (exceptionPtr.get()) - exception = exceptionPtr->GetMessage(); - return result; + funcPtr->ExecuteFunction(arguments[0], argList); + if (funcPtr->HasException()) + exception = funcPtr->GetException()->GetMessage(); + return true; } return false; } @@ -140,7 +134,7 @@ void InitBindingTest(CefRefPtr browser, CefRefPtr frame, CefRefPtr object) { // Create the new V8 object. - CefRefPtr testObjPtr = CefV8Value::CreateObject(NULL, NULL); + CefRefPtr testObjPtr = CefV8Value::CreateObject(NULL); // Add the new V8 object to the global window object with the name // "cef_test". object->SetValue("cef_test", testObjPtr, V8_PROPERTY_ATTRIBUTE_NONE); diff --git a/cef1/tests/cefclient/cefclient.cpp b/cef1/tests/cefclient/cefclient.cpp index 617852228..d00d72b75 100644 --- a/cef1/tests/cefclient/cefclient.cpp +++ b/cef1/tests/cefclient/cefclient.cpp @@ -40,10 +40,9 @@ void UIT_InvokeScript(CefRefPtr browser) { CefV8ValueList args; args.push_back(arg0); - CefRefPtr retVal; - CefRefPtr exception; - if (evalFunc->ExecuteFunctionWithContext(v8Context, globalObj, args, retVal, - exception, false)) { + CefRefPtr retVal = + evalFunc->ExecuteFunctionWithContext(v8Context, globalObj, args); + if (!evalFunc->HasException()) { if (retVal.get()) { frame->ExecuteJavaScript( std::string("alert('InvokeScript returns ") + @@ -51,12 +50,13 @@ void UIT_InvokeScript(CefRefPtr browser) { url, 0); } else { frame->ExecuteJavaScript( - std::string("alert('InvokeScript returns exception: ") + - exception->GetMessage().ToString() + "!');", - url, 0); + std::string("alert('InvokeScript returned no value!"), url, 0); } } else { - frame->ExecuteJavaScript("alert('Failed to execute function!');", url, 0); + frame->ExecuteJavaScript( + std::string("alert('InvokeScript returns exception: ") + + evalFunc->GetException()->GetMessage().ToString() + "!');", + url, 0); } v8Context->Exit(); diff --git a/cef1/tests/cefclient/extension_test.cpp b/cef1/tests/cefclient/extension_test.cpp index e0e0c7a1b..d8eb7a946 100644 --- a/cef1/tests/cefclient/extension_test.cpp +++ b/cef1/tests/cefclient/extension_test.cpp @@ -42,7 +42,7 @@ class ClientV8ExtensionHandler : public CefV8Handler { } else if (name == "GetTestObject") { // Handle the GetTestObject native function by creating and returning a // new V8 object. - retval = CefV8Value::CreateObject(NULL, NULL); + retval = CefV8Value::CreateObject(NULL); // Add a string parameter to the new V8 object. retval->SetValue("param", CefV8Value::CreateString( "Retrieving a parameter on a native object succeeded."), diff --git a/cef1/tests/unittests/storage_unittest.cc b/cef1/tests/unittests/storage_unittest.cc deleted file mode 100644 index 98df8203f..000000000 --- a/cef1/tests/unittests/storage_unittest.cc +++ /dev/null @@ -1,462 +0,0 @@ -// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. - -#include "include/cef_storage.h" -#include "include/cef_v8.h" -#include "tests/unittests/test_handler.h" -#include "tests/unittests/test_suite.h" -#include "base/scoped_temp_dir.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -static const char* kOrigin = "http://tests"; -static const char* kNav1 = "http://tests/nav1.html"; -static const char* kNav2 = "http://tests/nav2.html"; - -static const char* kKey1 = "foo"; -static const char* kVal1 = "bar"; -static const char* kKey2 = "choo"; -static const char* kVal2 = "whatzit"; - -class StorageTestHandler : public TestHandler { - public: - class V8Handler : public CefV8Handler { - public: - explicit V8Handler(CefRefPtr tester) - : tester_(tester) {} - - virtual bool Execute(const CefString& name, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefString& exception) OVERRIDE { - if (arguments.size() != 2) - return false; - - std::string key = arguments[0]->GetStringValue(); - std::string val = arguments[1]->GetStringValue(); - - if (key == kKey1 && val == kVal1) - tester_->got_js_read1_.yes(); - else if (key == kKey2 && val == kVal2) - tester_->got_js_read2_.yes(); - - return true; - } - - CefRefPtr tester_; - - IMPLEMENT_REFCOUNTING(V8Handler); - }; - - class StorageVisitor : public CefStorageVisitor { - public: - enum Mode { - VisitKey, - DeleteKey1, - DeleteKey2 - }; - - StorageVisitor(CefRefPtr tester, - const std::string& description, Mode mode, - TrackCallback* callback1, TrackCallback* callback2, - int expected_total) - : tester_(tester), description_(description), mode_(mode), - callback1_(callback1), callback2_(callback2), - expected_total_(expected_total), actual_total_(0) { - } - virtual ~StorageVisitor() { - EXPECT_EQ(expected_total_, actual_total_) << "test = "<< description_; - } - - virtual bool Visit(CefStorageType type, const CefString& origin, - const CefString& key, const CefString& value, int count, - int total, bool& deleteData) OVERRIDE { - EXPECT_EQ(type, tester_->type_); - std::string originStr = origin; - EXPECT_EQ(originStr, kOrigin); - - std::string keyStr = key; - std::string valueStr = value; - if (keyStr == kKey1 && valueStr == kVal1) - callback1_->yes(); - else if (keyStr == kKey2 && valueStr == kVal2) - callback2_->yes(); - - EXPECT_EQ(expected_total_, total) << "test = "<< description_; - - if ((mode_ == DeleteKey1 && keyStr == kKey1) || - (mode_ == DeleteKey2 && keyStr == kKey2)) - deleteData = true; - - actual_total_++; - - return true; - } - - CefRefPtr tester_; - std::string description_; - Mode mode_; - TrackCallback* callback1_; - TrackCallback* callback2_; - int expected_total_; - int actual_total_; - - IMPLEMENT_REFCOUNTING(StorageVisitor); - }; - - StorageTestHandler(CefStorageType type, bool expectKeysSet, bool leaveKeysSet) - : type_(type), - expect_keys_set_(expectKeysSet), - leave_keys_set_(leaveKeysSet), - nav_(0) {} - - virtual void RunTest() OVERRIDE { - // Verify the key status. - CefVisitStorage(type_, kOrigin, "", - new StorageVisitor(this, "startupvisit", - StorageVisitor::VisitKey, - &got_cpp_startupvisit_fail_, - &got_cpp_startupvisit_fail_, - expect_keys_set_?2:0)); - - std::stringstream ss; - - std::string func = - (type_ == ST_LOCALSTORAGE?"localStorage":"sessionStorage"); - - // Values will be set vis JS on page load. - ss << "Nav1"; - AddResource(kNav1, ss.str(), "text/html"); - ss.str(""); - - // Values will be verified vis JS on page load. - ss << "Nav2"; - AddResource(kNav2, ss.str(), "text/html"); - ss.str(""); - - // Create the browser. - CreateBrowser(kNav1); - } - - virtual void OnLoadEnd(CefRefPtr browser, - CefRefPtr frame, - int httpStatusCode) OVERRIDE { - if (nav_ == 0) { - // Verify read all. - CefVisitStorage(type_, "", "", - new StorageVisitor(this, "all_read", - StorageVisitor::VisitKey, - &got_cpp_all_read1_, - &got_cpp_all_read2_, 2)); - - // Verify read origin. - CefVisitStorage(type_, kOrigin, "", - new StorageVisitor(this, "origin_read", - StorageVisitor::VisitKey, - &got_cpp_origin_read1_, - &got_cpp_origin_read2_, 2)); - - // Verify read key1. - CefVisitStorage(type_, kOrigin, kKey1, - new StorageVisitor(this, "key1_read", - StorageVisitor::VisitKey, - &got_cpp_key_read1_, - &got_cpp_key_read1_fail_, 1)); - - // Verify read key2. - CefVisitStorage(type_, kOrigin, kKey2, - new StorageVisitor(this, "key2_read", - StorageVisitor::VisitKey, - &got_cpp_key_read2_fail_, - &got_cpp_key_read2_, 1)); - - // Delete key1. Verify that key2 still gets read. - CefVisitStorage(type_, kOrigin, "", - new StorageVisitor(this, "key1_delete", - StorageVisitor::DeleteKey1, - &got_cpp_key_delete1_delete_, - &got_cpp_key_delete1_, 2)); - - // Verify that key1 was deleted. - CefVisitStorage(type_, kOrigin, "", - new StorageVisitor(this, "key1_delete_verify", - StorageVisitor::VisitKey, - &got_cpp_afterdeletevisit1_fail_, - &got_cpp_afterdeletevisit1_, 1)); - - // Delete key2. - CefVisitStorage(type_, kOrigin, "", - new StorageVisitor(this, "key2_delete", - StorageVisitor::DeleteKey2, - &got_cpp_key_delete2_fail_, - &got_cpp_key_delete2_delete_, 1)); - - // Verify that all keys have been deleted. - CefVisitStorage(type_, kOrigin, "", - new StorageVisitor(this, "key2_delete_verify", - StorageVisitor::VisitKey, - &got_cpp_afterdeletevisit2_fail_, - &got_cpp_afterdeletevisit2_fail_, 0)); - - // Reset the values. - CefSetStorage(type_, kOrigin, kKey1, kVal1); - CefSetStorage(type_, kOrigin, kKey2, kVal2); - - // Verify that all values have been reset. - CefVisitStorage(type_, "", "", - new StorageVisitor(this, "reset1a_verify", - StorageVisitor::VisitKey, - &got_cpp_all_reset1a_, - &got_cpp_all_reset2a_, 2)); - - // Delete all values. - CefDeleteStorage(type_, "", ""); - - // Verify that all values have been deleted. - CefVisitStorage(type_, "", "", - new StorageVisitor(this, "delete_all_verify", - StorageVisitor::VisitKey, - &got_cpp_afterdeleteall_fail_, - &got_cpp_afterdeleteall_fail_, 0)); - - // Reset all values. - CefSetStorage(type_, kOrigin, kKey1, kVal1); - CefSetStorage(type_, kOrigin, kKey2, kVal2); - - // Verify that all values have been reset. - CefVisitStorage(type_, "", "", - new StorageVisitor(this, "reset1b_verify", - StorageVisitor::VisitKey, - &got_cpp_all_reset1b_, - &got_cpp_all_reset2b_, 2)); - - // Delete all values by origin. - CefDeleteStorage(type_, kOrigin, ""); - - // Verify that all values have been deleted. - CefVisitStorage(type_, "", "", - new StorageVisitor(this, "delete_origin_verify", - StorageVisitor::VisitKey, - &got_cpp_afterdeleteorigin_fail_, - &got_cpp_afterdeleteorigin_fail_, 0)); - - // Reset the values. - CefSetStorage(type_, kOrigin, kKey1, kVal1); - CefSetStorage(type_, kOrigin, kKey2, kVal2); - - // Verify that all values have been reset. - CefVisitStorage(type_, "", "", - new StorageVisitor(this, "reset1c_verify", - StorageVisitor::VisitKey, - &got_cpp_all_reset1c_, - &got_cpp_all_reset2c_, 2)); - - // Delete key1. - CefDeleteStorage(type_, kOrigin, kKey1); - - // Verify that key1 has been deleted. - CefVisitStorage(type_, "", "", - new StorageVisitor(this, "direct_key1_delete_verify", - StorageVisitor::VisitKey, - &got_cpp_afterdeletekey1_fail_, - &got_cpp_afterdeletekey1_, 1)); - - // Delete key2. - CefDeleteStorage(type_, kOrigin, kKey2); - - // Verify that all values have been deleted. - CefVisitStorage(type_, "", "", - new StorageVisitor(this, "direct_key2_delete_verify", - StorageVisitor::VisitKey, - &got_cpp_afterdeletekey2_fail_, - &got_cpp_afterdeletekey2_fail_, 0)); - - // Reset all values. - CefSetStorage(type_, kOrigin, kKey1, kVal1); - CefSetStorage(type_, kOrigin, kKey2, kVal2); - - // Verify that all values have been reset. - CefVisitStorage(type_, "", "", - new StorageVisitor(this, "reset1d_verify", - StorageVisitor::VisitKey, - &got_cpp_all_reset1d_, - &got_cpp_all_reset2d_, 2)); - - nav_++; - // Verify JS read after navigation. - frame->LoadURL(kNav2); - } else { - if (!leave_keys_set_) { - // Delete all values by origin. - CefDeleteStorage(type_, kOrigin, ""); - } - - // Verify the key status. - CefVisitStorage(type_, kOrigin, "", - new StorageVisitor(this, "shutdownvisit", - StorageVisitor::VisitKey, - &got_cpp_shutdownvisit_fail_, - &got_cpp_shutdownvisit_fail_, - leave_keys_set_?2:0)); - - DestroyTest(); - } - } - - virtual void OnContextCreated(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr context) OVERRIDE { - // Retrieve the 'window' object. - CefRefPtr object = context->GetGlobal(); - - CefRefPtr handler = new V8Handler(this); - CefRefPtr testObj = CefV8Value::CreateObject(NULL, NULL); - testObj->SetValue("result", CefV8Value::CreateFunction("result", handler), - V8_PROPERTY_ATTRIBUTE_NONE); - object->SetValue("test", testObj, V8_PROPERTY_ATTRIBUTE_NONE); - } - - CefStorageType type_; - bool expect_keys_set_; - bool leave_keys_set_; - int nav_; - - TrackCallback got_cpp_startupvisit_fail_; - TrackCallback got_cpp_all_read1_; - TrackCallback got_cpp_all_read2_; - TrackCallback got_cpp_origin_read1_; - TrackCallback got_cpp_origin_read2_; - TrackCallback got_cpp_key_read1_; - TrackCallback got_cpp_key_read1_fail_; - TrackCallback got_cpp_key_read2_; - TrackCallback got_cpp_key_read2_fail_; - TrackCallback got_cpp_key_delete1_; - TrackCallback got_cpp_key_delete1_delete_; - TrackCallback got_cpp_key_delete2_delete_; - TrackCallback got_cpp_key_delete2_fail_; - TrackCallback got_cpp_afterdeletevisit1_; - TrackCallback got_cpp_afterdeletevisit1_fail_; - TrackCallback got_cpp_afterdeletevisit2_fail_; - TrackCallback got_cpp_all_reset1a_; - TrackCallback got_cpp_all_reset2a_; - TrackCallback got_cpp_afterdeleteall_fail_; - TrackCallback got_cpp_all_reset1b_; - TrackCallback got_cpp_all_reset2b_; - TrackCallback got_cpp_afterdeleteorigin_fail_; - TrackCallback got_cpp_all_reset1c_; - TrackCallback got_cpp_all_reset2c_; - TrackCallback got_cpp_afterdeletekey1_; - TrackCallback got_cpp_afterdeletekey1_fail_; - TrackCallback got_cpp_afterdeletekey2_fail_; - TrackCallback got_cpp_all_reset1d_; - TrackCallback got_cpp_all_reset2d_; - TrackCallback got_js_read1_; - TrackCallback got_js_read2_; - TrackCallback got_cpp_shutdownvisit_fail_; -}; - -void StorageTest(CefStorageType type, bool expectKeysSet, bool leaveKeysSet) { - CefRefPtr handler = - new StorageTestHandler(type, expectKeysSet, leaveKeysSet); - handler->ExecuteTest(); - - if (expectKeysSet) - EXPECT_TRUE(handler->got_cpp_startupvisit_fail_); - else - EXPECT_FALSE(handler->got_cpp_startupvisit_fail_); - - EXPECT_TRUE(handler->got_cpp_all_read1_); - EXPECT_TRUE(handler->got_cpp_all_read2_); - EXPECT_TRUE(handler->got_cpp_origin_read1_); - EXPECT_TRUE(handler->got_cpp_origin_read2_); - EXPECT_TRUE(handler->got_cpp_key_read1_); - EXPECT_FALSE(handler->got_cpp_key_read1_fail_); - EXPECT_TRUE(handler->got_cpp_key_read2_); - EXPECT_FALSE(handler->got_cpp_key_read2_fail_); - EXPECT_TRUE(handler->got_cpp_key_delete1_); - EXPECT_TRUE(handler->got_cpp_key_delete1_delete_); - EXPECT_TRUE(handler->got_cpp_key_delete2_delete_); - EXPECT_FALSE(handler->got_cpp_key_delete2_fail_); - EXPECT_TRUE(handler->got_cpp_afterdeletevisit1_); - EXPECT_FALSE(handler->got_cpp_afterdeletevisit1_fail_); - EXPECT_FALSE(handler->got_cpp_afterdeletevisit2_fail_); - EXPECT_TRUE(handler->got_cpp_all_reset1a_); - EXPECT_TRUE(handler->got_cpp_all_reset2a_); - EXPECT_FALSE(handler->got_cpp_afterdeleteall_fail_); - EXPECT_TRUE(handler->got_cpp_all_reset1b_); - EXPECT_TRUE(handler->got_cpp_all_reset2b_); - EXPECT_FALSE(handler->got_cpp_afterdeleteorigin_fail_); - EXPECT_TRUE(handler->got_cpp_all_reset1c_); - EXPECT_TRUE(handler->got_cpp_all_reset2c_); - EXPECT_TRUE(handler->got_cpp_afterdeletekey1_); - EXPECT_FALSE(handler->got_cpp_afterdeletekey1_fail_); - EXPECT_FALSE(handler->got_cpp_afterdeletekey2_fail_); - EXPECT_TRUE(handler->got_cpp_all_reset1d_); - EXPECT_TRUE(handler->got_cpp_all_reset2d_); - EXPECT_TRUE(handler->got_js_read1_); - EXPECT_TRUE(handler->got_js_read2_); - - if (leaveKeysSet) - EXPECT_TRUE(handler->got_cpp_shutdownvisit_fail_); - else - EXPECT_FALSE(handler->got_cpp_shutdownvisit_fail_); -} - -} // namespace - -// Test localStorage. -TEST(StorageTest, Local) { - StorageTest(ST_LOCALSTORAGE, false, false); -} - -// Test sessionStorage. -TEST(StorageTest, Session) { - StorageTest(ST_SESSIONSTORAGE, false, false); -} - -// Test changing the localStorage directory. -TEST(StorageTest, LocalChangeDirectory) { - std::string cache_path; - CefTestSuite::GetCachePath(cache_path); - - ScopedTempDir temp_dir; - - // Create a new temporary directory. - EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); - - // Set the new temporary directory as the storage location. - EXPECT_TRUE(CefSetStoragePath(ST_LOCALSTORAGE, temp_dir.path().value())); - - // Run the test leaving behind the set keys. - StorageTest(ST_LOCALSTORAGE, false, true); - - // Restore the original storage location. - EXPECT_TRUE(CefSetStoragePath(ST_LOCALSTORAGE, cache_path)); - - // Run the test. It will fail if the set keys exist in the original storage - // location. - StorageTest(ST_LOCALSTORAGE, false, false); - - // Set the new temporary directory as the storage location. - EXPECT_TRUE(CefSetStoragePath(ST_LOCALSTORAGE, temp_dir.path().value())); - - // Run the test verifying that the keys set previously still exist in the - // temporary directory. - StorageTest(ST_LOCALSTORAGE, true, false); - - // Restore the original storage directory. - EXPECT_TRUE(CefSetStoragePath(ST_LOCALSTORAGE, cache_path)); -} diff --git a/cef1/tests/unittests/v8_unittest.cc b/cef1/tests/unittests/v8_unittest.cc index f683fd48d..ba0a01e12 100644 --- a/cef1/tests/unittests/v8_unittest.cc +++ b/cef1/tests/unittests/v8_unittest.cc @@ -7,12 +7,1531 @@ #include "tests/unittests/test_handler.h" #include "testing/gtest/include/gtest/gtest.h" +// How to add a new test: +// 1. Add a new value to the V8TestMode enumeration. +// 2. Add a method that implements the test in V8TestHandler. +// 3. Add a case for the new enumeration value in V8TestHandler::RunTest. +// 4. Add a line for the test in the "Define the tests" section at the bottom of +// the file. + namespace { -// Base class for V8 unit tests. +// Unique values for V8 tests. +const char* kV8TestUrl = "http://tests/V8Test.Test"; +const char* kV8BindingTestUrl = "http://tests/V8Test.BindingTest"; +const char* kV8ContextParentTestUrl = "http://tests/V8Test.ContextParentTest"; +const char* kV8ContextChildTestUrl = "http://tests/V8Test.ContextChildTest"; +const char* kV8TestMsg = "V8Test.Test"; + +enum V8TestMode { + V8TEST_NULL_CREATE = 0, + V8TEST_BOOL_CREATE, + V8TEST_INT_CREATE, + V8TEST_UINT_CREATE, + V8TEST_DOUBLE_CREATE, + V8TEST_DATE_CREATE, + V8TEST_STRING_CREATE, + V8TEST_ARRAY_CREATE, + V8TEST_ARRAY_VALUE, + V8TEST_OBJECT_CREATE, + V8TEST_OBJECT_USERDATA, + V8TEST_OBJECT_ACCESSOR, + V8TEST_OBJECT_ACCESSOR_EXCEPTION, + V8TEST_OBJECT_ACCESSOR_FAIL, + V8TEST_OBJECT_ACCESSOR_READONLY, + V8TEST_OBJECT_VALUE, + V8TEST_OBJECT_VALUE_READONLY, + V8TEST_OBJECT_VALUE_ENUM, + V8TEST_OBJECT_VALUE_DONTENUM, + V8TEST_OBJECT_VALUE_DELETE, + V8TEST_OBJECT_VALUE_DONTDELETE, + V8TEST_FUNCTION_CREATE, + V8TEST_FUNCTION_HANDLER, + V8TEST_FUNCTION_HANDLER_EXCEPTION, + V8TEST_FUNCTION_HANDLER_FAIL, + V8TEST_FUNCTION_HANDLER_NO_OBJECT, + V8TEST_FUNCTION_HANDLER_WITH_CONTEXT, + V8TEST_CONTEXT_EVAL, + V8TEST_CONTEXT_EVAL_EXCEPTION, + V8TEST_CONTEXT_ENTERED, + V8TEST_BINDING, +}; + + class V8TestHandler : public TestHandler { public: - explicit V8TestHandler(const std::string& code) { + explicit V8TestHandler(V8TestMode test_mode, + const char* test_url) + : test_mode_(test_mode), + test_url_(test_url) { + } + + virtual void RunTest() OVERRIDE { + if (test_mode_ == V8TEST_CONTEXT_ENTERED) { + AddResource(kV8ContextParentTestUrl, "" + "", "text/html"); + AddResource(kV8ContextChildTestUrl, "CHILD", + "text/html"); + CreateBrowser(kV8ContextParentTestUrl); + } else { + EXPECT_TRUE(test_url_ != NULL); + AddResource(test_url_, "TEST", "text/html"); + CreateBrowser(test_url_); + } + } + + // Run the specified test. + void RunTest(V8TestMode test_mode) { + switch (test_mode) { + case V8TEST_NULL_CREATE: + RunNullCreateTest(); + break; + case V8TEST_BOOL_CREATE: + RunBoolCreateTest(); + break; + case V8TEST_INT_CREATE: + RunIntCreateTest(); + break; + case V8TEST_UINT_CREATE: + RunUIntCreateTest(); + break; + case V8TEST_DOUBLE_CREATE: + RunDoubleCreateTest(); + break; + case V8TEST_DATE_CREATE: + RunDateCreateTest(); + break; + case V8TEST_STRING_CREATE: + RunStringCreateTest(); + break; + case V8TEST_ARRAY_CREATE: + RunArrayCreateTest(); + break; + case V8TEST_ARRAY_VALUE: + RunArrayValueTest(); + break; + case V8TEST_OBJECT_CREATE: + RunObjectCreateTest(); + break; + case V8TEST_OBJECT_USERDATA: + RunObjectUserDataTest(); + break; + case V8TEST_OBJECT_ACCESSOR: + RunObjectAccessorTest(); + break; + case V8TEST_OBJECT_ACCESSOR_EXCEPTION: + RunObjectAccessorExceptionTest(); + break; + case V8TEST_OBJECT_ACCESSOR_FAIL: + RunObjectAccessorFailTest(); + break; + case V8TEST_OBJECT_ACCESSOR_READONLY: + RunObjectAccessorReadOnlyTest(); + break; + case V8TEST_OBJECT_VALUE: + RunObjectValueTest(); + break; + case V8TEST_OBJECT_VALUE_READONLY: + RunObjectValueReadOnlyTest(); + break; + case V8TEST_OBJECT_VALUE_ENUM: + RunObjectValueEnumTest(); + break; + case V8TEST_OBJECT_VALUE_DONTENUM: + RunObjectValueDontEnumTest(); + break; + case V8TEST_OBJECT_VALUE_DELETE: + RunObjectValueDeleteTest(); + break; + case V8TEST_OBJECT_VALUE_DONTDELETE: + RunObjectValueDontDeleteTest(); + break; + case V8TEST_FUNCTION_CREATE: + RunFunctionCreateTest(); + break; + case V8TEST_FUNCTION_HANDLER: + RunFunctionHandlerTest(); + break; + case V8TEST_FUNCTION_HANDLER_EXCEPTION: + RunFunctionHandlerExceptionTest(); + break; + case V8TEST_FUNCTION_HANDLER_FAIL: + RunFunctionHandlerFailTest(); + break; + case V8TEST_FUNCTION_HANDLER_NO_OBJECT: + RunFunctionHandlerNoObjectTest(); + break; + case V8TEST_FUNCTION_HANDLER_WITH_CONTEXT: + RunFunctionHandlerWithContextTest(); + break; + case V8TEST_CONTEXT_EVAL: + RunContextEvalTest(); + break; + case V8TEST_CONTEXT_EVAL_EXCEPTION: + RunContextEvalExceptionTest(); + break; + case V8TEST_CONTEXT_ENTERED: + RunContextEnteredTest(); + break; + case V8TEST_BINDING: + RunBindingTest(); + break; + default: + ADD_FAILURE(); + DestroyTest(); + break; + } + } + + void RunNullCreateTest() { + CefRefPtr value = CefV8Value::CreateNull(); + EXPECT_TRUE(value.get()); + EXPECT_TRUE(value->IsNull()); + + EXPECT_FALSE(value->IsUndefined()); + EXPECT_FALSE(value->IsArray()); + EXPECT_FALSE(value->IsBool()); + EXPECT_FALSE(value->IsDate()); + EXPECT_FALSE(value->IsDouble()); + EXPECT_FALSE(value->IsFunction()); + EXPECT_FALSE(value->IsInt()); + EXPECT_FALSE(value->IsUInt()); + EXPECT_FALSE(value->IsObject()); + EXPECT_FALSE(value->IsString()); + + DestroyTest(); + } + + void RunBoolCreateTest() { + CefRefPtr value = CefV8Value::CreateBool(true); + EXPECT_TRUE(value.get()); + EXPECT_TRUE(value->IsBool()); + EXPECT_EQ(true, value->GetBoolValue()); + + EXPECT_FALSE(value->IsUndefined()); + EXPECT_FALSE(value->IsArray()); + EXPECT_FALSE(value->IsDate()); + EXPECT_FALSE(value->IsDouble()); + EXPECT_FALSE(value->IsFunction()); + EXPECT_FALSE(value->IsInt()); + EXPECT_FALSE(value->IsUInt()); + EXPECT_FALSE(value->IsNull()); + EXPECT_FALSE(value->IsObject()); + EXPECT_FALSE(value->IsString()); + + DestroyTest(); + } + + void RunIntCreateTest() { + CefRefPtr value = CefV8Value::CreateInt(12); + EXPECT_TRUE(value.get()); + EXPECT_TRUE(value->IsInt()); + EXPECT_TRUE(value->IsUInt()); + EXPECT_TRUE(value->IsDouble()); + EXPECT_EQ(12, value->GetIntValue()); + EXPECT_EQ((uint32)12, value->GetUIntValue()); + EXPECT_EQ(12, value->GetDoubleValue()); + + EXPECT_FALSE(value->IsUndefined()); + EXPECT_FALSE(value->IsArray()); + EXPECT_FALSE(value->IsBool()); + EXPECT_FALSE(value->IsDate()); + EXPECT_FALSE(value->IsFunction()); + EXPECT_FALSE(value->IsNull()); + EXPECT_FALSE(value->IsObject()); + EXPECT_FALSE(value->IsString()); + + DestroyTest(); + } + + void RunUIntCreateTest() { + CefRefPtr value = CefV8Value::CreateUInt(12); + EXPECT_TRUE(value.get()); + EXPECT_TRUE(value->IsInt()); + EXPECT_TRUE(value->IsUInt()); + EXPECT_TRUE(value->IsDouble()); + EXPECT_EQ(12, value->GetIntValue()); + EXPECT_EQ((uint32)12, value->GetUIntValue()); + EXPECT_EQ(12, value->GetDoubleValue()); + + EXPECT_FALSE(value->IsUndefined()); + EXPECT_FALSE(value->IsArray()); + EXPECT_FALSE(value->IsBool()); + EXPECT_FALSE(value->IsDate()); + EXPECT_FALSE(value->IsFunction()); + EXPECT_FALSE(value->IsNull()); + EXPECT_FALSE(value->IsObject()); + EXPECT_FALSE(value->IsString()); + + DestroyTest(); + } + + void RunDoubleCreateTest() { + CefRefPtr value = CefV8Value::CreateDouble(12.1223); + EXPECT_TRUE(value.get()); + EXPECT_TRUE(value->IsDouble()); + EXPECT_EQ(12.1223, value->GetDoubleValue()); + + EXPECT_FALSE(value->IsUndefined()); + EXPECT_FALSE(value->IsArray()); + EXPECT_FALSE(value->IsBool()); + EXPECT_FALSE(value->IsDate()); + EXPECT_FALSE(value->IsFunction()); + EXPECT_FALSE(value->IsInt()); + EXPECT_FALSE(value->IsUInt()); + EXPECT_FALSE(value->IsNull()); + EXPECT_FALSE(value->IsObject()); + EXPECT_FALSE(value->IsString()); + + DestroyTest(); + } + + void RunDateCreateTest() { + CefRefPtr context = GetContext(); + + CefTime date; + date.year = 2200; + date.month = 4; +#if !defined(OS_MACOSX) + date.day_of_week = 5; +#endif + date.day_of_month = 11; + date.hour = 20; + date.minute = 15; + date.second = 42; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr value = CefV8Value::CreateDate(date); + EXPECT_TRUE(value.get()); + EXPECT_TRUE(value->IsDate()); + EXPECT_TRUE(value->IsObject()); + EXPECT_EQ(date.GetTimeT(), value->GetDateValue().GetTimeT()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + EXPECT_FALSE(value->IsUndefined()); + EXPECT_FALSE(value->IsArray()); + EXPECT_FALSE(value->IsBool()); + EXPECT_FALSE(value->IsDouble()); + EXPECT_FALSE(value->IsFunction()); + EXPECT_FALSE(value->IsInt()); + EXPECT_FALSE(value->IsUInt()); + EXPECT_FALSE(value->IsNull()); + EXPECT_FALSE(value->IsString()); + + DestroyTest(); + } + + void RunStringCreateTest() { + CefRefPtr value = CefV8Value::CreateString("My string"); + EXPECT_TRUE(value.get()); + EXPECT_TRUE(value->IsString()); + EXPECT_STREQ("My string", value->GetStringValue().ToString().c_str()); + + EXPECT_FALSE(value->IsUndefined()); + EXPECT_FALSE(value->IsArray()); + EXPECT_FALSE(value->IsBool()); + EXPECT_FALSE(value->IsDate()); + EXPECT_FALSE(value->IsDouble()); + EXPECT_FALSE(value->IsFunction()); + EXPECT_FALSE(value->IsInt()); + EXPECT_FALSE(value->IsUInt()); + EXPECT_FALSE(value->IsNull()); + EXPECT_FALSE(value->IsObject()); + + DestroyTest(); + } + + void RunArrayCreateTest() { + CefRefPtr context = GetContext(); + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr value = CefV8Value::CreateArray(2); + EXPECT_TRUE(value.get()); + EXPECT_TRUE(value->IsArray()); + EXPECT_TRUE(value->IsObject()); + EXPECT_EQ(2, value->GetArrayLength()); + EXPECT_FALSE(value->HasValue(0)); + EXPECT_FALSE(value->HasValue(1)); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + EXPECT_FALSE(value->IsUndefined()); + EXPECT_FALSE(value->IsBool()); + EXPECT_FALSE(value->IsDate()); + EXPECT_FALSE(value->IsDouble()); + EXPECT_FALSE(value->IsFunction()); + EXPECT_FALSE(value->IsInt()); + EXPECT_FALSE(value->IsUInt()); + EXPECT_FALSE(value->IsNull()); + EXPECT_FALSE(value->IsString()); + + DestroyTest(); + } + + void RunArrayValueTest() { + CefRefPtr context = GetContext(); + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr value = CefV8Value::CreateArray(0); + EXPECT_TRUE(value.get()); + EXPECT_TRUE(value->IsArray()); + EXPECT_EQ(0, value->GetArrayLength()); + + // Test addng values. + EXPECT_FALSE(value->HasValue(0)); + EXPECT_FALSE(value->HasValue(1)); + + EXPECT_TRUE(value->SetValue(0, CefV8Value::CreateInt(10))); + EXPECT_FALSE(value->HasException()); + EXPECT_TRUE(value->HasValue(0)); + EXPECT_FALSE(value->HasValue(1)); + + EXPECT_TRUE(value->GetValue(0)->IsInt()); + EXPECT_EQ(10, value->GetValue(0)->GetIntValue()); + EXPECT_FALSE(value->HasException()); + EXPECT_EQ(1, value->GetArrayLength()); + + EXPECT_TRUE(value->SetValue(1, CefV8Value::CreateInt(43))); + EXPECT_FALSE(value->HasException()); + EXPECT_TRUE(value->HasValue(0)); + EXPECT_TRUE(value->HasValue(1)); + + EXPECT_TRUE(value->GetValue(1)->IsInt()); + EXPECT_EQ(43, value->GetValue(1)->GetIntValue()); + EXPECT_FALSE(value->HasException()); + EXPECT_EQ(2, value->GetArrayLength()); + + EXPECT_TRUE(value->DeleteValue(0)); + EXPECT_FALSE(value->HasValue(0)); + EXPECT_TRUE(value->HasValue(1)); + EXPECT_EQ(2, value->GetArrayLength()); + + EXPECT_TRUE(value->DeleteValue(1)); + EXPECT_FALSE(value->HasValue(0)); + EXPECT_FALSE(value->HasValue(1)); + EXPECT_EQ(2, value->GetArrayLength()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunObjectCreateTest() { + CefRefPtr context = GetContext(); + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr value = CefV8Value::CreateObject(NULL); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + EXPECT_TRUE(value.get()); + EXPECT_TRUE(value->IsObject()); + EXPECT_FALSE(value->GetUserData().get()); + + EXPECT_FALSE(value->IsUndefined()); + EXPECT_FALSE(value->IsArray()); + EXPECT_FALSE(value->IsBool()); + EXPECT_FALSE(value->IsDate()); + EXPECT_FALSE(value->IsDouble()); + EXPECT_FALSE(value->IsFunction()); + EXPECT_FALSE(value->IsInt()); + EXPECT_FALSE(value->IsUInt()); + EXPECT_FALSE(value->IsNull()); + EXPECT_FALSE(value->IsString()); + + DestroyTest(); + } + + void RunObjectUserDataTest() { + CefRefPtr context = GetContext(); + + class UserData : public CefBase { + public: + explicit UserData(int value) : value_(value) {} + int value_; + IMPLEMENT_REFCOUNTING(UserData); + }; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr value = CefV8Value::CreateObject(NULL); + EXPECT_TRUE(value.get()); + + EXPECT_TRUE(value->SetUserData(new UserData(10))); + + CefRefPtr user_data = value->GetUserData(); + EXPECT_TRUE(user_data.get()); + UserData* user_data_impl = static_cast(user_data.get()); + EXPECT_EQ(10, user_data_impl->value_); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunObjectAccessorTest() { + CefRefPtr context = GetContext(); + + static const char* kName = "val"; + static const int kValue = 20; + + class Accessor : public CefV8Accessor { + public: + Accessor() : value_(0) {} + virtual bool Get(const CefString& name, + const CefRefPtr object, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + EXPECT_STREQ(kName, name.ToString().c_str()); + + EXPECT_TRUE(object.get()); + EXPECT_TRUE(object->IsSame(object_)); + + EXPECT_FALSE(retval.get()); + EXPECT_TRUE(exception.empty()); + + got_get_.yes(); + retval = CefV8Value::CreateInt(value_); + EXPECT_EQ(kValue, retval->GetIntValue()); + return true; + } + + virtual bool Set(const CefString& name, + const CefRefPtr object, + const CefRefPtr value, + CefString& exception) OVERRIDE { + EXPECT_STREQ(kName, name.ToString().c_str()); + + EXPECT_TRUE(object.get()); + EXPECT_TRUE(object->IsSame(object_)); + + EXPECT_TRUE(value.get()); + EXPECT_TRUE(exception.empty()); + + got_set_.yes(); + value_ = value->GetIntValue(); + EXPECT_EQ(kValue, value_); + return true; + } + + CefRefPtr object_; + int value_; + TrackCallback got_get_; + TrackCallback got_set_; + + IMPLEMENT_REFCOUNTING(Accessor); + }; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + Accessor* accessor = new Accessor; + CefRefPtr accessorPtr(accessor); + + CefRefPtr object = CefV8Value::CreateObject(accessor); + EXPECT_TRUE(object.get()); + accessor->object_ = object; + + EXPECT_FALSE(object->HasValue(kName)); + + EXPECT_TRUE(object->SetValue(kName, V8_ACCESS_CONTROL_DEFAULT, + V8_PROPERTY_ATTRIBUTE_NONE)); + EXPECT_FALSE(object->HasException()); + EXPECT_TRUE(object->HasValue(kName)); + + EXPECT_TRUE(object->SetValue(kName, CefV8Value::CreateInt(kValue), + V8_PROPERTY_ATTRIBUTE_NONE)); + EXPECT_FALSE(object->HasException()); + EXPECT_TRUE(accessor->got_set_); + EXPECT_EQ(kValue, accessor->value_); + + CefRefPtr val = object->GetValue(kName); + EXPECT_FALSE(object->HasException()); + EXPECT_TRUE(val.get()); + EXPECT_TRUE(accessor->got_get_); + EXPECT_TRUE(val->IsInt()); + EXPECT_EQ(kValue, val->GetIntValue()); + + accessor->object_ = NULL; + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunObjectAccessorExceptionTest() { + CefRefPtr context = GetContext(); + + static const char* kName = "val"; + static const char* kGetException = "My get exception"; + static const char* kSetException = "My set exception"; + static const char* kGetExceptionMsg = "Uncaught Error: My get exception"; + static const char* kSetExceptionMsg = "Uncaught Error: My set exception"; + + class Accessor : public CefV8Accessor { + public: + Accessor() {} + virtual bool Get(const CefString& name, + const CefRefPtr object, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + got_get_.yes(); + exception = kGetException; + return true; + } + + virtual bool Set(const CefString& name, + const CefRefPtr object, + const CefRefPtr value, + CefString& exception) OVERRIDE { + got_set_.yes(); + exception = kSetException; + return true; + } + + TrackCallback got_get_; + TrackCallback got_set_; + + IMPLEMENT_REFCOUNTING(Accessor); + }; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr exception; + Accessor* accessor = new Accessor; + CefRefPtr accessorPtr(accessor); + + CefRefPtr object = CefV8Value::CreateObject(accessor); + EXPECT_TRUE(object.get()); + + EXPECT_FALSE(object->HasValue(kName)); + + EXPECT_TRUE(object->SetValue(kName, V8_ACCESS_CONTROL_DEFAULT, + V8_PROPERTY_ATTRIBUTE_NONE)); + EXPECT_FALSE(object->HasException()); + EXPECT_TRUE(object->HasValue(kName)); + + EXPECT_FALSE(object->SetValue(kName, CefV8Value::CreateInt(1), + V8_PROPERTY_ATTRIBUTE_NONE)); + EXPECT_TRUE(object->HasException()); + EXPECT_TRUE(accessor->got_set_); + exception = object->GetException(); + EXPECT_TRUE(exception.get()); + EXPECT_STREQ(kSetExceptionMsg, exception->GetMessage().ToString().c_str()); + + EXPECT_TRUE(object->ClearException()); + EXPECT_FALSE(object->HasException()); + + CefRefPtr val = object->GetValue(kName); + EXPECT_FALSE(val.get()); + EXPECT_TRUE(object->HasException()); + EXPECT_TRUE(accessor->got_get_); + exception = object->GetException(); + EXPECT_TRUE(exception.get()); + EXPECT_STREQ(kGetExceptionMsg, exception->GetMessage().ToString().c_str()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunObjectAccessorFailTest() { + CefRefPtr context = GetContext(); + + static const char* kName = "val"; + + class Accessor : public CefV8Accessor { + public: + Accessor() {} + virtual bool Get(const CefString& name, + const CefRefPtr object, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + got_get_.yes(); + return false; + } + + virtual bool Set(const CefString& name, + const CefRefPtr object, + const CefRefPtr value, + CefString& exception) OVERRIDE { + got_set_.yes(); + return false; + } + + TrackCallback got_get_; + TrackCallback got_set_; + + IMPLEMENT_REFCOUNTING(Accessor); + }; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr exception; + Accessor* accessor = new Accessor; + CefRefPtr accessorPtr(accessor); + + CefRefPtr object = CefV8Value::CreateObject(accessor); + EXPECT_TRUE(object.get()); + + EXPECT_FALSE(object->HasValue(kName)); + + EXPECT_TRUE(object->SetValue(kName, V8_ACCESS_CONTROL_DEFAULT, + V8_PROPERTY_ATTRIBUTE_NONE)); + EXPECT_FALSE(object->HasException()); + EXPECT_TRUE(object->HasValue(kName)); + + EXPECT_TRUE(object->SetValue(kName, CefV8Value::CreateInt(1), + V8_PROPERTY_ATTRIBUTE_NONE)); + EXPECT_FALSE(object->HasException()); + EXPECT_TRUE(accessor->got_set_); + + CefRefPtr val = object->GetValue(kName); + EXPECT_TRUE(val.get()); + EXPECT_FALSE(object->HasException()); + EXPECT_TRUE(accessor->got_get_); + EXPECT_TRUE(val->IsUndefined()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunObjectAccessorReadOnlyTest() { + CefRefPtr context = GetContext(); + + static const char* kName = "val"; + + class Accessor : public CefV8Accessor { + public: + Accessor() {} + virtual bool Get(const CefString& name, + const CefRefPtr object, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + got_get_.yes(); + return true; + } + + virtual bool Set(const CefString& name, + const CefRefPtr object, + const CefRefPtr value, + CefString& exception) OVERRIDE { + got_set_.yes(); + return true; + } + + TrackCallback got_get_; + TrackCallback got_set_; + + IMPLEMENT_REFCOUNTING(Accessor); + }; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr exception; + Accessor* accessor = new Accessor; + CefRefPtr accessorPtr(accessor); + + CefRefPtr object = CefV8Value::CreateObject(accessor); + EXPECT_TRUE(object.get()); + + EXPECT_FALSE(object->HasValue(kName)); + + EXPECT_TRUE(object->SetValue(kName, V8_ACCESS_CONTROL_DEFAULT, + V8_PROPERTY_ATTRIBUTE_READONLY)); + EXPECT_FALSE(object->HasException()); + EXPECT_TRUE(object->HasValue(kName)); + + EXPECT_TRUE(object->SetValue(kName, CefV8Value::CreateInt(1), + V8_PROPERTY_ATTRIBUTE_NONE)); + EXPECT_FALSE(object->HasException()); + EXPECT_FALSE(accessor->got_set_); + + CefRefPtr val = object->GetValue(kName); + EXPECT_TRUE(val.get()); + EXPECT_FALSE(object->HasException()); + EXPECT_TRUE(accessor->got_get_); + EXPECT_TRUE(val->IsUndefined()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunObjectValueTest() { + CefRefPtr context = GetContext(); + + static const char* kName = "test_arg"; + static const int kVal1 = 13; + static const int kVal2 = 65; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr object = context->GetGlobal(); + EXPECT_TRUE(object.get()); + + object->SetValue(kName, CefV8Value::CreateInt(kVal1), + V8_PROPERTY_ATTRIBUTE_NONE); + + std::stringstream test; + test << + "if (window." << kName << " != " << kVal1 << ") throw 'Fail';\n" << + "window." << kName << " = " << kVal2 << ";"; + + CefRefPtr retval; + CefRefPtr exception; + + EXPECT_TRUE(context->Eval(test.str(), retval, exception)); + if (exception.get()) + ADD_FAILURE() << exception->GetMessage().c_str(); + + CefRefPtr newval = object->GetValue(kName); + EXPECT_TRUE(newval.get()); + EXPECT_TRUE(newval->IsInt()); + EXPECT_EQ(kVal2, newval->GetIntValue()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunObjectValueReadOnlyTest() { + CefRefPtr context = GetContext(); + + static const char* kName = "test_arg"; + static const int kVal1 = 13; + static const int kVal2 = 65; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr object = context->GetGlobal(); + EXPECT_TRUE(object.get()); + + object->SetValue(kName, CefV8Value::CreateInt(kVal1), + V8_PROPERTY_ATTRIBUTE_READONLY); + + std::stringstream test; + test << + "if (window." << kName << " != " << kVal1 << ") throw 'Fail';\n" << + "window." << kName << " = " << kVal2 << ";"; + + CefRefPtr retval; + CefRefPtr exception; + + EXPECT_TRUE(context->Eval(test.str(), retval, exception)); + if (exception.get()) + ADD_FAILURE() << exception->GetMessage().c_str(); + + CefRefPtr newval = object->GetValue(kName); + EXPECT_TRUE(newval.get()); + EXPECT_TRUE(newval->IsInt()); + EXPECT_EQ(kVal1, newval->GetIntValue()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunObjectValueEnumTest() { + CefRefPtr context = GetContext(); + + static const char* kObjName = "test_obj"; + static const char* kArgName = "test_arg"; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr object = context->GetGlobal(); + EXPECT_TRUE(object.get()); + + CefRefPtr obj1 = CefV8Value::CreateObject(NULL); + object->SetValue(kObjName, obj1, V8_PROPERTY_ATTRIBUTE_NONE); + + obj1->SetValue(kArgName, CefV8Value::CreateInt(0), + V8_PROPERTY_ATTRIBUTE_NONE); + + std::stringstream test; + test << + "for (var i in window." << kObjName << ") {\n" + "window." << kObjName << "[i]++;\n" + "}"; + + CefRefPtr retval; + CefRefPtr exception; + + EXPECT_TRUE(context->Eval(test.str(), retval, exception)); + if (exception.get()) + ADD_FAILURE() << exception->GetMessage().c_str(); + + CefRefPtr newval = obj1->GetValue(kArgName); + EXPECT_TRUE(newval.get()); + EXPECT_TRUE(newval->IsInt()); + EXPECT_EQ(1, newval->GetIntValue()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunObjectValueDontEnumTest() { + CefRefPtr context = GetContext(); + + static const char* kObjName = "test_obj"; + static const char* kArgName = "test_arg"; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr object = context->GetGlobal(); + EXPECT_TRUE(object.get()); + + CefRefPtr obj1 = CefV8Value::CreateObject(NULL); + object->SetValue(kObjName, obj1, V8_PROPERTY_ATTRIBUTE_NONE); + + obj1->SetValue(kArgName, CefV8Value::CreateInt(0), + V8_PROPERTY_ATTRIBUTE_DONTENUM); + + std::stringstream test; + test << + "for (var i in window." << kObjName << ") {\n" + "window." << kObjName << "[i]++;\n" + "}"; + + CefRefPtr retval; + CefRefPtr exception; + + EXPECT_TRUE(context->Eval(test.str(), retval, exception)); + if (exception.get()) + ADD_FAILURE() << exception->GetMessage().c_str(); + + CefRefPtr newval = obj1->GetValue(kArgName); + EXPECT_TRUE(newval.get()); + EXPECT_TRUE(newval->IsInt()); + EXPECT_EQ(0, newval->GetIntValue()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunObjectValueDeleteTest() { + CefRefPtr context = GetContext(); + + static const char* kName = "test_arg"; + static const int kVal1 = 13; + static const int kVal2 = 65; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr object = context->GetGlobal(); + EXPECT_TRUE(object.get()); + + object->SetValue(kName, CefV8Value::CreateInt(kVal1), + V8_PROPERTY_ATTRIBUTE_NONE); + + std::stringstream test; + test << + "if (window." << kName << " != " << kVal1 << ") throw 'Fail';\n" << + "window." << kName << " = " << kVal2 << ";\n" + "delete window." << kName << ";"; + + CefRefPtr retval; + CefRefPtr exception; + + EXPECT_TRUE(context->Eval(test.str(), retval, exception)); + if (exception.get()) + ADD_FAILURE() << exception->GetMessage().c_str(); + + CefRefPtr newval = object->GetValue(kName); + EXPECT_TRUE(newval.get()); + EXPECT_TRUE(newval->IsUndefined()); + EXPECT_FALSE(newval->IsInt()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunObjectValueDontDeleteTest() { + CefRefPtr context = GetContext(); + + static const char* kName = "test_arg"; + static const int kVal1 = 13; + static const int kVal2 = 65; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr object = context->GetGlobal(); + EXPECT_TRUE(object.get()); + + object->SetValue(kName, CefV8Value::CreateInt(kVal1), + V8_PROPERTY_ATTRIBUTE_DONTDELETE); + + std::stringstream test; + test << + "if (window." << kName << " != " << kVal1 << ") throw 'Fail';\n" << + "window." << kName << " = " << kVal2 << ";\n" + "delete window." << kName << ";"; + + CefRefPtr retval; + CefRefPtr exception; + + EXPECT_TRUE(context->Eval(test.str(), retval, exception)); + if (exception.get()) + ADD_FAILURE() << exception->GetMessage().c_str(); + + CefRefPtr newval = object->GetValue(kName); + EXPECT_TRUE(newval.get()); + EXPECT_TRUE(newval->IsInt()); + EXPECT_EQ(kVal2, newval->GetIntValue()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunFunctionCreateTest() { + CefRefPtr context = GetContext(); + + class Handler : public CefV8Handler { + public: + Handler() {} + virtual bool Execute(const CefString& name, + CefRefPtr object, + const CefV8ValueList& arguments, + CefRefPtr& retval, + CefString& exception) OVERRIDE { return false; } + IMPLEMENT_REFCOUNTING(Handler); + }; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr value = CefV8Value::CreateFunction("f", new Handler); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + EXPECT_TRUE(value.get()); + EXPECT_TRUE(value->IsFunction()); + EXPECT_TRUE(value->IsObject()); + + EXPECT_FALSE(value->IsUndefined()); + EXPECT_FALSE(value->IsArray()); + EXPECT_FALSE(value->IsBool()); + EXPECT_FALSE(value->IsDate()); + EXPECT_FALSE(value->IsDouble()); + EXPECT_FALSE(value->IsInt()); + EXPECT_FALSE(value->IsUInt()); + EXPECT_FALSE(value->IsNull()); + EXPECT_FALSE(value->IsString()); + + DestroyTest(); + } + + void RunFunctionHandlerTest() { + CefRefPtr context = GetContext(); + + static const char* kFuncName = "myfunc"; + static const int kVal1 = 32; + static const int kVal2 = 41; + static const int kRetVal = 8; + + class Handler : public CefV8Handler { + public: + Handler() {} + virtual bool Execute(const CefString& name, + CefRefPtr object, + const CefV8ValueList& arguments, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + EXPECT_STREQ(kFuncName, name.ToString().c_str()); + EXPECT_TRUE(object->IsSame(object_)); + + EXPECT_EQ((size_t)2, arguments.size()); + EXPECT_TRUE(arguments[0]->IsInt()); + EXPECT_EQ(kVal1, arguments[0]->GetIntValue()); + EXPECT_TRUE(arguments[1]->IsInt()); + EXPECT_EQ(kVal2, arguments[1]->GetIntValue()); + + EXPECT_TRUE(exception.empty()); + + retval = CefV8Value::CreateInt(kRetVal); + EXPECT_TRUE(retval.get()); + EXPECT_EQ(kRetVal, retval->GetIntValue()); + + got_execute_.yes(); + return true; + } + + CefRefPtr object_; + TrackCallback got_execute_; + + IMPLEMENT_REFCOUNTING(Handler); + }; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + Handler* handler = new Handler; + CefRefPtr handlerPtr(handler); + + CefRefPtr func = + CefV8Value::CreateFunction(kFuncName, handler); + EXPECT_TRUE(func.get()); + + CefRefPtr obj = CefV8Value::CreateObject(NULL); + EXPECT_TRUE(obj.get()); + handler->object_ = obj; + + CefV8ValueList args; + args.push_back(CefV8Value::CreateInt(kVal1)); + args.push_back(CefV8Value::CreateInt(kVal2)); + + CefRefPtr retval = func->ExecuteFunction(obj, args); + EXPECT_TRUE(handler->got_execute_); + EXPECT_TRUE(retval.get()); + EXPECT_FALSE(func->HasException()); + EXPECT_TRUE(retval->IsInt()); + EXPECT_EQ(kRetVal, retval->GetIntValue()); + + handler->object_ = NULL; + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunFunctionHandlerExceptionTest() { + CefRefPtr context = GetContext(); + + static const char* kException = "My error"; + static const char* kExceptionMsg = "Uncaught Error: My error"; + + class Handler : public CefV8Handler { + public: + Handler() {} + virtual bool Execute(const CefString& name, + CefRefPtr object, + const CefV8ValueList& arguments, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + exception = kException; + got_execute_.yes(); + return true; + } + + TrackCallback got_execute_; + + IMPLEMENT_REFCOUNTING(Handler); + }; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + Handler* handler = new Handler; + CefRefPtr handlerPtr(handler); + + CefRefPtr func = + CefV8Value::CreateFunction("myfunc", handler); + EXPECT_TRUE(func.get()); + + CefV8ValueList args; + + CefRefPtr retval = func->ExecuteFunction(NULL, args); + EXPECT_TRUE(handler->got_execute_); + EXPECT_FALSE(retval.get()); + EXPECT_TRUE(func->HasException()); + CefRefPtr exception = func->GetException(); + EXPECT_TRUE(exception.get()); + EXPECT_STREQ(kExceptionMsg, exception->GetMessage().ToString().c_str()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunFunctionHandlerFailTest() { + CefRefPtr context = GetContext(); + + class Handler : public CefV8Handler { + public: + Handler() {} + virtual bool Execute(const CefString& name, + CefRefPtr object, + const CefV8ValueList& arguments, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + got_execute_.yes(); + return false; + } + + TrackCallback got_execute_; + + IMPLEMENT_REFCOUNTING(Handler); + }; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + Handler* handler = new Handler; + CefRefPtr handlerPtr(handler); + + CefRefPtr func = + CefV8Value::CreateFunction("myfunc", handler); + EXPECT_TRUE(func.get()); + + CefV8ValueList args; + + CefRefPtr retval = func->ExecuteFunction(NULL, args); + EXPECT_TRUE(handler->got_execute_); + EXPECT_TRUE(retval.get()); + EXPECT_FALSE(func->HasException()); + EXPECT_TRUE(retval->IsUndefined()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunFunctionHandlerNoObjectTest() { + CefRefPtr context = GetContext(); + + class Handler : public CefV8Handler { + public: + Handler() {} + virtual bool Execute(const CefString& name, + CefRefPtr object, + const CefV8ValueList& arguments, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + EXPECT_TRUE(object.get()); + CefRefPtr context = CefV8Context::GetCurrentContext(); + EXPECT_TRUE(context.get()); + CefRefPtr global = context->GetGlobal(); + EXPECT_TRUE(global.get()); + EXPECT_TRUE(global->IsSame(object)); + + got_execute_.yes(); + return true; + } + + TrackCallback got_execute_; + + IMPLEMENT_REFCOUNTING(Handler); + }; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + Handler* handler = new Handler; + CefRefPtr handlerPtr(handler); + + CefRefPtr func = + CefV8Value::CreateFunction("myfunc", handler); + EXPECT_TRUE(func.get()); + + CefV8ValueList args; + + CefRefPtr retval = func->ExecuteFunction(NULL, args); + EXPECT_TRUE(handler->got_execute_); + EXPECT_TRUE(retval.get()); + EXPECT_FALSE(func->HasException()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + void RunFunctionHandlerWithContextTest() { + CefRefPtr context = GetContext(); + + class Handler : public CefV8Handler { + public: + Handler() {} + virtual bool Execute(const CefString& name, + CefRefPtr object, + const CefV8ValueList& arguments, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + CefRefPtr context = CefV8Context::GetCurrentContext(); + EXPECT_TRUE(context.get()); + EXPECT_TRUE(context->IsSame(context_)); + got_execute_.yes(); + return true; + } + + CefRefPtr context_; + TrackCallback got_execute_; + + IMPLEMENT_REFCOUNTING(Handler); + }; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + Handler* handler = new Handler; + CefRefPtr handlerPtr(handler); + handler->context_ = context; + + CefRefPtr func = + CefV8Value::CreateFunction("myfunc", handler); + EXPECT_TRUE(func.get()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + CefV8ValueList args; + + CefRefPtr retval = + func->ExecuteFunctionWithContext(context, NULL, args); + EXPECT_TRUE(handler->got_execute_); + EXPECT_TRUE(retval.get()); + EXPECT_FALSE(func->HasException()); + + handler->context_ = NULL; + + DestroyTest(); + } + + void RunContextEvalTest() { + CefRefPtr context = GetContext(); + + CefRefPtr retval; + CefRefPtr exception; + + EXPECT_TRUE(context->Eval("1+2", retval, exception)); + EXPECT_TRUE(retval.get()); + EXPECT_TRUE(retval->IsInt()); + EXPECT_EQ(3, retval->GetIntValue()); + EXPECT_FALSE(exception.get()); + + DestroyTest(); + } + + void RunContextEvalExceptionTest() { + CefRefPtr context = GetContext(); + + CefRefPtr retval; + CefRefPtr exception; + + EXPECT_FALSE(context->Eval("1+foo", retval, exception)); + EXPECT_FALSE(retval.get()); + EXPECT_TRUE(exception.get()); + + DestroyTest(); + } + + void RunContextEnteredTest() { + CefRefPtr context = GetContext(); + + CefRefPtr retval; + CefRefPtr exception; + + // Test value defined in OnContextCreated + EXPECT_TRUE(context->Eval( + "document.getElementById('f').contentWindow.v8_context_entered_test()", + retval, exception)); + if (exception.get()) + ADD_FAILURE() << exception->GetMessage().c_str(); + + EXPECT_TRUE(retval.get()); + EXPECT_TRUE(retval->IsInt()); + EXPECT_EQ(21, retval->GetIntValue()); + + DestroyTest(); + } + + void RunBindingTest() { + CefRefPtr context = GetContext(); + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr object = context->GetGlobal(); + EXPECT_TRUE(object.get()); + + // Test value defined in OnContextCreated + CefRefPtr value = object->GetValue("v8_binding_test"); + EXPECT_TRUE(value.get()); + EXPECT_TRUE(value->IsInt()); + EXPECT_EQ(12, value->GetIntValue()); + + // Exit the V8 context. + EXPECT_TRUE(context->Exit()); + + DestroyTest(); + } + + virtual void OnLoadEnd(CefRefPtr browser, + CefRefPtr frame, + int httpStatusCode) OVERRIDE { + if (frame->IsMain()) + RunTest(test_mode_); + } + + virtual void OnContextCreated(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr context) OVERRIDE { + std::string url = frame->GetURL(); + if (url == kV8ContextChildTestUrl) { + // For V8TEST_CONTEXT_ENTERED + class Handler : public CefV8Handler { + public: + Handler() {} + virtual bool Execute(const CefString& name, + CefRefPtr object, + const CefV8ValueList& arguments, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + // context for the sub-frame + CefRefPtr context = CefV8Context::GetCurrentContext(); + EXPECT_TRUE(context.get()); + + // entered context should be the same as the main frame context + CefRefPtr entered = CefV8Context::GetEnteredContext(); + EXPECT_TRUE(entered.get()); + EXPECT_TRUE(entered->IsSame(context_)); + + context_ = NULL; + retval = CefV8Value::CreateInt(21); + return true; + } + + CefRefPtr context_; + IMPLEMENT_REFCOUNTING(Handler); + }; + + Handler* handler = new Handler; + CefRefPtr handlerPtr(handler); + + // main frame context + handler->context_ = GetContext(); + + // Function that will be called from the parent frame context. + CefRefPtr func = + CefV8Value::CreateFunction("v8_context_entered_test", handler); + EXPECT_TRUE(func.get()); + + CefRefPtr object = context->GetGlobal(); + EXPECT_TRUE(object.get()); + EXPECT_TRUE(object->SetValue("v8_context_entered_test", func, + V8_PROPERTY_ATTRIBUTE_NONE)); + } else if (url == kV8BindingTestUrl) { + // For V8TEST_BINDING + CefRefPtr object = context->GetGlobal(); + EXPECT_TRUE(object.get()); + EXPECT_TRUE(object->SetValue("v8_binding_test", + CefV8Value::CreateInt(12), + V8_PROPERTY_ATTRIBUTE_NONE)); + } + } + + // Return the V8 context. + CefRefPtr GetContext() { + CefRefPtr context = + GetBrowser()->GetMainFrame()->GetV8Context(); + EXPECT_TRUE(context.get()); + return context; + } + + V8TestMode test_mode_; + const char* test_url_; +}; + +} // namespace + + +// Helpers for defining V8 tests. +#define V8_TEST_EX(name, test_mode, test_url) \ + TEST(V8Test, name) { \ + CefRefPtr handler = \ + new V8TestHandler(test_mode, test_url); \ + handler->ExecuteTest(); \ + } + +#define V8_TEST(name, test_mode) \ + V8_TEST_EX(name, test_mode, kV8TestUrl) + + +// Define the tests. +V8_TEST(NullCreate, V8TEST_NULL_CREATE); +V8_TEST(BoolCreate, V8TEST_BOOL_CREATE); +V8_TEST(IntCreate, V8TEST_INT_CREATE); +V8_TEST(UIntCreate, V8TEST_UINT_CREATE); +V8_TEST(DoubleCreate, V8TEST_DOUBLE_CREATE); +V8_TEST(DateCreate, V8TEST_DATE_CREATE); +V8_TEST(StringCreate, V8TEST_STRING_CREATE); +V8_TEST(ArrayCreate, V8TEST_ARRAY_CREATE); +V8_TEST(ArrayValue, V8TEST_ARRAY_VALUE); +V8_TEST(ObjectCreate, V8TEST_OBJECT_CREATE); +V8_TEST(ObjectUserData, V8TEST_OBJECT_USERDATA); +V8_TEST(ObjectAccessor, V8TEST_OBJECT_ACCESSOR); +V8_TEST(ObjectAccessorException, V8TEST_OBJECT_ACCESSOR_EXCEPTION); +V8_TEST(ObjectAccessorFail, V8TEST_OBJECT_ACCESSOR_FAIL); +V8_TEST(ObjectAccessorReadOnly, V8TEST_OBJECT_ACCESSOR_READONLY); +V8_TEST(ObjectValue, V8TEST_OBJECT_VALUE); +V8_TEST(ObjectValueReadOnly, V8TEST_OBJECT_VALUE_READONLY); +V8_TEST(ObjectValueEnum, V8TEST_OBJECT_VALUE_ENUM); +V8_TEST(ObjectValueDontEnum, V8TEST_OBJECT_VALUE_DONTENUM); +V8_TEST(ObjectValueDelete, V8TEST_OBJECT_VALUE_DELETE); +V8_TEST(ObjectValueDontDelete, V8TEST_OBJECT_VALUE_DONTDELETE); +V8_TEST(FunctionCreate, V8TEST_FUNCTION_CREATE); +V8_TEST(FunctionHandler, V8TEST_FUNCTION_HANDLER); +V8_TEST(FunctionHandlerException, V8TEST_FUNCTION_HANDLER_EXCEPTION); +V8_TEST(FunctionHandlerFail, V8TEST_FUNCTION_HANDLER_FAIL); +V8_TEST(FunctionHandlerNoObject, V8TEST_FUNCTION_HANDLER_NO_OBJECT); +V8_TEST(FunctionHandlerWithContext, V8TEST_FUNCTION_HANDLER_WITH_CONTEXT); +V8_TEST(ContextEval, V8TEST_CONTEXT_EVAL); +V8_TEST(ContextEvalException, V8TEST_CONTEXT_EVAL_EXCEPTION); +V8_TEST_EX(ContextEntered, V8TEST_CONTEXT_ENTERED, NULL); +V8_TEST_EX(Binding, V8TEST_BINDING, kV8BindingTestUrl); + + +namespace { + +// ExternalMemoryAllocation test handler. +class V8ExternalMemTestHandler : public TestHandler { + public: + explicit V8ExternalMemTestHandler(const std::string& code) { html_ = ""; @@ -76,8 +1595,7 @@ TEST(V8Test, ExternalMemoryAllocation) { CefString& exception) { static const int kTestSize = 999999999; if (name == "createObject") { - retval = CefV8Value::CreateObject( - CefRefPtr(), CefRefPtr()); + retval = CefV8Value::CreateObject(CefRefPtr()); object_created_ = (retval->AdjustExternallyAllocatedMemory(kTestSize) == kTestSize); return true; @@ -96,7 +1614,7 @@ TEST(V8Test, ExternalMemoryAllocation) { Test* test = new Test(); CefRegisterExtension("v8/externalMemory", test->GetExtensionCode(), test); - V8TestHandler* test_handler = new V8TestHandler(test->GetTestCode()); + V8ExternalMemTestHandler* test_handler = new V8ExternalMemTestHandler(test->GetTestCode()); test_handler->ExecuteTest(); ASSERT_TRUE(test->object_created_); diff --git a/cef1/tests/unittests/v8_unittest_legacy.cc b/cef1/tests/unittests/v8_unittest_legacy.cc deleted file mode 100644 index 3ed2f8543..000000000 --- a/cef1/tests/unittests/v8_unittest_legacy.cc +++ /dev/null @@ -1,1729 +0,0 @@ -// Copyright (c) 2012 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. -// -// NOTE: DO NOT ADD NEW TESTS TO THIS FILE. USE v8_unittest.cc INSTEAD. -// http://code.google.com/p/chromiumembedded/issues/detail?id=480 - -#include "include/cef_runnable.h" -#include "include/cef_v8.h" -#include "tests/unittests/test_handler.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -bool g_V8TestV8HandlerExecuteCalled; -bool g_V8TestV8HandlerExecute2Called; - -class V8TestV8Handler : public CefV8Handler { - public: - explicit V8TestV8Handler(bool bindingTest) { binding_test_ = bindingTest; } - - virtual bool Execute(const CefString& name, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefString& exception) { - TestExecute(name, object, arguments, retval, exception); - return true; - } - - void TestExecute(const CefString& name, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefString& exception) { - if (name == "execute") { - g_V8TestV8HandlerExecuteCalled = true; - - ASSERT_EQ((size_t)9, arguments.size()); - int argct = 0; - - // basic types - ASSERT_TRUE(arguments[argct]->IsInt()); - ASSERT_EQ(5, arguments[argct]->GetIntValue()); - argct++; - - ASSERT_TRUE(arguments[argct]->IsDouble()); - ASSERT_EQ(6.543, arguments[argct]->GetDoubleValue()); - argct++; - - ASSERT_TRUE(arguments[argct]->IsBool()); - ASSERT_EQ(true, arguments[argct]->GetBoolValue()); - argct++; - - ASSERT_TRUE(arguments[argct]->IsDate()); - CefTime date = arguments[argct]->GetDateValue(); - ASSERT_EQ(date.year, 2010); - ASSERT_EQ(date.month, 5); - ASSERT_EQ(date.day_of_month, 3); -#if !defined(OS_MACOSX) - ASSERT_EQ(date.day_of_week, 1); -#endif - ASSERT_EQ(date.hour, 12); - ASSERT_EQ(date.minute, 30); - ASSERT_EQ(date.second, 10); - ASSERT_NEAR(date.millisecond, 100, 1); - argct++; - - ASSERT_TRUE(arguments[argct]->IsString()); - ASSERT_EQ(arguments[argct]->GetStringValue(), "test string"); - argct++; - - CefRefPtr value; - - // array - ASSERT_TRUE(arguments[argct]->IsArray()); - ASSERT_EQ(4, arguments[argct]->GetArrayLength()); - { - int subargct = 0; - value = arguments[argct]->GetValue(subargct); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsInt()); - ASSERT_EQ(7, value->GetIntValue()); - subargct++; - - value = arguments[argct]->GetValue(subargct); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsDouble()); - ASSERT_EQ(5.432, value->GetDoubleValue()); - subargct++; - - value = arguments[argct]->GetValue(subargct); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsBool()); - ASSERT_FALSE(value->GetBoolValue()); - subargct++; - - value = arguments[argct]->GetValue(subargct); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsString()); - ASSERT_EQ(value->GetStringValue(), "another string"); - subargct++; - } - argct++; - - // object - ASSERT_TRUE(arguments[argct]->IsObject()); - { - value = arguments[argct]->GetValue("arg0"); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsInt()); - ASSERT_EQ(2, value->GetIntValue()); - - value = arguments[argct]->GetValue("arg1"); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsDouble()); - ASSERT_EQ(3.433, value->GetDoubleValue()); - - value = arguments[argct]->GetValue("arg2"); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsBool()); - ASSERT_EQ(true, value->GetBoolValue()); - - value = arguments[argct]->GetValue("arg3"); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsString()); - ASSERT_EQ(value->GetStringValue(), "some string"); - } - argct++; - - // function that returns a value - ASSERT_TRUE(arguments[argct]->IsFunction()); - { - CefV8ValueList args; - args.push_back(CefV8Value::CreateInt(5)); - args.push_back(CefV8Value::CreateDouble(3.5)); - args.push_back(CefV8Value::CreateBool(true)); - args.push_back(CefV8Value::CreateString("10")); - CefRefPtr rv; - CefRefPtr exception; - ASSERT_TRUE(arguments[argct]->ExecuteFunction( - arguments[argct], args, rv, exception, false)); - ASSERT_TRUE(rv.get() != NULL); - ASSERT_TRUE(rv->IsDouble()); - ASSERT_EQ(19.5, rv->GetDoubleValue()); - } - argct++; - - // function that throws an exception - ASSERT_TRUE(arguments[argct]->IsFunction()); - { - CefV8ValueList args; - args.push_back(CefV8Value::CreateDouble(5)); - args.push_back(CefV8Value::CreateDouble(0)); - CefRefPtr rv; - CefRefPtr exception; - ASSERT_TRUE(arguments[argct]->ExecuteFunction( - arguments[argct], args, rv, exception, false)); - ASSERT_TRUE(exception.get()); - ASSERT_EQ(exception->GetMessage(), "Uncaught My Exception"); - } - argct++; - - if (binding_test_) { - // values - value = object->GetValue("intVal"); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsInt()); - ASSERT_EQ(12, value->GetIntValue()); - - value = object->GetValue("doubleVal"); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsDouble()); - ASSERT_EQ(5.432, value->GetDoubleValue()); - - value = object->GetValue("boolVal"); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsBool()); - ASSERT_EQ(true, value->GetBoolValue()); - - value = object->GetValue("stringVal"); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsString()); - ASSERT_EQ(value->GetStringValue(), "the string"); - - value = object->GetValue("dateVal"); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsDate()); - CefTime date = value->GetDateValue(); - ASSERT_EQ(date.year, 2010); - ASSERT_EQ(date.month, 5); -#if !defined(OS_MACOSX) - ASSERT_EQ(date.day_of_week, 1); -#endif - ASSERT_EQ(date.day_of_month, 3); - ASSERT_EQ(date.hour, 12); - ASSERT_EQ(date.minute, 30); - ASSERT_EQ(date.second, 10); - ASSERT_NEAR(date.millisecond, 100, 1); - - value = object->GetValue("arrayVal"); - ASSERT_TRUE(value.get() != NULL); - ASSERT_TRUE(value->IsArray()); - { - CefRefPtr value2; - int subargct = 0; - value2 = value->GetValue(subargct); - ASSERT_TRUE(value2.get() != NULL); - ASSERT_TRUE(value2->IsInt()); - ASSERT_EQ(4, value2->GetIntValue()); - subargct++; - - value2 = value->GetValue(subargct); - ASSERT_TRUE(value2.get() != NULL); - ASSERT_TRUE(value2->IsDouble()); - ASSERT_EQ(120.43, value2->GetDoubleValue()); - subargct++; - - value2 = value->GetValue(subargct); - ASSERT_TRUE(value2.get() != NULL); - ASSERT_TRUE(value2->IsBool()); - ASSERT_EQ(true, value2->GetBoolValue()); - subargct++; - - value2 = value->GetValue(subargct); - ASSERT_TRUE(value2.get() != NULL); - ASSERT_TRUE(value2->IsString()); - ASSERT_EQ(value2->GetStringValue(), "a string"); - subargct++; - } - } - - retval = CefV8Value::CreateInt(5); - } else if (name == "execute2") { - g_V8TestV8HandlerExecute2Called = true; - - // check the result of calling the "execute" function - ASSERT_EQ((size_t)1, arguments.size()); - ASSERT_TRUE(arguments[0]->IsInt()); - ASSERT_EQ(5, arguments[0]->GetIntValue()); - } - } - - bool binding_test_; - - IMPLEMENT_REFCOUNTING(V8TestV8Handler); -}; - -class V8TestHandler : public TestHandler { - public: - explicit V8TestHandler(bool bindingTest) { binding_test_ = bindingTest; } - - virtual void RunTest() OVERRIDE { - std::string object; - if (binding_test_) { - // binding uses the window object - object = "window.test"; - } else { - // extension uses a global object - object = "test"; - } - - std::stringstream testHtml; - testHtml << - "" - "" - ""; - - AddResource("http://tests/run.html", testHtml.str(), "text/html"); - CreateBrowser("http://tests/run.html"); - } - - virtual void OnLoadEnd(CefRefPtr browser, - CefRefPtr frame, - int httpStatusCode) OVERRIDE { - if (!browser->IsPopup() && frame->IsMain()) - DestroyTest(); - } - - virtual void OnContextCreated(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr context) OVERRIDE { - if (binding_test_) - TestHandleJSBinding(browser, frame, context->GetGlobal()); - } - - void TestHandleJSBinding(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr object) { - // Create the new V8 object - CefRefPtr testObj = CefV8Value::CreateObject(NULL, NULL); - ASSERT_TRUE(testObj.get() != NULL); - ASSERT_TRUE(object->SetValue("test", testObj, V8_PROPERTY_ATTRIBUTE_NONE)); - - // Create an instance of V8ExecuteV8Handler - CefRefPtr testHandler(new V8TestV8Handler(true)); - ASSERT_TRUE(testHandler.get() != NULL); - - // Add the functions - CefRefPtr testFunc; - testFunc = CefV8Value::CreateFunction("execute", testHandler); - ASSERT_TRUE(testFunc.get() != NULL); - ASSERT_TRUE(testObj->SetValue("execute", testFunc, - V8_PROPERTY_ATTRIBUTE_NONE)); - testFunc = CefV8Value::CreateFunction("execute2", testHandler); - ASSERT_TRUE(testFunc.get() != NULL); - ASSERT_TRUE(testObj->SetValue("execute2", testFunc, - V8_PROPERTY_ATTRIBUTE_NONE)); - - // Add the values - ASSERT_TRUE(testObj->SetValue("intVal", - CefV8Value::CreateInt(12), V8_PROPERTY_ATTRIBUTE_NONE)); - ASSERT_TRUE(testObj->SetValue("doubleVal", - CefV8Value::CreateDouble(5.432), V8_PROPERTY_ATTRIBUTE_NONE)); - ASSERT_TRUE(testObj->SetValue("boolVal", - CefV8Value::CreateBool(true), V8_PROPERTY_ATTRIBUTE_NONE)); - ASSERT_TRUE(testObj->SetValue("stringVal", - CefV8Value::CreateString("the string"), V8_PROPERTY_ATTRIBUTE_NONE)); - - cef_time_t date = { - 2010, - 5, -#if !defined(OS_MACOSX) - 1, -#endif - 3, - 12, - 30, - 10, - 100 - }; - ASSERT_TRUE(testObj->SetValue("dateVal", CefV8Value::CreateDate(date), - V8_PROPERTY_ATTRIBUTE_NONE)); - - CefRefPtr testArray(CefV8Value::CreateArray()); - ASSERT_TRUE(testArray.get() != NULL); - ASSERT_TRUE(testObj->SetValue("arrayVal", testArray, - V8_PROPERTY_ATTRIBUTE_NONE)); - ASSERT_TRUE(testArray->SetValue(0, CefV8Value::CreateInt(4))); - ASSERT_TRUE(testArray->SetValue(1, CefV8Value::CreateDouble(120.43))); - ASSERT_TRUE(testArray->SetValue(2, CefV8Value::CreateBool(true))); - ASSERT_TRUE(testArray->SetValue(3, CefV8Value::CreateString("a string"))); - } - - bool binding_test_; -}; - -} // namespace - -// Verify window binding -TEST(V8Test, Binding) { - g_V8TestV8HandlerExecuteCalled = false; - g_V8TestV8HandlerExecute2Called = false; - - CefRefPtr handler = new V8TestHandler(true); - handler->ExecuteTest(); - - ASSERT_TRUE(g_V8TestV8HandlerExecuteCalled); - ASSERT_TRUE(g_V8TestV8HandlerExecute2Called); -} - -// Verify extensions -TEST(V8Test, Extension) { - g_V8TestV8HandlerExecuteCalled = false; - g_V8TestV8HandlerExecute2Called = false; - - std::string extensionCode = - "var test;" - "if (!test)" - " test = {};" - "(function() {" - " test.execute = function(a,b,c,d,e,f,g,h,i) {" - " native function execute();" - " return execute(a,b,c,d,e,f,g,h,i);" - " };" - " test.execute2 = function(a) {" - " native function execute2();" - " return execute2(a);" - " };" - "})();"; - CefRegisterExtension("v8/test", extensionCode, new V8TestV8Handler(false)); - - CefRefPtr handler = new V8TestHandler(false); - handler->ExecuteTest(); - - ASSERT_TRUE(g_V8TestV8HandlerExecuteCalled); - ASSERT_TRUE(g_V8TestV8HandlerExecute2Called); -} - -namespace { - -class TestNoNativeHandler : public TestHandler { - public: - class TestHandler : public CefV8Handler { - public: - explicit TestHandler(CefRefPtr test) - : test_(test) { - } - - virtual bool Execute(const CefString& name, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefString& exception) OVERRIDE { - if (name == "result") { - if (arguments.size() == 1 && arguments[0]->IsString()) { - std::string value = arguments[0]->GetStringValue(); - if (value == "correct") - test_->got_correct_.yes(); - else - return false; - return true; - } - } - - return false; - } - - CefRefPtr test_; - - IMPLEMENT_REFCOUNTING(TestHandler); - }; - - TestNoNativeHandler() { - } - - virtual void RunTest() OVERRIDE { - std::string testHtml = - "\n" - "\n" - ""; - AddResource("http://tests/run.html", testHtml, "text/html"); - - CreateBrowser("http://tests/run.html"); - } - - virtual void OnLoadEnd(CefRefPtr browser, - CefRefPtr frame, - int httpStatusCode) OVERRIDE { - DestroyTest(); - } - - virtual void OnContextCreated(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr context) OVERRIDE { - // Retrieve the 'window' object. - CefRefPtr object = context->GetGlobal(); - - // Create the functions that will be used during the test. - CefRefPtr obj = CefV8Value::CreateObject(NULL, NULL); - CefRefPtr handler = new TestHandler(this); - obj->SetValue("result", - CefV8Value::CreateFunction("result", handler), - V8_PROPERTY_ATTRIBUTE_NONE); - object->SetValue("test", obj, V8_PROPERTY_ATTRIBUTE_NONE); - } - - TrackCallback got_correct_; -}; - -} // namespace - -// Verify extensions with no native functions -TEST(V8Test, ExtensionNoNative) { - std::string extensionCode = - "var test_nonative;" - "if (!test_nonative)" - " test_nonative = {};" - "(function() {" - " test_nonative.add = function(a, b) {" - " return a + b;" - " };" - "})();"; - CefRegisterExtension("v8/test_nonative", extensionCode, NULL); - - CefRefPtr handler = new TestNoNativeHandler(); - handler->ExecuteTest(); - - EXPECT_TRUE(handler->got_correct_); -} - -namespace { - -// Using a delegate so that the code below can remain inline. -class CefV8HandlerDelegate { - public: - virtual ~CefV8HandlerDelegate() {} - virtual bool Execute(const CefString& name, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefString& exception) = 0; - - virtual bool Get(const CefString& name, - const CefRefPtr object, - CefRefPtr& retval, - CefString& exception) = 0; - - virtual bool Set(const CefString& name, - const CefRefPtr object, - const CefRefPtr value, - CefString& exception) = 0; -}; - -class DelegatingV8Handler : public CefV8Handler { - public: - explicit DelegatingV8Handler(CefV8HandlerDelegate *delegate) - : delegate_(delegate) {} - - ~DelegatingV8Handler() { - } - - bool Execute(const CefString& name, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefString& exception) OVERRIDE { - return delegate_->Execute(name, object, arguments, retval, exception); - } - - private: - CefV8HandlerDelegate* delegate_; - - IMPLEMENT_REFCOUNTING(DelegatingV8Handler); -}; - -class DelegatingV8Accessor: public CefV8Accessor { - public: - explicit DelegatingV8Accessor(CefV8HandlerDelegate *delegate) - : delegate_(delegate) { } - - bool Get(const CefString& name, - const CefRefPtr object, - CefRefPtr& retval, - CefString& exception) OVERRIDE { - return delegate_->Get(name, object, retval, exception); - } - - bool Set(const CefString& name, - const CefRefPtr object, - const CefRefPtr value, - CefString& exception) OVERRIDE { - return delegate_->Set(name, object, value, exception); - } - - private: - CefV8HandlerDelegate* delegate_; - - IMPLEMENT_REFCOUNTING(DelegatingV8Accessor); -}; - -class TestContextHandler: public TestHandler, public CefV8HandlerDelegate { - public: - TestContextHandler() {} - - virtual void RunTest() OVERRIDE { - // Test Flow: - // load main.html. - // 1. main.html calls hello("main", callIFrame) in the execute handler. - // The excute handler checks that "main" was called and saves - // the callIFrame function, context, and receiver object. - // 2. iframe.html calls hello("iframe") in the execute handler. - // The execute handler checks that "iframe" was called. if both main - // and iframe were called, it calls CallIFrame() - // 3. CallIFrame calls "callIFrame" in main.html - // 4. which calls iframe.html "calledFromMain()". - // 5. which calls "fromIFrame()" in execute handler. - // The execute handler checks that the entered and current urls are - // what we expect: "main.html" and "iframe.html", respectively - // 6. It then posts a task to call AsyncTestContext - // you can validate the entered and current context are still the - // same here, but it is not checked by this test case. - // 7. AsyncTestContext tests to make sure that no context is set at - // this point and loads "begin.html" - // 8. begin.html calls "begin(func1, func2)" in the execute handler - // The execute handler posts a tasks to call both of those functions - // when no context is defined. Both should work with the specified - // context. AsyncTestException should run first, followed by - // AsyncTestNavigate() which calls the func2 to do a document.location - // based loading of "end.html". - // 9. end.html calls "end()" in the execute handler. - // which concludes the test. - - y_ = 0; - - std::stringstream mainHtml; - mainHtml << - "" - "

Hello From Main Frame

" - "" - "" - ""; - - AddResource("http://tests/main.html", mainHtml.str(), "text/html"); - - std::stringstream iframeHtml; - iframeHtml << - "" - "

Hello From IFRAME

" - "" - ""; - - AddResource("http://tests/iframe.html", iframeHtml.str(), "text/html"); - - std::stringstream beginHtml; - beginHtml << - "" - "

V8 Context Test

" - "" - ""; - - AddResource("http://tests/begin.html", beginHtml.str(), "text/html"); - - std::stringstream endHtml; - endHtml << - "" - "

Navigation Succeeded!

" - "" - ""; - - AddResource("http://tests/end.html", endHtml.str(), "text/html"); - - CreateBrowser("http://tests/main.html"); - } - - virtual void OnLoadEnd(CefRefPtr browser, - CefRefPtr frame, - int httpStatusCode) OVERRIDE { - } - - virtual void OnContextCreated(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr context) OVERRIDE { - // Retrieve the 'window' object. - CefRefPtr object = context->GetGlobal(); - - CefRefPtr cc = CefV8Context::GetCurrentContext(); - CefRefPtr currentBrowser = cc->GetBrowser(); - CefRefPtr currentFrame = cc->GetFrame(); - CefString currentURL = currentFrame->GetURL(); - - CefRefPtr ec = CefV8Context::GetEnteredContext(); - CefRefPtr enteredBrowser = ec->GetBrowser(); - CefRefPtr enteredFrame = ec->GetFrame(); - CefString enteredURL = enteredFrame->GetURL(); - - CefRefPtr funcHandler(new DelegatingV8Handler(this)); - CefRefPtr helloFunc = - CefV8Value::CreateFunction("hello", funcHandler); - object->SetValue("hello", helloFunc, V8_PROPERTY_ATTRIBUTE_NONE); - - CefRefPtr fromIFrameFunc = - CefV8Value::CreateFunction("fromIFrame", funcHandler); - object->SetValue("fromIFrame", fromIFrameFunc, V8_PROPERTY_ATTRIBUTE_NONE); - - CefRefPtr goFunc = - CefV8Value::CreateFunction("begin", funcHandler); - object->SetValue("begin", goFunc, V8_PROPERTY_ATTRIBUTE_NONE); - - CefRefPtr doneFunc = - CefV8Value::CreateFunction("end", funcHandler); - object->SetValue("end", doneFunc, V8_PROPERTY_ATTRIBUTE_NONE); - - CefRefPtr compFunc = - CefV8Value::CreateFunction("comp", funcHandler); - object->SetValue("comp", compFunc, V8_PROPERTY_ATTRIBUTE_NONE); - - // Used for testing exceptions returned from accessors. - CefRefPtr gotGetExceptionFunc = - CefV8Value::CreateFunction("gotGetException", funcHandler); - object->SetValue("gotGetException", gotGetExceptionFunc, - V8_PROPERTY_ATTRIBUTE_NONE); - CefRefPtr gotSetExceptionFunc = - CefV8Value::CreateFunction("gotSetException", funcHandler); - object->SetValue("gotSetException", gotSetExceptionFunc, - V8_PROPERTY_ATTRIBUTE_NONE); - - // Create an object with accessor based properties: - CefRefPtr blankBase; - CefRefPtr accessor(new DelegatingV8Accessor(this)); - CefRefPtr point = CefV8Value::CreateObject(blankBase, accessor); - - point->SetValue("x", V8_ACCESS_CONTROL_DEFAULT, - V8_PROPERTY_ATTRIBUTE_READONLY); - point->SetValue("y", V8_ACCESS_CONTROL_DEFAULT, - V8_PROPERTY_ATTRIBUTE_NONE); - - object->SetValue("point", point, V8_PROPERTY_ATTRIBUTE_NONE); - - // Create another object with accessor based properties: - CefRefPtr exceptObj = - CefV8Value::CreateObject(NULL, new DelegatingV8Accessor(this)); - - exceptObj->SetValue("makeException", V8_ACCESS_CONTROL_DEFAULT, - V8_PROPERTY_ATTRIBUTE_NONE); - - object->SetValue("exceptObj", exceptObj, V8_PROPERTY_ATTRIBUTE_NONE); - } - - void CallIFrame() { - CefV8ValueList args; - CefRefPtr rv; - CefRefPtr exception; - CefRefPtr empty; - ASSERT_TRUE(funcIFrame_->ExecuteFunctionWithContext(contextIFrame_, empty, - args, rv, exception, - false)); - } - - void AsyncTestContext(CefRefPtr ec, - CefRefPtr cc) { - // we should not be in a context in this call. - CefRefPtr noContext = CefV8Context::GetCurrentContext(); - if (!noContext.get()) - got_no_context_.yes(); - - CefRefPtr enteredBrowser = ec->GetBrowser(); - CefRefPtr enteredFrame = ec->GetFrame(); - CefString enteredURL = enteredFrame->GetURL(); - CefString enteredName = enteredFrame->GetName(); - CefRefPtr enteredMainFrame = enteredBrowser->GetMainFrame(); - CefString enteredMainURL = enteredMainFrame->GetURL(); - CefString enteredMainName = enteredMainFrame->GetName(); - - CefRefPtr currentBrowser = cc->GetBrowser(); - CefRefPtr currentFrame = cc->GetFrame(); - CefString currentURL = currentFrame->GetURL(); - CefString currentName = currentFrame->GetName(); - CefRefPtr currentMainFrame = currentBrowser->GetMainFrame(); - CefString currentMainURL = currentMainFrame->GetURL(); - CefString currentMainName = currentMainFrame->GetName(); - - CefRefPtr copyFromMainFrame = - currentMainFrame->GetBrowser(); - - currentMainFrame->LoadURL("http://tests/begin.html"); - } - - void AsyncTestException(CefRefPtr context, - CefRefPtr func) { - CefV8ValueList args; - CefRefPtr rv; - CefRefPtr exception; - CefRefPtr empty; - ASSERT_TRUE(func->ExecuteFunctionWithContext(context, empty, args, rv, - exception, false)); - if (exception.get() && exception->GetMessage() == "Uncaught My Exception") - got_exception_.yes(); - } - - void AsyncTestNavigation(CefRefPtr context, - CefRefPtr func) { - CefRefPtr exception; - CefV8ValueList args; - CefRefPtr rv, obj, url; - - // Need to enter the context in order to create an Object, - // Array, or Function. Simple types like String, Int, - // Boolean, and Double don't require you to be in the - // context before creating them. - if ( context->Enter() ) { - CefRefPtr global = context->GetGlobal(); - CefRefPtr anArray = CefV8Value::CreateArray(); - CefRefPtr funcHandler(new DelegatingV8Handler(this)); - CefRefPtr foobarFunc = - CefV8Value::CreateFunction("foobar", funcHandler); - - obj = CefV8Value::CreateObject(NULL, NULL); - url = CefV8Value::CreateString("http://tests/end.html"); - - obj->SetValue("url", url, V8_PROPERTY_ATTRIBUTE_NONE); - obj->SetValue("foobar", foobarFunc, V8_PROPERTY_ATTRIBUTE_NONE); - obj->SetValue("anArray", anArray, V8_PROPERTY_ATTRIBUTE_NONE); - - args.push_back(obj); - - ASSERT_TRUE(func->ExecuteFunctionWithContext(context, global, args, rv, - exception, false)); - if (!exception.get()) - got_navigation_.yes(); - - context->Exit(); - } - } - - bool Execute(const CefString& name, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefString& exception) OVERRIDE { - CefRefPtr cc = CefV8Context::GetCurrentContext(); - CefRefPtr ec = CefV8Context::GetEnteredContext(); - - CefRefPtr enteredBrowser = ec->GetBrowser(); - CefRefPtr enteredFrame = ec->GetFrame(); - CefString enteredURL = enteredFrame->GetURL(); - CefString enteredName = enteredFrame->GetName(); - CefRefPtr enteredMainFrame = enteredBrowser->GetMainFrame(); - CefString enteredMainURL = enteredMainFrame->GetURL(); - CefString enteredMainName = enteredMainFrame->GetName(); - - CefRefPtr currentBrowser = cc->GetBrowser(); - CefRefPtr currentFrame = cc->GetFrame(); - CefString currentURL = currentFrame->GetURL(); - CefString currentName = currentFrame->GetName(); - CefRefPtr currentMainFrame = currentBrowser->GetMainFrame(); - CefString currentMainURL = currentMainFrame->GetURL(); - CefString currentMainName = currentMainFrame->GetName(); - - if (name == "hello") { - if (arguments.size() == 2 && arguments[0]->IsString() && - arguments[1]->IsFunction()) { - CefString msg = arguments[0]->GetStringValue(); - if (msg == "main") { - got_hello_main_.yes(); - contextIFrame_ = cc; - funcIFrame_ = arguments[1]; - } - } else if (arguments.size() == 1 && arguments[0]->IsString()) { - CefString msg = arguments[0]->GetStringValue(); - if (msg == "iframe") - got_hello_iframe_.yes(); - } else { - return false; - } - - if (got_hello_main_ && got_hello_iframe_ && funcIFrame_->IsFunction()) { - // NB: At this point, enteredURL == http://tests/iframe.html which is - // expected since the iframe made the call on its own. The unexpected - // behavior is that in the call to fromIFrame (below) the enteredURL - // == http://tests/main.html even though the iframe.html context was - // entered first. - // -- Perhaps WebKit does something other than look at the bottom - // of stack for the entered context. - if (enteredURL == "http://tests/iframe.html") - got_iframe_as_entered_url_.yes(); - CallIFrame(); - } - return true; - } else if (name == "fromIFrame") { - if (enteredURL == "http://tests/main.html") - got_correct_entered_url_.yes(); - if (currentURL == "http://tests/iframe.html") - got_correct_current_url_.yes(); - CefPostTask(TID_UI, NewCefRunnableMethod(this, - &TestContextHandler::AsyncTestContext, ec, cc)); - return true; - } else if (name == "begin") { - if (arguments.size() == 2 && arguments[0]->IsFunction() && - arguments[1]->IsFunction()) { - CefRefPtr funcException = arguments[0]; - CefRefPtr funcNavigate = arguments[1]; - CefPostTask(TID_UI, NewCefRunnableMethod(this, - &TestContextHandler::AsyncTestException, cc, funcException)); - CefPostTask(TID_UI, NewCefRunnableMethod(this, - &TestContextHandler::AsyncTestNavigation, cc, funcNavigate)); - return true; - } - } else if (name == "comp") { - if (arguments.size() == 3) { - CefRefPtr expected = arguments[0]; - CefRefPtr one = arguments[1]; - CefRefPtr two = arguments[2]; - - bool bExpected = expected->GetBoolValue(); - bool bOne2Two = one->IsSame(two); - bool bTwo2One = two->IsSame(one); - - // IsSame should match the expected - if ( bExpected != bOne2Two || bExpected != bTwo2One) - got_bad_is_same_.yes(); - } else { - got_bad_is_same_.yes(); - } - } else if (name == "end") { - got_testcomplete_.yes(); - DestroyTest(); - return true; - } else if (name == "gotGetException") { - if (arguments.size() == 1 && - arguments[0]->GetStringValue() == "Error: My Get Exception") { - got_getexception_.yes(); - } - return true; - } else if (name == "gotSetException") { - if (arguments.size() == 1 && - arguments[0]->GetStringValue() == "Error: My Set Exception") { - got_setexception_.yes(); - } - return true; - } - return false; - } - - bool Get(const CefString& name, - const CefRefPtr object, - CefRefPtr& retval, - CefString& exception) OVERRIDE { - if (name == "x") { - got_point_x_read_.yes(); - retval = CefV8Value::CreateInt(1234); - return true; - } else if (name == "y") { - got_point_y_read_.yes(); - retval = CefV8Value::CreateInt(y_); - return true; - } else if (name == "makeException") { - exception = "My Get Exception"; - return true; - } - return false; - } - - bool Set(const CefString& name, - const CefRefPtr object, - const CefRefPtr value, - CefString& exception) OVERRIDE { - if (name == "y") { - y_ = value->GetIntValue(); - if (y_ == 1234) - got_point_y_write_.yes(); - return true; - } else if (name == "makeException") { - exception = "My Set Exception"; - return true; - } - return false; - } - - // This function we will be called later to make it call into the - // IFRAME, which then calls "fromIFrame" so that we can check the - // entered vs current contexts are working as expected. - CefRefPtr contextIFrame_; - CefRefPtr funcIFrame_; - - TrackCallback got_point_x_read_; - TrackCallback got_point_y_read_; - TrackCallback got_point_y_write_; - TrackCallback got_bad_is_same_; - TrackCallback got_hello_main_; - TrackCallback got_hello_iframe_; - TrackCallback got_correct_entered_url_; - TrackCallback got_correct_current_url_; - TrackCallback got_iframe_as_entered_url_; - TrackCallback got_no_context_; - TrackCallback got_exception_; - TrackCallback got_getexception_; - TrackCallback got_setexception_; - TrackCallback got_navigation_; - TrackCallback got_testcomplete_; - - int y_; -}; - -} // namespace - -// Verify context works to allow async v8 callbacks -TEST(V8Test, Context) { - CefRefPtr handler = new TestContextHandler(); - handler->ExecuteTest(); - - EXPECT_TRUE(handler->got_point_x_read_); - EXPECT_TRUE(handler->got_point_y_read_); - EXPECT_TRUE(handler->got_point_y_write_); - EXPECT_FALSE(handler->got_bad_is_same_); - EXPECT_TRUE(handler->got_hello_main_); - EXPECT_TRUE(handler->got_hello_iframe_); - EXPECT_TRUE(handler->got_no_context_); - EXPECT_TRUE(handler->got_iframe_as_entered_url_); - EXPECT_TRUE(handler->got_correct_entered_url_); - EXPECT_TRUE(handler->got_correct_current_url_); - EXPECT_TRUE(handler->got_exception_); - EXPECT_TRUE(handler->got_getexception_); - EXPECT_TRUE(handler->got_setexception_); - EXPECT_TRUE(handler->got_navigation_); - EXPECT_TRUE(handler->got_testcomplete_); -} - -namespace { - -class TestInternalHandler : public TestHandler { - public: - class UserData : public CefBase { - public: - explicit UserData(CefRefPtr test) - : test_(test) { - } - - void Test(const std::string& name) { - if (name == "obj1-before") { - if (test_->nav_ == 0) - test_->got_userdata_obj1_before_test1_fail_.yes(); - else - test_->got_userdata_obj1_before_test2_fail_.yes(); - } else if (name == "obj2-before") { - if (test_->nav_ == 0) - test_->got_userdata_obj2_before_test1_.yes(); - else - test_->got_userdata_obj2_before_test2_fail_.yes(); - } else if (name == "obj1-after") { - if (test_->nav_ == 0) - test_->got_userdata_obj1_after_test1_fail_.yes(); - else - test_->got_userdata_obj1_after_test2_fail_.yes(); - } else if (name == "obj2-after") { - if (test_->nav_ == 0) - test_->got_userdata_obj2_after_test1_.yes(); - else - test_->got_userdata_obj2_after_test2_fail_.yes(); - } - } - - CefRefPtr test_; - - IMPLEMENT_REFCOUNTING(UserData); - }; - - class Accessor : public CefV8Accessor { - public: - explicit Accessor(CefRefPtr test) - : test_(test) { - } - - virtual bool Get(const CefString& name, - const CefRefPtr object, - CefRefPtr& retval, - CefString& exception) OVERRIDE { - if (test_->nav_ == 0) - test_->got_accessor_get1_.yes(); - else - test_->got_accessor_get2_fail_.yes(); - - retval = CefV8Value::CreateString("default2"); - return true; - } - - virtual bool Set(const CefString& name, - const CefRefPtr object, - const CefRefPtr value, - CefString& exception) OVERRIDE { - if (test_->nav_ == 0) - test_->got_accessor_set1_.yes(); - else - test_->got_accessor_set2_fail_.yes(); - - return true; - } - - CefRefPtr test_; - - IMPLEMENT_REFCOUNTING(Accessor); - }; - - class Handler : public CefV8Handler { - public: - explicit Handler(CefRefPtr test) - : test_(test), - execute_ct_(0) { - } - - virtual bool Execute(const CefString& name, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefString& exception) OVERRIDE { - CefRefPtr handler = - object->GetValue("func")->GetFunctionHandler(); - - if (execute_ct_ == 0) { - if (handler.get() == this) - test_->got_execute1_.yes(); - else - test_->got_execute1_fail_.yes(); - } else { - if (handler.get() == this) - test_->got_execute2_.yes(); - else - test_->got_execute2_fail_.yes(); - } - - execute_ct_++; - - return true; - } - - CefRefPtr test_; - int execute_ct_; - - IMPLEMENT_REFCOUNTING(Accessor); - }; - - class TestHandler : public CefV8Handler { - public: - explicit TestHandler(CefRefPtr test) - : test_(test) { - } - - virtual bool Execute(const CefString& name, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefString& exception) OVERRIDE { - if (name == "store") { - // Store a JSON value. - if (arguments.size() == 2 && arguments[0]->IsString() && - arguments[1]->IsString()) { - std::string name = arguments[0]->GetStringValue(); - std::string val = arguments[1]->GetStringValue(); - if (name == "obj1") { - test_->obj1_json_ = val; - if (val == "{\"value\":\"testval1\",\"value2\":\"default1\"}") - test_->got_obj1_json_.yes(); - } else if (name == "obj2") { - test_->obj2_json_ = val; - if (val == "{\"value\":\"testval2\",\"value2\":\"default2\"}") - test_->got_obj2_json_.yes(); - } else { - return false; - } - retval = CefV8Value::CreateBool(true); - return true; - } - } else if (name == "retrieve") { - // Retrieve a JSON value. - if (arguments.size() == 1 && arguments[0]->IsString()) { - std::string name = arguments[0]->GetStringValue(); - std::string val; - if (name == "obj1") - val = test_->obj1_json_; - else if (name == "obj2") - val = test_->obj2_json_; - if (!val.empty()) { - retval = CefV8Value::CreateString(val); - return true; - } - } - } else if (name == "userdata") { - if (arguments.size() == 2 && arguments[0]->IsString() && - arguments[1]->IsObject()) { - std::string name = arguments[0]->GetStringValue(); - CefRefPtr userData = - reinterpret_cast(arguments[1]->GetUserData().get()); - if (!userData.get()) { - // No UserData object. - if (name == "obj1-before") { - if (test_->nav_ == 0) - test_->got_userdata_obj1_before_null1_.yes(); - else - test_->got_userdata_obj1_before_null2_.yes(); - } else if (name == "obj2-before") { - if (test_->nav_ == 0) - test_->got_userdata_obj2_before_null1_fail_.yes(); - else - test_->got_userdata_obj2_before_null2_.yes(); - } else if (name == "obj1-after") { - if (test_->nav_ == 0) - test_->got_userdata_obj1_after_null1_.yes(); - else - test_->got_userdata_obj1_after_null2_.yes(); - } else if (name == "obj2-after") { - if (test_->nav_ == 0) - test_->got_userdata_obj2_after_null1_fail_.yes(); - else - test_->got_userdata_obj2_after_null2_.yes(); - } - } else { - // Call the test function. - userData->Test(name); - } - return true; - } - } else if (name == "record") { - if (arguments.size() == 1 && arguments[0]->IsString()) { - std::string name = arguments[0]->GetStringValue(); - if (name == "userdata-obj1-set-succeed") { - if (test_->nav_ == 0) - test_->got_userdata_obj1_set_succeed1_.yes(); - else - test_->got_userdata_obj1_set_succeed2_.yes(); - } else if (name == "userdata-obj1-set-except") { - if (test_->nav_ == 0) - test_->got_userdata_obj1_set_except1_fail_.yes(); - else - test_->got_userdata_obj1_set_except2_fail_.yes(); - } else if (name == "userdata-obj2-set-succeed") { - if (test_->nav_ == 0) - test_->got_userdata_obj2_set_succeed1_.yes(); - else - test_->got_userdata_obj2_set_succeed2_.yes(); - } else if (name == "userdata-obj2-set-except") { - if (test_->nav_ == 0) - test_->got_userdata_obj2_set_except1_fail_.yes(); - else - test_->got_userdata_obj2_set_except2_fail_.yes(); - } else if (name == "func-set-succeed") { - test_->got_func_set_succeed_.yes(); - } else if (name == "func-set-except") { - test_->got_func_set_except_fail_.yes(); - } - return true; - } - } - - return false; - } - - CefRefPtr test_; - - IMPLEMENT_REFCOUNTING(TestHandler); - }; - - TestInternalHandler() - : nav_(0) { - } - - virtual void RunTest() OVERRIDE { - std::string tests = - // Test userdata retrieval. - "window.test.userdata('obj1-before', window.obj1);\n" - "window.test.userdata('obj2-before', window.obj2);\n" - // Test accessors. - "window.obj1.value2 = 'newval1';\n" - "window.obj2.value2 = 'newval2';\n" - "val1 = window.obj1.value2;\n" - "val2 = window.obj2.value2;\n" - // Test setting the hidden internal values. - "try { window.obj1['Cef::UserData'] = 1;\n" - "window.obj1['Cef::Accessor'] = 1;\n" - "window.test.record('userdata-obj1-set-succeed'); }\n" - "catch(e) { window.test.record('userdata-obj1-set-except'); }\n" - "try { window.obj2['Cef::UserData'] = 1;\n" - "window.obj2['Cef::Accessor'] = 1;\n" - "window.test.record('userdata-obj2-set-succeed'); }\n" - "catch(e) { window.test.record('userdata-obj2-set-except'); }\n" - // Test userdata retrieval after messing with the internal values. - "window.test.userdata('obj1-after', window.obj1);\n" - "window.test.userdata('obj2-after', window.obj2);\n" - // Test accessors after messing with the internal values. - "window.obj1.value2 = 'newval1';\n" - "window.obj2.value2 = 'newval2';\n" - "val1 = window.obj1.value2;\n" - "val2 = window.obj2.value2;\n"; - - std::stringstream testHtml; - - testHtml << - "\n" - "\n" - ""; - AddResource("http://tests/run1.html", testHtml.str(), "text/html"); - testHtml.str(""); - - testHtml << - "\n" - "\n" - ""; - AddResource("http://tests/run2.html", testHtml.str(), "text/html"); - testHtml.str(""); - - CreateBrowser("http://tests/run1.html"); - } - - virtual void OnLoadEnd(CefRefPtr browser, - CefRefPtr frame, - int httpStatusCode) OVERRIDE { - if (nav_ == 0) { - // Navigate to the next page. - frame->LoadURL("http://tests/run2.html"); - } else { - DestroyTest(); - } - - nav_++; - } - - virtual void OnContextCreated(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr context) OVERRIDE { - // Retrieve the 'window' object. - CefRefPtr object = context->GetGlobal(); - - if (nav_ == 0) { - // Create an object without any internal values. - CefRefPtr obj1 = CefV8Value::CreateObject(NULL, NULL); - obj1->SetValue("value", CefV8Value::CreateString("testval1"), - V8_PROPERTY_ATTRIBUTE_NONE); - obj1->SetValue("value2", CefV8Value::CreateString("default1"), - V8_PROPERTY_ATTRIBUTE_NONE); - object->SetValue("obj1", obj1, V8_PROPERTY_ATTRIBUTE_NONE); - - // Create an object with Cef::Accessor and Cef::UserData internal values. - CefRefPtr obj2 = - CefV8Value::CreateObject(new UserData(this), new Accessor(this)); - obj2->SetValue("value", CefV8Value::CreateString("testval2"), - V8_PROPERTY_ATTRIBUTE_NONE); - obj2->SetValue("value2", V8_ACCESS_CONTROL_DEFAULT, - V8_PROPERTY_ATTRIBUTE_NONE); - object->SetValue("obj2", obj2, V8_PROPERTY_ATTRIBUTE_NONE); - - // Create a function with Cef::Handler internal value. - CefRefPtr func = - CefV8Value::CreateFunction("func", new Handler(this)); - object->SetValue("func", func, V8_PROPERTY_ATTRIBUTE_NONE); - } - - // Used for executing the test. - CefRefPtr handler = new TestHandler(this); - CefRefPtr obj = CefV8Value::CreateObject(NULL, NULL); - obj->SetValue("store", CefV8Value::CreateFunction("store", handler), - V8_PROPERTY_ATTRIBUTE_NONE); - obj->SetValue("retrieve", CefV8Value::CreateFunction("retrieve", handler), - V8_PROPERTY_ATTRIBUTE_NONE); - obj->SetValue("userdata", CefV8Value::CreateFunction("userdata", handler), - V8_PROPERTY_ATTRIBUTE_NONE); - obj->SetValue("record", CefV8Value::CreateFunction("record", handler), - V8_PROPERTY_ATTRIBUTE_NONE); - object->SetValue("test", obj, V8_PROPERTY_ATTRIBUTE_NONE); - } - - int nav_; - std::string obj1_json_, obj2_json_; - - TrackCallback got_obj1_json_; - TrackCallback got_obj2_json_; - - TrackCallback got_userdata_obj1_before_null1_; - TrackCallback got_userdata_obj2_before_null1_fail_; - TrackCallback got_userdata_obj1_before_test1_fail_; - TrackCallback got_userdata_obj2_before_test1_; - TrackCallback got_userdata_obj1_set_succeed1_; - TrackCallback got_userdata_obj1_set_except1_fail_; - TrackCallback got_userdata_obj2_set_succeed1_; - TrackCallback got_userdata_obj2_set_except1_fail_; - TrackCallback got_userdata_obj1_after_null1_; - TrackCallback got_userdata_obj2_after_null1_fail_; - TrackCallback got_userdata_obj1_after_test1_fail_; - TrackCallback got_userdata_obj2_after_test1_; - - TrackCallback got_userdata_obj1_before_null2_; - TrackCallback got_userdata_obj2_before_null2_; - TrackCallback got_userdata_obj1_before_test2_fail_; - TrackCallback got_userdata_obj2_before_test2_fail_; - TrackCallback got_userdata_obj1_set_succeed2_; - TrackCallback got_userdata_obj1_set_except2_fail_; - TrackCallback got_userdata_obj2_set_succeed2_; - TrackCallback got_userdata_obj2_set_except2_fail_; - TrackCallback got_userdata_obj1_after_null2_; - TrackCallback got_userdata_obj2_after_null2_; - TrackCallback got_userdata_obj1_after_test2_fail_; - TrackCallback got_userdata_obj2_after_test2_fail_; - - TrackCallback got_accessor_get1_; - TrackCallback got_accessor_get2_fail_; - TrackCallback got_accessor_set1_; - TrackCallback got_accessor_set2_fail_; - - TrackCallback got_execute1_; - TrackCallback got_execute1_fail_; - TrackCallback got_func_set_succeed_; - TrackCallback got_func_set_except_fail_; - TrackCallback got_execute2_; - TrackCallback got_execute2_fail_; -}; - -} // namespace - -// Test that messing around with CEF internal values doesn't cause crashes. -TEST(V8Test, Internal) { - CefRefPtr handler = new TestInternalHandler(); - handler->ExecuteTest(); - - EXPECT_TRUE(handler->got_obj1_json_.isSet()); - EXPECT_TRUE(handler->got_obj2_json_.isSet()); - - EXPECT_TRUE(handler->got_userdata_obj1_before_null1_.isSet()); - EXPECT_FALSE(handler->got_userdata_obj2_before_null1_fail_.isSet()); - EXPECT_FALSE(handler->got_userdata_obj1_before_test1_fail_.isSet()); - EXPECT_TRUE(handler->got_userdata_obj2_before_test1_.isSet()); - EXPECT_TRUE(handler->got_userdata_obj1_set_succeed1_.isSet()); - EXPECT_FALSE(handler->got_userdata_obj1_set_except1_fail_.isSet()); - EXPECT_TRUE(handler->got_userdata_obj2_set_succeed1_.isSet()); - EXPECT_FALSE(handler->got_userdata_obj2_set_except1_fail_.isSet()); - EXPECT_TRUE(handler->got_userdata_obj1_after_null1_.isSet()); - EXPECT_FALSE(handler->got_userdata_obj2_after_null1_fail_.isSet()); - EXPECT_FALSE(handler->got_userdata_obj1_after_test1_fail_.isSet()); - EXPECT_TRUE(handler->got_userdata_obj2_after_test1_.isSet()); - - EXPECT_TRUE(handler->got_userdata_obj1_before_null2_.isSet()); - EXPECT_TRUE(handler->got_userdata_obj2_before_null2_.isSet()); - EXPECT_FALSE(handler->got_userdata_obj1_before_test2_fail_.isSet()); - EXPECT_FALSE(handler->got_userdata_obj2_before_test2_fail_.isSet()); - EXPECT_TRUE(handler->got_userdata_obj1_set_succeed2_.isSet()); - EXPECT_FALSE(handler->got_userdata_obj1_set_except2_fail_.isSet()); - EXPECT_TRUE(handler->got_userdata_obj2_set_succeed2_.isSet()); - EXPECT_FALSE(handler->got_userdata_obj2_set_except2_fail_.isSet()); - EXPECT_TRUE(handler->got_userdata_obj1_after_null2_.isSet()); - EXPECT_TRUE(handler->got_userdata_obj2_after_null2_.isSet()); - EXPECT_FALSE(handler->got_userdata_obj1_after_test2_fail_.isSet()); - EXPECT_FALSE(handler->got_userdata_obj2_after_test2_fail_.isSet()); - - EXPECT_TRUE(handler->got_accessor_get1_.isSet()); - EXPECT_FALSE(handler->got_accessor_get2_fail_.isSet()); - EXPECT_TRUE(handler->got_accessor_set1_.isSet()); - EXPECT_FALSE(handler->got_accessor_set2_fail_.isSet()); - - EXPECT_TRUE(handler->got_execute1_.isSet()); - EXPECT_FALSE(handler->got_execute1_fail_.isSet()); - EXPECT_TRUE(handler->got_execute2_.isSet()); - EXPECT_FALSE(handler->got_execute2_fail_.isSet()); -} - -namespace { - -static const int kNumExceptionTests = 3; - -class TestExceptionHandler : public TestHandler { - public: - class TestHandler : public CefV8Handler { - public: - explicit TestHandler(CefRefPtr test) - : test_(test) { - } - - virtual bool Execute(const CefString& name, - CefRefPtr object, - const CefV8ValueList& arguments, - CefRefPtr& retval, - CefString& exception) OVERRIDE { - if (name == "register") { - if (arguments.size() == 1 && arguments[0]->IsFunction()) { - test_->got_register_.yes(); - - // Keep pointers to the callback function and context. - test_->test_func_ = arguments[0]; - test_->test_context_ = CefV8Context::GetCurrentContext(); - return true; - } - } else if (name == "execute") { - if (arguments.size() == 2 && arguments[0]->IsInt() && - arguments[1]->IsBool()) { - // Execute the test callback function. - test_->ExecuteTestCallback(arguments[0]->GetIntValue(), - arguments[1]->GetBoolValue()); - return true; - } - } else if (name == "result") { - if (arguments.size() == 1 && arguments[0]->IsString()) { - std::string value = arguments[0]->GetStringValue(); - if (value == "no_exception") - test_->got_no_exception_result_.yes(); - else if (value == "exception") - test_->got_exception_result_.yes(); - else if (value == "done") - test_->got_done_result_.yes(); - else - return false; - return true; - } - } - - return false; - } - - CefRefPtr test_; - - IMPLEMENT_REFCOUNTING(TestHandler); - }; - - TestExceptionHandler() { - } - - virtual void RunTest() OVERRIDE { - std::string testHtml = - "\n" - "\n" - ""; - AddResource("http://tests/run.html", testHtml, "text/html"); - - CreateBrowser("http://tests/run.html"); - } - - // Execute the callback function. - void ExecuteTestCallback(int test, bool rethrow_exception) { - if (test <= 0 || test > kNumExceptionTests) - return; - - got_execute_test_[test-1].yes(); - - if (!test_func_.get()) - return; - - CefV8ValueList args; - CefRefPtr retval; - CefRefPtr exception; - if (test_func_->ExecuteFunctionWithContext(test_context_, NULL, args, - retval, exception, rethrow_exception)) { - got_execute_function_[test-1].yes(); - - if (exception.get()) { - got_exception_[test-1].yes(); - - std::string message = exception->GetMessage(); - EXPECT_EQ("Uncaught Some test exception", message) << "test = " << test; - - std::string source_line = exception->GetSourceLine(); - EXPECT_EQ(" throw 'Some test exception';", source_line) << "test = " << - test; - - std::string script = exception->GetScriptResourceName(); - EXPECT_EQ("http://tests/run.html", script) << "test = " << test; - - int line_number = exception->GetLineNumber(); - EXPECT_EQ(4, line_number) << "test = " << test; - - int start_pos = exception->GetStartPosition(); - EXPECT_EQ(25, start_pos) << "test = " << test; - - int end_pos = exception->GetEndPosition(); - EXPECT_EQ(26, end_pos) << "test = " << test; - - int start_col = exception->GetStartColumn(); - EXPECT_EQ(2, start_col) << "test = " << test; - - int end_col = exception->GetEndColumn(); - EXPECT_EQ(3, end_col) << "test = " << test; - } - } - - if (test == kNumExceptionTests) - DestroyTest(); - } - - virtual void OnLoadEnd(CefRefPtr browser, - CefRefPtr frame, - int httpStatusCode) OVERRIDE { - got_load_end_.yes(); - - // Test 3: Execute the callback asynchronously without re-throwing the - // exception. - CefPostTask(TID_UI, - NewCefRunnableMethod(this, &TestExceptionHandler::ExecuteTestCallback, - 3, false)); - } - - virtual void OnContextCreated(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr context) OVERRIDE { - // Retrieve the 'window' object. - CefRefPtr object = context->GetGlobal(); - - // Create the functions that will be used during the test. - CefRefPtr obj = CefV8Value::CreateObject(NULL, NULL); - CefRefPtr handler = new TestHandler(this); - obj->SetValue("register", - CefV8Value::CreateFunction("register", handler), - V8_PROPERTY_ATTRIBUTE_NONE); - obj->SetValue("execute", - CefV8Value::CreateFunction("execute", handler), - V8_PROPERTY_ATTRIBUTE_NONE); - obj->SetValue("result", - CefV8Value::CreateFunction("result", handler), - V8_PROPERTY_ATTRIBUTE_NONE); - object->SetValue("test", obj, V8_PROPERTY_ATTRIBUTE_NONE); - } - - CefRefPtr test_func_; - CefRefPtr test_context_; - - TrackCallback got_register_; - TrackCallback got_load_end_; - TrackCallback got_execute_test_[kNumExceptionTests]; - TrackCallback got_execute_function_[kNumExceptionTests]; - TrackCallback got_exception_[kNumExceptionTests]; - TrackCallback got_exception_result_; - TrackCallback got_no_exception_result_; - TrackCallback got_done_result_; -}; - -} // namespace - -// Test V8 exception results. -TEST(V8Test, Exception) { - CefRefPtr handler = new TestExceptionHandler(); - handler->ExecuteTest(); - - EXPECT_TRUE(handler->got_register_); - EXPECT_TRUE(handler->got_load_end_); - EXPECT_TRUE(handler->got_exception_result_); - EXPECT_FALSE(handler->got_no_exception_result_); - EXPECT_TRUE(handler->got_done_result_); - - for (int i = 0; i < kNumExceptionTests; ++i) { - EXPECT_TRUE(handler->got_execute_test_[i]) << "test = " << i+1; - EXPECT_TRUE(handler->got_execute_function_[i]) << "test = " << i+1; - EXPECT_TRUE(handler->got_exception_[i]) << "test = " << i+1; - } -} - -namespace { - -class TestPermissionsHandler : public V8TestHandler { - public: - explicit TestPermissionsHandler(bool denyExtensions) : V8TestHandler(false) { - deny_extensions_ = denyExtensions; - } - - virtual bool OnBeforeScriptExtensionLoad(CefRefPtr browser, - CefRefPtr frame, - const CefString& extensionName) { - return deny_extensions_; - } - - bool deny_extensions_; -}; - -} // namespace - -// Verify extension permissions -TEST(V8Test, Permissions) { - g_V8TestV8HandlerExecuteCalled = false; - - std::string extensionCode = - "var test;" - "if (!test)" - " test = {};" - "(function() {" - " test.execute = function(a,b,c,d,e,f,g,h,i) {" - " native function execute();" - " return execute(a,b,c,d,e,f,g,h,i);" - " };" - "})();"; - CefRegisterExtension("v8/test", extensionCode, new V8TestV8Handler(false)); - - CefRefPtr deny_handler = new TestPermissionsHandler(true); - deny_handler->ExecuteTest(); - - ASSERT_FALSE(g_V8TestV8HandlerExecuteCalled); - - CefRefPtr allow_handler = new TestPermissionsHandler(false); - allow_handler->ExecuteTest(); - - ASSERT_TRUE(g_V8TestV8HandlerExecuteCalled); -} diff --git a/cef1/tools/cef_parser.py b/cef1/tools/cef_parser.py index 000e76d25..722ac4b19 100644 --- a/cef1/tools/cef_parser.py +++ b/cef1/tools/cef_parser.py @@ -359,6 +359,8 @@ _simpletypes = { 'void' : ['void', ''], 'void*' : ['void*', 'NULL'], 'int' : ['int', '0'], + 'int32' : ['int32', '0'], + 'uint32' : ['uint32', '0'], 'int64' : ['int64', '0'], 'uint64' : ['uint64', '0'], 'double' : ['double', '0'], @@ -801,6 +803,14 @@ class obj_class: """ Return the array of typedef objects. """ return self.typedefs + def has_typedef_alias(self, alias): + """ Returns true if the specified typedef alias is defined in the scope + of this class declaration. """ + for typedef in self.typedefs: + if typedef.get_alias() == alias: + return True + return False + def get_static_funcs(self): """ Return the array of static function objects. """ return self.staticfuncs @@ -1045,8 +1055,10 @@ class obj_function: if isimpl and isinstance(self, obj_function_virtual): # enumeration return values must be qualified with the class name + # if the type is defined in the class declaration scope. type = self.get_retval().get_type() - if type.is_result_struct() and type.is_result_struct_enum(): + if type.is_result_struct() and type.is_result_struct_enum() and \ + self.parent.has_typedef_alias(retval): retval = self.parent.get_name()+'::'+retval return { 'retval' : retval, 'name' : name, 'args' : args }