content_browser_client.h 7.78 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 41 42
class SiteInstance;
}

class CefContentBrowserClient : public content::ContentBrowserClient {
 public:
  CefContentBrowserClient();
  virtual ~CefContentBrowserClient();

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
  virtual content::BrowserMainParts* CreateBrowserMainParts(
      const content::MainFunctionParams& parameters) OVERRIDE;
84
  virtual void RenderProcessWillLaunch(
85 86 87
      content::RenderProcessHost* host) OVERRIDE;
  virtual net::URLRequestContextGetter* CreateRequestContext(
      content::BrowserContext* browser_context,
88 89
      content::ProtocolHandlerMap* protocol_handlers,
      content::ProtocolHandlerScopedVector protocol_interceptors) OVERRIDE;
90 91 92 93
  virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
      content::BrowserContext* browser_context,
      const base::FilePath& partition_path,
      bool in_memory,
94 95
      content::ProtocolHandlerMap* protocol_handlers,
      content::ProtocolHandlerScopedVector protocol_interceptors) OVERRIDE;
96
  virtual bool IsHandledURL(const GURL& url) OVERRIDE;
97
  virtual void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
98
                                              int child_process_id) OVERRIDE;
99 100
  virtual content::QuotaPermissionContext*
      CreateQuotaPermissionContext() OVERRIDE;
101
  virtual content::MediaObserver* GetMediaObserver() OVERRIDE;
102 103
  virtual content::SpeechRecognitionManagerDelegate*
      GetSpeechRecognitionManagerDelegate() OVERRIDE;
104 105
  virtual void AllowCertificateError(
      int render_process_id,
106
      int render_frame_id,
107 108 109 110 111 112 113
      int cert_error,
      const net::SSLInfo& ssl_info,
      const GURL& request_url,
      ResourceType::Type resource_type,
      bool overridable,
      bool strict_enforcement,
      const base::Callback<void(bool)>& callback,
114
      content::CertificateRequestResultType* result) OVERRIDE;
115
  virtual content::AccessTokenStore* CreateAccessTokenStore() OVERRIDE;
116
  virtual bool CanCreateWindow(const GURL& opener_url,
117
                               const GURL& opener_top_level_frame_url,
118
                               const GURL& source_origin,
119
                               WindowContainerType container_type,
120 121 122
                               const GURL& target_url,
                               const content::Referrer& referrer,
                               WindowOpenDisposition disposition,
123
                               const blink::WebWindowFeatures& features,
124 125
                               bool user_gesture,
                               bool opener_suppressed,
126 127
                               content::ResourceContext* context,
                               int render_process_id,
128 129
                               bool is_guest,
                               int opener_id,
130
                               bool* no_javascript_access) OVERRIDE;
131
  virtual void ResourceDispatcherHostCreated() OVERRIDE;
132 133
  virtual void OverrideWebkitPrefs(content::RenderViewHost* rvh,
                                   const GURL& url,
134
                                   WebPreferences* prefs) OVERRIDE;
135
  virtual SkColor GetBaseBackgroundColor(content::RenderViewHost* rvh) OVERRIDE;
136 137
  virtual void BrowserURLHandlerCreated(
      content::BrowserURLHandler* handler) OVERRIDE;
138
  virtual std::string GetDefaultDownloadName() OVERRIDE;
139

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

147 148 149
#if defined(OS_WIN)
  const wchar_t* GetResourceDllName() OVERRIDE;
#endif
150

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

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

165 166 167 168
  CefBrowserContext* browser_context() const;
  scoped_refptr<net::URLRequestContextGetter> request_context() const;
  CefDevToolsDelegate* devtools_delegate() const;
  PrefService* pref_service() const;
169

170 171 172 173
  // Passes ownership.
  scoped_ptr<net::ProxyConfigService> proxy_config_service() const;

 private:
174 175
  CefBrowserMainParts* browser_main_parts_;

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

180
  base::Lock browser_info_lock_;
181

182 183 184 185
  // Access must be protected by |browser_info_lock_|.
  typedef std::list<scoped_refptr<CefBrowserInfo> > BrowserInfoList;
  BrowserInfoList browser_info_list_;
  int next_browser_id_;
186 187 188

  // Only accessed on the IO thread.
  LastCreateWindowParams last_create_window_params_;
189 190 191
};

#endif  // CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_