Loosen up heuristics for detecting account creation forms.
[chromium-blink-merge.git] / content / shell / shell_main_delegate.cc
blob35a9350be74dec5d359d8529ac6e7f3cf34107fa
1 // Copyright (c) 2012 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/shell_main_delegate.h"
7 #include "base/command_line.h"
8 #include "base/file_path.h"
9 #include "base/logging.h"
10 #include "base/path_service.h"
11 #include "content/public/browser/browser_main_runner.h"
12 #include "content/public/common/content_switches.h"
13 #include "content/public/common/url_constants.h"
14 #include "content/shell/shell_browser_main.h"
15 #include "content/shell/shell_content_browser_client.h"
16 #include "content/shell/shell_content_renderer_client.h"
17 #include "content/shell/shell_switches.h"
18 #include "net/cookies/cookie_monster.h"
19 #include "net/http/http_stream_factory.h"
20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/base/ui_base_paths.h"
23 #if defined(OS_ANDROID)
24 #include "base/global_descriptors_posix.h"
25 #include "content/shell/android/shell_descriptors.h"
26 #endif
28 #if defined(OS_MACOSX)
29 #include "content/shell/paths_mac.h"
30 #endif // OS_MACOSX
32 #if defined(OS_WIN)
33 #include "base/logging_win.h"
34 #include <initguid.h>
35 #endif
37 namespace {
39 #if defined(OS_WIN)
40 // If "Content Shell" doesn't show up in your list of trace providers in
41 // Sawbuck, add these registry entries to your machine (NOTE the optional
42 // Wow6432Node key for x64 machines):
43 // 1. Find: HKLM\SOFTWARE\[Wow6432Node\]Google\Sawbuck\Providers
44 // 2. Add a subkey with the name "{6A3E50A4-7E15-4099-8413-EC94D8C2A4B6}"
45 // 3. Add these values:
46 // "default_flags"=dword:00000001
47 // "default_level"=dword:00000004
48 // @="Content Shell"
50 // {6A3E50A4-7E15-4099-8413-EC94D8C2A4B6}
51 const GUID kContentShellProviderName = {
52 0x6a3e50a4, 0x7e15, 0x4099,
53 { 0x84, 0x13, 0xec, 0x94, 0xd8, 0xc2, 0xa4, 0xb6 } };
54 #endif
56 void InitLogging() {
57 FilePath log_filename;
58 PathService::Get(base::DIR_EXE, &log_filename);
59 log_filename = log_filename.AppendASCII("content_shell.log");
60 logging::InitLogging(
61 log_filename.value().c_str(),
62 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
63 logging::LOCK_LOG_FILE,
64 logging::DELETE_OLD_LOG_FILE,
65 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
66 logging::SetLogItems(true, true, true, true);
69 } // namespace
71 namespace content {
73 ShellMainDelegate::ShellMainDelegate() {
76 ShellMainDelegate::~ShellMainDelegate() {
77 #if defined(OS_ANDROID)
78 NOTREACHED();
79 #endif
82 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) {
83 #if defined(OS_WIN)
84 // Enable trace control and transport through event tracing for Windows.
85 logging::LogEventProvider::Initialize(kContentShellProviderName);
86 #endif
88 InitLogging();
89 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
90 CommandLine::ForCurrentProcess()->AppendSwitch(
91 switches::kAllowFileAccessFromFiles);
92 CommandLine::ForCurrentProcess()->AppendSwitch(
93 switches::kForceCompositingMode);
94 //net::HttpStreamFactory::set_ignore_certificate_errors(true);
95 net::CookieMonster::EnableFileScheme();
97 SetContentClient(&content_client_);
98 return false;
101 void ShellMainDelegate::PreSandboxStartup() {
102 #if defined(OS_MACOSX)
103 OverrideFrameworkBundlePath();
104 OverrideChildProcessPath();
105 #endif // OS_MACOSX
106 InitializeResourceBundle();
109 int ShellMainDelegate::RunProcess(
110 const std::string& process_type,
111 const MainFunctionParams& main_function_params) {
112 if (!process_type.empty())
113 return -1;
115 #if !defined(OS_ANDROID)
116 return ShellBrowserMain(main_function_params);
117 #else
118 // If no process type is specified, we are creating the main browser process.
119 browser_runner_.reset(BrowserMainRunner::Create());
120 int exit_code = browser_runner_->Initialize(main_function_params);
121 DCHECK(exit_code < 0)
122 << "BrowserRunner::Initialize failed in ShellMainDelegate";
124 return exit_code;
125 #endif
128 void ShellMainDelegate::InitializeResourceBundle() {
129 #if defined(OS_ANDROID)
130 // In the Android case, the renderer runs with a different UID and can never
131 // access the file system. So we are passed a file descriptor to the
132 // ResourceBundle pak at launch time.
133 int pak_fd =
134 base::GlobalDescriptors::GetInstance()->MaybeGet(kShellPakDescriptor);
135 if (pak_fd != base::kInvalidPlatformFileValue) {
136 ui::ResourceBundle::InitSharedInstanceWithPakFile(pak_fd, false);
137 ResourceBundle::GetSharedInstance().AddDataPackFromFile(
138 pak_fd, ui::SCALE_FACTOR_100P);
139 return;
141 #endif
143 FilePath pak_file;
144 #if defined(OS_MACOSX)
145 pak_file = GetResourcesPakFilePath();
146 #else
147 FilePath pak_dir;
149 #if defined(OS_ANDROID)
150 bool got_path = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir);
151 DCHECK(got_path);
152 pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks"));
153 #else
154 PathService::Get(base::DIR_MODULE, &pak_dir);
155 #endif
157 pak_file = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak"));
158 #endif
159 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
162 ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() {
163 browser_client_.reset(new ShellContentBrowserClient);
164 return browser_client_.get();
167 ContentRendererClient* ShellMainDelegate::CreateContentRendererClient() {
168 renderer_client_.reset(new ShellContentRendererClient);
169 return renderer_client_.get();
172 } // namespace content