| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 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 #include "components/offline_pages/content/background_loader/background_loader_c
ontents.h" |
| 6 |
| 7 #include "content/public/browser/web_contents.h" |
| 8 |
| 9 namespace background_loader { |
| 10 |
| 11 BackgroundLoaderContents::BackgroundLoaderContents( |
| 12 content::BrowserContext* browser_context) |
| 13 : browser_context_(browser_context) { |
| 14 web_contents_.reset(content::WebContents::Create( |
| 15 content::WebContents::CreateParams(browser_context_))); |
| 16 web_contents_->SetDelegate(this); |
| 17 } |
| 18 |
| 19 BackgroundLoaderContents::~BackgroundLoaderContents() {} |
| 20 |
| 21 void BackgroundLoaderContents::LoadPage(const GURL& url) { |
| 22 web_contents_->GetController().LoadURL( |
| 23 url /* url to be loaded */, |
| 24 content::Referrer() /* Default referrer policy, no referring url */, |
| 25 ui::PAGE_TRANSITION_LINK /* page transition type: clicked on link */, |
| 26 std::string() /* extra headers */); |
| 27 } |
| 28 |
| 29 void BackgroundLoaderContents::Cancel() { |
| 30 web_contents_->Close(); |
| 31 } |
| 32 |
| 33 bool BackgroundLoaderContents::IsNeverVisible( |
| 34 content::WebContents* web_contents) { |
| 35 // Background, so not visible. |
| 36 return true; |
| 37 } |
| 38 |
| 39 void BackgroundLoaderContents::CloseContents(content::WebContents* source) { |
| 40 // Do nothing. Other pages should not be able to close a background page. |
| 41 NOTREACHED(); |
| 42 } |
| 43 |
| 44 bool BackgroundLoaderContents::ShouldSuppressDialogs( |
| 45 content::WebContents* source) { |
| 46 // Dialog prompts are not actionable in the background. |
| 47 return true; |
| 48 } |
| 49 |
| 50 bool BackgroundLoaderContents::ShouldFocusPageAfterCrash() { |
| 51 // Background page should never be focused. |
| 52 return false; |
| 53 } |
| 54 |
| 55 void BackgroundLoaderContents::CanDownload( |
| 56 const GURL& url, |
| 57 const std::string& request_method, |
| 58 const base::Callback<void(bool)>& callback) { |
| 59 // Do not download anything. |
| 60 callback.Run(false); |
| 61 } |
| 62 |
| 63 bool BackgroundLoaderContents::ShouldCreateWebContents( |
| 64 content::WebContents* contents, |
| 65 int32_t route_id, |
| 66 int32_t main_frame_route_id, |
| 67 int32_t main_frame_widget_route_id, |
| 68 WindowContainerType window_container_type, |
| 69 const std::string& frame_name, |
| 70 const GURL& target_url, |
| 71 const std::string& partition_id, |
| 72 content::SessionStorageNamespace* session_storage_namespace) { |
| 73 // Background pages should not create other webcontents/tabs. |
| 74 return false; |
| 75 } |
| 76 |
| 77 void BackgroundLoaderContents::AddNewContents( |
| 78 content::WebContents* source, |
| 79 content::WebContents* new_contents, |
| 80 WindowOpenDisposition disposition, |
| 81 const gfx::Rect& initial_rect, |
| 82 bool user_gesture, |
| 83 bool* was_blocked) { |
| 84 // Pop-ups should be blocked; |
| 85 // background pages should not create other contents |
| 86 if (was_blocked != nullptr) |
| 87 *was_blocked = true; |
| 88 } |
| 89 |
| 90 #if defined(OS_ANDROID) |
| 91 bool BackgroundLoaderContents::ShouldBlockMediaRequest(const GURL& url) { |
| 92 // Background pages should not have access to media. |
| 93 return true; |
| 94 } |
| 95 #endif |
| 96 |
| 97 void BackgroundLoaderContents::RequestMediaAccessPermission( |
| 98 content::WebContents* contents, |
| 99 const content::MediaStreamRequest& request, |
| 100 const content::MediaResponseCallback& callback) { |
| 101 // No permissions granted, act as if dismissed. |
| 102 callback.Run( |
| 103 content::MediaStreamDevices(), |
| 104 content::MediaStreamRequestResult::MEDIA_DEVICE_PERMISSION_DISMISSED, |
| 105 std::unique_ptr<content::MediaStreamUI>()); |
| 106 } |
| 107 |
| 108 bool BackgroundLoaderContents::CheckMediaAccessPermission( |
| 109 content::WebContents* contents, |
| 110 const GURL& security_origin, |
| 111 content::MediaStreamType type) { |
| 112 return false; // No permissions granted. |
| 113 } |
| 114 |
| 115 BackgroundLoaderContents::BackgroundLoaderContents() |
| 116 : browser_context_(nullptr) { |
| 117 web_contents_.reset(); |
| 118 } |
| 119 |
| 120 } // namespace background_loader |
| OLD | NEW |