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

Side by Side 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 unified diff | Download patch
« sky/viewer/internals.h ('K') | « sky/viewer/internals.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sky/viewer/internals.h" 5 #include "sky/viewer/internals.h"
6 6
7 #include "mojo/edk/js/core.h" 7 #include "mojo/edk/js/core.h"
8 #include "mojo/edk/js/handle.h" 8 #include "mojo/edk/js/handle.h"
9 #include "mojo/edk/js/support.h" 9 #include "mojo/edk/js/support.h"
10 #include "mojo/edk/js/threading.h"
10 #include "mojo/public/cpp/application/connect.h" 11 #include "mojo/public/cpp/application/connect.h"
11 #include "mojo/public/cpp/bindings/array.h" 12 #include "mojo/public/cpp/bindings/array.h"
12 #include "mojo/public/interfaces/application/shell.mojom.h" 13 #include "mojo/public/interfaces/application/shell.mojom.h"
13 #include "sky/engine/public/web/WebDocument.h" 14 #include "sky/engine/public/web/WebDocument.h"
14 #include "sky/engine/public/web/WebFrame.h" 15 #include "sky/engine/public/web/WebFrame.h"
15 #include "sky/engine/public/web/WebView.h" 16 #include "sky/engine/public/web/WebView.h"
16 #include "sky/viewer/document_view.h" 17 #include "sky/viewer/document_view.h"
17 #include "v8/include/v8.h" 18 #include "v8/include/v8.h"
18 #include <limits> 19 #include <limits>
19 20
20 namespace sky { 21 namespace sky {
21 22
22 gin::WrapperInfo Internals::kWrapperInfo = {gin::kEmbedderNativeGin}; 23 gin::WrapperInfo Internals::kWrapperInfo = {gin::kEmbedderNativeGin};
23 24
25 class JSShellProxy : public mojo::Shell {
26 public:
27 JSShellProxy(mojo::ScopedMessagePipeHandle handle, Internals* internals)
28 : internals_(internals),
29 binding_(this, handle.Pass()) {
30 }
31
32 void ConnectToApplication(
33 const mojo::String& application_url,
34 mojo::InterfaceRequest<mojo::ServiceProvider> provider) override {
35 if (internals_->document_view_) {
36 mojo::Shell* shell = internals_->document_view_->shell();
37 shell->ConnectToApplication(application_url, provider.Pass());
38 }
39 }
40
41 private:
42 Internals* internals_;
43 mojo::Binding<mojo::Shell> binding_;
44 };
45
24 // static 46 // static
25 gin::Handle<Internals> Internals::Create( 47 gin::Handle<Internals> Internals::Create(
26 v8::Isolate* isolate, DocumentView* document_view) { 48 v8::Isolate* isolate, DocumentView* document_view) {
27 gin::Handle<Internals> internals = 49 gin::Handle<Internals> internals =
28 gin::CreateHandle(isolate, new Internals(document_view)); 50 gin::CreateHandle(isolate, new Internals(document_view));
29 v8::Handle<v8::Object> object = internals.ToV8().As<v8::Object>(); 51 v8::Handle<v8::Object> object = internals.ToV8().As<v8::Object>();
30 object->Set(gin::StringToV8(isolate, "core"), 52 object->Set(gin::StringToV8(isolate, "core"),
31 mojo::js::Core::GetModule(isolate)); 53 mojo::js::Core::GetModule(isolate));
32 object->Set(gin::StringToV8(isolate, "support"), 54 object->Set(gin::StringToV8(isolate, "support"),
33 mojo::js::Support::GetModule(isolate)); 55 mojo::js::Support::GetModule(isolate));
56 object->Set(gin::StringToV8(isolate, "threading"),
57 mojo::js::Threading::GetModule(isolate));
34 return internals; 58 return internals;
35 } 59 }
36 60
37 Internals::Internals(DocumentView* document_view) 61 Internals::Internals(DocumentView* document_view)
38 : document_view_(document_view->GetWeakPtr()) { 62 : document_view_(document_view->GetWeakPtr()) {
39 mojo::ConnectToService(document_view->imported_services(), &test_harness_); 63 mojo::ConnectToService(document_view->imported_services(), &test_harness_);
40 } 64 }
41 65
42 Internals::~Internals() { 66 Internals::~Internals() {
67 for (unsigned i = 0; i < js_shell_proxies_.size(); i++)
68 delete js_shell_proxies_[i];
43 } 69 }
44 70
45 gin::ObjectTemplateBuilder Internals::GetObjectTemplateBuilder( 71 gin::ObjectTemplateBuilder Internals::GetObjectTemplateBuilder(
46 v8::Isolate* isolate) { 72 v8::Isolate* isolate) {
47 return Wrappable<Internals>::GetObjectTemplateBuilder(isolate) 73 return Wrappable<Internals>::GetObjectTemplateBuilder(isolate)
48 .SetMethod("renderTreeAsText", &Internals::RenderTreeAsText) 74 .SetMethod("renderTreeAsText", &Internals::RenderTreeAsText)
49 .SetMethod("contentAsText", &Internals::ContentAsText) 75 .SetMethod("contentAsText", &Internals::ContentAsText)
50 .SetMethod("notifyTestComplete", &Internals::NotifyTestComplete) 76 .SetMethod("notifyTestComplete", &Internals::NotifyTestComplete)
51 .SetMethod("connectToService", &Internals::ConnectToService) 77 .SetMethod("connectToService", &Internals::ConnectToService)
52 .SetMethod("pauseAnimations", &Internals::pauseAnimations); 78 .SetMethod("pauseAnimations", &Internals::pauseAnimations)
79 .SetMethod("shellProxyHandle", &Internals::ShellProxyHandle);
80 }
81
82 // Returns a MessagePipe handle that's connected to a JSShellProxy. The caller
83 // owns the handle.
84 mojo::Handle Internals::ShellProxyHandle() {
85 mojo::MessagePipe pipe;
86 if (document_view_)
87 js_shell_proxies_.push_back(new JSShellProxy(pipe.handle0.Pass(), this));
88 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
53 } 89 }
54 90
55 std::string Internals::RenderTreeAsText() { 91 std::string Internals::RenderTreeAsText() {
56 if (!document_view_) 92 if (!document_view_)
57 return std::string(); 93 return std::string();
58 return document_view_->web_view()->mainFrame()->renderTreeAsText().utf8(); 94 return document_view_->web_view()->mainFrame()->renderTreeAsText().utf8();
59 } 95 }
60 96
61 std::string Internals::ContentAsText() { 97 std::string Internals::ContentAsText() {
62 if (!document_view_) 98 if (!document_view_)
(...skipping 24 matching lines...) Expand all
87 } 123 }
88 124
89 void Internals::pauseAnimations(double pauseTime) { 125 void Internals::pauseAnimations(double pauseTime) {
90 if (pauseTime < 0) 126 if (pauseTime < 0)
91 return; 127 return;
92 128
93 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin g(pauseTime); 129 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin g(pauseTime);
94 } 130 }
95 131
96 } // namespace sky 132 } // namespace sky
OLDNEW
« 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