Chromium Code Reviews| Index: content/browser/webui/web_ui_impl.cc |
| diff --git a/content/browser/webui/web_ui_impl.cc b/content/browser/webui/web_ui_impl.cc |
| index 8e3aef02d4a46377df213cb9d3a7d8db6266a367..1cdfb2bc3741443e3e5725b888e803dfc5cc68c0 100644 |
| --- a/content/browser/webui/web_ui_impl.cc |
| +++ b/content/browser/webui/web_ui_impl.cc |
| @@ -18,8 +18,10 @@ |
| #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| #include "content/common/view_messages.h" |
| #include "content/public/browser/content_browser_client.h" |
| +#include "content/public/browser/navigation_handle.h" |
| #include "content/public/browser/render_frame_host.h" |
| #include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| #include "content/public/browser/web_ui_controller.h" |
| #include "content/public/browser/web_ui_message_handler.h" |
| #include "content/public/common/bindings_policy.h" |
| @@ -27,6 +29,26 @@ |
| namespace content { |
| +class WebUIImpl::MainFrameNavigationObserver : public WebContentsObserver { |
| + public: |
| + MainFrameNavigationObserver(WebUIImpl* parent, WebContents* contents) |
|
Charlie Reis
2016/06/25 00:02:19
nit: s/parent/web_ui/
tommycli
2016/06/25 00:12:17
Done.
|
| + : WebContentsObserver(contents), web_ui_(parent) {} |
| + ~MainFrameNavigationObserver() override {} |
| + |
| + private: |
| + void DidFinishNavigation(NavigationHandle* navigation_handle) override { |
| + // Only disallow JavaScript on cross-document navigations in the main frame. |
| + if (!navigation_handle->IsInMainFrame() || |
| + !navigation_handle->HasCommitted() || navigation_handle->IsSamePage()) { |
| + return; |
| + } |
| + |
| + web_ui_->DisallowJavascriptOnAllHandlers(); |
| + } |
| + |
| + WebUIImpl* web_ui_; |
| +}; |
| + |
| const WebUI::TypeID WebUI::kNoWebUI = NULL; |
| // static |
| @@ -50,6 +72,7 @@ WebUIImpl::WebUIImpl(WebContents* contents, const std::string& frame_name) |
| : link_transition_type_(ui::PAGE_TRANSITION_LINK), |
| bindings_(BINDINGS_POLICY_WEB_UI), |
| web_contents_(contents), |
| + web_contents_observer_(new MainFrameNavigationObserver(this, contents)), |
| frame_name_(frame_name) { |
| DCHECK(contents); |
| } |
| @@ -95,14 +118,10 @@ void WebUIImpl::RenderViewReused(RenderViewHost* render_view_host, |
| GURL site_url = render_view_host->GetSiteInstance()->GetSiteURL(); |
| GetContentClient()->browser()->LogWebUIUrl(site_url); |
| } |
| - |
| - for (WebUIMessageHandler* handler : handlers_) |
| - handler->RenderViewReused(); |
| } |
| void WebUIImpl::RenderFrameHostSwappingOut() { |
| - for (WebUIMessageHandler* handler : handlers_) |
| - handler->DisallowJavascript(); |
| + DisallowJavascriptOnAllHandlers(); |
| } |
| WebContents* WebUIImpl::GetWebContents() const { |
| @@ -284,4 +303,9 @@ void WebUIImpl::AddToSetIfFrameNameMatches( |
| frame_set->insert(host); |
| } |
| +void WebUIImpl::DisallowJavascriptOnAllHandlers() { |
| + for (WebUIMessageHandler* handler : handlers_) |
| + handler->DisallowJavascript(); |
| +} |
| + |
| } // namespace content |