Chromium Code Reviews| 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/browser/ui/webui/print_preview_ui.h" | 5 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | |
| 7 #include "base/values.h" | 8 #include "base/values.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/webui/print_preview_handler.h" | 10 #include "chrome/browser/ui/webui/print_preview_handler.h" |
| 10 #include "chrome/browser/ui/webui/print_preview_ui_html_source.h" | |
| 11 #include "content/browser/browser_thread.h" | |
| 12 #include "content/browser/tab_contents/tab_contents.h" | 11 #include "content/browser/tab_contents/tab_contents.h" |
| 13 | 12 |
| 14 PrintPreviewUI::PrintPreviewUI(TabContents* contents) | 13 PrintPreviewUI::PrintPreviewUI(TabContents* contents) : WebUI(contents) { |
| 15 : WebUI(contents), | |
| 16 html_source_(new PrintPreviewUIHTMLSource()) { | |
| 17 // PrintPreviewUI owns |handler|. | 14 // PrintPreviewUI owns |handler|. |
| 18 PrintPreviewHandler* handler = new PrintPreviewHandler(); | 15 PrintPreviewHandler* handler = new PrintPreviewHandler(); |
| 19 AddMessageHandler(handler->Attach(this)); | 16 AddMessageHandler(handler->Attach(this)); |
| 20 | 17 |
| 21 // Set up the chrome://print/ source. | 18 // Set up the chrome://print/ data source. |
| 22 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source_); | 19 data_source_ = PrintPreviewDataSource::GetInstance(); |
| 20 contents->profile()->GetChromeURLDataManager()->AddDataSource(data_source_); | |
| 21 | |
| 22 // Store the PrintPreviewUIAddress as a string. | |
| 23 char preview_ui_addr[128]; | |
|
Lei Zhang
2011/05/26 01:48:31
Since we are using the memory address as the ident
kmadhusu
2011/05/26 15:51:22
Done.
| |
| 24 base::snprintf(preview_ui_addr, 128, "%p", this); | |
| 25 preview_ui_addr_str_.reset(new std::string(preview_ui_addr)); | |
| 23 } | 26 } |
| 24 | 27 |
| 25 PrintPreviewUI::~PrintPreviewUI() { | 28 PrintPreviewUI::~PrintPreviewUI() { |
| 29 data_source_->RemoveEntry(*preview_ui_addr_str_); | |
| 26 } | 30 } |
| 27 | 31 |
| 28 PrintPreviewUIHTMLSource* PrintPreviewUI::html_source() { | 32 void PrintPreviewUI::GetPrintPreviewData( |
| 29 return html_source_.get(); | 33 PrintPreviewDataSource::PrintPreviewData* data) { |
| 34 data_source_->GetDataEntry(*preview_ui_addr_str_, data); | |
| 35 } | |
| 36 | |
| 37 void PrintPreviewUI::SetPrintPreviewData( | |
| 38 const PrintPreviewDataSource::PrintPreviewData& data) { | |
| 39 data_source_->SetDataEntry(*preview_ui_addr_str_, data); | |
| 30 } | 40 } |
| 31 | 41 |
| 32 void PrintPreviewUI::OnInitiatorTabClosed( | 42 void PrintPreviewUI::OnInitiatorTabClosed( |
| 33 const std::string& initiator_url) { | 43 const std::string& initiator_url) { |
| 34 StringValue initiator_tab_url(initiator_url); | 44 StringValue initiator_tab_url(initiator_url); |
| 35 CallJavascriptFunction("onInitiatorTabClosed", initiator_tab_url); | 45 CallJavascriptFunction("onInitiatorTabClosed", initiator_tab_url); |
| 36 } | 46 } |
| 37 | 47 |
| 38 void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count, | 48 void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count, |
| 39 const string16& job_title, | 49 const string16& job_title, |
| 40 bool modifiable) { | 50 bool modifiable) { |
| 41 VLOG(1) << "Print preview request finished with " | 51 VLOG(1) << "Print preview request finished with " |
| 42 << expected_pages_count << " pages"; | 52 << expected_pages_count << " pages"; |
| 43 FundamentalValue pages_count(expected_pages_count); | 53 FundamentalValue pages_count(expected_pages_count); |
| 44 StringValue title(job_title); | 54 StringValue title(job_title); |
| 45 FundamentalValue is_preview_modifiable(modifiable); | 55 FundamentalValue is_preview_modifiable(modifiable); |
| 56 StringValue tab_identifier(*preview_ui_addr_str_); | |
| 46 CallJavascriptFunction("updatePrintPreview", pages_count, title, | 57 CallJavascriptFunction("updatePrintPreview", pages_count, title, |
| 47 is_preview_modifiable); | 58 is_preview_modifiable, tab_identifier); |
| 48 } | 59 } |
| OLD | NEW |