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/extension_function_dispatcher.h"
11 #include "extensions/browser/guest_view/app_view/app_view_guest_delegate.h"
13 namespace extensions
{
17 // An AppViewGuest provides the browser-side implementation of <appview> API.
18 // AppViewGuest is created on attachment. That is, when a guest WebContents is
19 // associated with a particular embedder WebContents. This happens on calls to
21 class AppViewGuest
: public guest_view::GuestView
<AppViewGuest
>,
22 public ExtensionFunctionDispatcher::Delegate
{
24 static const char Type
[];
26 // Completes the creation of a WebContents associated with the provided
27 // |guest_extensions_id|.
28 static bool CompletePendingRequest(
29 content::BrowserContext
* browser_context
,
31 int guest_instance_id
,
32 const std::string
& guest_extension_id
);
34 static GuestViewBase
* Create(content::WebContents
* owner_web_contents
);
36 // ExtensionFunctionDispatcher::Delegate implementation.
37 WindowController
* GetExtensionWindowController() const override
;
38 content::WebContents
* GetAssociatedWebContents() const override
;
40 // content::WebContentsObserver implementation.
41 bool OnMessageReceived(const IPC::Message
& message
) override
;
43 // content::WebContentsDelegate implementation.
44 bool HandleContextMenu(const content::ContextMenuParams
& params
) override
;
45 void RequestMediaAccessPermission(
46 content::WebContents
* web_contents
,
47 const content::MediaStreamRequest
& request
,
48 const content::MediaResponseCallback
& callback
) override
;
49 bool CheckMediaAccessPermission(content::WebContents
* web_contents
,
50 const GURL
& security_origin
,
51 content::MediaStreamType type
) override
;
53 // GuestViewBase implementation.
54 bool CanRunInDetachedState() const override
;
55 void CreateWebContents(const base::DictionaryValue
& create_params
,
56 const WebContentsCreatedCallback
& callback
) override
;
57 void DidInitialize(const base::DictionaryValue
& create_params
) override
;
58 const char* GetAPINamespace() const override
;
59 int GetTaskPrefix() const override
;
61 // Sets the AppDelegate for this guest.
62 void SetAppDelegateForTest(AppDelegate
* delegate
);
65 explicit AppViewGuest(content::WebContents
* owner_web_contents
);
67 ~AppViewGuest() override
;
69 void OnRequest(const ExtensionHostMsg_Request_Params
& params
);
71 void CompleteCreateWebContents(const GURL
& url
,
72 const Extension
* guest_extension
,
73 const WebContentsCreatedCallback
& callback
);
75 void LaunchAppAndFireEvent(scoped_ptr
<base::DictionaryValue
> data
,
76 const WebContentsCreatedCallback
& callback
,
77 ExtensionHost
* extension_host
);
80 std::string guest_extension_id_
;
81 scoped_ptr
<ExtensionFunctionDispatcher
> extension_function_dispatcher_
;
82 scoped_ptr
<AppViewGuestDelegate
> app_view_guest_delegate_
;
83 scoped_ptr
<AppDelegate
> app_delegate_
;
85 // This is used to ensure pending tasks will not fire after this object is
87 base::WeakPtrFactory
<AppViewGuest
> weak_ptr_factory_
;
89 DISALLOW_COPY_AND_ASSIGN(AppViewGuest
);
92 } // namespace extensions
94 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_