• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Embedded Framework Authors.
2 // Portions copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 
6 #include "libcef/browser/extensions/extensions_api_client.h"
7 
8 #include "include/internal/cef_types_wrappers.h"
9 #include "libcef/browser/browser_context.h"
10 #include "libcef/browser/extensions/api/file_system/cef_file_system_delegate.h"
11 #include "libcef/browser/extensions/api/storage/sync_value_store_cache.h"
12 #include "libcef/browser/extensions/extension_web_contents_observer.h"
13 #include "libcef/browser/extensions/mime_handler_view_guest_delegate.h"
14 #include "libcef/browser/printing/print_view_manager.h"
15 
16 #include "base/memory/ptr_util.h"
17 #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h"
18 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
19 #include "components/pdf/browser/pdf_web_contents_helper.h"
20 #include "components/zoom/zoom_controller.h"
21 #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h"
22 #include "printing/mojom/print.mojom.h"
23 
24 namespace extensions {
25 
CefExtensionsAPIClient()26 CefExtensionsAPIClient::CefExtensionsAPIClient() {}
27 
CreateAppViewGuestDelegate() const28 AppViewGuestDelegate* CefExtensionsAPIClient::CreateAppViewGuestDelegate()
29     const {
30   // TODO(extensions): Implement to support Apps.
31   NOTREACHED();
32   return nullptr;
33 }
34 
35 std::unique_ptr<guest_view::GuestViewManagerDelegate>
CreateGuestViewManagerDelegate(content::BrowserContext * context) const36 CefExtensionsAPIClient::CreateGuestViewManagerDelegate(
37     content::BrowserContext* context) const {
38   // The GuestViewManager instance associated with the returned Delegate, which
39   // will be retrieved in the future via GuestViewManager::FromBrowserContext,
40   // will be associated with the CefBrowserContext.
41   return base::WrapUnique(
42       new extensions::ExtensionsGuestViewManagerDelegate(context));
43 }
44 
45 std::unique_ptr<MimeHandlerViewGuestDelegate>
CreateMimeHandlerViewGuestDelegate(MimeHandlerViewGuest * guest) const46 CefExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate(
47     MimeHandlerViewGuest* guest) const {
48   return base::WrapUnique(new CefMimeHandlerViewGuestDelegate(guest));
49 }
50 
AttachWebContentsHelpers(content::WebContents * web_contents) const51 void CefExtensionsAPIClient::AttachWebContentsHelpers(
52     content::WebContents* web_contents) const {
53   PrefsTabHelper::CreateForWebContents(web_contents);
54   printing::CefPrintViewManager::CreateForWebContents(web_contents);
55 
56   // Used by the PDF extension.
57   pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
58       web_contents, std::unique_ptr<pdf::PDFWebContentsHelperClient>(
59                         new ChromePDFWebContentsHelperClient()));
60 
61   // Used by the tabs extension API.
62   zoom::ZoomController::CreateForWebContents(web_contents);
63 }
64 
AddAdditionalValueStoreCaches(content::BrowserContext * context,const scoped_refptr<value_store::ValueStoreFactory> & factory,const scoped_refptr<base::ObserverListThreadSafe<SettingsObserver>> & observers,std::map<settings_namespace::Namespace,ValueStoreCache * > * caches)65 void CefExtensionsAPIClient::AddAdditionalValueStoreCaches(
66     content::BrowserContext* context,
67     const scoped_refptr<value_store::ValueStoreFactory>& factory,
68     const scoped_refptr<base::ObserverListThreadSafe<SettingsObserver>>&
69         observers,
70     std::map<settings_namespace::Namespace, ValueStoreCache*>* caches) {
71   // Add support for chrome.storage.sync.
72   // Because we don't support syncing with Google, we follow the behavior of
73   // chrome.storage.sync as if Chrome were permanently offline, by using a local
74   // store see: https://developer.chrome.com/apps/storage for more information
75   (*caches)[settings_namespace::SYNC] = new cef::SyncValueStoreCache(factory);
76 }
77 
GetFileSystemDelegate()78 FileSystemDelegate* CefExtensionsAPIClient::GetFileSystemDelegate() {
79   if (!file_system_delegate_)
80     file_system_delegate_ = std::make_unique<cef::CefFileSystemDelegate>();
81   return file_system_delegate_.get();
82 }
83 
84 }  // namespace extensions
85