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

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: Nits 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 base::KillProcess(base::GetCurrentProcessHandle(), 1, false); 382 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
383 } else if (url == GURL(chrome::kChromeUIHangURL)) { 383 } else if (url == GURL(chrome::kChromeUIHangURL)) {
384 for (;;) { 384 for (;;) {
385 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); 385 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
386 } 386 }
387 } else if (url == GURL(chrome::kChromeUIShorthangURL)) { 387 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
388 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); 388 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
389 } 389 }
390 } 390 }
391 391
392 // Returns false unless this is a top-level navigation.
393 static bool IsTopLevelNavigation(WebFrame* frame) {
394 return frame->parent() == NULL;
395 }
396
397 // Returns false unless this is a top-level navigation that crosses origins.
398 static bool IsNonLocalTopLevelNavigation(const GURL& url,
399 WebFrame* frame,
400 WebNavigationType type) {
401 if (!IsTopLevelNavigation(frame))
402 return false;
403
404 // Navigations initiated within Webkit are not sent out to the external host
405 // in the following cases.
406 // 1. The url scheme is not http/https
407 // 2. The origin of the url and the opener is the same in which case the
408 // opener relationship is maintained.
409 // 3. Reloads/form submits/back forward navigations
410 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
411 return false;
412
413 // Not interested in reloads/form submits/resubmits/back forward navigations.
414 if (type != WebKit::WebNavigationTypeReload &&
415 type != WebKit::WebNavigationTypeFormSubmitted &&
416 type != WebKit::WebNavigationTypeFormResubmitted &&
417 type != WebKit::WebNavigationTypeBackForward) {
418 // The opener relationship between the new window and the parent allows the
419 // new window to script the parent and vice versa. This is not allowed if
420 // the origins of the two domains are different. This can be treated as a
421 // top level navigation and routed back to the host.
422 WebKit::WebFrame* opener = frame->opener();
423 if (!opener) {
424 return true;
425 }
426
427 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
428 return true;
429 }
430 return false;
431 }
432
392 /////////////////////////////////////////////////////////////////////////////// 433 ///////////////////////////////////////////////////////////////////////////////
393 434
394 struct RenderViewImpl::PendingFileChooser { 435 struct RenderViewImpl::PendingFileChooser {
395 PendingFileChooser(const content::FileChooserParams& p, 436 PendingFileChooser(const content::FileChooserParams& p,
396 WebFileChooserCompletion* c) 437 WebFileChooserCompletion* c)
397 : params(p), 438 : params(p),
398 completion(c) { 439 completion(c) {
399 } 440 }
400 content::FileChooserParams params; 441 content::FileChooserParams params;
401 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. 442 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
(...skipping 1966 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 WebString origin_str = frame->document().securityOrigin().toString(); 2409 WebString origin_str = frame->document().securityOrigin().toString();
2369 GURL frame_url(origin_str.utf8().data()); 2410 GURL frame_url(origin_str.utf8().data());
2370 // TODO(cevans): revisit whether this origin check is still necessary once 2411 // TODO(cevans): revisit whether this origin check is still necessary once
2371 // crbug.com/101395 is fixed. 2412 // crbug.com/101395 is fixed.
2372 if (frame_url.GetOrigin() != url.GetOrigin()) { 2413 if (frame_url.GetOrigin() != url.GetOrigin()) {
2373 OpenURL(frame, url, referrer, default_policy); 2414 OpenURL(frame, url, referrer, default_policy);
2374 return WebKit::WebNavigationPolicyIgnore; 2415 return WebKit::WebNavigationPolicyIgnore;
2375 } 2416 }
2376 } 2417 }
2377 2418
2378 // If the browser is interested, then give it a chance to look at top level 2419 // If the browser is interested, then give it a chance to look at the request.
2379 // navigations.
2380 if (is_content_initiated) { 2420 if (is_content_initiated) {
2381 bool browser_handles_top_level_requests = 2421 bool browser_handles_request =
2382 renderer_preferences_.browser_handles_top_level_requests && 2422 renderer_preferences_.browser_handles_non_local_top_level_requests &&
2383 IsNonLocalTopLevelNavigation(url, frame, type); 2423 IsNonLocalTopLevelNavigation(url, frame, type);
2384 if (browser_handles_top_level_requests || 2424 if (!browser_handles_request) {
2385 renderer_preferences_.browser_handles_all_requests) { 2425 browser_handles_request =
2426 renderer_preferences_.browser_handles_all_top_level_requests &&
2427 IsTopLevelNavigation(frame);
2428 }
2429
2430 if (browser_handles_request) {
2386 // Reset these counters as the RenderView could be reused for the next 2431 // Reset these counters as the RenderView could be reused for the next
2387 // navigation. 2432 // navigation.
2388 page_id_ = -1; 2433 page_id_ = -1;
2389 last_page_id_sent_to_browser_ = -1; 2434 last_page_id_sent_to_browser_ = -1;
2390 OpenURL(frame, url, referrer, default_policy); 2435 OpenURL(frame, url, referrer, default_policy);
2391 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. 2436 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2392 } 2437 }
2393 } 2438 }
2394 2439
2395 // Detect when we're crossing a permission-based boundary (e.g. into or out of 2440 // Detect when we're crossing a permission-based boundary (e.g. into or out of
(...skipping 2935 matching lines...) Expand 10 before | Expand all | Expand 10 after
5331 &override_state)) 5376 &override_state))
5332 return override_state; 5377 return override_state;
5333 return current_state; 5378 return current_state;
5334 } 5379 }
5335 5380
5336 WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() { 5381 WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
5337 EnsureMediaStreamImpl(); 5382 EnsureMediaStreamImpl();
5338 return media_stream_impl_; 5383 return media_stream_impl_;
5339 } 5384 }
5340 5385
5341 bool RenderViewImpl::IsNonLocalTopLevelNavigation(
5342 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
5343 // Must be a top level frame.
5344 if (frame->parent() != NULL)
5345 return false;
5346
5347 // Navigations initiated within Webkit are not sent out to the external host
5348 // in the following cases.
5349 // 1. The url scheme is not http/https
5350 // 2. The origin of the url and the opener is the same in which case the
5351 // opener relationship is maintained.
5352 // 3. Reloads/form submits/back forward navigations
5353 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
5354 return false;
5355
5356 // Not interested in reloads/form submits/resubmits/back forward navigations.
5357 if (type != WebKit::WebNavigationTypeReload &&
5358 type != WebKit::WebNavigationTypeFormSubmitted &&
5359 type != WebKit::WebNavigationTypeFormResubmitted &&
5360 type != WebKit::WebNavigationTypeBackForward) {
5361 // The opener relationship between the new window and the parent allows the
5362 // new window to script the parent and vice versa. This is not allowed if
5363 // the origins of the two domains are different. This can be treated as a
5364 // top level navigation and routed back to the host.
5365 WebKit::WebFrame* opener = frame->opener();
5366 if (!opener) {
5367 return true;
5368 } else {
5369 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
5370 return true;
5371 }
5372 }
5373 return false;
5374 }
5375
5376 void RenderViewImpl::OnAsyncFileOpened( 5386 void RenderViewImpl::OnAsyncFileOpened(
5377 base::PlatformFileError error_code, 5387 base::PlatformFileError error_code,
5378 IPC::PlatformFileForTransit file_for_transit, 5388 IPC::PlatformFileForTransit file_for_transit,
5379 int message_id) { 5389 int message_id) {
5380 pepper_delegate_.OnAsyncFileOpened( 5390 pepper_delegate_.OnAsyncFileOpened(
5381 error_code, 5391 error_code,
5382 IPC::PlatformFileForTransitToPlatformFile(file_for_transit), 5392 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5383 message_id); 5393 message_id);
5384 } 5394 }
5385 5395
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5425 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { 5435 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
5426 return !!RenderThreadImpl::current()->compositor_thread(); 5436 return !!RenderThreadImpl::current()->compositor_thread();
5427 } 5437 }
5428 5438
5429 void RenderViewImpl::OnJavaBridgeInit() { 5439 void RenderViewImpl::OnJavaBridgeInit() {
5430 DCHECK(!java_bridge_dispatcher_); 5440 DCHECK(!java_bridge_dispatcher_);
5431 #if defined(ENABLE_JAVA_BRIDGE) 5441 #if defined(ENABLE_JAVA_BRIDGE)
5432 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); 5442 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this);
5433 #endif 5443 #endif
5434 } 5444 }
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