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.
4
5#ifndef CONTENT_SHELL_BROWSER_SHELL_CONTENT_BROWSER_CLIENT_H_
6#define CONTENT_SHELL_BROWSER_SHELL_CONTENT_BROWSER_CLIENT_H_
7
8#include <string>
9
10#include "base/compiler_specific.h"
11#include "base/files/file_path.h"
12#include "base/memory/scoped_ptr.h"
13#include "content/public/browser/content_browser_client.h"
14#include "content/shell/browser/shell_speech_recognition_manager_delegate.h"
15
16namespace content {
17
18class ShellBrowserContext;
19class ShellBrowserMainParts;
20class ShellNotificationManager;
21class ShellResourceDispatcherHostDelegate;
22
23class ShellContentBrowserClient : public ContentBrowserClient {
24 public:
25  // Gets the current instance.
26  static ShellContentBrowserClient* Get();
27
28  static void SetSwapProcessesForRedirect(bool swap);
29
30  ShellContentBrowserClient();
31  virtual ~ShellContentBrowserClient();
32
33  // Will be lazily created when running layout tests.
34  ShellNotificationManager* GetShellNotificationManager();
35
36  // ContentBrowserClient overrides.
37  virtual BrowserMainParts* CreateBrowserMainParts(
38      const MainFunctionParams& parameters) OVERRIDE;
39  virtual void RenderProcessWillLaunch(RenderProcessHost* host) OVERRIDE;
40  virtual net::URLRequestContextGetter* CreateRequestContext(
41      BrowserContext* browser_context,
42      ProtocolHandlerMap* protocol_handlers,
43      URLRequestInterceptorScopedVector request_interceptors) OVERRIDE;
44  virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
45      BrowserContext* browser_context,
46      const base::FilePath& partition_path,
47      bool in_memory,
48      ProtocolHandlerMap* protocol_handlers,
49      URLRequestInterceptorScopedVector request_interceptors) OVERRIDE;
50  virtual bool IsHandledURL(const GURL& url) OVERRIDE;
51  virtual void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
52                                              int child_process_id) OVERRIDE;
53  virtual void OverrideWebkitPrefs(RenderViewHost* render_view_host,
54                                   const GURL& url,
55                                   WebPreferences* prefs) OVERRIDE;
56  virtual void ResourceDispatcherHostCreated() OVERRIDE;
57  virtual AccessTokenStore* CreateAccessTokenStore() OVERRIDE;
58  virtual std::string GetDefaultDownloadName() OVERRIDE;
59  virtual WebContentsViewDelegate* GetWebContentsViewDelegate(
60      WebContents* web_contents) OVERRIDE;
61  virtual QuotaPermissionContext* CreateQuotaPermissionContext() OVERRIDE;
62  virtual void RequestDesktopNotificationPermission(
63      const GURL& source_origin,
64      RenderFrameHost* render_frame_host,
65      const base::Callback<void(blink::WebNotificationPermission)>& callback)
66          OVERRIDE;
67  virtual blink::WebNotificationPermission
68      CheckDesktopNotificationPermission(
69          const GURL& source_url,
70          ResourceContext* context,
71          int render_process_id) OVERRIDE;
72  virtual SpeechRecognitionManagerDelegate*
73      GetSpeechRecognitionManagerDelegate() OVERRIDE;
74  virtual net::NetLog* GetNetLog() OVERRIDE;
75  virtual bool ShouldSwapProcessesForRedirect(ResourceContext* resource_context,
76                                              const GURL& current_url,
77                                              const GURL& new_url) OVERRIDE;
78  virtual DevToolsManagerDelegate* GetDevToolsManagerDelegate() OVERRIDE;
79
80#if defined(OS_POSIX) && !defined(OS_MACOSX)
81  virtual void GetAdditionalMappedFilesForChildProcess(
82      const base::CommandLine& command_line,
83      int child_process_id,
84      std::vector<FileDescriptorInfo>* mappings) OVERRIDE;
85#endif
86#if defined(OS_WIN)
87  virtual void PreSpawnRenderer(sandbox::TargetPolicy* policy,
88                                bool* success) OVERRIDE;
89#endif
90
91  ShellBrowserContext* browser_context();
92  ShellBrowserContext* off_the_record_browser_context();
93  ShellResourceDispatcherHostDelegate* resource_dispatcher_host_delegate() {
94    return resource_dispatcher_host_delegate_.get();
95  }
96  ShellBrowserMainParts* shell_browser_main_parts() {
97    return shell_browser_main_parts_;
98  }
99
100 private:
101  ShellBrowserContext* ShellBrowserContextForBrowserContext(
102      BrowserContext* content_browser_context);
103
104  scoped_ptr<ShellNotificationManager> shell_notification_manager_;
105
106  scoped_ptr<ShellResourceDispatcherHostDelegate>
107      resource_dispatcher_host_delegate_;
108
109  base::FilePath webkit_source_dir_;
110
111  ShellBrowserMainParts* shell_browser_main_parts_;
112};
113
114}  // namespace content
115
116#endif  // CONTENT_SHELL_BROWSER_SHELL_CONTENT_BROWSER_CLIENT_H_
117