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. 4 5 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_ 6 #define EXTENSIONS_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_ 7 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" 12 13 namespace extensions { 14 class Extension; 15 class ExtensionHost; 16 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[]; 25 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); 33 34 static GuestViewBase* Create(content::BrowserContext* browser_context, 35 int guest_instance_id); 36 37 // ExtensionFunctionDispatcher::Delegate implementation. 38 virtual WindowController* GetExtensionWindowController() const OVERRIDE; 39 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; 40 41 // content::WebContentsObserver implementation. 42 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 43 44 // content::WebContentsDelegate implementation. 45 virtual bool HandleContextMenu( 46 const content::ContextMenuParams& params) OVERRIDE; 47 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 GURL& embedder_site_url, 55 const base::DictionaryValue& create_params, 56 const WebContentsCreatedCallback& callback) OVERRIDE; 57 virtual void DidAttachToEmbedder() OVERRIDE; 58 virtual void DidInitialize() OVERRIDE; 59 60 private: 61 AppViewGuest(content::BrowserContext* browser_context, int guest_instance_id); 62 63 virtual ~AppViewGuest(); 64 65 void OnRequest(const ExtensionHostMsg_Request_Params& params); 66 67 void CompleteCreateWebContents(const GURL& url, 68 const Extension* guest_extension, 69 const WebContentsCreatedCallback& callback); 70 71 void LaunchAppAndFireEvent(scoped_ptr<base::DictionaryValue> data, 72 const WebContentsCreatedCallback& callback, 73 ExtensionHost* extension_host); 74 75 GURL url_; 76 std::string guest_extension_id_; 77 scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; 78 scoped_ptr<AppViewGuestDelegate> app_view_guest_delegate_; 79 80 // This is used to ensure pending tasks will not fire after this object is 81 // destroyed. 82 base::WeakPtrFactory<AppViewGuest> weak_ptr_factory_; 83 84 DISALLOW_COPY_AND_ASSIGN(AppViewGuest); 85 }; 86 87 } // namespace extensions 88 89 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_ 90