1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef ANDROID_WEBVIEW_AW_BROWSER_DELEGATE_H_ 6#define ANDROID_WEBVIEW_AW_BROWSER_DELEGATE_H_ 7 8#include "base/basictypes.h" 9 10namespace content { 11class BrowserContext; 12class JavaScriptDialogManager; 13class WebContents; 14} 15 16namespace android_webview { 17 18class AwContentsContainer; 19 20// The concrete class implementing this interface is the responsible for 21// creating he browser component objects that the Android WebView depends on. 22// The motivation for this abstraction is to keep code under 23// android_webview/native from holding direct chrome/ layer dependencies. 24// Note this is a distinct role to the Webview embedder proper: this class is 25// about 'static' environmental decoupling, allowing dependency injection by the 26// top-level lib, whereas runtime behavior is controlled by propagated back to 27// the embedding application code via WebContentsDelegate and the like. 28class AwBrowserDependencyFactory { 29 public: 30 virtual ~AwBrowserDependencyFactory(); 31 32 // Allows the lib executive to inject the delegate instance. Ownership of 33 // |delegate| is NOT transferred, but the object must be long-lived. 34 static void SetInstance(AwBrowserDependencyFactory* delegate); 35 36 // Returns the singleton instance. |SetInstance| must have been called. 37 static AwBrowserDependencyFactory* GetInstance(); 38 39 // Returns the current browser context based on the specified mode. 40 virtual content::BrowserContext* GetBrowserContext() = 0; 41 42 // Constructs and returns ownership of a WebContents instance. 43 virtual content::WebContents* CreateWebContents() = 0; 44 45 protected: 46 AwBrowserDependencyFactory(); 47 48 private: 49 DISALLOW_COPY_AND_ASSIGN(AwBrowserDependencyFactory); 50}; 51 52} // namespace android_webview 53 54#endif // ANDROID_WEBVIEW_AW_BROWSER_DELEGATE_H_ 55