Home | History | Annotate | Download | only in browser
      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_BROWSER_AW_BROWSER_CONTEXT_H_
      6 #define ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_
      7 
      8 #include <vector>
      9 
     10 #include "android_webview/browser/aw_download_manager_delegate.h"
     11 #include "base/basictypes.h"
     12 #include "base/compiler_specific.h"
     13 #include "base/files/file_path.h"
     14 #include "base/memory/ref_counted.h"
     15 #include "base/memory/scoped_ptr.h"
     16 #include "components/visitedlink/browser/visitedlink_delegate.h"
     17 #include "content/public/browser/browser_context.h"
     18 #include "content/public/browser/content_browser_client.h"
     19 #include "content/public/browser/geolocation_permission_context.h"
     20 #include "net/url_request/url_request_job_factory.h"
     21 
     22 class GURL;
     23 
     24 namespace visitedlink {
     25 class VisitedLinkMaster;
     26 }
     27 
     28 namespace content {
     29 class ResourceContext;
     30 class WebContents;
     31 }
     32 
     33 namespace android_webview {
     34 
     35 class AwFormDatabaseService;
     36 class AwQuotaManagerBridge;
     37 class AwURLRequestContextGetter;
     38 class JniDependencyFactory;
     39 
     40 class AwBrowserContext : public content::BrowserContext,
     41                          public visitedlink::VisitedLinkDelegate {
     42  public:
     43 
     44   AwBrowserContext(const base::FilePath path,
     45                    JniDependencyFactory* native_factory);
     46   virtual ~AwBrowserContext();
     47 
     48   // Currently only one instance per process is supported.
     49   static AwBrowserContext* GetDefault();
     50 
     51   // Convenience method to returns the AwBrowserContext corresponding to the
     52   // given WebContents.
     53   static AwBrowserContext* FromWebContents(
     54       content::WebContents* web_contents);
     55 
     56   // Called before BrowserThreads are created.
     57   void InitializeBeforeThreadCreation();
     58 
     59   // Maps to BrowserMainParts::PreMainMessageLoopRun.
     60   void PreMainMessageLoopRun();
     61 
     62   // These methods map to Add methods in visitedlink::VisitedLinkMaster.
     63   void AddVisitedURLs(const std::vector<GURL>& urls);
     64 
     65   net::URLRequestContextGetter* CreateRequestContext(
     66       content::ProtocolHandlerMap* protocol_handlers);
     67   net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
     68       const base::FilePath& partition_path,
     69       bool in_memory,
     70       content::ProtocolHandlerMap* protocol_handlers);
     71 
     72   AwQuotaManagerBridge* GetQuotaManagerBridge();
     73 
     74   AwFormDatabaseService* GetFormDatabaseService();
     75   void CreateUserPrefServiceIfNecessary();
     76 
     77   // content::BrowserContext implementation.
     78   virtual base::FilePath GetPath() const OVERRIDE;
     79   virtual bool IsOffTheRecord() const OVERRIDE;
     80   virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
     81   virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
     82       int renderer_child_id) OVERRIDE;
     83   virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
     84   virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
     85       int renderer_child_id) OVERRIDE;
     86   virtual net::URLRequestContextGetter*
     87       GetMediaRequestContextForStoragePartition(
     88           const base::FilePath& partition_path, bool in_memory) OVERRIDE;
     89   virtual void RequestMIDISysExPermission(
     90       int render_process_id,
     91       int render_view_id,
     92       const GURL& requesting_frame,
     93       const MIDISysExPermissionCallback& callback) OVERRIDE;
     94   virtual content::ResourceContext* GetResourceContext() OVERRIDE;
     95   virtual content::DownloadManagerDelegate*
     96       GetDownloadManagerDelegate() OVERRIDE;
     97   virtual content::GeolocationPermissionContext*
     98       GetGeolocationPermissionContext() OVERRIDE;
     99   virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
    100 
    101   // visitedlink::VisitedLinkDelegate implementation.
    102   virtual void RebuildTable(
    103       const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
    104 
    105  private:
    106   // The file path where data for this context is persisted.
    107   base::FilePath context_storage_path_;
    108 
    109   JniDependencyFactory* native_factory_;
    110   scoped_refptr<AwURLRequestContextGetter> url_request_context_getter_;
    111   scoped_refptr<content::GeolocationPermissionContext>
    112       geolocation_permission_context_;
    113   scoped_refptr<AwQuotaManagerBridge> quota_manager_bridge_;
    114   scoped_ptr<AwFormDatabaseService> form_database_service_;
    115 
    116   AwDownloadManagerDelegate download_manager_delegate_;
    117 
    118   scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
    119   scoped_ptr<content::ResourceContext> resource_context_;
    120 
    121   bool user_pref_service_ready_;
    122 
    123   DISALLOW_COPY_AND_ASSIGN(AwBrowserContext);
    124 };
    125 
    126 }  // namespace android_webview
    127 
    128 #endif  // ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_
    129