Commit 2b79ebba authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Update HatsWebDialog's usage of OTR profiles.

IndependentOTRProfileManager is deprecated. Usage of it in
HatsWebDialog is replaced by profile API functions.

Bug: 1033903
Change-Id: Ie531e0c319351c20ea69d9faa2065803a2e08573
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2153073
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760390}
parent e08bd060
......@@ -167,7 +167,7 @@ IN_PROC_BROWSER_TEST_F(HatsWebDialogBrowserTest, Cookies) {
Create(browser(), base::TimeDelta::FromSeconds(100));
settings_map = HostContentSettingsMapFactory::GetForProfile(
dialog->off_the_record_profile());
dialog->otr_profile_for_testing());
GURL url1("https://survey.google.com/");
GURL url2("https://survey.g.doubleclick.net/");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
......
......@@ -11,6 +11,7 @@
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_destroyer.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/hats/hats_bubble_view.h"
......@@ -76,21 +77,17 @@ void HatsWebDialog::Create(Browser* browser, const std::string& site_id) {
}
HatsWebDialog::HatsWebDialog(Browser* browser, const std::string& site_id)
: otr_profile_registration_(
IndependentOTRProfileManager::GetInstance()
->CreateFromOriginalProfile(
browser->profile(),
base::BindOnce(&HatsWebDialog::OnOriginalProfileDestroyed,
base::Unretained(this)))),
: otr_profile_(browser->profile()->GetOffTheRecordProfile(
Profile::OTRProfileID::CreateUnique("HaTS:WebDialog"))),
browser_(browser),
site_id_(site_id) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Profile* profile = off_the_record_profile();
DCHECK(profile->IsIndependentOffTheRecordProfile());
otr_profile_->AddObserver(this);
// As this is not a user-facing profile, force enable cookies for the
// resources loaded by HaTS.
auto* settings_map = HostContentSettingsMapFactory::GetForProfile(profile);
auto* settings_map =
HostContentSettingsMapFactory::GetForProfile(otr_profile_);
settings_map->SetContentSettingCustomScope(
ContentSettingsPattern::FromString("[*.]google.com"),
ContentSettingsPattern::Wildcard(), ContentSettingsType::COOKIES,
......@@ -103,6 +100,10 @@ HatsWebDialog::HatsWebDialog(Browser* browser, const std::string& site_id)
HatsWebDialog::~HatsWebDialog() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (otr_profile_) {
otr_profile_->RemoveObserver(this);
ProfileDestroyer::DestroyProfileWhenAppropriate(otr_profile_);
}
}
ui::ModalType HatsWebDialog::GetDialogModalType() const {
......@@ -230,10 +231,9 @@ const base::TimeDelta HatsWebDialog::ContentLoadingTimeout() const {
void HatsWebDialog::CreateWebDialog(Browser* browser) {
// Create a web dialog aligned to the bottom center of the location bar.
DialogDelegate::SetButtons(ui::DIALOG_BUTTON_NONE);
webview_ =
new views::WebDialogView(off_the_record_profile(), this,
std::make_unique<ChromeWebContentsHandler>(),
/* use_dialog_frame= */ true);
webview_ = new views::WebDialogView(
otr_profile_, this, std::make_unique<ChromeWebContentsHandler>(),
/* use_dialog_frame= */ true);
webview_->SetPreferredSize(
gfx::Size(kDefaultHatsDialogWidth, kDefaultHatsDialogHeight));
preloading_widget_ = constrained_window::CreateBrowserModalDialogViews(
......@@ -255,10 +255,9 @@ void HatsWebDialog::CreateWebDialog(Browser* browser) {
weak_factory_.GetWeakPtr()));
}
void HatsWebDialog::OnOriginalProfileDestroyed(Profile* profile) {
if (otr_profile_registration_ &&
profile == otr_profile_registration_->profile())
otr_profile_registration_.reset();
void HatsWebDialog::OnProfileWillBeDestroyed(Profile* profile) {
DCHECK(profile == otr_profile_);
otr_profile_ = nullptr;
}
void HatsWebDialog::Show(views::Widget* widget, bool accept) {
......
......@@ -11,7 +11,7 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/timer/timer.h"
#include "chrome/browser/profiles/independent_otr_profile_manager.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "ui/views/window/dialog_delegate.h"
#include "ui/web_dialogs/web_dialog_delegate.h"
......@@ -28,7 +28,8 @@ class Widget;
// TODO(weili): This dialog shares a lot of common code with the one in
// chrome/browser/chromeos/hats/, should be merged into one.
class HatsWebDialog : public ui::WebDialogDelegate,
public views::DialogDelegateView {
public views::DialogDelegateView,
public ProfileObserver {
public:
// Create an instance of HatsWebDialog and load its content without showing.
static void Create(Browser* browser, const std::string& site_id);
......@@ -73,16 +74,14 @@ class HatsWebDialog : public ui::WebDialogDelegate,
virtual void OnLoadTimedOut();
virtual const base::TimeDelta ContentLoadingTimeout() const;
Profile* off_the_record_profile() {
return otr_profile_registration_->profile();
}
Profile* otr_profile_for_testing() { return otr_profile_; }
void CreateWebDialog(Browser* browser);
void OnOriginalProfileDestroyed(Profile* profile);
// ProfileObserver:
void OnProfileWillBeDestroyed(Profile* profile) override;
void Show(views::Widget* widget, bool accept);
std::unique_ptr<IndependentOTRProfileManager::OTRProfileRegistration>
otr_profile_registration_;
Profile* otr_profile_;
Browser* browser_;
const std::string site_id_;
......@@ -91,11 +90,11 @@ class HatsWebDialog : public ui::WebDialogDelegate,
// The widget created for preloading. It is owned by us until it is shown to
// user.
views::Widget* preloading_widget_{nullptr};
views::WebDialogView* webview_{nullptr};
views::Widget* preloading_widget_ = nullptr;
views::WebDialogView* webview_ = nullptr;
// Indicate whether HaTS resources were loaded successfully.
bool resource_loaded_{false};
bool resource_loaded_ = false;
base::WeakPtrFactory<HatsWebDialog> weak_factory_{this};
......
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