1 // Copyright 2014 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.
5 #include "chrome/browser/extensions/api/chrome_extensions_api_client.h"
7 #include "base/files/file_path.h"
8 #include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h"
9 #include "chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry.h"
10 #include "chrome/browser/extensions/api/management/chrome_management_api_delegate.h"
11 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h"
12 #include "chrome/browser/extensions/api/web_request/chrome_extension_web_request_event_router_delegate.h"
13 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
14 #include "chrome/browser/favicon/favicon_helper.h"
15 #include "chrome/browser/guest_view/app_view/chrome_app_view_guest_delegate.h"
16 #include "chrome/browser/guest_view/extension_options/chrome_extension_options_guest_delegate.h"
17 #include "chrome/browser/guest_view/mime_handler_view/chrome_mime_handler_view_guest_delegate.h"
18 #include "chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.h"
19 #include "chrome/browser/guest_view/web_view/chrome_web_view_permission_helper_delegate.h"
20 #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h"
21 #include "components/pdf/browser/pdf_web_contents_helper.h"
22 #include "content/public/browser/browser_context.h"
23 #include "content/public/browser/browser_thread.h"
24 #include "extensions/browser/api/virtual_keyboard_private/virtual_keyboard_delegate.h"
25 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
26 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
28 #if defined(ENABLE_CONFIGURATION_POLICY)
29 #include "chrome/browser/extensions/api/storage/managed_value_store_cache.h"
32 #if defined(OS_CHROMEOS)
33 #include "chrome/browser/extensions/api/virtual_keyboard_private/chrome_virtual_keyboard_delegate.h"
36 #if defined(ENABLE_PRINTING)
37 #if defined(ENABLE_PRINT_PREVIEW)
38 #include "chrome/browser/printing/print_preview_message_handler.h"
39 #include "chrome/browser/printing/print_view_manager.h"
41 #include "chrome/browser/printing/print_view_manager_basic.h"
42 #endif // defined(ENABLE_PRINT_PREVIEW)
43 #endif // defined(ENABLE_PRINTING)
45 namespace extensions
{
47 ChromeExtensionsAPIClient::ChromeExtensionsAPIClient() {}
49 ChromeExtensionsAPIClient::~ChromeExtensionsAPIClient() {}
51 void ChromeExtensionsAPIClient::AddAdditionalValueStoreCaches(
52 content::BrowserContext
* context
,
53 const scoped_refptr
<SettingsStorageFactory
>& factory
,
54 const scoped_refptr
<base::ObserverListThreadSafe
<SettingsObserver
>>&
56 std::map
<settings_namespace::Namespace
, ValueStoreCache
*>* caches
) {
57 // Add support for chrome.storage.sync.
58 (*caches
)[settings_namespace::SYNC
] =
59 new SyncValueStoreCache(factory
, observers
, context
->GetPath());
61 #if defined(ENABLE_CONFIGURATION_POLICY)
62 // Add support for chrome.storage.managed.
63 (*caches
)[settings_namespace::MANAGED
] =
64 new ManagedValueStoreCache(context
, factory
, observers
);
68 void ChromeExtensionsAPIClient::AttachWebContentsHelpers(
69 content::WebContents
* web_contents
) const {
70 favicon::CreateContentFaviconDriverForWebContents(web_contents
);
71 #if defined(ENABLE_PRINTING)
72 #if defined(ENABLE_PRINT_PREVIEW)
73 printing::PrintViewManager::CreateForWebContents(web_contents
);
74 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents
);
76 printing::PrintViewManagerBasic::CreateForWebContents(web_contents
);
77 #endif // defined(ENABLE_PRINT_PREVIEW)
78 #endif // defined(ENABLE_PRINTING)
79 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
81 scoped_ptr
<pdf::PDFWebContentsHelperClient
>(
82 new ChromePDFWebContentsHelperClient()));
84 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
88 AppViewGuestDelegate
* ChromeExtensionsAPIClient::CreateAppViewGuestDelegate()
90 return new ChromeAppViewGuestDelegate();
93 ExtensionOptionsGuestDelegate
*
94 ChromeExtensionsAPIClient::CreateExtensionOptionsGuestDelegate(
95 ExtensionOptionsGuest
* guest
) const {
96 return new ChromeExtensionOptionsGuestDelegate(guest
);
99 scoped_ptr
<MimeHandlerViewGuestDelegate
>
100 ChromeExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate(
101 MimeHandlerViewGuest
* guest
) const {
102 return make_scoped_ptr(new ChromeMimeHandlerViewGuestDelegate());
105 WebViewGuestDelegate
* ChromeExtensionsAPIClient::CreateWebViewGuestDelegate(
106 WebViewGuest
* web_view_guest
) const {
107 return new ChromeWebViewGuestDelegate(web_view_guest
);
110 WebViewPermissionHelperDelegate
* ChromeExtensionsAPIClient::
111 CreateWebViewPermissionHelperDelegate(
112 WebViewPermissionHelper
* web_view_permission_helper
) const {
113 return new ChromeWebViewPermissionHelperDelegate(web_view_permission_helper
);
116 WebRequestEventRouterDelegate
*
117 ChromeExtensionsAPIClient::CreateWebRequestEventRouterDelegate() const {
118 return new ChromeExtensionWebRequestEventRouterDelegate();
121 scoped_refptr
<ContentRulesRegistry
>
122 ChromeExtensionsAPIClient::CreateContentRulesRegistry(
123 content::BrowserContext
* browser_context
,
124 RulesCacheDelegate
* cache_delegate
) const {
125 return scoped_refptr
<ContentRulesRegistry
>(
126 new ChromeContentRulesRegistry(browser_context
, cache_delegate
));
129 scoped_ptr
<DevicePermissionsPrompt
>
130 ChromeExtensionsAPIClient::CreateDevicePermissionsPrompt(
131 content::WebContents
* web_contents
) const {
132 return make_scoped_ptr(new ChromeDevicePermissionsPrompt(web_contents
));
135 scoped_ptr
<VirtualKeyboardDelegate
>
136 ChromeExtensionsAPIClient::CreateVirtualKeyboardDelegate() const {
137 #if defined(OS_CHROMEOS)
138 return make_scoped_ptr(new ChromeVirtualKeyboardDelegate());
144 ManagementAPIDelegate
* ChromeExtensionsAPIClient::CreateManagementAPIDelegate()
146 return new ChromeManagementAPIDelegate
;
149 } // namespace extensions