Update V8 to version 4.6.61.
[chromium-blink-merge.git] / content / public / browser / web_ui_message_handler.h
blobb6908769a00b28a824e51271db0a724a03e39c08
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/strings/string16.h"
11 #include "content/common/content_export.h"
13 class GURL;
14 class WebUIBrowserTest;
16 namespace base {
17 class DictionaryValue;
18 class ListValue;
21 namespace content {
23 class WebUI;
24 class WebUIImpl;
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
28 // host is destroyed.
29 class CONTENT_EXPORT WebUIMessageHandler {
30 public:
31 WebUIMessageHandler() : web_ui_(nullptr) {}
32 virtual ~WebUIMessageHandler() {}
34 protected:
35 FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest, ExtractIntegerValue);
36 FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest, ExtractDoubleValue);
37 FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest, ExtractStringValue);
39 // Helper methods:
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,
46 double* out_value);
48 // Extract a string value from a list Value.
49 static base::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; }
62 private:
63 // Provide external classes access to web_ui() and set_web_ui().
64 friend class WebUIImpl;
65 friend class ::WebUIBrowserTest;
67 WebUI* web_ui_;
70 } // namespace content
72 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_