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

Side by Side Diff: content/renderer/render_view_impl.cc

Issue 10387074: Only disallow top-level navigations in platform apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mike's review feedback Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/renderer/render_view_impl.h" 5 #include "content/renderer/render_view_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 2344 matching lines...) Expand 10 before | Expand all | Expand 10 after
2355 WebString origin_str = frame->document().securityOrigin().toString(); 2355 WebString origin_str = frame->document().securityOrigin().toString();
2356 GURL frame_url(origin_str.utf8().data()); 2356 GURL frame_url(origin_str.utf8().data());
2357 // TODO(cevans): revisit whether this origin check is still necessary once 2357 // TODO(cevans): revisit whether this origin check is still necessary once
2358 // crbug.com/101395 is fixed. 2358 // crbug.com/101395 is fixed.
2359 if (frame_url.GetOrigin() != url.GetOrigin()) { 2359 if (frame_url.GetOrigin() != url.GetOrigin()) {
2360 OpenURL(frame, url, referrer, default_policy); 2360 OpenURL(frame, url, referrer, default_policy);
2361 return WebKit::WebNavigationPolicyIgnore; 2361 return WebKit::WebNavigationPolicyIgnore;
2362 } 2362 }
2363 } 2363 }
2364 2364
2365 // If the browser is interested, then give it a chance to look at top level 2365 // If the browser is interested, then give it a chance to look at the request.
2366 // navigations.
2367 if (is_content_initiated) { 2366 if (is_content_initiated) {
2368 bool browser_handles_top_level_requests = 2367 bool browser_handles_request =
2369 renderer_preferences_.browser_handles_top_level_requests && 2368 renderer_preferences_.browser_handles_top_level_requests &&
2370 IsNonLocalTopLevelNavigation(url, frame, type); 2369 IsNonLocalTopLevelNavigation(url, frame, type);
2371 if (browser_handles_top_level_requests || 2370 if (!browser_handles_request) {
2372 renderer_preferences_.browser_handles_all_requests) { 2371 browser_handles_request = renderer_preferences_.
2372 browser_handles_all_top_level_or_non_local_requests &&
2373 IsNonLocalOrTopLevelNavigation(url, frame);
2374 }
2375
2376 if (browser_handles_request) {
2373 // Reset these counters as the RenderView could be reused for the next 2377 // Reset these counters as the RenderView could be reused for the next
2374 // navigation. 2378 // navigation.
2375 page_id_ = -1; 2379 page_id_ = -1;
2376 last_page_id_sent_to_browser_ = -1; 2380 last_page_id_sent_to_browser_ = -1;
2377 OpenURL(frame, url, referrer, default_policy); 2381 OpenURL(frame, url, referrer, default_policy);
2378 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. 2382 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2379 } 2383 }
2380 } 2384 }
2381 2385
2382 // Detect when we're crossing a permission-based boundary (e.g. into or out of 2386 // Detect when we're crossing a permission-based boundary (e.g. into or out of
(...skipping 2821 matching lines...) Expand 10 before | Expand all | Expand 10 after
5204 &override_state)) 5208 &override_state))
5205 return override_state; 5209 return override_state;
5206 return current_state; 5210 return current_state;
5207 } 5211 }
5208 5212
5209 WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() { 5213 WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
5210 EnsureMediaStreamImpl(); 5214 EnsureMediaStreamImpl();
5211 return media_stream_impl_; 5215 return media_stream_impl_;
5212 } 5216 }
5213 5217
5218 bool RenderViewImpl::IsNonLocalOrTopLevelNavigation(
darin (slow to review) 2012/05/12 00:00:51 it seems like you are using "NonLocal" to mean !sa
Mihai Parparita -not on Chrome 2012/05/15 20:51:46 The problem is that data: URLs are allowed too, so
darin (slow to review) 2012/05/15 23:58:44 What about blob URLs or filesystem URLs? I think
Mihai Parparita -not on Chrome 2012/05/16 00:36:45 Both of those should be allowed (added them to the
5219 const GURL& url, WebKit::WebFrame* frame) const {
5220 if (frame->parent() == NULL)
5221 return true;
5222
5223 // data: URLs don't involve remote content either, thus are considered local.
5224 if (url.SchemeIs(chrome::kDataScheme))
5225 return false;
5226
5227 return url.GetOrigin() != GURL(frame->top()->document().url()).GetOrigin();
darin (slow to review) 2012/05/12 00:00:51 why do you check the origin of frame->top() as opp
Mihai Parparita -not on Chrome 2012/05/15 20:51:46 The frame hasn't navigated yet, so it's at about:b
darin (slow to review) 2012/05/15 23:58:44 But what if the top-most frame was created dynamic
Mihai Parparita -not on Chrome 2012/05/16 00:36:45 I've switched to using the document's security ori
5228 }
5229
5214 bool RenderViewImpl::IsNonLocalTopLevelNavigation( 5230 bool RenderViewImpl::IsNonLocalTopLevelNavigation(
5215 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) { 5231 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type)
5232 const {
5216 // Must be a top level frame. 5233 // Must be a top level frame.
5217 if (frame->parent() != NULL) 5234 if (frame->parent() != NULL)
5218 return false; 5235 return false;
5219 5236
5220 // Navigations initiated within Webkit are not sent out to the external host 5237 // Navigations initiated within Webkit are not sent out to the external host
5221 // in the following cases. 5238 // in the following cases.
5222 // 1. The url scheme is not http/https 5239 // 1. The url scheme is not http/https
5223 // 2. The origin of the url and the opener is the same in which case the 5240 // 2. The origin of the url and the opener is the same in which case the
5224 // opener relationship is maintained. 5241 // opener relationship is maintained.
5225 // 3. Reloads/form submits/back forward navigations 5242 // 3. Reloads/form submits/back forward navigations
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
5300 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { 5317 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
5301 return !!RenderThreadImpl::current()->compositor_thread(); 5318 return !!RenderThreadImpl::current()->compositor_thread();
5302 } 5319 }
5303 5320
5304 void RenderViewImpl::OnJavaBridgeInit() { 5321 void RenderViewImpl::OnJavaBridgeInit() {
5305 DCHECK(!java_bridge_dispatcher_.get()); 5322 DCHECK(!java_bridge_dispatcher_.get());
5306 #if defined(ENABLE_JAVA_BRIDGE) 5323 #if defined(ENABLE_JAVA_BRIDGE)
5307 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); 5324 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
5308 #endif 5325 #endif
5309 } 5326 }
OLDNEW
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698