OLD | NEW |
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/test/base/test_tab_strip_model_observer.h" | 5 #include "chrome/test/base/test_tab_strip_model_observer.h" |
6 | 6 |
7 #include "base/bind.h" | |
8 #include "chrome/browser/printing/print_preview_tab_controller.h" | |
9 #include "chrome/browser/tabs/tab_strip_model.h" | 7 #include "chrome/browser/tabs/tab_strip_model.h" |
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
11 #include "content/public/browser/notification_source.h" | 9 #include "content/public/browser/notification_source.h" |
12 | 10 |
13 TestTabStripModelObserver::TestTabStripModelObserver( | 11 TestTabStripModelObserver::TestTabStripModelObserver( |
14 TabStripModel* tab_strip_model, | 12 TabStripModel* tab_strip_model, |
15 TestTabStripModelObserver::JsInjectionReadyObserver* | 13 TestTabStripModelObserver::JsInjectionReadyObserver* |
16 js_injection_ready_observer) | 14 js_injection_ready_observer) |
17 : TestNavigationObserver(js_injection_ready_observer, 1), | 15 : TestNavigationObserver(js_injection_ready_observer, 1), |
18 tab_strip_model_(tab_strip_model) { | 16 tab_strip_model_(tab_strip_model) { |
19 tab_strip_model_->AddObserver(this); | 17 tab_strip_model_->AddObserver(this); |
20 } | 18 } |
21 | 19 |
22 TestTabStripModelObserver::~TestTabStripModelObserver() { | 20 TestTabStripModelObserver::~TestTabStripModelObserver() { |
23 tab_strip_model_->RemoveObserver(this); | 21 tab_strip_model_->RemoveObserver(this); |
24 } | 22 } |
25 | 23 |
26 void TestTabStripModelObserver::TabBlockedStateChanged( | 24 void TestTabStripModelObserver::TabInsertedAt( |
27 TabContentsWrapper* contents, int index) { | 25 TabContentsWrapper* contents, int index, bool foreground) { |
28 // Need to do this later - the print preview tab has not been created yet. | 26 RegisterAsObserver( |
29 MessageLoop::current()->PostTask( | 27 content::Source<NavigationController>(&contents->controller())); |
30 FROM_HERE, | |
31 base::Bind(&TestTabStripModelObserver::ObservePrintPreviewTabContents, | |
32 base::Unretained(this), | |
33 contents)); | |
34 } | 28 } |
35 | |
36 void TestTabStripModelObserver::ObservePrintPreviewTabContents( | |
37 TabContentsWrapper* contents) { | |
38 printing::PrintPreviewTabController* tab_controller = | |
39 printing::PrintPreviewTabController::GetInstance(); | |
40 if (tab_controller) { | |
41 TabContentsWrapper* preview_tab = | |
42 tab_controller->GetPrintPreviewForTab(contents); | |
43 if (preview_tab) { | |
44 RegisterAsObserver( | |
45 content::Source<NavigationController>(&preview_tab->controller())); | |
46 } | |
47 } | |
48 } | |
OLD | NEW |