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 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_
6 #define EXTENSIONS_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_
8 #include "base/id_map.h"
9 #include "components/guest_view/browser/guest_view.h"
10 #include "extensions/browser/guest_view/app_view/app_view_guest_delegate.h"
12 namespace extensions
{
16 // An AppViewGuest provides the browser-side implementation of <appview> API.
17 // AppViewGuest is created on attachment. That is, when a guest WebContents is
18 // associated with a particular embedder WebContents. This happens on calls to
20 class AppViewGuest
: public guest_view::GuestView
<AppViewGuest
> {
22 static const char Type
[];
24 // Completes the creation of a WebContents associated with the provided
25 // |guest_extensions_id|.
26 static bool CompletePendingRequest(
27 content::BrowserContext
* browser_context
,
29 int guest_instance_id
,
30 const std::string
& guest_extension_id
);
32 static GuestViewBase
* Create(content::WebContents
* owner_web_contents
);
34 // content::WebContentsDelegate implementation.
35 bool HandleContextMenu(const content::ContextMenuParams
& params
) override
;
36 void RequestMediaAccessPermission(
37 content::WebContents
* web_contents
,
38 const content::MediaStreamRequest
& request
,
39 const content::MediaResponseCallback
& callback
) override
;
40 bool CheckMediaAccessPermission(content::WebContents
* web_contents
,
41 const GURL
& security_origin
,
42 content::MediaStreamType type
) override
;
44 // GuestViewBase implementation.
45 bool CanRunInDetachedState() const override
;
46 void CreateWebContents(const base::DictionaryValue
& create_params
,
47 const WebContentsCreatedCallback
& callback
) override
;
48 void DidInitialize(const base::DictionaryValue
& create_params
) override
;
49 const char* GetAPINamespace() const override
;
50 int GetTaskPrefix() const override
;
52 // Sets the AppDelegate for this guest.
53 void SetAppDelegateForTest(AppDelegate
* delegate
);
56 explicit AppViewGuest(content::WebContents
* owner_web_contents
);
58 ~AppViewGuest() override
;
60 void CompleteCreateWebContents(const GURL
& url
,
61 const Extension
* guest_extension
,
62 const WebContentsCreatedCallback
& callback
);
64 void LaunchAppAndFireEvent(scoped_ptr
<base::DictionaryValue
> data
,
65 const WebContentsCreatedCallback
& callback
,
66 ExtensionHost
* extension_host
);
69 std::string guest_extension_id_
;
70 scoped_ptr
<AppViewGuestDelegate
> app_view_guest_delegate_
;
71 scoped_ptr
<AppDelegate
> app_delegate_
;
73 // This is used to ensure pending tasks will not fire after this object is
75 base::WeakPtrFactory
<AppViewGuest
> weak_ptr_factory_
;
77 DISALLOW_COPY_AND_ASSIGN(AppViewGuest
);
80 } // namespace extensions
82 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_