Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: components/offline_pages/content/background_loader/background_loader_contents.cc

Issue 2481443002: Implementation (cc file) for background loader contents. (Closed)
Patch Set: remove unneeded dep from tests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.
dougarnett 2016/11/14 20:12:16 NOTREACHED() then?
chili 2016/11/15 02:02:22 Done.
41 }
42
43 bool BackgroundLoaderContents::ShouldSuppressDialogs(
44 content::WebContents* source) {
45 // Dialog prompts are not actionable in the background.
46 return true;
47 }
48
49 bool BackgroundLoaderContents::ShouldFocusPageAfterCrash() {
50 // Background page should never be focused.
51 return false;
52 }
53
54 void BackgroundLoaderContents::CanDownload(
55 const GURL& url,
56 const std::string& request_method,
57 const base::Callback<void(bool)>& callback) {
58 // Do not download anything.
59 callback.Run(false);
60 }
61
62 bool BackgroundLoaderContents::ShouldCreateWebContents(
63 content::WebContents* contents,
64 int32_t route_id,
65 int32_t main_frame_route_id,
66 int32_t main_frame_widget_route_id,
67 WindowContainerType window_container_type,
68 const std::string& frame_name,
69 const GURL& target_url,
70 const std::string& partition_id,
71 content::SessionStorageNamespace* session_storage_namespace) {
72 // Background pages should not create other webcontents/tabs.
73 return false;
74 }
75
76 void BackgroundLoaderContents::AddNewContents(
77 content::WebContents* source,
78 content::WebContents* new_contents,
79 WindowOpenDisposition disposition,
80 const gfx::Rect& initial_rect,
81 bool user_gesture,
82 bool* was_blocked) {
83 // Pop-ups should be blocked;
84 // background pages should not create other contents
85 if (was_blocked != nullptr)
86 *was_blocked = true;
87 }
88
89 #if defined(OS_ANDROID)
90 bool BackgroundLoaderContents::ShouldBlockMediaRequest(const GURL& url) {
91 // Background pages should not have access to media.
92 return true;
93 }
94 #endif
95
96 void BackgroundLoaderContents::RequestMediaAccessPermission(
97 content::WebContents* contents,
98 const content::MediaStreamRequest& request,
99 const content::MediaResponseCallback& callback) {
100 // No permissions granted, act as if dismissed.
101 callback.Run(
102 content::MediaStreamDevices(),
103 content::MediaStreamRequestResult::MEDIA_DEVICE_PERMISSION_DISMISSED,
104 std::unique_ptr<content::MediaStreamUI>());
105 }
106
107 bool BackgroundLoaderContents::CheckMediaAccessPermission(
108 content::WebContents* contents,
109 const GURL& security_origin,
110 content::MediaStreamType type) {
111 return false; // No permissions granted.
112 }
113
114 BackgroundLoaderContents::BackgroundLoaderContents()
115 : browser_context_(nullptr) {
116 web_contents_.reset();
117 }
118
119 } // namespace background_loader
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698