| OLD | NEW |
| 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 "sky/engine/public/web/WebDocument.h" | 13 #include "sky/engine/public/web/WebDocument.h" |
| 14 #include "sky/engine/public/web/WebFrame.h" | 14 #include "sky/engine/public/web/WebFrame.h" |
| 15 #include "sky/engine/public/web/WebView.h" | 15 #include "sky/engine/public/web/WebView.h" |
| 16 #include "sky/viewer/document_view.h" | 16 #include "sky/viewer/document_view.h" |
| 17 #include "v8/include/v8.h" | 17 #include "v8/include/v8.h" |
| 18 #include <limits> | 18 #include <limits> |
| 19 | 19 |
| 20 namespace sky { | 20 namespace sky { |
| 21 | 21 |
| 22 gin::WrapperInfo Internals::kWrapperInfo = {gin::kEmbedderNativeGin}; | 22 gin::WrapperInfo Internals::kWrapperInfo = {gin::kEmbedderNativeGin}; |
| 23 | 23 |
| 24 // static | 24 // static |
| 25 gin::Handle<Internals> Internals::Create( | 25 gin::Handle<Internals> Internals::Create( |
| 26 v8::Isolate* isolate, DocumentView* document_view) { | 26 v8::Isolate* isolate, DocumentView* document_view) { |
| 27 gin::Handle<Internals> internals = | 27 gin::Handle<Internals> internals = |
| 28 gin::CreateHandle(isolate, new Internals(document_view)); | 28 gin::CreateHandle(isolate, new Internals(document_view)); |
| 29 v8::Handle<v8::Object> object = internals.ToV8().As<v8::Object>(); | 29 v8::Handle<v8::Object> object = internals.ToV8().As<v8::Object>(); |
| 30 object->Set(gin::StringToV8(isolate, "core"), | 30 object->Set(gin::StringToV8(isolate, "core"), |
| 31 mojo::js::Core::GetModule(isolate)); | 31 mojo::js::Core::GetModule(isolate)); |
| 32 object->Set(gin::StringToV8(isolate, "support"), | 32 object->Set(gin::StringToV8(isolate, "support"), |
| 33 mojo::js::Support::GetModule(isolate)); | 33 mojo::js::Support::GetModule(isolate)); |
| 34 object->Set(gin::StringToV8(isolate, "threading"), |
| 35 mojo::js::Threading::GetModule(isolate)); |
| 34 return internals; | 36 return internals; |
| 35 } | 37 } |
| 36 | 38 |
| 37 Internals::Internals(DocumentView* document_view) | 39 Internals::Internals(DocumentView* document_view) |
| 38 : document_view_(document_view->GetWeakPtr()) { | 40 : document_view_(document_view->GetWeakPtr()), |
| 41 shell_binding_(this) { |
| 39 mojo::ConnectToService(document_view->imported_services(), &test_harness_); | 42 mojo::ConnectToService(document_view->imported_services(), &test_harness_); |
| 40 } | 43 } |
| 41 | 44 |
| 42 Internals::~Internals() { | 45 Internals::~Internals() { |
| 43 } | 46 } |
| 44 | 47 |
| 45 gin::ObjectTemplateBuilder Internals::GetObjectTemplateBuilder( | 48 gin::ObjectTemplateBuilder Internals::GetObjectTemplateBuilder( |
| 46 v8::Isolate* isolate) { | 49 v8::Isolate* isolate) { |
| 47 return Wrappable<Internals>::GetObjectTemplateBuilder(isolate) | 50 return Wrappable<Internals>::GetObjectTemplateBuilder(isolate) |
| 48 .SetMethod("renderTreeAsText", &Internals::RenderTreeAsText) | 51 .SetMethod("renderTreeAsText", &Internals::RenderTreeAsText) |
| 49 .SetMethod("contentAsText", &Internals::ContentAsText) | 52 .SetMethod("contentAsText", &Internals::ContentAsText) |
| 50 .SetMethod("notifyTestComplete", &Internals::NotifyTestComplete) | 53 .SetMethod("notifyTestComplete", &Internals::NotifyTestComplete) |
| 51 .SetMethod("connectToService", &Internals::ConnectToService) | 54 .SetMethod("connectToService", &Internals::ConnectToService) |
| 52 .SetMethod("connectToEmbedderService", | 55 .SetMethod("connectToEmbedderService", |
| 53 &Internals::ConnectToEmbedderService) | 56 &Internals::ConnectToEmbedderService) |
| 54 .SetMethod("pauseAnimations", &Internals::pauseAnimations); | 57 .SetMethod("pauseAnimations", &Internals::pauseAnimations) |
| 58 .SetMethod("passShellProxyHandle", &Internals::PassShellProxyHandle); |
| 55 } | 59 } |
| 56 | 60 |
| 57 std::string Internals::RenderTreeAsText() { | 61 std::string Internals::RenderTreeAsText() { |
| 58 if (!document_view_) | 62 if (!document_view_) |
| 59 return std::string(); | 63 return std::string(); |
| 60 return document_view_->web_view()->mainFrame()->renderTreeAsText().utf8(); | 64 return document_view_->web_view()->mainFrame()->renderTreeAsText().utf8(); |
| 61 } | 65 } |
| 62 | 66 |
| 63 std::string Internals::ContentAsText() { | 67 std::string Internals::ContentAsText() { |
| 64 if (!document_view_) | 68 if (!document_view_) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 78 const std::string& interface_name) { | 82 const std::string& interface_name) { |
| 79 if (!document_view_) | 83 if (!document_view_) |
| 80 return mojo::Handle(); | 84 return mojo::Handle(); |
| 81 | 85 |
| 82 mojo::MessagePipe pipe; | 86 mojo::MessagePipe pipe; |
| 83 document_view_->imported_services()->ConnectToService(interface_name, | 87 document_view_->imported_services()->ConnectToService(interface_name, |
| 84 pipe.handle1.Pass()); | 88 pipe.handle1.Pass()); |
| 85 return pipe.handle0.release(); | 89 return pipe.handle0.release(); |
| 86 } | 90 } |
| 87 | 91 |
| 92 // Returns a MessagePipe handle that's connected to this Shell. The caller |
| 93 // owns the handle and is expected to use it to create the JS Application for |
| 94 // the DocumentView. |
| 95 mojo::Handle Internals::PassShellProxyHandle() { |
| 96 mojo::MessagePipe pipe; |
| 97 if (!shell_binding_.is_bound()) |
| 98 shell_binding_.Bind(pipe.handle0.Pass()); |
| 99 return pipe.handle1.release(); |
| 100 } |
| 101 |
| 102 void Internals::ConnectToApplication( |
| 103 const mojo::String& application_url, |
| 104 mojo::InterfaceRequest<mojo::ServiceProvider> provider) { |
| 105 if (document_view_) |
| 106 document_view_->shell()->ConnectToApplication( |
| 107 application_url, provider.Pass()); |
| 108 } |
| 109 |
| 88 mojo::Handle Internals::ConnectToService( | 110 mojo::Handle Internals::ConnectToService( |
| 89 const std::string& application_url, const std::string& interface_name) { | 111 const std::string& application_url, const std::string& interface_name) { |
| 90 if (!document_view_) | 112 if (!document_view_) |
| 91 return mojo::Handle(); | 113 return mojo::Handle(); |
| 92 | 114 |
| 93 mojo::ServiceProviderPtr service_provider; | 115 mojo::ServiceProviderPtr service_provider; |
| 94 document_view_->shell()->ConnectToApplication( | 116 ConnectToApplication(application_url, mojo::GetProxy(&service_provider)); |
| 95 application_url, mojo::GetProxy(&service_provider)); | |
| 96 | 117 |
| 97 mojo::MessagePipe pipe; | 118 mojo::MessagePipe pipe; |
| 98 service_provider->ConnectToService(interface_name, pipe.handle1.Pass()); | 119 service_provider->ConnectToService(interface_name, pipe.handle1.Pass()); |
| 99 return pipe.handle0.release(); | 120 return pipe.handle0.release(); |
| 100 } | 121 } |
| 101 | 122 |
| 102 void Internals::pauseAnimations(double pauseTime) { | 123 void Internals::pauseAnimations(double pauseTime) { |
| 103 if (pauseTime < 0) | 124 if (pauseTime < 0) |
| 104 return; | 125 return; |
| 105 | 126 |
| 106 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin
g(pauseTime); | 127 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin
g(pauseTime); |
| 107 } | 128 } |
| 108 | 129 |
| 109 } // namespace sky | 130 } // namespace sky |
| OLD | NEW |