Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / public / provider / web / web_ui_ios_message_handler.h
blob133dc8280fec6eddaa7135b661169a9c539b0f27
1 // Copyright 2014 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 IOS_PUBLIC_PROVIDER_WEB_WEB_UI_IOS_MESSAGE_HANDLER_H_
6 #define IOS_PUBLIC_PROVIDER_WEB_WEB_UI_IOS_MESSAGE_HANDLER_H_
8 #include "base/basictypes.h"
9 #include "base/strings/string16.h"
11 class GURL;
13 namespace base {
14 class DictionaryValue;
15 class ListValue;
18 namespace web {
20 class WebUIIOS;
21 class WebUIIOSImpl;
23 // Messages sent from the DOM are forwarded via the WebUIIOS to handler
24 // classes. These objects are owned by WebUIIOS and destroyed when the
25 // host is destroyed.
26 class WebUIIOSMessageHandler {
27 public:
28 WebUIIOSMessageHandler() : web_ui_(NULL) {}
29 virtual ~WebUIIOSMessageHandler() {}
31 protected:
32 // Helper methods:
34 // Extract an integer value from a list Value.
35 static bool ExtractIntegerValue(const base::ListValue* value, int* out_int);
37 // Extract a floating point (double) value from a list Value.
38 static bool ExtractDoubleValue(const base::ListValue* value,
39 double* out_value);
41 // Extract a string value from a list Value.
42 static base::string16 ExtractStringValue(const base::ListValue* value);
44 // This is where subclasses specify which messages they'd like to handle and
45 // perform any additional initialization. At this point web_ui() will return
46 // the associated WebUIIOS object.
47 virtual void RegisterMessages() = 0;
49 // Returns the attached WebUIIOS for this handler.
50 WebUIIOS* web_ui() const { return web_ui_; }
52 // Sets the attached WebUIIOS - exposed to subclasses for testing purposes.
53 void set_web_ui(WebUIIOS* web_ui) { web_ui_ = web_ui; }
55 private:
56 // Provide external classes access to web_ui() and set_web_ui().
57 friend class WebUIIOSImpl;
59 WebUIIOS* web_ui_;
62 } // namespace web
64 #endif // IOS_PUBLIC_PROVIDER_WEB_WEB_UI_IOS_MESSAGE_HANDLER_H_