| 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). 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, | 56 const std::string& optional_presentation_id, |
| 53 const gfx::Size& initial_size); | 57 const gfx::Size& initial_size); |
| 54 | 58 |
| 55 protected: | 59 protected: |
| 56 friend class OffscreenPresentation; | 60 friend class OffscreenPresentation; |
| 57 | 61 |
| 58 // Accessor to the extension background page's WebContents. | 62 // Accessor to the extension background page's WebContents. |
| 59 content::WebContents* extension_web_contents() const { | 63 content::WebContents* extension_web_contents() const { |
| 60 return extension_web_contents_; | 64 return extension_web_contents_; |
| 61 } | 65 } |
| 62 | 66 |
| 63 // Shuts down and destroys the |presentation|. | 67 // Shuts down and destroys the |presentation|. |
| 64 void ClosePresentation(OffscreenPresentation* presentation); | 68 void ClosePresentation(OffscreenPresentation* presentation); |
| 65 | 69 |
| 66 private: | 70 private: |
| 67 friend class content::WebContentsUserData<OffscreenPresentationsOwner>; | 71 friend class content::WebContentsUserData<OffscreenPresentationsOwner>; |
| 68 | 72 |
| 69 explicit OffscreenPresentationsOwner(content::WebContents* contents); | 73 explicit OffscreenPresentationsOwner(content::WebContents* contents); |
| 70 | 74 |
| 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_; | 75 content::WebContents* const extension_web_contents_; |
| 77 ScopedVector<OffscreenPresentation> presentations_; | 76 ScopedVector<OffscreenPresentation> presentations_; |
| 78 | 77 |
| 79 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationsOwner); | 78 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationsOwner); |
| 80 }; | 79 }; |
| 81 | 80 |
| 82 // Owns and controls a WebContents instance containing a presentation page. | 81 // Owns and controls a WebContents instance containing a presentation page. |
| 83 // Since the presentation page does not interact with the user in any direct | 82 // 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 | 83 // way, the WebContents is not attached to any Browser window/UI, and all input |
| 85 // and focusing capabilities are blocked. | 84 // 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 | 210 // This is false until after the Start() method is called, and capture of the |
| 212 // |presentation_web_contents_| is first detected. | 211 // |presentation_web_contents_| is first detected. |
| 213 bool content_capture_was_detected_; | 212 bool content_capture_was_detected_; |
| 214 | 213 |
| 215 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation); | 214 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation); |
| 216 }; | 215 }; |
| 217 | 216 |
| 218 } // namespace extensions | 217 } // namespace extensions |
| 219 | 218 |
| 220 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_OFFSCREEN_PRESENTATION_H_ | 219 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_OFFSCREEN_PRESENTATION_H_ |
| OLD | NEW |