From 57a44195618d77770169ac2908a4cb75826b1e36 Mon Sep 17 00:00:00 2001
From: Bryan Reynaert
Date: Mon, 19 Jun 2017 02:51:34 -0400
Subject: [PATCH 1/4] Updated header files from CEF Git
---
include/base/cef_atomic_ref_count.h | 126 +
include/base/cef_atomicops.h | 199 +
include/base/cef_basictypes.h | 77 +
include/base/cef_bind.h | 575 +++
include/base/cef_bind_helpers.h | 579 +++
include/base/cef_build.h | 197 +
include/base/cef_callback.h | 801 +++++
include/base/cef_callback_forward.h | 59 +
include/base/cef_callback_helpers.h | 93 +
include/base/cef_callback_list.h | 449 +++
include/base/cef_cancelable_callback.h | 293 ++
include/base/cef_lock.h | 174 +
include/base/cef_logging.h | 760 ++++
include/base/cef_macros.h | 220 ++
include/base/cef_move.h | 261 ++
include/base/cef_platform_thread.h | 106 +
include/base/cef_ref_counted.h | 378 ++
include/base/cef_scoped_ptr.h | 625 ++++
include/base/cef_string16.h | 214 ++
include/base/cef_template_util.h | 214 ++
include/base/cef_thread_checker.h | 121 +
include/base/cef_thread_collision_warner.h | 276 ++
include/base/cef_trace_event.h | 420 +++
include/base/cef_tuple.h | 1610 +++++++++
include/base/cef_weak_ptr.h | 385 ++
include/base/internal/cef_atomicops_arm_gcc.h | 325 ++
.../cef_atomicops_atomicword_compat.h | 124 +
include/base/internal/cef_atomicops_mac.h | 223 ++
include/base/internal/cef_atomicops_x86_gcc.h | 268 ++
.../base/internal/cef_atomicops_x86_msvc.h | 221 ++
include/base/internal/cef_bind_internal.h | 3190 +++++++++++++++++
include/base/internal/cef_bind_internal_win.h | 396 ++
include/base/internal/cef_callback_internal.h | 224 ++
include/base/internal/cef_lock_impl.h | 87 +
.../cef_raw_scoped_refptr_mismatch_checker.h | 181 +
.../base/internal/cef_thread_checker_impl.h | 72 +
include/capi/cef_accessibility_handler_capi.h | 81 +
include/capi/cef_app_capi.h | 67 +-
include/capi/cef_auth_callback_capi.h | 19 +-
include/capi/cef_base_capi.h | 59 +-
include/capi/cef_browser_capi.h | 626 +++-
.../capi/cef_browser_process_handler_capi.h | 45 +-
include/capi/cef_callback_capi.h | 25 +-
include/capi/cef_client_capi.h | 53 +-
include/capi/cef_command_line_capi.h | 81 +-
include/capi/cef_context_menu_handler_capi.h | 152 +-
include/capi/cef_cookie_capi.h | 170 +-
include/capi/cef_crash_util_capi.h | 153 +
include/capi/cef_dialog_handler_capi.h | 58 +-
include/capi/cef_display_handler_capi.h | 68 +-
include/capi/cef_dom_capi.h | 228 +-
include/capi/cef_download_handler_capi.h | 43 +-
include/capi/cef_download_item_capi.h | 51 +-
include/capi/cef_drag_data_capi.h | 126 +-
include/capi/cef_drag_handler_capi.h | 34 +-
include/capi/cef_file_util_capi.h | 121 +
include/capi/cef_find_handler_capi.h | 81 +
include/capi/cef_focus_handler_capi.h | 28 +-
include/capi/cef_frame_capi.h | 84 +-
include/capi/cef_geolocation_capi.h | 14 +-
include/capi/cef_geolocation_handler_capi.h | 49 +-
include/capi/cef_image_capi.h | 205 ++
include/capi/cef_jsdialog_handler_capi.h | 57 +-
include/capi/cef_keyboard_handler_capi.h | 31 +-
include/capi/cef_life_span_handler_capi.h | 195 +-
include/capi/cef_load_handler_capi.h | 80 +-
include/capi/cef_menu_model_capi.h | 381 +-
include/capi/cef_menu_model_delegate_capi.h | 123 +
include/capi/cef_navigation_entry_capi.h | 132 +
include/capi/cef_origin_whitelist_capi.h | 21 +-
include/capi/cef_parser_capi.h | 168 +
include/capi/cef_path_util_capi.h | 9 +-
include/capi/cef_print_handler_capi.h | 158 +
include/capi/cef_print_settings_capi.h | 208 ++
include/capi/cef_process_message_capi.h | 25 +-
include/capi/cef_process_util_capi.h | 9 +-
include/capi/cef_render_handler_capi.h | 146 +-
.../capi/cef_render_process_handler_capi.h | 60 +-
include/capi/cef_request_capi.h | 159 +-
include/capi/cef_request_context_capi.h | 238 +-
.../capi/cef_request_context_handler_capi.h | 54 +-
include/capi/cef_request_handler_capi.h | 284 +-
include/capi/cef_resource_bundle_capi.h | 112 +
.../capi/cef_resource_bundle_handler_capi.h | 59 +-
include/capi/cef_resource_handler_capi.h | 47 +-
include/capi/cef_response_capi.h | 55 +-
include/capi/cef_response_filter_capi.h | 110 +
include/capi/cef_scheme_capi.h | 110 +-
include/capi/cef_ssl_info_capi.h | 88 +
include/capi/cef_ssl_status_capi.h | 95 +
include/capi/cef_stream_capi.h | 93 +-
include/capi/cef_string_visitor_capi.h | 16 +-
include/capi/cef_task_capi.h | 49 +-
include/capi/cef_thread_capi.h | 117 +
include/capi/cef_trace_capi.h | 28 +-
include/capi/cef_urlrequest_capi.h | 79 +-
include/capi/cef_v8_capi.h | 403 ++-
include/capi/cef_values_capi.h | 536 ++-
include/capi/cef_waitable_event_capi.h | 117 +
include/capi/cef_web_plugin_capi.h | 138 +-
include/capi/cef_x509_certificate_capi.h | 213 ++
include/capi/cef_xml_reader_capi.h | 94 +-
include/capi/cef_zip_reader_capi.h | 49 +-
include/capi/test/cef_translator_test_capi.h | 781 ++++
include/capi/views/cef_box_layout_capi.h | 88 +
include/capi/views/cef_browser_view_capi.h | 102 +
.../views/cef_browser_view_delegate_capi.h | 121 +
include/capi/views/cef_button_capi.h | 103 +
include/capi/views/cef_button_delegate_capi.h | 80 +
include/capi/views/cef_display_capi.h | 146 +
.../cef_fill_layout_capi.h} | 44 +-
include/capi/views/cef_label_button_capi.h | 166 +
include/capi/views/cef_layout_capi.h | 85 +
include/capi/views/cef_menu_button_capi.h | 101 +
.../views/cef_menu_button_delegate_capi.h | 76 +
include/capi/views/cef_panel_capi.h | 151 +
include/capi/views/cef_panel_delegate_capi.h | 65 +
include/capi/views/cef_scroll_view_capi.h | 112 +
include/capi/views/cef_textfield_capi.h | 276 ++
.../capi/views/cef_textfield_delegate_capi.h | 83 +
include/capi/views/cef_view_capi.h | 389 ++
include/capi/views/cef_view_delegate_capi.h | 134 +
include/capi/views/cef_window_capi.h | 314 ++
include/capi/views/cef_window_delegate_capi.h | 132 +
include/internal/cef_build.h | 129 -
include/internal/cef_export.h | 11 +-
include/internal/cef_linux.h | 91 +-
include/internal/cef_logging_internal.h | 68 +
include/internal/cef_mac.h | 86 +-
include/internal/cef_ptr.h | 111 +-
include/internal/cef_string.h | 4 +-
include/internal/cef_string_list.h | 5 +-
include/internal/cef_string_map.h | 9 +-
include/internal/cef_string_multimap.h | 15 +-
include/internal/cef_string_types.h | 97 +-
include/internal/cef_string_wrappers.h | 163 +-
include/internal/cef_thread_internal.h | 78 +
include/internal/cef_time.h | 5 +-
include/internal/cef_trace_event_internal.h | 124 +
include/internal/cef_tuple.h | 1088 ------
include/internal/cef_types.h | 1533 ++++++--
include/internal/cef_types_linux.h | 63 +-
include/internal/cef_types_mac.h | 41 +-
include/internal/cef_types_win.h | 48 +-
include/internal/cef_types_wrappers.h | 573 ++-
include/internal/cef_win.h | 97 +-
146 files changed, 26474 insertions(+), 3904 deletions(-)
create mode 100644 include/base/cef_atomic_ref_count.h
create mode 100644 include/base/cef_atomicops.h
create mode 100644 include/base/cef_basictypes.h
create mode 100644 include/base/cef_bind.h
create mode 100644 include/base/cef_bind_helpers.h
create mode 100644 include/base/cef_build.h
create mode 100644 include/base/cef_callback.h
create mode 100644 include/base/cef_callback_forward.h
create mode 100644 include/base/cef_callback_helpers.h
create mode 100644 include/base/cef_callback_list.h
create mode 100644 include/base/cef_cancelable_callback.h
create mode 100644 include/base/cef_lock.h
create mode 100644 include/base/cef_logging.h
create mode 100644 include/base/cef_macros.h
create mode 100644 include/base/cef_move.h
create mode 100644 include/base/cef_platform_thread.h
create mode 100644 include/base/cef_ref_counted.h
create mode 100644 include/base/cef_scoped_ptr.h
create mode 100644 include/base/cef_string16.h
create mode 100644 include/base/cef_template_util.h
create mode 100644 include/base/cef_thread_checker.h
create mode 100644 include/base/cef_thread_collision_warner.h
create mode 100644 include/base/cef_trace_event.h
create mode 100644 include/base/cef_tuple.h
create mode 100644 include/base/cef_weak_ptr.h
create mode 100644 include/base/internal/cef_atomicops_arm_gcc.h
create mode 100644 include/base/internal/cef_atomicops_atomicword_compat.h
create mode 100644 include/base/internal/cef_atomicops_mac.h
create mode 100644 include/base/internal/cef_atomicops_x86_gcc.h
create mode 100644 include/base/internal/cef_atomicops_x86_msvc.h
create mode 100644 include/base/internal/cef_bind_internal.h
create mode 100644 include/base/internal/cef_bind_internal_win.h
create mode 100644 include/base/internal/cef_callback_internal.h
create mode 100644 include/base/internal/cef_lock_impl.h
create mode 100644 include/base/internal/cef_raw_scoped_refptr_mismatch_checker.h
create mode 100644 include/base/internal/cef_thread_checker_impl.h
create mode 100644 include/capi/cef_accessibility_handler_capi.h
create mode 100644 include/capi/cef_crash_util_capi.h
create mode 100644 include/capi/cef_file_util_capi.h
create mode 100644 include/capi/cef_find_handler_capi.h
create mode 100644 include/capi/cef_image_capi.h
create mode 100644 include/capi/cef_menu_model_delegate_capi.h
create mode 100644 include/capi/cef_navigation_entry_capi.h
create mode 100644 include/capi/cef_parser_capi.h
create mode 100644 include/capi/cef_print_handler_capi.h
create mode 100644 include/capi/cef_print_settings_capi.h
create mode 100644 include/capi/cef_resource_bundle_capi.h
create mode 100644 include/capi/cef_response_filter_capi.h
create mode 100644 include/capi/cef_ssl_info_capi.h
create mode 100644 include/capi/cef_ssl_status_capi.h
create mode 100644 include/capi/cef_thread_capi.h
create mode 100644 include/capi/cef_waitable_event_capi.h
create mode 100644 include/capi/cef_x509_certificate_capi.h
create mode 100644 include/capi/test/cef_translator_test_capi.h
create mode 100644 include/capi/views/cef_box_layout_capi.h
create mode 100644 include/capi/views/cef_browser_view_capi.h
create mode 100644 include/capi/views/cef_browser_view_delegate_capi.h
create mode 100644 include/capi/views/cef_button_capi.h
create mode 100644 include/capi/views/cef_button_delegate_capi.h
create mode 100644 include/capi/views/cef_display_capi.h
rename include/capi/{cef_url_capi.h => views/cef_fill_layout_capi.h} (66%)
create mode 100644 include/capi/views/cef_label_button_capi.h
create mode 100644 include/capi/views/cef_layout_capi.h
create mode 100644 include/capi/views/cef_menu_button_capi.h
create mode 100644 include/capi/views/cef_menu_button_delegate_capi.h
create mode 100644 include/capi/views/cef_panel_capi.h
create mode 100644 include/capi/views/cef_panel_delegate_capi.h
create mode 100644 include/capi/views/cef_scroll_view_capi.h
create mode 100644 include/capi/views/cef_textfield_capi.h
create mode 100644 include/capi/views/cef_textfield_delegate_capi.h
create mode 100644 include/capi/views/cef_view_capi.h
create mode 100644 include/capi/views/cef_view_delegate_capi.h
create mode 100644 include/capi/views/cef_window_capi.h
create mode 100644 include/capi/views/cef_window_delegate_capi.h
delete mode 100644 include/internal/cef_build.h
create mode 100644 include/internal/cef_logging_internal.h
create mode 100644 include/internal/cef_thread_internal.h
create mode 100644 include/internal/cef_trace_event_internal.h
delete mode 100644 include/internal/cef_tuple.h
diff --git a/include/base/cef_atomic_ref_count.h b/include/base/cef_atomic_ref_count.h
new file mode 100644
index 0000000..755f8a8
--- /dev/null
+++ b/include/base/cef_atomic_ref_count.h
@@ -0,0 +1,126 @@
+// Copyright (c) 2014 Marshall A. Greenblatt. Portions copyright (c) 2011
+// Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the name Chromium Embedded
+// Framework nor the names of its contributors may be used to endorse
+// or promote products derived from this software without specific prior
+// written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// This is a low level implementation of atomic semantics for reference
+// counting. Please use cef_ref_counted.h directly instead.
+//
+// The Chromium implementation includes annotations to avoid some false
+// positives when using data race detection tools. Annotations are not
+// currently supported by the CEF implementation.
+
+#ifndef CEF_INCLUDE_BASE_CEF_ATOMIC_REF_COUNT_H_
+#define CEF_INCLUDE_BASE_CEF_ATOMIC_REF_COUNT_H_
+#pragma once
+
+#if defined(BASE_ATOMIC_REF_COUNT_H_)
+// Do nothing if the Chromium header has already been included.
+// This can happen in cases where Chromium code is used directly by the
+// client application. When using Chromium code directly always include
+// the Chromium header first to avoid type conflicts.
+#elif defined(USING_CHROMIUM_INCLUDES)
+// When building CEF include the Chromium header directly.
+#include "base/atomic_ref_count.h"
+#else // !USING_CHROMIUM_INCLUDES
+// The following is substantially similar to the Chromium implementation.
+// If the Chromium implementation diverges the below implementation should be
+// updated to match.
+
+#include "include/base/cef_atomicops.h"
+
+// Annotations are not currently supported.
+#define ANNOTATE_HAPPENS_BEFORE(obj) /* empty */
+#define ANNOTATE_HAPPENS_AFTER(obj) /* empty */
+
+namespace base {
+
+typedef subtle::Atomic32 AtomicRefCount;
+
+// Increment a reference count by "increment", which must exceed 0.
+inline void AtomicRefCountIncN(volatile AtomicRefCount* ptr,
+ AtomicRefCount increment) {
+ subtle::NoBarrier_AtomicIncrement(ptr, increment);
+}
+
+// Decrement a reference count by "decrement", which must exceed 0,
+// and return whether the result is non-zero.
+// Insert barriers to ensure that state written before the reference count
+// became zero will be visible to a thread that has just made the count zero.
+inline bool AtomicRefCountDecN(volatile AtomicRefCount* ptr,
+ AtomicRefCount decrement) {
+ ANNOTATE_HAPPENS_BEFORE(ptr);
+ bool res = (subtle::Barrier_AtomicIncrement(ptr, -decrement) != 0);
+ if (!res) {
+ ANNOTATE_HAPPENS_AFTER(ptr);
+ }
+ return res;
+}
+
+// Increment a reference count by 1.
+inline void AtomicRefCountInc(volatile AtomicRefCount* ptr) {
+ base::AtomicRefCountIncN(ptr, 1);
+}
+
+// Decrement a reference count by 1 and return whether the result is non-zero.
+// Insert barriers to ensure that state written before the reference count
+// became zero will be visible to a thread that has just made the count zero.
+inline bool AtomicRefCountDec(volatile AtomicRefCount* ptr) {
+ return base::AtomicRefCountDecN(ptr, 1);
+}
+
+// Return whether the reference count is one. If the reference count is used
+// in the conventional way, a refrerence count of 1 implies that the current
+// thread owns the reference and no other thread shares it. This call performs
+// the test for a reference count of one, and performs the memory barrier
+// needed for the owning thread to act on the object, knowing that it has
+// exclusive access to the object.
+inline bool AtomicRefCountIsOne(volatile AtomicRefCount* ptr) {
+ bool res = (subtle::Acquire_Load(ptr) == 1);
+ if (res) {
+ ANNOTATE_HAPPENS_AFTER(ptr);
+ }
+ return res;
+}
+
+// Return whether the reference count is zero. With conventional object
+// referencing counting, the object will be destroyed, so the reference count
+// should never be zero. Hence this is generally used for a debug check.
+inline bool AtomicRefCountIsZero(volatile AtomicRefCount* ptr) {
+ bool res = (subtle::Acquire_Load(ptr) == 0);
+ if (res) {
+ ANNOTATE_HAPPENS_AFTER(ptr);
+ }
+ return res;
+}
+
+} // namespace base
+
+#endif // !USING_CHROMIUM_INCLUDES
+
+#endif // CEF_INCLUDE_BASE_CEF_ATOMIC_REF_COUNT_H_
diff --git a/include/base/cef_atomicops.h b/include/base/cef_atomicops.h
new file mode 100644
index 0000000..96aebab
--- /dev/null
+++ b/include/base/cef_atomicops.h
@@ -0,0 +1,199 @@
+// Copyright (c) 2014 Marshall A. Greenblatt. Portions copyright (c) 2012
+// Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the name Chromium Embedded
+// Framework nor the names of its contributors may be used to endorse
+// or promote products derived from this software without specific prior
+// written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// For atomic operations on reference counts, see cef_atomic_ref_count.h.
+
+// The routines exported by this module are subtle. If you use them, even if
+// you get the code right, it will depend on careful reasoning about atomicity
+// and memory ordering; it will be less readable, and harder to maintain. If
+// you plan to use these routines, you should have a good reason, such as solid
+// evidence that performance would otherwise suffer, or there being no
+// alternative. You should assume only properties explicitly guaranteed by the
+// specifications in this file. You are almost certainly _not_ writing code
+// just for the x86; if you assume x86 semantics, x86 hardware bugs and
+// implementations on other archtectures will cause your code to break. If you
+// do not know what you are doing, avoid these routines, and use a Mutex.
+//
+// It is incorrect to make direct assignments to/from an atomic variable.
+// You should use one of the Load or Store routines. The NoBarrier
+// versions are provided when no barriers are needed:
+// NoBarrier_Store()
+// NoBarrier_Load()
+// Although there are currently no compiler enforcement, you are encouraged
+// to use these.
+//
+
+#ifndef CEF_INCLUDE_BASE_CEF_ATOMICOPS_H_
+#define CEF_INCLUDE_BASE_CEF_ATOMICOPS_H_
+#pragma once
+
+#if defined(BASE_ATOMICOPS_H_)
+// Do nothing if the Chromium header has already been included.
+// This can happen in cases where Chromium code is used directly by the
+// client application. When using Chromium code directly always include
+// the Chromium header first to avoid type conflicts.
+#elif defined(USING_CHROMIUM_INCLUDES)
+// When building CEF include the Chromium header directly.
+#include "base/atomicops.h"
+#else // !USING_CHROMIUM_INCLUDES
+// The following is substantially similar to the Chromium implementation.
+// If the Chromium implementation diverges the below implementation should be
+// updated to match.
+
+#include
+
+#include "include/base/cef_build.h"
+
+#if defined(OS_WIN) && defined(ARCH_CPU_64_BITS)
+// windows.h #defines this (only on x64). This causes problems because the
+// public API also uses MemoryBarrier at the public name for this fence. So, on
+// X64, undef it, and call its documented
+// (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208.aspx)
+// implementation directly.
+#undef MemoryBarrier
+#endif
+
+namespace base {
+namespace subtle {
+
+typedef int32_t Atomic32;
+#ifdef ARCH_CPU_64_BITS
+// We need to be able to go between Atomic64 and AtomicWord implicitly. This
+// means Atomic64 and AtomicWord should be the same type on 64-bit.
+#if defined(__ILP32__) || defined(OS_NACL)
+// NaCl's intptr_t is not actually 64-bits on 64-bit!
+// http://code.google.com/p/nativeclient/issues/detail?id=1162
+typedef int64_t Atomic64;
+#else
+typedef intptr_t Atomic64;
+#endif
+#endif
+
+// Use AtomicWord for a machine-sized pointer. It will use the Atomic32 or
+// Atomic64 routines below, depending on your architecture.
+typedef intptr_t AtomicWord;
+
+// Atomically execute:
+// result = *ptr;
+// if (*ptr == old_value)
+// *ptr = new_value;
+// return result;
+//
+// I.e., replace "*ptr" with "new_value" if "*ptr" used to be "old_value".
+// Always return the old value of "*ptr"
+//
+// This routine implies no memory barriers.
+Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
+ Atomic32 old_value,
+ Atomic32 new_value);
+
+// Atomically store new_value into *ptr, returning the previous value held in
+// *ptr. This routine implies no memory barriers.
+Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, Atomic32 new_value);
+
+// Atomically increment *ptr by "increment". Returns the new value of
+// *ptr with the increment applied. This routine implies no memory barriers.
+Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, Atomic32 increment);
+
+Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, Atomic32 increment);
+
+// These following lower-level operations are typically useful only to people
+// implementing higher-level synchronization operations like spinlocks,
+// mutexes, and condition-variables. They combine CompareAndSwap(), a load, or
+// a store with appropriate memory-ordering instructions. "Acquire" operations
+// ensure that no later memory access can be reordered ahead of the operation.
+// "Release" operations ensure that no previous memory access can be reordered
+// after the operation. "Barrier" operations have both "Acquire" and "Release"
+// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory
+// access.
+Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
+ Atomic32 old_value,
+ Atomic32 new_value);
+Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
+ Atomic32 old_value,
+ Atomic32 new_value);
+
+void MemoryBarrier();
+void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value);
+void Acquire_Store(volatile Atomic32* ptr, Atomic32 value);
+void Release_Store(volatile Atomic32* ptr, Atomic32 value);
+
+Atomic32 NoBarrier_Load(volatile const Atomic32* ptr);
+Atomic32 Acquire_Load(volatile const Atomic32* ptr);
+Atomic32 Release_Load(volatile const Atomic32* ptr);
+
+// 64-bit atomic operations (only available on 64-bit processors).
+#ifdef ARCH_CPU_64_BITS
+Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
+ Atomic64 old_value,
+ Atomic64 new_value);
+Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, Atomic64 new_value);
+Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment);
+Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment);
+
+Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
+ Atomic64 old_value,
+ Atomic64 new_value);
+Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
+ Atomic64 old_value,
+ Atomic64 new_value);
+void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value);
+void Acquire_Store(volatile Atomic64* ptr, Atomic64 value);
+void Release_Store(volatile Atomic64* ptr, Atomic64 value);
+Atomic64 NoBarrier_Load(volatile const Atomic64* ptr);
+Atomic64 Acquire_Load(volatile const Atomic64* ptr);
+Atomic64 Release_Load(volatile const Atomic64* ptr);
+#endif // ARCH_CPU_64_BITS
+
+} // namespace subtle
+} // namespace base
+
+// Include our platform specific implementation.
+#if defined(OS_WIN) && defined(COMPILER_MSVC) && defined(ARCH_CPU_X86_FAMILY)
+#include "include/base/internal/cef_atomicops_x86_msvc.h"
+#elif defined(OS_MACOSX)
+#include "include/base/internal/cef_atomicops_mac.h"
+#elif defined(COMPILER_GCC) && defined(ARCH_CPU_X86_FAMILY)
+#include "include/base/internal/cef_atomicops_x86_gcc.h"
+#elif defined(COMPILER_GCC) && defined(__ARM_ARCH)
+#include "include/base/internal/cef_atomicops_arm_gcc.h"
+#else
+#error "Atomic operations are not supported on your platform"
+#endif
+
+// On some platforms we need additional declarations to make
+// AtomicWord compatible with our other Atomic* types.
+#if defined(OS_MACOSX) || defined(OS_OPENBSD)
+#include "include/base/internal/cef_atomicops_atomicword_compat.h"
+#endif
+
+#endif // !USING_CHROMIUM_INCLUDES
+
+#endif // CEF_INCLUDE_BASE_CEF_ATOMICOPS_H_
diff --git a/include/base/cef_basictypes.h b/include/base/cef_basictypes.h
new file mode 100644
index 0000000..0086a1d
--- /dev/null
+++ b/include/base/cef_basictypes.h
@@ -0,0 +1,77 @@
+// Copyright (c) 2014 Marshall A. Greenblatt. Portions copyright (c) 2012
+// Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the name Chromium Embedded
+// Framework nor the names of its contributors may be used to endorse
+// or promote products derived from this software without specific prior
+// written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef CEF_INCLUDE_BASE_CEF_BASICTYPES_H_
+#define CEF_INCLUDE_BASE_CEF_BASICTYPES_H_
+#pragma once
+
+#include // For UINT_MAX
+#include // For size_t
+
+#include "include/base/cef_build.h"
+
+// The NSPR system headers define 64-bit as |long| when possible, except on
+// Mac OS X. In order to not have typedef mismatches, we do the same on LP64.
+//
+// On Mac OS X, |long long| is used for 64-bit types for compatibility with
+// format macros even in the LP64 model.
+#if defined(__LP64__) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
+typedef long int64;
+typedef unsigned long uint64;
+#else
+typedef long long int64;
+typedef unsigned long long uint64;
+#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
+
+// UTF-16 character type.
+// This should be kept synchronized with base/strings/string16.h
+#ifndef char16
+#if defined(WCHAR_T_IS_UTF16)
+typedef wchar_t char16;
+#elif defined(WCHAR_T_IS_UTF32)
+typedef unsigned short char16;
+#endif
+#endif
+
+#endif // CEF_INCLUDE_BASE_CEF_BASICTYPES_H_
diff --git a/include/base/cef_bind.h b/include/base/cef_bind.h
new file mode 100644
index 0000000..77c9c55
--- /dev/null
+++ b/include/base/cef_bind.h
@@ -0,0 +1,575 @@
+// Copyright (c) 2014 Marshall A. Greenblatt. Portions copyright (c) 2011
+// Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the name Chromium Embedded
+// Framework nor the names of its contributors may be used to endorse
+// or promote products derived from this software without specific prior
+// written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef CEF_INCLUDE_BASE_CEF_BIND_H_
+#define CEF_INCLUDE_BASE_CEF_BIND_H_
+#pragma once
+
+#if defined(BASE_BIND_H_)
+// Do nothing if the Chromium header has already been included.
+// This can happen in cases where Chromium code is used directly by the
+// client application. When using Chromium code directly always include
+// the Chromium header first to avoid type conflicts.
+#elif defined(USING_CHROMIUM_INCLUDES)
+// When building CEF include the Chromium header directly.
+#include "base/bind.h"
+#else // !USING_CHROMIUM_INCLUDES
+// The following is substantially similar to the Chromium implementation.
+// If the Chromium implementation diverges the below implementation should be
+// updated to match.
+
+#include "include/base/internal/cef_bind_internal.h"
+#include "include/base/internal/cef_callback_internal.h"
+
+// -----------------------------------------------------------------------------
+// Usage documentation
+// -----------------------------------------------------------------------------
+//
+// See base/cef_callback.h for documentation.
+//
+//
+// -----------------------------------------------------------------------------
+// Implementation notes
+// -----------------------------------------------------------------------------
+//
+// If you're reading the implementation, before proceeding further, you should
+// read the top comment of base/bind_internal.h for a definition of common
+// terms and concepts.
+//
+// RETURN TYPES
+//
+// Though Bind()'s result is meant to be stored in a Callback<> type, it
+// cannot actually return the exact type without requiring a large amount
+// of extra template specializations. The problem is that in order to
+// discern the correct specialization of Callback<>, Bind would need to
+// unwrap the function signature to determine the signature's arity, and
+// whether or not it is a method.
+//
+// Each unique combination of (arity, function_type, num_prebound) where
+// function_type is one of {function, method, const_method} would require
+// one specialization. We eventually have to do a similar number of
+// specializations anyways in the implementation (see the Invoker<>,
+// classes). However, it is avoidable in Bind if we return the result
+// via an indirection like we do below.
+//
+// TODO(ajwong): We might be able to avoid this now, but need to test.
+//
+// It is possible to move most of the COMPILE_ASSERT asserts into BindState<>,
+// but it feels a little nicer to have the asserts here so people do not
+// need to crack open bind_internal.h. On the other hand, it makes Bind()
+// harder to read.
+
+namespace base {
+
+template
+base::Callback::RunnableType,
+ typename cef_internal::FunctorTraits::RunType,
+ void()>::UnboundRunType>
+Bind(Functor functor) {
+ // Typedefs for how to store and run the functor.
+ typedef
+ typename cef_internal::FunctorTraits::RunnableType RunnableType;
+ typedef typename cef_internal::FunctorTraits::RunType RunType;
+
+ typedef cef_internal::BindState BindState;
+
+ return Callback(
+ new BindState(cef_internal::MakeRunnable(functor)));
+}
+
+template
+base::Callback::RunnableType,
+ typename cef_internal::FunctorTraits::RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType)>::
+ UnboundRunType>
+Bind(Functor functor, const P1& p1) {
+ // Typedefs for how to store and run the functor.
+ typedef
+ typename cef_internal::FunctorTraits::RunnableType RunnableType;
+ typedef typename cef_internal::FunctorTraits::RunType RunType;
+
+ // Use RunnableType::RunType instead of RunType above because our
+ // checks should below for bound references need to know what the actual
+ // functor is going to interpret the argument as.
+ typedef cef_internal::FunctionTraits
+ BoundFunctorTraits;
+
+ // Do not allow binding a non-const reference parameter. Non-const reference
+ // parameters are disallowed by the Google style guide. Also, binding a
+ // non-const reference parameter can make for subtle bugs because the
+ // invoked function will receive a reference to the stored copy of the
+ // argument and not the original.
+ COMPILE_ASSERT(
+ !(is_non_const_reference::value),
+ do_not_bind_functions_with_nonconst_ref);
+
+ // For methods, we need to be careful for parameter 1. We do not require
+ // a scoped_refptr because BindState<> itself takes care of AddRef() for
+ // methods. We also disallow binding of an array as the method's target
+ // object.
+ COMPILE_ASSERT(cef_internal::HasIsMethodTag::value ||
+ !cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p1_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::HasIsMethodTag::value ||
+ !is_array::value,
+ first_bound_argument_to_method_cannot_be_array);
+ typedef cef_internal::BindState<
+ RunnableType, RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType)>
+ BindState;
+
+ return Callback(
+ new BindState(cef_internal::MakeRunnable(functor), p1));
+}
+
+template
+base::Callback::RunnableType,
+ typename cef_internal::FunctorTraits::RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType)>::
+ UnboundRunType>
+Bind(Functor functor, const P1& p1, const P2& p2) {
+ // Typedefs for how to store and run the functor.
+ typedef
+ typename cef_internal::FunctorTraits::RunnableType RunnableType;
+ typedef typename cef_internal::FunctorTraits::RunType RunType;
+
+ // Use RunnableType::RunType instead of RunType above because our
+ // checks should below for bound references need to know what the actual
+ // functor is going to interpret the argument as.
+ typedef cef_internal::FunctionTraits
+ BoundFunctorTraits;
+
+ // Do not allow binding a non-const reference parameter. Non-const reference
+ // parameters are disallowed by the Google style guide. Also, binding a
+ // non-const reference parameter can make for subtle bugs because the
+ // invoked function will receive a reference to the stored copy of the
+ // argument and not the original.
+ COMPILE_ASSERT(
+ !(is_non_const_reference::value ||
+ is_non_const_reference::value),
+ do_not_bind_functions_with_nonconst_ref);
+
+ // For methods, we need to be careful for parameter 1. We do not require
+ // a scoped_refptr because BindState<> itself takes care of AddRef() for
+ // methods. We also disallow binding of an array as the method's target
+ // object.
+ COMPILE_ASSERT(cef_internal::HasIsMethodTag::value ||
+ !cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p1_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::HasIsMethodTag::value ||
+ !is_array::value,
+ first_bound_argument_to_method_cannot_be_array);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p2_is_refcounted_type_and_needs_scoped_refptr);
+ typedef cef_internal::BindState<
+ RunnableType, RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType)>
+ BindState;
+
+ return Callback(
+ new BindState(cef_internal::MakeRunnable(functor), p1, p2));
+}
+
+template
+base::Callback::RunnableType,
+ typename cef_internal::FunctorTraits::RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType)>::
+ UnboundRunType>
+Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3) {
+ // Typedefs for how to store and run the functor.
+ typedef
+ typename cef_internal::FunctorTraits::RunnableType RunnableType;
+ typedef typename cef_internal::FunctorTraits::RunType RunType;
+
+ // Use RunnableType::RunType instead of RunType above because our
+ // checks should below for bound references need to know what the actual
+ // functor is going to interpret the argument as.
+ typedef cef_internal::FunctionTraits
+ BoundFunctorTraits;
+
+ // Do not allow binding a non-const reference parameter. Non-const reference
+ // parameters are disallowed by the Google style guide. Also, binding a
+ // non-const reference parameter can make for subtle bugs because the
+ // invoked function will receive a reference to the stored copy of the
+ // argument and not the original.
+ COMPILE_ASSERT(
+ !(is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value),
+ do_not_bind_functions_with_nonconst_ref);
+
+ // For methods, we need to be careful for parameter 1. We do not require
+ // a scoped_refptr because BindState<> itself takes care of AddRef() for
+ // methods. We also disallow binding of an array as the method's target
+ // object.
+ COMPILE_ASSERT(cef_internal::HasIsMethodTag::value ||
+ !cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p1_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::HasIsMethodTag::value ||
+ !is_array::value,
+ first_bound_argument_to_method_cannot_be_array);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p2_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p3_is_refcounted_type_and_needs_scoped_refptr);
+ typedef cef_internal::BindState<
+ RunnableType, RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType)>
+ BindState;
+
+ return Callback(
+ new BindState(cef_internal::MakeRunnable(functor), p1, p2, p3));
+}
+
+template
+base::Callback::RunnableType,
+ typename cef_internal::FunctorTraits::RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType)>::
+ UnboundRunType>
+Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4) {
+ // Typedefs for how to store and run the functor.
+ typedef
+ typename cef_internal::FunctorTraits::RunnableType RunnableType;
+ typedef typename cef_internal::FunctorTraits::RunType RunType;
+
+ // Use RunnableType::RunType instead of RunType above because our
+ // checks should below for bound references need to know what the actual
+ // functor is going to interpret the argument as.
+ typedef cef_internal::FunctionTraits
+ BoundFunctorTraits;
+
+ // Do not allow binding a non-const reference parameter. Non-const reference
+ // parameters are disallowed by the Google style guide. Also, binding a
+ // non-const reference parameter can make for subtle bugs because the
+ // invoked function will receive a reference to the stored copy of the
+ // argument and not the original.
+ COMPILE_ASSERT(
+ !(is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value),
+ do_not_bind_functions_with_nonconst_ref);
+
+ // For methods, we need to be careful for parameter 1. We do not require
+ // a scoped_refptr because BindState<> itself takes care of AddRef() for
+ // methods. We also disallow binding of an array as the method's target
+ // object.
+ COMPILE_ASSERT(cef_internal::HasIsMethodTag::value ||
+ !cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p1_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::HasIsMethodTag::value ||
+ !is_array::value,
+ first_bound_argument_to_method_cannot_be_array);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p2_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p3_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p4_is_refcounted_type_and_needs_scoped_refptr);
+ typedef cef_internal::BindState<
+ RunnableType, RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType)>
+ BindState;
+
+ return Callback(
+ new BindState(cef_internal::MakeRunnable(functor), p1, p2, p3, p4));
+}
+
+template
+base::Callback::RunnableType,
+ typename cef_internal::FunctorTraits::RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType)>::
+ UnboundRunType>
+Bind(Functor functor,
+ const P1& p1,
+ const P2& p2,
+ const P3& p3,
+ const P4& p4,
+ const P5& p5) {
+ // Typedefs for how to store and run the functor.
+ typedef
+ typename cef_internal::FunctorTraits::RunnableType RunnableType;
+ typedef typename cef_internal::FunctorTraits::RunType RunType;
+
+ // Use RunnableType::RunType instead of RunType above because our
+ // checks should below for bound references need to know what the actual
+ // functor is going to interpret the argument as.
+ typedef cef_internal::FunctionTraits
+ BoundFunctorTraits;
+
+ // Do not allow binding a non-const reference parameter. Non-const reference
+ // parameters are disallowed by the Google style guide. Also, binding a
+ // non-const reference parameter can make for subtle bugs because the
+ // invoked function will receive a reference to the stored copy of the
+ // argument and not the original.
+ COMPILE_ASSERT(
+ !(is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value),
+ do_not_bind_functions_with_nonconst_ref);
+
+ // For methods, we need to be careful for parameter 1. We do not require
+ // a scoped_refptr because BindState<> itself takes care of AddRef() for
+ // methods. We also disallow binding of an array as the method's target
+ // object.
+ COMPILE_ASSERT(cef_internal::HasIsMethodTag::value ||
+ !cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p1_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::HasIsMethodTag::value ||
+ !is_array::value,
+ first_bound_argument_to_method_cannot_be_array);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p2_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p3_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p4_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p5_is_refcounted_type_and_needs_scoped_refptr);
+ typedef cef_internal::BindState<
+ RunnableType, RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType)>
+ BindState;
+
+ return Callback(
+ new BindState(cef_internal::MakeRunnable(functor), p1, p2, p3, p4, p5));
+}
+
+template
+base::Callback::RunnableType,
+ typename cef_internal::FunctorTraits::RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType)>::
+ UnboundRunType>
+Bind(Functor functor,
+ const P1& p1,
+ const P2& p2,
+ const P3& p3,
+ const P4& p4,
+ const P5& p5,
+ const P6& p6) {
+ // Typedefs for how to store and run the functor.
+ typedef
+ typename cef_internal::FunctorTraits::RunnableType RunnableType;
+ typedef typename cef_internal::FunctorTraits::RunType RunType;
+
+ // Use RunnableType::RunType instead of RunType above because our
+ // checks should below for bound references need to know what the actual
+ // functor is going to interpret the argument as.
+ typedef cef_internal::FunctionTraits
+ BoundFunctorTraits;
+
+ // Do not allow binding a non-const reference parameter. Non-const reference
+ // parameters are disallowed by the Google style guide. Also, binding a
+ // non-const reference parameter can make for subtle bugs because the
+ // invoked function will receive a reference to the stored copy of the
+ // argument and not the original.
+ COMPILE_ASSERT(
+ !(is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value),
+ do_not_bind_functions_with_nonconst_ref);
+
+ // For methods, we need to be careful for parameter 1. We do not require
+ // a scoped_refptr because BindState<> itself takes care of AddRef() for
+ // methods. We also disallow binding of an array as the method's target
+ // object.
+ COMPILE_ASSERT(cef_internal::HasIsMethodTag::value ||
+ !cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p1_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::HasIsMethodTag::value ||
+ !is_array::value,
+ first_bound_argument_to_method_cannot_be_array);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p2_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p3_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p4_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p5_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p6_is_refcounted_type_and_needs_scoped_refptr);
+ typedef cef_internal::BindState<
+ RunnableType, RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType)>
+ BindState;
+
+ return Callback(new BindState(
+ cef_internal::MakeRunnable(functor), p1, p2, p3, p4, p5, p6));
+}
+
+template
+base::Callback::RunnableType,
+ typename cef_internal::FunctorTraits::RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType)>::
+ UnboundRunType>
+Bind(Functor functor,
+ const P1& p1,
+ const P2& p2,
+ const P3& p3,
+ const P4& p4,
+ const P5& p5,
+ const P6& p6,
+ const P7& p7) {
+ // Typedefs for how to store and run the functor.
+ typedef
+ typename cef_internal::FunctorTraits::RunnableType RunnableType;
+ typedef typename cef_internal::FunctorTraits::RunType RunType;
+
+ // Use RunnableType::RunType instead of RunType above because our
+ // checks should below for bound references need to know what the actual
+ // functor is going to interpret the argument as.
+ typedef cef_internal::FunctionTraits
+ BoundFunctorTraits;
+
+ // Do not allow binding a non-const reference parameter. Non-const reference
+ // parameters are disallowed by the Google style guide. Also, binding a
+ // non-const reference parameter can make for subtle bugs because the
+ // invoked function will receive a reference to the stored copy of the
+ // argument and not the original.
+ COMPILE_ASSERT(
+ !(is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value ||
+ is_non_const_reference::value),
+ do_not_bind_functions_with_nonconst_ref);
+
+ // For methods, we need to be careful for parameter 1. We do not require
+ // a scoped_refptr because BindState<> itself takes care of AddRef() for
+ // methods. We also disallow binding of an array as the method's target
+ // object.
+ COMPILE_ASSERT(cef_internal::HasIsMethodTag::value ||
+ !cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p1_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::HasIsMethodTag::value ||
+ !is_array::value,
+ first_bound_argument_to_method_cannot_be_array);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p2_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p3_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p4_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p5_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p6_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(!cef_internal::NeedsScopedRefptrButGetsRawPtr::value,
+ p7_is_refcounted_type_and_needs_scoped_refptr);
+ typedef cef_internal::BindState<
+ RunnableType, RunType,
+ void(typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType,
+ typename cef_internal::CallbackParamTraits::StorageType)>
+ BindState;
+
+ return Callback(new BindState(
+ cef_internal::MakeRunnable(functor), p1, p2, p3, p4, p5, p6, p7));
+}
+
+} // namespace base
+
+#endif // !USING_CHROMIUM_INCLUDES
+
+#endif // CEF_INCLUDE_BASE_CEF_BIND_H_
diff --git a/include/base/cef_bind_helpers.h b/include/base/cef_bind_helpers.h
new file mode 100644
index 0000000..2b4798b
--- /dev/null
+++ b/include/base/cef_bind_helpers.h
@@ -0,0 +1,579 @@
+// Copyright (c) 2014 Marshall A. Greenblatt. Portions copyright (c) 2011
+// Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the name Chromium Embedded
+// Framework nor the names of its contributors may be used to endorse
+// or promote products derived from this software without specific prior
+// written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// This defines a set of argument wrappers and related factory methods that
+// can be used specify the refcounting and reference semantics of arguments
+// that are bound by the Bind() function in base/bind.h.
+//
+// It also defines a set of simple functions and utilities that people want
+// when using Callback<> and Bind().
+//
+//
+// ARGUMENT BINDING WRAPPERS
+//
+// The wrapper functions are base::Unretained(), base::Owned(), base::Passed(),
+// base::ConstRef(), and base::IgnoreResult().
+//
+// Unretained() allows Bind() to bind a non-refcounted class, and to disable
+// refcounting on arguments that are refcounted objects.
+//
+// Owned() transfers ownership of an object to the Callback resulting from
+// bind; the object will be deleted when the Callback is deleted.
+//
+// Passed() is for transferring movable-but-not-copyable types (eg. scoped_ptr)
+// through a Callback. Logically, this signifies a destructive transfer of
+// the state of the argument into the target function. Invoking
+// Callback::Run() twice on a Callback that was created with a Passed()
+// argument will CHECK() because the first invocation would have already
+// transferred ownership to the target function.
+//
+// ConstRef() allows binding a constant reference to an argument rather
+// than a copy.
+//
+// IgnoreResult() is used to adapt a function or Callback with a return type to
+// one with a void return. This is most useful if you have a function with,
+// say, a pesky ignorable bool return that you want to use with PostTask or
+// something else that expect a Callback with a void return.
+//
+// EXAMPLE OF Unretained():
+//
+// class Foo {
+// public:
+// void func() { cout << "Foo:f" << endl; }
+// };
+//
+// // In some function somewhere.
+// Foo foo;
+// Closure foo_callback =
+// Bind(&Foo::func, Unretained(&foo));
+// foo_callback.Run(); // Prints "Foo:f".
+//
+// Without the Unretained() wrapper on |&foo|, the above call would fail
+// to compile because Foo does not support the AddRef() and Release() methods.
+//
+//
+// EXAMPLE OF Owned():
+//
+// void foo(int* arg) { cout << *arg << endl }
+//
+// int* pn = new int(1);
+// Closure foo_callback = Bind(&foo, Owned(pn));
+//
+// foo_callback.Run(); // Prints "1"
+// foo_callback.Run(); // Prints "1"
+// *n = 2;
+// foo_callback.Run(); // Prints "2"
+//
+// foo_callback.Reset(); // |pn| is deleted. Also will happen when
+// // |foo_callback| goes out of scope.
+//
+// Without Owned(), someone would have to know to delete |pn| when the last
+// reference to the Callback is deleted.
+//
+//
+// EXAMPLE OF ConstRef():
+//
+// void foo(int arg) { cout << arg << endl }
+//
+// int n = 1;
+// Closure no_ref = Bind(&foo, n);
+// Closure has_ref = Bind(&foo, ConstRef(n));
+//
+// no_ref.Run(); // Prints "1"
+// has_ref.Run(); // Prints "1"
+//
+// n = 2;
+// no_ref.Run(); // Prints "1"
+// has_ref.Run(); // Prints "2"
+//
+// Note that because ConstRef() takes a reference on |n|, |n| must outlive all
+// its bound callbacks.
+//
+//
+// EXAMPLE OF IgnoreResult():
+//
+// int DoSomething(int arg) { cout << arg << endl; }
+//
+// // Assign to a Callback with a void return type.
+// Callback cb = Bind(IgnoreResult(&DoSomething));
+// cb->Run(1); // Prints "1".
+//
+// // Prints "1" on |ml|.
+// ml->PostTask(FROM_HERE, Bind(IgnoreResult(&DoSomething), 1);
+//
+//
+// EXAMPLE OF Passed():
+//
+// void TakesOwnership(scoped_ptr arg) { }
+// scoped_ptr CreateFoo() { return scoped_ptr(new Foo()); }
+//
+// scoped_ptr f(new Foo());
+//
+// // |cb| is given ownership of Foo(). |f| is now NULL.
+// // You can use f.Pass() in place of &f, but it's more verbose.
+// Closure cb = Bind(&TakesOwnership, Passed(&f));
+//
+// // Run was never called so |cb| still owns Foo() and deletes
+// // it on Reset().
+// cb.Reset();
+//
+// // |cb| is given a new Foo created by CreateFoo().
+// cb = Bind(&TakesOwnership, Passed(CreateFoo()));
+//
+// // |arg| in TakesOwnership() is given ownership of Foo(). |cb|
+// // no longer owns Foo() and, if reset, would not delete Foo().
+// cb.Run(); // Foo() is now transferred to |arg| and deleted.
+// cb.Run(); // This CHECK()s since Foo() already been used once.
+//
+// Passed() is particularly useful with PostTask() when you are transferring
+// ownership of an argument into a task, but don't necessarily know if the
+// task will always be executed. This can happen if the task is cancellable
+// or if it is posted to a MessageLoopProxy.
+//
+//
+// SIMPLE FUNCTIONS AND UTILITIES.
+//
+// DoNothing() - Useful for creating a Closure that does nothing when called.
+// DeletePointer() - Useful for creating a Closure that will delete a
+// pointer when invoked. Only use this when necessary.
+// In most cases MessageLoop::DeleteSoon() is a better
+// fit.
+
+#ifndef CEF_INCLUDE_BASE_CEF_BIND_HELPERS_H_
+#define CEF_INCLUDE_BASE_CEF_BIND_HELPERS_H_
+#pragma once
+
+#if defined(BASE_BIND_HELPERS_H_)
+// Do nothing if the Chromium header has already been included.
+// This can happen in cases where Chromium code is used directly by the
+// client application. When using Chromium code directly always include
+// the Chromium header first to avoid type conflicts.
+#elif defined(USING_CHROMIUM_INCLUDES)
+// When building CEF include the Chromium header directly.
+#include "base/bind_helpers.h"
+#else // !USING_CHROMIUM_INCLUDES
+// The following is substantially similar to the Chromium implementation.
+// If the Chromium implementation diverges the below implementation should be
+// updated to match.
+
+#include "include/base/cef_basictypes.h"
+#include "include/base/cef_callback.h"
+#include "include/base/cef_template_util.h"
+#include "include/base/cef_weak_ptr.h"
+
+namespace base {
+namespace cef_internal {
+
+// Use the Substitution Failure Is Not An Error (SFINAE) trick to inspect T
+// for the existence of AddRef() and Release() functions of the correct
+// signature.
+//
+// http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error
+// http://stackoverflow.com/questions/257288/is-it-possible-to-write-a-c-template-to-check-for-a-functions-existence
+// http://stackoverflow.com/questions/4358584/sfinae-approach-comparison
+// http://stackoverflow.com/questions/1966362/sfinae-to-check-for-inherited-member-functions
+//
+// The last link in particular show the method used below.
+//
+// For SFINAE to work with inherited methods, we need to pull some extra tricks
+// with multiple inheritance. In the more standard formulation, the overloads
+// of Check would be:
+//
+// template
+// Yes NotTheCheckWeWant(Helper<&C::TargetFunc>*);
+//
+// template
+// No NotTheCheckWeWant(...);
+//
+// static const bool value = sizeof(NotTheCheckWeWant(0)) == sizeof(Yes);
+//
+// The problem here is that template resolution will not match
+// C::TargetFunc if TargetFunc does not exist directly in C. That is, if
+// TargetFunc in inherited from an ancestor, &C::TargetFunc will not match,
+// |value| will be false. This formulation only checks for whether or
+// not TargetFunc exist directly in the class being introspected.
+//
+// To get around this, we play a dirty trick with multiple inheritance.
+// First, We create a class BaseMixin that declares each function that we
+// want to probe for. Then we create a class Base that inherits from both T
+// (the class we wish to probe) and BaseMixin. Note that the function
+// signature in BaseMixin does not need to match the signature of the function
+// we are probing for; thus it's easiest to just use void(void).
+//
+// Now, if TargetFunc exists somewhere in T, then &Base::TargetFunc has an
+// ambiguous resolution between BaseMixin and T. This lets us write the
+// following:
+//
+// template
+// No GoodCheck(Helper<&C::TargetFunc>*);
+//
+// template
+// Yes GoodCheck(...);
+//
+// static const bool value = sizeof(GoodCheck(0)) == sizeof(Yes);
+//
+// Notice here that the variadic version of GoodCheck() returns Yes here
+// instead of No like the previous one. Also notice that we calculate |value|
+// by specializing GoodCheck() on Base instead of T.
+//
+// We've reversed the roles of the variadic, and Helper overloads.
+// GoodCheck(Helper<&C::TargetFunc>*), when C = Base, fails to be a valid
+// substitution if T::TargetFunc exists. Thus GoodCheck(0) will resolve
+// to the variadic version if T has TargetFunc. If T::TargetFunc does not
+// exist, then &C::TargetFunc is not ambiguous, and the overload resolution
+// will prefer GoodCheck(Helper<&C::TargetFunc>*).
+//
+// This method of SFINAE will correctly probe for inherited names, but it cannot
+// typecheck those names. It's still a good enough sanity check though.
+//
+// Works on gcc-4.2, gcc-4.4, and Visual Studio 2008.
+//
+// TODO(ajwong): Move to ref_counted.h or template_util.h when we've vetted
+// this works well.
+//
+// TODO(ajwong): Make this check for Release() as well.
+// See http://crbug.com/82038.
+template
+class SupportsAddRefAndRelease {
+ typedef char Yes[1];
+ typedef char No[2];
+
+ struct BaseMixin {
+ void AddRef();
+ };
+
+// MSVC warns when you try to use Base if T has a private destructor, the
+// common pattern for refcounted types. It does this even though no attempt to
+// instantiate Base is made. We disable the warning for this definition.
+#if defined(OS_WIN)
+#pragma warning(push)
+#pragma warning(disable : 4624)
+#endif
+ struct Base : public T, public BaseMixin {};
+#if defined(OS_WIN)
+#pragma warning(pop)
+#endif
+
+ template
+ struct Helper {};
+
+ template
+ static No& Check(Helper<&C::AddRef>*);
+
+ template
+ static Yes& Check(...);
+
+ public:
+ static const bool value = sizeof(Check(0)) == sizeof(Yes);
+};
+
+// Helpers to assert that arguments of a recounted type are bound with a
+// scoped_refptr.
+template
+struct UnsafeBindtoRefCountedArgHelper : false_type {};
+
+template
+struct UnsafeBindtoRefCountedArgHelper
+ : integral_constant::value> {};
+
+template
+struct UnsafeBindtoRefCountedArg : false_type {};
+
+template
+struct UnsafeBindtoRefCountedArg
+ : UnsafeBindtoRefCountedArgHelper::value, T> {};
+
+template
+class HasIsMethodTag {
+ typedef char Yes[1];
+ typedef char No[2];
+
+ template
+ static Yes& Check(typename U::IsMethod*);
+
+ template
+ static No& Check(...);
+
+ public:
+ static const bool value = sizeof(Check(0)) == sizeof(Yes);
+};
+
+template
+class UnretainedWrapper {
+ public:
+ explicit UnretainedWrapper(T* o) : ptr_(o) {}
+ T* get() const { return ptr_; }
+
+ private:
+ T* ptr_;
+};
+
+template
+class ConstRefWrapper {
+ public:
+ explicit ConstRefWrapper(const T& o) : ptr_(&o) {}
+ const T& get() const { return *ptr_; }
+
+ private:
+ const T* ptr_;
+};
+
+template
+struct IgnoreResultHelper {
+ explicit IgnoreResultHelper(T functor) : functor_(functor) {}
+
+ T functor_;
+};
+
+template
+struct IgnoreResultHelper> {
+ explicit IgnoreResultHelper(const Callback& functor) : functor_(functor) {}
+
+ const Callback& functor_;
+};
+
+// An alternate implementation is to avoid the destructive copy, and instead
+// specialize ParamTraits<> for OwnedWrapper<> to change the StorageType to
+// a class that is essentially a scoped_ptr<>.
+//
+// The current implementation has the benefit though of leaving ParamTraits<>
+// fully in callback_internal.h as well as avoiding type conversions during
+// storage.
+template
+class OwnedWrapper {
+ public:
+ explicit OwnedWrapper(T* o) : ptr_(o) {}
+ ~OwnedWrapper() { delete ptr_; }
+ T* get() const { return ptr_; }
+ OwnedWrapper(const OwnedWrapper& other) {
+ ptr_ = other.ptr_;
+ other.ptr_ = NULL;
+ }
+
+ private:
+ mutable T* ptr_;
+};
+
+// PassedWrapper is a copyable adapter for a scoper that ignores const.
+//
+// It is needed to get around the fact that Bind() takes a const reference to
+// all its arguments. Because Bind() takes a const reference to avoid
+// unnecessary copies, it is incompatible with movable-but-not-copyable
+// types; doing a destructive "move" of the type into Bind() would violate
+// the const correctness.
+//
+// This conundrum cannot be solved without either C++11 rvalue references or
+// a O(2^n) blowup of Bind() templates to handle each combination of regular
+// types and movable-but-not-copyable types. Thus we introduce a wrapper type
+// that is copyable to transmit the correct type information down into
+// BindState<>. Ignoring const in this type makes sense because it is only
+// created when we are explicitly trying to do a destructive move.
+//
+// Two notes:
+// 1) PassedWrapper supports any type that has a "Pass()" function.
+// This is intentional. The whitelisting of which specific types we
+// support is maintained by CallbackParamTraits<>.
+// 2) is_valid_ is distinct from NULL because it is valid to bind a "NULL"
+// scoper to a Callback and allow the Callback to execute once.
+template
+class PassedWrapper {
+ public:
+ explicit PassedWrapper(T scoper) : is_valid_(true), scoper_(scoper.Pass()) {}
+ PassedWrapper(const PassedWrapper& other)
+ : is_valid_(other.is_valid_), scoper_(other.scoper_.Pass()) {}
+ T Pass() const {
+ CHECK(is_valid_);
+ is_valid_ = false;
+ return scoper_.Pass();
+ }
+
+ private:
+ mutable bool is_valid_;
+ mutable T scoper_;
+};
+
+// Unwrap the stored parameters for the wrappers above.
+template
+struct UnwrapTraits {
+ typedef const T& ForwardType;
+ static ForwardType Unwrap(const T& o) { return o; }
+};
+
+template
+struct UnwrapTraits> {
+ typedef T* ForwardType;
+ static ForwardType Unwrap(UnretainedWrapper unretained) {
+ return unretained.get();
+ }
+};
+
+template
+struct UnwrapTraits> {
+ typedef const T& ForwardType;
+ static ForwardType Unwrap(ConstRefWrapper const_ref) {
+ return const_ref.get();
+ }
+};
+
+template
+struct UnwrapTraits> {
+ typedef T* ForwardType;
+ static ForwardType Unwrap(const scoped_refptr& o) { return o.get(); }
+};
+
+template
+struct UnwrapTraits> {
+ typedef const WeakPtr& ForwardType;
+ static ForwardType Unwrap(const WeakPtr& o) { return o; }
+};
+
+template
+struct UnwrapTraits> {
+ typedef T* ForwardType;
+ static ForwardType Unwrap(const OwnedWrapper& o) { return o.get(); }
+};
+
+template
+struct UnwrapTraits> {
+ typedef T ForwardType;
+ static T Unwrap(PassedWrapper& o) { return o.Pass(); }
+};
+
+// Utility for handling different refcounting semantics in the Bind()
+// function.
+template
+struct MaybeRefcount;
+
+template
+struct MaybeRefcount {
+ static void AddRef(const T&) {}
+ static void Release(const T&) {}
+};
+
+template
+struct MaybeRefcount {
+ static void AddRef(const T*) {}
+ static void Release(const T*) {}
+};
+
+template