Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / extensions / browser / guest_view / extensions_guest_view_manager_delegate.cc
blobc76988fb3082d58ccc703bc076286161417e524e
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/api/extensions_api_client.h"
12 #include "extensions/browser/event_router.h"
13 #include "extensions/browser/guest_view/app_view/app_view_guest.h"
14 #include "extensions/browser/guest_view/extension_options/extension_options_guest.h"
15 #include "extensions/browser/guest_view/extension_view/extension_view_guest.h"
16 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
17 #include "extensions/browser/guest_view/surface_worker/surface_worker_guest.h"
18 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
19 #include "extensions/browser/process_manager.h"
20 #include "extensions/browser/process_map.h"
21 #include "extensions/common/features/feature.h"
22 #include "extensions/common/features/feature_provider.h"
24 using guest_view::GuestViewBase;
25 using guest_view::GuestViewManager;
27 namespace extensions {
29 ExtensionsGuestViewManagerDelegate::ExtensionsGuestViewManagerDelegate(
30 content::BrowserContext* context)
31 : context_(context) {
34 ExtensionsGuestViewManagerDelegate::~ExtensionsGuestViewManagerDelegate() {
37 void ExtensionsGuestViewManagerDelegate::DispatchEvent(
38 const std::string& event_name,
39 scoped_ptr<base::DictionaryValue> args,
40 GuestViewBase* guest,
41 int instance_id) {
42 EventFilteringInfo info;
43 info.SetInstanceID(instance_id);
44 scoped_ptr<base::ListValue> event_args(new base::ListValue());
45 event_args->Append(args.release());
47 EventRouter::DispatchEvent(
48 guest->owner_web_contents(),
49 guest->browser_context(),
50 guest->owner_host(),
51 event_name,
52 event_args.Pass(),
53 EventRouter::USER_GESTURE_UNKNOWN,
54 info);
57 bool ExtensionsGuestViewManagerDelegate::IsGuestAvailableToContext(
58 GuestViewBase* guest) {
59 const Feature* feature =
60 FeatureProvider::GetAPIFeature(guest->GetAPINamespace());
61 CHECK(feature);
63 ProcessMap* process_map = ProcessMap::Get(context_);
64 CHECK(process_map);
66 const Extension* owner_extension = ProcessManager::Get(context_)->
67 GetExtensionForWebContents(guest->owner_web_contents());
69 // Ok for |owner_extension| to be nullptr, the embedder might be WebUI.
70 Feature::Availability availability = feature->IsAvailableToContext(
71 owner_extension,
72 process_map->GetMostLikelyContextType(
73 owner_extension,
74 guest->owner_web_contents()->GetRenderProcessHost()->GetID()),
75 guest->GetOwnerSiteURL());
77 return availability.is_available();
80 bool ExtensionsGuestViewManagerDelegate::IsOwnedByExtension(
81 GuestViewBase* guest) {
82 return !!ProcessManager::Get(context_)->
83 GetExtensionForWebContents(guest->owner_web_contents());
86 void ExtensionsGuestViewManagerDelegate::RegisterAdditionalGuestViewTypes() {
87 GuestViewManager* manager = GuestViewManager::FromBrowserContext(context_);
88 manager->RegisterGuestViewType<AppViewGuest>();
89 manager->RegisterGuestViewType<ExtensionOptionsGuest>();
90 manager->RegisterGuestViewType<ExtensionViewGuest>();
91 manager->RegisterGuestViewType<MimeHandlerViewGuest>();
92 manager->RegisterGuestViewType<SurfaceWorkerGuest>();
93 manager->RegisterGuestViewType<WebViewGuest>();
96 } // namespace extensions