[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 1 | // Copyright 2013 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 CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_ |
| 6 | #define CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_ |
| 7 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 8 | #include <queue> |
| 9 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 10 | #include "base/values.h" |
[email protected] | 4c0e827 | 2013-07-03 23:39:22 | [diff] [blame] | 11 | #include "content/public/browser/browser_plugin_guest_delegate.h" |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 12 | #include "content/public/browser/web_contents.h" |
| 13 | |
| 14 | class AdViewGuest; |
| 15 | class WebViewGuest; |
[email protected] | 06153f0 | 2013-12-04 03:01:28 | [diff] [blame] | 16 | struct RendererContentSettingRules; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 17 | |
| 18 | // A GuestView is the base class browser-side API implementation for a <*view> |
| 19 | // tag. GuestView maintains an association between a guest WebContents and an |
| 20 | // embedder WebContents. It receives events issued from the guest and relays |
| 21 | // them to the embedder. |
[email protected] | 4c0e827 | 2013-07-03 23:39:22 | [diff] [blame] | 22 | class GuestView : public content::BrowserPluginGuestDelegate { |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 23 | public: |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 24 | enum Type { |
| 25 | WEBVIEW, |
| 26 | ADVIEW, |
| 27 | UNKNOWN |
| 28 | }; |
| 29 | |
| 30 | class Event { |
| 31 | public: |
[email protected] | 0aad647 | 2013-12-04 18:25:38 | [diff] [blame^] | 32 | Event(const std::string& name, scoped_ptr<DictionaryValue> args); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 33 | ~Event(); |
| 34 | |
[email protected] | 0aad647 | 2013-12-04 18:25:38 | [diff] [blame^] | 35 | const std::string& name() const { return name_; } |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 36 | |
| 37 | scoped_ptr<DictionaryValue> GetArguments(); |
| 38 | |
| 39 | private: |
[email protected] | 0aad647 | 2013-12-04 18:25:38 | [diff] [blame^] | 40 | const std::string name_; |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 41 | scoped_ptr<DictionaryValue> args_; |
| 42 | }; |
| 43 | |
[email protected] | 50c827d | 2013-09-13 21:36:09 | [diff] [blame] | 44 | static Type GetViewTypeFromString(const std::string& api_type); |
| 45 | |
| 46 | static GuestView* Create(content::WebContents* guest_web_contents, |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 47 | const std::string& extension_id, |
[email protected] | 50c827d | 2013-09-13 21:36:09 | [diff] [blame] | 48 | Type view_type); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 49 | |
| 50 | static GuestView* FromWebContents(content::WebContents* web_contents); |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 51 | |
| 52 | static GuestView* From(int embedder_process_id, int instance_id); |
| 53 | |
[email protected] | 3f24f97c | 2013-11-17 21:53:33 | [diff] [blame] | 54 | // For GuestViews, we create special guest processes, which host the |
| 55 | // tag content separately from the main application that embeds the tag. |
| 56 | // A GuestView can specify both the partition name and whether the storage |
| 57 | // for that partition should be persisted. Each tag gets a SiteInstance with |
| 58 | // a specially formatted URL, based on the application it is hosted by and |
| 59 | // the partition requested by it. The format for that URL is: |
| 60 | // chrome-guest://partition_domain/persist?partition_name |
| 61 | static bool GetGuestPartitionConfigForSite(const GURL& site, |
| 62 | std::string* partition_domain, |
| 63 | std::string* partition_name, |
| 64 | bool* in_memory); |
| 65 | |
[email protected] | 06153f0 | 2013-12-04 03:01:28 | [diff] [blame] | 66 | // By default, JavaScript and images are enabled in guest content. |
| 67 | static void GetDefaultContentSettingRules( |
| 68 | RendererContentSettingRules* rules, bool incognito); |
| 69 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 70 | virtual void Attach(content::WebContents* embedder_web_contents, |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 71 | const base::DictionaryValue& args); |
| 72 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 73 | content::WebContents* embedder_web_contents() const { |
| 74 | return embedder_web_contents_; |
| 75 | } |
| 76 | |
| 77 | // Returns the guest WebContents. |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 78 | content::WebContents* guest_web_contents() const { |
| 79 | return guest_web_contents_; |
| 80 | } |
| 81 | |
| 82 | virtual Type GetViewType() const; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 83 | |
| 84 | // Returns a WebViewGuest if this GuestView belongs to a <webview>. |
| 85 | virtual WebViewGuest* AsWebView() = 0; |
| 86 | |
| 87 | // Returns an AdViewGuest if the GuestView belongs to an <adview>. |
| 88 | virtual AdViewGuest* AsAdView() = 0; |
| 89 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 90 | // Returns whether this guest has an associated embedder. |
| 91 | bool attached() const { return !!embedder_web_contents_; } |
| 92 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 93 | // Returns the instance ID of the <*view> element. |
| 94 | int view_instance_id() const { return view_instance_id_; } |
| 95 | |
| 96 | // Returns the instance ID of the guest WebContents. |
| 97 | int guest_instance_id() const { return guest_instance_id_; } |
| 98 | |
| 99 | // Returns the extension ID of the embedder. |
| 100 | const std::string& extension_id() const { return extension_id_; } |
| 101 | |
| 102 | // Returns the user browser context of the embedder. |
| 103 | content::BrowserContext* browser_context() const { return browser_context_; } |
| 104 | |
| 105 | // Returns the embedder's process ID. |
| 106 | int embedder_render_process_id() const { return embedder_render_process_id_; } |
| 107 | |
| 108 | protected: |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 109 | GuestView(content::WebContents* guest_web_contents, |
| 110 | const std::string& extension_id); |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 111 | virtual ~GuestView(); |
| 112 | |
| 113 | // Dispatches an event |event_name| to the embedder with the |event| fields. |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 114 | void DispatchEvent(Event* event); |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 115 | |
| 116 | private: |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 117 | void SendQueuedEvents(); |
| 118 | |
[email protected] | 70e7c0e | 2013-11-08 00:33:21 | [diff] [blame] | 119 | content::WebContents* const guest_web_contents_; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 120 | content::WebContents* embedder_web_contents_; |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 121 | const std::string extension_id_; |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 122 | int embedder_render_process_id_; |
[email protected] | 70e7c0e | 2013-11-08 00:33:21 | [diff] [blame] | 123 | content::BrowserContext* const browser_context_; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 124 | // |guest_instance_id_| is a profile-wide unique identifier for a guest |
| 125 | // WebContents. |
| 126 | const int guest_instance_id_; |
| 127 | // |view_instance_id_| is an identifier that's unique within a particular |
| 128 | // embedder RenderViewHost for a particular <*view> instance. |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 129 | int view_instance_id_; |
| 130 | |
| 131 | // This is a queue of Events that are destined to be sent to the embedder once |
| 132 | // the guest is attached to a particular embedder. |
| 133 | std::queue<Event*> pending_events_; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 134 | |
| 135 | DISALLOW_COPY_AND_ASSIGN(GuestView); |
| 136 | }; |
| 137 | |
| 138 | #endif // CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_ |