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_extension_id| and |guest_instance_id| for the given
27 // |guest_render_process_host| is the RenderProcessHost and |url| is the
28 // resource GURL of the extension instance making this request. If there is
29 // any mismatch between the expected |guest_instance_id| and
30 // |guest_extension_id| provided and the recorded copies from when the the
31 // <appview> was created, the RenderProcessHost of the extension instance
32 // behind this request will be killed.
33 static bool CompletePendingRequest(
34 content::BrowserContext
* browser_context
,
36 int guest_instance_id
,
37 const std::string
& guest_extension_id
,
38 content::RenderProcessHost
* guest_render_process_host
);
40 static GuestViewBase
* Create(content::WebContents
* owner_web_contents
);
42 static std::vector
<int> GetAllRegisteredInstanceIdsForTesting();
44 // content::WebContentsDelegate implementation.
45 bool HandleContextMenu(const content::ContextMenuParams
& params
) override
;
46 void RequestMediaAccessPermission(
47 content::WebContents
* web_contents
,
48 const content::MediaStreamRequest
& request
,
49 const content::MediaResponseCallback
& callback
) override
;
50 bool CheckMediaAccessPermission(content::WebContents
* web_contents
,
51 const GURL
& security_origin
,
52 content::MediaStreamType type
) override
;
54 // GuestViewBase implementation.
55 bool CanRunInDetachedState() const override
;
56 void CreateWebContents(const base::DictionaryValue
& create_params
,
57 const WebContentsCreatedCallback
& callback
) override
;
58 void DidInitialize(const base::DictionaryValue
& create_params
) override
;
59 const char* GetAPINamespace() const override
;
60 int GetTaskPrefix() const override
;
62 // Sets the AppDelegate for this guest.
63 void SetAppDelegateForTest(AppDelegate
* delegate
);
66 explicit AppViewGuest(content::WebContents
* owner_web_contents
);
68 ~AppViewGuest() override
;
70 void CompleteCreateWebContents(const GURL
& url
,
71 const Extension
* guest_extension
,
72 const WebContentsCreatedCallback
& callback
);
74 void LaunchAppAndFireEvent(scoped_ptr
<base::DictionaryValue
> data
,
75 const WebContentsCreatedCallback
& callback
,
76 ExtensionHost
* extension_host
);
79 std::string guest_extension_id_
;
80 scoped_ptr
<AppViewGuestDelegate
> app_view_guest_delegate_
;
81 scoped_ptr
<AppDelegate
> app_delegate_
;
83 // This is used to ensure pending tasks will not fire after this object is
85 base::WeakPtrFactory
<AppViewGuest
> weak_ptr_factory_
;
87 DISALLOW_COPY_AND_ASSIGN(AppViewGuest
);
90 } // namespace extensions
92 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_