| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/browser_tabstrip.h" | 5 #include "chrome/browser/ui/browser_tabstrip.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 9 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 return params.target_contents; | 87 return params.target_contents; |
| 88 } | 88 } |
| 89 | 89 |
| 90 void AddTab(Browser* browser, | 90 void AddTab(Browser* browser, |
| 91 TabContents* tab_contents, | 91 TabContents* tab_contents, |
| 92 content::PageTransition type) { | 92 content::PageTransition type) { |
| 93 browser->tab_strip_model()->AddTabContents(tab_contents, -1, type, | 93 browser->tab_strip_model()->AddTabContents(tab_contents, -1, type, |
| 94 TabStripModel::ADD_ACTIVE); | 94 TabStripModel::ADD_ACTIVE); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void AddWebContents(Browser* browser, | 97 bool AddWebContents(Browser* browser, |
| 98 content::WebContents* source_contents, | 98 content::WebContents* source_contents, |
| 99 content::WebContents* new_contents, | 99 content::WebContents* new_contents, |
| 100 WindowOpenDisposition disposition, | 100 WindowOpenDisposition disposition, |
| 101 const gfx::Rect& initial_pos, | 101 const gfx::Rect& initial_pos, |
| 102 bool user_gesture) { | 102 bool user_gesture) { |
| 103 // No code for this yet. | 103 // No code for this yet. |
| 104 DCHECK(disposition != SAVE_TO_DISK); | 104 DCHECK(disposition != SAVE_TO_DISK); |
| 105 // Can't create a new contents for the current tab - invalid case. | 105 // Can't create a new contents for the current tab - invalid case. |
| 106 DCHECK(disposition != CURRENT_TAB); | 106 DCHECK(disposition != CURRENT_TAB); |
| 107 | 107 |
| 108 TabContents* source_tab_contents = NULL; | 108 TabContents* source_tab_contents = NULL; |
| 109 BlockedContentTabHelper* source_blocked_content = NULL; | 109 BlockedContentTabHelper* source_blocked_content = NULL; |
| 110 TabContents* new_tab_contents = TabContents::FromWebContents(new_contents); | 110 TabContents* new_tab_contents = TabContents::FromWebContents(new_contents); |
| 111 if (!new_tab_contents) { | 111 if (!new_tab_contents) { |
| 112 new_tab_contents = | 112 new_tab_contents = |
| 113 BrowserTabstripTabContentsCreator::CreateTabContents(new_contents); | 113 BrowserTabstripTabContentsCreator::CreateTabContents(new_contents); |
| 114 } | 114 } |
| 115 if (source_contents) { | 115 if (source_contents) { |
| 116 source_tab_contents = TabContents::FromWebContents(source_contents); | 116 source_tab_contents = TabContents::FromWebContents(source_contents); |
| 117 source_blocked_content = source_tab_contents->blocked_content_tab_helper(); | 117 source_blocked_content = source_tab_contents->blocked_content_tab_helper(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 if (source_tab_contents) { | 120 if (source_tab_contents) { |
| 121 // Handle blocking of all contents. | 121 // Handle blocking of tabs, |
| 122 if (source_blocked_content->all_contents_blocked()) { | 122 if (source_blocked_content->all_contents_blocked()) { |
| 123 source_blocked_content->AddTabContents(new_tab_contents, | 123 source_blocked_content->AddTabContents( |
| 124 disposition, | 124 new_tab_contents, disposition, initial_pos, user_gesture); |
| 125 initial_pos, | 125 return false; |
| 126 user_gesture); | |
| 127 return; | |
| 128 } | 126 } |
| 129 | 127 |
| 130 // Handle blocking of popups. | 128 // Handle blocking of popups. |
| 131 if ((disposition == NEW_POPUP) && !user_gesture && | 129 if ((disposition == NEW_POPUP || disposition == NEW_FOREGROUND_TAB) && |
| 130 !user_gesture && |
| 132 !CommandLine::ForCurrentProcess()->HasSwitch( | 131 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 133 switches::kDisablePopupBlocking)) { | 132 switches::kDisablePopupBlocking)) { |
| 134 // Unrequested popups from normal pages are constrained unless they're in | 133 // Unrequested popups from normal pages are constrained unless they're in |
| 135 // the white list. The popup owner will handle checking this. | 134 // the white list. The popup owner will handle checking this. |
| 136 source_tab_contents->blocked_content_tab_helper()-> | 135 source_blocked_content->AddPopup( |
| 137 AddPopup(new_tab_contents, initial_pos, user_gesture); | 136 new_tab_contents, disposition, initial_pos, user_gesture); |
| 138 return; | 137 return false; |
| 139 } | 138 } |
| 140 | 139 |
| 141 new_contents->GetRenderViewHost()->DisassociateFromPopupCount(); | 140 new_contents->GetRenderViewHost()->DisassociateFromPopupCount(); |
| 142 } | 141 } |
| 143 | 142 |
| 144 NavigateParams params(browser, new_tab_contents); | 143 NavigateParams params(browser, new_tab_contents); |
| 145 params.source_contents = source_contents ? | 144 params.source_contents = source_contents ? |
| 146 GetTabContentsAt(browser, GetIndexOfTab(browser, source_contents)) : NULL; | 145 GetTabContentsAt(browser, GetIndexOfTab(browser, source_contents)) : NULL; |
| 147 params.disposition = disposition; | 146 params.disposition = disposition; |
| 148 params.window_bounds = initial_pos; | 147 params.window_bounds = initial_pos; |
| 149 params.window_action = NavigateParams::SHOW_WINDOW; | 148 params.window_action = NavigateParams::SHOW_WINDOW; |
| 150 params.user_gesture = user_gesture; | 149 params.user_gesture = user_gesture; |
| 151 Navigate(¶ms); | 150 Navigate(¶ms); |
| 151 return true; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void CloseWebContents(Browser* browser, content::WebContents* contents) { | 154 void CloseWebContents(Browser* browser, content::WebContents* contents) { |
| 155 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); | 155 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); |
| 156 if (index == TabStripModel::kNoTab) { | 156 if (index == TabStripModel::kNoTab) { |
| 157 NOTREACHED() << "CloseWebContents called for tab not in our strip"; | 157 NOTREACHED() << "CloseWebContents called for tab not in our strip"; |
| 158 return; | 158 return; |
| 159 } | 159 } |
| 160 browser->tab_strip_model()->CloseTabContentsAt( | 160 browser->tab_strip_model()->CloseTabContentsAt( |
| 161 index, | 161 index, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 187 return BrowserTabstripTabContentsCreator::CreateTabContents( | 187 return BrowserTabstripTabContentsCreator::CreateTabContents( |
| 188 content::WebContents::CreateWithSessionStorage( | 188 content::WebContents::CreateWithSessionStorage( |
| 189 profile, | 189 profile, |
| 190 site_instance, | 190 site_instance, |
| 191 routing_id, | 191 routing_id, |
| 192 base_web_contents, | 192 base_web_contents, |
| 193 session_storage_namespace_map)); | 193 session_storage_namespace_map)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 } // namespace chrome | 196 } // namespace chrome |
| OLD | NEW |