Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Unified Diff: sky/viewer/internals.cc

Issue 837283002: Mojo JS Bindings: merge Application, Shell, ServiceProvider with Sky (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« sky/viewer/internals.h ('K') | « sky/viewer/internals.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/viewer/internals.cc
diff --git a/sky/viewer/internals.cc b/sky/viewer/internals.cc
index 99e8c3bef07240ac249e64f17567318dbfef5497..adfa48094596d9efaeea0db4f6a25b536cb444bc 100644
--- a/sky/viewer/internals.cc
+++ b/sky/viewer/internals.cc
@@ -7,6 +7,7 @@
#include "mojo/edk/js/core.h"
#include "mojo/edk/js/handle.h"
#include "mojo/edk/js/support.h"
+#include "mojo/edk/js/threading.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/cpp/bindings/array.h"
#include "mojo/public/interfaces/application/shell.mojom.h"
@@ -21,6 +22,27 @@ namespace sky {
gin::WrapperInfo Internals::kWrapperInfo = {gin::kEmbedderNativeGin};
+class JSShellProxy : public mojo::Shell {
+ public:
+ JSShellProxy(mojo::ScopedMessagePipeHandle handle, Internals* internals)
+ : internals_(internals),
+ binding_(this, handle.Pass()) {
+ }
+
+ void ConnectToApplication(
+ const mojo::String& application_url,
+ mojo::InterfaceRequest<mojo::ServiceProvider> provider) override {
+ if (internals_->document_view_) {
+ mojo::Shell* shell = internals_->document_view_->shell();
+ shell->ConnectToApplication(application_url, provider.Pass());
+ }
+ }
+
+ private:
+ Internals* internals_;
+ mojo::Binding<mojo::Shell> binding_;
+};
+
// static
gin::Handle<Internals> Internals::Create(
v8::Isolate* isolate, DocumentView* document_view) {
@@ -31,6 +53,8 @@ gin::Handle<Internals> Internals::Create(
mojo::js::Core::GetModule(isolate));
object->Set(gin::StringToV8(isolate, "support"),
mojo::js::Support::GetModule(isolate));
+ object->Set(gin::StringToV8(isolate, "threading"),
+ mojo::js::Threading::GetModule(isolate));
return internals;
}
@@ -40,6 +64,8 @@ Internals::Internals(DocumentView* document_view)
}
Internals::~Internals() {
+ for (unsigned i = 0; i < js_shell_proxies_.size(); i++)
+ delete js_shell_proxies_[i];
}
gin::ObjectTemplateBuilder Internals::GetObjectTemplateBuilder(
@@ -49,7 +75,17 @@ gin::ObjectTemplateBuilder Internals::GetObjectTemplateBuilder(
.SetMethod("contentAsText", &Internals::ContentAsText)
.SetMethod("notifyTestComplete", &Internals::NotifyTestComplete)
.SetMethod("connectToService", &Internals::ConnectToService)
- .SetMethod("pauseAnimations", &Internals::pauseAnimations);
+ .SetMethod("pauseAnimations", &Internals::pauseAnimations)
+ .SetMethod("shellProxyHandle", &Internals::ShellProxyHandle);
+}
+
+// Returns a MessagePipe handle that's connected to a JSShellProxy. The caller
+// owns the handle.
+mojo::Handle Internals::ShellProxyHandle() {
+ mojo::MessagePipe pipe;
+ if (document_view_)
+ js_shell_proxies_.push_back(new JSShellProxy(pipe.handle0.Pass(), this));
+ return pipe.handle1.release();
abarth-chromium 2015/01/07 22:52:01 Hum... Can we return the same JS object each time
hansmuller1 2015/01/07 23:33:04 This one-time method is now called passProxyHandle
}
std::string Internals::RenderTreeAsText() {
« sky/viewer/internals.h ('K') | « sky/viewer/internals.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698