| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "base/string16.h" |
| 11 #include "content/common/content_export.h" |
| 12 |
| 13 class GURL; |
| 14 class WebUI; |
| 15 class WebUIBrowserTest; |
| 16 |
| 17 namespace base { |
| 18 class DictionaryValue; |
| 19 class ListValue; |
| 20 } |
| 21 |
| 22 namespace content { |
| 23 |
| 24 // Messages sent from the DOM are forwarded via the WebUI to handler |
| 25 // classes. These objects are owned by WebUI and destroyed when the |
| 26 // host is destroyed. |
| 27 class CONTENT_EXPORT WebUIMessageHandler { |
| 28 public: |
| 29 WebUIMessageHandler() : web_ui_(NULL) {} |
| 30 virtual ~WebUIMessageHandler() {} |
| 31 |
| 32 protected: |
| 33 // Helper methods: |
| 34 |
| 35 // Adds "url" and "title" keys on incoming dictionary, setting title |
| 36 // as the url as a fallback on empty title. |
| 37 static void SetURLAndTitle(base::DictionaryValue* dictionary, |
| 38 string16 title, |
| 39 const GURL& gurl); |
| 40 |
| 41 // Extract an integer value from a list Value. |
| 42 static bool ExtractIntegerValue(const base::ListValue* value, int* out_int); |
| 43 |
| 44 // Extract a floating point (double) value from a list Value. |
| 45 static bool ExtractDoubleValue(const base::ListValue* value, |
| 46 double* out_value); |
| 47 |
| 48 // Extract a string value from a list Value. |
| 49 static string16 ExtractStringValue(const base::ListValue* value); |
| 50 |
| 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; |
| 55 |
| 56 // Returns the attached WebUI for this handler. |
| 57 WebUI* web_ui() const { return web_ui_; } |
| 58 |
| 59 private: |
| 60 friend class ::WebUI; |
| 61 friend class ::WebUIBrowserTest; |
| 62 |
| 63 void set_web_ui(WebUI* web_ui) { web_ui_ = web_ui; } |
| 64 |
| 65 WebUI* web_ui_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(WebUIMessageHandler); |
| 68 }; |
| 69 |
| 70 } // namespace content |
| 71 |
| 72 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ |
| 73 |
| OLD | NEW |