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

Side by Side Diff: dart/site/try/src/compilation.dart

Issue 349683003: Improve running in iframes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r37602. Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | dart/site/try/src/iframe_error_handler.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library trydart.compilation; 5 library trydart.compilation;
6 6
7 import 'dart:html' show 7 import 'dart:html' show
8 Blob, 8 Blob,
9 Element, 9 Element,
10 ErrorEvent, 10 ErrorEvent,
(...skipping 19 matching lines...) Expand all
30 interaction, 30 interaction,
31 outputDiv, 31 outputDiv,
32 outputFrame; 32 outputFrame;
33 33
34 import 'settings.dart' show 34 import 'settings.dart' show
35 alwaysRunInWorker, 35 alwaysRunInWorker,
36 minified, 36 minified,
37 onlyAnalyze, 37 onlyAnalyze,
38 verboseCompiler; 38 verboseCompiler;
39 39
40 import 'iframe_error_handler.dart' show
41 errorStream;
40 42
41 /** 43 /**
42 * Scheme for recognizing files stored in memory. 44 * Scheme for recognizing files stored in memory.
43 * 45 *
44 * From http://tools.ietf.org/html/bcp35#section-2.8: 46 * From http://tools.ietf.org/html/bcp35#section-2.8:
45 * 47 *
46 * Organizations that desire a private name space for URI scheme names 48 * Organizations that desire a private name space for URI scheme names
47 * are encouraged to use a prefix based on their domain name, expressed 49 * are encouraged to use a prefix based on their domain name, expressed
48 * in reverse order. For example, a URI scheme name of com-example-info 50 * in reverse order. For example, a URI scheme name of com-example-info
49 * might be registered by the vendor that owns the example.com domain 51 * might be registered by the vendor that owns the example.com domain
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // Fool isolate_helper.dart so it does not think this is an isolate. 155 // Fool isolate_helper.dart so it does not think this is an isolate.
154 var window = self; 156 var window = self;
155 function dartPrint(msg) { 157 function dartPrint(msg) {
156 self.postMessage(msg); 158 self.postMessage(msg);
157 }; 159 };
158 self.importScripts("$url"); 160 self.importScripts("$url");
159 '''; 161 ''';
160 var wrapperUrl = 162 var wrapperUrl =
161 Url.createObjectUrl(new Blob([wrapper], 'application/javascript')); 163 Url.createObjectUrl(new Blob([wrapper], 'application/javascript'));
162 objectUrls.add(wrapperUrl); 164 objectUrls.add(wrapperUrl);
163 void retryInIframe(_) { 165
164 var frame = makeOutputFrame(url); 166 run(wrapperUrl, () => makeOutputFrame(url));
165 outputFrame.replaceWith(frame);
166 outputFrame = frame;
167 console.append(buildButton('Try in iframe', retryInIframe));
168 }
169 void onError(String errorMessage) {
170 console.appendText(errorMessage);
171 console.appendText(' ');
172 console.append(buildButton('Try in iframe', retryInIframe));
173 console.appendText('\n');
174 }
175 if (usesDartHtml && !alwaysRunInWorker) {
176 retryInIframe(null);
177 } else {
178 runInWorker(wrapperUrl, onError);
179 }
180 } 167 }
181 168
182 // This is called in browsers that do not support creating Object 169 // This is called in browsers that do not support creating Object
183 // URLs in a web worker. For example, Safari and Firefox < 21. 170 // URLs in a web worker. For example, Safari and Firefox < 21.
184 onCode(String code) { 171 onCode(String code) {
185 void retryInIframe(_) { 172 IFrameElement makeIframe() {
186 // The obvious thing would be to call [makeOutputFrame], but 173 // The obvious thing would be to call [makeOutputFrame], but
187 // Safari doesn't support access to Object URLs in an iframe. 174 // Safari doesn't support access to Object URLs in an iframe.
188 175
189 var frame = new IFrameElement() 176 IFrameElement frame = new IFrameElement()
190 ..src = 'iframe.html' 177 ..src = 'iframe.html'
191 ..style.width = '100%' 178 ..style.width = '100%'
192 ..style.height = '0px'; 179 ..style.height = '0px';
193 frame.onLoad.listen((_) { 180 frame.onLoad.listen((_) {
194 frame.contentWindow.postMessage(['source', code], '*'); 181 frame.contentWindow.postMessage(['source', code], '*');
195 }); 182 });
196 outputFrame.replaceWith(frame); 183 return frame;
197 outputFrame = frame;
198 }
199
200 void onError(String errorMessage) {
201 console.appendText(errorMessage);
202 console.appendText(' ');
203 console.append(buildButton('Try in iframe', retryInIframe));
204 console.appendText('\n');
205 } 184 }
206 185
207 String codeWithPrint = 186 String codeWithPrint =
208 '$code\n' 187 '$code\n'
209 'function dartPrint(msg) { postMessage(msg); }\n'; 188 'function dartPrint(msg) { postMessage(msg); }\n';
210 var url = 189 var url =
211 Url.createObjectUrl( 190 Url.createObjectUrl(
212 new Blob([codeWithPrint], 'application/javascript')); 191 new Blob([codeWithPrint], 'application/javascript'));
213 objectUrls.add(url); 192 objectUrls.add(url);
214 193
194 run(url, makeIframe);
195 }
196
197 void run(String url, IFrameElement makeIframe()) {
198 void retryInIframe() {
199 var frame = makeIframe();
200 frame.style
201 ..visibility = 'hidden'
202 ..position = 'absolute';
203 outputFrame.parent.insertBefore(frame, outputFrame);
204 outputFrame = frame;
205 errorStream(frame).listen(interaction.onIframeError);
206 }
207 void onError(String errorMessage) {
208 console
209 ..appendText(errorMessage)
210 ..appendText(' ')
211 ..append(buildButton('Try in iframe', (_) => retryInIframe()))
212 ..appendText('\n');
213 }
214 interaction.aboutToRun();
215 if (usesDartHtml && !alwaysRunInWorker) { 215 if (usesDartHtml && !alwaysRunInWorker) {
216 retryInIframe(null); 216 retryInIframe();
217 } else { 217 } else {
218 runInWorker(url, onError); 218 runInWorker(url, onError);
219 } 219 }
220 } 220 }
221 221
222 void runInWorker(String url, void onError(String errorMessage)) { 222 void runInWorker(String url, void onError(String errorMessage)) {
223 worker = new Worker(url) 223 worker = new Worker(url)
224 ..onMessage.listen((MessageEvent event) { 224 ..onMessage.listen((MessageEvent event) {
225 interaction.consolePrintLine(event.data); 225 interaction.consolePrintLine(event.data);
226 }) 226 })
(...skipping 23 matching lines...) Expand all
250 if (seenMessages.add('$begin:$end: [$kind] $message')) { 250 if (seenMessages.add('$begin:$end: [$kind] $message')) {
251 // Guard against duplicated messages. 251 // Guard against duplicated messages.
252 addDiagnostic(kind, message, begin, end); 252 addDiagnostic(kind, message, begin, end);
253 } 253 }
254 } 254 }
255 255
256 onCrash(data) { 256 onCrash(data) {
257 interaction.consolePrintLine(data); 257 interaction.consolePrintLine(data);
258 } 258 }
259 } 259 }
OLDNEW
« no previous file with comments | « no previous file | dart/site/try/src/iframe_error_handler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698