Skip to content

Commit 8d7a169

Browse files
authored
Change Frame identifier from Int64 to String (#4740)
* Change Frame identifier from Int64 to String Issue #4737 * Fix SetCanExecuteJavascriptOnMainFrame frameId parsing * Add tests * NetCore Tests - Install missing packages
1 parent 9d52314 commit 8d7a169

30 files changed

+173
-94
lines changed

CefSharp.BrowserSubprocess.Core/BindObjectAsyncHandler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ namespace CefSharp
151151
auto rootObjectWrappers = _browserWrapper->JavascriptRootObjectWrappers;
152152

153153
JavascriptRootObjectWrapper^ rootObject;
154-
if (!rootObjectWrappers->TryGetValue(frame->GetIdentifier(), rootObject))
154+
if (!rootObjectWrappers->TryGetValue(StringUtils::ToClr(frame->GetIdentifier()), rootObject))
155155
{
156156
#ifdef NETCOREAPP
157157
rootObject = gcnew JavascriptRootObjectWrapper(browser->GetIdentifier());
158158
#else
159159
rootObject = gcnew JavascriptRootObjectWrapper(browser->GetIdentifier(), _browserWrapper->BrowserProcess);
160160
#endif
161-
rootObjectWrappers->TryAdd(frame->GetIdentifier(), rootObject);
161+
rootObjectWrappers->TryAdd(StringUtils::ToClr(frame->GetIdentifier()), rootObject);
162162
}
163163

164164
//Cached objects only contains a list of objects not already bound

CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ namespace CefSharp
220220
auto rootObjectWrappers = browserWrapper->JavascriptRootObjectWrappers;
221221

222222
JavascriptRootObjectWrapper^ wrapper;
223-
if (rootObjectWrappers->TryRemove(frame->GetIdentifier(), wrapper))
223+
if (rootObjectWrappers->TryRemove(StringUtils::ToClr(frame->GetIdentifier()), wrapper))
224224
{
225225
delete wrapper;
226226
}
@@ -292,7 +292,7 @@ namespace CefSharp
292292
frame->SendProcessMessage(CefProcessId::PID_BROWSER, uncaughtExceptionMessage);
293293
}
294294

295-
JavascriptRootObjectWrapper^ CefAppUnmanagedWrapper::GetJsRootObjectWrapper(int browserId, int64_t frameId)
295+
JavascriptRootObjectWrapper^ CefAppUnmanagedWrapper::GetJsRootObjectWrapper(int browserId, CefString& frameId)
296296
{
297297
auto browserWrapper = FindBrowserWrapper(browserId);
298298

@@ -302,16 +302,17 @@ namespace CefSharp
302302
}
303303

304304
auto rootObjectWrappers = browserWrapper->JavascriptRootObjectWrappers;
305+
auto frameIdClr = StringUtils::ToClr(frameId);
305306

306307
JavascriptRootObjectWrapper^ rootObject;
307-
if (!rootObjectWrappers->TryGetValue(frameId, rootObject))
308+
if (!rootObjectWrappers->TryGetValue(frameIdClr, rootObject))
308309
{
309310
#ifdef NETCOREAPP
310311
rootObject = gcnew JavascriptRootObjectWrapper(browserId);
311312
#else
312313
rootObject = gcnew JavascriptRootObjectWrapper(browserId, browserWrapper->BrowserProcess);
313314
#endif
314-
rootObjectWrappers->TryAdd(frameId, rootObject);
315+
rootObjectWrappers->TryAdd(frameIdClr, rootObject);
315316
}
316317

317318
return rootObject;
@@ -400,7 +401,7 @@ namespace CefSharp
400401
}
401402

402403
//both messages have callbackId stored at index 0
403-
auto frameId = frame->GetIdentifier();
404+
auto frameId = StringUtils::ToClr(frame->GetIdentifier());
404405
int64_t callbackId = GetInt64(argList, 0);
405406

406407
if (name == kEvaluateJavascriptRequest)
@@ -604,7 +605,7 @@ namespace CefSharp
604605
{
605606
auto jsCallbackId = GetInt64(argList, 0);
606607
JavascriptRootObjectWrapper^ rootObjectWrapper;
607-
browserWrapper->JavascriptRootObjectWrappers->TryGetValue(frame->GetIdentifier(), rootObjectWrapper);
608+
browserWrapper->JavascriptRootObjectWrappers->TryGetValue(StringUtils::ToClr(frame->GetIdentifier()), rootObjectWrapper);
608609
if (rootObjectWrapper != nullptr && rootObjectWrapper->CallbackRegistry != nullptr)
609610
{
610611
rootObjectWrapper->CallbackRegistry->Deregister(jsCallbackId);
@@ -712,7 +713,7 @@ namespace CefSharp
712713
{
713714
if (frame.get() && frame->IsValid())
714715
{
715-
auto frameId = frame->GetIdentifier();
716+
auto frameId = StringUtils::ToClr(frame->GetIdentifier());
716717
auto callbackId = GetInt64(argList, 0);
717718

718719
JavascriptRootObjectWrapper^ rootObjectWrapper;

CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace CefSharp
7272
}
7373

7474
CefBrowserWrapper^ FindBrowserWrapper(int browserId);
75-
JavascriptRootObjectWrapper^ GetJsRootObjectWrapper(int browserId, int64_t frameId);
75+
JavascriptRootObjectWrapper^ GetJsRootObjectWrapper(int browserId, CefString& frameId);
7676

7777
virtual DECL CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override;
7878
virtual DECL void OnBrowserCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDictionaryValue> extraInfo) override;

CefSharp.BrowserSubprocess.Core/CefBrowserWrapper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace CefSharp
3131

3232
internal:
3333
//Frame Identifier is used as Key
34-
property ConcurrentDictionary<int64_t, JavascriptRootObjectWrapper^>^ JavascriptRootObjectWrappers;
34+
property ConcurrentDictionary<String^, JavascriptRootObjectWrapper^>^ JavascriptRootObjectWrappers;
3535

3636
public:
3737
CefBrowserWrapper(CefRefPtr<CefBrowser> cefBrowser)
@@ -40,7 +40,7 @@ namespace CefSharp
4040
BrowserId = cefBrowser->GetIdentifier();
4141
IsPopup = cefBrowser->IsPopup();
4242

43-
JavascriptRootObjectWrappers = gcnew ConcurrentDictionary<int64_t, JavascriptRootObjectWrapper^>();
43+
JavascriptRootObjectWrappers = gcnew ConcurrentDictionary<String^, JavascriptRootObjectWrapper^>();
4444
}
4545

4646
!CefBrowserWrapper()
@@ -54,7 +54,7 @@ namespace CefSharp
5454

5555
if (JavascriptRootObjectWrappers != nullptr)
5656
{
57-
for each (KeyValuePair<int64_t, JavascriptRootObjectWrapper^> entry in JavascriptRootObjectWrappers)
57+
for each (KeyValuePair<String^, JavascriptRootObjectWrapper^> entry in JavascriptRootObjectWrappers)
5858
{
5959
delete entry.Value;
6060
}

CefSharp.BrowserSubprocess.Core/JavascriptCallbackRegistry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace CefSharp
2121
auto result = gcnew JavascriptCallback();
2222
result->Id = newId;
2323
result->BrowserId = _browserId;
24-
result->FrameId = context->GetFrame()->GetIdentifier();
24+
result->FrameId = StringUtils::ToClr(context->GetFrame()->GetIdentifier());
2525
return result;
2626
}
2727

CefSharp.BrowserSubprocess.Core/Wrapper/Browser.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ IFrame^ Browser::FocusedFrame::get()
155155
// Returns the frame with the specified identifier, or NULL if not found.
156156
///
157157
/*--cef(capi_name=get_frame_byident)--*/
158-
IFrame^ Browser::GetFrame(Int64 identifier)
158+
IFrame^ Browser::GetFrameByIdentifier(String^ identifier)
159159
{
160-
auto frame = _browser->GetFrame(identifier);
160+
auto frame = _browser->GetFrameByIdentifier(StringUtils::ToNative(identifier));
161161

162162
if (frame.get())
163163
{
@@ -171,9 +171,9 @@ IFrame^ Browser::GetFrame(Int64 identifier)
171171
// Returns the frame with the specified name, or NULL if not found.
172172
///
173173
/*--cef(optional_param=name)--*/
174-
IFrame^ Browser::GetFrame(String^ name)
174+
IFrame^ Browser::GetFrameByName(String^ name)
175175
{
176-
auto frame = _browser->GetFrame(StringUtils::ToNative(name));
176+
auto frame = _browser->GetFrameByName(StringUtils::ToNative(name));
177177

178178
if (frame.get())
179179
{
@@ -196,14 +196,14 @@ int Browser::GetFrameCount()
196196
// Returns the identifiers of all existing frames.
197197
///
198198
/*--cef(count_func=identifiers:GetFrameCount)--*/
199-
List<Int64>^ Browser::GetFrameIdentifiers()
199+
List<String^>^ Browser::GetFrameIdentifiers()
200200
{
201-
std::vector<Int64> identifiers;
201+
std::vector<CefString> identifiers;
202202
_browser->GetFrameIdentifiers(identifiers);
203-
List<Int64>^ results = gcnew List<Int64>(static_cast<int>(identifiers.size()));
203+
List<String^>^ results = gcnew List<String^>(static_cast<int>(identifiers.size()));
204204
for (UINT i = 0; i < identifiers.size(); i++)
205205
{
206-
results->Add(identifiers[i]);
206+
results->Add(StringUtils::ToClr(identifiers[i]));
207207
}
208208
return results;
209209
}

CefSharp.BrowserSubprocess.Core/Wrapper/Browser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ namespace CefSharp
158158
// Returns the frame with the specified identifier, or NULL if not found.
159159
///
160160
/*--cef(capi_name=get_frame_byident)--*/
161-
virtual IFrame^ GetFrame(Int64 identifier);
161+
virtual IFrame^ GetFrameByIdentifier(String^ identifier);
162162

163163
///
164164
// Returns the frame with the specified name, or NULL if not found.
165165
///
166166
/*--cef(optional_param=name)--*/
167-
virtual IFrame^ GetFrame(String^ name);
167+
virtual IFrame^ GetFrameByName(String^ name);
168168

169169
///
170170
// Returns the number of frames that currently exist.
@@ -176,7 +176,7 @@ namespace CefSharp
176176
// Returns the identifiers of all existing frames.
177177
///
178178
/*--cef(count_func=identifiers:GetFrameCount)--*/
179-
virtual List<Int64>^ GetFrameIdentifiers();
179+
virtual List<String^>^ GetFrameIdentifiers();
180180

181181
///
182182
// Returns the names of all existing frames.

CefSharp.BrowserSubprocess.Core/Wrapper/Frame.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ String^ Frame::Name::get()
205205
// Returns the globally unique identifier for this frame.
206206
///
207207
/*--cef()--*/
208-
Int64 Frame::Identifier::get()
208+
String^ Frame::Identifier::get()
209209
{
210-
return _frame->GetIdentifier();
210+
return StringUtils::ToClr(_frame->GetIdentifier());
211211
}
212212

213213
///

CefSharp.BrowserSubprocess.Core/Wrapper/Frame.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ namespace CefSharp
201201
// Returns the globally unique identifier for this frame.
202202
///
203203
/*--cef()--*/
204-
virtual property Int64 Identifier
204+
virtual property String^ Identifier
205205
{
206-
Int64 get();
206+
String^ get();
207207
}
208208

209209
///

CefSharp.Core.Runtime/Internals/CefBrowserWrapper.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ IFrame^ CefBrowserWrapper::FocusedFrame::get()
192192
// Returns the frame with the specified identifier, or NULL if not found.
193193
///
194194
/*--cef(capi_name=get_frame_byident)--*/
195-
IFrame^ CefBrowserWrapper::GetFrame(Int64 identifier)
195+
IFrame^ CefBrowserWrapper::GetFrameByIdentifier(String^ identifier)
196196
{
197197
ThrowIfDisposed();
198198

199-
auto frame = _browser->GetFrame(identifier);
199+
auto frame = _browser->GetFrameByIdentifier(StringUtils::ToNative(identifier));
200200

201201
if (frame.get())
202202
{
@@ -210,11 +210,11 @@ IFrame^ CefBrowserWrapper::GetFrame(Int64 identifier)
210210
// Returns the frame with the specified name, or NULL if not found.
211211
///
212212
/*--cef(optional_param=name)--*/
213-
IFrame^ CefBrowserWrapper::GetFrame(String^ name)
213+
IFrame^ CefBrowserWrapper::GetFrameByName(String^ name)
214214
{
215215
ThrowIfDisposed();
216216

217-
auto frame = _browser->GetFrame(StringUtils::ToNative(name));
217+
auto frame = _browser->GetFrameByName(StringUtils::ToNative(name));
218218

219219
if (frame.get())
220220
{
@@ -238,16 +238,16 @@ int CefBrowserWrapper::GetFrameCount()
238238
// Returns the identifiers of all existing frames.
239239
///
240240
/*--cef(count_func=identifiers:GetFrameCount)--*/
241-
List<Int64>^ CefBrowserWrapper::GetFrameIdentifiers()
241+
List<String^>^ CefBrowserWrapper::GetFrameIdentifiers()
242242
{
243243
ThrowIfDisposed();
244244

245-
std::vector<Int64> identifiers;
245+
std::vector<CefString> identifiers;
246246
_browser->GetFrameIdentifiers(identifiers);
247-
List<Int64>^ results = gcnew List<Int64>(static_cast<int>(identifiers.size()));
247+
List<String^>^ results = gcnew List<String^>(static_cast<int>(identifiers.size()));
248248
for (UINT i = 0; i < identifiers.size(); i++)
249249
{
250-
results->Add(identifiers[i]);
250+
results->Add(StringUtils::ToClr(identifiers[i]));
251251
}
252252
return results;
253253
}

0 commit comments

Comments
 (0)