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_content_browser_client.h"
7 #include "base/command_line.h"
8 #include "base/file_path.h"
9 #include "content/public/browser/resource_dispatcher_host.h"
10 #include "content/shell/geolocation/shell_access_token_store.h"
11 #include "content/shell/shell.h"
12 #include "content/shell/shell_browser_context.h"
13 #include "content/shell/shell_browser_main_parts.h"
14 #include "content/shell/shell_devtools_delegate.h"
15 #include "content/shell/shell_resource_dispatcher_host_delegate.h"
16 #include "content/shell/shell_switches.h"
17 #include "content/shell/shell_web_contents_view_delegate_creator.h"
18 #include "content/shell/webkit_test_runner_host.h"
19 #include "googleurl/src/gurl.h"
21 #if defined(OS_ANDROID)
22 #include "base/android/path_utils.h"
23 #include "base/path_service.h"
24 #include "base/platform_file.h"
25 #include "content/shell/android/shell_descriptors.h"
30 ShellContentBrowserClient::ShellContentBrowserClient()
31 : shell_browser_main_parts_(NULL
) {
34 ShellContentBrowserClient::~ShellContentBrowserClient() {
37 BrowserMainParts
* ShellContentBrowserClient::CreateBrowserMainParts(
38 const MainFunctionParams
& parameters
) {
39 shell_browser_main_parts_
= new ShellBrowserMainParts(parameters
);
40 return shell_browser_main_parts_
;
43 void ShellContentBrowserClient::RenderViewHostCreated(
44 RenderViewHost
* render_view_host
) {
45 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree
))
47 new WebKitTestRunnerHost(render_view_host
);
50 void ShellContentBrowserClient::AppendExtraCommandLineSwitches(
51 CommandLine
* command_line
, int child_process_id
) {
52 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree
))
53 command_line
->AppendSwitch(switches::kDumpRenderTree
);
56 void ShellContentBrowserClient::ResourceDispatcherHostCreated() {
57 resource_dispatcher_host_delegate_
.reset(
58 new ShellResourceDispatcherHostDelegate());
59 ResourceDispatcherHost::Get()->SetDelegate(
60 resource_dispatcher_host_delegate_
.get());
63 std::string
ShellContentBrowserClient::GetDefaultDownloadName() {
67 WebContentsViewDelegate
* ShellContentBrowserClient::GetWebContentsViewDelegate(
68 WebContents
* web_contents
) {
69 #if defined(TOOLKIT_GTK) || defined(OS_WIN) || defined(OS_MACOSX)
70 return CreateShellWebContentsViewDelegate(web_contents
);
76 #if defined(OS_ANDROID)
77 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
78 const CommandLine
& command_line
,
79 base::GlobalDescriptors::Mapping
* mappings
) {
80 int flags
= base::PLATFORM_FILE_OPEN
| base::PLATFORM_FILE_READ
;
82 DCHECK(PathService::Get(base::DIR_ANDROID_APP_DATA
, &pak_file
));
83 pak_file
= pak_file
.Append(FILE_PATH_LITERAL("paks"));
84 pak_file
= pak_file
.Append(FILE_PATH_LITERAL("content_shell.pak"));
86 base::PlatformFile f
=
87 base::CreatePlatformFile(pak_file
, flags
, NULL
, NULL
);
88 if (f
== base::kInvalidPlatformFileValue
) {
89 NOTREACHED() << "Failed to open file when creating renderer process: "
90 << "content_shell.pak";
92 mappings
->push_back(std::pair
<base::GlobalDescriptors::Key
, int>(
93 kShellPakDescriptor
, f
));
97 ShellBrowserContext
* ShellContentBrowserClient::browser_context() {
98 return shell_browser_main_parts_
->browser_context();
102 ShellContentBrowserClient::off_the_record_browser_context() {
103 return shell_browser_main_parts_
->off_the_record_browser_context();
106 AccessTokenStore
* ShellContentBrowserClient::CreateAccessTokenStore() {
107 return new ShellAccessTokenStore(browser_context()->GetRequestContext());
110 } // namespace content