summaryrefslogtreecommitdiffstats
path: root/content/public
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-31 04:02:55 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-31 04:02:55 +0000
commit26e2632ad09c70437fd40336cbee82af0d56a0d8 (patch)
tree20fc6633eb78bcacee9ecb7e0517fd0407921799 /content/public
parenta0d75a4fc048c27289df8ecbf1982c7aa40bea6e (diff)
downloadchromium_src-26e2632ad09c70437fd40336cbee82af0d56a0d8.zip
chromium_src-26e2632ad09c70437fd40336cbee82af0d56a0d8.tar.gz
chromium_src-26e2632ad09c70437fd40336cbee82af0d56a0d8.tar.bz2
Move WebUIMessageHandler to its own file in the public directory and put it in the content namespace.
BUG=98716 TBR=joi Review URL: http://codereview.chromium.org/8986007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116057 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/public')
-rw-r--r--content/public/browser/web_ui_message_handler.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/content/public/browser/web_ui_message_handler.h b/content/public/browser/web_ui_message_handler.h
new file mode 100644
index 0000000..9619d37
--- /dev/null
+++ b/content/public/browser/web_ui_message_handler.h
@@ -0,0 +1,73 @@
+// Copyright (c) 2011 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 CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_
+#define CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/string16.h"
+#include "content/common/content_export.h"
+
+class GURL;
+class WebUI;
+class WebUIBrowserTest;
+
+namespace base {
+class DictionaryValue;
+class ListValue;
+}
+
+namespace content {
+
+// Messages sent from the DOM are forwarded via the WebUI to handler
+// classes. These objects are owned by WebUI and destroyed when the
+// host is destroyed.
+class CONTENT_EXPORT WebUIMessageHandler {
+ public:
+ WebUIMessageHandler() : web_ui_(NULL) {}
+ virtual ~WebUIMessageHandler() {}
+
+ protected:
+ // Helper methods:
+
+ // Adds "url" and "title" keys on incoming dictionary, setting title
+ // as the url as a fallback on empty title.
+ static void SetURLAndTitle(base::DictionaryValue* dictionary,
+ string16 title,
+ const GURL& gurl);
+
+ // Extract an integer value from a list Value.
+ static bool ExtractIntegerValue(const base::ListValue* value, int* out_int);
+
+ // Extract a floating point (double) value from a list Value.
+ static bool ExtractDoubleValue(const base::ListValue* value,
+ double* out_value);
+
+ // Extract a string value from a list Value.
+ static string16 ExtractStringValue(const base::ListValue* value);
+
+ // This is where subclasses specify which messages they'd like to handle and
+ // perform any additional initialization.. At this point web_ui() will return
+ // the associated WebUI object.
+ virtual void RegisterMessages() = 0;
+
+ // Returns the attached WebUI for this handler.
+ WebUI* web_ui() const { return web_ui_; }
+
+ private:
+ friend class ::WebUI;
+ friend class ::WebUIBrowserTest;
+
+ void set_web_ui(WebUI* web_ui) { web_ui_ = web_ui; }
+
+ WebUI* web_ui_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebUIMessageHandler);
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_
+