OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_EXTENSIONS_API_TAB_CAPTURE_OFFSCREEN_PRESENTATION_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_OFFSCREEN_PRESENTATION_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_OFFSCREEN_PRESENTATION_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_OFFSCREEN_PRESENTATION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
14 #include "content/public/browser/web_contents_delegate.h" | 14 #include "content/public/browser/web_contents_delegate.h" |
15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
16 #include "content/public/browser/web_contents_user_data.h" | 16 #include "content/public/browser/web_contents_user_data.h" |
17 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
18 | 18 |
19 class Profile; | 19 class Profile; |
20 | 20 |
21 namespace extensions { | 21 namespace extensions { |
22 | 22 |
| 23 // TODO(miu): This file and classes should be renamed, as this implementation |
| 24 // has expanded in scope to be used for all off-screen tabs. |
| 25 |
23 class OffscreenPresentation; // Forward declaration. See below. | 26 class OffscreenPresentation; // Forward declaration. See below. |
24 | 27 |
25 // Creates, owns, and manages all OffscreenPresentation instances created by the | 28 // Creates, owns, and manages all OffscreenPresentation instances created by the |
26 // same extension background page. When the extension background page's | 29 // same extension background page. When the extension background page's |
27 // WebContents is about to be destroyed, its associated | 30 // WebContents is about to be destroyed, its associated |
28 // OffscreenPresentationsOwner and all of its OffscreenPresentation instances | 31 // OffscreenPresentationsOwner and all of its OffscreenPresentation instances |
29 // are destroyed. | 32 // are destroyed. |
30 // | 33 // |
31 // Usage: | 34 // Usage: |
32 // | 35 // |
33 // OffscreenPresentationsOwner::Get(extension_contents) | 36 // OffscreenPresentationsOwner::Get(extension_contents) |
34 // ->FindOrStartPresentation(start_url, presentation_id, size); | 37 // ->StartPresentation(start_url, size); |
35 // | 38 // |
36 // This class operates exclusively on the UI thread and so is not thread-safe. | 39 // This class operates exclusively on the UI thread and so is not thread-safe. |
37 class OffscreenPresentationsOwner | 40 class OffscreenPresentationsOwner |
38 : protected content::WebContentsUserData<OffscreenPresentationsOwner> { | 41 : protected content::WebContentsUserData<OffscreenPresentationsOwner> { |
39 public: | 42 public: |
40 ~OffscreenPresentationsOwner() override; | 43 ~OffscreenPresentationsOwner() override; |
41 | 44 |
42 // Returns the OffscreenPresentationsOwner instance associated with the given | 45 // Returns the OffscreenPresentationsOwner instance associated with the given |
43 // extension background page's WebContents. Never returns nullptr. | 46 // extension background page's WebContents. Never returns nullptr. |
44 static OffscreenPresentationsOwner* Get( | 47 static OffscreenPresentationsOwner* Get( |
45 content::WebContents* extension_web_contents); | 48 content::WebContents* extension_web_contents); |
46 | 49 |
47 // Find a presentation, keyed by |start_url| and |presentation_id|. If found, | 50 // Instantiate a new off-screen tab and navigate it to |start_url|. The new |
48 // return it. Otherwise, instantiate a new one and return that. If too many | 51 // tab's main frame will start out with the given |initial_size| in DIP |
49 // presentations have already been started, this method returns nullptr. | 52 // coordinates. If too many off-screen tabs have already been started, this |
50 OffscreenPresentation* FindOrStartPresentation( | 53 // method returns nullptr. |
| 54 OffscreenPresentation* StartPresentation( |
51 const GURL& start_url, | 55 const GURL& start_url, |
52 const std::string& presentation_id, | |
53 const gfx::Size& initial_size); | 56 const gfx::Size& initial_size); |
54 | 57 |
| 58 // Retrieve an existing instance by its ID. If not found, this method returns |
| 59 // nullptr. |
| 60 OffscreenPresentation* FindByOffscreenTabId( |
| 61 const std::string& offscreen_tab_id) const; |
| 62 |
55 protected: | 63 protected: |
56 friend class OffscreenPresentation; | 64 friend class OffscreenPresentation; |
57 | 65 |
58 // Accessor to the extension background page's WebContents. | 66 // Accessor to the extension background page's WebContents. |
59 content::WebContents* extension_web_contents() const { | 67 content::WebContents* extension_web_contents() const { |
60 return extension_web_contents_; | 68 return extension_web_contents_; |
61 } | 69 } |
62 | 70 |
63 // Shuts down and destroys the |presentation|. | 71 // Shuts down and destroys the |presentation|. |
64 void ClosePresentation(OffscreenPresentation* presentation); | 72 void ClosePresentation(OffscreenPresentation* presentation); |
65 | 73 |
66 private: | 74 private: |
67 friend class content::WebContentsUserData<OffscreenPresentationsOwner>; | 75 friend class content::WebContentsUserData<OffscreenPresentationsOwner>; |
68 | 76 |
69 explicit OffscreenPresentationsOwner(content::WebContents* contents); | 77 explicit OffscreenPresentationsOwner(content::WebContents* contents); |
70 | 78 |
71 // Returns the OffscreenPresentation that matches the given |start_url| and | 79 // Returns a unique, random ID that no other OffscreenPresentation has. |
72 // |presentation_id|, or nullptr if not found. | 80 std::string CreateUniqueRandomId() const; |
73 OffscreenPresentation* FindPresentation( | |
74 const GURL& start_url, const std::string& presentation_id) const; | |
75 | 81 |
76 content::WebContents* const extension_web_contents_; | 82 content::WebContents* const extension_web_contents_; |
77 ScopedVector<OffscreenPresentation> presentations_; | 83 ScopedVector<OffscreenPresentation> presentations_; |
78 | 84 |
79 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationsOwner); | 85 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationsOwner); |
80 }; | 86 }; |
81 | 87 |
82 // Owns and controls a WebContents instance containing a presentation page. | 88 // Owns and controls a WebContents instance containing a presentation page. |
83 // Since the presentation page does not interact with the user in any direct | 89 // Since the presentation page does not interact with the user in any direct |
84 // way, the WebContents is not attached to any Browser window/UI, and all input | 90 // way, the WebContents is not attached to any Browser window/UI, and all input |
(...skipping 12 matching lines...) Expand all Loading... |
97 // 3. Automatically, when the extension background page's WebContents is | 103 // 3. Automatically, when the extension background page's WebContents is |
98 // destroyed. | 104 // destroyed. |
99 // | 105 // |
100 // This class operates exclusively on the UI thread and so is not thread-safe. | 106 // This class operates exclusively on the UI thread and so is not thread-safe. |
101 class OffscreenPresentation : protected content::WebContentsDelegate, | 107 class OffscreenPresentation : protected content::WebContentsDelegate, |
102 protected content::WebContentsObserver { | 108 protected content::WebContentsObserver { |
103 public: | 109 public: |
104 ~OffscreenPresentation() final; | 110 ~OffscreenPresentation() final; |
105 | 111 |
106 const GURL& start_url() const { return start_url_; } | 112 const GURL& start_url() const { return start_url_; } |
107 const std::string& presentation_id() const { return presentation_id_; } | 113 const std::string& id() const { return id_; } |
108 | 114 |
109 // The presentation page's WebContents instance. | 115 // The presentation page's WebContents instance. |
110 content::WebContents* web_contents() const { | 116 content::WebContents* web_contents() const { |
111 return presentation_web_contents_.get(); | 117 return presentation_web_contents_.get(); |
112 } | 118 } |
113 | 119 |
114 protected: | 120 protected: |
115 friend class OffscreenPresentationsOwner; | 121 friend class OffscreenPresentationsOwner; |
116 | 122 |
117 OffscreenPresentation(OffscreenPresentationsOwner* owner, | 123 OffscreenPresentation(OffscreenPresentationsOwner* owner, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // Called by |capture_poll_timer_| to automatically destroy this | 183 // Called by |capture_poll_timer_| to automatically destroy this |
178 // OffscreenPresentation when the capturer count returns to zero. | 184 // OffscreenPresentation when the capturer count returns to zero. |
179 void DieIfContentCaptureEnded(); | 185 void DieIfContentCaptureEnded(); |
180 | 186 |
181 OffscreenPresentationsOwner* const owner_; | 187 OffscreenPresentationsOwner* const owner_; |
182 | 188 |
183 // The starting URL for this presentation, which may or may not match the | 189 // The starting URL for this presentation, which may or may not match the |
184 // current WebContents URL if navigations have occurred. | 190 // current WebContents URL if navigations have occurred. |
185 const GURL start_url_; | 191 const GURL start_url_; |
186 | 192 |
187 // The presentation ID used to help uniquely identify this instance. | 193 // An ID used to uniquely identify this instance. |
188 const std::string presentation_id_; | 194 const std::string id_; |
189 | 195 |
190 // A non-shared off-the-record profile based on the profile of the extension | 196 // A non-shared off-the-record profile based on the profile of the extension |
191 // background page. | 197 // background page. |
192 const scoped_ptr<Profile> profile_; | 198 const scoped_ptr<Profile> profile_; |
193 | 199 |
194 // The WebContents containing the offscreen presentation page. | 200 // The WebContents containing the offscreen presentation page. |
195 scoped_ptr<content::WebContents> presentation_web_contents_; | 201 scoped_ptr<content::WebContents> presentation_web_contents_; |
196 | 202 |
197 // The time at which Start() finished creating |presentation_web_contents_|. | 203 // The time at which Start() finished creating |presentation_web_contents_|. |
198 base::TimeTicks start_time_; | 204 base::TimeTicks start_time_; |
(...skipping 12 matching lines...) Expand all Loading... |
211 // This is false until after the Start() method is called, and capture of the | 217 // This is false until after the Start() method is called, and capture of the |
212 // |presentation_web_contents_| is first detected. | 218 // |presentation_web_contents_| is first detected. |
213 bool content_capture_was_detected_; | 219 bool content_capture_was_detected_; |
214 | 220 |
215 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation); | 221 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation); |
216 }; | 222 }; |
217 | 223 |
218 } // namespace extensions | 224 } // namespace extensions |
219 | 225 |
220 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_OFFSCREEN_PRESENTATION_H_ | 226 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_OFFSCREEN_PRESENTATION_H_ |
OLD | NEW |