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

Side by Side Diff: chrome/browser/extensions/api/page_capture/page_capture_api.cc

Issue 2552203007: Public Sessions - prompt the user for pageCapture requests (Closed)
Patch Set: Changed pref name & location; removed incognito code Created 3 years, 11 months 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/page_capture/page_capture_api.h" 5 #include "chrome/browser/extensions/api/page_capture/page_capture_api.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
11 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/memory/ptr_util.h"
12 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/extensions/api/page_capture/page_capture_permission_hel per.h"
13 #include "chrome/browser/extensions/extension_tab_util.h" 16 #include "chrome/browser/extensions/extension_tab_util.h"
14 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profiles_state.h"
15 #include "content/public/browser/child_process_security_policy.h" 19 #include "content/public/browser/child_process_security_policy.h"
16 #include "content/public/browser/notification_details.h" 20 #include "content/public/browser/notification_details.h"
17 #include "content/public/browser/notification_source.h" 21 #include "content/public/browser/notification_source.h"
18 #include "content/public/browser/notification_types.h" 22 #include "content/public/browser/notification_types.h"
19 #include "content/public/browser/render_frame_host.h" 23 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/mhtml_generation_params.h" 26 #include "content/public/common/mhtml_generation_params.h"
23 #include "extensions/common/extension_messages.h" 27 #include "extensions/common/extension_messages.h"
24 28
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 void PageCaptureSaveAsMHTMLFunction::SetTestDelegate(TestDelegate* delegate) { 60 void PageCaptureSaveAsMHTMLFunction::SetTestDelegate(TestDelegate* delegate) {
57 test_delegate_ = delegate; 61 test_delegate_ = delegate;
58 } 62 }
59 63
60 bool PageCaptureSaveAsMHTMLFunction::RunAsync() { 64 bool PageCaptureSaveAsMHTMLFunction::RunAsync() {
61 params_ = SaveAsMHTML::Params::Create(*args_); 65 params_ = SaveAsMHTML::Params::Create(*args_);
62 EXTENSION_FUNCTION_VALIDATE(params_.get()); 66 EXTENSION_FUNCTION_VALIDATE(params_.get());
63 67
64 AddRef(); // Balanced in ReturnFailure/ReturnSuccess() 68 AddRef(); // Balanced in ReturnFailure/ReturnSuccess()
65 69
70 // In Public Sessions, extensions (and apps) are force-installed by admin
71 // policy so the user does not get a chance to review the permissions for
72 // these extensions. This is not acceptable from a security/privacy
73 // standpoint, so when an extension uses the PageCapture API for the first
74 // time, we show the user a dialog where they can choose whether to allow the
75 // extension access to the API.
76 #if defined(OS_CHROMEOS)
77 if (profiles::IsPublicSession()) {
78 auto success_callback = base::Bind(
79 base::IgnoreResult(&BrowserThread::PostTask), BrowserThread::FILE,
80 FROM_HERE,
81 base::Bind(&PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile,
82 base::Unretained(this)));
83 auto failure_callback = base::Bind(
84 &PageCaptureSaveAsMHTMLFunction::ReturnFailure, base::Unretained(this));
85 permission_helper_ = base::MakeUnique<PageCapturePermissionHelper>(
86 extension(),
87 // OffTheRecordPrefs are used here because the pref must not be
88 // persistent across user sessions.
89 GetProfile()->GetOffTheRecordPrefs(), success_callback,
90 failure_callback);
91 permission_helper_->HandlePermissionRequest(GetWebContents());
92 return true;
93 }
94 #endif
95
66 BrowserThread::PostTask( 96 BrowserThread::PostTask(
67 BrowserThread::FILE, FROM_HERE, 97 BrowserThread::FILE, FROM_HERE,
68 base::Bind(&PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile, this)); 98 base::Bind(&PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile, this));
69 return true; 99 return true;
70 } 100 }
71 101
72 bool PageCaptureSaveAsMHTMLFunction::OnMessageReceived( 102 bool PageCaptureSaveAsMHTMLFunction::OnMessageReceived(
73 const IPC::Message& message) { 103 const IPC::Message& message) {
74 if (message.type() != ExtensionHostMsg_ResponseAck::ID) 104 if (message.type() != ExtensionHostMsg_ResponseAck::ID)
75 return false; 105 return false;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 GetProfile(), 223 GetProfile(),
194 include_incognito(), 224 include_incognito(),
195 &browser, 225 &browser,
196 NULL, 226 NULL,
197 &web_contents, 227 &web_contents,
198 NULL)) { 228 NULL)) {
199 return NULL; 229 return NULL;
200 } 230 }
201 return web_contents; 231 return web_contents;
202 } 232 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698