| 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_H__ | 5 #ifndef CHROME_BROWSER_DOM_UI_H__ |
| 6 #define CHROME_BROWSER_DOM_UI_H__ | 6 #define CHROME_BROWSER_DOM_UI_H__ |
| 7 | 7 |
| 8 #include "base/task.h" | 8 #include "base/task.h" |
| 9 #include "chrome/browser/dom_ui/dom_ui_contents.h" | 9 #include "chrome/browser/dom_ui/dom_ui_contents.h" |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // of the call, and should be thought of more like sending a message to | 35 // of the call, and should be thought of more like sending a message to |
| 36 // the page. | 36 // the page. |
| 37 // There are two function variants for one-arg and two-arg calls. | 37 // There are two function variants for one-arg and two-arg calls. |
| 38 void CallJavascriptFunction(const std::wstring& function_name); | 38 void CallJavascriptFunction(const std::wstring& function_name); |
| 39 void CallJavascriptFunction(const std::wstring& function_name, | 39 void CallJavascriptFunction(const std::wstring& function_name, |
| 40 const Value& arg); | 40 const Value& arg); |
| 41 void CallJavascriptFunction(const std::wstring& function_name, | 41 void CallJavascriptFunction(const std::wstring& function_name, |
| 42 const Value& arg1, | 42 const Value& arg1, |
| 43 const Value& arg2); | 43 const Value& arg2); |
| 44 | 44 |
| 45 // Overriddable control over the contents. |
| 46 // Favicon should be displayed normally. |
| 47 virtual bool ShouldDisplayFavIcon() { return true; } |
| 48 // No special bookmark bar behavior |
| 49 virtual bool IsBookmarkBarAlwaysVisible() { return false; } |
| 50 // When NTP gets the initial focus, focus the URL bar. |
| 51 virtual void SetInitialFocus() {}; |
| 52 // Whether we want to display the page's URL. |
| 53 virtual bool ShouldDisplayURL() { return true; } |
| 54 // Hide the referrer. |
| 55 virtual void RequestOpenURL(const GURL& url, const GURL&, |
| 56 WindowOpenDisposition disposition); |
| 57 |
| 58 DOMUIContents* get_contents() { return contents_; } |
| 45 Profile* get_profile() { return contents_->profile(); } | 59 Profile* get_profile() { return contents_->profile(); } |
| 46 | 60 |
| 47 protected: | 61 protected: |
| 48 void AddMessageHandler(DOMMessageHandler* handler); | 62 void AddMessageHandler(DOMMessageHandler* handler); |
| 49 | 63 |
| 50 DOMUIContents* contents_; | 64 DOMUIContents* contents_; |
| 51 | 65 |
| 52 private: | 66 private: |
| 53 // Execute a string of raw Javascript on the page. | 67 // Execute a string of raw Javascript on the page. |
| 54 void ExecuteJavascript(const std::wstring& javascript); | 68 void ExecuteJavascript(const std::wstring& javascript); |
| 55 | 69 |
| 56 // The DOMMessageHandlers we own. | 70 // The DOMMessageHandlers we own. |
| 57 std::vector<DOMMessageHandler*> handlers_; | 71 std::vector<DOMMessageHandler*> handlers_; |
| 58 | 72 |
| 59 // A map of message name -> message handling callback. | 73 // A map of message name -> message handling callback. |
| 60 typedef std::map<std::string, MessageCallback*> MessageCallbackMap; | 74 typedef std::map<std::string, MessageCallback*> MessageCallbackMap; |
| 61 MessageCallbackMap message_callbacks_; | 75 MessageCallbackMap message_callbacks_; |
| 62 | 76 |
| 63 DISALLOW_COPY_AND_ASSIGN(DOMUI); | 77 DISALLOW_COPY_AND_ASSIGN(DOMUI); |
| 64 }; | 78 }; |
| 65 | 79 |
| 66 // Messages sent from the DOM are forwarded via the DOMUIContents to handler | 80 // Messages sent from the DOM are forwarded via the DOMUIContents to handler |
| 67 // classes. These objects are owned by DOMUIHost and destroyed when the | 81 // classes. These objects are owned by DOMUIHost and destroyed when the |
| 68 // host is destroyed. | 82 // host is destroyed. |
| 69 class DOMMessageHandler { | 83 class DOMMessageHandler { |
| 70 public: | 84 public: |
| 71 explicit DOMMessageHandler(DOMUI* dom_ui); | 85 explicit DOMMessageHandler(DOMUI* dom_ui); |
| 72 virtual ~DOMMessageHandler(); | 86 virtual ~DOMMessageHandler() {}; |
| 73 | 87 |
| 74 protected: | 88 protected: |
| 75 // Adds "url" and "title" keys on incoming dictionary, setting title | 89 // Adds "url" and "title" keys on incoming dictionary, setting title |
| 76 // as the url as a fallback on empty title. | 90 // as the url as a fallback on empty title. |
| 77 static void SetURLAndTitle(DictionaryValue* dictionary, | 91 static void SetURLAndTitle(DictionaryValue* dictionary, |
| 78 std::wstring title, | 92 std::wstring title, |
| 79 const GURL& gurl); | 93 const GURL& gurl); |
| 80 | 94 |
| 81 // Extract an integer value from a Value. | 95 // Extract an integer value from a Value. |
| 82 bool ExtractIntegerValue(const Value* value, int* out_int); | 96 bool ExtractIntegerValue(const Value* value, int* out_int); |
| 83 | 97 |
| 84 // Extract a string value from a Value. | 98 // Extract a string value from a Value. |
| 85 std::wstring ExtractStringValue(const Value* value); | 99 std::wstring ExtractStringValue(const Value* value); |
| 86 | 100 |
| 87 DOMUI* const dom_ui_; | 101 DOMUI* const dom_ui_; |
| 88 | 102 |
| 89 private: | 103 private: |
| 90 DISALLOW_COPY_AND_ASSIGN(DOMMessageHandler); | 104 DISALLOW_COPY_AND_ASSIGN(DOMMessageHandler); |
| 91 }; | 105 }; |
| 92 | 106 |
| 93 | |
| 94 #endif // CHROME_BROWSER_DOM_UI_H__ | 107 #endif // CHROME_BROWSER_DOM_UI_H__ |
| OLD | NEW |