Gets HTMLIFrameElement::embedViewManagerClient to work with dart

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/948943002
This commit is contained in:
Scott Violet 2015-02-23 15:29:22 -08:00
parent 6871080f93
commit 15d7cd9b47
10 changed files with 109 additions and 71 deletions

View File

@ -10,6 +10,7 @@
#include "sky/engine/core/html/parser/HTMLParserIdioms.h"
#include "sky/engine/core/loader/FrameLoaderClient.h"
#include "sky/engine/core/rendering/RenderIFrame.h"
#include "sky/engine/tonic/mojo_converter.h"
namespace blink {
@ -79,14 +80,13 @@ PassRefPtr<DartValue> HTMLIFrameElement::takeExposedServicesHandle(DartState*)
return DartValue::Create();
}
void HTMLIFrameElement::embedViewManagerClient(DartValue* client) {
void HTMLIFrameElement::embedViewManagerClient(RefPtr<DartValue> client)
{
if (!m_contentView)
return;
// TODO(dart)
// mojo::MessagePipeHandle handle;
// if (gin::ConvertFromV8(client.isolate(), client.v8Value(), &handle))
// m_contentView->Embed(mojo::MakeProxy<mojo::ViewManagerClient>(mojo::MakeScopedHandle(handle)));
m_contentView->Embed(mojo::MakeProxy<mojo::ViewManagerClient>(
DartConverter<mojo::ScopedMessagePipeHandle>::FromDart(client->dart_value())));
}
void HTMLIFrameElement::navigateView()

View File

@ -28,7 +28,7 @@ public:
PassRefPtr<DartValue> takeServicesHandle(DartState*);
PassRefPtr<DartValue> takeExposedServicesHandle(DartState*);
void embedViewManagerClient(DartValue* client);
void embedViewManagerClient(RefPtr<DartValue> client);
private:
explicit HTMLIFrameElement(Document&);

View File

@ -5,7 +5,7 @@
interface HTMLIFrameElement : HTMLElement {
[Reflect, URL] attribute DOMString src;
// void embedViewManagerClient(any client);
void embedViewManagerClient(any client);
// [CallWith=ScriptState] any takeServicesHandle();
// [CallWith=ScriptState] any takeExposedServicesHandle();
};

View File

@ -38,10 +38,12 @@ source_set("tonic") {
"dart_wrappable.cc",
"dart_wrappable.h",
"dart_wrapper_info.h",
"mojo_converter.h",
]
deps = [
"//base",
"//mojo/public/cpp/system",
"//sky/engine/wtf",
]

View File

@ -0,0 +1,32 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_TONIC_MOJO_CONVERTER_H_
#define SKY_ENGINE_TONIC_MOJO_CONVERTER_H_
#include "mojo/public/cpp/system/handle.h"
#include "sky/engine/tonic/dart_converter.h"
namespace blink {
template <typename HandleType>
struct DartConverter<mojo::ScopedHandleBase<HandleType>> {
static mojo::ScopedHandleBase<HandleType> FromDart(Dart_Handle handle) {
uint64_t mojo_handle64 = 0;
Dart_Handle result = Dart_IntegerToUint64(handle, &mojo_handle64);
if (Dart_IsError(result) || !mojo_handle64)
return mojo::ScopedHandleBase<HandleType>();
HandleType mojo_handle(static_cast<MojoHandle>(mojo_handle64));
return mojo::MakeScopedHandle(mojo_handle);
}
static Dart_Handle ToDart(mojo::ScopedHandleBase<HandleType> mojo_handle) {
return Dart_NewInteger(static_cast<int64_t>(mojo_handle.release().value()));
}
};
} // namespace blink
#endif // SKY_ENGINE_TONIC_MOJO_CONVERTER_H_

View File

@ -13,7 +13,7 @@ final _EmbedderImpl embedder = new _EmbedderImpl();
class _EmbedderImpl {
static final ShellProxy shell = new ShellProxy.fromHandle(
new core.MojoHandle(internals.takeShellProxyHandle()));
new core.MojoHandle(internals.takeShellProxyHandle()));
static final ApplicationConnection connection = new ApplicationConnection(
new ServiceProviderStub.fromHandle(

View File

@ -40,5 +40,4 @@ crbug.com/2 modules/load-event.sky [ Skip ]
crbug.com/2 modules/modules.sky [ Skip ]
crbug.com/2 modules/script-import.sky [ Skip ]
crbug.com/2 parser/script.sky [ Skip ]
crbug.com/2 services/iframe-embed-vmc.sky [ Skip ]
crbug.com/2 services/iframe-service-provider.sky [ Skip ]

View File

@ -1,34 +1,56 @@
<html>
<import src="/gen/mojo/public/interfaces/application/shell.mojom.sky" as="shellMojom" />
<import src="/gen/mojo/public/sky/connection.sky" as="connection" />
<import src="/gen/mojo/public/sky/core.sky" as="core" />
<import src="/gen/mojo/services/public/sky/shell.sky" as="shellJS" />
<import src="/gen/services/js/test/echo_service.mojom.sky" as="echoServiceMojom" />
<import src="/gen/mojo/services/view_manager/public/interfaces/view_manager.mojom.sky" as="ViewManager">
<import src="/gen/mojo/services/input_events/public/interfaces/input_events.mojom.sky" as="InputEvents"/>
<import src="/sky/framework/sky-element/sky-element.sky" as="SkyElement" />
<sky>
<iframe></iframe>
<script>
var shellHandle = internals.takeShellProxyHandle();
var shellProxy = connection.bindHandleToProxy(shellHandle, shellMojom.Shell);
var shell = new shellJS.Shell(shellProxy);
import 'dart:async';
import 'dart:mojo_bindings';
import 'dart:mojo_core';
import 'dart:sky';
import 'dart:sky.internals' as internals;
import 'dart:typed_data';
import '/mojo/public/dart/application.dart';
// The vmcApp provides ViewManagerClient and EchoService.
var vmcURL = "http://127.0.0.1:8000/sky/tests/services/resources/iframe-vmc.js"
var vmcApp = shell.connectToApplication(vmcURL);
import 'package:mojo/public/interfaces/application/shell.mojom.dart' as shell_mojom;
import 'package:mojo/services/input_events/public/interfaces/input_events.mojom.dart' as input_events;
import 'package:mojo/services/view_manager/public/interfaces/view_manager.mojom.dart' as view_manager;
import 'package:services/js/test/echo_service.mojom.dart' as echo_service_mojom;
// The Promise returned by the vmcApp's echoString() method will not
// resolve until the vmcApp's onEmbed() method runs.
var echoService = vmcApp.requestService(echoServiceMojom.EchoService);
echoService.echoString("success").then(function(response) {
internals.notifyTestComplete(response.value);
});
class IFrameEmbed extends Application {
IFrameEmbed.fromHandle(MojoHandle handle) : super.fromHandle(handle);
IFrameEmbed(MojoMessagePipeEndpoint endpoint) : super(endpoint);
// Using internals.connectToService here, instead of just connecting
// with vmcApp, because we just need a MessagePipe handle (not a proxy).
var vmcService = internals.connectToService(vmcURL, ViewManager.ViewManagerClient.name);
document.querySelector("iframe").embedViewManagerClient(vmcService);
void initialize(List<String> args, String url) {
// The vmcApp provides ViewManagerClient and EchoService.
const vmcURL =
"http://127.0.0.1:8000/sky/tests/services/resources/iframe-vmc.js";
final vmcAppConnection = connectToApplication(vmcURL);
// The Promise returned by the vmcApp's echoString() method will not
// resolve until the vmcApp's onEmbed() method runs.
final echoService = new echo_service_mojom.EchoServiceProxy.unbound();
vmcAppConnection.requestService(echoService);
echoService.echoString("success").then((response) {
internals.notifyTestComplete(response.value);
});
var applicationPipe = new MojoMessagePipe();
var proxyEndpoint = applicationPipe.endpoints[0];
var applicationEndpoint = applicationPipe.endpoints[1];
vmcAppConnection.remoteServiceProvider.connectToService(
view_manager.ViewManagerClient.name, applicationEndpoint);
document.querySelector("iframe").
embedViewManagerClient(proxyEndpoint.handle.h);
}
}
main() {
var messagePipe = new MojoMessagePipe();
var app = new IFrameEmbed(messagePipe.endpoints[1]);
app.listen();
var shellProxy = new shell_mojom.ShellProxy.fromHandle(
new MojoHandle(internals.takeShellProxyHandle()));
app.initializeFromShellProxy(shellProxy, [], "");
}
</script>
</html>
</sky>

View File

@ -29,11 +29,6 @@ Internals* GetInternals() {
return static_cast<Internals*>(state->GetUserData(&kInternalsKey));
}
void RenderTreeAsText(Dart_NativeArguments args) {
Dart_Handle result = StdStringToDart(GetInternals()->RenderTreeAsText());
Dart_SetReturnValue(args, result);
}
void ContentAsText(Dart_NativeArguments args) {
Dart_Handle result = StdStringToDart(GetInternals()->ContentAsText());
Dart_SetReturnValue(args, result);
@ -44,28 +39,33 @@ void NotifyTestComplete(Dart_NativeArguments args) {
GetInternals()->NotifyTestComplete(StdStringFromDart(test_result));
}
void RenderTreeAsText(Dart_NativeArguments args) {
Dart_Handle result = StdStringToDart(GetInternals()->RenderTreeAsText());
Dart_SetReturnValue(args, result);
}
void TakeShellProxyHandle(Dart_NativeArguments args) {
Dart_SetIntegerReturnValue(args,
GetInternals()->TakeShellProxyHandle().value());
}
void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) {
Dart_SetIntegerReturnValue(args,
GetInternals()->TakeServicesProvidedToEmbedder().value());
void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) {
Dart_SetIntegerReturnValue(
args, GetInternals()->TakeServicesProvidedByEmbedder().value());
}
void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) {
Dart_SetIntegerReturnValue(args,
GetInternals()->TakeServicesProvidedByEmbedder().value());
void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) {
Dart_SetIntegerReturnValue(
args, GetInternals()->TakeServicesProvidedToEmbedder().value());
}
const DartBuiltin::Natives kNativeFunctions[] = {
{"renderTreeAsText", RenderTreeAsText, 0},
{"contentAsText", ContentAsText, 0},
{"notifyTestComplete", NotifyTestComplete, 1},
{"takeShellProxyHandle", TakeShellProxyHandle, 0},
{"takeServicesProvidedToEmbedder", TakeServicesProvidedToEmbedder, 0},
{"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0},
{"contentAsText", ContentAsText, 0},
{"notifyTestComplete", NotifyTestComplete, 1},
{"renderTreeAsText", RenderTreeAsText, 0},
{"takeShellProxyHandle", TakeShellProxyHandle, 0},
{"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0},
{"takeServicesProvidedToEmbedder", TakeServicesProvidedToEmbedder, 0},
};
const DartBuiltin& GetBuiltin() {
@ -86,12 +86,12 @@ const uint8_t* Symbolizer(Dart_NativeFunction native_function) {
const char kLibraryName[] = "dart:sky.internals";
const char kLibrarySource[] = R"DART(
String renderTreeAsText() native "renderTreeAsText";
String contentAsText() native "contentAsText";
void notifyTestComplete(String test_result) native "notifyTestComplete";
String renderTreeAsText() native "renderTreeAsText";
int takeShellProxyHandle() native "takeShellProxyHandle";
int takeServicesProvidedToEmbedder() native "takeServicesProvidedToEmbedder";
int takeServicesProvidedByEmbedder() native "takeServicesProvidedByEmbedder";
int takeServicesProvidedToEmbedder() native "takeServicesProvidedToEmbedder";
)DART";
} // namespace
@ -172,20 +172,6 @@ void Internals::ConnectToApplication(
}
}
mojo::Handle Internals::ConnectToService(
const std::string& application_url, const std::string& interface_name) {
if (!document_view_)
return mojo::Handle();
mojo::ServiceProviderPtr service_provider;
ConnectToApplication(application_url, mojo::GetProxy(&service_provider),
nullptr);
mojo::MessagePipe pipe;
service_provider->ConnectToService(interface_name, pipe.handle1.Pass());
return pipe.handle0.release();
}
void Internals::pauseAnimations(double pauseTime) {
if (pauseTime < 0)
return;

View File

@ -35,9 +35,6 @@ class Internals : public base::SupportsUserData::Data,
mojo::Handle TakeServicesProvidedToEmbedder();
mojo::Handle TakeServicesProvidedByEmbedder();
mojo::Handle ConnectToService(
const std::string& application_url, const std::string& interface_name);
void pauseAnimations(double pauseTime);
private: