Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: chrome/browser/ui/blocked_content/blocked_content_tab_helper.cc

Issue 6854035: Move blocked content from TabContents to TabContentsWrapper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
6
7 #include "base/auto_reset.h"
8 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/blocked_content/blocked_content_container.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
12 #include "content/browser/renderer_host/render_view_host.h"
13 #include "content/browser/tab_contents/tab_contents.h"
14 #include "content/common/notification_service.h"
15
16 BlockedContentTabHelper::BlockedContentTabHelper(
17 TabContentsWrapper* tab_contents)
18 : TabContentsObserver(tab_contents->tab_contents()),
19 blocked_contents_(new BlockedContentContainer(tab_contents)),
20 all_contents_blocked_(false),
21 tab_contents_wrapper_(tab_contents) {
22 }
23
24 BlockedContentTabHelper::~BlockedContentTabHelper() {
25 }
26
27 void BlockedContentTabHelper::DidNavigateMainFramePostCommit(
28 const NavigationController::LoadCommittedDetails& details,
29 const ViewHostMsg_FrameNavigate_Params& params) {
30 // Clear all page actions, blocked content notifications and browser actions
31 // for this tab, unless this is an in-page navigation.
32 if (!details.is_in_page) {
33 // Close blocked popups.
34 if (blocked_contents_->GetBlockedContentsCount()) {
35 blocked_contents_->Clear();
36 PopupNotificationVisibilityChanged(false);
37 }
38 }
39 }
40
41 void BlockedContentTabHelper::PopupNotificationVisibilityChanged(
42 bool visible) {
43 if (tab_contents()->is_being_destroyed())
44 return;
45 tab_contents()->GetTabSpecificContentSettings()->SetPopupsBlocked(visible);
46 }
47
48 void BlockedContentTabHelper::SetAllContentsBlocked(bool value) {
49 if (all_contents_blocked_ == value)
50 return;
51
52 all_contents_blocked_ = value;
53 if (!all_contents_blocked_ && blocked_contents_->GetBlockedContentsCount()) {
54 std::vector<TabContentsWrapper*> blocked;
55 blocked_contents_->GetBlockedContents(&blocked);
56 for (size_t i = 0; i < blocked.size(); ++i)
57 blocked_contents_->LaunchForContents(blocked[i]);
58 }
59 }
60
61 void BlockedContentTabHelper::AddTabContents(TabContentsWrapper* new_contents,
62 WindowOpenDisposition disposition,
63 const gfx::Rect& initial_pos,
64 bool user_gesture) {
65 if (!blocked_contents_->GetBlockedContentsCount())
66 PopupNotificationVisibilityChanged(true);
67 blocked_contents_->AddTabContents(new_contents, disposition, initial_pos,
68 user_gesture);
69 }
70
71 void BlockedContentTabHelper::AddPopup(TabContentsWrapper* new_contents,
72 const gfx::Rect& initial_pos,
73 bool user_gesture) {
74 // A page can't spawn popups (or do anything else, either) until its load
75 // commits, so when we reach here, the popup was spawned by the
76 // NavigationController's last committed entry, not the active entry. For
77 // example, if a page opens a popup in an onunload() handler, then the active
78 // entry is the page to be loaded as we navigate away from the unloading
79 // page. For this reason, we can't use GetURL() to get the opener URL,
80 // because it returns the active entry.
81 NavigationEntry* entry = tab_contents()->controller().GetLastCommittedEntry();
82 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
83
84 if (creator.is_valid() &&
85 tab_contents()->profile()->GetHostContentSettingsMap()->GetContentSetting(
86 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
87 tab_contents()->AddNewContents(new_contents->tab_contents(),
88 NEW_POPUP,
89 initial_pos,
90 true); // user_gesture
91 } else {
92 // Call blocked_contents_->AddTabContents with user_gesture == true
93 // so that the contents will not get blocked again.
94 // TODO(stevenjb): Remove user_gesture parameter from
95 // BlockedContentContainer::AddTabContents()?
stevenjb 2011/04/21 19:03:00 As long as this is getting re-factored, it might b
Avi (use Gerrit) 2011/04/21 20:06:02 Done.
96 blocked_contents_->AddTabContents(new_contents,
97 NEW_POPUP,
98 initial_pos,
99 true); // user gesture
100 tab_contents()->GetContentSettingsDelegate()->OnContentBlocked(
101 CONTENT_SETTINGS_TYPE_POPUPS, std::string());
102 }
103 }
104
105 void BlockedContentTabHelper::LaunchForContents(
106 TabContentsWrapper* tab_contents) {
107 blocked_contents_->LaunchForContents(tab_contents);
108 if (!blocked_contents_->GetBlockedContentsCount())
109 PopupNotificationVisibilityChanged(false);
110 }
111
112 size_t BlockedContentTabHelper::GetBlockedContentsCount() const {
113 return blocked_contents_->GetBlockedContentsCount();
114 }
115
116 void BlockedContentTabHelper::GetBlockedContents(
117 std::vector<TabContentsWrapper*>* blocked_contents) const {
118 blocked_contents_->GetBlockedContents(blocked_contents);
119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698