summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-03 23:24:40 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-03 23:24:40 +0000
commitb4cb09136ad55f2e72093d723d287fe63094dd88 (patch)
tree2e0786658c85e5b8f4e42b649ec308a5ce2d66ac /chrome/browser
parent1168b68bbbbf53df44445820f58b06e45421c628 (diff)
downloadchromium_src-b4cb09136ad55f2e72093d723d287fe63094dd88.zip
chromium_src-b4cb09136ad55f2e72093d723d287fe63094dd88.tar.gz
chromium_src-b4cb09136ad55f2e72093d723d287fe63094dd88.tar.bz2
Add an IFDEF for developers of about:tracking2, so the javascript/html are loaded directly off disk rather than getting loaded from the resources package. This avoids having to rebuild after each change to test it in the webapp.
BUG=100992 Review URL: http://codereview.chromium.org/8452005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108575 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/ui/webui/tracking_ui.cc68
1 files changed, 68 insertions, 0 deletions
diff --git a/chrome/browser/ui/webui/tracking_ui.cc b/chrome/browser/ui/webui/tracking_ui.cc
index 271184a..87988024 100644
--- a/chrome/browser/ui/webui/tracking_ui.cc
+++ b/chrome/browser/ui/webui/tracking_ui.cc
@@ -6,6 +6,13 @@
#include <string>
+// When testing the javacript code, it is cumbersome to have to keep
+// re-building the resouces package and reloading the browser. To solve
+// this, enable the following flag to read the webapp's source files
+// directly off disk, so all you have to do is refresh the page to
+// test the modifications.
+//#define USE_SOURCE_FILES_DIRECTLY
+
#include "base/bind.h"
#include "base/tracked_objects.h"
#include "chrome/browser/profiles/profile.h"
@@ -16,10 +23,69 @@
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
+#ifdef USE_SOURCE_FILES_DIRECTLY
+#include "base/base_paths.h"
+#include "base/file_util.h"
+#include "base/memory/ref_counted_memory.h"
+#include "base/path_service.h"
+#endif // USE_SOURCE_FILES_DIRECTLY
+
using content::BrowserThread;
namespace {
+#ifdef USE_SOURCE_FILES_DIRECTLY
+
+class TrackingWebUIDataSource : public ChromeURLDataManager::DataSource {
+ public:
+ TrackingWebUIDataSource()
+ : DataSource(chrome::kChromeUITrackingHost2, MessageLoop::current()) {
+ }
+
+ protected:
+ // ChromeURLDataManager
+ virtual std::string GetMimeType(const std::string& path) const OVERRIDE {
+ if (EndsWith(path, ".js", false))
+ return "application/javascript";
+ return "text/html";
+ }
+
+ virtual void StartDataRequest(const std::string& path,
+ bool is_incognito,
+ int request_id) OVERRIDE {
+ FilePath base_path;
+ PathService::Get(base::DIR_SOURCE_ROOT, &base_path);
+ base_path = base_path.AppendASCII("chrome");
+ base_path = base_path.AppendASCII("browser");
+ base_path = base_path.AppendASCII("resources");
+
+ // If no resource was specified, default to tracking.html.
+ std::string filename = path.empty() ? "tracking.html" : path;
+
+ FilePath file_path;
+ file_path = base_path.AppendASCII(filename);
+
+ // Read the file synchronously and send it as the response.
+ base::ThreadRestrictions::ScopedAllowIO allow;
+ std::string file_contents;
+ if (!file_util::ReadFileToString(file_path, &file_contents))
+ LOG(ERROR) << "Couldn't read file: " << file_path.value();
+ scoped_refptr<base::RefCountedString> response =
+ new base::RefCountedString();
+ response->data() = file_contents;
+ SendResponse(request_id, response);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TrackingWebUIDataSource);
+};
+
+ChromeURLDataManager::DataSource* CreateTrackingHTMLSource() {
+ return new TrackingWebUIDataSource();
+}
+
+#else // USE_SOURCE_FILES_DIRECTLY
+
ChromeWebUIDataSource* CreateTrackingHTMLSource() {
// TODO(eroman): Use kChromeUITrackingHost instead of kChromeUITrackingHost2
// once migration to webui is complete.
@@ -32,6 +98,8 @@ ChromeWebUIDataSource* CreateTrackingHTMLSource() {
return source;
}
+#endif
+
// This class receives javascript messages from the renderer.
// Note that the WebUI infrastructure runs on the UI thread, therefore all of
// this class's methods are expected to run on the UI thread.