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 #include "content/browser/webui/web_ui_impl.h" | 5 #include "content/browser/webui/web_ui_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 IPC_BEGIN_MESSAGE_MAP(WebUIImpl, message) | 72 IPC_BEGIN_MESSAGE_MAP(WebUIImpl, message) |
73 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) | 73 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
74 IPC_MESSAGE_UNHANDLED(handled = false) | 74 IPC_MESSAGE_UNHANDLED(handled = false) |
75 IPC_END_MESSAGE_MAP() | 75 IPC_END_MESSAGE_MAP() |
76 return handled; | 76 return handled; |
77 } | 77 } |
78 | 78 |
79 void WebUIImpl::OnWebUISend(const GURL& source_url, | 79 void WebUIImpl::OnWebUISend(const GURL& source_url, |
80 const std::string& message, | 80 const std::string& message, |
81 const ListValue& args) { | 81 const ListValue& args) { |
82 // If the URL comes from a url where the document is not available, that can | |
83 // only mean that the page navigated or reloaded while a WebUISend IPC was in | |
84 // flight. We should not handle these orphaned WebUISends. | |
85 if (document_available_origins_.find(source_url.GetOrigin()) == | |
86 document_available_origins_.end()) { | |
87 return; | |
88 } | |
89 | |
90 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> | 82 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> |
91 HasWebUIBindings(web_contents_->GetRenderProcessHost()->GetID())) { | 83 HasWebUIBindings(web_contents_->GetRenderProcessHost()->GetID())) { |
92 NOTREACHED() << "Blocked unauthorized use of WebUIBindings."; | 84 NOTREACHED() << "Blocked unauthorized use of WebUIBindings."; |
93 return; | 85 return; |
94 } | 86 } |
95 | 87 |
96 ProcessWebUIMessage(source_url, message, args); | 88 ProcessWebUIMessage(source_url, message, args); |
97 } | 89 } |
98 | 90 |
99 void WebUIImpl::RenderViewCreated(content::RenderViewHost* render_view_host) { | 91 void WebUIImpl::RenderViewCreated(content::RenderViewHost* render_view_host) { |
(...skipping 11 matching lines...) Expand all Loading... |
111 #endif // defined(TOOLKIT_VIEWS) | 103 #endif // defined(TOOLKIT_VIEWS) |
112 | 104 |
113 // Let the WebUI know that we're looking for UI that's optimized for touch | 105 // Let the WebUI know that we're looking for UI that's optimized for touch |
114 // input. | 106 // input. |
115 // TODO(rbyers) Figure out the right model for enabling touch-optimized UI | 107 // TODO(rbyers) Figure out the right model for enabling touch-optimized UI |
116 // (http://crbug.com/105380). | 108 // (http://crbug.com/105380). |
117 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTouchOptimizedUI)) | 109 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTouchOptimizedUI)) |
118 render_view_host->SetWebUIProperty("touchOptimized", "true"); | 110 render_view_host->SetWebUIProperty("touchOptimized", "true"); |
119 } | 111 } |
120 | 112 |
121 void WebUIImpl::DocumentAvailableInFrame(const GURL& source_url) { | |
122 document_available_origins_.insert(source_url.GetOrigin()); | |
123 } | |
124 | |
125 WebContents* WebUIImpl::GetWebContents() const { | 113 WebContents* WebUIImpl::GetWebContents() const { |
126 return web_contents_; | 114 return web_contents_; |
127 } | 115 } |
128 | 116 |
129 bool WebUIImpl::ShouldHideFavicon() const { | 117 bool WebUIImpl::ShouldHideFavicon() const { |
130 return hide_favicon_; | 118 return hide_favicon_; |
131 } | 119 } |
132 | 120 |
133 void WebUIImpl::HideFavicon() { | 121 void WebUIImpl::HideFavicon() { |
134 hide_favicon_ = true; | 122 hide_favicon_ = true; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 handler->set_web_ui(this); | 258 handler->set_web_ui(this); |
271 handler->RegisterMessages(); | 259 handler->RegisterMessages(); |
272 handlers_.push_back(handler); | 260 handlers_.push_back(handler); |
273 } | 261 } |
274 | 262 |
275 void WebUIImpl::ExecuteJavascript(const string16& javascript) { | 263 void WebUIImpl::ExecuteJavascript(const string16& javascript) { |
276 static_cast<RenderViewHostImpl*>( | 264 static_cast<RenderViewHostImpl*>( |
277 web_contents_->GetRenderViewHost())->ExecuteJavascriptInWebFrame( | 265 web_contents_->GetRenderViewHost())->ExecuteJavascriptInWebFrame( |
278 ASCIIToUTF16(frame_xpath_), javascript); | 266 ASCIIToUTF16(frame_xpath_), javascript); |
279 } | 267 } |
OLD | NEW |