sparkbun 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/sparkbun.cjs +18 -0
- package/dist-linux-arm64/bsdiff +0 -0
- package/dist-linux-arm64/bspatch +0 -0
- package/dist-linux-arm64/libElectrobunCore.so +0 -0
- package/dist-linux-arm64/libNativeWrapper.so +0 -0
- package/dist-linux-arm64/libasar.so +0 -0
- package/dist-linux-x64/bsdiff +0 -0
- package/dist-linux-x64/bspatch +0 -0
- package/dist-linux-x64/libElectrobunCore.so +0 -0
- package/dist-linux-x64/libNativeWrapper.so +0 -0
- package/dist-linux-x64/libasar.so +0 -0
- package/dist-macos-arm64/bsdiff +0 -0
- package/dist-macos-arm64/bspatch +0 -0
- package/dist-macos-arm64/libElectrobunCore.dylib +0 -0
- package/dist-macos-arm64/libNativeWrapper.dylib +0 -0
- package/dist-macos-arm64/libasar.dylib +0 -0
- package/dist-macos-arm64/libwebgpu_dawn.dylib +0 -0
- package/dist-macos-arm64/preload-full.js +885 -0
- package/dist-macos-arm64/preload-sandboxed.js +111 -0
- package/dist-macos-arm64/process_helper +0 -0
- package/dist-win-x64/ElectrobunCore.dll +0 -0
- package/dist-win-x64/WebView2Loader.dll +0 -0
- package/dist-win-x64/bsdiff.exe +0 -0
- package/dist-win-x64/bspatch.exe +0 -0
- package/dist-win-x64/libNativeWrapper.dll +0 -0
- package/dist-win-x64/zig-asar/arm64/libasar.dll +0 -0
- package/dist-win-x64/zig-asar/x64/libasar.dll +0 -0
- package/package.json +47 -0
- package/scripts/build-and-upload-artifacts.js +207 -0
- package/scripts/gen-webgpu-ffi.mjs +162 -0
- package/scripts/install-windows-deps.ps1 +80 -0
- package/scripts/package-release.js +237 -0
- package/scripts/push-version.js +84 -0
- package/scripts/update-bun-version.ts +122 -0
- package/scripts/update-cef-version.ts +145 -0
- package/src/browser/builtinrpcSchema.ts +19 -0
- package/src/browser/global.d.ts +36 -0
- package/src/browser/index.ts +234 -0
- package/src/browser/webviewtag.ts +88 -0
- package/src/browser/wgputag.ts +48 -0
- package/src/bun/SparkBunConfig.ts +497 -0
- package/src/bun/__tests__/ffi-contract.test.ts +105 -0
- package/src/bun/core/ApplicationMenu.ts +70 -0
- package/src/bun/core/BrowserView.ts +416 -0
- package/src/bun/core/BrowserWindow.ts +396 -0
- package/src/bun/core/BuildConfig.ts +71 -0
- package/src/bun/core/ContextMenu.ts +75 -0
- package/src/bun/core/GpuWindow.ts +289 -0
- package/src/bun/core/Paths.ts +5 -0
- package/src/bun/core/Socket.ts +22 -0
- package/src/bun/core/Tray.ts +197 -0
- package/src/bun/core/Updater.ts +1131 -0
- package/src/bun/core/Utils.ts +487 -0
- package/src/bun/core/WGPUView.ts +167 -0
- package/src/bun/core/menuRoles.ts +181 -0
- package/src/bun/events/ApplicationEvents.ts +22 -0
- package/src/bun/events/event.ts +27 -0
- package/src/bun/events/eventEmitter.ts +45 -0
- package/src/bun/events/trayEvents.ts +11 -0
- package/src/bun/events/webviewEvents.ts +39 -0
- package/src/bun/events/windowEvents.ts +23 -0
- package/src/bun/index.ts +120 -0
- package/src/bun/preload/.generated/compiled.ts +2 -0
- package/src/bun/preload/build.ts +65 -0
- package/src/bun/preload/dragRegions.ts +41 -0
- package/src/bun/preload/encryption.ts +86 -0
- package/src/bun/preload/events.ts +171 -0
- package/src/bun/preload/globals.d.ts +45 -0
- package/src/bun/preload/index-sandboxed.ts +28 -0
- package/src/bun/preload/index.ts +77 -0
- package/src/bun/preload/internalRpc.ts +80 -0
- package/src/bun/preload/overlaySync.ts +107 -0
- package/src/bun/preload/webviewTag.ts +451 -0
- package/src/bun/preload/wgpuTag.ts +246 -0
- package/src/bun/proc/linux.md +43 -0
- package/src/bun/proc/native.ts +3253 -0
- package/src/bun/webGPU.ts +346 -0
- package/src/bun/webgpuAdapter.ts +3011 -0
- package/src/cli/bun.lockb +0 -0
- package/src/cli/index.ts +4653 -0
- package/src/cli/package-lock.json +81 -0
- package/src/cli/package.json +11 -0
- package/src/cli/templates/embedded.ts +2 -0
- package/src/core/build.zig +16 -0
- package/src/core/main.zig +3378 -0
- package/src/extractor/build.zig +22 -0
- package/src/installer/installer-template.ts +216 -0
- package/src/launcher/main.ts +221 -0
- package/src/native/build/libNativeWrapper.so +0 -0
- package/src/native/linux/build/nativeWrapper.o +0 -0
- package/src/native/linux/cef_loader.cpp +110 -0
- package/src/native/linux/cef_loader.h +28 -0
- package/src/native/linux/cef_process_helper_linux.cpp +160 -0
- package/src/native/linux/nativeWrapper.cpp +11768 -0
- package/src/native/macos/cef_process_helper_mac.cc +160 -0
- package/src/native/macos/nativeWrapper.mm +9172 -0
- package/src/native/shared/accelerator_parser.h +72 -0
- package/src/native/shared/app_paths.h +110 -0
- package/src/native/shared/asar.h +35 -0
- package/src/native/shared/cache_migration.h +244 -0
- package/src/native/shared/callbacks.h +57 -0
- package/src/native/shared/cef_response_filter.h +189 -0
- package/src/native/shared/chromium_flags.h +181 -0
- package/src/native/shared/config.h +66 -0
- package/src/native/shared/download_event.h +197 -0
- package/src/native/shared/ffi_helpers.h +139 -0
- package/src/native/shared/glob_match.h +59 -0
- package/src/native/shared/json_menu_parser.h +223 -0
- package/src/native/shared/mime_types.h +101 -0
- package/src/native/shared/navigation_rules.h +98 -0
- package/src/native/shared/partition_context.h +137 -0
- package/src/native/shared/pending_resize_queue.h +45 -0
- package/src/native/shared/permissions.h +118 -0
- package/src/native/shared/permissions_cef.h +74 -0
- package/src/native/shared/preload_script.h +71 -0
- package/src/native/shared/shutdown_guard.h +134 -0
- package/src/native/shared/thread_safe_map.h +138 -0
- package/src/native/shared/webview_storage.h +91 -0
- package/src/native/win/cef_process_helper_win.cpp +143 -0
- package/src/native/win/dcomp_compositor.h +352 -0
- package/src/native/win/nativeWrapper.cpp +12434 -0
- package/src/npmbin/index.js +34 -0
- package/src/shared/bun-version.ts +3 -0
- package/src/shared/cef-version.ts +5 -0
- package/src/shared/naming.test.ts +327 -0
- package/src/shared/naming.ts +188 -0
- package/src/shared/platform.ts +48 -0
- package/src/shared/rpc.ts +541 -0
- package/src/shared/sparkbun-version.ts +2 -0
- package/src/types/three.d.ts +1 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// thread_safe_map.h - Cross-platform thread-safe map template
|
|
2
|
+
// Generic thread-safe container for tracking windows, webviews, etc.
|
|
3
|
+
// Used across Windows, macOS, and Linux
|
|
4
|
+
//
|
|
5
|
+
// This is a header-only implementation to avoid build complexity.
|
|
6
|
+
|
|
7
|
+
#ifndef ELECTROBUN_THREAD_SAFE_MAP_H
|
|
8
|
+
#define ELECTROBUN_THREAD_SAFE_MAP_H
|
|
9
|
+
|
|
10
|
+
#include <map>
|
|
11
|
+
#include <mutex>
|
|
12
|
+
#include <functional>
|
|
13
|
+
#include <optional>
|
|
14
|
+
#include <vector>
|
|
15
|
+
|
|
16
|
+
namespace electrobun {
|
|
17
|
+
|
|
18
|
+
// Thread-safe wrapper around std::map
|
|
19
|
+
// Provides synchronized access to key-value storage
|
|
20
|
+
template<typename KeyType, typename ValueType>
|
|
21
|
+
class ThreadSafeMap {
|
|
22
|
+
public:
|
|
23
|
+
ThreadSafeMap() = default;
|
|
24
|
+
|
|
25
|
+
// Insert or update a value
|
|
26
|
+
void set(const KeyType& key, const ValueType& value) {
|
|
27
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
28
|
+
map_[key] = value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Insert or update with move semantics
|
|
32
|
+
void set(const KeyType& key, ValueType&& value) {
|
|
33
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
34
|
+
map_[key] = std::move(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Get a value (returns copy for thread safety)
|
|
38
|
+
std::optional<ValueType> get(const KeyType& key) const {
|
|
39
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
40
|
+
auto it = map_.find(key);
|
|
41
|
+
if (it != map_.end()) {
|
|
42
|
+
return it->second;
|
|
43
|
+
}
|
|
44
|
+
return std::nullopt;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Get a value with default fallback
|
|
48
|
+
ValueType getOrDefault(const KeyType& key, const ValueType& defaultValue) const {
|
|
49
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
50
|
+
auto it = map_.find(key);
|
|
51
|
+
if (it != map_.end()) {
|
|
52
|
+
return it->second;
|
|
53
|
+
}
|
|
54
|
+
return defaultValue;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Check if key exists
|
|
58
|
+
bool contains(const KeyType& key) const {
|
|
59
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
60
|
+
return map_.find(key) != map_.end();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Remove a key
|
|
64
|
+
bool remove(const KeyType& key) {
|
|
65
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
66
|
+
return map_.erase(key) > 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Clear all entries
|
|
70
|
+
void clear() {
|
|
71
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
72
|
+
map_.clear();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Get size
|
|
76
|
+
size_t size() const {
|
|
77
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
78
|
+
return map_.size();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Check if empty
|
|
82
|
+
bool empty() const {
|
|
83
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
84
|
+
return map_.empty();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Get all keys
|
|
88
|
+
std::vector<KeyType> keys() const {
|
|
89
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
90
|
+
std::vector<KeyType> result;
|
|
91
|
+
result.reserve(map_.size());
|
|
92
|
+
for (const auto& pair : map_) {
|
|
93
|
+
result.push_back(pair.first);
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Execute a function on each entry (read-only)
|
|
99
|
+
void forEach(const std::function<void(const KeyType&, const ValueType&)>& fn) const {
|
|
100
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
101
|
+
for (const auto& pair : map_) {
|
|
102
|
+
fn(pair.first, pair.second);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Execute a function on a specific entry if it exists
|
|
107
|
+
// Returns true if the entry was found and the function was executed
|
|
108
|
+
bool withEntry(const KeyType& key,
|
|
109
|
+
const std::function<void(ValueType&)>& fn) {
|
|
110
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
111
|
+
auto it = map_.find(key);
|
|
112
|
+
if (it != map_.end()) {
|
|
113
|
+
fn(it->second);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Execute a function on a specific entry (const version)
|
|
120
|
+
bool withEntry(const KeyType& key,
|
|
121
|
+
const std::function<void(const ValueType&)>& fn) const {
|
|
122
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
123
|
+
auto it = map_.find(key);
|
|
124
|
+
if (it != map_.end()) {
|
|
125
|
+
fn(it->second);
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private:
|
|
132
|
+
mutable std::mutex mutex_;
|
|
133
|
+
std::map<KeyType, ValueType> map_;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
} // namespace electrobun
|
|
137
|
+
|
|
138
|
+
#endif // ELECTROBUN_THREAD_SAFE_MAP_H
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// webview_storage.h - Cross-platform webview content storage
|
|
2
|
+
// Thread-safe storage for webview HTML content
|
|
3
|
+
// Used across Windows, macOS, and Linux
|
|
4
|
+
//
|
|
5
|
+
// This is a header-only implementation to avoid build complexity.
|
|
6
|
+
|
|
7
|
+
#ifndef ELECTROBUN_WEBVIEW_STORAGE_H
|
|
8
|
+
#define ELECTROBUN_WEBVIEW_STORAGE_H
|
|
9
|
+
|
|
10
|
+
#include <string>
|
|
11
|
+
#include <map>
|
|
12
|
+
#include <mutex>
|
|
13
|
+
#include <cstdint>
|
|
14
|
+
#include <cstring>
|
|
15
|
+
|
|
16
|
+
namespace electrobun {
|
|
17
|
+
|
|
18
|
+
// Thread-safe storage for webview HTML content
|
|
19
|
+
// Replaces the duplicated webviewHTMLContent maps across platforms
|
|
20
|
+
class WebviewContentStorage {
|
|
21
|
+
public:
|
|
22
|
+
static WebviewContentStorage& getInstance() {
|
|
23
|
+
static WebviewContentStorage instance;
|
|
24
|
+
return instance;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
void setContent(uint32_t webviewId, const std::string& content) {
|
|
28
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
29
|
+
content_[webviewId] = content;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
void setContent(uint32_t webviewId, const char* content) {
|
|
33
|
+
if (content) {
|
|
34
|
+
setContent(webviewId, std::string(content));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
std::string getContent(uint32_t webviewId) const {
|
|
39
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
40
|
+
auto it = content_.find(webviewId);
|
|
41
|
+
if (it != content_.end()) {
|
|
42
|
+
return it->second;
|
|
43
|
+
}
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Returns a strdup'd string for FFI - caller must free
|
|
48
|
+
const char* getContentForFFI(uint32_t webviewId) const {
|
|
49
|
+
std::string content = getContent(webviewId);
|
|
50
|
+
if (content.empty()) {
|
|
51
|
+
return nullptr;
|
|
52
|
+
}
|
|
53
|
+
return strdup(content.c_str());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
bool hasContent(uint32_t webviewId) const {
|
|
57
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
58
|
+
return content_.find(webviewId) != content_.end();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
void removeContent(uint32_t webviewId) {
|
|
62
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
63
|
+
content_.erase(webviewId);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
void clear() {
|
|
67
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
68
|
+
content_.clear();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private:
|
|
72
|
+
WebviewContentStorage() = default;
|
|
73
|
+
WebviewContentStorage(const WebviewContentStorage&) = delete;
|
|
74
|
+
WebviewContentStorage& operator=(const WebviewContentStorage&) = delete;
|
|
75
|
+
|
|
76
|
+
mutable std::mutex mutex_;
|
|
77
|
+
std::map<uint32_t, std::string> content_;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Convenience functions for backward compatibility with existing code
|
|
81
|
+
inline void setWebviewHTMLContentShared(uint32_t webviewId, const char* htmlContent) {
|
|
82
|
+
WebviewContentStorage::getInstance().setContent(webviewId, htmlContent);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
inline const char* getWebviewHTMLContentShared(uint32_t webviewId) {
|
|
86
|
+
return WebviewContentStorage::getInstance().getContentForFFI(webviewId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
} // namespace electrobun
|
|
90
|
+
|
|
91
|
+
#endif // ELECTROBUN_WEBVIEW_STORAGE_H
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#include "include/cef_app.h"
|
|
2
|
+
#include "include/cef_v8.h"
|
|
3
|
+
#include <map>
|
|
4
|
+
#include <mutex>
|
|
5
|
+
|
|
6
|
+
class HelperApp : public CefApp, public CefRenderProcessHandler {
|
|
7
|
+
public:
|
|
8
|
+
// CefApp methods:
|
|
9
|
+
virtual void OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) override {
|
|
10
|
+
registrar->AddCustomScheme("views",
|
|
11
|
+
CEF_SCHEME_OPTION_STANDARD |
|
|
12
|
+
CEF_SCHEME_OPTION_CORS_ENABLED |
|
|
13
|
+
CEF_SCHEME_OPTION_SECURE | // treat it like https
|
|
14
|
+
CEF_SCHEME_OPTION_CSP_BYPASSING | // allow things like crypto.subtle
|
|
15
|
+
CEF_SCHEME_OPTION_FETCH_ENABLED);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override {
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// CefRenderProcessHandler methods:
|
|
23
|
+
|
|
24
|
+
// Called when a browser is created - receive sandbox flag via extra_info
|
|
25
|
+
virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser,
|
|
26
|
+
CefRefPtr<CefDictionaryValue> extra_info) override {
|
|
27
|
+
if (extra_info && extra_info->HasKey("sandbox")) {
|
|
28
|
+
bool sandbox = extra_info->GetBool("sandbox");
|
|
29
|
+
std::lock_guard<std::mutex> lock(sandbox_map_mutex_);
|
|
30
|
+
sandbox_map_[browser->GetIdentifier()] = sandbox;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Called when a browser is destroyed - cleanup sandbox flag
|
|
35
|
+
virtual void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) override {
|
|
36
|
+
std::lock_guard<std::mutex> lock(sandbox_map_mutex_);
|
|
37
|
+
sandbox_map_.erase(browser->GetIdentifier());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
|
|
41
|
+
CefRefPtr<CefFrame> frame,
|
|
42
|
+
CefRefPtr<CefV8Context> context) override {
|
|
43
|
+
// Check if this browser is sandboxed
|
|
44
|
+
bool is_sandboxed = false;
|
|
45
|
+
{
|
|
46
|
+
std::lock_guard<std::mutex> lock(sandbox_map_mutex_);
|
|
47
|
+
auto it = sandbox_map_.find(browser->GetIdentifier());
|
|
48
|
+
if (it != sandbox_map_.end()) {
|
|
49
|
+
is_sandboxed = it->second;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Get the global window object
|
|
54
|
+
CefRefPtr<CefV8Context> v8Context = frame->GetV8Context();
|
|
55
|
+
v8Context->Enter();
|
|
56
|
+
|
|
57
|
+
CefRefPtr<CefV8Value> window = context->GetGlobal();
|
|
58
|
+
|
|
59
|
+
// Create eventBridge - event-only bridge (always available for all webviews, including sandboxed)
|
|
60
|
+
CefRefPtr<CefV8Value> eventBridge = CefV8Value::CreateObject(nullptr, nullptr);
|
|
61
|
+
CefRefPtr<CefV8Value> eventPostMessage = CreatePostMessageFunction(browser, "EventBridgeMessage");
|
|
62
|
+
eventBridge->SetValue("postMessage", eventPostMessage, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
63
|
+
window->SetValue("__electrobunEventBridge", eventBridge, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
64
|
+
|
|
65
|
+
// Only create hostBridge/bunBridge aliases and internalBridge for non-sandboxed webviews
|
|
66
|
+
if (!is_sandboxed) {
|
|
67
|
+
// Create hostBridge - user RPC bridge
|
|
68
|
+
CefRefPtr<CefV8Value> bunBridge = CefV8Value::CreateObject(nullptr, nullptr);
|
|
69
|
+
CefRefPtr<CefV8Value> bunPostMessage = CreatePostMessageFunction(browser, "BunBridgeMessage");
|
|
70
|
+
bunBridge->SetValue("postMessage", bunPostMessage, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
71
|
+
window->SetValue("__electrobunHostBridge", bunBridge, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
72
|
+
window->SetValue("__electrobunBunBridge", bunBridge, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
73
|
+
|
|
74
|
+
// Create internalBridge - internal RPC bridge
|
|
75
|
+
CefRefPtr<CefV8Value> internalBridge = CefV8Value::CreateObject(nullptr, nullptr);
|
|
76
|
+
CefRefPtr<CefV8Value> internalPostMessage = CreatePostMessageFunction(browser, "internalMessage");
|
|
77
|
+
internalBridge->SetValue("postMessage", internalPostMessage, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
78
|
+
window->SetValue("__electrobunInternalBridge", internalBridge, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
v8Context->Exit();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private:
|
|
85
|
+
// Map of browser ID to sandbox flag
|
|
86
|
+
std::map<int, bool> sandbox_map_;
|
|
87
|
+
std::mutex sandbox_map_mutex_;
|
|
88
|
+
// Helper class to handle V8 function calls
|
|
89
|
+
class V8Handler : public CefV8Handler {
|
|
90
|
+
public:
|
|
91
|
+
V8Handler(CefRefPtr<CefBrowser> browser, const CefString& messageName)
|
|
92
|
+
: browser_(browser), message_name_(messageName) {}
|
|
93
|
+
|
|
94
|
+
virtual bool Execute(const CefString& name,
|
|
95
|
+
CefRefPtr<CefV8Value> object,
|
|
96
|
+
const CefV8ValueList& arguments,
|
|
97
|
+
CefRefPtr<CefV8Value>& retval,
|
|
98
|
+
CefString& exception) override {
|
|
99
|
+
if (arguments.size() > 0 && arguments[0]->IsString()) {
|
|
100
|
+
// Create and send process message to the main process
|
|
101
|
+
CefRefPtr<CefFrame> mainFrame = browser_->GetMainFrame();
|
|
102
|
+
if (mainFrame) {
|
|
103
|
+
CefRefPtr<CefProcessMessage> message = CefProcessMessage::Create(message_name_);
|
|
104
|
+
message->GetArgumentList()->SetString(0, arguments[0]->GetStringValue());
|
|
105
|
+
mainFrame->SendProcessMessage(PID_BROWSER, message);
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private:
|
|
113
|
+
CefRefPtr<CefBrowser> browser_;
|
|
114
|
+
CefString message_name_;
|
|
115
|
+
IMPLEMENT_REFCOUNTING(V8Handler);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
CefRefPtr<CefV8Value> CreatePostMessageFunction(CefRefPtr<CefBrowser> browser,
|
|
119
|
+
const CefString& messageName) {
|
|
120
|
+
return CefV8Value::CreateFunction(
|
|
121
|
+
"postMessage",
|
|
122
|
+
new V8Handler(browser, messageName)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
IMPLEMENT_REFCOUNTING(HelperApp);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// Entry point function for Windows sub-processes.
|
|
130
|
+
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
|
|
131
|
+
// Provide CEF with command-line arguments.
|
|
132
|
+
CefMainArgs main_args(hInstance);
|
|
133
|
+
|
|
134
|
+
CefRefPtr<CefApp> app(new HelperApp);
|
|
135
|
+
|
|
136
|
+
// Execute the sub-process.
|
|
137
|
+
return CefExecuteProcess(main_args, app, nullptr);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Alternative entry point for console applications
|
|
141
|
+
int main() {
|
|
142
|
+
return wWinMain(GetModuleHandle(NULL), NULL, GetCommandLineW(), SW_HIDE);
|
|
143
|
+
}
|