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_GUEST_VIEW_BASE_H_ | 5 #ifndef CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 scoped_ptr<base::DictionaryValue> GetArguments(); | 32 scoped_ptr<base::DictionaryValue> GetArguments(); |
33 | 33 |
34 private: | 34 private: |
35 const std::string name_; | 35 const std::string name_; |
36 scoped_ptr<base::DictionaryValue> args_; | 36 scoped_ptr<base::DictionaryValue> args_; |
37 }; | 37 }; |
38 | 38 |
39 // Returns a *ViewGuest if this GuestView is of the given view type. | 39 // Returns a *ViewGuest if this GuestView is of the given view type. |
40 template <typename T> | 40 template <typename T> |
41 T* As() { | 41 T* As() { |
42 if (!strcmp(GetViewType(), T::Type)) { | 42 if (IsViewType(T::Type)) |
43 return static_cast<T*>(this); | 43 return static_cast<T*>(this); |
44 } | 44 |
45 return NULL; | 45 return NULL; |
46 } | 46 } |
47 | 47 |
48 static GuestViewBase* Create(content::WebContents* guest_web_contents, | 48 static GuestViewBase* Create(content::WebContents* guest_web_contents, |
49 const std::string& embedder_extension_id, | 49 const std::string& embedder_extension_id, |
50 const std::string& view_type); | 50 const std::string& view_type, |
| 51 const base::WeakPtr<GuestViewBase>& opener); |
51 | 52 |
52 static GuestViewBase* FromWebContents(content::WebContents* web_contents); | 53 static GuestViewBase* FromWebContents(content::WebContents* web_contents); |
53 | 54 |
54 static GuestViewBase* From(int embedder_process_id, int instance_id); | 55 static GuestViewBase* From(int embedder_process_id, int instance_id); |
55 | 56 |
56 // For GuestViewBases, we create special guest processes, which host the | 57 // For GuestViewBases, we create special guest processes, which host the |
57 // tag content separately from the main application that embeds the tag. | 58 // tag content separately from the main application that embeds the tag. |
58 // A GuestViewBase can specify both the partition name and whether the storage | 59 // A GuestViewBase can specify both the partition name and whether the storage |
59 // for that partition should be persisted. Each tag gets a SiteInstance with | 60 // for that partition should be persisted. Each tag gets a SiteInstance with |
60 // a specially formatted URL, based on the application it is hosted by and | 61 // a specially formatted URL, based on the application it is hosted by and |
61 // the partition requested by it. The format for that URL is: | 62 // the partition requested by it. The format for that URL is: |
62 // chrome-guest://partition_domain/persist?partition_name | 63 // chrome-guest://partition_domain/persist?partition_name |
63 static bool GetGuestPartitionConfigForSite(const GURL& site, | 64 static bool GetGuestPartitionConfigForSite(const GURL& site, |
64 std::string* partition_domain, | 65 std::string* partition_domain, |
65 std::string* partition_name, | 66 std::string* partition_name, |
66 bool* in_memory); | 67 bool* in_memory); |
67 | 68 |
68 // By default, JavaScript and images are enabled in guest content. | 69 // By default, JavaScript and images are enabled in guest content. |
69 static void GetDefaultContentSettingRules(RendererContentSettingRules* rules, | 70 static void GetDefaultContentSettingRules(RendererContentSettingRules* rules, |
70 bool incognito); | 71 bool incognito); |
71 | 72 |
72 virtual const char* GetViewType() const = 0; | 73 virtual const char* GetViewType() const = 0; |
73 | 74 |
| 75 bool IsViewType(const char* const view_type) const { |
| 76 return !strcmp(GetViewType(), view_type); |
| 77 } |
| 78 |
| 79 base::WeakPtr<GuestViewBase> AsWeakPtr(); |
| 80 |
74 virtual void Attach(content::WebContents* embedder_web_contents, | 81 virtual void Attach(content::WebContents* embedder_web_contents, |
75 const base::DictionaryValue& args); | 82 const base::DictionaryValue& args); |
76 | 83 |
77 content::WebContents* embedder_web_contents() const { | 84 content::WebContents* embedder_web_contents() const { |
78 return embedder_web_contents_; | 85 return embedder_web_contents_; |
79 } | 86 } |
80 | 87 |
81 // Returns the guest WebContents. | 88 // Returns the guest WebContents. |
82 content::WebContents* guest_web_contents() const { | 89 content::WebContents* guest_web_contents() const { |
83 return guest_web_contents_; | 90 return guest_web_contents_; |
(...skipping 15 matching lines...) Expand all Loading... |
99 | 106 |
100 // Returns whether this GuestView is embedded in an extension/app. | 107 // Returns whether this GuestView is embedded in an extension/app. |
101 bool in_extension() const { return !embedder_extension_id_.empty(); } | 108 bool in_extension() const { return !embedder_extension_id_.empty(); } |
102 | 109 |
103 // Returns the user browser context of the embedder. | 110 // Returns the user browser context of the embedder. |
104 content::BrowserContext* browser_context() const { return browser_context_; } | 111 content::BrowserContext* browser_context() const { return browser_context_; } |
105 | 112 |
106 // Returns the embedder's process ID. | 113 // Returns the embedder's process ID. |
107 int embedder_render_process_id() const { return embedder_render_process_id_; } | 114 int embedder_render_process_id() const { return embedder_render_process_id_; } |
108 | 115 |
| 116 // BrowserPluginGuestDelegate implementation. |
| 117 virtual content::WebContents* GetOpener() const OVERRIDE; |
| 118 virtual void SetOpener(content::WebContents* opener) OVERRIDE; |
| 119 |
109 protected: | 120 protected: |
110 GuestViewBase(content::WebContents* guest_web_contents, | 121 GuestViewBase(content::WebContents* guest_web_contents, |
111 const std::string& embedder_extension_id); | 122 const std::string& embedder_extension_id, |
| 123 const base::WeakPtr<GuestViewBase>& opener); |
112 virtual ~GuestViewBase(); | 124 virtual ~GuestViewBase(); |
113 | 125 |
114 // Dispatches an event |event_name| to the embedder with the |event| fields. | 126 // Dispatches an event |event_name| to the embedder with the |event| fields. |
115 void DispatchEvent(Event* event); | 127 void DispatchEvent(Event* event); |
116 | 128 |
117 private: | 129 private: |
118 void SendQueuedEvents(); | 130 void SendQueuedEvents(); |
119 | 131 |
120 content::WebContents* const guest_web_contents_; | 132 content::WebContents* const guest_web_contents_; |
121 content::WebContents* embedder_web_contents_; | 133 content::WebContents* embedder_web_contents_; |
122 const std::string embedder_extension_id_; | 134 const std::string embedder_extension_id_; |
123 int embedder_render_process_id_; | 135 int embedder_render_process_id_; |
124 content::BrowserContext* const browser_context_; | 136 content::BrowserContext* const browser_context_; |
125 // |guest_instance_id_| is a profile-wide unique identifier for a guest | 137 // |guest_instance_id_| is a profile-wide unique identifier for a guest |
126 // WebContents. | 138 // WebContents. |
127 const int guest_instance_id_; | 139 const int guest_instance_id_; |
128 // |view_instance_id_| is an identifier that's unique within a particular | 140 // |view_instance_id_| is an identifier that's unique within a particular |
129 // embedder RenderViewHost for a particular <*view> instance. | 141 // embedder RenderViewHost for a particular <*view> instance. |
130 int view_instance_id_; | 142 int view_instance_id_; |
131 | 143 |
132 // This is a queue of Events that are destined to be sent to the embedder once | 144 // This is a queue of Events that are destined to be sent to the embedder once |
133 // the guest is attached to a particular embedder. | 145 // the guest is attached to a particular embedder. |
134 std::deque<linked_ptr<Event> > pending_events_; | 146 std::deque<linked_ptr<Event> > pending_events_; |
135 | 147 |
| 148 // The opener guest view. |
| 149 base::WeakPtr<GuestViewBase> opener_; |
| 150 |
136 // This is used to ensure pending tasks will not fire after this object is | 151 // This is used to ensure pending tasks will not fire after this object is |
137 // destroyed. | 152 // destroyed. |
138 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 153 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
139 | 154 |
140 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 155 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
141 }; | 156 }; |
142 | 157 |
143 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 158 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
OLD | NEW |