-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More heavily-WIP-style work towards #159. I wonder if we'll ever gonn…
…a get that one solved actually... Well, of course we are, but how well with it work? Anyway, time to go to bed now and so forth.
- Loading branch information
Showing
10 changed files
with
197 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using CefSharp.Internals.JavascriptBinding; | ||
using System; | ||
|
||
namespace CefSharp.BrowserSubprocess | ||
{ | ||
internal class JavascriptProxy : IJavascriptProxy | ||
{ | ||
public const String BaseAddress = "net.pipe://localhost"; | ||
public const String ServiceName = "JavaScriptProxy"; | ||
public const String Address = BaseAddress + "/" + ServiceName; | ||
|
||
public object EvaluateScript(int frameId, string script, double timeout) | ||
{ | ||
var cefFrame = SubprocessCefApp.Instance.CefBrowserWrapper.GetFrame(frameId); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using CefSharp.Internals.JavascriptBinding; | ||
using System; | ||
using System.ServiceModel; | ||
using System.ServiceModel.Description; | ||
|
||
namespace CefSharp.BrowserSubprocess | ||
{ | ||
internal class JavascriptServiceHost | ||
{ | ||
public static void Create(int browserId) | ||
{ | ||
var uris = new[] | ||
{ | ||
new Uri(JavascriptProxy.BaseAddress) | ||
}; | ||
|
||
var host = new ServiceHost(typeof(JavascriptProxy), uris); | ||
AddDebugBehavior(host); | ||
|
||
// TODO: Include the name of the "parent process" here also, so you can run more than one CefSharp-based application | ||
// TODO: simultaneously. :) | ||
var serviceName = JavascriptProxy.ServiceName + "_" + browserId; | ||
|
||
host.AddServiceEndpoint( | ||
typeof(IJavascriptProxy), | ||
new NetNamedPipeBinding(), | ||
serviceName | ||
); | ||
|
||
host.Open(); | ||
} | ||
|
||
private static void AddDebugBehavior(ServiceHostBase host) | ||
{ | ||
var serviceDebugBehavior = host.Description.Behaviors.Find<ServiceDebugBehavior>(); | ||
|
||
if (serviceDebugBehavior == null) | ||
{ | ||
serviceDebugBehavior = new ServiceDebugBehavior | ||
{ | ||
IncludeExceptionDetailInFaults = true | ||
}; | ||
host.Description.Behaviors.Add(serviceDebugBehavior); | ||
} | ||
else | ||
{ | ||
serviceDebugBehavior.IncludeExceptionDetailInFaults = true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// 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. | ||
|
||
#include "include/cef_browser.h" | ||
#include "include/cef_runnable.h" | ||
|
||
using namespace System::Threading; | ||
|
||
namespace CefSharp | ||
{ | ||
namespace Wrappers | ||
{ | ||
private class CefBrowserUnmanagedWrapper | ||
{ | ||
CefRefPtr<CefBrowser> _cefBrowser; | ||
|
||
public: | ||
CefRefPtr<CefFrame> Frame; | ||
gcroot<AutoResetEvent^> WaitHandle; | ||
|
||
CefBrowserUnmanagedWrapper(CefRefPtr<CefBrowser> cefBrowser) | ||
{ | ||
_cefBrowser = cefBrowser; | ||
WaitHandle = gcnew AutoResetEvent(false); | ||
} | ||
|
||
void GetFrameCallback(int64 frameId) | ||
{ | ||
Frame = _cefBrowser->GetFrame(frameId); | ||
WaitHandle->Set(); | ||
} | ||
|
||
IMPLEMENT_REFCOUNTING(CefBrowserUnmanagedWrapper); | ||
}; | ||
|
||
public ref class CefBrowserWrapper | ||
{ | ||
CefRefPtr<CefBrowser>* _cefBrowser; | ||
int _browserId; | ||
CefRefPtr<CefBrowserUnmanagedWrapper>* _unmanagedWrapper; | ||
|
||
public: | ||
property int BrowserId | ||
{ | ||
int get() { return _browserId; } | ||
private: void set(int value) { _browserId = value; } | ||
} | ||
|
||
CefBrowserWrapper(CefRefPtr<CefBrowser> cefBrowser) | ||
{ | ||
_cefBrowser = &cefBrowser; | ||
_browserId = cefBrowser->GetIdentifier(); | ||
|
||
// TODO: Should be deallocated at some point to avoid leaking memory. | ||
_unmanagedWrapper = new CefRefPtr<CefBrowserUnmanagedWrapper>(new CefBrowserUnmanagedWrapper(cefBrowser)); | ||
} | ||
|
||
System::IntPtr GetFrame(long frameId) | ||
{ | ||
// TODO: Could we do something genericly useful here using C++ lambdas? To avoid having to make a lot of of these... | ||
// TODO: DON'T USE AUTORESETEVENT STUPIDITY! Even though the code below compiles & runs correctly, it deadlocks the | ||
// thread from which the request came, which is very, very stupid, especially since V8 and Chromium are built | ||
// with asynchrony in mind. Instead, we should re-think this API to utilize WCF callbacks instead: | ||
// http://idunno.org/archive/2008/05/29/wcf-callbacks-a-beginners-guide.aspx | ||
// That feels much more like 2013, and not 1994... :) | ||
CefPostTask(CefThreadId::TID_RENDERER, NewCefRunnableMethod(_unmanagedWrapper->get(), &CefBrowserUnmanagedWrapper::GetFrameCallback, frameId)); | ||
_unmanagedWrapper->get()->WaitHandle->WaitOne(); | ||
|
||
// TODO: Wrap in a CefFrameWrapper, obviously... | ||
return (System::IntPtr)&_unmanagedWrapper->get()->Frame; | ||
} | ||
}; | ||
} | ||
} |