Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / browser / guest_view / app_view / app_view_guest.h
blobbfe84fdba9211a618b7ed1bf7ab7f764566a96af
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 "extensions/browser/extension_function_dispatcher.h"
10 #include "extensions/browser/guest_view/app_view/app_view_guest_delegate.h"
11 #include "extensions/browser/guest_view/guest_view.h"
13 namespace extensions {
14 class Extension;
15 class ExtensionHost;
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
20 // the connect API.
21 class AppViewGuest : public GuestView<AppViewGuest>,
22 public ExtensionFunctionDispatcher::Delegate {
23 public:
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,
30 const GURL& url,
31 int guest_instance_id,
32 const std::string& guest_extension_id);
34 static GuestViewBase* Create(content::BrowserContext* browser_context,
35 int guest_instance_id);
37 // ExtensionFunctionDispatcher::Delegate implementation.
38 virtual WindowController* GetExtensionWindowController() const OVERRIDE;
39 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
41 // content::WebContentsObserver implementation.
42 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
44 // content::WebContentsDelegate implementation.
45 virtual bool HandleContextMenu(
46 const content::ContextMenuParams& params) OVERRIDE;
48 // GuestViewBase implementation.
49 virtual const char* GetAPINamespace() const OVERRIDE;
50 virtual int GetTaskPrefix() const OVERRIDE;
51 virtual void CreateWebContents(
52 const std::string& embedder_extension_id,
53 int embedder_render_process_id,
54 const base::DictionaryValue& create_params,
55 const WebContentsCreatedCallback& callback) OVERRIDE;
56 virtual void DidAttachToEmbedder() OVERRIDE;
57 virtual void DidInitialize() OVERRIDE;
59 private:
60 AppViewGuest(content::BrowserContext* browser_context, int guest_instance_id);
62 virtual ~AppViewGuest();
64 void OnRequest(const ExtensionHostMsg_Request_Params& params);
66 void CompleteCreateWebContents(const GURL& url,
67 const Extension* guest_extension,
68 const WebContentsCreatedCallback& callback);
70 void LaunchAppAndFireEvent(scoped_ptr<base::DictionaryValue> data,
71 const WebContentsCreatedCallback& callback,
72 ExtensionHost* extension_host);
74 GURL url_;
75 std::string guest_extension_id_;
76 scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_;
77 scoped_ptr<AppViewGuestDelegate> app_view_guest_delegate_;
79 // This is used to ensure pending tasks will not fire after this object is
80 // destroyed.
81 base::WeakPtrFactory<AppViewGuest> weak_ptr_factory_;
83 DISALLOW_COPY_AND_ASSIGN(AppViewGuest);
86 } // namespace extensions
88 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_