| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 """Produces configured shell abstractions. | 5 """Produces configured shell abstractions. |
| 6 | 6 |
| 7 This module knows how to produce a configured shell abstraction based on | 7 This module knows how to produce a configured shell abstraction based on |
| 8 shell_config.ShellConfig. | 8 shell_config.ShellConfig. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 if map_origins: | 95 if map_origins: |
| 96 for map_origin in sorted(map_origins): | 96 for map_origin in sorted(map_origins): |
| 97 mapping = _rewrite(map_origin, _host_local_origin_destination, shell, | 97 mapping = _rewrite(map_origin, _host_local_origin_destination, shell, |
| 98 next_port) | 98 next_port) |
| 99 next_port += 1 | 99 next_port += 1 |
| 100 # Origin mappings are specified as separate, repeated shell arguments. | 100 # Origin mappings are specified as separate, repeated shell arguments. |
| 101 args.append('--map-origin=' + mapping) | 101 args.append('--map-origin=' + mapping) |
| 102 return args | 102 return args |
| 103 | 103 |
| 104 | 104 |
| 105 def _configure_sky(shell_args): | |
| 106 """Maps mojo:sky_viewer as a content handler for dart applications. | |
| 107 app. | |
| 108 | |
| 109 Args: | |
| 110 shell_args: Current list of shell arguments. | |
| 111 | |
| 112 Returns: | |
| 113 Updated list of shell arguments. | |
| 114 """ | |
| 115 # Configure the content type mappings for the sky_viewer. This is needed | |
| 116 # only for the Sky apps that do not declare mojo:sky_viewer in a shebang. | |
| 117 # TODO(ppi): drop this part once we can rely on the Sky files declaring | |
| 118 # correct shebang. | |
| 119 shell_args = append_to_argument(shell_args, '--content-handlers=', | |
| 120 'text/sky,mojo:sky_viewer') | |
| 121 shell_args = append_to_argument(shell_args, '--content-handlers=', | |
| 122 'application/dart,mojo:sky_viewer') | |
| 123 return shell_args | |
| 124 | |
| 125 | |
| 126 def configure_local_origin(shell, local_dir, fixed_port=True): | 105 def configure_local_origin(shell, local_dir, fixed_port=True): |
| 127 """Sets up a local http server to serve files in |local_dir| along with | 106 """Sets up a local http server to serve files in |local_dir| along with |
| 128 device port forwarding if needed. | 107 device port forwarding if needed. |
| 129 | 108 |
| 130 Returns: | 109 Returns: |
| 131 The list of arguments to be appended to the shell argument list. | 110 The list of arguments to be appended to the shell argument list. |
| 132 """ | 111 """ |
| 133 | 112 |
| 134 origin_url = shell.serve_local_directory( | 113 origin_url = shell.serve_local_directory( |
| 135 local_dir, _LOCAL_ORIGIN_PORT if fixed_port else 0) | 114 local_dir, _LOCAL_ORIGIN_PORT if fixed_port else 0) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 shell_args = _apply_mappings(shell, shell_args, shell_config.map_url_list, | 206 shell_args = _apply_mappings(shell, shell_args, shell_config.map_url_list, |
| 228 shell_config.map_origin_list) | 207 shell_config.map_origin_list) |
| 229 | 208 |
| 230 if shell_config.origin: | 209 if shell_config.origin: |
| 231 if _is_web_url(shell_config.origin): | 210 if _is_web_url(shell_config.origin): |
| 232 shell_args.append('--origin=' + shell_config.origin) | 211 shell_args.append('--origin=' + shell_config.origin) |
| 233 else: | 212 else: |
| 234 shell_args.extend(configure_local_origin(shell, shell_config.origin, | 213 shell_args.extend(configure_local_origin(shell, shell_config.origin, |
| 235 fixed_port=True)) | 214 fixed_port=True)) |
| 236 | 215 |
| 237 if shell_config.sky: | 216 if shell_config.content_handlers: |
| 238 shell_args = _configure_sky(shell_args) | 217 for (mime_type, |
| 218 content_handler_url) in shell_config.content_handlers.iteritems(): |
| 219 shell_args = append_to_argument(shell_args, '--content-handlers=', |
| 220 '%s,%s' % (mime_type, |
| 221 content_handler_url)) |
| 239 | 222 |
| 240 for dev_server_config in shell_config.dev_servers: | 223 for dev_server_config in shell_config.dev_servers: |
| 241 shell_args = _configure_dev_server(shell, shell_args, dev_server_config) | 224 shell_args = _configure_dev_server(shell, shell_args, dev_server_config) |
| 242 | 225 |
| 243 return shell, shell_args | 226 return shell, shell_args |
| OLD | NEW |