Add initial support for API versioning (see #3836)

- Generated files are now created when running cef_create_projects or
  the new version_manager.py tool. These files are still created in the
  cef/ source tree (same location as before) but Git ignores them due to
  the generated .gitignore file.
- API hashes are committed to Git as a new cef_api_versions.json file.
  This file is used for both code generation and CEF version calculation
  (replacing the previous usage of cef_api_hash.h for this purpose).
  It will be updated by the CEF admin before merging breaking API
  changes upstream.
- As an added benefit to the above, contributor PRs will no longer
  contain generated code that is susceptible to frequent merge conflicts.
- From a code generation perspective, the main difference is that we now
  use versioned structs (e.g. cef_browser_0_t instead of cef_browser_t)
  on the libcef (dll/framework) side. Most of the make_*.py tool changes
  are related to supporting this.
- From the client perspective, you can now define CEF_API_VERSION in the
  project configuration (or get CEF_EXPERIMENTAL by default). This
  define will change the API exposed in CEF’s include/ and include/capi
  header files. All client-side targets including libcef_dll_wrapper
  will need be recompiled when changing this define.
- Examples of the new API-related define usage are provided in
  cef_api_version_test.h, api_version_test_impl.cc and
  api_version_unittest.cc.

To test:
- Run `ceftests --gtest_filter=ApiVersionTest.*`
- Add `cef_api_version=13300` to GN_DEFINES. Re-run configure, build and
  ceftests steps.
- Repeat with 13301, 13302, 13303 (all supported test versions).
This commit is contained in:
Marshall Greenblatt
2024-12-09 15:20:44 -05:00
parent 219bf3406c
commit dd81904a2f
68 changed files with 7466 additions and 1265 deletions

View File

@@ -13,8 +13,8 @@
#include "include/base/cef_callback.h"
#include "include/cef_browser.h"
#include "include/cef_command_ids.h"
#include "include/cef_frame.h"
#include "include/cef_id_mappers.h"
#include "include/cef_parser.h"
#include "include/cef_shared_process_message_builder.h"
#include "include/cef_ssl_status.h"
@@ -318,6 +318,32 @@ bool IsAllowedToolbarButton(cef_chrome_toolbar_button_type_t button_type) {
}
bool IsAllowedAppMenuCommandId(int command_id) {
// Version-safe static declarations of IDC variables using names from
// cef_command_ids.h.
CEF_DECLARE_COMMAND_ID(IDC_NEW_WINDOW);
CEF_DECLARE_COMMAND_ID(IDC_NEW_INCOGNITO_WINDOW);
CEF_DECLARE_COMMAND_ID(IDC_ZOOM_MENU);
CEF_DECLARE_COMMAND_ID(IDC_ZOOM_PLUS);
CEF_DECLARE_COMMAND_ID(IDC_ZOOM_NORMAL);
CEF_DECLARE_COMMAND_ID(IDC_ZOOM_MINUS);
CEF_DECLARE_COMMAND_ID(IDC_FULLSCREEN);
CEF_DECLARE_COMMAND_ID(IDC_PRINT);
CEF_DECLARE_COMMAND_ID(IDC_FIND);
CEF_DECLARE_COMMAND_ID(IDC_FIND_NEXT);
CEF_DECLARE_COMMAND_ID(IDC_FIND_PREVIOUS);
CEF_DECLARE_COMMAND_ID(IDC_MORE_TOOLS_MENU);
CEF_DECLARE_COMMAND_ID(IDC_CLEAR_BROWSING_DATA);
CEF_DECLARE_COMMAND_ID(IDC_MANAGE_EXTENSIONS);
CEF_DECLARE_COMMAND_ID(IDC_PERFORMANCE);
CEF_DECLARE_COMMAND_ID(IDC_TASK_MANAGER);
CEF_DECLARE_COMMAND_ID(IDC_DEV_TOOLS);
CEF_DECLARE_COMMAND_ID(IDC_EDIT_MENU);
CEF_DECLARE_COMMAND_ID(IDC_CUT);
CEF_DECLARE_COMMAND_ID(IDC_COPY);
CEF_DECLARE_COMMAND_ID(IDC_PASTE);
CEF_DECLARE_COMMAND_ID(IDC_OPTIONS);
CEF_DECLARE_COMMAND_ID(IDC_EXIT);
// Only the commands in this array will be allowed.
static const int kAllowedCommandIds[] = {
IDC_NEW_WINDOW,
@@ -361,6 +387,28 @@ bool IsAllowedAppMenuCommandId(int command_id) {
}
bool IsAllowedContextMenuCommandId(int command_id) {
// Version-safe static declarations of IDC variables using names from
// cef_command_ids.h.
CEF_DECLARE_COMMAND_ID(IDC_CONTENT_CONTEXT_CUSTOM_FIRST);
CEF_DECLARE_COMMAND_ID(IDC_CONTENT_CONTEXT_CUSTOM_LAST);
CEF_DECLARE_COMMAND_ID(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST);
CEF_DECLARE_COMMAND_ID(IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST);
CEF_DECLARE_COMMAND_ID(IDC_BACK);
CEF_DECLARE_COMMAND_ID(IDC_FORWARD);
CEF_DECLARE_COMMAND_ID(IDC_RELOAD);
CEF_DECLARE_COMMAND_ID(IDC_RELOAD_BYPASSING_CACHE);
CEF_DECLARE_COMMAND_ID(IDC_RELOAD_CLEARING_CACHE);
CEF_DECLARE_COMMAND_ID(IDC_STOP);
CEF_DECLARE_COMMAND_ID(IDC_PRINT);
CEF_DECLARE_COMMAND_ID(IDC_CONTENT_CONTEXT_CUT);
CEF_DECLARE_COMMAND_ID(IDC_CONTENT_CONTEXT_COPY);
CEF_DECLARE_COMMAND_ID(IDC_CONTENT_CONTEXT_PASTE);
CEF_DECLARE_COMMAND_ID(IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE);
CEF_DECLARE_COMMAND_ID(IDC_CONTENT_CONTEXT_DELETE);
CEF_DECLARE_COMMAND_ID(IDC_CONTENT_CONTEXT_SELECTALL);
CEF_DECLARE_COMMAND_ID(IDC_CONTENT_CONTEXT_UNDO);
CEF_DECLARE_COMMAND_ID(IDC_CONTENT_CONTEXT_REDO);
// Allow commands added by web content.
if (command_id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST &&
command_id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) {

View File

@@ -7,7 +7,7 @@
#include "include/cef_app.h"
#import "include/cef_application_mac.h"
#include "include/cef_command_ids.h"
#import "include/cef_id_mappers.h"
#import "include/wrapper/cef_library_loader.h"
#include "tests/cefclient/browser/main_context_impl.h"
#include "tests/cefclient/browser/resource.h"
@@ -404,6 +404,24 @@ void RemoveMenuItem(NSMenu* menu, SEL action_selector) {
//
// This implementation is based on Chromium's AppController class.
- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
// Version-safe static declarations of IDC variables using names from
// cef_command_ids.h.
CEF_DECLARE_COMMAND_ID(IDC_OPEN_FILE);
CEF_DECLARE_COMMAND_ID(IDC_NEW_TAB);
CEF_DECLARE_COMMAND_ID(IDC_FOCUS_LOCATION);
CEF_DECLARE_COMMAND_ID(IDC_FOCUS_SEARCH);
CEF_DECLARE_COMMAND_ID(IDC_SHOW_HISTORY);
CEF_DECLARE_COMMAND_ID(IDC_SHOW_BOOKMARK_MANAGER);
CEF_DECLARE_COMMAND_ID(IDC_CLEAR_BROWSING_DATA);
CEF_DECLARE_COMMAND_ID(IDC_SHOW_DOWNLOADS);
CEF_DECLARE_COMMAND_ID(IDC_IMPORT_SETTINGS);
CEF_DECLARE_COMMAND_ID(IDC_MANAGE_EXTENSIONS);
CEF_DECLARE_COMMAND_ID(IDC_HELP_PAGE_VIA_MENU);
CEF_DECLARE_COMMAND_ID(IDC_OPTIONS);
CEF_DECLARE_COMMAND_ID(IDC_NEW_WINDOW);
CEF_DECLARE_COMMAND_ID(IDC_TASK_MANAGER);
CEF_DECLARE_COMMAND_ID(IDC_NEW_INCOGNITO_WINDOW);
SEL action = [item action];
BOOL enable = NO;
// Whether opening a new browser window is allowed.
@@ -413,37 +431,26 @@ void RemoveMenuItem(NSMenu* menu, SEL action_selector) {
// no key window.
if (action == @selector(commandDispatch:) ||
action == @selector(commandDispatchUsingKeyModifiers:)) {
switch ([item tag]) {
const auto tag = [item tag];
if (tag == IDC_OPEN_FILE || tag == IDC_NEW_TAB ||
tag == IDC_FOCUS_LOCATION || tag == IDC_FOCUS_SEARCH ||
tag == IDC_SHOW_HISTORY || tag == IDC_SHOW_BOOKMARK_MANAGER ||
tag == IDC_CLEAR_BROWSING_DATA || tag == IDC_SHOW_DOWNLOADS ||
tag == IDC_IMPORT_SETTINGS || tag == IDC_MANAGE_EXTENSIONS ||
tag == IDC_HELP_PAGE_VIA_MENU || tag == IDC_OPTIONS) {
// Browser-level items that open in new tabs or perform an action in a
// current tab should not open if there's a window- or app-modal dialog.
case IDC_OPEN_FILE:
case IDC_NEW_TAB:
case IDC_FOCUS_LOCATION:
case IDC_FOCUS_SEARCH:
case IDC_SHOW_HISTORY:
case IDC_SHOW_BOOKMARK_MANAGER:
case IDC_CLEAR_BROWSING_DATA:
case IDC_SHOW_DOWNLOADS:
case IDC_IMPORT_SETTINGS:
case IDC_MANAGE_EXTENSIONS:
case IDC_HELP_PAGE_VIA_MENU:
case IDC_OPTIONS:
enable = canOpenNewBrowser && ![self keyWindowIsModal];
break;
enable = canOpenNewBrowser && ![self keyWindowIsModal];
} else if (tag == IDC_NEW_WINDOW) {
// Browser-level items that open in new windows: allow the user to open
// a new window even if there's a window-modal dialog.
case IDC_NEW_WINDOW:
enable = canOpenNewBrowser;
break;
case IDC_TASK_MANAGER:
enable = YES;
break;
case IDC_NEW_INCOGNITO_WINDOW:
enable = canOpenNewBrowser;
break;
default:
enable = ![self keyWindowIsModal];
break;
enable = canOpenNewBrowser;
} else if (tag == IDC_TASK_MANAGER) {
enable = YES;
} else if (tag == IDC_NEW_INCOGNITO_WINDOW) {
enable = canOpenNewBrowser;
} else {
enable = ![self keyWindowIsModal];
}
} else if ([self respondsToSelector:action]) {
// All other selectors that this class implements.
@@ -469,22 +476,23 @@ void RemoveMenuItem(NSMenu* menu, SEL action_selector) {
}
}
// Version-safe static declarations of IDC variables using names from
// cef_command_ids.h.
CEF_DECLARE_COMMAND_ID(IDC_FIND);
CEF_DECLARE_COMMAND_ID(IDC_FIND_NEXT);
CEF_DECLARE_COMMAND_ID(IDC_FIND_PREVIOUS);
// Handle specific commands where we want to make the last active browser
// frontmost and then re-execute the command.
switch ([sender tag]) {
case IDC_FIND:
case IDC_FIND_NEXT:
case IDC_FIND_PREVIOUS:
if (id window = [self getActiveBrowserNSWindow]) {
[window makeKeyAndOrderFront:nil];
if ([window respondsToSelector:@selector(commandDispatch:)]) {
[window commandDispatch:sender];
return;
}
const auto tag = [sender tag];
if (tag == IDC_FIND || tag == IDC_FIND_NEXT || tag == IDC_FIND_PREVIOUS) {
if (id window = [self getActiveBrowserNSWindow]) {
[window makeKeyAndOrderFront:nil];
if ([window respondsToSelector:@selector(commandDispatch:)]) {
[window commandDispatch:sender];
return;
}
break;
default:
break;
}
}
LOG(INFO) << "Unhandled commandDispatch: for tag " << [sender tag];

View File

@@ -0,0 +1,868 @@
// Copyright (c) 2024 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 <memory>
#include "include/test/cef_api_version_test.h"
#include "tests/ceftests/test_handler.h"
#include "tests/gtest/include/gtest/gtest.h"
namespace {
template <typename T>
static int GetValue(T& obj) {
#if CEF_API_REMOVED(13301)
return obj->GetValue();
#elif CEF_API_RANGE(13301, 13302)
return obj->GetValueV1();
#elif CEF_API_ADDED(13302)
return obj->GetValueV2();
#endif
}
CefRefPtr<CefApiVersionTestRefPtrLibrary> CreateRefPtrLibrary(int val) {
#if CEF_API_ADDED(13301)
return CefApiVersionTestRefPtrLibrary::Create(val);
#else
auto obj = CefApiVersionTestRefPtrLibrary::Create();
obj->SetValue(val);
return obj;
#endif
}
CefRefPtr<CefApiVersionTestRefPtrLibraryChild> CreateRefPtrLibraryChild(
int val1,
int val2) {
#if CEF_API_ADDED(13301)
return CefApiVersionTestRefPtrLibraryChild::Create(val1, val2);
#else
auto obj = CefApiVersionTestRefPtrLibraryChild::Create();
obj->SetValue(val1);
obj->SetOtherValue(val2);
return obj;
#endif
}
#if CEF_API_REMOVED(13301)
CefRefPtr<CefApiVersionTestRefPtrLibraryChildChild>
#elif CEF_API_RANGE(13301, 13302)
CefRefPtr<CefApiVersionTestRefPtrLibraryChildChildV1>
#elif CEF_API_ADDED(13302)
CefRefPtr<CefApiVersionTestRefPtrLibraryChildChildV2>
#endif
CreateRefPtrLibraryChildChild(int val1, int val2, int val3) {
#if CEF_API_REMOVED(13301)
auto obj = CefApiVersionTestRefPtrLibraryChildChild::Create();
obj->SetValue(val1);
obj->SetOtherValue(val2);
obj->SetOtherOtherValue(val3);
return obj;
#elif CEF_API_RANGE(13301, 13302)
return CefApiVersionTestRefPtrLibraryChildChildV1::Create(val1, val2, val3);
#elif CEF_API_ADDED(13302)
return CefApiVersionTestRefPtrLibraryChildChildV2::Create(val1, val2, val3);
#endif
}
} // namespace
// Test getting/setting library-side RefPtr types.
TEST(ApiVersionTest, RefPtrLibrary) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kTestVal = 12;
CefRefPtr<CefApiVersionTestRefPtrLibrary> test_obj =
CreateRefPtrLibrary(kTestVal);
EXPECT_EQ(kTestVal, GetValue(test_obj));
int retval = obj->SetRefPtrLibrary(test_obj);
EXPECT_EQ(kTestVal, retval);
EXPECT_EQ(kTestVal, GetValue(test_obj));
const int kTestVal2 = 30;
CefRefPtr<CefApiVersionTestRefPtrLibrary> test_obj2 =
obj->GetRefPtrLibrary(kTestVal2);
EXPECT_EQ(kTestVal2, GetValue(test_obj2));
int retval2 = obj->SetRefPtrLibrary(test_obj2);
EXPECT_EQ(kTestVal2, retval2);
EXPECT_EQ(kTestVal2, GetValue(test_obj2));
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
EXPECT_TRUE(test_obj->HasOneRef());
EXPECT_TRUE(test_obj2->HasOneRef());
}
// Test getting/setting inherited library-side RefPtr types.
TEST(ApiVersionTest, RefPtrLibraryInherit) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kTestVal = 12;
const int kTestVal2 = 40;
auto test_obj = CreateRefPtrLibraryChild(kTestVal, kTestVal2);
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
int retval = obj->SetRefPtrLibrary(test_obj);
EXPECT_EQ(kTestVal, retval);
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
EXPECT_EQ(kTestVal, obj->SetChildRefPtrLibrary(test_obj));
auto parent = obj->SetChildRefPtrLibraryAndReturnParent(test_obj);
EXPECT_EQ(kTestVal, GetValue(parent));
parent = nullptr;
const int kTestVal3 = 100;
auto test_obj2 =
CreateRefPtrLibraryChildChild(kTestVal, kTestVal2, kTestVal3);
EXPECT_EQ(kTestVal, GetValue(test_obj2));
EXPECT_EQ(kTestVal2, test_obj2->GetOtherValue());
EXPECT_EQ(kTestVal3, test_obj2->GetOtherOtherValue());
int retval2 = obj->SetRefPtrLibrary(test_obj2);
EXPECT_EQ(kTestVal, retval2);
EXPECT_EQ(kTestVal, GetValue(test_obj2));
EXPECT_EQ(kTestVal2, test_obj2->GetOtherValue());
EXPECT_EQ(kTestVal3, test_obj2->GetOtherOtherValue());
EXPECT_EQ(kTestVal, obj->SetChildRefPtrLibrary(test_obj2));
auto parent2 = obj->SetChildRefPtrLibraryAndReturnParent(test_obj2);
EXPECT_EQ(kTestVal, GetValue(parent2));
parent2 = nullptr;
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
EXPECT_TRUE(test_obj->HasOneRef());
EXPECT_TRUE(test_obj2->HasOneRef());
}
// Test getting/setting library-side RefPtr list types.
TEST(ApiVersionTest, RefPtrLibraryList) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kVal1 = 34;
const int kVal2 = 10;
CefRefPtr<CefApiVersionTestRefPtrLibrary> val1 = CreateRefPtrLibrary(kVal1);
CefRefPtr<CefApiVersionTestRefPtrLibrary> val2 =
CreateRefPtrLibraryChild(kVal2, 0);
std::vector<CefRefPtr<CefApiVersionTestRefPtrLibrary>> list;
list.push_back(val1);
list.push_back(val2);
EXPECT_TRUE(obj->SetRefPtrLibraryList(list, kVal1, kVal2));
list.clear();
EXPECT_TRUE(obj->GetRefPtrLibraryListByRef(list, kVal1, kVal2));
EXPECT_EQ(2U, list.size());
EXPECT_EQ(kVal1, GetValue(list[0]));
EXPECT_EQ(kVal2, GetValue(list[1]));
list.clear();
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
EXPECT_TRUE(val1->HasOneRef());
EXPECT_TRUE(val2->HasOneRef());
}
namespace {
class ApiVersionTestRefPtrClient : public CefApiVersionTestRefPtrClient {
public:
explicit ApiVersionTestRefPtrClient(int val) : val_(val) {}
int GetValueLegacy() override { return val_legacy_; }
#if CEF_API_ADDED(CEF_EXPERIMENTAL)
int GetValueExp() override { return val_exp_; }
#endif
#if CEF_API_REMOVED(13301)
int GetValue() override { return val_; }
#elif CEF_API_RANGE(13301, 13302)
int GetValueV1() override { return val_; }
#elif CEF_API_ADDED(13302)
int GetValueV2() override { return val_; }
#endif
private:
const int val_;
int val_legacy_ = -1;
#if CEF_API_ADDED(CEF_EXPERIMENTAL)
int val_exp_ = -1;
#endif
IMPLEMENT_REFCOUNTING(ApiVersionTestRefPtrClient);
DISALLOW_COPY_AND_ASSIGN(ApiVersionTestRefPtrClient);
};
#if CEF_API_REMOVED(13302)
class ApiVersionTestRefPtrClientChild
: public CefApiVersionTestRefPtrClientChild {
public:
ApiVersionTestRefPtrClientChild(int val, int other_val)
: val_(val), other_val_(other_val) {}
int GetValueLegacy() override { return val_legacy_; }
#if CEF_API_ADDED(CEF_EXPERIMENTAL)
int GetValueExp() override { return val_exp_; }
#endif
#if CEF_API_REMOVED(13301)
int GetValue() override { return val_; }
#elif CEF_API_RANGE(13301, 13302)
int GetValueV1() override { return val_; }
#elif CEF_API_ADDED(13302)
int GetValueV2() override { return val_; }
#endif
#if CEF_API_REMOVED(13301)
int GetOtherValue() override { return other_val_; }
#else
int GetOtherValueV1() override { return other_val_; }
#endif
private:
const int val_;
const int other_val_;
int val_legacy_ = -1;
#if CEF_API_ADDED(CEF_EXPERIMENTAL)
int val_exp_ = -1;
#endif
IMPLEMENT_REFCOUNTING(ApiVersionTestRefPtrClientChild);
DISALLOW_COPY_AND_ASSIGN(ApiVersionTestRefPtrClientChild);
};
using ApiVersionTestRefPtrClientChildType = ApiVersionTestRefPtrClientChild;
#else // CEF_API_ADDED(13302)
class ApiVersionTestRefPtrClientChildV2
: public CefApiVersionTestRefPtrClientChildV2 {
public:
ApiVersionTestRefPtrClientChildV2(int val, int other_val)
: val_(val), other_val_(other_val) {}
int GetValueLegacy() override { return val_legacy_; }
#if CEF_API_ADDED(CEF_EXPERIMENTAL)
int GetValueExp() override { return val_exp_; }
#endif
#if CEF_API_REMOVED(13301)
int GetValue() override { return val_; }
#elif CEF_API_RANGE(13301, 13302)
int GetValueV1() override { return val_; }
#elif CEF_API_ADDED(13302)
int GetValueV2() override { return val_; }
#endif
int GetOtherValue() override { return other_val_; }
#if CEF_API_ADDED(13303)
int GetAnotherValue() override { return another_val_; }
#endif
private:
const int val_;
const int other_val_;
#if CEF_API_ADDED(13303)
int another_val_ = -1;
#endif
int val_legacy_ = -1;
#if CEF_API_ADDED(CEF_EXPERIMENTAL)
int val_exp_ = -1;
#endif
IMPLEMENT_REFCOUNTING(ApiVersionTestRefPtrClientChildV2);
DISALLOW_COPY_AND_ASSIGN(ApiVersionTestRefPtrClientChildV2);
};
using ApiVersionTestRefPtrClientChildType = ApiVersionTestRefPtrClientChildV2;
#endif // CEF_API_ADDED(13302)
template <typename T>
static int GetOtherValue(T& obj) {
#if CEF_API_REMOVED(13301)
// ApiVersionTestRefPtrClientChild
return obj->GetOtherValue();
#elif CEF_API_RANGE(13301, 13302)
// ApiVersionTestRefPtrClientChild
return obj->GetOtherValueV1();
#elif CEF_API_ADDED(13302)
// ApiVersionTestRefPtrClientChildV2
return obj->GetOtherValue();
#endif
}
} // namespace
// Test getting/setting client-side RefPtr types.
TEST(ApiVersionTest, RefPtrClient) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kTestVal = 12;
CefRefPtr<ApiVersionTestRefPtrClient> test_obj =
new ApiVersionTestRefPtrClient(kTestVal);
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal, obj->SetRefPtrClient(test_obj.get()));
CefRefPtr<CefApiVersionTestRefPtrClient> handler =
obj->SetRefPtrClientAndReturn(test_obj.get());
EXPECT_EQ(test_obj.get(), handler.get());
EXPECT_EQ(kTestVal, GetValue(handler));
handler = nullptr;
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
EXPECT_TRUE(test_obj->HasOneRef());
}
// Test getting/setting inherited client-side RefPtr types.
TEST(ApiVersionTest, RefPtrClientInherit) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kTestVal = 12;
const int kTestVal2 = 86;
CefRefPtr<ApiVersionTestRefPtrClientChildType> test_obj =
new ApiVersionTestRefPtrClientChildType(kTestVal, kTestVal2);
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal2, GetOtherValue(test_obj));
int retval = obj->SetRefPtrClient(test_obj);
EXPECT_EQ(kTestVal, retval);
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal2, GetOtherValue(test_obj));
EXPECT_EQ(kTestVal, obj->SetChildRefPtrClient(test_obj));
CefRefPtr<CefApiVersionTestRefPtrClient> handler =
obj->SetChildRefPtrClientAndReturnParent(test_obj);
EXPECT_EQ(kTestVal, GetValue(handler));
EXPECT_EQ(test_obj.get(), handler.get());
handler = nullptr;
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
EXPECT_TRUE(test_obj->HasOneRef());
}
// Test getting/setting client-side RefPtr list types.
TEST(ApiVersionTest, RefPtrClientList) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kVal1 = 34;
const int kVal2 = 10;
CefRefPtr<CefApiVersionTestRefPtrClient> val1 =
new ApiVersionTestRefPtrClient(kVal1);
CefRefPtr<CefApiVersionTestRefPtrClient> val2 =
new ApiVersionTestRefPtrClientChildType(kVal2, 0);
std::vector<CefRefPtr<CefApiVersionTestRefPtrClient>> list;
list.push_back(val1);
list.push_back(val2);
EXPECT_TRUE(obj->SetRefPtrClientList(list, kVal1, kVal2));
list.clear();
EXPECT_TRUE(obj->GetRefPtrClientListByRef(list, val1, val2));
EXPECT_EQ(2U, list.size());
EXPECT_EQ(kVal1, GetValue(list[0]));
EXPECT_EQ(val1.get(), list[0].get());
EXPECT_EQ(kVal2, GetValue(list[1]));
EXPECT_EQ(val2.get(), list[1].get());
list.clear();
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
EXPECT_TRUE(val1->HasOneRef());
EXPECT_TRUE(val2->HasOneRef());
}
namespace {
CefOwnPtr<CefApiVersionTestScopedLibrary> CreateScopedLibrary(int val) {
#if CEF_API_ADDED(13301)
return CefApiVersionTestScopedLibrary::Create(val);
#else
auto obj = CefApiVersionTestScopedLibrary::Create();
obj->SetValue(val);
return obj;
#endif
}
CefOwnPtr<CefApiVersionTestScopedLibraryChild> CreateScopedLibraryChild(
int val1,
int val2) {
#if CEF_API_ADDED(13301)
return CefApiVersionTestScopedLibraryChild::Create(val1, val2);
#else
auto obj = CefApiVersionTestScopedLibraryChild::Create();
obj->SetValue(val1);
obj->SetOtherValue(val2);
return obj;
#endif
}
#if CEF_API_REMOVED(13301)
CefOwnPtr<CefApiVersionTestScopedLibraryChildChild>
#elif CEF_API_RANGE(13301, 13302)
CefOwnPtr<CefApiVersionTestScopedLibraryChildChildV1>
#elif CEF_API_ADDED(13302)
CefOwnPtr<CefApiVersionTestScopedLibraryChildChildV2>
#endif
CreateScopedLibraryChildChild(int val1, int val2, int val3) {
#if CEF_API_REMOVED(13301)
auto obj = CefApiVersionTestScopedLibraryChildChild::Create();
obj->SetValue(val1);
obj->SetOtherValue(val2);
obj->SetOtherOtherValue(val3);
return obj;
#elif CEF_API_RANGE(13301, 13302)
return CefApiVersionTestScopedLibraryChildChildV1::Create(val1, val2, val3);
#elif CEF_API_ADDED(13302)
return CefApiVersionTestScopedLibraryChildChildV2::Create(val1, val2, val3);
#endif
}
} // namespace
// Test getting/setting library-side OwnPtr types.
TEST(ApiVersionTest, OwnPtrLibrary) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kTestVal = 12;
CefOwnPtr<CefApiVersionTestScopedLibrary> test_obj =
CreateScopedLibrary(kTestVal);
EXPECT_TRUE(test_obj.get());
EXPECT_EQ(kTestVal, GetValue(test_obj));
int retval = obj->SetOwnPtrLibrary(std::move(test_obj));
EXPECT_EQ(kTestVal, retval);
EXPECT_FALSE(test_obj.get());
const int kTestVal2 = 30;
CefOwnPtr<CefApiVersionTestScopedLibrary> test_obj2 =
obj->GetOwnPtrLibrary(kTestVal2);
EXPECT_TRUE(test_obj2.get());
EXPECT_EQ(kTestVal2, GetValue(test_obj2));
int retval2 = obj->SetOwnPtrLibrary(std::move(test_obj2));
EXPECT_EQ(kTestVal2, retval2);
EXPECT_FALSE(test_obj2.get());
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
}
// Test getting/setting inherited library-side OwnPtr types.
TEST(ApiVersionTest, OwnPtrLibraryInherit) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kTestVal = 12;
const int kTestVal2 = 40;
auto test_obj = CreateScopedLibraryChild(kTestVal, kTestVal2);
EXPECT_TRUE(test_obj.get());
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
int retval = obj->SetOwnPtrLibrary(std::move(test_obj));
EXPECT_EQ(kTestVal, retval);
EXPECT_FALSE(test_obj.get());
test_obj = CreateScopedLibraryChild(kTestVal, kTestVal2);
EXPECT_TRUE(test_obj.get());
EXPECT_EQ(kTestVal, obj->SetChildOwnPtrLibrary(std::move(test_obj)));
EXPECT_FALSE(test_obj.get());
test_obj = CreateScopedLibraryChild(kTestVal, kTestVal2);
EXPECT_TRUE(test_obj.get());
CefOwnPtr<CefApiVersionTestScopedLibrary> test_obj_parent =
obj->SetChildOwnPtrLibraryAndReturnParent(std::move(test_obj));
EXPECT_FALSE(test_obj.get());
EXPECT_TRUE(test_obj_parent.get());
EXPECT_EQ(kTestVal, GetValue(test_obj_parent));
test_obj_parent.reset(nullptr);
const int kTestVal3 = 100;
auto test_obj2 =
CreateScopedLibraryChildChild(kTestVal, kTestVal2, kTestVal3);
EXPECT_EQ(kTestVal, GetValue(test_obj2));
EXPECT_EQ(kTestVal2, test_obj2->GetOtherValue());
EXPECT_EQ(kTestVal3, test_obj2->GetOtherOtherValue());
int retval2 = obj->SetOwnPtrLibrary(std::move(test_obj2));
EXPECT_EQ(kTestVal, retval2);
EXPECT_FALSE(test_obj2.get());
test_obj2 = CreateScopedLibraryChildChild(kTestVal, kTestVal2, kTestVal3);
EXPECT_EQ(kTestVal, obj->SetChildOwnPtrLibrary(std::move(test_obj2)));
EXPECT_FALSE(test_obj2.get());
test_obj2 = CreateScopedLibraryChildChild(kTestVal, kTestVal2, kTestVal3);
test_obj_parent =
obj->SetChildOwnPtrLibraryAndReturnParent(std::move(test_obj2));
EXPECT_FALSE(test_obj2.get());
EXPECT_TRUE(test_obj_parent.get());
EXPECT_EQ(kTestVal, GetValue(test_obj_parent));
test_obj_parent.reset(nullptr);
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
}
namespace {
class ApiVersionTestScopedClient : public CefApiVersionTestScopedClient {
public:
ApiVersionTestScopedClient(int val, TrackCallback* got_delete)
: val_(val), got_delete_(got_delete) {}
~ApiVersionTestScopedClient() override { got_delete_->yes(); }
int GetValueLegacy() override { return val_legacy_; }
#if CEF_API_ADDED(CEF_EXPERIMENTAL)
int GetValueExp() override { return val_exp_; }
#endif
#if CEF_API_REMOVED(13301)
int GetValue() override { return val_; }
#elif CEF_API_RANGE(13301, 13302)
int GetValueV1() override { return val_; }
#elif CEF_API_ADDED(13302)
int GetValueV2() override { return val_; }
#endif
private:
const int val_;
int val_legacy_ = -1;
#if CEF_API_ADDED(CEF_EXPERIMENTAL)
int val_exp_ = -1;
#endif
TrackCallback* got_delete_;
DISALLOW_COPY_AND_ASSIGN(ApiVersionTestScopedClient);
};
#if CEF_API_REMOVED(13302)
class ApiVersionTestScopedClientChild
: public CefApiVersionTestScopedClientChild {
public:
ApiVersionTestScopedClientChild(int val,
int other_val,
TrackCallback* got_delete)
: val_(val), other_val_(other_val), got_delete_(got_delete) {}
~ApiVersionTestScopedClientChild() override { got_delete_->yes(); }
int GetValueLegacy() override { return val_legacy_; }
#if CEF_API_ADDED(CEF_EXPERIMENTAL)
int GetValueExp() override { return val_exp_; }
#endif
#if CEF_API_REMOVED(13301)
int GetValue() override { return val_; }
#elif CEF_API_RANGE(13301, 13302)
int GetValueV1() override { return val_; }
#elif CEF_API_ADDED(13302)
int GetValueV2() override { return val_; }
#endif
#if CEF_API_REMOVED(13301)
int GetOtherValue() override { return other_val_; }
#else
int GetOtherValueV1() override { return other_val_; }
#endif
private:
const int val_;
const int other_val_;
int val_legacy_ = -1;
#if CEF_API_ADDED(CEF_EXPERIMENTAL)
int val_exp_ = -1;
#endif
TrackCallback* got_delete_;
DISALLOW_COPY_AND_ASSIGN(ApiVersionTestScopedClientChild);
};
using ApiVersionTestScopedClientChildType = ApiVersionTestScopedClientChild;
#else // CEF_API_ADDED(13302)
class ApiVersionTestScopedClientChildV2
: public CefApiVersionTestScopedClientChildV2 {
public:
ApiVersionTestScopedClientChildV2(int val,
int other_val,
TrackCallback* got_delete)
: val_(val), other_val_(other_val), got_delete_(got_delete) {}
~ApiVersionTestScopedClientChildV2() override { got_delete_->yes(); }
int GetValueLegacy() override { return val_legacy_; }
#if CEF_API_ADDED(CEF_EXPERIMENTAL)
int GetValueExp() override { return val_exp_; }
#endif
#if CEF_API_REMOVED(13301)
int GetValue() override { return val_; }
#elif CEF_API_RANGE(13301, 13302)
int GetValueV1() override { return val_; }
#elif CEF_API_ADDED(13302)
int GetValueV2() override { return val_; }
#endif
int GetOtherValue() override { return other_val_; }
#if CEF_API_ADDED(13303)
int GetAnotherValue() override { return another_val_; }
#endif
private:
const int val_;
const int other_val_;
#if CEF_API_ADDED(13303)
int another_val_ = -1;
#endif
int val_legacy_ = -1;
#if CEF_API_ADDED(CEF_EXPERIMENTAL)
int val_exp_ = -1;
#endif
TrackCallback* got_delete_;
DISALLOW_COPY_AND_ASSIGN(ApiVersionTestScopedClientChildV2);
};
using ApiVersionTestScopedClientChildType = ApiVersionTestScopedClientChildV2;
#endif // CEF_API_ADDED(13302)
} // namespace
// Test getting/setting client-side OwnPtr types.
TEST(ApiVersionTest, OwnPtrClient) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kTestVal = 12;
TrackCallback got_delete;
CefOwnPtr<CefApiVersionTestScopedClient> test_obj(
new ApiVersionTestScopedClient(kTestVal, &got_delete));
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal, obj->SetOwnPtrClient(std::move(test_obj)));
EXPECT_FALSE(test_obj.get());
EXPECT_TRUE(got_delete);
got_delete.reset();
test_obj =
std::make_unique<ApiVersionTestScopedClient>(kTestVal, &got_delete);
CefOwnPtr<CefApiVersionTestScopedClient> handler =
obj->SetOwnPtrClientAndReturn(std::move(test_obj));
EXPECT_FALSE(test_obj.get());
EXPECT_TRUE(handler.get());
EXPECT_FALSE(got_delete);
EXPECT_EQ(kTestVal, GetValue(handler));
handler.reset(nullptr);
EXPECT_TRUE(got_delete);
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
}
// Test getting/setting inherited client-side OwnPtr types.
TEST(ApiVersionTest, OwnPtrClientInherit) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kTestVal = 12;
const int kTestVal2 = 86;
TrackCallback got_delete;
CefOwnPtr<ApiVersionTestScopedClientChildType> test_obj(
new ApiVersionTestScopedClientChildType(kTestVal, kTestVal2,
&got_delete));
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal2, GetOtherValue(test_obj));
EXPECT_EQ(kTestVal, obj->SetOwnPtrClient(std::move(test_obj)));
EXPECT_FALSE(test_obj.get());
EXPECT_TRUE(got_delete);
got_delete.reset();
test_obj = std::make_unique<ApiVersionTestScopedClientChildType>(
kTestVal, kTestVal2, &got_delete);
EXPECT_EQ(kTestVal, obj->SetChildOwnPtrClient(std::move(test_obj)));
EXPECT_FALSE(test_obj.get());
EXPECT_TRUE(got_delete);
got_delete.reset();
test_obj = std::make_unique<ApiVersionTestScopedClientChildType>(
kTestVal, kTestVal2, &got_delete);
CefOwnPtr<CefApiVersionTestScopedClient> handler(
obj->SetChildOwnPtrClientAndReturnParent(std::move(test_obj)));
EXPECT_EQ(kTestVal, GetValue(handler));
EXPECT_FALSE(test_obj.get());
EXPECT_FALSE(got_delete);
handler.reset(nullptr);
EXPECT_TRUE(got_delete);
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
}
// Test getting/setting library-side RawPtr types.
TEST(ApiVersionTest, RawPtrLibrary) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kTestVal = 12;
auto test_obj = CreateScopedLibrary(kTestVal);
EXPECT_EQ(kTestVal, GetValue(test_obj));
int retval = obj->SetRawPtrLibrary(test_obj.get());
EXPECT_EQ(kTestVal, retval);
EXPECT_EQ(kTestVal, GetValue(test_obj));
const int kTestVal2 = 30;
auto test_obj2 = obj->GetOwnPtrLibrary(kTestVal2);
EXPECT_EQ(kTestVal2, GetValue(test_obj2));
int retval2 = obj->SetRawPtrLibrary(test_obj2.get());
EXPECT_EQ(kTestVal2, retval2);
EXPECT_EQ(kTestVal2, GetValue(test_obj2));
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
}
// Test getting/setting inherited library-side RawPtr types.
TEST(ApiVersionTest, RawPtrLibraryInherit) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kTestVal = 12;
const int kTestVal2 = 40;
auto test_obj = CreateScopedLibraryChild(kTestVal, kTestVal2);
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
int retval = obj->SetRawPtrLibrary(test_obj.get());
EXPECT_EQ(kTestVal, retval);
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
EXPECT_EQ(kTestVal, obj->SetChildRawPtrLibrary(test_obj.get()));
const int kTestVal3 = 100;
auto test_obj2 =
CreateScopedLibraryChildChild(kTestVal, kTestVal2, kTestVal3);
EXPECT_EQ(kTestVal, GetValue(test_obj2));
EXPECT_EQ(kTestVal2, test_obj2->GetOtherValue());
EXPECT_EQ(kTestVal3, test_obj2->GetOtherOtherValue());
int retval2 = obj->SetRawPtrLibrary(test_obj2.get());
EXPECT_EQ(kTestVal, retval2);
EXPECT_EQ(kTestVal, GetValue(test_obj2));
EXPECT_EQ(kTestVal2, test_obj2->GetOtherValue());
EXPECT_EQ(kTestVal3, test_obj2->GetOtherOtherValue());
EXPECT_EQ(kTestVal, obj->SetChildRawPtrLibrary(test_obj2.get()));
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
}
// Test getting/setting library-side RawPtr list types.
TEST(ApiVersionTest, RawPtrLibraryList) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kVal1 = 34;
const int kVal2 = 10;
auto val1 = CreateScopedLibrary(kVal1);
auto val2 = CreateScopedLibraryChild(kVal2, 0);
std::vector<CefRawPtr<CefApiVersionTestScopedLibrary>> list;
list.push_back(val1.get());
list.push_back(val2.get());
EXPECT_TRUE(obj->SetRawPtrLibraryList(list, kVal1, kVal2));
list.clear();
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
}
// Test getting/setting client-side RawPtr types.
TEST(ApiVersionTest, RawPtrClient) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kTestVal = 12;
TrackCallback got_delete;
CefOwnPtr<ApiVersionTestScopedClient> test_obj(
new ApiVersionTestScopedClient(kTestVal, &got_delete));
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal, obj->SetRawPtrClient(test_obj.get()));
EXPECT_FALSE(got_delete);
test_obj.reset(nullptr);
EXPECT_TRUE(got_delete);
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
}
// Test getting/setting inherited client-side RawPtr types.
TEST(ApiVersionTest, RawPtrClientInherit) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kTestVal = 12;
const int kTestVal2 = 86;
TrackCallback got_delete;
CefOwnPtr<ApiVersionTestScopedClientChildType> test_obj(
new ApiVersionTestScopedClientChildType(kTestVal, kTestVal2,
&got_delete));
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal2, GetOtherValue(test_obj));
int retval = obj->SetRawPtrClient(test_obj.get());
EXPECT_EQ(kTestVal, retval);
EXPECT_EQ(kTestVal, GetValue(test_obj));
EXPECT_EQ(kTestVal2, GetOtherValue(test_obj));
EXPECT_FALSE(got_delete);
EXPECT_EQ(kTestVal, obj->SetChildRawPtrClient(test_obj.get()));
EXPECT_FALSE(got_delete);
test_obj.reset(nullptr);
EXPECT_TRUE(got_delete);
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
}
// Test getting/setting client-side RawPtr list types.
TEST(ApiVersionTest, RawPtrClientList) {
CefRefPtr<CefApiVersionTest> obj = CefApiVersionTest::Create();
const int kVal1 = 34;
const int kVal2 = 10;
TrackCallback got_delete1, got_delete2;
CefOwnPtr<CefApiVersionTestScopedClient> val1(
new ApiVersionTestScopedClient(kVal1, &got_delete1));
CefOwnPtr<CefApiVersionTestScopedClient> val2(
new ApiVersionTestScopedClientChildType(kVal2, 0, &got_delete2));
std::vector<CefRawPtr<CefApiVersionTestScopedClient>> list;
list.push_back(val1.get());
list.push_back(val2.get());
EXPECT_TRUE(obj->SetRawPtrClientList(list, kVal1, kVal2));
list.clear();
EXPECT_FALSE(got_delete1);
val1.reset(nullptr);
EXPECT_TRUE(got_delete1);
EXPECT_FALSE(got_delete2);
val2.reset(nullptr);
EXPECT_TRUE(got_delete2);
// Only one reference to the object should exist.
EXPECT_TRUE(obj->HasOneRef());
}

View File

@@ -3,7 +3,6 @@
// can be found in the LICENSE file.
#include "include/base/cef_callback.h"
#include "include/cef_pack_resources.h"
#include "include/cef_request_context_handler.h"
#include "include/wrapper/cef_closure_task.h"
#include "include/wrapper/cef_stream_resource_handler.h"

View File

@@ -18,6 +18,7 @@
#endif
#include "include/base/cef_callback.h"
#include "include/cef_api_hash.h"
#include "include/cef_app.h"
#include "include/cef_task.h"
#include "include/cef_thread.h"
@@ -136,6 +137,10 @@ class ScopedPlatformSetup final {
int main(int argc, char* argv[]) {
int exit_code;
#if CEF_API_VERSION != CEF_EXPERIMENTAL
printf("Running with configured CEF API version %d\n", CEF_API_VERSION);
#endif
#if defined(OS_WIN) && defined(ARCH_CPU_32_BITS)
// Run the main thread on 32-bit Windows using a fiber with the preferred 4MiB
// stack size. This function must be called at the top of the executable entry

View File

@@ -3,7 +3,7 @@
// can be found in the LICENSE file.
#include "include/cef_api_hash.h"
#include "include/cef_version.h"
#include "include/cef_version_info.h"
#include "tests/gtest/include/gtest/gtest.h"
TEST(VersionTest, VersionInfo) {
@@ -18,7 +18,7 @@ TEST(VersionTest, VersionInfo) {
}
TEST(VersionTest, ApiHash) {
EXPECT_STREQ(CEF_API_HASH_PLATFORM, cef_api_hash(0));
EXPECT_STREQ(CEF_API_HASH_UNIVERSAL, cef_api_hash(1));
EXPECT_STREQ(CEF_COMMIT_HASH, cef_api_hash(2));
EXPECT_STREQ(CEF_API_HASH_PLATFORM, cef_api_hash(CEF_API_VERSION, 0));
EXPECT_STREQ(CEF_API_HASH_UNIVERSAL, cef_api_hash(CEF_API_VERSION, 1));
EXPECT_STREQ(CEF_COMMIT_HASH, cef_api_hash(CEF_API_VERSION, 2));
}

View File

@@ -3,7 +3,6 @@
// can be found in the LICENSE file.
#include "include/base/cef_callback.h"
#include "include/cef_pack_strings.h"
#include "include/views/cef_panel.h"
#include "include/views/cef_panel_delegate.h"
#include "include/views/cef_scroll_view.h"

View File

@@ -3,7 +3,6 @@
// can be found in the LICENSE file.
#include "include/base/cef_callback.h"
#include "include/cef_pack_strings.h"
#include "include/views/cef_textfield.h"
#include "include/views/cef_textfield_delegate.h"
#include "include/wrapper/cef_closure_task.h"