| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_DOM_UI_DOM_UI_H_ | 5 #ifndef CHROME_BROWSER_DOM_UI_DOM_UI_H_ |
| 6 #define CHROME_BROWSER_DOM_UI_DOM_UI_H_ | 6 #define CHROME_BROWSER_DOM_UI_DOM_UI_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 MessageCallbackMap message_callbacks_; | 122 MessageCallbackMap message_callbacks_; |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(DOMUI); | 124 DISALLOW_COPY_AND_ASSIGN(DOMUI); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 // Messages sent from the DOM are forwarded via the DOMUI to handler | 127 // Messages sent from the DOM are forwarded via the DOMUI to handler |
| 128 // classes. These objects are owned by DOMUI and destroyed when the | 128 // classes. These objects are owned by DOMUI and destroyed when the |
| 129 // host is destroyed. | 129 // host is destroyed. |
| 130 class DOMMessageHandler { | 130 class DOMMessageHandler { |
| 131 public: | 131 public: |
| 132 explicit DOMMessageHandler(DOMUI* dom_ui); | 132 DOMMessageHandler() : dom_ui_(NULL) { } |
| 133 virtual ~DOMMessageHandler() {}; | 133 virtual ~DOMMessageHandler() {}; |
| 134 | 134 |
| 135 // Attaches |this| to |dom_ui| in order to handle messages from it. Declared |
| 136 // virtual so that subclasses can do special init work as soon as the dom_ui |
| 137 // is provided. Returns |this| for convenience. |
| 138 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
| 135 protected: | 139 protected: |
| 136 // Adds "url" and "title" keys on incoming dictionary, setting title | 140 // Adds "url" and "title" keys on incoming dictionary, setting title |
| 137 // as the url as a fallback on empty title. | 141 // as the url as a fallback on empty title. |
| 138 static void SetURLAndTitle(DictionaryValue* dictionary, | 142 static void SetURLAndTitle(DictionaryValue* dictionary, |
| 139 std::wstring title, | 143 std::wstring title, |
| 140 const GURL& gurl); | 144 const GURL& gurl); |
| 141 | 145 |
| 146 // This is where subclasses specify which messages they'd like to handle. |
| 147 virtual void RegisterMessages() = 0; |
| 148 |
| 142 // Extract an integer value from a Value. | 149 // Extract an integer value from a Value. |
| 143 bool ExtractIntegerValue(const Value* value, int* out_int); | 150 bool ExtractIntegerValue(const Value* value, int* out_int); |
| 144 | 151 |
| 145 // Extract a string value from a Value. | 152 // Extract a string value from a Value. |
| 146 std::wstring ExtractStringValue(const Value* value); | 153 std::wstring ExtractStringValue(const Value* value); |
| 147 | 154 |
| 148 DOMUI* const dom_ui_; | 155 DOMUI* dom_ui_; |
| 149 | 156 |
| 150 private: | 157 private: |
| 151 DISALLOW_COPY_AND_ASSIGN(DOMMessageHandler); | 158 DISALLOW_COPY_AND_ASSIGN(DOMMessageHandler); |
| 152 }; | 159 }; |
| 153 | 160 |
| 154 #endif // CHROME_BROWSER_DOM_UI_DOM_UI_H_ | 161 #endif // CHROME_BROWSER_DOM_UI_DOM_UI_H_ |
| OLD | NEW |