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 29 matching lines...) Expand all Loading... | |
40 template <typename T> | 40 template <typename T> |
41 T* As() { | 41 T* As() { |
42 if (!strcmp(GetViewType(), T::Type)) { | 42 if (!strcmp(GetViewType(), 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 base::WeakPtr<GuestViewBase> AsWeakPtr(); | |
76 | |
74 virtual void Attach(content::WebContents* embedder_web_contents, | 77 virtual void Attach(content::WebContents* embedder_web_contents, |
75 const base::DictionaryValue& args); | 78 const base::DictionaryValue& args); |
76 | 79 |
77 content::WebContents* embedder_web_contents() const { | 80 content::WebContents* embedder_web_contents() const { |
78 return embedder_web_contents_; | 81 return embedder_web_contents_; |
79 } | 82 } |
80 | 83 |
81 // Returns the guest WebContents. | 84 // Returns the guest WebContents. |
82 content::WebContents* guest_web_contents() const { | 85 content::WebContents* guest_web_contents() const { |
83 return guest_web_contents_; | 86 return guest_web_contents_; |
(...skipping 15 matching lines...) Expand all Loading... | |
99 | 102 |
100 // Returns whether this GuestView is embedded in an extension/app. | 103 // Returns whether this GuestView is embedded in an extension/app. |
101 bool in_extension() const { return !embedder_extension_id_.empty(); } | 104 bool in_extension() const { return !embedder_extension_id_.empty(); } |
102 | 105 |
103 // Returns the user browser context of the embedder. | 106 // Returns the user browser context of the embedder. |
104 content::BrowserContext* browser_context() const { return browser_context_; } | 107 content::BrowserContext* browser_context() const { return browser_context_; } |
105 | 108 |
106 // Returns the embedder's process ID. | 109 // Returns the embedder's process ID. |
107 int embedder_render_process_id() const { return embedder_render_process_id_; } | 110 int embedder_render_process_id() const { return embedder_render_process_id_; } |
108 | 111 |
112 // BrowserPluginGuestDelegate implementation. | |
113 virtual content::WebContents* GetOpener() const OVERRIDE; | |
114 virtual void SetOpener(content::WebContents* opener) OVERRIDE; | |
115 | |
109 protected: | 116 protected: |
110 GuestViewBase(content::WebContents* guest_web_contents, | 117 GuestViewBase(content::WebContents* guest_web_contents, |
111 const std::string& embedder_extension_id); | 118 const std::string& embedder_extension_id, |
119 const base::WeakPtr<GuestViewBase>& opener); | |
112 virtual ~GuestViewBase(); | 120 virtual ~GuestViewBase(); |
113 | 121 |
114 // Dispatches an event |event_name| to the embedder with the |event| fields. | 122 // Dispatches an event |event_name| to the embedder with the |event| fields. |
115 void DispatchEvent(Event* event); | 123 void DispatchEvent(Event* event); |
116 | 124 |
117 private: | 125 private: |
118 void SendQueuedEvents(); | 126 void SendQueuedEvents(); |
119 | 127 |
120 content::WebContents* const guest_web_contents_; | 128 content::WebContents* const guest_web_contents_; |
121 content::WebContents* embedder_web_contents_; | 129 content::WebContents* embedder_web_contents_; |
122 const std::string embedder_extension_id_; | 130 const std::string embedder_extension_id_; |
123 int embedder_render_process_id_; | 131 int embedder_render_process_id_; |
124 content::BrowserContext* const browser_context_; | 132 content::BrowserContext* const browser_context_; |
125 // |guest_instance_id_| is a profile-wide unique identifier for a guest | 133 // |guest_instance_id_| is a profile-wide unique identifier for a guest |
126 // WebContents. | 134 // WebContents. |
127 const int guest_instance_id_; | 135 const int guest_instance_id_; |
128 // |view_instance_id_| is an identifier that's unique within a particular | 136 // |view_instance_id_| is an identifier that's unique within a particular |
129 // embedder RenderViewHost for a particular <*view> instance. | 137 // embedder RenderViewHost for a particular <*view> instance. |
130 int view_instance_id_; | 138 int view_instance_id_; |
131 | 139 |
132 // This is a queue of Events that are destined to be sent to the embedder once | 140 // 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. | 141 // the guest is attached to a particular embedder. |
134 std::deque<linked_ptr<Event> > pending_events_; | 142 std::deque<linked_ptr<Event> > pending_events_; |
135 | 143 |
144 // Returns a WeakPtr to this GuestView. | |
lazyboy
2014/05/01 20:06:59
1) this is a member so doc shouldn't start /w "ret
Fady Samuel
2014/05/01 21:05:28
Done.
| |
145 base::WeakPtr<GuestViewBase> opener_; | |
146 | |
136 // This is used to ensure pending tasks will not fire after this object is | 147 // This is used to ensure pending tasks will not fire after this object is |
137 // destroyed. | 148 // destroyed. |
138 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 149 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
139 | 150 |
140 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 151 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
141 }; | 152 }; |
142 | 153 |
143 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 154 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
OLD | NEW |