Chromium Code Reviews| Index: components/offline_pages/content/background_loader/background_loader_contents.cc |
| diff --git a/components/offline_pages/content/background_loader/background_loader_contents.cc b/components/offline_pages/content/background_loader/background_loader_contents.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9d52966d4812219878fb67039934ff7b17dfe824 |
| --- /dev/null |
| +++ b/components/offline_pages/content/background_loader/background_loader_contents.cc |
| @@ -0,0 +1,119 @@ |
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/offline_pages/content/background_loader/background_loader_contents.h" |
| + |
| +#include "content/public/browser/web_contents.h" |
| + |
| +namespace background_loader { |
| + |
| +BackgroundLoaderContents::BackgroundLoaderContents( |
| + content::BrowserContext* browser_context) |
| + : browser_context_(browser_context) { |
| + web_contents_.reset(content::WebContents::Create( |
| + content::WebContents::CreateParams(browser_context_))); |
| + web_contents_->SetDelegate(this); |
| +} |
| + |
| +BackgroundLoaderContents::~BackgroundLoaderContents() {} |
| + |
| +void BackgroundLoaderContents::LoadPage(const GURL& url) { |
| + web_contents_->GetController().LoadURL( |
| + url /* url to be loaded */, |
| + content::Referrer() /* Default referrer policy, no referring url */, |
| + ui::PAGE_TRANSITION_LINK /* page transition type: clicked on link */, |
| + std::string() /* extra headers */); |
| +} |
| + |
| +void BackgroundLoaderContents::Cancel() { |
| + web_contents_->Close(); |
| +} |
| + |
| +bool BackgroundLoaderContents::IsNeverVisible( |
| + content::WebContents* web_contents) { |
| + // Background, so not visible. |
| + return true; |
| +} |
| + |
| +void BackgroundLoaderContents::CloseContents(content::WebContents* source) { |
| + // Do nothing. Other pages should not be able to close a background page. |
|
dougarnett
2016/11/14 20:12:16
NOTREACHED() then?
chili
2016/11/15 02:02:22
Done.
|
| +} |
| + |
| +bool BackgroundLoaderContents::ShouldSuppressDialogs( |
| + content::WebContents* source) { |
| + // Dialog prompts are not actionable in the background. |
| + return true; |
| +} |
| + |
| +bool BackgroundLoaderContents::ShouldFocusPageAfterCrash() { |
| + // Background page should never be focused. |
| + return false; |
| +} |
| + |
| +void BackgroundLoaderContents::CanDownload( |
| + const GURL& url, |
| + const std::string& request_method, |
| + const base::Callback<void(bool)>& callback) { |
| + // Do not download anything. |
| + callback.Run(false); |
| +} |
| + |
| +bool BackgroundLoaderContents::ShouldCreateWebContents( |
| + content::WebContents* contents, |
| + int32_t route_id, |
| + int32_t main_frame_route_id, |
| + int32_t main_frame_widget_route_id, |
| + WindowContainerType window_container_type, |
| + const std::string& frame_name, |
| + const GURL& target_url, |
| + const std::string& partition_id, |
| + content::SessionStorageNamespace* session_storage_namespace) { |
| + // Background pages should not create other webcontents/tabs. |
| + return false; |
| +} |
| + |
| +void BackgroundLoaderContents::AddNewContents( |
| + content::WebContents* source, |
| + content::WebContents* new_contents, |
| + WindowOpenDisposition disposition, |
| + const gfx::Rect& initial_rect, |
| + bool user_gesture, |
| + bool* was_blocked) { |
| + // Pop-ups should be blocked; |
| + // background pages should not create other contents |
| + if (was_blocked != nullptr) |
| + *was_blocked = true; |
| +} |
| + |
| +#if defined(OS_ANDROID) |
| +bool BackgroundLoaderContents::ShouldBlockMediaRequest(const GURL& url) { |
| + // Background pages should not have access to media. |
| + return true; |
| +} |
| +#endif |
| + |
| +void BackgroundLoaderContents::RequestMediaAccessPermission( |
| + content::WebContents* contents, |
| + const content::MediaStreamRequest& request, |
| + const content::MediaResponseCallback& callback) { |
| + // No permissions granted, act as if dismissed. |
| + callback.Run( |
| + content::MediaStreamDevices(), |
| + content::MediaStreamRequestResult::MEDIA_DEVICE_PERMISSION_DISMISSED, |
| + std::unique_ptr<content::MediaStreamUI>()); |
| +} |
| + |
| +bool BackgroundLoaderContents::CheckMediaAccessPermission( |
| + content::WebContents* contents, |
| + const GURL& security_origin, |
| + content::MediaStreamType type) { |
| + return false; // No permissions granted. |
| +} |
| + |
| +BackgroundLoaderContents::BackgroundLoaderContents() |
| + : browser_context_(nullptr) { |
| + web_contents_.reset(); |
| +} |
| + |
| +} // namespace background_loader |