Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / extensions / browser / guest_view / extensions_guest_view_manager_delegate.cc
blob854c6b289f657e328b059976af604503b4ed156a
1 // Copyright 2015 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 "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h"
7 #include "components/guest_view/browser/guest_view_base.h"
8 #include "components/guest_view/browser/guest_view_manager.h"
9 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/render_process_host.h"
11 #include "extensions/browser/event_router.h"
12 #include "extensions/browser/guest_view/app_view/app_view_guest.h"
13 #include "extensions/browser/guest_view/extension_options/extension_options_guest.h"
14 #include "extensions/browser/guest_view/extension_view/extension_view_guest.h"
15 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
16 #include "extensions/browser/guest_view/surface_worker/surface_worker_guest.h"
17 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
18 #include "extensions/browser/process_manager.h"
19 #include "extensions/browser/process_map.h"
20 #include "extensions/common/features/feature.h"
21 #include "extensions/common/features/feature_provider.h"
23 using guest_view::GuestViewBase;
24 using guest_view::GuestViewManager;
26 namespace extensions {
28 ExtensionsGuestViewManagerDelegate::ExtensionsGuestViewManagerDelegate(
29 content::BrowserContext* context)
30 : context_(context) {
33 ExtensionsGuestViewManagerDelegate::~ExtensionsGuestViewManagerDelegate() {
36 void ExtensionsGuestViewManagerDelegate::DispatchEvent(
37 const std::string& event_name,
38 scoped_ptr<base::DictionaryValue> args,
39 GuestViewBase* guest,
40 int instance_id) {
41 EventFilteringInfo info;
42 info.SetInstanceID(instance_id);
43 scoped_ptr<base::ListValue> event_args(new base::ListValue());
44 event_args->Append(args.release());
46 EventRouter::DispatchEvent(
47 guest->owner_web_contents(),
48 guest->browser_context(),
49 guest->owner_host(),
50 event_name,
51 event_args.Pass(),
52 EventRouter::USER_GESTURE_UNKNOWN,
53 info);
56 bool ExtensionsGuestViewManagerDelegate::IsGuestAvailableToContext(
57 GuestViewBase* guest) {
58 const Feature* feature =
59 FeatureProvider::GetAPIFeature(guest->GetAPINamespace());
60 CHECK(feature);
62 ProcessMap* process_map = ProcessMap::Get(context_);
63 CHECK(process_map);
65 const Extension* owner_extension = ProcessManager::Get(context_)->
66 GetExtensionForWebContents(guest->owner_web_contents());
68 // Ok for |owner_extension| to be nullptr, the embedder might be WebUI.
69 Feature::Availability availability = feature->IsAvailableToContext(
70 owner_extension,
71 process_map->GetMostLikelyContextType(
72 owner_extension,
73 guest->owner_web_contents()->GetRenderProcessHost()->GetID()),
74 guest->GetOwnerSiteURL());
76 return availability.is_available();
79 bool ExtensionsGuestViewManagerDelegate::IsOwnedByExtension(
80 GuestViewBase* guest) {
81 return !!ProcessManager::Get(context_)->
82 GetExtensionForWebContents(guest->owner_web_contents());
85 void ExtensionsGuestViewManagerDelegate::RegisterAdditionalGuestViewTypes() {
86 GuestViewManager* manager = GuestViewManager::FromBrowserContext(context_);
87 manager->RegisterGuestViewType<AppViewGuest>();
88 manager->RegisterGuestViewType<ExtensionOptionsGuest>();
89 manager->RegisterGuestViewType<ExtensionViewGuest>();
90 manager->RegisterGuestViewType<MimeHandlerViewGuest>();
91 manager->RegisterGuestViewType<SurfaceWorkerGuest>();
92 manager->RegisterGuestViewType<WebViewGuest>();
95 } // namespace extensions