tab_specific_content_settings.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/content_settings/tab_specific_content_settings.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <list>
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/lazy_instance.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/utf_string_conversions.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browsing_data/browsing_data_appcache_helper.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browsing_data/cookies_tree_model.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/content_settings/content_settings_details.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/content_settings/content_settings_utils.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/content_settings/host_content_settings_map.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_notification_types.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/render_messages.h"
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/browser_thread.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_controller.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_details.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_entry.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/render_view_host.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/render_view_host_observer.h"
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents_delegate.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/cookies/canonical_cookie.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "webkit/fileapi/file_system_types.h"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::BrowserThread;
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::NavigationController;
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::NavigationEntry;
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::RenderViewHost;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::WebContents;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings);
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InterstitialHostObserver : public content::RenderViewHostObserver {
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit InterstitialHostObserver(RenderViewHost* rvh)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      : content::RenderViewHostObserver(rvh) {}
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // content::RenderViewHostObserver overrides.
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RenderViewHostInitialized() OVERRIDE {
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Send(new ChromeViewMsg_SetAsInterstitial(routing_id()));
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delete this;
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TabSpecificContentSettings::SiteDataObserver::SiteDataObserver(
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TabSpecificContentSettings* tab_specific_content_settings)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : tab_specific_content_settings_(tab_specific_content_settings) {
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_specific_content_settings_->AddSiteDataObserver(this);
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TabSpecificContentSettings::SiteDataObserver::~SiteDataObserver() {
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (tab_specific_content_settings_)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    tab_specific_content_settings_->RemoveSiteDataObserver(this);
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::SiteDataObserver::ContentSettingsDestroyed() {
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_specific_content_settings_ = NULL;
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TabSpecificContentSettings::TabSpecificContentSettings(WebContents* tab)
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : content::WebContentsObserver(tab),
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      profile_(Profile::FromBrowserContext(tab->GetBrowserContext())),
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      allowed_local_shared_objects_(profile_),
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      blocked_local_shared_objects_(profile_),
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      geolocation_settings_state_(profile_),
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()),
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()),
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT),
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      load_plugins_link_enabled_(true) {
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ClearBlockedContentSettingsExceptForCookies();
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ClearCookieSpecificContentSettings();
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  registrar_.Add(this, chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED,
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 content::Source<HostContentSettingsMap>(
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                     profile_->GetHostContentSettingsMap()));
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TabSpecificContentSettings::~TabSpecificContentSettings() {
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FOR_EACH_OBSERVER(
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      SiteDataObserver, observer_list_, ContentSettingsDestroyed());
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TabSpecificContentSettings* TabSpecificContentSettings::Get(
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int render_process_id, int render_view_id) {
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderViewHost* view = RenderViewHost::FromID(render_process_id,
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                render_view_id);
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!view)
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return NULL;
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  WebContents* web_contents = WebContents::FromRenderViewHost(view);
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!web_contents)
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return NULL;
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return TabSpecificContentSettings::FromWebContents(web_contents);
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::CookiesRead(int render_process_id,
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             int render_view_id,
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             const GURL& url,
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             const GURL& frame_url,
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             const net::CookieList& cookie_list,
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             bool blocked_by_policy) {
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TabSpecificContentSettings* settings = Get(render_process_id, render_view_id);
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (settings) {
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    settings->OnCookiesRead(url, frame_url, cookie_list,
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            blocked_by_policy);
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::CookieChanged(
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int render_process_id,
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int render_view_id,
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& url,
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& frame_url,
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::string& cookie_line,
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const net::CookieOptions& options,
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool blocked_by_policy) {
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TabSpecificContentSettings* settings = Get(render_process_id, render_view_id);
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (settings)
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    settings->OnCookieChanged(url, frame_url, cookie_line, options,
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              blocked_by_policy);
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::WebDatabaseAccessed(
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int render_process_id,
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int render_view_id,
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& url,
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const string16& name,
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const string16& display_name,
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool blocked_by_policy) {
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TabSpecificContentSettings* settings = Get(render_process_id, render_view_id);
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (settings)
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    settings->OnWebDatabaseAccessed(url, name, display_name, blocked_by_policy);
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::DOMStorageAccessed(int render_process_id,
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                    int render_view_id,
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                    const GURL& url,
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                    bool local,
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                    bool blocked_by_policy) {
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TabSpecificContentSettings* settings = Get(render_process_id, render_view_id);
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (settings)
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    settings->OnLocalStorageAccessed(url, local, blocked_by_policy);
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::IndexedDBAccessed(int render_process_id,
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                   int render_view_id,
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                   const GURL& url,
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                   const string16& description,
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                   bool blocked_by_policy) {
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TabSpecificContentSettings* settings = Get(render_process_id, render_view_id);
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (settings)
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    settings->OnIndexedDBAccessed(url, description, blocked_by_policy);
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::FileSystemAccessed(int render_process_id,
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                    int render_view_id,
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                    const GURL& url,
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                    bool blocked_by_policy) {
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TabSpecificContentSettings* settings = Get(render_process_id, render_view_id);
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (settings)
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    settings->OnFileSystemAccessed(url, blocked_by_policy);
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool TabSpecificContentSettings::IsContentBlocked(
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ContentSettingsType content_type) const {
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION)
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << "Geolocation settings handled by ContentSettingGeolocationImageModel";
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << "Notifications settings handled by "
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << "ContentSettingsNotificationsImageModel";
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (content_type == CONTENT_SETTINGS_TYPE_IMAGES ||
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT ||
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content_type == CONTENT_SETTINGS_TYPE_PLUGINS ||
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content_type == CONTENT_SETTINGS_TYPE_COOKIES ||
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content_type == CONTENT_SETTINGS_TYPE_POPUPS ||
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT ||
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM ||
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      content_type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return content_blocked_[content_type];
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return false;
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool TabSpecificContentSettings::IsBlockageIndicated(
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ContentSettingsType content_type) const {
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return content_blockage_indicated_to_user_[content_type];
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::SetBlockageHasBeenIndicated(
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ContentSettingsType content_type) {
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content_blockage_indicated_to_user_[content_type] = true;
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool TabSpecificContentSettings::IsContentAllowed(
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ContentSettingsType content_type) const {
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method currently only returns meaningful values for the content type
2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // cookies, mediastream, and PPAPI broker.
2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (content_type != CONTENT_SETTINGS_TYPE_COOKIES &&
2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM &&
2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      content_type != CONTENT_SETTINGS_TYPE_PPAPI_BROKER) {
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return content_allowed_[content_type];
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const std::set<std::string>&
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TabSpecificContentSettings::BlockedResourcesForType(
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        ContentSettingsType content_type) const {
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (blocked_resources_[content_type].get()) {
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return *blocked_resources_[content_type];
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CR_DEFINE_STATIC_LOCAL(std::set<std::string>, empty_set, ());
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return empty_set;
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::AddBlockedResource(
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ContentSettingsType content_type,
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::string& resource_identifier) {
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!blocked_resources_[content_type].get())
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    blocked_resources_[content_type].reset(new std::set<std::string>());
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  blocked_resources_[content_type]->insert(resource_identifier);
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::OnContentBlocked(
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ContentSettingsType type,
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::string& resource_identifier) {
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION)
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << "Geolocation settings handled by OnGeolocationPermissionSet";
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (type < 0 || type >= CONTENT_SETTINGS_NUM_TYPES)
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return;
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
267c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Media is different from other content setting types since it allows new
268c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // setting to kick in without reloading the page, and the UI for media is
269c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // always reflecting the newest permission setting.
270c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM)
271c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    content_allowed_[type] = false;
272c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  else
273c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    content_allowed_[type] = true;
2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Unless UI for resource content settings is enabled, ignore the resource
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // identifier.
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(bauerb): The UI to unblock content should be disabled if the content
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // setting was not set by the user.
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string identifier;
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (CommandLine::ForCurrentProcess()->HasSwitch(
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      switches::kEnableResourceContentSettings)) {
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    identifier = resource_identifier;
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!identifier.empty())
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AddBlockedResource(type, identifier);
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined (OS_ANDROID)
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (type == CONTENT_SETTINGS_TYPE_POPUPS) {
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // For Android we do not have a persistent button that will always be
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // visible for blocked popups.  Instead we have info bars which could be
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // dismissed.  Have to clear the blocked state so we properly notify the
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // relevant pieces again.
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content_blocked_[type] = false;
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content_blockage_indicated_to_user_[type] = false;
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!content_blocked_[type]) {
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content_blocked_[type] = true;
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // TODO: it would be nice to have a way of mocking this in tests.
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content::NotificationService::current()->Notify(
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        content::Source<WebContents>(web_contents()),
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        content::NotificationService::NoDetails());
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TabSpecificContentSettings::OnContentAllowed(ContentSettingsType type) {
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION)
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << "Geolocation settings handled by OnGeolocationPermissionSet";
3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool access_changed = false;
312c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
313c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // The setting for media is overwritten here because media does not need to
314c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // reload the page to have the new setting kick in. See issue/175993.
315c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (content_blocked_[type]) {
316c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      content_blocked_[type] = false;
317c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      access_changed = true;
318c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!content_allowed_[type]) {
3222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    content_allowed_[type] = true;
3232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    access_changed = true;
3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (access_changed) {
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content::NotificationService::current()->Notify(
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        content::Source<WebContents>(web_contents()),
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        content::NotificationService::NoDetails());
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::OnCookiesRead(
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& url,
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& frame_url,
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const net::CookieList& cookie_list,
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool blocked_by_policy) {
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (cookie_list.empty())
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (blocked_by_policy) {
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    blocked_local_shared_objects_.cookies()->AddReadCookies(
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        frame_url, url, cookie_list);
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string());
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    allowed_local_shared_objects_.cookies()->AddReadCookies(
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        frame_url, url, cookie_list);
3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES);
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NotifySiteDataObservers();
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::OnCookieChanged(
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& url,
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& frame_url,
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::string& cookie_line,
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const net::CookieOptions& options,
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool blocked_by_policy) {
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (blocked_by_policy) {
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    blocked_local_shared_objects_.cookies()->AddChangedCookie(
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        frame_url, url, cookie_line, options);
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string());
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    allowed_local_shared_objects_.cookies()->AddChangedCookie(
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        frame_url, url, cookie_line, options);
3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES);
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NotifySiteDataObservers();
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::OnIndexedDBAccessed(
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& url,
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const string16& description,
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool blocked_by_policy) {
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (blocked_by_policy) {
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    blocked_local_shared_objects_.indexed_dbs()->AddIndexedDB(
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url, description);
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string());
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    allowed_local_shared_objects_.indexed_dbs()->AddIndexedDB(
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url, description);
3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES);
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NotifySiteDataObservers();
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::OnLocalStorageAccessed(
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& url,
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool local,
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool blocked_by_policy) {
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LocalSharedObjectsContainer& container = blocked_by_policy ?
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      blocked_local_shared_objects_ : allowed_local_shared_objects_;
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CannedBrowsingDataLocalStorageHelper* helper =
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      local ? container.local_storages() : container.session_storages();
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  helper->AddLocalStorage(url);
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (blocked_by_policy)
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string());
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  else
4032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES);
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NotifySiteDataObservers();
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::OnWebDatabaseAccessed(
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& url,
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const string16& name,
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const string16& display_name,
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool blocked_by_policy) {
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (blocked_by_policy) {
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    blocked_local_shared_objects_.databases()->AddDatabase(
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url, UTF16ToUTF8(name), UTF16ToUTF8(display_name));
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string());
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    allowed_local_shared_objects_.databases()->AddDatabase(
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url, UTF16ToUTF8(name), UTF16ToUTF8(display_name));
4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES);
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NotifySiteDataObservers();
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::OnFileSystemAccessed(
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& url,
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool blocked_by_policy) {
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (blocked_by_policy) {
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    blocked_local_shared_objects_.file_systems()->AddFileSystem(url,
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        fileapi::kFileSystemTypeTemporary, 0);
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string());
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    allowed_local_shared_objects_.file_systems()->AddFileSystem(url,
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        fileapi::kFileSystemTypeTemporary, 0);
4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES);
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NotifySiteDataObservers();
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::OnGeolocationPermissionSet(
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& requesting_origin,
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool allowed) {
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin,
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                         allowed);
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationService::current()->Notify(
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::Source<WebContents>(web_contents()),
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::NotificationService::NoDetails());
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TabSpecificContentSettings::OnMediaStreamAllowed() {
4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  OnContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM);
4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() {
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < arraysize(content_blocked_); ++i) {
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (i == CONTENT_SETTINGS_TYPE_COOKIES)
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      continue;
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    blocked_resources_[i].reset();
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content_blocked_[i] = false;
4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    content_allowed_[i] = false;
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content_blockage_indicated_to_user_[i] = false;
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  load_plugins_link_enabled_ = true;
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationService::current()->Notify(
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::Source<WebContents>(web_contents()),
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::NotificationService::NoDetails());
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::ClearCookieSpecificContentSettings() {
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  blocked_local_shared_objects_.Reset();
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  allowed_local_shared_objects_.Reset();
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content_blocked_[CONTENT_SETTINGS_TYPE_COOKIES] = false;
4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content_allowed_[CONTENT_SETTINGS_TYPE_COOKIES] = false;
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content_blockage_indicated_to_user_[CONTENT_SETTINGS_TYPE_COOKIES] = false;
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationService::current()->Notify(
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::Source<WebContents>(web_contents()),
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::NotificationService::NoDetails());
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::SetPopupsBlocked(bool blocked) {
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content_blocked_[CONTENT_SETTINGS_TYPE_POPUPS] = blocked;
4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content_blockage_indicated_to_user_[CONTENT_SETTINGS_TYPE_POPUPS] = false;
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationService::current()->Notify(
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::Source<WebContents>(web_contents()),
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::NotificationService::NoDetails());
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::GeolocationDidNavigate(
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const content::LoadCommittedDetails& details) {
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  geolocation_settings_state_.DidNavigate(details);
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::ClearGeolocationContentSettings() {
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  geolocation_settings_state_.ClearStateMap();
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TabSpecificContentSettings::SetPepperBrokerAllowed(bool allowed) {
5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (allowed) {
5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    OnContentAllowed(CONTENT_SETTINGS_TYPE_PPAPI_BROKER);
5062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    OnContentBlocked(CONTENT_SETTINGS_TYPE_PPAPI_BROKER, std::string());
5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::RenderViewForInterstitialPageCreated(
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RenderViewHost* render_view_host) {
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We want to tell the renderer-side code to ignore content settings for this
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // page but we must wait until the RenderView is created.
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  new InterstitialHostObserver(render_view_host);
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool TabSpecificContentSettings::OnMessageReceived(
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const IPC::Message& message) {
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool handled = true;
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  IPC_BEGIN_MESSAGE_MAP(TabSpecificContentSettings, message)
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, OnContentBlocked)
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPC_MESSAGE_UNHANDLED(handled = false)
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  IPC_END_MESSAGE_MAP()
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return handled;
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::DidNavigateMainFrame(
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const content::LoadCommittedDetails& details,
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const content::FrameNavigateParams& params) {
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!details.is_in_page) {
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Clear "blocked" flags.
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ClearBlockedContentSettingsExceptForCookies();
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GeolocationDidNavigate(details);
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::DidStartProvisionalLoadForFrame(
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int64 frame_id,
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int64 parent_frame_id,
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool is_main_frame,
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& validated_url,
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool is_error_page,
5442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    bool is_iframe_srcdoc,
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RenderViewHost* render_view_host) {
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!is_main_frame)
5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If we're displaying a network error page do not reset the content
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // settings delegate's cookies so the user has a chance to modify cookie
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // settings.
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!is_error_page)
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ClearCookieSpecificContentSettings();
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ClearGeolocationContentSettings();
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url,
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                  bool blocked_by_policy) {
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (blocked_by_policy) {
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url);
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string());
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url);
5642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES);
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::Observe(
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int type,
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const content::NotificationSource& source,
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const content::NotificationDetails& details) {
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(type == chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED);
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::Details<const ContentSettingsDetails> settings_details(details);
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const NavigationController& controller = web_contents()->GetController();
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NavigationEntry* entry = controller.GetActiveEntry();
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL entry_url;
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (entry)
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    entry_url = entry->GetURL();
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (settings_details.ptr()->update_all() ||
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // The active NavigationEntry is the URL in the URL field of a tab.
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // Currently this should be matched by the |primary_pattern|.
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      settings_details.ptr()->primary_pattern().Matches(entry_url)) {
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Profile* profile =
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        Profile::FromBrowserContext(web_contents()->GetBrowserContext());
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RendererContentSettingRules rules;
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GetRendererContentSettingRules(profile->GetHostContentSettingsMap(),
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   &rules);
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Send(new ChromeViewMsg_SetContentSettingRules(rules));
5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::AddSiteDataObserver(
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SiteDataObserver* observer) {
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  observer_list_.AddObserver(observer);
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::RemoveSiteDataObserver(
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SiteDataObserver* observer) {
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  observer_list_.RemoveObserver(observer);
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TabSpecificContentSettings::NotifySiteDataObservers() {
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FOR_EACH_OBSERVER(SiteDataObserver, observer_list_, OnSiteDataAccessed());
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
606