| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_ | 5 #ifndef CHROME_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_ |
| 6 #define CHROME_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_ | 6 #define CHROME_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_ |
| 7 | 7 |
| 8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
| 9 #include "chrome/browser/guest_view/guest_view.h" | 9 #include "chrome/browser/guest_view/guest_view.h" |
| 10 #include "extensions/browser/extension_function_dispatcher.h" | 10 #include "extensions/browser/extension_function_dispatcher.h" |
| 11 | 11 |
| 12 namespace extensions { | 12 namespace extensions { |
| 13 class Extension; | 13 class Extension; |
| 14 class ExtensionHost; | 14 class ExtensionHost; |
| 15 }; | 15 }; |
| 16 | 16 |
| 17 // An AppViewGuest provides the browser-side implementation of <appview> API. | 17 // An AppViewGuest provides the browser-side implementation of <appview> API. |
| 18 // AppViewGuest is created on attachment. That is, when a guest WEbContnets is | 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 | 19 // associated with a particular embedder WebContents. This happens on calls to |
| 20 // the connect API. | 20 // the connect API. |
| 21 class AppViewGuest : public GuestView<AppViewGuest>, | 21 class AppViewGuest : public GuestView<AppViewGuest>, |
| 22 public extensions::ExtensionFunctionDispatcher::Delegate { | 22 public extensions::ExtensionFunctionDispatcher::Delegate { |
| 23 public: | 23 public: |
| 24 static const char Type[]; | 24 static const char Type[]; |
| 25 | 25 |
| 26 // Completes the creation of a WebContents associated with the provided | 26 // Completes the creation of a WebContents associated with the provided |
| 27 // |guest_extensions_id|. | 27 // |guest_extensions_id|. |
| 28 static bool CompletePendingRequest( | 28 static bool CompletePendingRequest( |
| 29 content::BrowserContext* browser_context, | 29 content::BrowserContext* browser_context, |
| 30 const GURL& url, | 30 const GURL& url, |
| 31 int guest_instance_id, | 31 int guest_instance_id, |
| 32 const std::string& guest_extension_id); | 32 const std::string& guest_extension_id); |
| 33 | 33 |
| 34 AppViewGuest(content::BrowserContext* browser_context, | 34 static GuestViewBase* Create(content::BrowserContext* browser_context, |
| 35 int guest_instance_id); | 35 int guest_instance_id); |
| 36 | 36 |
| 37 // ExtensionFunctionDispatcher::Delegate implementation. | 37 // ExtensionFunctionDispatcher::Delegate implementation. |
| 38 virtual extensions::WindowController* GetExtensionWindowController() const | 38 virtual extensions::WindowController* GetExtensionWindowController() const |
| 39 OVERRIDE; | 39 OVERRIDE; |
| 40 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; | 40 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; |
| 41 | 41 |
| 42 // content::WebContentsObserver implementation. | 42 // content::WebContentsObserver implementation. |
| 43 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 43 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 44 | 44 |
| 45 // content::WebContentsDelegate implementation. | 45 // content::WebContentsDelegate implementation. |
| 46 virtual bool HandleContextMenu( | 46 virtual bool HandleContextMenu( |
| 47 const content::ContextMenuParams& params) OVERRIDE; | 47 const content::ContextMenuParams& params) OVERRIDE; |
| 48 | 48 |
| 49 // GuestViewBase implementation. | 49 // GuestViewBase implementation. |
| 50 virtual bool CanEmbedderUseGuestView( | 50 virtual bool CanEmbedderUseGuestView( |
| 51 const std::string& embedder_extension_id) OVERRIDE; | 51 const std::string& embedder_extension_id) OVERRIDE; |
| 52 virtual void CreateWebContents( | 52 virtual void CreateWebContents( |
| 53 const std::string& embedder_extension_id, | 53 const std::string& embedder_extension_id, |
| 54 int embedder_render_process_id, | 54 int embedder_render_process_id, |
| 55 const base::DictionaryValue& create_params, | 55 const base::DictionaryValue& create_params, |
| 56 const WebContentsCreatedCallback& callback) OVERRIDE; | 56 const WebContentsCreatedCallback& callback) OVERRIDE; |
| 57 virtual void DidAttachToEmbedder() OVERRIDE; | 57 virtual void DidAttachToEmbedder() OVERRIDE; |
| 58 virtual void DidInitialize() OVERRIDE; | 58 virtual void DidInitialize() OVERRIDE; |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 AppViewGuest(content::BrowserContext* browser_context, |
| 62 int guest_instance_id); |
| 63 |
| 61 virtual ~AppViewGuest(); | 64 virtual ~AppViewGuest(); |
| 62 | 65 |
| 63 void OnRequest(const ExtensionHostMsg_Request_Params& params); | 66 void OnRequest(const ExtensionHostMsg_Request_Params& params); |
| 64 | 67 |
| 65 void CompleteCreateWebContents(const GURL& url, | 68 void CompleteCreateWebContents(const GURL& url, |
| 66 const extensions::Extension* guest_extension, | 69 const extensions::Extension* guest_extension, |
| 67 const WebContentsCreatedCallback& callback); | 70 const WebContentsCreatedCallback& callback); |
| 68 | 71 |
| 69 void LaunchAppAndFireEvent(const WebContentsCreatedCallback& callback, | 72 void LaunchAppAndFireEvent(const WebContentsCreatedCallback& callback, |
| 70 extensions::ExtensionHost* extension_host); | 73 extensions::ExtensionHost* extension_host); |
| 71 | 74 |
| 72 GURL url_; | 75 GURL url_; |
| 73 std::string guest_extension_id_; | 76 std::string guest_extension_id_; |
| 74 scoped_ptr<extensions::ExtensionFunctionDispatcher> | 77 scoped_ptr<extensions::ExtensionFunctionDispatcher> |
| 75 extension_function_dispatcher_; | 78 extension_function_dispatcher_; |
| 76 | 79 |
| 77 // This is used to ensure pending tasks will not fire after this object is | 80 // This is used to ensure pending tasks will not fire after this object is |
| 78 // destroyed. | 81 // destroyed. |
| 79 base::WeakPtrFactory<AppViewGuest> weak_ptr_factory_; | 82 base::WeakPtrFactory<AppViewGuest> weak_ptr_factory_; |
| 80 | 83 |
| 81 DISALLOW_COPY_AND_ASSIGN(AppViewGuest); | 84 DISALLOW_COPY_AND_ASSIGN(AppViewGuest); |
| 82 }; | 85 }; |
| 83 | 86 |
| 84 #endif // CHROME_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_ | 87 #endif // CHROME_BROWSER_GUEST_VIEW_APP_VIEW_APP_VIEW_GUEST_H_ |
| OLD | NEW |