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, presentation_id, 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, navigate it to |start_url|, and register |
48 // return it. Otherwise, instantiate a new one and return that. If too many | 51 // it with the presentation router using |presentation_id| (if a non-empty |
49 // presentations have already been started, this method returns nullptr. | 52 // string). The new tab's main frame will start out with the given |
50 OffscreenPresentation* FindOrStartPresentation( | 53 // |initial_size| in DIP coordinates. If too many off-screen tabs have |
| 54 // already been started, this method returns nullptr. |
| 55 OffscreenPresentation* StartPresentation( |
51 const GURL& start_url, | 56 const GURL& start_url, |
52 const std::string& presentation_id, | 57 const std::string& optional_presentation_id, |
53 const gfx::Size& initial_size); | 58 const gfx::Size& initial_size); |
54 | 59 |
55 protected: | 60 protected: |
56 friend class OffscreenPresentation; | 61 friend class OffscreenPresentation; |
57 | 62 |
58 // Accessor to the extension background page's WebContents. | 63 // Accessor to the extension background page's WebContents. |
59 content::WebContents* extension_web_contents() const { | 64 content::WebContents* extension_web_contents() const { |
60 return extension_web_contents_; | 65 return extension_web_contents_; |
61 } | 66 } |
62 | 67 |
63 // Shuts down and destroys the |presentation|. | 68 // Shuts down and destroys the |presentation|. |
64 void ClosePresentation(OffscreenPresentation* presentation); | 69 void ClosePresentation(OffscreenPresentation* presentation); |
65 | 70 |
66 private: | 71 private: |
67 friend class content::WebContentsUserData<OffscreenPresentationsOwner>; | 72 friend class content::WebContentsUserData<OffscreenPresentationsOwner>; |
68 | 73 |
69 explicit OffscreenPresentationsOwner(content::WebContents* contents); | 74 explicit OffscreenPresentationsOwner(content::WebContents* contents); |
70 | 75 |
71 // Returns the OffscreenPresentation that matches the given |start_url| and | |
72 // |presentation_id|, or nullptr if not found. | |
73 OffscreenPresentation* FindPresentation( | |
74 const GURL& start_url, const std::string& presentation_id) const; | |
75 | |
76 content::WebContents* const extension_web_contents_; | 76 content::WebContents* const extension_web_contents_; |
77 ScopedVector<OffscreenPresentation> presentations_; | 77 ScopedVector<OffscreenPresentation> presentations_; |
78 | 78 |
79 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationsOwner); | 79 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationsOwner); |
80 }; | 80 }; |
81 | 81 |
82 // Owns and controls a WebContents instance containing a presentation page. | 82 // Owns and controls a WebContents instance containing a presentation page. |
83 // Since the presentation page does not interact with the user in any direct | 83 // 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 | 84 // way, the WebContents is not attached to any Browser window/UI, and all input |
85 // and focusing capabilities are blocked. | 85 // and focusing capabilities are blocked. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 // This is false until after the Start() method is called, and capture of the | 211 // This is false until after the Start() method is called, and capture of the |
212 // |presentation_web_contents_| is first detected. | 212 // |presentation_web_contents_| is first detected. |
213 bool content_capture_was_detected_; | 213 bool content_capture_was_detected_; |
214 | 214 |
215 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation); | 215 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation); |
216 }; | 216 }; |
217 | 217 |
218 } // namespace extensions | 218 } // namespace extensions |
219 | 219 |
220 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_OFFSCREEN_PRESENTATION_H_ | 220 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_OFFSCREEN_PRESENTATION_H_ |
OLD | NEW |