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

Side by Side Diff: sky/viewer/internals.cc

Issue 944733002: Sky should expose services provided to/by embedder (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « 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/engine/config.h" 5 #include "sky/engine/config.h"
6 #include "sky/viewer/internals.h" 6 #include "sky/viewer/internals.h"
7 7
8 #include "mojo/public/cpp/application/connect.h" 8 #include "mojo/public/cpp/application/connect.h"
9 #include "mojo/public/cpp/bindings/array.h" 9 #include "mojo/public/cpp/bindings/array.h"
10 #include "sky/engine/public/web/WebDocument.h" 10 #include "sky/engine/public/web/WebDocument.h"
(...skipping 26 matching lines...) Expand all
37 void ContentAsText(Dart_NativeArguments args) { 37 void ContentAsText(Dart_NativeArguments args) {
38 Dart_Handle result = StdStringToDart(GetInternals()->ContentAsText()); 38 Dart_Handle result = StdStringToDart(GetInternals()->ContentAsText());
39 Dart_SetReturnValue(args, result); 39 Dart_SetReturnValue(args, result);
40 } 40 }
41 41
42 void NotifyTestComplete(Dart_NativeArguments args) { 42 void NotifyTestComplete(Dart_NativeArguments args) {
43 Dart_Handle test_result = Dart_GetNativeArgument(args, 0); 43 Dart_Handle test_result = Dart_GetNativeArgument(args, 0);
44 GetInternals()->NotifyTestComplete(StdStringFromDart(test_result)); 44 GetInternals()->NotifyTestComplete(StdStringFromDart(test_result));
45 } 45 }
46 46
47 void PassShellProxyHandle(Dart_NativeArguments args) { 47 void TakeShellProxyHandle(Dart_NativeArguments args) {
48 Dart_SetIntegerReturnValue(args, GetInternals()->PassShellProxyHandle().value( )); 48 Dart_SetIntegerReturnValue(args,
49 GetInternals()->TakeShellProxyHandle().value());
50 }
51
52 void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) {
53 Dart_SetIntegerReturnValue(args,
54 GetInternals()->TakeServicesProvidedToEmbedder().value());
55 }
56
57 void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) {
58 Dart_SetIntegerReturnValue(args,
59 GetInternals()->TakeServicesProvidedByEmbedder().value());
49 } 60 }
50 61
51 const DartBuiltin::Natives kNativeFunctions[] = { 62 const DartBuiltin::Natives kNativeFunctions[] = {
52 {"renderTreeAsText", RenderTreeAsText, 0}, 63 {"renderTreeAsText", RenderTreeAsText, 0},
53 {"contentAsText", ContentAsText, 0}, 64 {"contentAsText", ContentAsText, 0},
54 {"notifyTestComplete", NotifyTestComplete, 1}, 65 {"notifyTestComplete", NotifyTestComplete, 1},
55 {"passShellProxyHandle", PassShellProxyHandle, 0}, 66 {"takeShellProxyHandle", TakeShellProxyHandle, 0},
67 {"takeServicesProvidedToEmbedder", TakeServicesProvidedToEmbedder, 0},
68 {"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0},
56 }; 69 };
57 70
58 const DartBuiltin& GetBuiltin() { 71 const DartBuiltin& GetBuiltin() {
59 static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions, 72 static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions,
60 arraysize(kNativeFunctions)); 73 arraysize(kNativeFunctions));
61 return builtin; 74 return builtin;
62 } 75 }
63 76
64 Dart_NativeFunction Resolver(Dart_Handle name, 77 Dart_NativeFunction Resolver(Dart_Handle name,
65 int argument_count, 78 int argument_count,
66 bool* auto_setup_scope) { 79 bool* auto_setup_scope) {
67 return GetBuiltin().Resolver(name, argument_count, auto_setup_scope); 80 return GetBuiltin().Resolver(name, argument_count, auto_setup_scope);
68 } 81 }
69 82
70 const uint8_t* Symbolizer(Dart_NativeFunction native_function) { 83 const uint8_t* Symbolizer(Dart_NativeFunction native_function) {
71 return GetBuiltin().Symbolizer(native_function); 84 return GetBuiltin().Symbolizer(native_function);
72 } 85 }
73 86
74 const char kLibraryName[] = "dart:sky.internals"; 87 const char kLibraryName[] = "dart:sky.internals";
75 const char kLibrarySource[] = R"DART( 88 const char kLibrarySource[] = R"DART(
76 String renderTreeAsText() native "renderTreeAsText"; 89 String renderTreeAsText() native "renderTreeAsText";
77 String contentAsText() native "contentAsText"; 90 String contentAsText() native "contentAsText";
78 void notifyTestComplete(String test_result) native "notifyTestComplete"; 91 void notifyTestComplete(String test_result) native "notifyTestComplete";
79 int passShellProxyHandle() native "passShellProxyHandle"; 92 int takeShellProxyHandle() native "takeShellProxyHandle";
93 int takeServicesProvidedToEmbedder() native "takeServicesProvidedToEmbedder";
94 int takeServicesProvidedByEmbedder() native "takeServicesProvidedByEmbedder";
80 )DART"; 95 )DART";
81 96
82 } // namespace 97 } // namespace
83 98
84 void Internals::Create(Dart_Isolate isolate, DocumentView* document_view) { 99 void Internals::Create(Dart_Isolate isolate, DocumentView* document_view) {
85 DartState* state = DartState::From(isolate); 100 DartState* state = DartState::From(isolate);
86 state->SetUserData(&kInternalsKey, new Internals(document_view)); 101 state->SetUserData(&kInternalsKey, new Internals(document_view));
87 Dart_Handle library = 102 Dart_Handle library =
88 Dart_LoadLibrary(Dart_NewStringFromCString(kLibraryName), 103 Dart_LoadLibrary(Dart_NewStringFromCString(kLibraryName),
89 Dart_NewStringFromCString(kLibrarySource), 0, 0); 104 Dart_NewStringFromCString(kLibrarySource), 0, 0);
90 CHECK(!LogIfError(library)); 105 CHECK(!LogIfError(library));
91 CHECK(!LogIfError(Dart_FinalizeLoading(true))); 106 CHECK(!LogIfError(Dart_FinalizeLoading(true)));
92 CHECK(!LogIfError(Dart_SetNativeResolver(library, Resolver, Symbolizer))); 107 CHECK(!LogIfError(Dart_SetNativeResolver(library, Resolver, Symbolizer)));
93 } 108 }
94 109
95 Internals::Internals(DocumentView* document_view) 110 Internals::Internals(DocumentView* document_view)
96 : document_view_(document_view->GetWeakPtr()), 111 : document_view_(document_view->GetWeakPtr()),
97 shell_binding_(this) { 112 shell_binding_(this) {
98 if (document_view_->imported_services()) 113 test_harness_ = document_view_->TakeTestHarness();
99 mojo::ConnectToService(document_view_->imported_services(), &test_harness_);
100 } 114 }
101 115
102 Internals::~Internals() { 116 Internals::~Internals() {
103 } 117 }
104 118
105 std::string Internals::RenderTreeAsText() { 119 std::string Internals::RenderTreeAsText() {
106 if (!document_view_) 120 if (!document_view_)
107 return std::string(); 121 return std::string();
108 return document_view_->web_view()->mainFrame()->renderTreeAsText().utf8(); 122 return document_view_->web_view()->mainFrame()->renderTreeAsText().utf8();
109 } 123 }
110 124
111 std::string Internals::ContentAsText() { 125 std::string Internals::ContentAsText() {
112 if (!document_view_) 126 if (!document_view_)
113 return std::string(); 127 return std::string();
114 return document_view_->web_view()->mainFrame()->contentAsText( 128 return document_view_->web_view()->mainFrame()->contentAsText(
115 1024*1024).utf8(); 129 1024*1024).utf8();
116 } 130 }
117 131
118 void Internals::NotifyTestComplete(const std::string& test_result) { 132 void Internals::NotifyTestComplete(const std::string& test_result) {
119 if (!RuntimeFlags::Get().testing()) 133 if (!RuntimeFlags::Get().testing())
120 return; 134 return;
121 std::vector<unsigned char> pixels; 135 std::vector<unsigned char> pixels;
122 document_view_->GetPixelsForTesting(&pixels); 136 document_view_->GetPixelsForTesting(&pixels);
123 if (test_harness_) { 137 if (test_harness_) {
124 test_harness_->OnTestComplete(test_result, 138 test_harness_->OnTestComplete(test_result,
125 mojo::Array<uint8_t>::From(pixels)); 139 mojo::Array<uint8_t>::From(pixels));
126 } 140 }
127 } 141 }
128 142
129 mojo::Handle Internals::ConnectToEmbedderService( 143 mojo::Handle Internals::TakeServicesProvidedToEmbedder() {
130 const std::string& interface_name) { 144 if (!document_view_)
131 if (!document_view_ || !document_view_->imported_services())
132 return mojo::Handle(); 145 return mojo::Handle();
146 return document_view_->TakeServicesProvidedToEmbedder().release();
147 }
133 148
134 mojo::MessagePipe pipe; 149 mojo::Handle Internals::TakeServicesProvidedByEmbedder() {
135 document_view_->imported_services()->ConnectToService(interface_name, 150 if (!document_view_)
136 pipe.handle1.Pass()); 151 return mojo::Handle();
137 return pipe.handle0.release(); 152 return document_view_->TakeServicesProvidedByEmbedder().release();
138 } 153 }
139 154
140 // Returns a MessagePipe handle that's connected to this Shell. The caller 155 // Returns a MessagePipe handle that's connected to this Shell. The caller
141 // owns the handle and is expected to use it to create the JS Application for 156 // owns the handle and is expected to use it to create the JS Application for
142 // the DocumentView. 157 // the DocumentView.
143 mojo::Handle Internals::PassShellProxyHandle() { 158 mojo::Handle Internals::TakeShellProxyHandle() {
144 mojo::ShellPtr shell; 159 mojo::ShellPtr shell;
145 if (!shell_binding_.is_bound()) 160 if (!shell_binding_.is_bound())
146 shell_binding_.Bind(GetProxy(&shell)); 161 shell_binding_.Bind(GetProxy(&shell));
147 return shell.PassMessagePipe().release(); 162 return shell.PassMessagePipe().release();
148 } 163 }
149 164
150 void Internals::ConnectToApplication( 165 void Internals::ConnectToApplication(
151 const mojo::String& application_url, 166 const mojo::String& application_url,
152 mojo::InterfaceRequest<mojo::ServiceProvider> services, 167 mojo::InterfaceRequest<mojo::ServiceProvider> services,
153 mojo::ServiceProviderPtr exposed_services) { 168 mojo::ServiceProviderPtr exposed_services) {
(...skipping 18 matching lines...) Expand all
172 } 187 }
173 188
174 void Internals::pauseAnimations(double pauseTime) { 189 void Internals::pauseAnimations(double pauseTime) {
175 if (pauseTime < 0) 190 if (pauseTime < 0)
176 return; 191 return;
177 192
178 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin g(pauseTime); 193 document_view_->web_view()->mainFrame()->document().pauseAnimationsForTestin g(pauseTime);
179 } 194 }
180 195
181 } // namespace sky 196 } // namespace sky
OLDNEW
« no previous file with comments | « sky/viewer/internals.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698