Eric Seidel 1ff137055e Move wm_flow off of views and onto Sky
This is a proof of concept for replacing ui/views
code with Sky instead. erg says this will allow him
to delete 10s of thousands of LOC from mojo.

Mojo does not yet expose the current binary's URL:
https://docs.google.com/a/chromium.org/document/d/1AQ2y6ekzvbdaMF5WrUQmneyXJnke-MnYYL4Gz1AKDos
So I've worked around that by passing the url
of the binary via the helper script.

I discovered several bugs in the wm_flow code
including that it doesn't handle view resizes
(during embiggen).  Related, I discovered that
every time a new window is made it drops the
connections to the embedded.cc app from the
previous window, since the ViewManagerDelegate
is incorrectly implemented as part of the
ApplicationDelegate on both app.cc and embedded.cc.
We'd need to split out a separate per-view object
in both of those apps to handle the
ViewManagerDelegate calls.

There are some changes to logging during loading
as well as the CopyToFile helper to have better
error reporting.  I hit several issues early on trying
to get mojo to load the http: urls correctly, including
eventually running out of disk space on my /tmp
and mojo then silently failing to launch the app
(due to mojo never clearing its caches crbug.com/446302).

I had to re-write the mojo_demo.sh script in python
as well as split the sky_server handling code out of
skydb into a separate python module in order to cleanly
launch sky_server.  We could use a separate server
if we wanted to but the primary benefit of sky_server
is that it sets up the proper url->disk mappings into
the generated file directories, etc.

BUG=443439
R=abarth@chromium.org

Review URL: https://codereview.chromium.org/817573003
2015-01-06 14:40:41 -08:00

96 lines
3.0 KiB
Python
Executable File

#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from skypy.paths import Paths
from skypy.skyserver import SkyServer
import argparse
import logging
import os
import skypy.configuration as configuration
import subprocess
import urlparse
SUPPORTED_MIME_TYPES = [
'text/html',
'text/sky',
'text/plain',
]
HTTP_PORT = 9999
class SkyDebugger(object):
def __init__(self):
self.paths = None
def _server_root_and_url_from_path_arg(self, url_or_path):
# This is already a valid url we don't need a local server.
if urlparse.urlparse(url_or_path).scheme:
return None, url_or_path
path = os.path.abspath(url_or_path)
if os.path.commonprefix([path, self.paths.src_root]) == self.paths.src_root:
server_root = self.paths.src_root
else:
server_root = os.path.dirname(path)
logging.warn(
'%s is outside of mojo root, using %s as server root' %
(path, server_root))
local_url = SkyServer.url_for_path(HTTP_PORT, server_root, path)
return server_root, local_url
def _in_chromoting(self):
return os.environ.get('CHROME_REMOTE_DESKTOP_SESSION', False)
def main(self):
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser(description='Sky launcher/debugger')
parser.add_argument('--gdb', action='store_true')
parser.add_argument('--use-osmesa', action='store_true',
default=self._in_chromoting())
parser.add_argument('url_or_path', nargs='?', type=str)
configuration.add_arguments(parser)
args = parser.parse_args()
self.paths = Paths(os.path.join('out', args.configuration))
content_handlers = ['%s,%s' % (mime_type, 'mojo:sky_viewer')
for mime_type in SUPPORTED_MIME_TYPES]
shell_command = [
self.paths.mojo_shell_path,
'--v=1',
'--content-handlers=%s' % ','.join(content_handlers),
'--url-mappings=mojo:window_manager=mojo:sky_debugger',
'mojo:window_manager',
]
if args.use_osmesa:
shell_command.append('--args-for=mojo:native_viewport_service --use-osmesa')
server_root = None
if args.url_or_path:
# Check if we need a local server for the url/path arg:
server_root, url = \
self._server_root_and_url_from_path_arg(args.url_or_path)
prompt_args = '--args-for=mojo:sky_debugger_prompt %s' % url
shell_command.append(prompt_args)
if args.gdb:
shell_command = ['gdb', '--args'] + shell_command
if server_root:
with SkyServer(self.paths, HTTP_PORT, args.configuration,
server_root):
subprocess.check_call(shell_command)
else:
subprocess.check_call(shell_command)
if __name__ == '__main__':
SkyDebugger().main()