Commit 247cd6ef authored by rbpotter's avatar rbpotter Committed by Commit Bot

PrintPreviewHandler: Send signed in accounts in initial settings

This CL changes PrintPreviewHandler to obtain the sign in state from the
identity service, and send this with initial settings. This will
eventually allow Print Preview to set the initial cloudPrintState
without querying the cloud print server.

Bug: 961359
Change-Id: I4382801b7e9a474e3664966d1794e4f4d6b0a7a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1616329
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661000}
parent 0fed282e
...@@ -43,7 +43,8 @@ print_preview.LocalDestinationInfo; ...@@ -43,7 +43,8 @@ print_preview.LocalDestinationInfo;
* isHeaderFooterManaged: boolean, * isHeaderFooterManaged: boolean,
* serializedAppStateStr: ?string, * serializedAppStateStr: ?string,
* serializedDefaultDestinationSelectionRulesStr: ?string, * serializedDefaultDestinationSelectionRulesStr: ?string,
* cloudPrintURL: (string | undefined) * cloudPrintURL: (string | undefined),
* userAccounts: (Array<string> | undefined)
* }} * }}
* @see corresponding field name definitions in print_preview_handler.cc * @see corresponding field name definitions in print_preview_handler.cc
*/ */
......
...@@ -281,6 +281,8 @@ const char kHeaderFooter[] = "headerFooter"; ...@@ -281,6 +281,8 @@ const char kHeaderFooter[] = "headerFooter";
const char kIsHeaderFooterManaged[] = "isHeaderFooterManaged"; const char kIsHeaderFooterManaged[] = "isHeaderFooterManaged";
// Name of a dictionary field holding the cloud print URL. // Name of a dictionary field holding the cloud print URL.
const char kCloudPrintURL[] = "cloudPrintURL"; const char kCloudPrintURL[] = "cloudPrintURL";
// Name of a dictionary field holding the signed in user accounts.
const char kUserAccounts[] = "userAccounts";
// Get the print job settings dictionary from |json_str|. // Get the print job settings dictionary from |json_str|.
// Returns |base::Value()| on failure. // Returns |base::Value()| on failure.
...@@ -958,6 +960,18 @@ void PrintPreviewHandler::HandleGetInitialSettings( ...@@ -958,6 +960,18 @@ void PrintPreviewHandler::HandleGetInitialSettings(
weak_factory_.GetWeakPtr(), callback_id)); weak_factory_.GetWeakPtr(), callback_id));
} }
void PrintPreviewHandler::GetUserAccountList(base::Value* settings) {
base::Value account_list(base::Value::Type::LIST);
if (identity_manager_) {
const std::vector<gaia::ListedAccount>& accounts =
identity_manager_->GetAccountsInCookieJar().signed_in_accounts;
for (const gaia::ListedAccount& account : accounts) {
account_list.GetList().emplace_back(account.email);
}
}
settings->SetKey(kUserAccounts, std::move(account_list));
}
void PrintPreviewHandler::SendInitialSettings( void PrintPreviewHandler::SendInitialSettings(
const std::string& callback_id, const std::string& callback_id,
const std::string& default_printer) { const std::string& default_printer) {
...@@ -1010,6 +1024,10 @@ void PrintPreviewHandler::SendInitialSettings( ...@@ -1010,6 +1024,10 @@ void PrintPreviewHandler::SendInitialSettings(
} }
GetNumberFormatAndMeasurementSystem(&initial_settings); GetNumberFormatAndMeasurementSystem(&initial_settings);
if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) {
GetUserAccountList(&initial_settings);
}
ResolveJavascriptCallback(base::Value(callback_id), initial_settings); ResolveJavascriptCallback(base::Value(callback_id), initial_settings);
} }
...@@ -1313,17 +1331,21 @@ void PrintPreviewHandler::OnPrintResult(const std::string& callback_id, ...@@ -1313,17 +1331,21 @@ void PrintPreviewHandler::OnPrintResult(const std::string& callback_id,
void PrintPreviewHandler::RegisterForGaiaCookieChanges() { void PrintPreviewHandler::RegisterForGaiaCookieChanges() {
DCHECK(!identity_manager_); DCHECK(!identity_manager_);
Profile* profile = Profile::FromWebUI(web_ui()); Profile* profile = Profile::FromWebUI(web_ui());
identity_manager_ = IdentityManagerFactory::GetForProfile(profile);
if (AccountConsistencyModeManager::IsMirrorEnabledForProfile(profile)) { if (AccountConsistencyModeManager::IsMirrorEnabledForProfile(profile)) {
identity_manager_ = IdentityManagerFactory::GetForProfile(profile);
identity_manager_->AddObserver(this); identity_manager_->AddObserver(this);
} }
} }
void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { void PrintPreviewHandler::UnregisterForGaiaCookieChanges() {
if (identity_manager_) { if (!identity_manager_)
return;
Profile* profile = Profile::FromWebUI(web_ui());
if (AccountConsistencyModeManager::IsMirrorEnabledForProfile(profile)) {
identity_manager_->RemoveObserver(this); identity_manager_->RemoveObserver(this);
identity_manager_ = nullptr;
} }
identity_manager_ = nullptr;
} }
void PrintPreviewHandler::BadMessageReceived() { void PrintPreviewHandler::BadMessageReceived() {
......
...@@ -279,6 +279,9 @@ class PrintPreviewHandler : public content::WebUIMessageHandler, ...@@ -279,6 +279,9 @@ class PrintPreviewHandler : public content::WebUIMessageHandler,
// Populates |settings| according to the current locale. // Populates |settings| according to the current locale.
void GetNumberFormatAndMeasurementSystem(base::Value* settings); void GetNumberFormatAndMeasurementSystem(base::Value* settings);
// Populates |settings| with the list of logged in accounts.
void GetUserAccountList(base::Value* settings);
PdfPrinterHandler* GetPdfPrinterHandler(); PdfPrinterHandler* GetPdfPrinterHandler();
// Called when printers are detected. // Called when printers are detected.
......
...@@ -372,6 +372,8 @@ class PrintPreviewHandlerTest : public testing::Test { ...@@ -372,6 +372,8 @@ class PrintPreviewHandlerTest : public testing::Test {
ASSERT_TRUE( ASSERT_TRUE(
settings->FindKeyOfType("cloudPrintURL", base::Value::Type::STRING)); settings->FindKeyOfType("cloudPrintURL", base::Value::Type::STRING));
ASSERT_TRUE(
settings->FindKeyOfType("userAccounts", base::Value::Type::LIST));
} }
IPC::TestSink& initiator_sink() { IPC::TestSink& initiator_sink() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment