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

Unified Diff: lib/src/template/file_system_browser.dart

Issue 11092092: Support compiling templates in the browser. Base URL: git@github.com:dart-lang/dart-web-components.git@master
Patch Set: Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/template/file_system.dart ('k') | lib/src/template/file_system_memory.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/template/file_system_browser.dart
diff --git a/lib/src/template/file_system_browser.dart b/lib/src/template/file_system_browser.dart
new file mode 100644
index 0000000000000000000000000000000000000000..266979ca8001badf7ca222507149932d3ed9c0ab
--- /dev/null
+++ b/lib/src/template/file_system_browser.dart
@@ -0,0 +1,63 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library file_system_browser;
+
+import 'dart:html';
+import 'file_system.dart';
+import 'package:js/js.dart' as js;
+
+
+/**
+ * File system implementation indirectly using the Chrome Extension Api's to
+ * proxy arbitrary urls. See extension/background.js for the code that does
+ * the actual proxying.
+ */
+class BrowserFileSystem implements FileSystem {
+
+ /**
+ * Chrome extension port used to communicate back to the source page that
+ * will consume these proxied urls.
+ */
+ js.Proxy sourcePagePort;
+
+ final _filesToProxy = <String>{};
+
+ BrowserFileSystem(this.sourcePagePort);
+
+ Future flush() {
+ // TODO(jacobr): this should really only return the future when the
+ // urls are fully proxied.
+ js.scoped(() {
+ var requests = [];
+ _filesToProxy.forEach((k,v) {
+ requests.add( js.map({'url': k, 'content': v}));
+ });
+ _filesToProxy.clear();
+ js.context.proxyUrls(sourcePagePort, js.array(requests));
+ });
+
+ return new Future.immediate(null);
+ }
+
+ void writeString(String path, String text) {
+ _filesToProxy[path] = text;
+ }
+
+ Future<String> readAll(String filename) {
+ var completer = new Completer<String>();
+ new HttpRequest.get(filename, onSuccess(HttpRequest request) {
+ completer.complete(request.responseText);
+ });
+ return completer.future;
+ }
+
+ void createDirectory(String path, [bool recursive = false]) {
+ // No need to actually create directories on the web.
+ }
+
+ void removeDirectory(String path, [bool recursive = false]) {
+ throw 'removeDirectory() is not implemented by BrowserFileSystem yet.';
+ }
+}
« no previous file with comments | « lib/src/template/file_system.dart ('k') | lib/src/template/file_system_memory.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698