@@ -22,24 +22,66 @@ namespace CefSharp
22
22
private class CefSharpApp : public CefApp ,
23
23
public CefBrowserProcessHandler
24
24
{
25
- gcroot<CefSettingsBase^> _cefSettings;
25
+ gcroot<IEnumerable<CefCustomScheme^>^> _customSchemes;
26
+ gcroot<CommandLineArgDictionary^> _commandLineArgs;
26
27
gcroot<IApp^> _app;
28
+ bool _commandLineDisabled;
29
+ bool _hasCustomScheme;
30
+ gcroot<String^> _customSchemeArg;
27
31
28
32
public:
29
- CefSharpApp (CefSettingsBase^ cefSettings, IApp^ app) :
30
- _cefSettings (cefSettings),
31
- _app (app)
33
+ CefSharpApp (bool externalMessagePump, bool commandLineDisabled, CommandLineArgDictionary^ commandLineArgs, IEnumerable<CefCustomScheme^>^ customSchemes, IApp^ app) :
34
+ _commandLineDisabled (commandLineDisabled),
35
+ _commandLineArgs (commandLineArgs),
36
+ _customSchemes (customSchemes),
37
+ _app (app),
38
+ _hasCustomScheme (false )
32
39
{
33
40
auto isMissingHandler = Object::ReferenceEquals (app, nullptr ) || Object::ReferenceEquals (app->BrowserProcessHandler , nullptr );
34
- if (cefSettings-> ExternalMessagePump && isMissingHandler)
41
+ if (externalMessagePump && isMissingHandler)
35
42
{
36
43
throw gcnew Exception (" browserProcessHandler cannot be null when using cefSettings.ExternalMessagePump" );
37
44
}
45
+
46
+ if (System::Linq::Enumerable::Count (customSchemes) > 0 )
47
+ {
48
+ String^ argument = " =" ;
49
+ auto registeredSchemes = gcnew List<String^>();
50
+
51
+ for each (CefCustomScheme ^ scheme in customSchemes)
52
+ {
53
+ // We don't need to register http or https in the render process
54
+ if (scheme->SchemeName == " http" ||
55
+ scheme->SchemeName == " https" )
56
+ {
57
+ continue ;
58
+ }
59
+
60
+ // We've already registered this scheme name
61
+ if (registeredSchemes->Contains (scheme->SchemeName ))
62
+ {
63
+ continue ;
64
+ }
65
+
66
+ _hasCustomScheme = true ;
67
+
68
+ registeredSchemes->Add (scheme->SchemeName );
69
+
70
+ argument += scheme->SchemeName + " |" ;
71
+ argument += ((int )scheme->Options ).ToString () + " ;" ;
72
+ }
73
+
74
+ if (_hasCustomScheme)
75
+ {
76
+ _customSchemeArg = argument->TrimEnd (' ;' );
77
+ }
78
+ }
38
79
}
39
80
40
81
~CefSharpApp ()
41
82
{
42
- _cefSettings = nullptr ;
83
+ _customSchemes = nullptr ;
84
+ _commandLineArgs = nullptr ;
43
85
delete _app;
44
86
_app = nullptr ;
45
87
}
@@ -56,8 +98,10 @@ namespace CefSharp
56
98
_app->BrowserProcessHandler ->OnContextInitialized ();
57
99
}
58
100
101
+ auto customSchemes = (IEnumerable<CefCustomScheme^>^)_customSchemes;
102
+
59
103
// CefRegisterSchemeHandlerFactory requires access to the Global CefRequestContext
60
- for each (CefCustomScheme^ cefCustomScheme in _cefSettings-> CefCustomSchemes )
104
+ for each (CefCustomScheme^ cefCustomScheme in customSchemes )
61
105
{
62
106
if (!Object::ReferenceEquals (cefCustomScheme->SchemeHandlerFactory , nullptr ))
63
107
{
@@ -93,41 +137,9 @@ namespace CefSharp
93
137
// We need to know the process Id to establish WCF communication and for monitoring of parent process exit
94
138
commandLine->AppendArgument (StringUtils::ToNative (CefSharpArguments::HostProcessIdArgument + " =" + Process::GetCurrentProcess ()->Id ));
95
139
96
- if (_cefSettings-> _cefCustomSchemes -> Count > 0 )
140
+ if (_hasCustomScheme )
97
141
{
98
- String^ argument = " =" ;
99
- bool hasCustomScheme = false ;
100
- auto registeredSchemes = gcnew List<String^>();
101
-
102
- for each (CefCustomScheme^ scheme in _cefSettings->CefCustomSchemes )
103
- {
104
- // We don't need to register http or https in the render process
105
- if (scheme->SchemeName == " http" ||
106
- scheme->SchemeName == " https" )
107
- {
108
- continue ;
109
- }
110
-
111
- // We've already registered this scheme name
112
- if (registeredSchemes->Contains (scheme->SchemeName ))
113
- {
114
- continue ;
115
- }
116
-
117
- hasCustomScheme = true ;
118
-
119
- registeredSchemes->Add (scheme->SchemeName );
120
-
121
- argument += scheme->SchemeName + " |" ;
122
- argument += ((int )scheme->Options ).ToString () + " ;" ;
123
- }
124
-
125
- if (hasCustomScheme)
126
- {
127
- argument = argument->TrimEnd (' ;' );
128
-
129
- commandLine->AppendArgument (StringUtils::ToNative (CefSharpArguments::CustomSchemeArgument + argument));
130
- }
142
+ commandLine->AppendArgument (StringUtils::ToNative (CefSharpArguments::CustomSchemeArgument + _customSchemeArg));
131
143
}
132
144
133
145
if (CefSharpSettings::FocusedNodeChangedEnabled)
@@ -138,7 +150,7 @@ namespace CefSharp
138
150
139
151
virtual void OnBeforeCommandLineProcessing (const CefString& process_type, CefRefPtr<CefCommandLine> command_line) OVERRIDE
140
152
{
141
- if (CefSharpSettings::Proxy != nullptr && !_cefSettings-> CommandLineArgsDisabled )
153
+ if (CefSharpSettings::Proxy != nullptr && !_commandLineDisabled )
142
154
{
143
155
command_line->AppendSwitchWithValue (" proxy-server" , StringUtils::ToNative (CefSharpSettings::Proxy->IP + " :" + CefSharpSettings::Proxy->Port ));
144
156
@@ -148,15 +160,17 @@ namespace CefSharp
148
160
}
149
161
}
150
162
151
- if (_cefSettings-> CefCommandLineArgs ->Count > 0 )
163
+ if (_commandLineArgs ->Count > 0 )
152
164
{
153
165
auto commandLine = command_line.get ();
154
166
155
167
// Not clear what should happen if we
156
168
// * already have some command line flags given (is this possible? Perhaps from globalCommandLine)
157
169
// * have no flags given (-> call SetProgramm() with first argument?)
158
170
159
- for each (KeyValuePair<String^, String^>^ kvp in _cefSettings->CefCommandLineArgs )
171
+ auto args = (CommandLineArgDictionary^)_commandLineArgs;
172
+
173
+ for each (KeyValuePair<String^, String^>^ kvp in args)
160
174
{
161
175
CefString name = StringUtils::ToNative (kvp->Key );
162
176
CefString value = StringUtils::ToNative (kvp->Value );
0 commit comments