content_browser_client.h 6.01 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 15
#include <string>
#include <utility>

#include "base/compiler_specific.h"
16
#include "base/memory/ref_counted.h"
17
#include "base/memory/scoped_ptr.h"
18
#include "base/synchronization/lock.h"
19
#include "content/public/browser/content_browser_client.h"
20
#include "googleurl/src/gurl.h"
21

22
class CefBrowserContext;
23
class CefBrowserInfo;
24
class CefBrowserMainParts;
25
class CefResourceDispatcherHostDelegate;
26 27

namespace content {
28
class PluginServiceFilter;
29 30 31 32 33 34 35 36
class SiteInstance;
}

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

37 38 39
  // Returns the singleton CefContentBrowserClient instance.
  static CefContentBrowserClient* Get();

40 41 42 43
  CefBrowserMainParts* browser_main_parts() const {
    return browser_main_parts_;
  }

44 45
  // Methods for managing CefBrowserInfo life span. Do not add new callers of
  // these methods.
46 47
  // During popup window creation there is a race between the call to
  // CefBrowserMessageFilter::OnGetNewBrowserInfo on the IO thread and the call
48 49 50
  // 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.
51 52 53 54 55 56 57 58 59 60 61
  scoped_refptr<CefBrowserInfo> CreateBrowserInfo();
  scoped_refptr<CefBrowserInfo> GetOrCreateBrowserInfo(int render_process_id,
                                                       int render_view_id);
  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
  // method but consider using CefContext::GetBrowserByRoutingID() instead.
  scoped_refptr<CefBrowserInfo> GetBrowserInfo(int render_process_id,
                                               int render_view_id);
62

63 64
  virtual content::BrowserMainParts* CreateBrowserMainParts(
      const content::MainFunctionParams& parameters) OVERRIDE;
65
  virtual content::WebContentsViewPort* OverrideCreateWebContentsView(
66 67
      content::WebContents* web_contents,
      content::RenderViewHostDelegateView** rvhdv) OVERRIDE;
68 69 70 71
  virtual void RenderProcessHostCreated(
      content::RenderProcessHost* host) OVERRIDE;
  virtual net::URLRequestContextGetter* CreateRequestContext(
      content::BrowserContext* browser_context,
72
      content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
73 74 75 76
  virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
      content::BrowserContext* browser_context,
      const base::FilePath& partition_path,
      bool in_memory,
77
      content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
78
  virtual bool IsHandledURL(const GURL& url) OVERRIDE;
79 80
  virtual void AppendExtraCommandLineSwitches(CommandLine* command_line,
                                              int child_process_id) OVERRIDE;
81 82
  virtual content::QuotaPermissionContext*
      CreateQuotaPermissionContext() OVERRIDE;
83
  virtual content::MediaObserver* GetMediaObserver() OVERRIDE;
84 85
  virtual content::SpeechRecognitionManagerDelegate*
      GetSpeechRecognitionManagerDelegate() OVERRIDE;
86 87 88 89 90 91 92 93 94 95
  virtual void AllowCertificateError(
      int render_process_id,
      int render_view_id,
      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,
96
      content::CertificateRequestResultType* result) OVERRIDE;
97
  virtual content::AccessTokenStore* CreateAccessTokenStore() OVERRIDE;
98 99 100 101 102 103
  virtual bool CanCreateWindow(const GURL& opener_url,
                               const GURL& origin,
                               WindowContainerType container_type,
                               content::ResourceContext* context,
                               int render_process_id,
                               bool* no_javascript_access) OVERRIDE;
104
  virtual void ResourceDispatcherHostCreated() OVERRIDE;
105 106
  virtual void OverrideWebkitPrefs(content::RenderViewHost* rvh,
                                   const GURL& url,
107
                                   WebPreferences* prefs) OVERRIDE;
108 109
  virtual void BrowserURLHandlerCreated(
      content::BrowserURLHandler* handler) OVERRIDE;
110
  virtual std::string GetDefaultDownloadName() OVERRIDE;
111

112 113 114
#if defined(OS_WIN)
  const wchar_t* GetResourceDllName() OVERRIDE;
#endif
115

116 117 118 119
  // Add a custom scheme registration.
  void AddCustomScheme(const std::string& scheme);
  void LockCustomSchemes();

120 121 122
  // Store additional state from the ViewHostMsg_CreateWindow message that will
  // be used when CanCreateWindow() is called.
  struct LastCreateWindowParams {
123 124
    int opener_process_id;
    int opener_view_id;
125 126 127 128 129 130
    int64 opener_frame_id;
    GURL target_url;
    string16 target_frame_name;
  };
  void set_last_create_window_params(const LastCreateWindowParams& params);

131
 private:
132 133 134
  CefBrowserContext* CefBrowserContextForBrowserContext(
      content::BrowserContext* content_browser_context);

135 136
  CefBrowserMainParts* browser_main_parts_;

137
  scoped_ptr<content::PluginServiceFilter> plugin_service_filter_;
138 139
  scoped_ptr<CefResourceDispatcherHostDelegate>
      resource_dispatcher_host_delegate_;
140

141
  base::Lock browser_info_lock_;
142

143 144 145 146
  // Access must be protected by |browser_info_lock_|.
  typedef std::list<scoped_refptr<CefBrowserInfo> > BrowserInfoList;
  BrowserInfoList browser_info_list_;
  int next_browser_id_;
147

148 149 150 151
  typedef std::set<std::string> SchemeSet;
  SchemeSet scheme_set_;
  bool scheme_set_locked_;

152 153
  // Only accessed on the IO thread.
  LastCreateWindowParams last_create_window_params_;
154 155 156
};

#endif  // CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_