Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: content/browser/webui/web_ui_impl.cc

Issue 2099563002: WebUI: DisallowJavascript only on Refresh and non-same-page navigations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: small fixes Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..2fdc9803266066423feaff0f3fb4589343c31475 100644
--- a/content/browser/webui/web_ui_impl.cc
+++ b/content/browser/webui/web_ui_impl.cc
@@ -18,6 +18,7 @@
#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_ui_controller.h"
Charlie Reis 2016/06/24 23:15:00 IWYU nit: web_contents_observer.h
tommycli 2016/06/24 23:55:36 Done.
@@ -27,6 +28,25 @@
namespace content {
+class WebUIImpl::MainFrameNavigationObserver : public WebContentsObserver {
+ public:
+ MainFrameNavigationObserver(WebUIImpl* parent, WebContents* contents)
+ : WebContentsObserver(contents), parent_(parent) {}
+ ~MainFrameNavigationObserver() override {}
+
+ private:
+ void DidFinishNavigation(NavigationHandle* navigation_handle) override {
+ if (!navigation_handle->IsInMainFrame() ||
Charlie Reis 2016/06/24 23:15:00 // Only disallow Javascript on cross-document navi
tommycli 2016/06/24 23:55:36 Done.
+ !navigation_handle->HasCommitted() || navigation_handle->IsSamePage()) {
+ return;
+ }
+
+ parent_->DisallowJavascriptOnAllHandlers();
+ }
+
+ WebUIImpl* parent_;
Charlie Reis 2016/06/24 23:15:00 web_ui_, perhaps? (Parent is a confusing term, si
tommycli 2016/06/24 23:55:36 Done.
+};
+
const WebUI::TypeID WebUI::kNoWebUI = NULL;
// static
@@ -50,6 +70,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 +116,10 @@ void WebUIImpl::RenderViewReused(RenderViewHost* render_view_host,
GURL site_url = render_view_host->GetSiteInstance()->GetSiteURL();
GetContentClient()->browser()->LogWebUIUrl(site_url);
Charlie Reis 2016/06/24 23:15:01 Ooh, I wonder if we can get rid of RenderViewReuse
tommycli 2016/06/24 23:55:36 Yeah I think that would be eminently doable. But y
}
-
- for (WebUIMessageHandler* handler : handlers_)
- handler->RenderViewReused();
}
void WebUIImpl::RenderFrameHostSwappingOut() {
- for (WebUIMessageHandler* handler : handlers_)
- handler->DisallowJavascript();
+ DisallowJavascriptOnAllHandlers();
}
WebContents* WebUIImpl::GetWebContents() const {
@@ -284,4 +301,9 @@ void WebUIImpl::AddToSetIfFrameNameMatches(
frame_set->insert(host);
}
+void WebUIImpl::DisallowJavascriptOnAllHandlers() {
+ for (WebUIMessageHandler* handler : handlers_)
+ handler->DisallowJavascript();
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698