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/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 Loading... | |
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(WebKit::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 WebKit::WebFrame* frame, | |
darin (slow to review)
2012/05/21 22:09:54
nit: should not need the WebKit:: prefixes due to
Mihai Parparita -not on Chrome
2012/05/21 22:13:01
Done.
| |
400 WebKit::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)) | |
abarth-chromium
2012/05/21 20:44:19
What about FTP? Whenever you find yourself listin
| |
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 } else { | |
darin (slow to review)
2012/05/21 22:09:54
nit: no need for "else" after "return"
Mihai Parparita -not on Chrome
2012/05/21 22:13:01
Done.
| |
426 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) | |
abarth-chromium
2012/05/21 20:44:19
This isn't the right way to do an origin compariso
| |
427 return true; | |
428 } | |
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 Loading... | |
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 2921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5317 &override_state)) | 5362 &override_state)) |
5318 return override_state; | 5363 return override_state; |
5319 return current_state; | 5364 return current_state; |
5320 } | 5365 } |
5321 | 5366 |
5322 WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() { | 5367 WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() { |
5323 EnsureMediaStreamImpl(); | 5368 EnsureMediaStreamImpl(); |
5324 return media_stream_impl_; | 5369 return media_stream_impl_; |
5325 } | 5370 } |
5326 | 5371 |
5327 bool RenderViewImpl::IsNonLocalTopLevelNavigation( | |
5328 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) { | |
5329 // Must be a top level frame. | |
5330 if (frame->parent() != NULL) | |
5331 return false; | |
5332 | |
5333 // Navigations initiated within Webkit are not sent out to the external host | |
5334 // in the following cases. | |
5335 // 1. The url scheme is not http/https | |
5336 // 2. The origin of the url and the opener is the same in which case the | |
5337 // opener relationship is maintained. | |
5338 // 3. Reloads/form submits/back forward navigations | |
5339 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme)) | |
5340 return false; | |
5341 | |
5342 // Not interested in reloads/form submits/resubmits/back forward navigations. | |
5343 if (type != WebKit::WebNavigationTypeReload && | |
5344 type != WebKit::WebNavigationTypeFormSubmitted && | |
5345 type != WebKit::WebNavigationTypeFormResubmitted && | |
5346 type != WebKit::WebNavigationTypeBackForward) { | |
5347 // The opener relationship between the new window and the parent allows the | |
5348 // new window to script the parent and vice versa. This is not allowed if | |
5349 // the origins of the two domains are different. This can be treated as a | |
5350 // top level navigation and routed back to the host. | |
5351 WebKit::WebFrame* opener = frame->opener(); | |
5352 if (!opener) { | |
5353 return true; | |
5354 } else { | |
5355 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) | |
5356 return true; | |
5357 } | |
5358 } | |
5359 return false; | |
5360 } | |
5361 | |
5362 void RenderViewImpl::OnAsyncFileOpened( | 5372 void RenderViewImpl::OnAsyncFileOpened( |
5363 base::PlatformFileError error_code, | 5373 base::PlatformFileError error_code, |
5364 IPC::PlatformFileForTransit file_for_transit, | 5374 IPC::PlatformFileForTransit file_for_transit, |
5365 int message_id) { | 5375 int message_id) { |
5366 pepper_delegate_.OnAsyncFileOpened( | 5376 pepper_delegate_.OnAsyncFileOpened( |
5367 error_code, | 5377 error_code, |
5368 IPC::PlatformFileForTransitToPlatformFile(file_for_transit), | 5378 IPC::PlatformFileForTransitToPlatformFile(file_for_transit), |
5369 message_id); | 5379 message_id); |
5370 } | 5380 } |
5371 | 5381 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5411 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { | 5421 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
5412 return !!RenderThreadImpl::current()->compositor_thread(); | 5422 return !!RenderThreadImpl::current()->compositor_thread(); |
5413 } | 5423 } |
5414 | 5424 |
5415 void RenderViewImpl::OnJavaBridgeInit() { | 5425 void RenderViewImpl::OnJavaBridgeInit() { |
5416 DCHECK(!java_bridge_dispatcher_); | 5426 DCHECK(!java_bridge_dispatcher_); |
5417 #if defined(ENABLE_JAVA_BRIDGE) | 5427 #if defined(ENABLE_JAVA_BRIDGE) |
5418 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); | 5428 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); |
5419 #endif | 5429 #endif |
5420 } | 5430 } |
OLD | NEW |