Initial Print Preview UI.
BUG=173
TEST=none
Review URL: http://codereview.chromium.org/3516010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61425 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index be6a1a6..1c5bba2 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -5017,6 +5017,11 @@
Set up cloud printing
</message>
+ <!-- Print Preview -->
+ <message name="IDS_PRINTPREVIEW_TITLE" desc="Title for print preview page ">
+ Print Preview
+ </message>
+
<!-- Load State -->
<message name="IDS_LOAD_STATE_IDLE"></message>
<message name="IDS_LOAD_STATE_WAITING_FOR_CACHE">
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd
index d369ddb4b..b42603d 100644
--- a/chrome/browser/browser_resources.grd
+++ b/chrome/browser/browser_resources.grd
@@ -33,7 +33,7 @@
</if>
<if expr="os != 'darwin'">
<include name="IDR_EXTENSIONS_INFOBAR_CSS" file="resources\extensions_infobar.css" flattenhtml="true" type="BINDATA" />
- </if>
+ </if>
<include name="IDR_EXTENSIONS_UI_HTML" file="resources\extensions_ui.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_GAIA_LOGIN_HTML" file="sync\resources\gaia_login.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_GMAIL_APP_MANIFEST" file="resources\gmail_app\manifest.json" type="BINDATA" />
@@ -50,6 +50,7 @@
<include name="IDR_NOTIFICATION_ICON_HTML" file="resources\notification_icon.html" type="BINDATA" />
<include name="IDR_OPTIONS_HTML" file="resources\options.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_PLUGINS_HTML" file="resources\plugins.html" flattenhtml="true" type="BINDATA" />
+ <include name="IDR_PRINTPREVIEW_HTML" file="resources\print_preview.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_SAFE_BROWSING_MALWARE_BLOCK" file="resources\safe_browsing_malware_block.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_SAFE_BROWSING_MULTIPLE_THREAT_BLOCK" file="resources\safe_browsing_multiple_threat_block.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_SAFE_BROWSING_PHISHING_BLOCK" file="resources\safe_browsing_phishing_block.html" flattenhtml="true" type="BINDATA" />
diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc
index 865ea5f..4cc5272 100644
--- a/chrome/browser/dom_ui/dom_ui_factory.cc
+++ b/chrome/browser/dom_ui/dom_ui_factory.cc
@@ -19,8 +19,9 @@
#include "chrome/browser/dom_ui/labs_ui.h"
#include "chrome/browser/dom_ui/net_internals_ui.h"
#include "chrome/browser/dom_ui/new_tab_ui.h"
-#include "chrome/browser/dom_ui/remoting_ui.h"
#include "chrome/browser/dom_ui/plugins_ui.h"
+#include "chrome/browser/dom_ui/print_preview_ui.h"
+#include "chrome/browser/dom_ui/remoting_ui.h"
#include "chrome/browser/dom_ui/options/options_ui.h"
#include "chrome/browser/dom_ui/slideshow_ui.h"
#include "chrome/browser/extensions/extension_dom_ui.h"
@@ -152,10 +153,12 @@
return &NewDOMUI<MediaplayerUI>;
if (url.host() == chrome::kChromeUIMobileSetupHost)
return &NewDOMUI<MobileSetupUI>;
- if (url.host() == chrome::kChromeUISettingsHost)
- return &NewDOMUI<OptionsUI>;
+ if (url.host() == chrome::kChromeUIPrintHost)
+ return &NewDOMUI<PrintPreviewUI>;
if (url.host() == chrome::kChromeUIRegisterPageHost)
return &NewDOMUI<RegisterPageUI>;
+ if (url.host() == chrome::kChromeUISettingsHost)
+ return &NewDOMUI<OptionsUI>;
if (url.host() == chrome::kChromeUISlideshowHost)
return &NewDOMUI<SlideshowUI>;
if (url.host() == chrome::kChromeUISystemInfoHost)
@@ -167,6 +170,12 @@
return &NewDOMUI<OptionsUI>;
}
}
+ if (url.host() == chrome::kChromeUIPrintHost) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnablePrintPreview)) {
+ return &NewDOMUI<PrintPreviewUI>;
+ }
+ }
#endif
return NULL;
diff --git a/chrome/browser/dom_ui/print_preview_ui.cc b/chrome/browser/dom_ui/print_preview_ui.cc
new file mode 100644
index 0000000..00ea02f
--- /dev/null
+++ b/chrome/browser/dom_ui/print_preview_ui.cc
@@ -0,0 +1,87 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/dom_ui/print_preview_ui.h"
+
+#include <algorithm>
+
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "base/message_loop.h"
+#include "base/singleton.h"
+#include "base/string_piece.h"
+#include "base/values.h"
+#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/dom_ui/dom_ui_theme_source.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/jstemplate_builder.h"
+#include "chrome/common/url_constants.h"
+
+#include "grit/browser_resources.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+
+namespace {
+
+void SetLocalizedStrings(DictionaryValue* localized_strings) {
+ localized_strings->SetString(std::string("title"),
+ l10n_util::GetStringUTF8(IDS_PRINTPREVIEW_TITLE));
+}
+
+} // namespace
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// PrintPreviewUIHTMLSource
+//
+////////////////////////////////////////////////////////////////////////////////
+
+PrintPreviewUIHTMLSource::PrintPreviewUIHTMLSource()
+ : DataSource(chrome::kChromeUIPrintHost, MessageLoop::current()) {
+}
+
+PrintPreviewUIHTMLSource::~PrintPreviewUIHTMLSource() {}
+
+void PrintPreviewUIHTMLSource::StartDataRequest(const std::string& path,
+ bool is_off_the_record,
+ int request_id) {
+ DictionaryValue localized_strings;
+ SetLocalizedStrings(&localized_strings);
+ SetFontAndTextDirection(&localized_strings);
+
+ static const base::StringPiece print_html(
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_PRINTPREVIEW_HTML));
+ const std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
+ print_html, &localized_strings);
+
+ scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
+ html_bytes->data.resize(full_html.size());
+ std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
+
+ SendResponse(request_id, html_bytes);
+}
+
+std::string PrintPreviewUIHTMLSource::GetMimeType(const std::string&) const {
+ return "text/html";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// PrintPreviewUI
+//
+////////////////////////////////////////////////////////////////////////////////
+
+PrintPreviewUI::PrintPreviewUI(TabContents* contents) : DOMUI(contents) {
+ // Set up the chrome://print/ source.
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ Singleton<ChromeURLDataManager>::get(),
+ &ChromeURLDataManager::AddDataSource,
+ make_scoped_refptr(new PrintPreviewUIHTMLSource())));
+}
+
+PrintPreviewUI::~PrintPreviewUI() {
+}
diff --git a/chrome/browser/dom_ui/print_preview_ui.h b/chrome/browser/dom_ui/print_preview_ui.h
new file mode 100644
index 0000000..58844637f
--- /dev/null
+++ b/chrome/browser/dom_ui/print_preview_ui.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_DOM_UI_PRINT_PREVIEW_UI_H_
+#define CHROME_BROWSER_DOM_UI_PRINT_PREVIEW_UI_H_
+#pragma once
+
+#include <string>
+
+#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
+#include "chrome/browser/dom_ui/dom_ui.h"
+
+struct UserMetricsAction;
+
+class PrintPreviewUIHTMLSource : public ChromeURLDataManager::DataSource {
+ public:
+ explicit PrintPreviewUIHTMLSource();
+ virtual ~PrintPreviewUIHTMLSource();
+
+ // Called when the network layer has requested a resource underneath
+ // the path we registered.
+ virtual void StartDataRequest(const std::string& path,
+ bool is_off_the_record,
+ int request_id);
+ virtual std::string GetMimeType(const std::string&) const;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PrintPreviewUIHTMLSource);
+};
+
+class PrintPreviewUI : public DOMUI {
+ public:
+ explicit PrintPreviewUI(TabContents* contents);
+ virtual ~PrintPreviewUI();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PrintPreviewUI);
+};
+
+#endif // CHROME_BROWSER_DOM_UI_PRINT_PREVIEW_UI_H_
diff --git a/chrome/browser/dom_ui/print_preview_ui_uitest.cc b/chrome/browser/dom_ui/print_preview_ui_uitest.cc
new file mode 100644
index 0000000..92f8b8b
--- /dev/null
+++ b/chrome/browser/dom_ui/print_preview_ui_uitest.cc
@@ -0,0 +1,48 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "app/l10n_util.h"
+#include "base/string16.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/url_constants.h"
+#include "chrome/test/automation/browser_proxy.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/ui/ui_test.h"
+
+#include "grit/generated_resources.h"
+
+namespace {
+
+class PrintPreviewUITest : public UITest {
+ public:
+ PrintPreviewUITest() {
+ dom_automation_enabled_ = true;
+ // TODO(thestig): Remove when print preview is enabled by default.
+ launch_arguments_.AppendSwitch(switches::kEnablePrintPreview);
+ }
+
+ void AssertIsPrintPage(TabProxy* tab) {
+ std::wstring title;
+ ASSERT_TRUE(tab->GetTabTitle(&title));
+ string16 expected_title = l10n_util::GetStringUTF16(IDS_PRINTPREVIEW_TITLE);
+ ASSERT_EQ(expected_title, WideToUTF16Hack(title));
+ }
+};
+
+// TODO(thestig) Remove this test in the future if loading
+// chrome::kChromeUIPrintURL directly does not make sense.
+TEST_F(PrintPreviewUITest, LoadPrintPreviewByURL) {
+ scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ ASSERT_TRUE(browser.get());
+
+ scoped_refptr<TabProxy> tab = browser->GetActiveTab();
+ ASSERT_TRUE(tab.get());
+
+ // Go to the print preview tab via URL.
+ NavigateToURL(GURL(chrome::kChromeUIPrintURL));
+ AssertIsPrintPage(tab);
+}
+
+} // namespace
diff --git a/chrome/browser/resources/print_preview.css b/chrome/browser/resources/print_preview.css
new file mode 100644
index 0000000..eeb5f2c
--- /dev/null
+++ b/chrome/browser/resources/print_preview.css
@@ -0,0 +1,105 @@
+/* TODO(thestig) make mainview float rather than fixed */
+body {
+ font-size: 100%;
+ -webkit-user-select: none;
+}
+
+#settings-title {
+ -webkit-padding-end: 24px;
+ padding-top: 1em;
+ padding-bottom: 1em;
+ text-align: end;
+ font-size: 125%;
+ font-weight: normal;
+ color: #53627d;
+ margin: 0;
+}
+
+#main-content {
+ background-color: #5d626c;
+ display: -webkit-box;
+ position: absolute;
+ left: 0;
+ right: 0;
+ top: 0;
+ bottom: 0;
+}
+
+#navbar-container {
+ background-color: #f8fafd;
+ position: relative;
+ width: 300px;
+ z-index: 2;
+}
+
+#destination-container {
+ background-color: #ffffff;
+ padding: 10px;
+}
+
+#options-container {
+ padding: 10px;
+}
+
+#mainview {
+ -webkit-box-align: stretch;
+ background: -webkit-gradient(linear,
+ left top,
+ right top,
+ from(#a4a4a4),
+ color-stop(0.02, #cccccc),
+ to(#cccccc));
+ margin: 0;
+ position: relative;
+ left: 0;
+ right: 0;
+ top: 0;
+ bottom: 0;
+ z-index: 1;
+}
+
+#mainview-content {
+ width: 480px;
+ padding: 10px 24px;
+}
+
+#thumbnails {
+ background: -webkit-gradient(linear,
+ left top,
+ right top,
+ from(#cccccc),
+ to(#5d626c));
+ margin: 0;
+ position: relative;
+ left: 0;
+ right: 0;
+ top: 0;
+ bottom: 0;
+ z-index: 1;
+}
+
+#thumbnails-content {
+ width: 160px;
+ padding: 10px;
+}
+
+.hidden {
+ display: none;
+}
+
+select {
+ margin: 0px;
+}
+
+.link-button {
+ background-color: transparent;
+ border: none;
+ color: blue;
+ cursor: pointer;
+ text-decoration: underline;
+}
+
+.text-button {
+ background-color: transparent;
+ border-color: transparent;
+}
diff --git a/chrome/browser/resources/print_preview.html b/chrome/browser/resources/print_preview.html
new file mode 100644
index 0000000..13218e7
--- /dev/null
+++ b/chrome/browser/resources/print_preview.html
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML>
+<html i18n-values="dir:textdirection;" id="t">
+<head>
+<meta charset="utf-8">
+<title i18n-content="title"></title>
+
+<link rel="stylesheet" href="dom_ui.css">
+<link rel="stylesheet" href="print_preview.css">
+
+<script src="chrome://resources/js/local_strings.js"></script>
+<script src="chrome://resources/js/util.js"></script>
+
+</head>
+<body i18n-values=".style.fontFamily:fontfamily;.style.fontSize:fontsize">
+<div id="main-content">
+ <div id="navbar-container">
+ <div id="destination-container">
+ <div id="destination-title">
+ Destination
+ </div>
+ <div id="destination-list">
+ LIST GOES HERE
+ </div>
+ <div id="print-buttons">
+ <button id="printButton">Print</button>
+ <button id="cancelButton">Cancel</button>
+ </div>
+ </div>
+ <div id="options-container">
+ OPTIONS HERE
+ </div>
+ </div>
+ <div id="mainview">
+ <div id="mainview-content">
+ MAIN
+ </div>
+ </div>
+ <div id="thumbnails">
+ <div id="thumbnails-content">
+ THUMBNAILS
+ </div>
+ </div>
+</div>
+
+<script>
+console.log('in bottom script');
+</script>
+</body>
+</html>
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index da1cb11c..69473157 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1276,6 +1276,8 @@
'browser/dom_ui/ntp_resource_cache.h',
'browser/dom_ui/plugins_ui.cc',
'browser/dom_ui/plugins_ui.h',
+ 'browser/dom_ui/print_preview_ui.cc',
+ 'browser/dom_ui/print_preview_ui.h',
'browser/dom_ui/remoting_ui.cc',
'browser/dom_ui/remoting_ui.h',
'browser/dom_ui/options/about_page_handler.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 4b0e32e3..403908a 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -474,6 +474,7 @@
'browser/dom_ui/bookmarks_ui_uitest.cc',
'browser/dom_ui/new_tab_ui_uitest.cc',
'browser/dom_ui/options/options_ui_uitest.cc',
+ 'browser/dom_ui/print_preview_ui_uitest.cc',
'browser/download/download_uitest.cc',
'browser/download/save_page_uitest.cc',
'browser/errorpage_uitest.cc',