| 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/public/cpp/application/connect.h" | 10 #include "mojo/public/cpp/application/connect.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 Internals::~Internals() { | 42 Internals::~Internals() { |
| 43 } | 43 } |
| 44 | 44 |
| 45 gin::ObjectTemplateBuilder Internals::GetObjectTemplateBuilder( | 45 gin::ObjectTemplateBuilder Internals::GetObjectTemplateBuilder( |
| 46 v8::Isolate* isolate) { | 46 v8::Isolate* isolate) { |
| 47 return Wrappable<Internals>::GetObjectTemplateBuilder(isolate) | 47 return Wrappable<Internals>::GetObjectTemplateBuilder(isolate) |
| 48 .SetMethod("renderTreeAsText", &Internals::RenderTreeAsText) | 48 .SetMethod("renderTreeAsText", &Internals::RenderTreeAsText) |
| 49 .SetMethod("contentAsText", &Internals::ContentAsText) | 49 .SetMethod("contentAsText", &Internals::ContentAsText) |
| 50 .SetMethod("notifyTestComplete", &Internals::NotifyTestComplete) | 50 .SetMethod("notifyTestComplete", &Internals::NotifyTestComplete) |
| 51 .SetMethod("connectToService", &Internals::ConnectToService) | 51 .SetMethod("connectToService", &Internals::ConnectToService) |
| 52 .SetMethod("connectToEmbedderService", |
| 53 &Internals::ConnectToEmbedderService) |
| 52 .SetMethod("pauseAnimations", &Internals::pauseAnimations); | 54 .SetMethod("pauseAnimations", &Internals::pauseAnimations); |
| 53 } | 55 } |
| 54 | 56 |
| 55 std::string Internals::RenderTreeAsText() { | 57 std::string Internals::RenderTreeAsText() { |
| 56 if (!document_view_) | 58 if (!document_view_) |
| 57 return std::string(); | 59 return std::string(); |
| 58 return document_view_->web_view()->mainFrame()->renderTreeAsText().utf8(); | 60 return document_view_->web_view()->mainFrame()->renderTreeAsText().utf8(); |
| 59 } | 61 } |
| 60 | 62 |
| 61 std::string Internals::ContentAsText() { | 63 std::string Internals::ContentAsText() { |
| 62 if (!document_view_) | 64 if (!document_view_) |
| 63 return std::string(); | 65 return std::string(); |
| 64 return document_view_->web_view()->mainFrame()->contentAsText( | 66 return document_view_->web_view()->mainFrame()->contentAsText( |
| 65 1024*1024).utf8(); | 67 1024*1024).utf8(); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void Internals::NotifyTestComplete(const std::string& test_result) { | 70 void Internals::NotifyTestComplete(const std::string& test_result) { |
| 69 std::vector<unsigned char> pixels; | 71 std::vector<unsigned char> pixels; |
| 70 document_view_->GetPixelsForTesting(&pixels); | 72 document_view_->GetPixelsForTesting(&pixels); |
| 71 test_harness_->OnTestComplete(test_result, | 73 test_harness_->OnTestComplete(test_result, |
| 72 mojo::Array<uint8_t>::From(pixels)); | 74 mojo::Array<uint8_t>::From(pixels)); |
| 73 } | 75 } |
| 74 | 76 |
| 77 mojo::Handle Internals::ConnectToEmbedderService( |
| 78 const std::string& interface_name) { |
| 79 if (!document_view_) |
| 80 return mojo::Handle(); |
| 81 |
| 82 mojo::MessagePipe pipe; |
| 83 document_view_->imported_services()->ConnectToService(interface_name, |
| 84 pipe.handle1.Pass()); |
| 85 return pipe.handle0.release(); |
| 86 } |
| 87 |
| 75 mojo::Handle Internals::ConnectToService( | 88 mojo::Handle Internals::ConnectToService( |
| 76 const std::string& application_url, const std::string& interface_name) { | 89 const std::string& application_url, const std::string& interface_name) { |
| 77 if (!document_view_) | 90 if (!document_view_) |
| 78 return mojo::Handle(); | 91 return mojo::Handle(); |
| 79 | 92 |
| 80 mojo::ServiceProviderPtr service_provider; | 93 mojo::ServiceProviderPtr service_provider; |
| 81 document_view_->shell()->ConnectToApplication( | 94 document_view_->shell()->ConnectToApplication( |
| 82 application_url, mojo::GetProxy(&service_provider)); | 95 application_url, mojo::GetProxy(&service_provider)); |
| 83 | 96 |
| 84 mojo::MessagePipe pipe; | 97 mojo::MessagePipe pipe; |
| 85 service_provider->ConnectToService(interface_name, pipe.handle1.Pass()); | 98 service_provider->ConnectToService(interface_name, pipe.handle1.Pass()); |
| 86 return pipe.handle0.release(); | 99 return pipe.handle0.release(); |
| 87 } | 100 } |
| 88 | 101 |
| 89 void Internals::pauseAnimations(double pauseTime) { | 102 void Internals::pauseAnimations(double pauseTime) { |
| 90 if (pauseTime < 0) | 103 if (pauseTime < 0) |
| 91 return; | 104 return; |
| 92 | 105 |
| 93 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin
g(pauseTime); | 106 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin
g(pauseTime); |
| 94 } | 107 } |
| 95 | 108 |
| 96 } // namespace sky | 109 } // namespace sky |
| OLD | NEW |