| 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/edk/js/threading.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 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"), | 34 object->Set(gin::StringToV8(isolate, "threading"), |
| 35 mojo::js::Threading::GetModule(isolate)); | 35 mojo::js::Threading::GetModule(isolate)); |
| 36 return internals; | 36 return internals; |
| 37 } | 37 } |
| 38 | 38 |
| 39 Internals::Internals(DocumentView* document_view) | 39 Internals::Internals(DocumentView* document_view) |
| 40 : document_view_(document_view->GetWeakPtr()), | 40 : document_view_(document_view->GetWeakPtr()), |
| 41 shell_binding_(this) { | 41 shell_binding_(this) { |
| 42 mojo::ConnectToService(document_view->imported_services(), &test_harness_); | 42 if (document_view_->imported_services()) |
| 43 mojo::ConnectToService(document_view_->imported_services(), &test_harness_); |
| 43 } | 44 } |
| 44 | 45 |
| 45 Internals::~Internals() { | 46 Internals::~Internals() { |
| 46 } | 47 } |
| 47 | 48 |
| 48 gin::ObjectTemplateBuilder Internals::GetObjectTemplateBuilder( | 49 gin::ObjectTemplateBuilder Internals::GetObjectTemplateBuilder( |
| 49 v8::Isolate* isolate) { | 50 v8::Isolate* isolate) { |
| 50 return Wrappable<Internals>::GetObjectTemplateBuilder(isolate) | 51 return Wrappable<Internals>::GetObjectTemplateBuilder(isolate) |
| 51 .SetMethod("renderTreeAsText", &Internals::RenderTreeAsText) | 52 .SetMethod("renderTreeAsText", &Internals::RenderTreeAsText) |
| 52 .SetMethod("contentAsText", &Internals::ContentAsText) | 53 .SetMethod("contentAsText", &Internals::ContentAsText) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 67 std::string Internals::ContentAsText() { | 68 std::string Internals::ContentAsText() { |
| 68 if (!document_view_) | 69 if (!document_view_) |
| 69 return std::string(); | 70 return std::string(); |
| 70 return document_view_->web_view()->mainFrame()->contentAsText( | 71 return document_view_->web_view()->mainFrame()->contentAsText( |
| 71 1024*1024).utf8(); | 72 1024*1024).utf8(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void Internals::NotifyTestComplete(const std::string& test_result) { | 75 void Internals::NotifyTestComplete(const std::string& test_result) { |
| 75 std::vector<unsigned char> pixels; | 76 std::vector<unsigned char> pixels; |
| 76 document_view_->GetPixelsForTesting(&pixels); | 77 document_view_->GetPixelsForTesting(&pixels); |
| 77 test_harness_->OnTestComplete(test_result, | 78 if (test_harness_) { |
| 78 mojo::Array<uint8_t>::From(pixels)); | 79 test_harness_->OnTestComplete(test_result, |
| 80 mojo::Array<uint8_t>::From(pixels)); |
| 81 } |
| 79 } | 82 } |
| 80 | 83 |
| 81 mojo::Handle Internals::ConnectToEmbedderService( | 84 mojo::Handle Internals::ConnectToEmbedderService( |
| 82 const std::string& interface_name) { | 85 const std::string& interface_name) { |
| 83 if (!document_view_) | 86 if (!document_view_ || !document_view_->imported_services()) |
| 84 return mojo::Handle(); | 87 return mojo::Handle(); |
| 85 | 88 |
| 86 mojo::MessagePipe pipe; | 89 mojo::MessagePipe pipe; |
| 87 document_view_->imported_services()->ConnectToService(interface_name, | 90 document_view_->imported_services()->ConnectToService(interface_name, |
| 88 pipe.handle1.Pass()); | 91 pipe.handle1.Pass()); |
| 89 return pipe.handle0.release(); | 92 return pipe.handle0.release(); |
| 90 } | 93 } |
| 91 | 94 |
| 92 // Returns a MessagePipe handle that's connected to this Shell. The caller | 95 // 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 | 96 // owns the handle and is expected to use it to create the JS Application for |
| (...skipping 30 matching lines...) Expand all Loading... |
| 124 } | 127 } |
| 125 | 128 |
| 126 void Internals::pauseAnimations(double pauseTime) { | 129 void Internals::pauseAnimations(double pauseTime) { |
| 127 if (pauseTime < 0) | 130 if (pauseTime < 0) |
| 128 return; | 131 return; |
| 129 | 132 |
| 130 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin
g(pauseTime); | 133 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin
g(pauseTime); |
| 131 } | 134 } |
| 132 | 135 |
| 133 } // namespace sky | 136 } // namespace sky |
| OLD | NEW |