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/webui/print_preview_ui.h" 6 7 #include "base/values.h" 8 #include "chrome/browser/profiles/profile.h" 9 #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" 13 PrintPreviewUI(TabContents * contents)14PrintPreviewUI::PrintPreviewUI(TabContents* contents) 15 : WebUI(contents), 16 html_source_(new PrintPreviewUIHTMLSource()) { 17 // PrintPreviewUI owns |handler|. 18 PrintPreviewHandler* handler = new PrintPreviewHandler(); 19 AddMessageHandler(handler->Attach(this)); 20 21 // Set up the chrome://print/ source. 22 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source_); 23 } 24 ~PrintPreviewUI()25PrintPreviewUI::~PrintPreviewUI() { 26 } 27 html_source()28PrintPreviewUIHTMLSource* PrintPreviewUI::html_source() { 29 return html_source_.get(); 30 } 31 PreviewDataIsAvailable(int expected_pages_count,const string16 & job_title)32void PrintPreviewUI::PreviewDataIsAvailable(int expected_pages_count, 33 const string16& job_title) { 34 FundamentalValue pages_count(expected_pages_count); 35 StringValue title(job_title); 36 CallJavascriptFunction("updatePrintPreview", pages_count, title); 37 } 38