content_browser_client.h 7.61 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
#include "include/cef_request_context_handler.h"
16 17
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/url_request_context_getter_impl.h"
18

19
#include "base/compiler_specific.h"
20
#include "base/memory/ref_counted.h"
21
#include "base/memory/scoped_ptr.h"
22
#include "base/synchronization/lock.h"
23
#include "content/public/browser/content_browser_client.h"
24
#include "third_party/skia/include/core/SkColor.h"
25
#include "url/gurl.h"
26

27
class CefBrowserHostImpl;
28
class CefBrowserInfo;
29
class CefBrowserMainParts;
30
class CefDevToolsDelegate;
31
class CefResourceDispatcherHostDelegate;
32
class PrefService;
33 34

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

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

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

47 48
  // Methods for managing CefBrowserInfo life span. Do not add new callers of
  // these methods.
49 50
  // During popup window creation there is a race between the call to
  // CefBrowserMessageFilter::OnGetNewBrowserInfo on the IO thread and the call
51 52 53
  // 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.
54
  scoped_refptr<CefBrowserInfo> CreateBrowserInfo(bool is_popup);
55 56 57 58 59
  scoped_refptr<CefBrowserInfo> GetOrCreateBrowserInfo(
      int render_view_process_id,
      int render_view_routing_id,
      int render_frame_process_id,
      int render_frame_routing_id);
60 61 62 63 64
  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
65
  // method but consider using CefBrowserHostImpl::GetBrowserFor[View|Frame]()
66
  // instead.
67 68 69 70
  scoped_refptr<CefBrowserInfo> GetBrowserInfoForView(int render_process_id,
                                                      int render_routing_id);
  scoped_refptr<CefBrowserInfo> GetBrowserInfoForFrame(int render_process_id,
                                                       int render_routing_id);
71

72
  // ContentBrowserClient implementation.
73 74 75 76
  content::BrowserMainParts* CreateBrowserMainParts(
      const content::MainFunctionParams& parameters) override;
  void RenderProcessWillLaunch(
      content::RenderProcessHost* host) override;
77 78
  bool ShouldUseProcessPerSite(content::BrowserContext* browser_context,
                               const GURL& effective_url) override;
79
  net::URLRequestContextGetter* CreateRequestContext(
80
      content::BrowserContext* browser_context,
81
      content::ProtocolHandlerMap* protocol_handlers,
82
      content::URLRequestInterceptorScopedVector request_interceptors)
83 84
      override;
  net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
85 86 87
      content::BrowserContext* browser_context,
      const base::FilePath& partition_path,
      bool in_memory,
88
      content::ProtocolHandlerMap* protocol_handlers,
89
      content::URLRequestInterceptorScopedVector request_interceptors)
90 91 92 93 94 95 96 97
      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*
98
      CreateSpeechRecognitionManagerDelegate() override;
99
  void AllowCertificateError(
100
      int render_process_id,
101
      int render_frame_id,
102 103 104
      int cert_error,
      const net::SSLInfo& ssl_info,
      const GURL& request_url,
105
      content::ResourceType resource_type,
106 107
      bool overridable,
      bool strict_enforcement,
108
      bool expired_previous_decision,
109
      const base::Callback<void(bool)>& callback,
110
      content::CertificateRequestResultType* result) override;
111 112 113 114
  void SelectClientCertificate(
      content::WebContents* web_contents,
      net::SSLCertRequestInfo* cert_request_info,
      scoped_ptr<content::ClientCertificateDelegate> delegate) override;
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
  content::AccessTokenStore* CreateAccessTokenStore() 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,
                           content::WebPreferences* prefs) override;
  void BrowserURLHandlerCreated(
      content::BrowserURLHandler* handler) override;
  std::string GetDefaultDownloadName() override;
136
  void DidCreatePpapiPlugin(content::BrowserPpapiHost* browser_host) override;
137 138
  content::DevToolsManagerDelegate* GetDevToolsManagerDelegate()
      override;
139

140
#if defined(OS_POSIX) && !defined(OS_MACOSX)
141
  void GetAdditionalMappedFilesForChildProcess(
142
      const base::CommandLine& command_line,
143
      int child_process_id,
144
      content::FileDescriptorInfo* mappings) override;
145 146
#endif

147
#if defined(OS_WIN)
148
  const wchar_t* GetResourceDllName() override;
149
  void PreSpawnRenderer(sandbox::TargetPolicy* policy, bool* success) override;
150
#endif
151

152 153
  // Perform browser process registration for the custom scheme.
  void RegisterCustomScheme(const std::string& scheme);
154

155 156 157
  // Store additional state from the ViewHostMsg_CreateWindow message that will
  // be used when CanCreateWindow() is called.
  struct LastCreateWindowParams {
158 159
    int opener_process_id;
    int opener_view_id;
160 161
    int64 opener_frame_id;
    GURL target_url;
162
    base::string16 target_frame_name;
163 164 165
  };
  void set_last_create_window_params(const LastCreateWindowParams& params);

166
  scoped_refptr<CefBrowserContextImpl> browser_context() const;
167 168
  CefDevToolsDelegate* devtools_delegate() const;
  PrefService* pref_service() const;
169

170
 private:
171
  static SkColor GetBaseBackgroundColor(CefRefPtr<CefBrowserHostImpl> browser);
172

173 174
  CefBrowserMainParts* browser_main_parts_;

175
  scoped_ptr<content::PluginServiceFilter> plugin_service_filter_;
176 177
  scoped_ptr<CefResourceDispatcherHostDelegate>
      resource_dispatcher_host_delegate_;
178

179 180 181 182 183
#if defined(OS_POSIX) && !defined(OS_MACOSX)
  base::ScopedFD v8_natives_fd_;
  base::ScopedFD v8_snapshot_fd_;
#endif

184
  base::Lock browser_info_lock_;
185

186 187 188 189
  // Access must be protected by |browser_info_lock_|.
  typedef std::list<scoped_refptr<CefBrowserInfo> > BrowserInfoList;
  BrowserInfoList browser_info_list_;
  int next_browser_id_;
190 191 192

  // Only accessed on the IO thread.
  LastCreateWindowParams last_create_window_params_;
193 194 195
};

#endif  // CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_