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