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