Skip to content

Commit

Permalink
ChromeOS: Re-enable screenshot during OOBE.
Browse files Browse the repository at this point in the history
Re-enable taking full screenshot in login screen.
File will be saved to temporary location.

Bug: 1180454
Test: Manual tested on DUT.

Change-Id: Ibdf464c1d0a575d5c5e968c4d425244b815207ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2733256
Commit-Queue: Judy Wang <shidi@chromium.org>
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#862170}
  • Loading branch information
Judy Wang authored and Chromium LUCI CQ committed Mar 11, 2021
1 parent b038347 commit c9b7477
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 22 deletions.
14 changes: 8 additions & 6 deletions ash/accelerators/accelerator_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,11 @@ void HandleShowKeyboardShortcutViewer() {
NewWindowDelegate::GetInstance()->ShowKeyboardShortcutViewer();
}

bool CanHandleScreenshot() {
bool CanHandleScreenshot(AcceleratorAction action) {
// The old screenshot code will handle the different sessions in its own code.
if (!features::IsCaptureModeEnabled())
// |TAKE_SCREENSHOT| is allowed when user session is blocked.
if (!features::IsCaptureModeEnabled() || action == TAKE_SCREENSHOT)
return true;

return !Shell::Get()->session_controller()->IsUserSessionBlocked();
}

Expand Down Expand Up @@ -793,9 +793,11 @@ void HandleTakeScreenshot(ui::KeyboardCode key_code) {
return;
}

// If it is the snip key, toggle capture mode.
// If it is the snip key, toggle capture mode unless the session is blocked,
// in which case, it behaves like a fullscreen screenshot.
auto* capture_mode_controller = CaptureModeController::Get();
if (key_code == ui::VKEY_SNAPSHOT) {
if (key_code == ui::VKEY_SNAPSHOT &&
!Shell::Get()->session_controller()->IsUserSessionBlocked()) {
if (capture_mode_controller->IsActive())
capture_mode_controller->Stop();
else
Expand Down Expand Up @@ -2034,7 +2036,7 @@ bool AcceleratorControllerImpl::CanPerformAction(
case TAKE_PARTIAL_SCREENSHOT:
case TAKE_SCREENSHOT:
case TAKE_WINDOW_SCREENSHOT:
return CanHandleScreenshot();
return CanHandleScreenshot(action);

// The following are always enabled.
case BRIGHTNESS_DOWN:
Expand Down
4 changes: 1 addition & 3 deletions ash/accelerators/accelerator_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ const AcceleratorAction kActionsAllowedAtLoginOrLockScreen[] = {
START_AMBIENT_MODE,
SWITCH_TO_LAST_USED_IME,
SWITCH_TO_NEXT_IME,
TAKE_SCREENSHOT,
TOGGLE_CAPS_LOCK,
TOGGLE_DICTATION,
TOGGLE_DOCKED_MAGNIFIER,
Expand All @@ -198,9 +199,6 @@ const size_t kActionsAllowedAtLoginOrLockScreenLength =
const AcceleratorAction kActionsAllowedAtLockScreen[] = {
EXIT,
SUSPEND,
TAKE_PARTIAL_SCREENSHOT,
TAKE_SCREENSHOT,
TAKE_WINDOW_SCREENSHOT,
};

const size_t kActionsAllowedAtLockScreenLength =
Expand Down
4 changes: 2 additions & 2 deletions ash/capture_mode/capture_mode_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ void CaptureModeController::ShowPreviewNotification(
message_center::RichNotificationData optional_fields;
message_center::ButtonInfo edit_button(
l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_BUTTON_EDIT));
if (!for_video)
if (!for_video && !Shell::Get()->session_controller()->IsUserSessionBlocked())
optional_fields.buttons.push_back(edit_button);
message_center::ButtonInfo delete_button(
l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_BUTTON_DELETE));
Expand Down Expand Up @@ -1032,7 +1032,7 @@ base::FilePath CaptureModeController::BuildImagePathForDisplay(
base::FilePath CaptureModeController::BuildPathNoExtension(
const char* const format_string,
base::Time timestamp) const {
const base::FilePath path = delegate_->GetActiveUserDownloadsDir();
const base::FilePath path = delegate_->GetScreenCaptureDir();
base::Time::Exploded exploded_time;
timestamp.LocalExplode(&exploded_time);

Expand Down
2 changes: 1 addition & 1 deletion ash/capture_mode/test_capture_mode_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ gfx::Size TestCaptureModeDelegate::GetCurrentVideoSize() const {
return fake_service_ ? fake_service_->video_size() : gfx::Size();
}

base::FilePath TestCaptureModeDelegate::GetActiveUserDownloadsDir() const {
base::FilePath TestCaptureModeDelegate::GetScreenCaptureDir() const {
return fake_downloads_dir_;
}

Expand Down
2 changes: 1 addition & 1 deletion ash/capture_mode/test_capture_mode_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TestCaptureModeDelegate : public CaptureModeDelegate {
gfx::Size GetCurrentVideoSize() const;

// CaptureModeDelegate:
base::FilePath GetActiveUserDownloadsDir() const override;
base::FilePath GetScreenCaptureDir() const override;
void ShowScreenCaptureItemInFolder(const base::FilePath& file_path) override;
void OpenScreenshotInImageEditor(const base::FilePath& file_path) override;
bool Uses24HourFormat() const override;
Expand Down
6 changes: 3 additions & 3 deletions ash/public/cpp/capture_mode_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class ASH_PUBLIC_EXPORT CaptureModeDelegate {
public:
virtual ~CaptureModeDelegate() = default;

// Returns the path to the active user's downloads directory. This will never
// be called if the user is not logged in.
virtual base::FilePath GetActiveUserDownloadsDir() const = 0;
// Returns the path to save screen capture files based on user login status.
// If no user is logged in, returns the temporary directory.
virtual base::FilePath GetScreenCaptureDir() const = 0;

// Shows the screenshot or screen recording item in the screen capture folder.
virtual void ShowScreenCaptureItemInFolder(
Expand Down
16 changes: 11 additions & 5 deletions chrome/browser/ui/ash/chrome_capture_mode_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ash/services/recording/public/mojom/recording_service.mojom.h"
#include "base/check.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/i18n/time_formatting.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
Expand Down Expand Up @@ -72,11 +73,16 @@ void ChromeCaptureModeDelegate::InterruptVideoRecordingIfAny() {
std::move(interrupt_video_recording_callback_).Run();
}

base::FilePath ChromeCaptureModeDelegate::GetActiveUserDownloadsDir() const {
DCHECK(chromeos::LoginState::Get()->IsUserLoggedIn());
DownloadPrefs* download_prefs =
DownloadPrefs::FromBrowserContext(ProfileManager::GetActiveUserProfile());
return download_prefs->DownloadPath();
base::FilePath ChromeCaptureModeDelegate::GetScreenCaptureDir() const {
if (chromeos::LoginState::Get()->IsUserLoggedIn()) {
DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(
ProfileManager::GetActiveUserProfile());
return download_prefs->DownloadPath();
}
base::FilePath tmp_dir;
if (!base::GetTempDir(&tmp_dir))
LOG(ERROR) << "Failed to find temporary directory.";
return tmp_dir;
}

void ChromeCaptureModeDelegate::ShowScreenCaptureItemInFolder(
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/ash/chrome_capture_mode_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ChromeCaptureModeDelegate : public ash::CaptureModeDelegate {
void InterruptVideoRecordingIfAny();

// ash::CaptureModeDelegate:
base::FilePath GetActiveUserDownloadsDir() const override;
base::FilePath GetScreenCaptureDir() const override;
void ShowScreenCaptureItemInFolder(const base::FilePath& file_path) override;
void OpenScreenshotInImageEditor(const base::FilePath& file_path) override;
bool Uses24HourFormat() const override;
Expand Down

0 comments on commit c9b7477

Please sign in to comment.