File: default_shell_browser_main_delegate.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (115 lines) | stat: -rw-r--r-- 3,814 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/shell/browser/default_shell_browser_main_delegate.h"

#include "apps/launcher.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/strings/string_tokenizer.h"
#include "build/build_config.h"
#include "extensions/common/switches.h"
#include "extensions/shell/browser/shell_extension_system.h"

#if defined(USE_AURA)
#include "extensions/shell/browser/shell_desktop_controller_aura.h"
#endif

#if BUILDFLAG(IS_MAC)
#include "extensions/shell/browser/shell_desktop_controller_mac.h"
#endif

namespace extensions {

namespace {

void LoadExtensionsFromCommandLine(ShellExtensionSystem* extension_system) {
  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
  if (!command_line->HasSwitch(switches::kLoadExtension))
    return;

  base::CommandLine::StringType path_list =
      command_line->GetSwitchValueNative(switches::kLoadExtension);

  base::StringTokenizerT<base::CommandLine::StringType,
                         base::CommandLine::StringType::const_iterator>
      tokenizer(path_list, FILE_PATH_LITERAL(","));
  while (tokenizer.GetNext()) {
    extension_system->LoadExtension(
        base::MakeAbsoluteFilePath(base::FilePath(tokenizer.token_piece())));
  }
}

void LoadAppsFromCommandLine(ShellExtensionSystem* extension_system,
                             content::BrowserContext* browser_context) {
  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
  if (!command_line->HasSwitch(switches::kLoadApps)) {
    LOG(ERROR) << "No app specified. Use --" << switches::kLoadApps
               << " to load and launch an app.";
    return;
  }

  base::CommandLine::StringType path_list =
      command_line->GetSwitchValueNative(switches::kLoadApps);

  base::StringTokenizerT<base::CommandLine::StringType,
                         base::CommandLine::StringType::const_iterator>
      tokenizer(path_list, FILE_PATH_LITERAL(","));

  const Extension* launch_app = nullptr;
  while (tokenizer.GetNext()) {
    base::FilePath app_absolute_dir =
        base::MakeAbsoluteFilePath(base::FilePath(tokenizer.token_piece()));

    const Extension* extension = extension_system->LoadApp(app_absolute_dir);
    if (extension && !launch_app)
      launch_app = extension;
  }

  if (launch_app) {
    base::FilePath current_directory;
    base::PathService::Get(base::DIR_CURRENT, &current_directory);
    apps::LaunchPlatformAppWithCommandLine(browser_context, launch_app,
                                           *command_line, current_directory,
                                           AppLaunchSource::kSourceCommandLine);
  } else {
    LOG(ERROR) << "Could not load any apps.";
  }
}

}  // namespace

DefaultShellBrowserMainDelegate::DefaultShellBrowserMainDelegate() {
}

DefaultShellBrowserMainDelegate::~DefaultShellBrowserMainDelegate() {
}

void DefaultShellBrowserMainDelegate::Start(
    content::BrowserContext* browser_context) {
  ShellExtensionSystem* extension_system =
      static_cast<ShellExtensionSystem*>(ExtensionSystem::Get(browser_context));
  extension_system->FinishInitialization();

  LoadExtensionsFromCommandLine(extension_system);
  LoadAppsFromCommandLine(extension_system, browser_context);
}

void DefaultShellBrowserMainDelegate::Shutdown() {
}

DesktopController* DefaultShellBrowserMainDelegate::CreateDesktopController(
    content::BrowserContext* context) {
#if defined(USE_AURA)
  return new ShellDesktopControllerAura(context);
#elif BUILDFLAG(IS_MAC)
  return new ShellDesktopControllerMac();
#else
  return NULL;
#endif
}

}  // namespace extensions