Commit cc12a6ab authored by scheib's avatar scheib Committed by Commit bot

Listen to Off The Record profiles in ContentSettingsHandler.

ContentSettingsHandler is now made aware of Off The Record profiles
and will observe them as well, correcting bugs where changes from the
settings webUI would function incorrectly.

This is a rework of a previously landed fix [fix] which was reverted due to
a crash bug [crash] when OTR profiles already existed before settings
were opened.

[fix] https://codereview.chromium.org/585953003
[crash] https://code.google.com/p/chromium/issues/detail?id=417597

BUG=425079, 418931

Committed: https://crrev.com/c9ba380c606442a025a38eb67f4d35c65b1a293c
Cr-Commit-Position: refs/heads/master@{#301273}

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

Cr-Commit-Position: refs/heads/master@{#301461}
parent 38a057db
......@@ -9,6 +9,7 @@
#include <vector>
#include "base/basictypes.h"
#include "base/logging.h"
// ScopedObserver is used to keep track of the set of sources an object has
// attached itself to as an observer. When ScopedObserver is destroyed it
......@@ -30,7 +31,9 @@ class ScopedObserver {
// Remove the object passed to the constructor as an observer from |source|.
void Remove(Source* source) {
sources_.erase(std::find(sources_.begin(), sources_.end(), source));
auto it = std::find(sources_.begin(), sources_.end(), source);
DCHECK(it != sources_.end());
sources_.erase(it);
source->RemoveObserver(observer_);
}
......
......@@ -497,7 +497,14 @@ void ContentSettingsHandler::InitializeHandler() {
base::Unretained(this)));
flash_settings_manager_.reset(new PepperFlashSettingsManager(this, context));
observer_.Add(Profile::FromWebUI(web_ui())->GetHostContentSettingsMap());
Profile* profile = Profile::FromWebUI(web_ui());
observer_.Add(profile->GetHostContentSettingsMap());
if (profile->HasOffTheRecordProfile()) {
auto map = profile->GetOffTheRecordProfile()->GetHostContentSettingsMap();
if (!observer_.IsObserving(map))
observer_.Add(map);
}
}
void ContentSettingsHandler::InitializePage() {
......@@ -529,16 +536,22 @@ void ContentSettingsHandler::Observe(
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_PROFILE_DESTROYED: {
if (content::Source<Profile>(source).ptr()->IsOffTheRecord()) {
Profile* profile = content::Source<Profile>(source).ptr();
if (profile->IsOffTheRecord() &&
observer_.IsObserving(profile->GetHostContentSettingsMap())) {
web_ui()->CallJavascriptFunction(
"ContentSettingsExceptionsArea.OTRProfileDestroyed");
observer_.Remove(profile->GetHostContentSettingsMap());
}
break;
}
case chrome::NOTIFICATION_PROFILE_CREATED: {
if (content::Source<Profile>(source).ptr()->IsOffTheRecord())
Profile* profile = content::Source<Profile>(source).ptr();
if (profile->IsOffTheRecord()) {
UpdateAllOTRExceptionsViewsFromModel();
observer_.Add(profile->GetHostContentSettingsMap());
}
break;
}
......
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