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"
8 #include "base/files/file_path.h"
9 #include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h"
10 #include "chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry.h"
11 #include "chrome/browser/extensions/api/declarative_content/default_content_predicate_evaluators.h"
12 #include "chrome/browser/extensions/api/management/chrome_management_api_delegate.h"
13 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h"
14 #include "chrome/browser/extensions/api/web_request/chrome_extension_web_request_event_router_delegate.h"
15 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
16 #include "chrome/browser/favicon/favicon_utils.h"
17 #include "chrome/browser/guest_view/app_view/chrome_app_view_guest_delegate.h"
18 #include "chrome/browser/guest_view/chrome_guest_view_manager_delegate.h"
19 #include "chrome/browser/guest_view/extension_options/chrome_extension_options_guest_delegate.h"
20 #include "chrome/browser/guest_view/mime_handler_view/chrome_mime_handler_view_guest_delegate.h"
21 #include "chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.h"
22 #include "chrome/browser/guest_view/web_view/chrome_web_view_permission_helper_delegate.h"
23 #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h"
24 #include "components/pdf/browser/pdf_web_contents_helper.h"
25 #include "content/public/browser/browser_context.h"
26 #include "content/public/browser/browser_thread.h"
27 #include "extensions/browser/api/virtual_keyboard_private/virtual_keyboard_delegate.h"
28 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
29 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
31 #if defined(ENABLE_CONFIGURATION_POLICY)
32 #include "chrome/browser/extensions/api/storage/managed_value_store_cache.h"
35 #if defined(OS_CHROMEOS)
36 #include "chrome/browser/extensions/api/virtual_keyboard_private/chrome_virtual_keyboard_delegate.h"
39 #if defined(ENABLE_PRINTING)
40 #if defined(ENABLE_PRINT_PREVIEW)
41 #include "chrome/browser/printing/print_preview_message_handler.h"
42 #include "chrome/browser/printing/print_view_manager.h"
44 #include "chrome/browser/printing/print_view_manager_basic.h"
45 #endif // defined(ENABLE_PRINT_PREVIEW)
46 #endif // defined(ENABLE_PRINTING)
48 namespace extensions
{
50 ChromeExtensionsAPIClient::ChromeExtensionsAPIClient() {}
52 ChromeExtensionsAPIClient::~ChromeExtensionsAPIClient() {}
54 void ChromeExtensionsAPIClient::AddAdditionalValueStoreCaches(
55 content::BrowserContext
* context
,
56 const scoped_refptr
<SettingsStorageFactory
>& factory
,
57 const scoped_refptr
<base::ObserverListThreadSafe
<SettingsObserver
>>&
59 std::map
<settings_namespace::Namespace
, ValueStoreCache
*>* caches
) {
60 // Add support for chrome.storage.sync.
61 (*caches
)[settings_namespace::SYNC
] =
62 new SyncValueStoreCache(factory
, observers
, context
->GetPath());
64 #if defined(ENABLE_CONFIGURATION_POLICY)
65 // Add support for chrome.storage.managed.
66 (*caches
)[settings_namespace::MANAGED
] =
67 new ManagedValueStoreCache(context
, factory
, observers
);
71 void ChromeExtensionsAPIClient::AttachWebContentsHelpers(
72 content::WebContents
* web_contents
) const {
73 favicon::CreateContentFaviconDriverForWebContents(web_contents
);
74 #if defined(ENABLE_PRINTING)
75 #if defined(ENABLE_PRINT_PREVIEW)
76 printing::PrintViewManager::CreateForWebContents(web_contents
);
77 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents
);
79 printing::PrintViewManagerBasic::CreateForWebContents(web_contents
);
80 #endif // defined(ENABLE_PRINT_PREVIEW)
81 #endif // defined(ENABLE_PRINTING)
82 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
84 scoped_ptr
<pdf::PDFWebContentsHelperClient
>(
85 new ChromePDFWebContentsHelperClient()));
87 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
91 AppViewGuestDelegate
* ChromeExtensionsAPIClient::CreateAppViewGuestDelegate()
93 return new ChromeAppViewGuestDelegate();
96 ExtensionOptionsGuestDelegate
*
97 ChromeExtensionsAPIClient::CreateExtensionOptionsGuestDelegate(
98 ExtensionOptionsGuest
* guest
) const {
99 return new ChromeExtensionOptionsGuestDelegate(guest
);
102 scoped_ptr
<guest_view::GuestViewManagerDelegate
>
103 ChromeExtensionsAPIClient::CreateGuestViewManagerDelegate(
104 content::BrowserContext
* context
) const {
105 return make_scoped_ptr(new ChromeGuestViewManagerDelegate(context
));
108 scoped_ptr
<MimeHandlerViewGuestDelegate
>
109 ChromeExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate(
110 MimeHandlerViewGuest
* guest
) const {
111 return make_scoped_ptr(new ChromeMimeHandlerViewGuestDelegate());
114 WebViewGuestDelegate
* ChromeExtensionsAPIClient::CreateWebViewGuestDelegate(
115 WebViewGuest
* web_view_guest
) const {
116 return new ChromeWebViewGuestDelegate(web_view_guest
);
119 WebViewPermissionHelperDelegate
* ChromeExtensionsAPIClient::
120 CreateWebViewPermissionHelperDelegate(
121 WebViewPermissionHelper
* web_view_permission_helper
) const {
122 return new ChromeWebViewPermissionHelperDelegate(web_view_permission_helper
);
125 WebRequestEventRouterDelegate
*
126 ChromeExtensionsAPIClient::CreateWebRequestEventRouterDelegate() const {
127 return new ChromeExtensionWebRequestEventRouterDelegate();
130 scoped_refptr
<ContentRulesRegistry
>
131 ChromeExtensionsAPIClient::CreateContentRulesRegistry(
132 content::BrowserContext
* browser_context
,
133 RulesCacheDelegate
* cache_delegate
) const {
134 return scoped_refptr
<ContentRulesRegistry
>(
135 new ChromeContentRulesRegistry(
138 base::Bind(&CreateDefaultContentPredicateEvaluators
,
139 base::Unretained(browser_context
))));
142 scoped_ptr
<DevicePermissionsPrompt
>
143 ChromeExtensionsAPIClient::CreateDevicePermissionsPrompt(
144 content::WebContents
* web_contents
) const {
145 return make_scoped_ptr(new ChromeDevicePermissionsPrompt(web_contents
));
148 scoped_ptr
<VirtualKeyboardDelegate
>
149 ChromeExtensionsAPIClient::CreateVirtualKeyboardDelegate() const {
150 #if defined(OS_CHROMEOS)
151 return make_scoped_ptr(new ChromeVirtualKeyboardDelegate());
157 ManagementAPIDelegate
* ChromeExtensionsAPIClient::CreateManagementAPIDelegate()
159 return new ChromeManagementAPIDelegate
;
162 } // namespace extensions