Removed a line that dispatches the 'cancelOverlay' event. This line was added by...
[chromium-blink-merge.git] / content / shell / browser / shell_browser_main_parts.cc
blob750d70eef1b37a520dc0345984a1ca1b3052f593
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/shell/browser/shell_browser_main_parts.h"
7 #include "base/base_switches.h"
8 #include "base/bind.h"
9 #include "base/command_line.h"
10 #include "base/files/file_path.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/threading/thread.h"
13 #include "base/threading/thread_restrictions.h"
14 #include "components/devtools_http_handler/devtools_http_handler.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/storage_partition.h"
17 #include "content/public/common/content_switches.h"
18 #include "content/public/common/main_function_params.h"
19 #include "content/public/common/url_constants.h"
20 #include "content/shell/browser/layout_test/layout_test_browser_context.h"
21 #include "content/shell/browser/shell.h"
22 #include "content/shell/browser/shell_browser_context.h"
23 #include "content/shell/browser/shell_devtools_manager_delegate.h"
24 #include "content/shell/browser/shell_net_log.h"
25 #include "content/shell/common/shell_switches.h"
26 #include "net/base/filename_util.h"
27 #include "net/base/net_module.h"
28 #include "net/grit/net_resources.h"
29 #include "ui/base/resource/resource_bundle.h"
30 #include "url/gurl.h"
32 #if defined(OS_ANDROID)
33 #include "components/crash/browser/crash_dump_manager_android.h"
34 #include "net/android/network_change_notifier_factory_android.h"
35 #include "net/base/network_change_notifier.h"
36 #endif
38 #if defined(USE_AURA) && defined(USE_X11)
39 #include "ui/events/devices/x11/touch_factory_x11.h"
40 #endif
41 #if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(OS_LINUX)
42 #include "ui/base/ime/input_method_initializer.h"
43 #endif
45 namespace content {
47 namespace {
49 GURL GetStartupURL() {
50 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
51 if (command_line->HasSwitch(switches::kContentBrowserTest))
52 return GURL();
53 const base::CommandLine::StringVector& args = command_line->GetArgs();
55 #if defined(OS_ANDROID)
56 // Delay renderer creation on Android until surface is ready.
57 return GURL();
58 #endif
60 if (args.empty())
61 return GURL("https://www.google.com/");
63 GURL url(args[0]);
64 if (url.is_valid() && url.has_scheme())
65 return url;
67 return net::FilePathToFileURL(base::FilePath(args[0]));
70 base::StringPiece PlatformResourceProvider(int key) {
71 if (key == IDR_DIR_HEADER_HTML) {
72 base::StringPiece html_data =
73 ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
74 IDR_DIR_HEADER_HTML);
75 return html_data;
77 return base::StringPiece();
80 } // namespace
82 ShellBrowserMainParts::ShellBrowserMainParts(
83 const MainFunctionParams& parameters)
84 : parameters_(parameters),
85 run_message_loop_(true),
86 devtools_http_handler_(nullptr) {
89 ShellBrowserMainParts::~ShellBrowserMainParts() {
90 DCHECK(!devtools_http_handler_);
93 #if !defined(OS_MACOSX)
94 void ShellBrowserMainParts::PreMainMessageLoopStart() {
95 #if defined(USE_AURA) && defined(USE_X11)
96 ui::TouchFactory::SetTouchDeviceListFromCommandLine();
97 #endif
99 #endif
101 void ShellBrowserMainParts::PostMainMessageLoopStart() {
102 #if defined(OS_ANDROID)
103 base::MessageLoopForUI::current()->Start();
104 #endif
107 void ShellBrowserMainParts::PreEarlyInitialization() {
108 #if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(OS_LINUX)
109 ui::InitializeInputMethodForTesting();
110 #endif
111 #if defined(OS_ANDROID)
112 net::NetworkChangeNotifier::SetFactory(
113 new net::NetworkChangeNotifierFactoryAndroid());
114 #endif
117 void ShellBrowserMainParts::InitializeBrowserContexts() {
118 set_browser_context(new ShellBrowserContext(false, net_log_.get()));
119 set_off_the_record_browser_context(
120 new ShellBrowserContext(true, net_log_.get()));
123 void ShellBrowserMainParts::InitializeMessageLoopContext() {
124 Shell::CreateNewWindow(browser_context_.get(),
125 GetStartupURL(),
126 NULL,
127 gfx::Size());
130 void ShellBrowserMainParts::PreMainMessageLoopRun() {
131 #if defined(OS_ANDROID)
132 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
133 switches::kEnableCrashReporter)) {
134 base::FilePath crash_dumps_dir =
135 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
136 switches::kCrashDumpsDir);
137 crash_dump_manager_.reset(new breakpad::CrashDumpManager(crash_dumps_dir));
139 #endif
141 net_log_.reset(new ShellNetLog("content_shell"));
142 InitializeBrowserContexts();
143 Shell::Initialize();
144 net::NetModule::SetResourceProvider(PlatformResourceProvider);
146 devtools_http_handler_.reset(
147 ShellDevToolsManagerDelegate::CreateHttpHandler(browser_context_.get()));
149 InitializeMessageLoopContext();
151 if (parameters_.ui_task) {
152 parameters_.ui_task->Run();
153 delete parameters_.ui_task;
154 run_message_loop_ = false;
158 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) {
159 return !run_message_loop_;
162 void ShellBrowserMainParts::PostMainMessageLoopRun() {
163 devtools_http_handler_.reset();
164 browser_context_.reset();
165 off_the_record_browser_context_.reset();
168 } // namespace