content_browser_client.h 8.14 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_
#define CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_
#pragma once

9
#include <list>
10
#include <map>
11
#include <set>
12 13 14
#include <string>
#include <utility>

15 16
#include "include/cef_request_context_handler.h"

17
#include "base/compiler_specific.h"
18
#include "base/memory/ref_counted.h"
19
#include "base/memory/scoped_ptr.h"
20
#include "base/synchronization/lock.h"
21
#include "content/public/browser/content_browser_client.h"
22 23
#include "net/proxy/proxy_config_service.h"
#include "net/url_request/url_request_context_getter.h"
24
#include "url/gurl.h"
25

26
class CefBrowserContext;
27
class CefBrowserInfo;
28
class CefBrowserMainParts;
29
class CefDevToolsDelegate;
30
class CefResourceDispatcherHostDelegate;
31
class PrefService;
32 33

namespace content {
34
class PluginServiceFilter;
35 36 37 38 39 40
class SiteInstance;
}

class CefContentBrowserClient : public content::ContentBrowserClient {
 public:
  CefContentBrowserClient();
41
  ~CefContentBrowserClient() override;
42

43 44 45
  // Returns the singleton CefContentBrowserClient instance.
  static CefContentBrowserClient* Get();

46 47
  // Methods for managing CefBrowserInfo life span. Do not add new callers of
  // these methods.
48 49
  // During popup window creation there is a race between the call to
  // CefBrowserMessageFilter::OnGetNewBrowserInfo on the IO thread and the call
50 51 52
  // to CefBrowserHostImpl::ShouldCreateWebContents on the UI thread. To resolve
  // this race CefBrowserInfo may be created when requested for the first time
  // and before the associated CefBrowserHostImpl is created.
53
  scoped_refptr<CefBrowserInfo> CreateBrowserInfo(bool is_popup);
54 55 56 57 58
  scoped_refptr<CefBrowserInfo> GetOrCreateBrowserInfo(
      int render_view_process_id,
      int render_view_routing_id,
      int render_frame_process_id,
      int render_frame_routing_id);
59 60 61 62 63
  void RemoveBrowserInfo(scoped_refptr<CefBrowserInfo> browser_info);
  void DestroyAllBrowsers();

  // Retrieves the CefBrowserInfo matching the specified IDs or an empty
  // pointer if no match is found. It is allowed to add new callers of this
64
  // method but consider using CefBrowserHostImpl::GetBrowserFor[View|Frame]()
65
  // instead.
66 67 68 69
  scoped_refptr<CefBrowserInfo> GetBrowserInfoForView(int render_process_id,
                                                      int render_routing_id);
  scoped_refptr<CefBrowserInfo> GetBrowserInfoForFrame(int render_process_id,
                                                       int render_routing_id);
70

71 72 73 74 75 76 77 78 79 80 81
  // Create and return a new CefBrowserContextProxy object.
  CefBrowserContext* CreateBrowserContextProxy(
      CefRefPtr<CefRequestContextHandler> handler);

  // BrowserContexts are nominally owned by RenderViewHosts and
  // CefRequestContextImpls. Keep track of how many objects reference a given
  // context and delete the context when the reference count reaches zero.
  void AddBrowserContextReference(CefBrowserContext* context);
  void RemoveBrowserContextReference(CefBrowserContext* context);

  // ContentBrowserClient implementation.
82 83 84 85 86
  content::BrowserMainParts* CreateBrowserMainParts(
      const content::MainFunctionParams& parameters) override;
  void RenderProcessWillLaunch(
      content::RenderProcessHost* host) override;
  net::URLRequestContextGetter* CreateRequestContext(
87
      content::BrowserContext* browser_context,
88
      content::ProtocolHandlerMap* protocol_handlers,
89
      content::URLRequestInterceptorScopedVector request_interceptors)
90 91
      override;
  net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
92 93 94
      content::BrowserContext* browser_context,
      const base::FilePath& partition_path,
      bool in_memory,
95
      content::ProtocolHandlerMap* protocol_handlers,
96
      content::URLRequestInterceptorScopedVector request_interceptors)
97 98 99 100 101 102 103 104
      override;
  bool IsHandledURL(const GURL& url) override;
  void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
                                              int child_process_id) override;
  content::QuotaPermissionContext*
      CreateQuotaPermissionContext() override;
  content::MediaObserver* GetMediaObserver() override;
  content::SpeechRecognitionManagerDelegate*
105
      CreateSpeechRecognitionManagerDelegate() override;
106
  void AllowCertificateError(
107
      int render_process_id,
108
      int render_frame_id,
109 110 111
      int cert_error,
      const net::SSLInfo& ssl_info,
      const GURL& request_url,
112
      content::ResourceType resource_type,
113 114
      bool overridable,
      bool strict_enforcement,
115
      bool expired_previous_decision,
116
      const base::Callback<void(bool)>& callback,
117 118 119 120
      content::CertificateRequestResultType* result) override;
  content::AccessTokenStore* CreateAccessTokenStore() override;
  void RequestPermission(
      content::PermissionType permission,
121 122 123 124
      content::WebContents* web_contents,
      int bridge_id,
      const GURL& requesting_frame,
      bool user_gesture,
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
      const base::Callback<void(bool)>& result_callback) override;
  void CancelPermissionRequest(content::PermissionType permission,
                                       content::WebContents* web_contents,
                                       int bridge_id,
                                       const GURL& requesting_frame) override;
  bool CanCreateWindow(const GURL& opener_url,
                       const GURL& opener_top_level_frame_url,
                       const GURL& source_origin,
                       WindowContainerType container_type,
                       const GURL& target_url,
                       const content::Referrer& referrer,
                       WindowOpenDisposition disposition,
                       const blink::WebWindowFeatures& features,
                       bool user_gesture,
                       bool opener_suppressed,
                       content::ResourceContext* context,
                       int render_process_id,
                       int opener_id,
                       bool* no_javascript_access) override;
  void ResourceDispatcherHostCreated() override;
  void OverrideWebkitPrefs(content::RenderViewHost* rvh,
                           const GURL& url,
                           content::WebPreferences* prefs) override;
  SkColor GetBaseBackgroundColor(content::RenderViewHost* rvh) override;
  void BrowserURLHandlerCreated(
      content::BrowserURLHandler* handler) override;
  std::string GetDefaultDownloadName() override;
  content::DevToolsManagerDelegate* GetDevToolsManagerDelegate()
      override;
154

155
#if defined(OS_POSIX) && !defined(OS_MACOSX)
156
  void GetAdditionalMappedFilesForChildProcess(
157
      const base::CommandLine& command_line,
158
      int child_process_id,
159
      content::FileDescriptorInfo* mappings) override;
160 161
#endif

162
#if defined(OS_WIN)
163
  const wchar_t* GetResourceDllName() override;
164
#endif
165

166 167
  // Perform browser process registration for the custom scheme.
  void RegisterCustomScheme(const std::string& scheme);
168

169 170 171
  // Store additional state from the ViewHostMsg_CreateWindow message that will
  // be used when CanCreateWindow() is called.
  struct LastCreateWindowParams {
172 173
    int opener_process_id;
    int opener_view_id;
174 175
    int64 opener_frame_id;
    GURL target_url;
176
    base::string16 target_frame_name;
177 178 179
  };
  void set_last_create_window_params(const LastCreateWindowParams& params);

180 181 182 183
  CefBrowserContext* browser_context() const;
  scoped_refptr<net::URLRequestContextGetter> request_context() const;
  CefDevToolsDelegate* devtools_delegate() const;
  PrefService* pref_service() const;
184

185 186 187 188
  // Passes ownership.
  scoped_ptr<net::ProxyConfigService> proxy_config_service() const;

 private:
189 190
  CefBrowserMainParts* browser_main_parts_;

191
  scoped_ptr<content::PluginServiceFilter> plugin_service_filter_;
192 193
  scoped_ptr<CefResourceDispatcherHostDelegate>
      resource_dispatcher_host_delegate_;
194

195
  base::Lock browser_info_lock_;
196

197 198 199 200
  // Access must be protected by |browser_info_lock_|.
  typedef std::list<scoped_refptr<CefBrowserInfo> > BrowserInfoList;
  BrowserInfoList browser_info_list_;
  int next_browser_id_;
201 202 203

  // Only accessed on the IO thread.
  LastCreateWindowParams last_create_window_params_;
204 205 206
};

#endif  // CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_