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

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: Moved CrOS only code to a separate file 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"
12 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/extensions/api/page_capture/page_capture_permission_hel per.h"
13 #include "chrome/browser/extensions/extension_tab_util.h" 15 #include "chrome/browser/extensions/extension_tab_util.h"
14 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chromeos/login/login_state.h"
15 #include "content/public/browser/child_process_security_policy.h" 18 #include "content/public/browser/child_process_security_policy.h"
16 #include "content/public/browser/notification_details.h" 19 #include "content/public/browser/notification_details.h"
17 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
18 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
19 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/mhtml_generation_params.h" 25 #include "content/public/common/mhtml_generation_params.h"
23 #include "extensions/common/extension_messages.h" 26 #include "extensions/common/extension_messages.h"
24 27
25 using content::BrowserThread; 28 using content::BrowserThread;
26 using content::ChildProcessSecurityPolicy; 29 using content::ChildProcessSecurityPolicy;
27 using content::WebContents; 30 using content::WebContents;
28 using extensions::PageCaptureSaveAsMHTMLFunction; 31 using extensions::PageCaptureSaveAsMHTMLFunction;
29 using storage::ShareableFileReference; 32 using storage::ShareableFileReference;
30 33
31 namespace SaveAsMHTML = extensions::api::page_capture::SaveAsMHTML; 34 namespace SaveAsMHTML = extensions::api::page_capture::SaveAsMHTML;
32 35
33 namespace { 36 namespace {
34 37
35 const char kFileTooBigError[] = "The MHTML file generated is too big."; 38 const char kFileTooBigError[] = "The MHTML file generated is too big.";
36 const char kMHTMLGenerationFailedError[] = "Failed to generate MHTML."; 39 const char kMHTMLGenerationFailedError[] = "Failed to generate MHTML.";
37 const char kTemporaryFileError[] = "Failed to create a temporary file."; 40 const char kTemporaryFileError[] = "Failed to create a temporary file.";
38 const char kTabClosedError[] = "Cannot find the tab for this request."; 41 const char kTabClosedError[] = "Cannot find the tab for this request.";
39 42
43 #if defined(OS_CHROMEOS)
44 bool IsPublicSession() {
45 return chromeos::LoginState::IsInitialized() &&
46 chromeos::LoginState::Get()->IsPublicSessionUser();
47 }
48 #endif
49
40 } // namespace 50 } // namespace
41 51
42 static PageCaptureSaveAsMHTMLFunction::TestDelegate* test_delegate_ = NULL; 52 static PageCaptureSaveAsMHTMLFunction::TestDelegate* test_delegate_ = NULL;
43 53
44 PageCaptureSaveAsMHTMLFunction::PageCaptureSaveAsMHTMLFunction() { 54 PageCaptureSaveAsMHTMLFunction::PageCaptureSaveAsMHTMLFunction() {
45 } 55 }
46 56
47 PageCaptureSaveAsMHTMLFunction::~PageCaptureSaveAsMHTMLFunction() { 57 PageCaptureSaveAsMHTMLFunction::~PageCaptureSaveAsMHTMLFunction() {
48 if (mhtml_file_.get()) { 58 if (mhtml_file_.get()) {
49 storage::ShareableFileReference* to_release = mhtml_file_.get(); 59 storage::ShareableFileReference* to_release = mhtml_file_.get();
50 to_release->AddRef(); 60 to_release->AddRef();
51 mhtml_file_ = NULL; 61 mhtml_file_ = NULL;
52 BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE, to_release); 62 BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE, to_release);
53 } 63 }
54 } 64 }
55 65
56 void PageCaptureSaveAsMHTMLFunction::SetTestDelegate(TestDelegate* delegate) { 66 void PageCaptureSaveAsMHTMLFunction::SetTestDelegate(TestDelegate* delegate) {
57 test_delegate_ = delegate; 67 test_delegate_ = delegate;
58 } 68 }
59 69
60 bool PageCaptureSaveAsMHTMLFunction::RunAsync() { 70 bool PageCaptureSaveAsMHTMLFunction::RunAsync() {
61 params_ = SaveAsMHTML::Params::Create(*args_); 71 params_ = SaveAsMHTML::Params::Create(*args_);
62 EXTENSION_FUNCTION_VALIDATE(params_.get()); 72 EXTENSION_FUNCTION_VALIDATE(params_.get());
63 73
64 AddRef(); // Balanced in ReturnFailure/ReturnSuccess() 74 AddRef(); // Balanced in ReturnFailure/ReturnSuccess()
65 75
76 // In Public Sessions, extensions (and apps) are force-installed by admin
77 // policy so the user does not get a chance to review the permissions for
78 // these extensions. This is not acceptable from a security/privacy
79 // standpoint, so when an extension uses the PageCapture API for the first
80 // time, we show the user a dialog where they can choose whether to allow the
81 // extension access to the API.
82 #if defined(OS_CHROMEOS)
83 if (IsPublicSession()) {
84 auto success_callback = base::Bind(
85 base::IgnoreResult(&BrowserThread::PostTask), BrowserThread::FILE,
86 FROM_HERE,
87 base::Bind(&PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile, this));
88 auto failure_callback =
89 base::Bind(&PageCaptureSaveAsMHTMLFunction::ReturnFailure, this);
90 permission_helper_.reset(new PageCapturePermissionHelper(
Devlin 2017/01/06 20:45:49 nit: prefer base::MakeUnique<>
Ivan Šandrk 2017/01/09 13:14:55 Done.
91 extension(),
92 // OffTheRecordPrefs are used here because the pref must not be
93 // persistent across user sessions.
94 GetProfile()->GetOffTheRecordPrefs(), success_callback,
95 failure_callback));
96 permission_helper_->HandlePermissionRequest(GetWebContents());
97 return true;
98 }
99 #endif
100
66 BrowserThread::PostTask( 101 BrowserThread::PostTask(
67 BrowserThread::FILE, FROM_HERE, 102 BrowserThread::FILE, FROM_HERE,
68 base::Bind(&PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile, this)); 103 base::Bind(&PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile, this));
69 return true; 104 return true;
70 } 105 }
71 106
72 bool PageCaptureSaveAsMHTMLFunction::OnMessageReceived( 107 bool PageCaptureSaveAsMHTMLFunction::OnMessageReceived(
73 const IPC::Message& message) { 108 const IPC::Message& message) {
74 if (message.type() != ExtensionHostMsg_ResponseAck::ID) 109 if (message.type() != ExtensionHostMsg_ResponseAck::ID)
75 return false; 110 return false;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 GetProfile(), 228 GetProfile(),
194 include_incognito(), 229 include_incognito(),
195 &browser, 230 &browser,
196 NULL, 231 NULL,
197 &web_contents, 232 &web_contents,
198 NULL)) { 233 NULL)) {
199 return NULL; 234 return NULL;
200 } 235 }
201 return web_contents; 236 return web_contents;
202 } 237 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698