| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/shell/browser/shell_browser_main_parts.h" | 5 #include "content/shell/browser/shell_browser_main_parts.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/storage_partition.h" | 15 #include "content/public/browser/storage_partition.h" |
| 16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 17 #include "content/public/common/main_function_params.h" | 17 #include "content/public/common/main_function_params.h" |
| 18 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
| 19 #include "content/shell/browser/layout_test/layout_test_browser_context.h" | 19 #include "content/shell/browser/layout_test/layout_test_browser_context.h" |
| 20 #include "content/shell/browser/shell.h" | 20 #include "content/shell/browser/shell.h" |
| 21 #include "content/shell/browser/shell_browser_context.h" | 21 #include "content/shell/browser/shell_browser_context.h" |
| 22 #include "content/shell/browser/shell_devtools_delegate.h" | 22 #include "content/shell/browser/shell_devtools_delegate.h" |
| 23 #include "content/shell/browser/shell_net_log.h" | 23 #include "content/shell/browser/shell_net_log.h" |
| 24 #include "content/shell/common/shell_switches.h" | 24 #include "content/shell/common/shell_switches.h" |
| 25 #include "net/base/filename_util.h" | 25 #include "net/base/filename_util.h" |
| 26 #include "net/base/net_module.h" | 26 #include "net/base/net_module.h" |
| 27 #include "net/grit/net_resources.h" | 27 #include "net/grit/net_resources.h" |
| 28 #include "storage/browser/quota/quota_manager.h" | |
| 29 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 31 | 30 |
| 32 #if defined(ENABLE_PLUGINS) | |
| 33 #include "content/public/browser/plugin_service.h" | |
| 34 #include "content/shell/browser/shell_plugin_service_filter.h" | |
| 35 #endif | |
| 36 | |
| 37 #if defined(OS_ANDROID) | 31 #if defined(OS_ANDROID) |
| 38 #include "components/crash/browser/crash_dump_manager_android.h" | 32 #include "components/crash/browser/crash_dump_manager_android.h" |
| 39 #include "net/android/network_change_notifier_factory_android.h" | 33 #include "net/android/network_change_notifier_factory_android.h" |
| 40 #include "net/base/network_change_notifier.h" | 34 #include "net/base/network_change_notifier.h" |
| 41 #endif | 35 #endif |
| 42 | 36 |
| 43 #if defined(USE_AURA) && defined(USE_X11) | 37 #if defined(USE_AURA) && defined(USE_X11) |
| 44 #include "ui/events/x/touch_factory_x11.h" | 38 #include "ui/events/x/touch_factory_x11.h" |
| 45 #endif | 39 #endif |
| 46 #if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(OS_LINUX) | 40 #if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(OS_LINUX) |
| 47 #include "ui/base/ime/input_method_initializer.h" | 41 #include "ui/base/ime/input_method_initializer.h" |
| 48 #endif | 42 #endif |
| 49 | 43 |
| 50 namespace content { | 44 namespace content { |
| 51 | 45 |
| 52 namespace { | 46 namespace { |
| 53 | 47 |
| 54 // Default quota for each origin is 5MB. | |
| 55 const int kDefaultLayoutTestQuotaBytes = 5 * 1024 * 1024; | |
| 56 | |
| 57 GURL GetStartupURL() { | 48 GURL GetStartupURL() { |
| 58 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 49 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 59 if (command_line->HasSwitch(switches::kContentBrowserTest)) | 50 if (command_line->HasSwitch(switches::kContentBrowserTest)) |
| 60 return GURL(); | 51 return GURL(); |
| 61 const CommandLine::StringVector& args = command_line->GetArgs(); | 52 const CommandLine::StringVector& args = command_line->GetArgs(); |
| 62 | 53 |
| 63 #if defined(OS_ANDROID) | 54 #if defined(OS_ANDROID) |
| 64 // Delay renderer creation on Android until surface is ready. | 55 // Delay renderer creation on Android until surface is ready. |
| 65 return GURL(); | 56 return GURL(); |
| 66 #endif | 57 #endif |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 void ShellBrowserMainParts::PreEarlyInitialization() { | 102 void ShellBrowserMainParts::PreEarlyInitialization() { |
| 112 #if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(OS_LINUX) | 103 #if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(OS_LINUX) |
| 113 ui::InitializeInputMethodForTesting(); | 104 ui::InitializeInputMethodForTesting(); |
| 114 #endif | 105 #endif |
| 115 #if defined(OS_ANDROID) | 106 #if defined(OS_ANDROID) |
| 116 net::NetworkChangeNotifier::SetFactory( | 107 net::NetworkChangeNotifier::SetFactory( |
| 117 new net::NetworkChangeNotifierFactoryAndroid()); | 108 new net::NetworkChangeNotifierFactoryAndroid()); |
| 118 #endif | 109 #endif |
| 119 } | 110 } |
| 120 | 111 |
| 112 void ShellBrowserMainParts::InitializeBrowserContexts() { |
| 113 browser_context_.reset(new ShellBrowserContext(false, net_log_.get())); |
| 114 off_the_record_browser_context_.reset( |
| 115 new ShellBrowserContext(true, net_log_.get())); |
| 116 } |
| 117 |
| 118 void ShellBrowserMainParts::InitializeMessageLoopContext() { |
| 119 Shell::CreateNewWindow(browser_context_.get(), |
| 120 GetStartupURL(), |
| 121 NULL, |
| 122 MSG_ROUTING_NONE, |
| 123 gfx::Size()); |
| 124 } |
| 125 |
| 121 void ShellBrowserMainParts::PreMainMessageLoopRun() { | 126 void ShellBrowserMainParts::PreMainMessageLoopRun() { |
| 122 #if defined(OS_ANDROID) | 127 #if defined(OS_ANDROID) |
| 123 if (CommandLine::ForCurrentProcess()->HasSwitch( | 128 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 124 switches::kEnableCrashReporter)) { | 129 switches::kEnableCrashReporter)) { |
| 125 base::FilePath crash_dumps_dir = | 130 base::FilePath crash_dumps_dir = |
| 126 CommandLine::ForCurrentProcess()->GetSwitchValuePath( | 131 CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
| 127 switches::kCrashDumpsDir); | 132 switches::kCrashDumpsDir); |
| 128 crash_dump_manager_.reset(new breakpad::CrashDumpManager(crash_dumps_dir)); | 133 crash_dump_manager_.reset(new breakpad::CrashDumpManager(crash_dumps_dir)); |
| 129 } | 134 } |
| 130 #endif | 135 #endif |
| 136 |
| 131 net_log_.reset(new ShellNetLog("content_shell")); | 137 net_log_.reset(new ShellNetLog("content_shell")); |
| 132 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { | 138 InitializeBrowserContexts(); |
| 133 browser_context_.reset(new LayoutTestBrowserContext(false, net_log_.get())); | |
| 134 off_the_record_browser_context_.reset( | |
| 135 new LayoutTestBrowserContext(true, net_log_.get())); | |
| 136 } else { | |
| 137 browser_context_.reset(new ShellBrowserContext(false, net_log_.get())); | |
| 138 off_the_record_browser_context_.reset( | |
| 139 new ShellBrowserContext(true, net_log_.get())); | |
| 140 } | |
| 141 | |
| 142 Shell::Initialize(); | 139 Shell::Initialize(); |
| 143 net::NetModule::SetResourceProvider(PlatformResourceProvider); | 140 net::NetModule::SetResourceProvider(PlatformResourceProvider); |
| 144 | 141 |
| 145 devtools_delegate_.reset(new ShellDevToolsDelegate(browser_context_.get())); | 142 devtools_delegate_.reset(new ShellDevToolsDelegate(browser_context_.get())); |
| 146 | 143 |
| 147 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { | 144 InitializeMessageLoopContext(); |
| 148 Shell::CreateNewWindow(browser_context_.get(), | |
| 149 GetStartupURL(), | |
| 150 NULL, | |
| 151 MSG_ROUTING_NONE, | |
| 152 gfx::Size()); | |
| 153 } | |
| 154 | |
| 155 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { | |
| 156 storage::QuotaManager* quota_manager = | |
| 157 BrowserContext::GetDefaultStoragePartition(browser_context()) | |
| 158 ->GetQuotaManager(); | |
| 159 BrowserThread::PostTask( | |
| 160 BrowserThread::IO, | |
| 161 FROM_HERE, | |
| 162 base::Bind(&storage::QuotaManager::SetTemporaryGlobalOverrideQuota, | |
| 163 quota_manager, | |
| 164 kDefaultLayoutTestQuotaBytes * | |
| 165 storage::QuotaManager::kPerHostTemporaryPortion, | |
| 166 storage::QuotaCallback())); | |
| 167 #if defined(ENABLE_PLUGINS) | |
| 168 PluginService* plugin_service = PluginService::GetInstance(); | |
| 169 plugin_service_filter_.reset(new ShellPluginServiceFilter); | |
| 170 plugin_service->SetFilter(plugin_service_filter_.get()); | |
| 171 #endif | |
| 172 } | |
| 173 | 145 |
| 174 if (parameters_.ui_task) { | 146 if (parameters_.ui_task) { |
| 175 parameters_.ui_task->Run(); | 147 parameters_.ui_task->Run(); |
| 176 delete parameters_.ui_task; | 148 delete parameters_.ui_task; |
| 177 run_message_loop_ = false; | 149 run_message_loop_ = false; |
| 178 } | 150 } |
| 179 } | 151 } |
| 180 | 152 |
| 181 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { | 153 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { |
| 182 return !run_message_loop_; | 154 return !run_message_loop_; |
| 183 } | 155 } |
| 184 | 156 |
| 185 void ShellBrowserMainParts::PostMainMessageLoopRun() { | 157 void ShellBrowserMainParts::PostMainMessageLoopRun() { |
| 186 if (devtools_delegate_) | 158 if (devtools_delegate_) |
| 187 devtools_delegate_->Stop(); | 159 devtools_delegate_->Stop(); |
| 188 browser_context_.reset(); | 160 browser_context_.reset(); |
| 189 off_the_record_browser_context_.reset(); | 161 off_the_record_browser_context_.reset(); |
| 190 } | 162 } |
| 191 | 163 |
| 192 } // namespace | 164 } // namespace |
| OLD | NEW |