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

Side by Side Diff: examples/js/show_image.js

Issue 848513004: Mojo JS Bindings: URL class (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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/js/README.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!mojo mojo:js_content_handler 1 #!mojo mojo:js_content_handler
2 // Demonstrate using the mojo window_manager application to "embed" a view that 2 // Demonstrate using the mojo window_manager application to "embed" a view that
3 // displays an image. To run this application set BUILD_DIR to the build 3 // displays an image. To run this application set BUILD_DIR to the build
4 // directory (like "src/out/Debug") and append a PNG image URL as the url 4 // directory (like "src/out/Debug") and append a PNG image URL as the url
5 // paramaeter for: absolute path for this directory, then: 5 // paramaeter for: absolute path for this directory, then:
6 // sky/tools/skydb start $BUILD_DIR examples/js/show_image.js?url=<PNG URL> 6 // sky/tools/skydb start $BUILD_DIR examples/js/show_image.js?url=<PNG URL>
7 // The skydb application starts an HTTP server that points at the build and 7 // The skydb application starts an HTTP server that points at the build and
8 // and source directories. It starts a simple - just one view - window manager 8 // and source directories. It starts a simple - just one view - window manager
9 // and then embeds this application in its root view. This application just 9 // and then embeds this application in its root view. This application just
10 // asks the same window manager to embed the PNG viewer. Doing so effectively 10 // asks the same window manager to embed the PNG viewer. Doing so effectively
11 // removes this application from the window manager's root view. 11 // removes this application from the window manager's root view.
12 12
13 define("main", [ 13 define("main", [
14 "mojo/services/public/js/application", 14 "mojo/services/public/js/application",
15 "mojo/services/public/js/service_provider", 15 "mojo/services/public/js/service_provider",
16 "mojo/services/window_manager/public/interfaces/window_manager.mojom", 16 "mojo/services/window_manager/public/interfaces/window_manager.mojom",
17 ], function(application, serviceProvider, windowManager) { 17 "third_party/js/url",
18 ], function(application, serviceProvider, windowManager, url) {
18 19
19 const Application = application.Application; 20 const Application = application.Application;
20 const ServiceProvider = serviceProvider.ServiceProvider; 21 const ServiceProvider = serviceProvider.ServiceProvider;
21 const WindowManager = windowManager.WindowManager; 22 const WindowManager = windowManager.WindowManager;
23 const URL = url.URL;
22 const defaultImageURL = 24 const defaultImageURL =
23 "http://upload.wikimedia.org/wikipedia/commons/8/87/Google_Chrome_icon_%28 2011%29.png"; 25 "http://upload.wikimedia.org/wikipedia/commons/8/87/Google_Chrome_icon_%28 2011%29.png";
24 26
25 var windowManager;
26 var windowManagerSP;
27
28 class WindowManagerClientImpl {
29 // An empty stub for now.
30 }
31
32 class ShowImage extends Application { 27 class ShowImage extends Application {
33 initialize() { 28 initialize() {
34 var imageURLKey = "?url="; 29 var imageURL = new URL(this.url, true).query.url || defaultImageURL;
35 var imageURLIndex = this.url.indexOf(imageURLKey); 30 var windowManager = this.shell.connectToService(
36 var imageURL = (imageURLIndex == -1) ? defaultImageURL : 31 "mojo:window_manager", WindowManager, {} /* empty WindowManagerClient */ );
37 this.url.substring(imageURLIndex + imageURLKey.length); 32 windowManager.embed(imageURL, function() { /* no ServiceProvider */ });
38
39 windowManager = this.shell.connectToService(
40 "mojo:window_manager", WindowManager, new WindowManagerClientImpl);
41 windowManager.embed(imageURL, function(spProxy) {
42 windowManagerSP = new ServiceProvider(spProxy);
43 });
44 33
45 // Displaying imageURL is now the responsibility of the Mojo application 34 // Displaying imageURL is now the responsibility of the Mojo application
46 // launched by its content handler. We're done. 35 // launched by its content handler. We're done.
47 this.quit(); 36 this.quit();
48 } 37 }
49 } 38 }
50 39
51 return ShowImage; 40 return ShowImage;
52 }); 41 });
53 42
OLDNEW
« no previous file with comments | « no previous file | third_party/js/README.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698