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

Side by Side Diff: Source/bindings/core/v8/ScriptController.cpp

Issue 1158973004: If javascript: returns no result, balance load progress notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix component building Created 5 years, 3 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
« no previous file with comments | « no previous file | Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved.
3 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Apple Inc. All rights reserved.
4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. 4 * Copyright (C) 2014 Opera Software ASA. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 bool ScriptController::executeScriptIfJavaScriptURL(const KURL& url) 480 bool ScriptController::executeScriptIfJavaScriptURL(const KURL& url)
481 { 481 {
482 if (!protocolIsJavaScript(url)) 482 if (!protocolIsJavaScript(url))
483 return false; 483 return false;
484 484
485 bool shouldBypassMainWorldContentSecurityPolicy = ContentSecurityPolicy::sho uldBypassMainWorld(frame()->document()); 485 bool shouldBypassMainWorldContentSecurityPolicy = ContentSecurityPolicy::sho uldBypassMainWorld(frame()->document());
486 if (!frame()->page() 486 if (!frame()->page()
487 || (!shouldBypassMainWorldContentSecurityPolicy && !frame()->document()- >contentSecurityPolicy()->allowJavaScriptURLs(frame()->document()->url(), eventH andlerPosition().m_line))) 487 || (!shouldBypassMainWorldContentSecurityPolicy && !frame()->document()- >contentSecurityPolicy()->allowJavaScriptURLs(frame()->document()->url(), eventH andlerPosition().m_line)))
488 return true; 488 return true;
489 489
490 if (frame()->loader().stateMachine()->isDisplayingInitialEmptyDocument()) 490 bool progressNotificationsNeeded = frame()->loader().stateMachine()->isDispl ayingInitialEmptyDocument() && !frame()->isLoading();
491 if (progressNotificationsNeeded)
491 frame()->loader().progress().progressStarted(); 492 frame()->loader().progress().progressStarted();
492 493
493 // We need to hold onto the LocalFrame here because executing script can 494 // We need to hold onto the LocalFrame here because executing script can
494 // destroy the frame. 495 // destroy the frame.
495 RefPtrWillBeRawPtr<LocalFrame> protect(frame()); 496 RefPtrWillBeRawPtr<LocalFrame> protect(frame());
496 RefPtrWillBeRawPtr<Document> ownerDocument(frame()->document()); 497 RefPtrWillBeRawPtr<Document> ownerDocument(frame()->document());
497 498
498 const int javascriptSchemeLength = sizeof("javascript:") - 1; 499 const int javascriptSchemeLength = sizeof("javascript:") - 1;
499 500
500 bool locationChangeBefore = frame()->navigationScheduler().locationChangePen ding(); 501 bool locationChangeBefore = frame()->navigationScheduler().locationChangePen ding();
501 502
502 String decodedURL = decodeURLEscapeSequences(url.string()); 503 String decodedURL = decodeURLEscapeSequences(url.string());
503 v8::HandleScope handleScope(isolate()); 504 v8::HandleScope handleScope(isolate());
504 v8::Local<v8::Value> result = evaluateScriptInMainWorld(ScriptSourceCode(dec odedURL.substring(javascriptSchemeLength)), NotSharableCrossOrigin, DoNotExecute ScriptWhenScriptsDisabled); 505 v8::Local<v8::Value> result = evaluateScriptInMainWorld(ScriptSourceCode(dec odedURL.substring(javascriptSchemeLength)), NotSharableCrossOrigin, DoNotExecute ScriptWhenScriptsDisabled);
505 506
506 // If executing script caused this frame to be removed from the page, we 507 // If executing script caused this frame to be removed from the page, we
507 // don't want to try to replace its document! 508 // don't want to try to replace its document!
508 if (!frame()->page()) 509 if (!frame()->page())
509 return true; 510 return true;
510 511
511 if (result.IsEmpty() || !result->IsString()) 512 if (result.IsEmpty() || !result->IsString()) {
513 if (progressNotificationsNeeded)
514 frame()->loader().progress().progressCompleted();
512 return true; 515 return true;
516 }
513 String scriptResult = toCoreString(v8::Local<v8::String>::Cast(result)); 517 String scriptResult = toCoreString(v8::Local<v8::String>::Cast(result));
514 518
515 // We're still in a frame, so there should be a DocumentLoader. 519 // We're still in a frame, so there should be a DocumentLoader.
516 ASSERT(frame()->document()->loader()); 520 ASSERT(frame()->document()->loader());
517 if (!locationChangeBefore && frame()->navigationScheduler().locationChangePe nding()) 521 if (!locationChangeBefore && frame()->navigationScheduler().locationChangePe nding())
518 return true; 522 return true;
519 523
520 frame()->loader().replaceDocumentWhileExecutingJavaScriptURL(scriptResult, o wnerDocument.get()); 524 frame()->loader().replaceDocumentWhileExecutingJavaScriptURL(scriptResult, o wnerDocument.get());
521 return true; 525 return true;
522 } 526 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 for (size_t i = 0; i < resultArray->Length(); ++i) { 595 for (size_t i = 0; i < resultArray->Length(); ++i) {
592 v8::Local<v8::Value> value; 596 v8::Local<v8::Value> value;
593 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) 597 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value))
594 return; 598 return;
595 results->append(value); 599 results->append(value);
596 } 600 }
597 } 601 }
598 } 602 }
599 603
600 } // namespace blink 604 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698