| Index: chrome/browser/ui/content_settings/content_settings_tab_helper.cc
|
| diff --git a/chrome/browser/ui/content_settings/content_settings_tab_helper.cc b/chrome/browser/ui/content_settings/content_settings_tab_helper.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..290eb869dd6a5e703fb021eab26651508636cd96
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/content_settings/content_settings_tab_helper.cc
|
| @@ -0,0 +1,144 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/content_settings/content_settings_tab_helper.h"
|
| +
|
| +#include "base/auto_reset.h"
|
| +#include "chrome/browser/content_settings/content_settings_details.h"
|
| +#include "chrome/browser/content_settings/host_content_settings_map.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/ui/content_settings/blocked_content_container.h"
|
| +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
|
| +#include "content/browser/renderer_host/render_view_host.h"
|
| +#include "content/browser/tab_contents/tab_contents.h"
|
| +#include "content/common/notification_service.h"
|
| +
|
| +ContentSettingsTabHelper::ContentSettingsTabHelper(
|
| + TabContentsWrapper* tab_contents)
|
| + : TabContentsObserver(tab_contents->tab_contents()),
|
| + blocked_contents_(new BlockedContentContainer(tab_contents)),
|
| + all_contents_blocked_(false),
|
| + dont_notify_render_view_(false),
|
| + tab_contents_wrapper_(tab_contents) {
|
| + registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
|
| + NotificationService::AllSources());
|
| +}
|
| +
|
| +ContentSettingsTabHelper::~ContentSettingsTabHelper() {
|
| + registrar_.RemoveAll();
|
| +}
|
| +
|
| +void ContentSettingsTabHelper::DidNavigateMainFramePostCommit(
|
| + const NavigationController::LoadCommittedDetails& details,
|
| + const ViewHostMsg_FrameNavigate_Params& params) {
|
| + // Clear all page actions, blocked content notifications and browser actions
|
| + // for this tab, unless this is an in-page navigation.
|
| + if (!details.is_in_page) {
|
| + // Close blocked popups.
|
| + if (blocked_contents_->GetBlockedContentsCount()) {
|
| + AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
|
| + blocked_contents_->Clear();
|
| + PopupNotificationVisibilityChanged(false);
|
| + }
|
| + }
|
| +}
|
| +
|
| +void ContentSettingsTabHelper::Observe(NotificationType type,
|
| + const NotificationSource& source,
|
| + const NotificationDetails& details) {
|
| + switch (type.value) {
|
| + case NotificationType::CONTENT_SETTINGS_CHANGED: {
|
| + Details<const ContentSettingsDetails> settings_details(details);
|
| + NavigationEntry* entry = tab_contents()->controller().GetActiveEntry();
|
| + GURL entry_url;
|
| + if (entry)
|
| + entry_url = entry->url();
|
| + if (settings_details.ptr()->update_all() ||
|
| + settings_details.ptr()->pattern().Matches(entry_url)) {
|
| + tab_contents()->render_view_host()->SendContentSettings(
|
| + entry_url,
|
| + tab_contents()->profile()->GetHostContentSettingsMap()->
|
| + GetContentSettings(entry_url));
|
| + }
|
| + break;
|
| + }
|
| +
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| +}
|
| +
|
| +void ContentSettingsTabHelper::PopupNotificationVisibilityChanged(
|
| + bool visible) {
|
| + if (tab_contents()->is_being_destroyed())
|
| + return;
|
| + tab_contents()->GetTabSpecificContentSettings()->SetPopupsBlocked(visible);
|
| + if (!dont_notify_render_view_)
|
| + tab_contents()->render_view_host()->AllowScriptToClose(!visible);
|
| +}
|
| +
|
| +void ContentSettingsTabHelper::SetAllContentsBlocked(bool value) {
|
| + if (all_contents_blocked_ == value)
|
| + return;
|
| +
|
| + all_contents_blocked_ = value;
|
| + if (!all_contents_blocked_ && blocked_contents_->GetBlockedContentsCount()) {
|
| + std::vector<TabContentsWrapper*> blocked;
|
| + blocked_contents_->GetBlockedContents(&blocked);
|
| + for (size_t i = 0; i < blocked.size(); ++i)
|
| + blocked_contents_->LaunchForContents(blocked[i]);
|
| + }
|
| +}
|
| +
|
| +void ContentSettingsTabHelper::AddTabContents(TabContentsWrapper* new_contents,
|
| + WindowOpenDisposition disposition,
|
| + const gfx::Rect& initial_pos,
|
| + bool user_gesture) {
|
| + if (!blocked_contents_->GetBlockedContentsCount())
|
| + PopupNotificationVisibilityChanged(true);
|
| + blocked_contents_->AddTabContents(new_contents, disposition, initial_pos,
|
| + user_gesture);
|
| +}
|
| +
|
| +void ContentSettingsTabHelper::AddPopup(TabContentsWrapper* new_contents,
|
| + const gfx::Rect& initial_pos) {
|
| + // A page can't spawn popups (or do anything else, either) until its load
|
| + // commits, so when we reach here, the popup was spawned by the
|
| + // NavigationController's last committed entry, not the active entry. For
|
| + // example, if a page opens a popup in an onunload() handler, then the active
|
| + // entry is the page to be loaded as we navigate away from the unloading
|
| + // page. For this reason, we can't use GetURL() to get the opener URL,
|
| + // because it returns the active entry.
|
| + NavigationEntry* entry = tab_contents()->controller().GetLastCommittedEntry();
|
| + GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
|
| +
|
| + if (creator.is_valid() &&
|
| + tab_contents()->profile()->GetHostContentSettingsMap()->GetContentSetting(
|
| + creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
|
| + tab_contents()->AddNewContents(new_contents->tab_contents(), NEW_POPUP,
|
| + initial_pos, true);
|
| + } else {
|
| + blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
|
| + true);
|
| + tab_contents()->GetContentSettingsDelegate()->OnContentBlocked(
|
| + CONTENT_SETTINGS_TYPE_POPUPS, std::string());
|
| + }
|
| +}
|
| +
|
| +void ContentSettingsTabHelper::LaunchForContents(
|
| + TabContentsWrapper* tab_contents) {
|
| + blocked_contents_->LaunchForContents(tab_contents);
|
| + if (!blocked_contents_->GetBlockedContentsCount())
|
| + PopupNotificationVisibilityChanged(false);
|
| +}
|
| +
|
| +size_t ContentSettingsTabHelper::GetBlockedContentsCount() const {
|
| + return blocked_contents_->GetBlockedContentsCount();
|
| +}
|
| +
|
| +void ContentSettingsTabHelper::GetBlockedContents(
|
| + std::vector<TabContentsWrapper*>* blocked_contents) const {
|
| + blocked_contents_->GetBlockedContents(blocked_contents);
|
| +}
|
| +
|
|
|