Skip to content

Commit

Permalink
refactor: remove the RenderFrameFunctionStore and use privates to mem…
Browse files Browse the repository at this point in the history
…ory manage (#23592)
  • Loading branch information
MarshallOfSound committed May 15, 2020
1 parent 3cf97d5 commit 9d7ba98
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 261 deletions.
2 changes: 0 additions & 2 deletions filenames.gni
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,6 @@ filenames = {
"shell/common/world_ids.h",
"shell/renderer/api/context_bridge/object_cache.cc",
"shell/renderer/api/context_bridge/object_cache.h",
"shell/renderer/api/context_bridge/render_frame_function_store.cc",
"shell/renderer/api/context_bridge/render_frame_function_store.h",
"shell/renderer/api/electron_api_context_bridge.cc",
"shell/renderer/api/electron_api_context_bridge.h",
"shell/renderer/api/electron_api_crash_reporter_renderer.cc",
Expand Down
7 changes: 2 additions & 5 deletions lib/renderer/api/context-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ const contextBridge: Electron.ContextBridge = {
exposeInMainWorld: (key: string, api: Record<string, any>) => {
checkContextIsolationEnabled();
return binding.exposeAPIInMainWorld(key, api);
},
debugGC: () => binding._debugGCMaps({})
}
} as any;

if (!binding._debugGCMaps) delete contextBridge.debugGC;

export default contextBridge;

export const internalContextBridge = {
Expand All @@ -33,6 +30,6 @@ export const internalContextBridge = {
isInMainWorld: () => binding._isCalledFromMainWorld() as boolean
};

if (binding._debugGCMaps) {
if (binding._isDebug) {
contextBridge.internalContextBridge = internalContextBridge;
}
6 changes: 6 additions & 0 deletions lib/sandboxed_renderer/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ function preloadRequire (module) {
// Process command line arguments.
const { hasSwitch } = process.electronBinding('command_line');

// Similar to nodes --expose-internals flag, this exposes electronBinding so
// that tests can call it to get access to some test only bindings
if (hasSwitch('unsafely-expose-electron-internals-for-testing')) {
preloadProcess.electronBinding = process.electronBinding;
}

const contextIsolation = hasSwitch('context-isolation');
const isHiddenPage = hasSwitch('hidden-page');
const rendererProcessReuseEnabled = hasSwitch('disable-electron-site-instance-overrides');
Expand Down
28 changes: 28 additions & 0 deletions shell/common/api/electron_api_v8_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ bool IsSameOrigin(const GURL& l, const GURL& r) {
return url::Origin::Create(l).IsSameOriginWith(url::Origin::Create(r));
}

#ifdef DCHECK_IS_ON
std::vector<v8::Global<v8::Value>> weakly_tracked_values;

void WeaklyTrackValue(v8::Isolate* isolate, v8::Local<v8::Value> value) {
v8::Global<v8::Value> global_value(isolate, value);
global_value.SetWeak();
weakly_tracked_values.push_back(std::move(global_value));
}

void ClearWeaklyTrackedValues() {
weakly_tracked_values.clear();
}

std::vector<v8::Local<v8::Value>> GetWeaklyTrackedValues(v8::Isolate* isolate) {
std::vector<v8::Local<v8::Value>> locals;
for (size_t i = 0; i < weakly_tracked_values.size(); i++) {
if (!weakly_tracked_values[i].IsEmpty())
locals.push_back(weakly_tracked_values[i].Get(isolate));
}
return locals;
}
#endif

void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
Expand All @@ -136,6 +159,11 @@ void Initialize(v8::Local<v8::Object> exports,
dict.SetMethod("requestGarbageCollectionForTesting",
&RequestGarbageCollectionForTesting);
dict.SetMethod("isSameOrigin", &IsSameOrigin);
#ifdef DCHECK_IS_ON
dict.SetMethod("getWeaklyTrackedValues", &GetWeaklyTrackedValues);
dict.SetMethod("clearWeaklyTrackedValues", &ClearWeaklyTrackedValues);
dict.SetMethod("weaklyTrackValue", &WeaklyTrackValue);
#endif
}

} // namespace
Expand Down
1 change: 1 addition & 0 deletions shell/common/gin_helper/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <vector>

#include "base/bind.h"
#include "gin/dictionary.h"
#include "shell/common/gin_converters/std_converter.h"
#include "shell/common/gin_helper/function_template.h"
#include "shell/common/gin_helper/locker.h"
Expand Down
49 changes: 0 additions & 49 deletions shell/renderer/api/context_bridge/render_frame_function_store.cc

This file was deleted.

61 changes: 0 additions & 61 deletions shell/renderer/api/context_bridge/render_frame_function_store.h

This file was deleted.

0 comments on commit 9d7ba98

Please sign in to comment.