1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_
6 #define CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_
8 #include "base/basictypes.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/string16.h"
11 #include "content/common/content_export.h"
14 class WebUIBrowserTest
;
17 class DictionaryValue
;
26 // Messages sent from the DOM are forwarded via the WebUI to handler
27 // classes. These objects are owned by WebUI and destroyed when the
29 class CONTENT_EXPORT WebUIMessageHandler
{
31 WebUIMessageHandler() : web_ui_(NULL
) {}
32 virtual ~WebUIMessageHandler() {}
35 FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest
, ExtractIntegerValue
);
36 FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest
, ExtractDoubleValue
);
37 FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest
, ExtractStringValue
);
41 // Extract an integer value from a list Value.
42 static bool ExtractIntegerValue(const base::ListValue
* value
, int* out_int
);
44 // Extract a floating point (double) value from a list Value.
45 static bool ExtractDoubleValue(const base::ListValue
* value
,
48 // Extract a string value from a list Value.
49 static string16
ExtractStringValue(const base::ListValue
* value
);
51 // This is where subclasses specify which messages they'd like to handle and
52 // perform any additional initialization.. At this point web_ui() will return
53 // the associated WebUI object.
54 virtual void RegisterMessages() = 0;
56 // Returns the attached WebUI for this handler.
57 WebUI
* web_ui() const { return web_ui_
; }
59 // Sets the attached WebUI - exposed to subclasses for testing purposes.
60 void set_web_ui(WebUI
* web_ui
) { web_ui_
= web_ui
; }
63 // Provide external classes access to web_ui() and set_web_ui().
64 friend class WebUIImpl
;
65 friend class ::WebUIBrowserTest
;
70 } // namespace content
72 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_