| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_WEBUI_WEB_UI_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_WEBUI_WEB_UI_IMPL_H_ |
| 6 #define CONTENT_BROWSER_WEBUI_WEB_UI_IMPL_H_ | 6 #define CONTENT_BROWSER_WEBUI_WEB_UI_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 const base::Value& arg4) override; | 76 const base::Value& arg4) override; |
| 77 void CallJavascriptFunctionUnsafe( | 77 void CallJavascriptFunctionUnsafe( |
| 78 const std::string& function_name, | 78 const std::string& function_name, |
| 79 const std::vector<const base::Value*>& args) override; | 79 const std::vector<const base::Value*>& args) override; |
| 80 ScopedVector<WebUIMessageHandler>* GetHandlersForTesting() override; | 80 ScopedVector<WebUIMessageHandler>* GetHandlersForTesting() override; |
| 81 | 81 |
| 82 // IPC::Listener implementation: | 82 // IPC::Listener implementation: |
| 83 bool OnMessageReceived(const IPC::Message& message) override; | 83 bool OnMessageReceived(const IPC::Message& message) override; |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 class MainFrameNavigationObserver; |
| 87 |
| 86 // IPC message handling. | 88 // IPC message handling. |
| 87 void OnWebUISend(const GURL& source_url, | 89 void OnWebUISend(const GURL& source_url, |
| 88 const std::string& message, | 90 const std::string& message, |
| 89 const base::ListValue& args); | 91 const base::ListValue& args); |
| 90 | 92 |
| 91 // Execute a string of raw JavaScript on the page. | 93 // Execute a string of raw JavaScript on the page. |
| 92 void ExecuteJavascript(const base::string16& javascript); | 94 void ExecuteJavascript(const base::string16& javascript); |
| 93 | 95 |
| 94 // Finds the frame in which to execute JavaScript based on |frame_name_|. If | 96 // Finds the frame in which to execute JavaScript based on |frame_name_|. If |
| 95 // |frame_name_| is empty, the main frame is returned. May return NULL if no | 97 // |frame_name_| is empty, the main frame is returned. May return NULL if no |
| 96 // frame of the specified name exists in the page. | 98 // frame of the specified name exists in the page. |
| 97 RenderFrameHost* TargetFrame(); | 99 RenderFrameHost* TargetFrame(); |
| 98 | 100 |
| 99 // A helper function for TargetFrame; adds a frame to the specified set if its | 101 // A helper function for TargetFrame; adds a frame to the specified set if its |
| 100 // name matches |frame_name_|. | 102 // name matches |frame_name_|. |
| 101 void AddToSetIfFrameNameMatches(std::set<RenderFrameHost*>* frame_set, | 103 void AddToSetIfFrameNameMatches(std::set<RenderFrameHost*>* frame_set, |
| 102 RenderFrameHost* host); | 104 RenderFrameHost* host); |
| 103 | 105 |
| 106 // Called internally and by the owned MainFrameNavigationObserver. |
| 107 void DisallowJavascriptOnAllHandlers(); |
| 108 |
| 104 // A map of message name -> message handling callback. | 109 // A map of message name -> message handling callback. |
| 105 typedef std::map<std::string, MessageCallback> MessageCallbackMap; | 110 typedef std::map<std::string, MessageCallback> MessageCallbackMap; |
| 106 MessageCallbackMap message_callbacks_; | 111 MessageCallbackMap message_callbacks_; |
| 107 | 112 |
| 108 // Options that may be overridden by individual Web UI implementations. The | 113 // Options that may be overridden by individual Web UI implementations. The |
| 109 // bool options default to false. See the public getters for more information. | 114 // bool options default to false. See the public getters for more information. |
| 110 base::string16 overridden_title_; // Defaults to empty string. | 115 base::string16 overridden_title_; // Defaults to empty string. |
| 111 ui::PageTransition link_transition_type_; // Defaults to LINK. | 116 ui::PageTransition link_transition_type_; // Defaults to LINK. |
| 112 int bindings_; // The bindings from BindingsPolicy that should be enabled for | 117 int bindings_; // The bindings from BindingsPolicy that should be enabled for |
| 113 // this page. | 118 // this page. |
| 114 | 119 |
| 115 // The WebUIMessageHandlers we own. | 120 // The WebUIMessageHandlers we own. |
| 116 ScopedVector<WebUIMessageHandler> handlers_; | 121 ScopedVector<WebUIMessageHandler> handlers_; |
| 117 | 122 |
| 118 // Non-owning pointer to the WebContents this WebUI is associated with. | 123 // Non-owning pointer to the WebContents this WebUI is associated with. |
| 119 WebContents* web_contents_; | 124 WebContents* web_contents_; |
| 120 | 125 |
| 126 // Notifies this WebUI about notifications in the main frame. |
| 127 std::unique_ptr<MainFrameNavigationObserver> web_contents_observer_; |
| 128 |
| 121 // The name of the frame this WebUI is embedded in. If empty, the main frame | 129 // The name of the frame this WebUI is embedded in. If empty, the main frame |
| 122 // is used. | 130 // is used. |
| 123 const std::string frame_name_; | 131 const std::string frame_name_; |
| 124 | 132 |
| 125 std::unique_ptr<WebUIController> controller_; | 133 std::unique_ptr<WebUIController> controller_; |
| 126 | 134 |
| 127 DISALLOW_COPY_AND_ASSIGN(WebUIImpl); | 135 DISALLOW_COPY_AND_ASSIGN(WebUIImpl); |
| 128 }; | 136 }; |
| 129 | 137 |
| 130 } // namespace content | 138 } // namespace content |
| 131 | 139 |
| 132 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_IMPL_H_ | 140 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_IMPL_H_ |
| OLD | NEW |