| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDER_ADAPTER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDER_ADAPTER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "chrome/browser/prerender/prerender_handle.h" |
| 11 |
| 12 class GURL; |
| 13 |
| 14 namespace content { |
| 15 class BrowserContext; |
| 16 class WebContents; |
| 17 class SessionStorageNamespace; |
| 18 } // namespace content |
| 19 |
| 20 namespace gfx { |
| 21 class Size; |
| 22 } // namespace gfx |
| 23 |
| 24 namespace offline_pages { |
| 25 |
| 26 // An adapter for managing a prerendering request for offlining. This handles |
| 27 // all calls into the prerender stack and tracks the active prerender handle. |
| 28 class PrerenderAdapter { |
| 29 public: |
| 30 PrerenderAdapter(); |
| 31 virtual ~PrerenderAdapter(); |
| 32 |
| 33 // Returns whether prerendering is enabled and configured. |
| 34 virtual bool CanPrerender() const; |
| 35 |
| 36 // Starts prerendering |url| for offlining. There must be no active |
| 37 // prerender request when calling this. Returns whether it was able |
| 38 // to start the prerendering operation. |
| 39 virtual bool StartPrerender( |
| 40 content::BrowserContext* browser_context, |
| 41 const GURL& url, |
| 42 content::SessionStorageNamespace* session_storage_namespace, |
| 43 const gfx::Size& size, |
| 44 prerender::PrerenderHandle::Observer* observer); |
| 45 |
| 46 // Returns a pointer to the prerendered WebContents. This should only be |
| 47 // called once prerendering observer events indicate content is loaded. |
| 48 // It may be used for snapshotting the page. The caller does NOT get |
| 49 // ownership on the contents and must call |DestroyActive()| |
| 50 // to report when it no longer needs the web contents. The caller should |
| 51 // have a PrerenderHandle::Observer and watch for |OnPrerenderStop()| to |
| 52 // learn that the web contents should no longer be used. |
| 53 virtual content::WebContents* GetWebContents() const; |
| 54 |
| 55 // Returns the final status of prerendering. |
| 56 virtual prerender::FinalStatus GetFinalStatus() const; |
| 57 |
| 58 // Returns whether this adapter has an active prerender request. This |
| 59 // adapter supports one request at a time. DestroyActive() may be used |
| 60 // to clear an active request (which will allow StartPrerender() to be |
| 61 // called to request a new one). |
| 62 virtual bool IsActive() const; |
| 63 |
| 64 // Returns whether there is an active prerendering associated with |
| 65 // the |handle|. This may be used to confirm that an observed prerender |
| 66 // event for |handle| applies to the active prerendering. |
| 67 virtual bool HasHandle(prerender::PrerenderHandle* handle) const; |
| 68 |
| 69 // Cancels any current prerendering operation and destroys its local handle. |
| 70 virtual void DestroyActive(); |
| 71 |
| 72 private: |
| 73 // At most one prerender request may be active for this adapter and this |
| 74 // holds its handle if one is active. |
| 75 std::unique_ptr<prerender::PrerenderHandle> active_handle_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(PrerenderAdapter); |
| 78 }; |
| 79 |
| 80 } // namespace offline_pages |
| 81 |
| 82 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDER_ADAPTER_H_ |
| OLD | NEW |