content_browser_client.h 5.36 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 12 13 14
#include <string>
#include <utility>

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

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

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

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

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

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

43 44
  // Methods for managing CefBrowserInfo life span. Do not add new callers of
  // these methods.
45 46
  // During popup window creation there is a race between the call to
  // CefBrowserMessageFilter::OnGetNewBrowserInfo on the IO thread and the call
47 48 49
  // 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.
50 51 52 53 54 55 56 57 58 59 60
  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);
61

62 63
  virtual content::BrowserMainParts* CreateBrowserMainParts(
      const content::MainFunctionParams& parameters) OVERRIDE;
64
  virtual content::WebContentsViewPort* OverrideCreateWebContentsView(
65 66
      content::WebContents* web_contents,
      content::RenderViewHostDelegateView** rvhdv) OVERRIDE;
67 68 69 70
  virtual void RenderProcessHostCreated(
      content::RenderProcessHost* host) OVERRIDE;
  virtual net::URLRequestContextGetter* CreateRequestContext(
      content::BrowserContext* browser_context,
71
      content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
72 73 74 75
  virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
      content::BrowserContext* browser_context,
      const base::FilePath& partition_path,
      bool in_memory,
76
      content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
77 78
  virtual void AppendExtraCommandLineSwitches(CommandLine* command_line,
                                              int child_process_id) OVERRIDE;
79 80
  virtual content::QuotaPermissionContext*
      CreateQuotaPermissionContext() OVERRIDE;
81
  virtual content::MediaObserver* GetMediaObserver() OVERRIDE;
82 83
  virtual content::SpeechRecognitionManagerDelegate*
      GetSpeechRecognitionManagerDelegate() OVERRIDE;
84
  virtual content::AccessTokenStore* CreateAccessTokenStore() OVERRIDE;
85 86 87 88 89 90
  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;
91
  virtual void ResourceDispatcherHostCreated() OVERRIDE;
92 93
  virtual void OverrideWebkitPrefs(content::RenderViewHost* rvh,
                                   const GURL& url,
94
                                   webkit_glue::WebPreferences* prefs) OVERRIDE;
95 96
  virtual void BrowserURLHandlerCreated(
      content::BrowserURLHandler* handler) OVERRIDE;
97
  virtual std::string GetDefaultDownloadName() OVERRIDE;
98

99 100 101
#if defined(OS_WIN)
  const wchar_t* GetResourceDllName() OVERRIDE;
#endif
102

103 104 105
  // Store additional state from the ViewHostMsg_CreateWindow message that will
  // be used when CanCreateWindow() is called.
  struct LastCreateWindowParams {
106 107
    int opener_process_id;
    int opener_view_id;
108 109 110 111 112 113
    int64 opener_frame_id;
    GURL target_url;
    string16 target_frame_name;
  };
  void set_last_create_window_params(const LastCreateWindowParams& params);

114
 private:
115 116 117
  CefBrowserContext* CefBrowserContextForBrowserContext(
      content::BrowserContext* content_browser_context);

118 119
  CefBrowserMainParts* browser_main_parts_;

120
  scoped_ptr<content::PluginServiceFilter> plugin_service_filter_;
121 122
  scoped_ptr<CefResourceDispatcherHostDelegate>
      resource_dispatcher_host_delegate_;
123

124
  base::Lock browser_info_lock_;
125

126 127 128 129
  // Access must be protected by |browser_info_lock_|.
  typedef std::list<scoped_refptr<CefBrowserInfo> > BrowserInfoList;
  BrowserInfoList browser_info_list_;
  int next_browser_id_;
130 131 132

  // Only accessed on the IO thread.
  LastCreateWindowParams last_create_window_params_;
133 134 135
};

#endif  // CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_