Commit 520a12ce authored by tsepez@chromium.org's avatar tsepez@chromium.org

Add content-security-policy directive to print-preview pages.

Since print-preview uses an object tag, relax the object-src restriction in
the content_security_policy.html file.  Also fix typo in print_preview.html
where the object tag has a src="", not a data="" attribute.
Review URL: http://codereview.chromium.org/7566049

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95850 0039d316-1c4b-4281-b951-d872f2087c98
parent 05464a71
......@@ -84,7 +84,8 @@
<include name="IDR_PLUGINS_HTML" file="resources\plugins.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_PLUGINS_JS" file="resources\plugins.js" type="BINDATA" />
<include name="IDR_READER_OUT_OF_DATE_HTML" file="resources\reader_out_of_date.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_PRINT_PREVIEW_HTML" file="resources\print_preview\print_preview.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_PRINT_PREVIEW_HTML" file="resources\print_preview\print_preview.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_PRINT_PREVIEW_JS" file="resources\print_preview\print_preview.js" 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" />
......
......@@ -11,7 +11,7 @@
-->
<meta
http-equiv="X-WebKit-CSP"
content="object-src 'none';
content="object-src 'self';
script-src chrome://resources
chrome-extension://mndnfokpggljbaajbnioimlmbfngpief
'self'
......
......@@ -2,6 +2,7 @@
<html i18n-values="dir:textdirection;">
<head>
<meta charset="utf-8">
<include src="../content_security_policy.html"/>
<title i18n-content="title"></title>
<link rel="icon" href="../../../app/theme/print_preview_favicon.png">
<link rel="stylesheet" href="../webui.css">
......@@ -10,15 +11,8 @@
<script src="chrome://resources/js/local_strings.js"></script>
<script src="chrome://resources/js/cr.js"></script>
<script src="chrome://resources/js/util.js"></script>
<script src="print_preview.js"></script>
<script src="print_preview_animations.js"></script>
<script src="print_preview_cloud.js"></script>
<script src="print_preview_utils.js"></script>
<script src="print_header.js"></script>
<script src="page_settings.js"></script>
<script src="copies_settings.js"></script>
<script src="layout_settings.js"></script>
<script src="color_settings.js"></script>
<script src="chrome://print/print_preview.js"></script>
<script src="chrome://print/strings.js"></script>
</head>
<body>
<div id="sidebar">
......@@ -70,6 +64,8 @@
</div>
<object id="dummy-viewer"
type="application/x-google-chrome-print-preview-pdf"
src="chrome://print/dummy.pdf"></object>
data="chrome://print/dummy.pdf"></object>
<script src="chrome://resources/js/i18n_template.js"></script>
<script src="chrome://resources/js/i18n_process.js"></script>
</body>
</html>
......@@ -966,3 +966,12 @@ PrintSettings.prototype.save = function() {
this.isLandscape = layoutSettings.isLandscape();
}
/// Pull in all other scripts in a single shot.
<include src="print_preview_animations.js"/>
<include src="print_preview_cloud.js"/>
<include src="print_preview_utils.js"/>
<include src="print_header.js"/>
<include src="page_settings.js"/>
<include src="copies_settings.js"/>
<include src="layout_settings.js"/>
<include src="color_settings.js"/>
......@@ -33,6 +33,9 @@ std::string ChromeWebUIDataSource::GetMimeType(const std::string& path) const {
if (EndsWith(path, ".js", false))
return "application/javascript";
if (EndsWith(path, ".pdf", false))
return "application/pdf";
return "text/html";
}
......
......@@ -23,117 +23,80 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
namespace {
PrintPreviewDataSource::PrintPreviewDataSource()
: ChromeWebUIDataSource(chrome::kChromeUIPrintHost) {
void SetLocalizedStrings(DictionaryValue* localized_strings) {
localized_strings->SetString(std::string("title"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_TITLE));
localized_strings->SetString(std::string("loading"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_LOADING));
AddLocalizedString("title", IDS_PRINT_PREVIEW_TITLE);
AddLocalizedString("loading", IDS_PRINT_PREVIEW_LOADING);
#if defined(GOOGLE_CHROME_BUILD)
localized_strings->SetString(std::string("noPlugin"),
l10n_util::GetStringFUTF8(IDS_PRINT_PREVIEW_NO_PLUGIN,
ASCIIToUTF16("chrome://plugins/")));
AddString("noPlugin", l10n_util::GetStringFUTF8(
IDS_PRINT_PREVIEW_NO_PLUGIN, ASCIIToUTF16("chrome://plugins/"));
#else
localized_strings->SetString(std::string("noPlugin"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_NO_PLUGIN));
AddLocalizedString("noPlugin", IDS_PRINT_PREVIEW_NO_PLUGIN);
#endif
localized_strings->SetString(std::string("launchNativeDialog"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_NATIVE_DIALOG));
localized_strings->SetString(std::string("previewFailed"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_FAILED));
localized_strings->SetString(std::string("initiatorTabClosed"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_INITIATOR_TAB_CLOSED));
localized_strings->SetString(std::string("reopenPage"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_REOPEN_PAGE));
localized_strings->SetString(std::string("printButton"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PRINT_BUTTON));
localized_strings->SetString(std::string("cancelButton"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_CANCEL_BUTTON));
localized_strings->SetString(std::string("printing"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PRINTING));
localized_strings->SetString(std::string("destinationLabel"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_DESTINATION_LABEL));
localized_strings->SetString(std::string("copiesLabel"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_COPIES_LABEL));
localized_strings->SetString(std::string("examplePageRangeText"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_EXAMPLE_PAGE_RANGE_TEXT));
localized_strings->SetString(std::string("invalidNumberOfCopies"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_INVALID_NUMBER_OF_COPIES));
localized_strings->SetString(std::string("layoutLabel"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_LAYOUT_LABEL));
localized_strings->SetString(std::string("optionAllPages"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_OPTION_ALL_PAGES));
localized_strings->SetString(std::string("optionBw"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_OPTION_BW));
localized_strings->SetString(std::string("optionCollate"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_OPTION_COLLATE));
localized_strings->SetString(std::string("optionColor"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_OPTION_COLOR));
localized_strings->SetString(std::string("optionLandscape"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_OPTION_LANDSCAPE));
localized_strings->SetString(std::string("optionPortrait"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_OPTION_PORTRAIT));
localized_strings->SetString(std::string("optionTwoSided"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_OPTION_TWO_SIDED));
localized_strings->SetString(std::string("pagesLabel"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PAGES_LABEL));
localized_strings->SetString(std::string("pageRangeTextBox"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PAGE_RANGE_TEXT));
localized_strings->SetString(std::string("pageRangeRadio"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PAGE_RANGE_RADIO));
localized_strings->SetString(std::string("printToPDF"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PRINT_TO_PDF));
localized_strings->SetString(std::string("printPreviewTitleFormat"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_TITLE_FORMAT));
localized_strings->SetString(std::string("printPreviewSummaryFormatShort"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_SUMMARY_FORMAT_SHORT));
localized_strings->SetString(std::string("printPreviewSummaryFormatLong"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_SUMMARY_FORMAT_LONG));
localized_strings->SetString(std::string("printPreviewSheetsLabelSingular"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_SHEETS_LABEL_SINGULAR));
localized_strings->SetString(std::string("printPreviewSheetsLabelPlural"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_SHEETS_LABEL_PLURAL));
localized_strings->SetString(std::string("printPreviewPageLabelSingular"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PAGE_LABEL_SINGULAR));
localized_strings->SetString(std::string("printPreviewPageLabelPlural"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PAGE_LABEL_PLURAL));
localized_strings->SetString(std::string("systemDialogOption"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION));
localized_strings->SetString(std::string("pageRangeInstruction"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PAGE_RANGE_INSTRUCTION));
localized_strings->SetString(std::string("copiesInstruction"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_COPIES_INSTRUCTION));
localized_strings->SetString(std::string("signIn"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_SIGN_IN));
localized_strings->SetString(std::string("morePrinters"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_MORE_PRINTERS));
localized_strings->SetString(std::string("addCloudPrinter"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_ADD_CLOUD_PRINTER));
localized_strings->SetString(std::string("cloudPrinters"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_CLOUD_PRINTERS));
localized_strings->SetString(std::string("localPrinters"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_LOCAL_PRINTERS));
localized_strings->SetString(std::string("manageCloudPrinters"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_MANAGE_CLOUD_PRINTERS));
localized_strings->SetString(std::string("manageLocalPrinters"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_MANAGE_LOCAL_PRINTERS));
localized_strings->SetString(std::string("managePrinters"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_MANAGE_PRINTERS));
localized_strings->SetString(std::string("incrementTitle"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_INCREMENT_TITLE));
localized_strings->SetString(std::string("decrementTitle"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_DECREMENT_TITLE));
localized_strings->SetString(std::string("printPagesLabel"),
l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_PRINT_PAGES_LABEL));
}
} // namespace
PrintPreviewDataSource::PrintPreviewDataSource()
: DataSource(chrome::kChromeUIPrintHost, MessageLoop::current()) {
AddLocalizedString("launchNativeDialog", IDS_PRINT_PREVIEW_NATIVE_DIALOG);
AddLocalizedString("previewFailed", IDS_PRINT_PREVIEW_FAILED);
AddLocalizedString("initiatorTabClosed",
IDS_PRINT_PREVIEW_INITIATOR_TAB_CLOSED);
AddLocalizedString("reopenPage", IDS_PRINT_PREVIEW_REOPEN_PAGE);
AddLocalizedString("printButton", IDS_PRINT_PREVIEW_PRINT_BUTTON);
AddLocalizedString("cancelButton", IDS_PRINT_PREVIEW_CANCEL_BUTTON);
AddLocalizedString("printing", IDS_PRINT_PREVIEW_PRINTING);
AddLocalizedString("destinationLabel", IDS_PRINT_PREVIEW_DESTINATION_LABEL);
AddLocalizedString("copiesLabel", IDS_PRINT_PREVIEW_COPIES_LABEL);
AddLocalizedString("examplePageRangeText",
IDS_PRINT_PREVIEW_EXAMPLE_PAGE_RANGE_TEXT);
AddLocalizedString("invalidNumberOfCopies",
IDS_PRINT_PREVIEW_INVALID_NUMBER_OF_COPIES);
AddLocalizedString("layoutLabel", IDS_PRINT_PREVIEW_LAYOUT_LABEL);
AddLocalizedString("optionAllPages", IDS_PRINT_PREVIEW_OPTION_ALL_PAGES);
AddLocalizedString("optionBw", IDS_PRINT_PREVIEW_OPTION_BW);
AddLocalizedString("optionCollate", IDS_PRINT_PREVIEW_OPTION_COLLATE);
AddLocalizedString("optionColor", IDS_PRINT_PREVIEW_OPTION_COLOR);
AddLocalizedString("optionLandscape", IDS_PRINT_PREVIEW_OPTION_LANDSCAPE);
AddLocalizedString("optionPortrait", IDS_PRINT_PREVIEW_OPTION_PORTRAIT);
AddLocalizedString("optionTwoSided", IDS_PRINT_PREVIEW_OPTION_TWO_SIDED);
AddLocalizedString("pagesLabel", IDS_PRINT_PREVIEW_PAGES_LABEL);
AddLocalizedString("pageRangeTextBox", IDS_PRINT_PREVIEW_PAGE_RANGE_TEXT);
AddLocalizedString("pageRangeRadio", IDS_PRINT_PREVIEW_PAGE_RANGE_RADIO);
AddLocalizedString("printToPDF", IDS_PRINT_PREVIEW_PRINT_TO_PDF);
AddLocalizedString("printPreviewTitleFormat", IDS_PRINT_PREVIEW_TITLE_FORMAT);
AddLocalizedString("printPreviewSummaryFormatShort",
IDS_PRINT_PREVIEW_SUMMARY_FORMAT_SHORT);
AddLocalizedString("printPreviewSummaryFormatLong",
IDS_PRINT_PREVIEW_SUMMARY_FORMAT_LONG);
AddLocalizedString("printPreviewSheetsLabelSingular",
IDS_PRINT_PREVIEW_SHEETS_LABEL_SINGULAR);
AddLocalizedString("printPreviewSheetsLabelPlural",
IDS_PRINT_PREVIEW_SHEETS_LABEL_PLURAL);
AddLocalizedString("printPreviewPageLabelSingular",
IDS_PRINT_PREVIEW_PAGE_LABEL_SINGULAR);
AddLocalizedString("printPreviewPageLabelPlural",
IDS_PRINT_PREVIEW_PAGE_LABEL_PLURAL);
AddLocalizedString("systemDialogOption",
IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION);
AddLocalizedString("pageRangeInstruction",
IDS_PRINT_PREVIEW_PAGE_RANGE_INSTRUCTION);
AddLocalizedString("copiesInstruction", IDS_PRINT_PREVIEW_COPIES_INSTRUCTION);
AddLocalizedString("signIn", IDS_PRINT_PREVIEW_SIGN_IN);
AddLocalizedString("morePrinters", IDS_PRINT_PREVIEW_MORE_PRINTERS);
AddLocalizedString("addCloudPrinter", IDS_PRINT_PREVIEW_ADD_CLOUD_PRINTER);
AddLocalizedString("cloudPrinters", IDS_PRINT_PREVIEW_CLOUD_PRINTERS);
AddLocalizedString("localPrinters", IDS_PRINT_PREVIEW_LOCAL_PRINTERS);
AddLocalizedString("manageCloudPrinters",
IDS_PRINT_PREVIEW_MANAGE_CLOUD_PRINTERS);
AddLocalizedString("manageLocalPrinters",
IDS_PRINT_PREVIEW_MANAGE_LOCAL_PRINTERS);
AddLocalizedString("managePrinters", IDS_PRINT_PREVIEW_MANAGE_PRINTERS);
AddLocalizedString("incrementTitle", IDS_PRINT_PREVIEW_INCREMENT_TITLE);
AddLocalizedString("decrementTitle", IDS_PRINT_PREVIEW_DECREMENT_TITLE);
AddLocalizedString("printPagesLabel", IDS_PRINT_PREVIEW_PRINT_PAGES_LABEL);
set_json_path("strings.js");
add_resource_path("print_preview.js", IDR_PRINT_PREVIEW_JS);
set_default_resource(IDR_PRINT_PREVIEW_HTML);
}
PrintPreviewDataSource::~PrintPreviewDataSource() {
......@@ -142,46 +105,26 @@ PrintPreviewDataSource::~PrintPreviewDataSource() {
void PrintPreviewDataSource::StartDataRequest(const std::string& path,
bool is_incognito,
int request_id) {
scoped_refptr<RefCountedBytes> data;
bool preview_data_requested = EndsWith(path, "/print.pdf", true);
if (preview_data_requested) {
std::vector<std::string> url_substr;
base::SplitString(path, '/', &url_substr);
int page_index = 0;
if (url_substr.size() == 3 && base::StringToInt(url_substr[1],
&page_index)) {
PrintPreviewDataService::GetInstance()->GetDataEntry(url_substr[0],
page_index, &data);
}
// Parent class handles most requests except for the print preview data.
if (!EndsWith(path, "/print.pdf", true)) {
ChromeWebUIDataSource::StartDataRequest(path, is_incognito, request_id);
return;
}
if (path.empty()) {
// Print Preview Index page.
DictionaryValue localized_strings;
SetLocalizedStrings(&localized_strings);
SetFontAndTextDirection(&localized_strings);
static const base::StringPiece print_html(
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_PRINT_PREVIEW_HTML));
std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
print_html, &localized_strings);
SendResponse(request_id, base::RefCountedString::TakeString(&full_html));
return;
} else if (preview_data_requested && data.get()) {
// Print Preview data.
// Print Preview data.
scoped_refptr<RefCountedBytes> data;
std::vector<std::string> url_substr;
base::SplitString(path, '/', &url_substr);
int page_index = 0;
if (url_substr.size() == 3 && base::StringToInt(url_substr[1], &page_index)) {
PrintPreviewDataService::GetInstance()->GetDataEntry(
url_substr[0], page_index, &data);
}
if (data.get()) {
SendResponse(request_id, data);
return;
} else {
// Invalid request.
scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes);
SendResponse(request_id, empty_bytes);
return;
}
}
std::string PrintPreviewDataSource::GetMimeType(const std::string& path) const {
return path.empty() ? "text/html" : "application/pdf";
// Invalid request.
scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes);
SendResponse(request_id, empty_bytes);
}
......@@ -10,10 +10,11 @@
#include "base/compiler_specific.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
// PrintPreviewDataSource serves data for chrome://print requests.
//
// The format for requesting data is as follows:
// The format for requesting PDF data is as follows:
// chrome://print/<PrintPreviewUIAddrStr>/<PageIndex>/print.pdf
//
// Parameters (< > required):
......@@ -24,8 +25,10 @@
//
// Example:
// chrome://print/0xab0123ef/10/print.pdf
class PrintPreviewDataSource : public ChromeURLDataManager::DataSource {
//
// Requests to chrome://print with paths not ending in /print.pdf are used
// to return the markup or other resources for the print preview page itself.
class PrintPreviewDataSource : public ChromeWebUIDataSource {
public:
PrintPreviewDataSource();
......@@ -33,8 +36,6 @@ class PrintPreviewDataSource : public ChromeURLDataManager::DataSource {
virtual void StartDataRequest(const std::string& path,
bool is_incognito,
int request_id) OVERRIDE;
virtual std::string GetMimeType(const std::string& path) const OVERRIDE;
private:
virtual ~PrintPreviewDataSource();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment