• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 the Chromium Embedded Framework Authors. Portions copyright
2 // 2013 The Chromium Authors. All rights reserved. Use of this source code is
3 // governed by a BSD-style license that can be found in the LICENSE file.
4 
5 #include "libcef/browser/extensions/extension_background_host.h"
6 
7 #include "libcef/browser/alloy/alloy_browser_host_impl.h"
8 #include "libcef/browser/extensions/extension_host_delegate.h"
9 
10 #include "base/callback.h"
11 
12 namespace extensions {
13 
CefExtensionBackgroundHost(AlloyBrowserHostImpl * browser,base::OnceClosure deleted_callback,const Extension * extension,content::WebContents * host_contents,const GURL & url,mojom::ViewType host_type)14 CefExtensionBackgroundHost::CefExtensionBackgroundHost(
15     AlloyBrowserHostImpl* browser,
16     base::OnceClosure deleted_callback,
17     const Extension* extension,
18     content::WebContents* host_contents,
19     const GURL& url,
20     mojom::ViewType host_type)
21     : ExtensionHost(new CefExtensionHostDelegate(browser),
22                     extension,
23                     host_contents->GetBrowserContext(),
24                     host_contents,
25                     url,
26                     host_type),
27       deleted_callback_(std::move(deleted_callback)) {
28   DCHECK(!deleted_callback_.is_null());
29 
30   // Only used for background pages.
31   DCHECK(host_type == mojom::ViewType::kExtensionBackgroundPage);
32 }
33 
~CefExtensionBackgroundHost()34 CefExtensionBackgroundHost::~CefExtensionBackgroundHost() {
35   std::move(deleted_callback_).Run();
36 }
37 
38 bool CefExtensionBackgroundHost::
ShouldAllowRendererInitiatedCrossProcessNavigation(bool is_main_frame_navigation)39     ShouldAllowRendererInitiatedCrossProcessNavigation(
40         bool is_main_frame_navigation) {
41   // Block navigations that cause the main frame to navigate to non-extension
42   // content (i.e. to web content).
43   return !is_main_frame_navigation;
44 }
45 
46 }  // namespace extensions
47