summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authormhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-14 01:51:32 +0000
committermhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-14 01:51:32 +0000
commitd53d849311746e2443b633b46ea20f13e4fc4481 (patch)
tree3c63c7b61f335556da0d0d141079e2c59dd43484 /chrome/browser/dom_ui
parent3ad70eb6fdb20cf77d09d29e8c0e848e80cdd3ad (diff)
downloadchromium_src-d53d849311746e2443b633b46ea20f13e4fc4481.zip
chromium_src-d53d849311746e2443b633b46ea20f13e4fc4481.tar.gz
chromium_src-d53d849311746e2443b633b46ea20f13e4fc4481.tar.bz2
Hookup Print HTML page to the DOM UI for Print Preview and Settings
Depends on initial foundation: http://src.chromium.org/viewvc/chrome?view=rev&revision=19906 And html mockup: http://src.chromium.org/viewvc/chrome?view=rev&revision=19918 BUG=173, 947 TEST=The user will see the print html page as a html test webpage. Review URL: http://codereview.chromium.org/155067 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20595 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/chrome_url_data_manager.cc20
-rw-r--r--chrome/browser/dom_ui/dom_ui_factory.cc6
-rw-r--r--chrome/browser/dom_ui/print_ui.cc53
-rw-r--r--chrome/browser/dom_ui/print_ui.h19
4 files changed, 91 insertions, 7 deletions
diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.cc b/chrome/browser/dom_ui/chrome_url_data_manager.cc
index 2537a12..36fde4d 100644
--- a/chrome/browser/dom_ui/chrome_url_data_manager.cc
+++ b/chrome/browser/dom_ui/chrome_url_data_manager.cc
@@ -116,6 +116,8 @@ void RegisterURLRequestChromeJob() {
URLRequest::RegisterProtocolFactory(kChromeURLScheme,
&ChromeURLDataManager::Factory);
+ URLRequest::RegisterProtocolFactory(chrome::kPrintScheme,
+ &ChromeURLDataManager::Factory);
#ifdef CHROME_PERSONALIZATION
url_util::AddStandardScheme(kPersonalizationScheme);
URLRequest::RegisterProtocolFactory(kPersonalizationScheme,
@@ -137,9 +139,10 @@ void ChromeURLDataManager::URLToRequest(const GURL& url,
std::string* path) {
#ifdef CHROME_PERSONALIZATION
DCHECK(url.SchemeIs(kChromeURLScheme) ||
- url.SchemeIs(kPersonalizationScheme));
+ url.SchemeIs(kPersonalizationScheme) ||
+ url.SchemeIs(chrome::kPrintScheme));
#else
- DCHECK(url.SchemeIs(kChromeURLScheme));
+ DCHECK(url.SchemeIs(kChromeURLScheme) || url.SchemeIs(chrome::kPrintScheme));
#endif
if (!url.is_valid()) {
@@ -149,13 +152,20 @@ void ChromeURLDataManager::URLToRequest(const GURL& url,
// Our input looks like: chrome://source_name/extra_bits?foo .
// So the url's "host" is our source, and everything after the host is
- // the path.
- source_name->assign(url.host());
+ // the path. For print:url schemes, we assume its always print.
+ if (url.SchemeIs(chrome::kPrintScheme))
+ source_name->assign(chrome::kPrintScheme);
+ else
+ source_name->assign(url.host());
const std::string& spec = url.possibly_invalid_spec();
const url_parse::Parsed& parsed = url.parsed_for_possibly_invalid_spec();
int offset = parsed.CountCharactersBefore(url_parse::Parsed::PATH, false);
- ++offset; // Skip the slash at the beginning of the path.
+
+ // We need to skip the slash at the beginning of the path for non print urls.
+ if (!url.SchemeIs(chrome::kPrintScheme))
+ ++offset;
+
if (offset < static_cast<int>(spec.size()))
path->assign(spec.substr(offset));
}
diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc
index 8ff6d03..d7f2e81 100644
--- a/chrome/browser/dom_ui/dom_ui_factory.cc
+++ b/chrome/browser/dom_ui/dom_ui_factory.cc
@@ -42,11 +42,14 @@ static bool CreateDOMUI(const GURL& url, TabContents* tab_contents,
return true;
}
+// TODO(mhm) Make sure this ifdef is removed once print is complete.
+#if !defined(GOOGLE_CHROME_BUILD)
if (url.SchemeIs(chrome::kPrintScheme)) {
if (new_ui)
*new_ui = new PrintUI(tab_contents);
return true;
}
+#endif
#ifdef CHROME_PERSONALIZATION
if (Personalization::NeedsDOMUI(url)) {
@@ -106,7 +109,8 @@ static bool CreateDOMUI(const GURL& url, TabContents* tab_contents,
bool DOMUIFactory::HasDOMUIScheme(const GURL& url) {
return url.SchemeIs(chrome::kChromeInternalScheme) ||
url.SchemeIs(chrome::kChromeUIScheme) ||
- url.SchemeIs(chrome::kExtensionScheme);
+ url.SchemeIs(chrome::kExtensionScheme) ||
+ url.SchemeIs(chrome::kPrintScheme);
}
// static
diff --git a/chrome/browser/dom_ui/print_ui.cc b/chrome/browser/dom_ui/print_ui.cc
index 973e5c7..82b2396 100644
--- a/chrome/browser/dom_ui/print_ui.cc
+++ b/chrome/browser/dom_ui/print_ui.cc
@@ -4,6 +4,18 @@
#include "chrome/browser/dom_ui/print_ui.h"
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "base/message_loop.h"
+#include "base/thread.h"
+#include "base/values.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/common/jstemplate_builder.h"
+#include "chrome/common/url_constants.h"
+
+#include "grit/browser_resources.h"
+#include "grit/generated_resources.h"
+
///////////////////////////////////////////////////////////////////////////////
//
// PrintUI
@@ -11,5 +23,44 @@
///////////////////////////////////////////////////////////////////////////////
PrintUI::PrintUI(TabContents* contents) : DOMUI(contents) {
- NOTIMPLEMENTED();
+ PrintUIHTMLSource* html_source = new PrintUIHTMLSource();
+
+ // Set up the print:url source.
+ g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(&chrome_url_data_manager,
+ &ChromeURLDataManager::AddDataSource,
+ html_source));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// PrintUIHTMLSource
+//
+////////////////////////////////////////////////////////////////////////////////
+
+PrintUIHTMLSource::PrintUIHTMLSource()
+ : DataSource(chrome::kPrintScheme, MessageLoop::current()) {
+}
+
+void PrintUIHTMLSource::StartDataRequest(const std::string& path,
+ int request_id) {
+ // Setup a dictionary so that the html page could read the values.
+ DictionaryValue localized_strings;
+ localized_strings.SetString(L"title",
+ l10n_util::GetString(IDS_PRINT));
+
+ SetFontAndTextDirection(&localized_strings);
+
+ // Setup the print html page.
+ static const StringPiece print_html(
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_PRINT_TAB_HTML));
+ const std::string full_html = jstemplate_builder::GetTemplateHtml(
+ print_html, &localized_strings, "t");
+
+ // Load the print html page into the tab contents.
+ 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);
}
diff --git a/chrome/browser/dom_ui/print_ui.h b/chrome/browser/dom_ui/print_ui.h
index 020b3f1..8443da4 100644
--- a/chrome/browser/dom_ui/print_ui.h
+++ b/chrome/browser/dom_ui/print_ui.h
@@ -5,8 +5,12 @@
#ifndef CHROME_BROWSER_DOM_UI_PRINT_UI_H_
#define CHROME_BROWSER_DOM_UI_PRINT_UI_H_
+#include <string>
+
+#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/dom_ui/dom_ui.h"
+// The TabContents used for the print page.
class PrintUI : public DOMUI {
public:
explicit PrintUI(TabContents* contents);
@@ -15,4 +19,19 @@ class PrintUI : public DOMUI {
DISALLOW_COPY_AND_ASSIGN(PrintUI);
};
+// To serve dynamic print data off of chrome.
+class PrintUIHTMLSource : public ChromeURLDataManager::DataSource {
+ public:
+ PrintUIHTMLSource();
+
+ // ChromeURLDataManager overrides.
+ virtual void StartDataRequest(const std::string& path, int request_id);
+ virtual std::string GetMimeType(const std::string&) const {
+ return "text/html";
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PrintUIHTMLSource);
+};
+
#endif // CHROME_BROWSER_DOM_UI_PRINT_UI_H_