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

Unified Diff: examples/js/show_image.js

Issue 845103004: Mojo JS Bindings: add show_image example (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 | « examples/js/README.md ('k') | mojo/public/tools/bindings/generators/mojom_js_generator.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/js/show_image.js
diff --git a/examples/js/show_image.js b/examples/js/show_image.js
new file mode 100644
index 0000000000000000000000000000000000000000..e0edf5f76ea4a134a6036555b44fbae075db5f20
--- /dev/null
+++ b/examples/js/show_image.js
@@ -0,0 +1,53 @@
+#!mojo mojo:js_content_handler
+// Demonstrate using the mojo window_manager application to "embed" a view that
+// displays an image. To run this application set BUILD_DIR to the build
+// directory (like "src/out/Debug") and append a PNG image URL as the url
+// paramaeter for: absolute path for this directory, then:
+// sky/tools/skydb start $BUILD_DIR examples/js/show_image.js?url=<PNG URL>
+// The skydb application starts an HTTP server that points at the build and
+// and source directories. It starts a simple - just one view - window manager
+// and then embeds this application in its root view. This application just
+// asks the same window manager to embed the PNG viewer. Doing so effectively
+// removes this application from the window manager's root view.
+
+define("main", [
+ "mojo/services/public/js/application",
+ "mojo/services/public/js/service_provider",
+ "mojo/services/window_manager/public/interfaces/window_manager.mojom",
+], function(application, serviceProvider, windowManager) {
+
+ const Application = application.Application;
+ const ServiceProvider = serviceProvider.ServiceProvider;
+ const WindowManager = windowManager.WindowManager;
+ const defaultImageURL =
+ "http://upload.wikimedia.org/wikipedia/commons/8/87/Google_Chrome_icon_%282011%29.png";
+
+ var windowManager;
+ var windowManagerSP;
+
+ class WindowManagerClientImpl {
+ // An empty stub for now.
+ }
+
+ class ShowImage extends Application {
+ initialize() {
+ var imageURLKey = "?url=";
+ var imageURLIndex = this.url.indexOf(imageURLKey);
+ var imageURL = (imageURLIndex == -1) ? defaultImageURL :
+ this.url.substring(imageURLIndex + imageURLKey.length);
+
+ windowManager = this.shell.connectToService(
+ "mojo:window_manager", WindowManager, new WindowManagerClientImpl);
+ windowManager.embed(imageURL, function(spProxy) {
+ windowManagerSP = new ServiceProvider(spProxy);
+ });
+
+ // Displaying imageURL is now the responsibility of the Mojo application
+ // launched by its content handler. We're done.
+ this.quit();
+ }
+ }
+
+ return ShowImage;
+});
+
« no previous file with comments | « examples/js/README.md ('k') | mojo/public/tools/bindings/generators/mojom_js_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698