• 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/storage/sync_value_store_cache.h"
11 #include "libcef/browser/extensions/extension_web_contents_observer.h"
12 #include "libcef/browser/extensions/mime_handler_view_guest_delegate.h"
13 #include "libcef/browser/extensions/pdf_web_contents_helper_client.h"
14 #include "libcef/browser/printing/print_view_manager.h"
15 
16 #include "base/memory/ptr_util.h"
17 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
18 #include "components/pdf/browser/pdf_web_contents_helper.h"
19 #include "components/zoom/zoom_controller.h"
20 #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h"
21 
22 namespace extensions {
23 
CefExtensionsAPIClient()24 CefExtensionsAPIClient::CefExtensionsAPIClient() {}
25 
CreateAppViewGuestDelegate() const26 AppViewGuestDelegate* CefExtensionsAPIClient::CreateAppViewGuestDelegate()
27     const {
28   // TODO(extensions): Implement to support Apps.
29   NOTREACHED();
30   return nullptr;
31 }
32 
33 std::unique_ptr<guest_view::GuestViewManagerDelegate>
CreateGuestViewManagerDelegate(content::BrowserContext * context) const34 CefExtensionsAPIClient::CreateGuestViewManagerDelegate(
35     content::BrowserContext* context) const {
36   // The GuestViewManager instance associated with the returned Delegate, which
37   // will be retrieved in the future via GuestViewManager::FromBrowserContext,
38   // will be associated with the CefBrowserContext.
39   return base::WrapUnique(
40       new extensions::ExtensionsGuestViewManagerDelegate(context));
41 }
42 
43 std::unique_ptr<MimeHandlerViewGuestDelegate>
CreateMimeHandlerViewGuestDelegate(MimeHandlerViewGuest * guest) const44 CefExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate(
45     MimeHandlerViewGuest* guest) const {
46   return base::WrapUnique(new CefMimeHandlerViewGuestDelegate(guest));
47 }
48 
AttachWebContentsHelpers(content::WebContents * web_contents) const49 void CefExtensionsAPIClient::AttachWebContentsHelpers(
50     content::WebContents* web_contents) const {
51   PrefsTabHelper::CreateForWebContents(web_contents);
52   printing::CefPrintViewManager::CreateForWebContents(web_contents);
53 
54   CefExtensionWebContentsObserver::CreateForWebContents(web_contents);
55 
56   // Used by the PDF extension.
57   pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
58       web_contents, std::unique_ptr<pdf::PDFWebContentsHelperClient>(
59                         new CefPDFWebContentsHelperClient()));
60 
61   // Used by the tabs extension API.
62   zoom::ZoomController::CreateForWebContents(web_contents);
63 }
64 
AddAdditionalValueStoreCaches(content::BrowserContext * context,const scoped_refptr<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<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 
78 }  // namespace extensions
79