Commit 7b4bf4d1 authored by mkwst's avatar mkwst Committed by Commit bot

Credential Manager: Stub out the browser-side IPC handlers.

BUG=400674
TBR=palmer@chromium.org

Review URL: https://codereview.chromium.org/496703002

Cr-Commit-Position: refs/heads/master@{#292852}
parent 95dc7bfd
......@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/memory/singleton.h"
#include "base/metrics/histogram.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/password_manager/password_manager_util.h"
#include "chrome/browser/password_manager/password_store_factory.h"
......@@ -25,6 +26,8 @@
#include "components/autofill/core/browser/password_generator.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/content/browser/password_manager_internals_service_factory.h"
#include "components/password_manager/content/common/credential_manager_messages.h"
#include "components/password_manager/content/common/credential_manager_types.h"
#include "components/password_manager/core/browser/log_receiver.h"
#include "components/password_manager/core/browser/password_form_manager.h"
#include "components/password_manager/core/browser/password_manager.h"
......@@ -282,6 +285,46 @@ bool ChromePasswordManagerClient::IsLoggingActive() const {
return can_use_log_router_ && !web_contents()->GetWebUI();
}
void ChromePasswordManagerClient::OnNotifyFailedSignIn(
int request_id,
const password_manager::CredentialInfo&) {
// TODO(mkwst): This is a stub.
web_contents()->GetRenderViewHost()->Send(
new CredentialManagerMsg_AcknowledgeFailedSignIn(
web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
}
void ChromePasswordManagerClient::OnNotifySignedIn(
int request_id,
const password_manager::CredentialInfo&) {
// TODO(mkwst): This is a stub.
web_contents()->GetRenderViewHost()->Send(
new CredentialManagerMsg_AcknowledgeSignedIn(
web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
}
void ChromePasswordManagerClient::OnNotifySignedOut(int request_id) {
// TODO(mkwst): This is a stub.
web_contents()->GetRenderViewHost()->Send(
new CredentialManagerMsg_AcknowledgeSignedOut(
web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
}
void ChromePasswordManagerClient::OnRequestCredential(
int request_id,
bool zero_click_only,
const std::vector<GURL>& federations) {
// TODO(mkwst): This is a stub.
password_manager::CredentialInfo info(base::ASCIIToUTF16("id"),
base::ASCIIToUTF16("name"),
GURL("https://example.com/image.png"));
web_contents()->GetRenderViewHost()->Send(
new CredentialManagerMsg_SendCredential(
web_contents()->GetRenderViewHost()->GetRoutingID(),
request_id,
info));
}
// static
password_manager::PasswordGenerationManager*
ChromePasswordManagerClient::GetGenerationManagerFromWebContents(
......@@ -313,6 +356,7 @@ bool ChromePasswordManagerClient::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ChromePasswordManagerClient, message)
// Autofill messages:
IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup,
ShowPasswordGenerationPopup)
IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordEditingPopup,
......@@ -321,6 +365,18 @@ bool ChromePasswordManagerClient::OnMessageReceived(
HidePasswordGenerationPopup)
IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordAutofillAgentConstructed,
NotifyRendererOfLoggingAvailability)
// Credential Manager messages:
IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifyFailedSignIn,
OnNotifyFailedSignIn);
IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifySignedIn,
OnNotifySignedIn);
IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifySignedOut,
OnNotifySignedOut);
IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_RequestCredential,
OnRequestCredential);
// Default:
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
......
......@@ -25,6 +25,7 @@ class WebContents;
}
namespace password_manager {
struct CredentialInfo;
class PasswordGenerationManager;
class PasswordManager;
}
......@@ -65,6 +66,17 @@ class ChromePasswordManagerClient
virtual void OnLogRouterAvailabilityChanged(bool router_can_be_used) OVERRIDE;
virtual void LogSavePasswordProgress(const std::string& text) OVERRIDE;
virtual bool IsLoggingActive() const OVERRIDE;
virtual void OnNotifyFailedSignIn(
int request_id,
const password_manager::CredentialInfo&) OVERRIDE;
virtual void OnNotifySignedIn(
int request_id,
const password_manager::CredentialInfo&) OVERRIDE;
virtual void OnNotifySignedOut(int request_id) OVERRIDE;
virtual void OnRequestCredential(
int request_id,
bool zero_click_only,
const std::vector<GURL>& federations) OVERRIDE;
// Hides any visible generation UI.
void HidePasswordGenerationPopup();
......
......@@ -2,15 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "base/command_line.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/content/common/autofill_messages.h"
#include "components/password_manager/content/browser/password_manager_internals_service_factory.h"
#include "components/password_manager/content/common/credential_manager_messages.h"
#include "components/password_manager/content/common/credential_manager_types.h"
#include "components/password_manager/core/browser/log_receiver.h"
#include "components/password_manager/core/browser/password_manager_internals_service.h"
#include "components/password_manager/core/common/password_manager_switches.h"
......@@ -26,6 +29,7 @@ using content::WebContents;
namespace {
const char kTestText[] = "abcd1234";
const int kRequestId = 4;
class MockLogReceiver : public password_manager::LogReceiver {
public:
......@@ -321,3 +325,62 @@ TEST_F(ChromePasswordManagerClientTest,
"https://passwords.google.com&rart=234"));
EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage());
}
TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnNotifyFailedSignIn) {
scoped_ptr<TestChromePasswordManagerClient> client(
new TestChromePasswordManagerClient(web_contents()));
password_manager::CredentialInfo info(base::ASCIIToUTF16("id"),
base::ASCIIToUTF16("name"),
GURL("https://example.com/image.png"));
client->OnNotifyFailedSignIn(kRequestId, info);
const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID;
const IPC::Message* message =
process()->sink().GetFirstMessageMatching(kMsgID);
EXPECT_TRUE(message);
process()->sink().ClearMessages();
}
TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnNotifySignedIn) {
scoped_ptr<TestChromePasswordManagerClient> client(
new TestChromePasswordManagerClient(web_contents()));
password_manager::CredentialInfo info(base::ASCIIToUTF16("id"),
base::ASCIIToUTF16("name"),
GURL("https://example.com/image.png"));
client->OnNotifySignedIn(kRequestId, info);
const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID;
const IPC::Message* message =
process()->sink().GetFirstMessageMatching(kMsgID);
EXPECT_TRUE(message);
process()->sink().ClearMessages();
}
TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnNotifySignedOut) {
scoped_ptr<TestChromePasswordManagerClient> client(
new TestChromePasswordManagerClient(web_contents()));
client->OnNotifySignedOut(kRequestId);
const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedOut::ID;
const IPC::Message* message =
process()->sink().GetFirstMessageMatching(kMsgID);
EXPECT_TRUE(message);
process()->sink().ClearMessages();
}
TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnRequestCredential) {
scoped_ptr<TestChromePasswordManagerClient> client(
new TestChromePasswordManagerClient(web_contents()));
std::vector<GURL> federations;
client->OnRequestCredential(kRequestId, false, federations);
const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
const IPC::Message* message =
process()->sink().GetFirstMessageMatching(kMsgID);
EXPECT_TRUE(message);
process()->sink().ClearMessages();
}
......@@ -13,14 +13,10 @@
#include "content/public/common/common_param_traits_macros.h"
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_message_utils.h"
#include "third_party/WebKit/public/platform/WebCredentialManagerError.h"
#include "url/gurl.h"
#define IPC_MESSAGE_START CredentialManagerMsgStart
IPC_ENUM_TRAITS_MAX_VALUE(blink::WebCredentialManagerError::ErrorType,
blink::WebCredentialManagerError::ErrorTypeLast);
IPC_ENUM_TRAITS_MAX_VALUE(password_manager::CredentialType,
password_manager::CREDENTIAL_TYPE_LAST);
......
......@@ -14,6 +14,7 @@ class PrefService;
namespace password_manager {
struct CredentialInfo;
class PasswordFormManager;
class PasswordManagerDriver;
class PasswordStore;
......@@ -114,6 +115,24 @@ class PasswordManagerClient {
virtual PasswordStore::AuthorizationPromptPolicy GetAuthorizationPromptPolicy(
const autofill::PasswordForm& form);
// Called in response to an IPC from the renderer, triggered by a page's call
// to 'navigator.credentials.notifyFailedSignIn'.
virtual void OnNotifyFailedSignIn(int request_id, const CredentialInfo&) {}
// Called in response to an IPC from the renderer, triggered by a page's call
// to 'navigator.credentials.notifySignedIn'.
virtual void OnNotifySignedIn(int request_id, const CredentialInfo&) {}
// Called in response to an IPC from the renderer, triggered by a page's call
// to 'navigator.credentials.notifySignedOut'.
virtual void OnNotifySignedOut(int request_id) {}
// Called in response to an IPC from the renderer, triggered by a page's call
// to 'navigator.credentials.request'.
virtual void OnRequestCredential(int request_id,
bool zero_click_only,
const std::vector<GURL>& federations) {}
private:
DISALLOW_COPY_AND_ASSIGN(PasswordManagerClient);
};
......
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