blob: da1c1c0487955840dc3fce1fc72f334be3faa1c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright (c) 2012 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_
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/string16.h"
#include "content/common/content_export.h"
class GURL;
class WebUIBrowserTest;
namespace base {
class DictionaryValue;
class ListValue;
}
namespace content {
class WebUI;
class WebUIImpl;
// 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:
FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest, ExtractIntegerValue);
FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest, ExtractDoubleValue);
FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest, ExtractStringValue);
// Helper methods:
// 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_; }
// Sets the attached WebUI - exposed to subclasses for testing purposes.
void set_web_ui(WebUI* web_ui) { web_ui_ = web_ui; }
private:
// Provide external classes access to web_ui() and set_web_ui().
friend class WebUIImpl;
friend class ::WebUIBrowserTest;
WebUI* web_ui_;
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_
|