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

Side by Side Diff: chrome/browser/printing/print_preview_tab_controller.cc

Issue 7574002: Be able to print items that do window.print(); window.close() (airline tix e.g.) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 9 years, 4 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/printing/print_preview_tab_controller.h" 5 #include "chrome/browser/printing/print_preview_tab_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/stack_trace.h"
8 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/printing/background_printing_manager.h"
10 #include "chrome/browser/sessions/restore_tab_helper.h" 12 #include "chrome/browser/sessions/restore_tab_helper.h"
11 #include "chrome/browser/tabs/tab_strip_model.h" 13 #include "chrome/browser/tabs/tab_strip_model.h"
12 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h" 15 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/browser_navigator.h" 16 #include "chrome/browser/ui/browser_navigator.h"
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
16 #include "chrome/browser/ui/webui/print_preview_ui.h" 18 #include "chrome/browser/ui/webui/print_preview_ui.h"
17 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
19 #include "content/browser/tab_contents/navigation_details.h" 21 #include "content/browser/tab_contents/navigation_details.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (source_tab_is_preview_tab && 133 if (source_tab_is_preview_tab &&
132 transition_type == PageTransition::FORWARD_BACK && 134 transition_type == PageTransition::FORWARD_BACK &&
133 nav_type == NavigationType::EXISTING_PAGE) { 135 nav_type == NavigationType::EXISTING_PAGE) {
134 return; 136 return;
135 } 137 }
136 } 138 }
137 139
138 if (source_tab_is_preview_tab) { 140 if (source_tab_is_preview_tab) {
139 // Remove the initiator tab's observers before erasing the mapping. 141 // Remove the initiator tab's observers before erasing the mapping.
140 TabContents* initiator_tab = GetInitiatorTab(source_tab); 142 TabContents* initiator_tab = GetInitiatorTab(source_tab);
141 if (initiator_tab) 143 if (initiator_tab) {
142 RemoveObservers(initiator_tab); 144 RemoveObservers(initiator_tab);
145 TabContentsWrapper* initiator_wrapper =
146 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab);
147 g_browser_process->background_printing_manager()->
148 ReleaseInitiatorTabContents(initiator_wrapper);
149 }
143 150
144 // |source_tab_is_preview_tab| is misleading in the case where the user 151 // |source_tab_is_preview_tab| is misleading in the case where the user
145 // chooses to re-open the initiator tab after closing it, as |source_tab| 152 // chooses to re-open the initiator tab after closing it, as |source_tab|
146 // has navigated to the URL of the initiator tab at this point. Make sure to 153 // has navigated to the URL of the initiator tab at this point. Make sure to
147 // verify that |source_tab| really is a print preview tab. 154 // verify that |source_tab| really is a print preview tab.
148 if (IsPrintPreviewTab(source_tab) && source_tab->web_ui()) { 155 if (IsPrintPreviewTab(source_tab) && source_tab->web_ui()) {
149 PrintPreviewUI* print_preview_ui = 156 PrintPreviewUI* print_preview_ui =
150 static_cast<PrintPreviewUI*>(source_tab->web_ui()); 157 static_cast<PrintPreviewUI*>(source_tab->web_ui());
151 print_preview_ui->OnNavigation(); 158 print_preview_ui->OnNavigation();
152 } 159 }
153 160
154 // Erase the map entry. 161 // Erase the map entry.
162 DLOG(INFO) << "erasing " << (void*)source_tab;
155 preview_tab_map_.erase(source_tab); 163 preview_tab_map_.erase(source_tab);
156 } else { 164 } else {
157 // Initiator tab is closed. Disable the controls in preview tab. 165 // Initiator tab is closed. Disable the controls in preview tab.
158 PrintPreviewUI* print_preview_ui = 166 PrintPreviewUI* print_preview_ui =
159 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); 167 static_cast<PrintPreviewUI*>(preview_tab->web_ui());
160 print_preview_ui->OnInitiatorTabClosed(source_tab->GetURL().spec()); 168 print_preview_ui->OnInitiatorTabClosed(source_tab->GetURL().spec());
161 169
162 // |source_tab| is an initiator tab, update the map entry. 170 // |source_tab| is an initiator tab, update the map entry.
171 DLOG(INFO) << "initiator tab closed; NULLING " << (void*)preview_tab;
163 preview_tab_map_[preview_tab] = NULL; 172 preview_tab_map_[preview_tab] = NULL;
164 } 173 }
165 RemoveObservers(source_tab); 174 RemoveObservers(source_tab);
166 } 175 }
167 176
168 // static 177 // static
169 bool PrintPreviewTabController::IsPrintPreviewTab(TabContents* tab) { 178 bool PrintPreviewTabController::IsPrintPreviewTab(TabContents* tab) {
170 const GURL& url = tab->GetURL(); 179 const GURL& url = tab->GetURL();
171 return (url.SchemeIs(chrome::kChromeUIScheme) && 180 return (url.SchemeIs(chrome::kChromeUIScheme) &&
172 url.host() == chrome::kChromeUIPrintHost); 181 url.host() == chrome::kChromeUIPrintHost);
173 } 182 }
174 183
175 void PrintPreviewTabController::EraseInitiatorTabInfo( 184 void PrintPreviewTabController::EraseInitiatorTabInfo(
176 TabContents* preview_tab) { 185 TabContents* preview_tab) {
177 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); 186 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab);
178 if (it == preview_tab_map_.end()) 187 if (it == preview_tab_map_.end())
179 return; 188 return;
180 189
181 RemoveObservers(it->second); 190 RemoveObservers(it->second);
191 DLOG(INFO) << __FUNCTION__ << ' ' << (void*)preview_tab;
192 base::debug::StackTrace().PrintBacktrace();
182 preview_tab_map_[preview_tab] = NULL; 193 preview_tab_map_[preview_tab] = NULL;
183 } 194 }
184 195
185 TabContents* PrintPreviewTabController::GetInitiatorTab( 196 TabContents* PrintPreviewTabController::GetInitiatorTab(
186 TabContents* preview_tab) { 197 TabContents* preview_tab) {
187 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); 198 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab);
188 if (it != preview_tab_map_.end()) 199 if (it != preview_tab_map_.end())
189 return preview_tab_map_[preview_tab]; 200 return preview_tab_map_[preview_tab];
190 return NULL; 201 return NULL;
191 } 202 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 254 }
244 255
245 void PrintPreviewTabController::RemoveObservers(TabContents* tab) { 256 void PrintPreviewTabController::RemoveObservers(TabContents* tab) {
246 registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, 257 registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
247 Source<TabContents>(tab)); 258 Source<TabContents>(tab));
248 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 259 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
249 Source<NavigationController>(&tab->controller())); 260 Source<NavigationController>(&tab->controller()));
250 } 261 }
251 262
252 } // namespace printing 263 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698