content_browser_client.h 4.73 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 CefBrowserInfo;
22 23
class CefBrowserMainParts;
class CefMediaObserver;
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 47
  // During popup window creation there is a race between the call to
  // CefBrowserMessageFilter::OnGetNewBrowserInfo on the IO thread and the call
  // to CefBrowserHostImpl::WebContentsCreated on the UI thread. To resolve this
48 49 50 51 52 53 54 55 56 57 58 59 60
  // race CefBrowserInfo may be created when requested for the first time and
  // before the associated CefBrowserHostImpl is created.
  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 64 65
  virtual content::BrowserMainParts* CreateBrowserMainParts(
      const content::MainFunctionParams& parameters) OVERRIDE;
  virtual void RenderProcessHostCreated(
      content::RenderProcessHost* host) OVERRIDE;
66 67 68
  virtual content::WebContentsView* OverrideCreateWebContentsView(
      content::WebContents* web_contents,
      content::RenderViewHostDelegateView** rvhdv) OVERRIDE;
69 70
  virtual void AppendExtraCommandLineSwitches(CommandLine* command_line,
                                              int child_process_id) OVERRIDE;
71 72
  virtual content::QuotaPermissionContext*
      CreateQuotaPermissionContext() OVERRIDE;
73 74
  virtual content::MediaObserver* GetMediaObserver() OVERRIDE;
  virtual content::AccessTokenStore* CreateAccessTokenStore() OVERRIDE;
75 76 77 78 79 80
  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;
81
  virtual void ResourceDispatcherHostCreated() OVERRIDE;
82 83
  virtual void OverrideWebkitPrefs(content::RenderViewHost* rvh,
                                   const GURL& url,
84
                                   webkit_glue::WebPreferences* prefs) OVERRIDE;
85 86
  virtual void BrowserURLHandlerCreated(
      content::BrowserURLHandler* handler) OVERRIDE;
87
  virtual std::string GetDefaultDownloadName() OVERRIDE;
88

89 90 91
#if defined(OS_WIN)
  const wchar_t* GetResourceDllName() OVERRIDE;
#endif
92

93 94 95 96 97 98 99 100 101 102
  // Store additional state from the ViewHostMsg_CreateWindow message that will
  // be used when CanCreateWindow() is called.
  struct LastCreateWindowParams {
    int opener_id;
    int64 opener_frame_id;
    GURL target_url;
    string16 target_frame_name;
  };
  void set_last_create_window_params(const LastCreateWindowParams& params);

103 104 105 106
 private:
  CefBrowserMainParts* browser_main_parts_;

  scoped_ptr<CefMediaObserver> media_observer_;
107
  scoped_ptr<content::PluginServiceFilter> plugin_service_filter_;
108 109
  scoped_ptr<CefResourceDispatcherHostDelegate>
      resource_dispatcher_host_delegate_;
110

111
  base::Lock browser_info_lock_;
112

113 114 115 116
  // Access must be protected by |browser_info_lock_|.
  typedef std::list<scoped_refptr<CefBrowserInfo> > BrowserInfoList;
  BrowserInfoList browser_info_list_;
  int next_browser_id_;
117 118 119

  // Only accessed on the IO thread.
  LastCreateWindowParams last_create_window_params_;
120 121 122
};

#endif  // CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_