Guest User

Untitled

a guest
Jan 10th, 2017
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.92 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. # Simple Chromium launcher with support for Pepper Flash
  4. #
  5. # Some rudimentary support for user flags is provided via a chromium-flags.conf
  6. # config file placed in $HOME/.config/ (or $XDG_CONFIG_HOME). Arguments are
  7. # split on whitespace and shell quoting rules apply but no further parsing is
  8. # performed. In case of improper quoting anywhere in the file, a fatal error is
  9. # raised. Lines starting with a hash symbol (#) are skipped.
  10.  
  11. use strict;
  12. use warnings;
  13.  
  14. use Cwd qw( abs_path );
  15. use JSON::PP qw( decode_json );
  16. use File::BaseDir qw( config_home );
  17. use Text::ParseWords qw ( shellwords );
  18.  
  19. my %PEPPER_FLASH = (
  20.     manifest => '/usr/lib/PepperFlash/manifest.json',
  21.     plugin => '/usr/lib/PepperFlash/libpepflashplayer.so',
  22. );
  23.  
  24. sub get_flash_version {
  25.     open my $manifest, '<', $PEPPER_FLASH{manifest} or return;
  26.  
  27.     my $json;
  28.  
  29.     eval {
  30.         $json = decode_json do { local $/; <$manifest> };
  31.     };
  32.  
  33.     return $json->{version} if $json;
  34. }
  35.  
  36. sub get_flash_flags {
  37.     my $flash_version = get_flash_version() // '';
  38.     my @flash_flags;
  39.  
  40.     if ($flash_version =~ /^[\d.]+$/ and -f $PEPPER_FLASH{plugin}) {
  41.         @flash_flags = (
  42.             "--ppapi-flash-path=$PEPPER_FLASH{plugin}",
  43.             "--ppapi-flash-version=$flash_version");
  44.     }
  45.  
  46.     return @flash_flags;
  47. }
  48.  
  49. sub get_user_flags {
  50.     my $conf_path = config_home 'chromium-flags.conf';
  51.     open my $conf, '<', $conf_path or return;
  52.  
  53.     my @lines = grep {!/^(\s*#|\s*$)/} map { chomp; $_ } <$conf>;
  54.     return if not @lines;
  55.  
  56.     my @user_flags = shellwords @lines;
  57.  
  58.     unless (@user_flags) {
  59.         system '/usr/lib/chromium-launcher/launcher-errmsg',
  60.             'Unable to parse user flags',
  61.             "Please check $conf_path for errors (e.g. mismatched quotes).\n\n" .
  62.             "The launcher will now exit.";
  63.         exit 1;
  64.     }
  65.  
  66.     return @user_flags;
  67. }
  68.  
  69. $ENV{CHROME_WRAPPER} = abs_path($0);
  70. $ENV{CHROME_DESKTOP} = 'chromium.desktop';
  71.  
  72. exec '/usr/lib/chromium/chromium', get_flash_flags, get_user_flags, @ARGV;
Add Comment
Please, Sign In to add comment