summaryrefslogtreecommitdiffstats
path: root/android_webview/native/aw_browser_dependency_factory.h
blob: 08243029159fab23dfd0f41d7a8762c52bc57d58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2012 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 ANDROID_WEBVIEW_AW_BROWSER_DELEGATE_H_
#define ANDROID_WEBVIEW_AW_BROWSER_DELEGATE_H_

#include "base/basictypes.h"

namespace content {
class BrowserContext;
class JavaScriptDialogManager;
class WebContents;
}

namespace android_webview {

class AwContentsContainer;

// The concrete class implementing this interface is the responsible for
// creating he browser component objects that the Android WebView depends on.
// The motivation for this abstraction is to keep code under
// android_webview/native from holding direct chrome/ layer dependencies.
// Note this is a distinct role to the Webview embedder proper: this class is
// about 'static' environmental decoupling, allowing dependency injection by the
// top-level lib, whereas runtime behavior is controlled by propagated back to
// the embedding application code via WebContentsDelegate and the like.
class AwBrowserDependencyFactory {
 public:
  virtual ~AwBrowserDependencyFactory();

  // Allows the lib executive to inject the delegate instance. Ownership of
  // |delegate| is NOT transferred, but the object must be long-lived.
  static void SetInstance(AwBrowserDependencyFactory* delegate);

  // Returns the singleton instance. |SetInstance| must have been called.
  static AwBrowserDependencyFactory* GetInstance();

  // Returns the current browser context based on the specified mode.
  virtual content::BrowserContext* GetBrowserContext() = 0;

  // Constructs and returns ownership of a WebContents instance.
  virtual content::WebContents* CreateWebContents() = 0;

 protected:
  AwBrowserDependencyFactory();

 private:
  DISALLOW_COPY_AND_ASSIGN(AwBrowserDependencyFactory);
};

}  // namespace android_webview

#endif  // ANDROID_WEBVIEW_AW_BROWSER_DELEGATE_H_