| 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 COMPONENTS_OFFLINE_PAGES_CONTENT_BACKGROUND_LOADER_BACKGROUND_LOADER_CON
TENTS_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_CONTENT_BACKGROUND_LOADER_BACKGROUND_LOADER_CON
TENTS_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "content/public/browser/web_contents_delegate.h" |
| 12 #include "url/gurl.h" |
| 13 |
| 14 namespace content { |
| 15 class WebContentsObserver; |
| 16 class WebContents; |
| 17 } |
| 18 |
| 19 namespace background_loader { |
| 20 |
| 21 // This class maintains a WebContents used in the background. It can host |
| 22 // a renderer but does not have any visible display. |
| 23 class BackgroundLoaderContents : public content::WebContentsDelegate { |
| 24 public: |
| 25 // Creates BackgroundLoaderContents with specified |browser_context| and |
| 26 // |session_storage_namespace|. This ctor should only be used if a different |
| 27 // session storage (e.g. non-persistent/incognito) should be used. |
| 28 // |session_storage_namespace| should not be null. |
| 29 BackgroundLoaderContents( |
| 30 content::BrowserContext* browser_context, |
| 31 content::SessionStorageNamespace* session_storage_namespace); |
| 32 |
| 33 // Creates BackgroundLoaderContents with specified |browser_context|. Uses |
| 34 // default session storage space. |
| 35 explicit BackgroundLoaderContents(content::BrowserContext* browser_context); |
| 36 ~BackgroundLoaderContents() override; |
| 37 |
| 38 // Loads the URL in a WebContents. Will call observe on all current observers |
| 39 // with the created WebContents. |
| 40 void LoadPage(const GURL& url); |
| 41 // Cancels loading of the current page. Calls Close() on internal WebContents. |
| 42 void Cancel(); |
| 43 |
| 44 void AddObserver(content::WebContentsObserver* observer); |
| 45 void RemoveObserver(content::WebContentsObserver* observer); |
| 46 |
| 47 // content::WebContentsDelegate implementation: |
| 48 bool IsNeverVisible(content::WebContents* web_contents) override; |
| 49 void CloseContents(content::WebContents* source) override; |
| 50 bool ShouldSuppressDialogs(content::WebContents* source) override; |
| 51 bool ShouldFocusPageAfterCrash() override; |
| 52 void CanDownload(const GURL& url, |
| 53 const std::string& request_method, |
| 54 const base::Callback<void(bool)>& callback) override; |
| 55 |
| 56 bool ShouldCreateWebContents( |
| 57 content::WebContents* contents, |
| 58 int32_t route_id, |
| 59 int32_t main_frame_route_id, |
| 60 int32_t main_frame_widget_route_id, |
| 61 WindowContainerType window_container_type, |
| 62 const std::string& frame_name, |
| 63 const GURL& target_url, |
| 64 const std::string& partition_id, |
| 65 content::SessionStorageNamespace* session_storage_namespace) override; |
| 66 |
| 67 void AddNewContents(WebContents* source, |
| 68 WebContents* new_contents, |
| 69 WindowOpenDisposition disposition, |
| 70 const gfx::Rect& initial_rect, |
| 71 bool user_gesture, |
| 72 bool* was_blocked) override; |
| 73 |
| 74 #if defined(OS_ANDROID) |
| 75 bool ShouldBlockMediaRequest(const GURL& url) override; |
| 76 #endif |
| 77 |
| 78 void RequestMediaAccessPermission( |
| 79 content::WebContents* contents, |
| 80 const content::MediaStreamRequest& request, |
| 81 const content::MediaResponseCallback& callback) override; |
| 82 bool CheckMediaAccessPermission(content::WebContents* contents, |
| 83 const GURL& security_origin, |
| 84 content::MediaStreamType type) override; |
| 85 |
| 86 private: |
| 87 std::unique_ptr<content::WebContents> web_contents_; |
| 88 content::SessionStorageNamespaceMap session_storage_namespace_map_; |
| 89 content::BrowserContext* browser_context_; |
| 90 base::ObserverList<WebContentsObserver> observers_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderContents); |
| 93 }; |
| 94 |
| 95 } // namespace background_loader |
| 96 #endif // COMPONENTS_OFFLINE_PAGES_CONTENT_BACKGROUND_LOADER_BACKGROUND_LOADER_
CONTENTS_H_ |
| OLD | NEW |