diff --git a/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.cpp b/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.cpp index 73fa1de43..0fcdff3a4 100644 --- a/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.cpp +++ b/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.cpp @@ -3,10 +3,37 @@ // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. #include "include/cef_app.h" +#include "JavascriptProxy.h" + +using namespace CefSharp::Internals::JavascriptBinding; +using namespace CefSharp::BrowserSubprocess; +using namespace System; +using namespace System::ServiceModel; +using namespace System::Threading; + +static void threadEntryPoint(); int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { + auto thread = gcnew Thread(gcnew ThreadStart(threadEntryPoint)); + thread->Start(); + CefMainArgs main_args(hInstance); CefRefPtr app; return CefExecuteProcess(main_args, app); } + +void threadEntryPoint() +{ + auto uris = gcnew array(1); + uris[0] = gcnew Uri(JavascriptProxy::BaseAddress); + + auto host = gcnew ServiceHost(JavascriptProxy::typeid, uris); + host->AddServiceEndpoint( + IJavascriptProxy::typeid, + gcnew NetNamedPipeBinding(), + JavascriptProxy::ServiceName + ); + + host->Open(); +} diff --git a/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.vcxproj b/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.vcxproj index 505ee80a5..df59fa1bd 100644 --- a/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.vcxproj +++ b/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.vcxproj @@ -90,13 +90,20 @@ - + {7b495581-2271-4f41-9476-acb86e8c864f} + + + + + + + diff --git a/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.vcxproj.filters b/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.vcxproj.filters index a948fecb0..79e92a5fe 100644 --- a/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.vcxproj.filters +++ b/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.vcxproj.filters @@ -15,7 +15,12 @@ - + + Header Files + + + + Source Files diff --git a/CefSharp.BrowserSubprocess/JavascriptProxy.h b/CefSharp.BrowserSubprocess/JavascriptProxy.h new file mode 100644 index 000000000..d8e4249f4 --- /dev/null +++ b/CefSharp.BrowserSubprocess/JavascriptProxy.h @@ -0,0 +1,29 @@ +// Copyright © 2010-2013 The CefSharp Project. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +#pragma once + +using namespace CefSharp::Internals::JavascriptBinding; +using namespace System; + +namespace CefSharp +{ + namespace BrowserSubprocess + { + private ref class JavascriptProxy : IJavascriptProxy + { + public: + // TODO: Don't hardwire the address like this, since it makes it impossible to run multiple apps that use + // CefSharp simultaneously... + literal String^ BaseAddress = "net.pipe://localhost"; + literal String^ ServiceName = "JavaScriptProxy"; + static String^ Address = BaseAddress + "/" + ServiceName; + + virtual Object^ EvaluateScript(String^ script, double timeout) + { + return "gurka"; + } + }; + } +} diff --git a/CefSharp/CefBrowserWrapper.h b/CefSharp/CefBrowserWrapper.h index cf20cbf7c..85e981f62 100644 --- a/CefSharp/CefBrowserWrapper.h +++ b/CefSharp/CefBrowserWrapper.h @@ -8,10 +8,13 @@ #include "BrowserSettings.h" #include "MouseButtonType.h" #include "ScriptCore.h" +#include "Internals/JavascriptBinding/IJavascriptProxy.h" #include "Internals/IRenderWebBrowser.h" #include "Internals/RenderClientAdapter.h" using namespace CefSharp::Internals; +using namespace CefSharp::Internals::JavascriptBinding; +using namespace System::ServiceModel; namespace CefSharp { @@ -20,6 +23,7 @@ namespace CefSharp private: RenderClientAdapter* _renderClientAdapter; ScriptCore* _scriptCore; + IJavascriptProxy^ _javaScriptProxy; public: property Object^ BitmapLock @@ -58,6 +62,14 @@ namespace CefSharp { _renderClientAdapter = new RenderClientAdapter(offscreenBrowserControl); _scriptCore = new ScriptCore(); + + // TODO: Address should certainly not be hardwired like this. + auto channelFactory = gcnew ChannelFactory( + gcnew NetNamedPipeBinding(), + gcnew EndpointAddress("net.pipe://localhost/JavaScriptProxy") + ); + + _javaScriptProxy = channelFactory->CreateChannel(); } ~CefBrowserWrapper() @@ -106,7 +118,6 @@ namespace CefSharp } } - void WasResized() { auto cefHost = _renderClientAdapter->TryGetCefHost(); @@ -240,16 +251,19 @@ namespace CefSharp Object^ EvaluateScript(String^ script, TimeSpan timeout) { - auto browser = _renderClientAdapter->GetCefBrowser(); + // TODO: implement the browserprocess and make it implement IScriptProxy, and set up a WCF listener. + return _javaScriptProxy->EvaluateScript(script, timeout.TotalMilliseconds); - if (browser != nullptr) - { - return _scriptCore->Evaluate(browser, StringUtils::ToNative(script), (DWORD) timeout.TotalMilliseconds); - } - else - { - return nullptr; - } + //auto browser = _renderClientAdapter->GetCefBrowser(); + + //if (browser != nullptr) + //{ + // return _scriptCore->Evaluate(browser, StringUtils::ToNative(script), (DWORD) timeout.TotalMilliseconds); + //} + //elser + //{ + // return nullptr; + //} } }; } diff --git a/CefSharp/CefSharp.vcxproj b/CefSharp/CefSharp.vcxproj index 152c453e6..bfae39bad 100644 --- a/CefSharp/CefSharp.vcxproj +++ b/CefSharp/CefSharp.vcxproj @@ -119,6 +119,7 @@ true true + @@ -156,6 +157,7 @@ + diff --git a/CefSharp/CefSharp.vcxproj.filters b/CefSharp/CefSharp.vcxproj.filters index c5edf07c6..a88b1079e 100644 --- a/CefSharp/CefSharp.vcxproj.filters +++ b/CefSharp/CefSharp.vcxproj.filters @@ -178,5 +178,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/CefSharp/Internals/JavascriptBinding/IJavascriptProxy.h b/CefSharp/Internals/JavascriptBinding/IJavascriptProxy.h new file mode 100644 index 000000000..ef86f4980 --- /dev/null +++ b/CefSharp/Internals/JavascriptBinding/IJavascriptProxy.h @@ -0,0 +1,23 @@ +// Copyright © 2010-2013 The CefSharp Project. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +using namespace System::ServiceModel; + +namespace CefSharp +{ + namespace Internals + { + namespace JavascriptBinding + { + // TODO: Should be internal (a.k.a. private in C++), but I couldn't manage to get InternalsVisibleTo functioning + // between C++ projects... + [ServiceContract] + public interface class IJavascriptProxy + { + [OperationContract] + Object^ EvaluateScript(String^ script, double timeout); + }; + } + } +} \ No newline at end of file