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

Side by Side Diff: third_party/WebKit/Source/core/testing/Internals.cpp

Issue 2109613007: Robustify Internals entry points against detached uses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | 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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 return treeScope1->comparePosition(*treeScope2); 484 return treeScope1->comparePosition(*treeScope2);
485 } 485 }
486 486
487 void Internals::pauseAnimations(double pauseTime, ExceptionState& exceptionState ) 487 void Internals::pauseAnimations(double pauseTime, ExceptionState& exceptionState )
488 { 488 {
489 if (pauseTime < 0) { 489 if (pauseTime < 0) {
490 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: indexExceedsMinimumBound("pauseTime", pauseTime, 0.0)); 490 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: indexExceedsMinimumBound("pauseTime", pauseTime, 0.0));
491 return; 491 return;
492 } 492 }
493 493
494 if (!frame())
495 return;
496
494 frame()->view()->updateAllLifecyclePhases(); 497 frame()->view()->updateAllLifecyclePhases();
495 frame()->document()->timeline().pauseAnimationsForTesting(pauseTime); 498 frame()->document()->timeline().pauseAnimationsForTesting(pauseTime);
496 } 499 }
497 500
498 bool Internals::isCompositedAnimation(Animation* animation) 501 bool Internals::isCompositedAnimation(Animation* animation)
499 { 502 {
500 return animation->hasActiveAnimationsOnCompositor(); 503 return animation->hasActiveAnimationsOnCompositor();
501 } 504 }
502 505
503 void Internals::disableCompositedAnimation(Animation* animation) 506 void Internals::disableCompositedAnimation(Animation* animation)
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 return document->autofocusElement(); 775 return document->autofocusElement();
773 } 776 }
774 777
775 bool Internals::hasAutofocusRequest() 778 bool Internals::hasAutofocusRequest()
776 { 779 {
777 return hasAutofocusRequest(0); 780 return hasAutofocusRequest(0);
778 } 781 }
779 782
780 Vector<String> Internals::formControlStateOfHistoryItem(ExceptionState& exceptio nState) 783 Vector<String> Internals::formControlStateOfHistoryItem(ExceptionState& exceptio nState)
781 { 784 {
782 HistoryItem* mainItem = frame()->loader().currentItem(); 785 HistoryItem* mainItem = nullptr;
786 if (frame())
787 mainItem = frame()->loader().currentItem();
783 if (!mainItem) { 788 if (!mainItem) {
784 exceptionState.throwDOMException(InvalidAccessError, "No history item is available."); 789 exceptionState.throwDOMException(InvalidAccessError, "No history item is available.");
785 return Vector<String>(); 790 return Vector<String>();
786 } 791 }
787 return mainItem->documentState(); 792 return mainItem->documentState();
788 } 793 }
789 794
790 void Internals::setFormControlStateOfHistoryItem(const Vector<String>& state, Ex ceptionState& exceptionState) 795 void Internals::setFormControlStateOfHistoryItem(const Vector<String>& state, Ex ceptionState& exceptionState)
791 { 796 {
792 HistoryItem* mainItem = frame()->loader().currentItem(); 797 HistoryItem* mainItem = nullptr;
798 if (frame())
799 mainItem = frame()->loader().currentItem();
793 if (!mainItem) { 800 if (!mainItem) {
794 exceptionState.throwDOMException(InvalidAccessError, "No history item is available."); 801 exceptionState.throwDOMException(InvalidAccessError, "No history item is available.");
795 return; 802 return;
796 } 803 }
797 mainItem->clearDocumentState(); 804 mainItem->clearDocumentState();
798 mainItem->setDocumentState(state); 805 mainItem->setDocumentState(state);
799 } 806 }
800 807
801 DOMWindow* Internals::pagePopupWindow() const 808 DOMWindow* Internals::pagePopupWindow() const
802 { 809 {
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
1866 exceptionState.throwDOMException(InvalidAccessError, document ? "The doc ument's page cannot be retrieved." : "No context document can be obtained."); 1873 exceptionState.throwDOMException(InvalidAccessError, document ? "The doc ument's page cannot be retrieved." : "No context document can be obtained.");
1867 return; 1874 return;
1868 } 1875 }
1869 1876
1870 Page* page = document->page(); 1877 Page* page = document->page();
1871 page->frameHost().setDefaultPageScaleLimits(minScaleFactor, maxScaleFactor); 1878 page->frameHost().setDefaultPageScaleLimits(minScaleFactor, maxScaleFactor);
1872 } 1879 }
1873 1880
1874 bool Internals::magnifyScaleAroundAnchor(float scaleFactor, float x, float y) 1881 bool Internals::magnifyScaleAroundAnchor(float scaleFactor, float x, float y)
1875 { 1882 {
1883 if (!frame())
1884 return false;
1885
1876 return frame()->host()->visualViewport().magnifyScaleAroundAnchor(scaleFacto r, FloatPoint(x, y)); 1886 return frame()->host()->visualViewport().magnifyScaleAroundAnchor(scaleFacto r, FloatPoint(x, y));
1877 } 1887 }
1878 1888
1879 void Internals::setIsCursorVisible(Document* document, bool isVisible, Exception State& exceptionState) 1889 void Internals::setIsCursorVisible(Document* document, bool isVisible, Exception State& exceptionState)
1880 { 1890 {
1881 ASSERT(document); 1891 ASSERT(document);
1882 if (!document->page()) { 1892 if (!document->page()) {
1883 exceptionState.throwDOMException(InvalidAccessError, "No context documen t can be obtained."); 1893 exceptionState.throwDOMException(InvalidAccessError, "No context documen t can be obtained.");
1884 return; 1894 return;
1885 } 1895 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1942 SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(sc heme); 1952 SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(sc heme);
1943 } 1953 }
1944 1954
1945 TypeConversions* Internals::typeConversions() const 1955 TypeConversions* Internals::typeConversions() const
1946 { 1956 {
1947 return TypeConversions::create(); 1957 return TypeConversions::create();
1948 } 1958 }
1949 1959
1950 PrivateScriptTest* Internals::privateScriptTest() const 1960 PrivateScriptTest* Internals::privateScriptTest() const
1951 { 1961 {
1962 if (!frame())
1963 return nullptr;
1964
1952 return PrivateScriptTest::create(frame()->document()); 1965 return PrivateScriptTest::create(frame()->document());
1953 } 1966 }
1954 1967
1955 DictionaryTest* Internals::dictionaryTest() const 1968 DictionaryTest* Internals::dictionaryTest() const
1956 { 1969 {
1957 return DictionaryTest::create(); 1970 return DictionaryTest::create();
1958 } 1971 }
1959 1972
1960 UnionTypesTest* Internals::unionTypesTest() const 1973 UnionTypesTest* Internals::unionTypesTest() const
1961 { 1974 {
1962 return UnionTypesTest::create(); 1975 return UnionTypesTest::create();
1963 } 1976 }
1964 1977
1965 Vector<String> Internals::getReferencedFilePaths() const 1978 Vector<String> Internals::getReferencedFilePaths() const
1966 { 1979 {
1980 if (!frame())
1981 return Vector<String>();
1982
1967 return frame()->loader().currentItem()->getReferencedFilePaths(); 1983 return frame()->loader().currentItem()->getReferencedFilePaths();
1968 } 1984 }
1969 1985
1970 void Internals::startTrackingRepaints(Document* document, ExceptionState& except ionState) 1986 void Internals::startTrackingRepaints(Document* document, ExceptionState& except ionState)
1971 { 1987 {
1972 ASSERT(document); 1988 ASSERT(document);
1973 if (!document->view()) { 1989 if (!document->view()) {
1974 exceptionState.throwDOMException(InvalidAccessError, "The document provi ded is invalid."); 1990 exceptionState.throwDOMException(InvalidAccessError, "The document provi ded is invalid.");
1975 return; 1991 return;
1976 } 1992 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2100 case Cursor::Grabbing: return "Grabbing"; 2116 case Cursor::Grabbing: return "Grabbing";
2101 case Cursor::Custom: return "Custom"; 2117 case Cursor::Custom: return "Custom";
2102 } 2118 }
2103 2119
2104 ASSERT_NOT_REACHED(); 2120 ASSERT_NOT_REACHED();
2105 return "UNKNOWN"; 2121 return "UNKNOWN";
2106 } 2122 }
2107 2123
2108 String Internals::getCurrentCursorInfo() 2124 String Internals::getCurrentCursorInfo()
2109 { 2125 {
2126 if (!frame())
2127 return String();
2128
2110 Cursor cursor = frame()->page()->chromeClient().lastSetCursorForTesting(); 2129 Cursor cursor = frame()->page()->chromeClient().lastSetCursorForTesting();
2111 2130
2112 StringBuilder result; 2131 StringBuilder result;
2113 result.append("type="); 2132 result.append("type=");
2114 result.append(cursorTypeToString(cursor.getType())); 2133 result.append(cursorTypeToString(cursor.getType()));
2115 result.append(" hotSpot="); 2134 result.append(" hotSpot=");
2116 result.appendNumber(cursor.hotSpot().x()); 2135 result.appendNumber(cursor.hotSpot().x());
2117 result.append(','); 2136 result.append(',');
2118 result.appendNumber(cursor.hotSpot().y()); 2137 result.appendNumber(cursor.hotSpot().y());
2119 if (cursor.getImage()) { 2138 if (cursor.getImage()) {
2120 IntSize size = cursor.getImage()->size(); 2139 IntSize size = cursor.getImage()->size();
2121 result.append(" image="); 2140 result.append(" image=");
2122 result.appendNumber(size.width()); 2141 result.appendNumber(size.width());
2123 result.append('x'); 2142 result.append('x');
2124 result.appendNumber(size.height()); 2143 result.appendNumber(size.height());
2125 } 2144 }
2126 if (cursor.imageScaleFactor() != 1) { 2145 if (cursor.imageScaleFactor() != 1) {
2127 result.append(" scale="); 2146 result.append(" scale=");
2128 NumberToStringBuffer buffer; 2147 NumberToStringBuffer buffer;
2129 result.append(numberToFixedPrecisionString(cursor.imageScaleFactor(), 8, buffer, true)); 2148 result.append(numberToFixedPrecisionString(cursor.imageScaleFactor(), 8, buffer, true));
2130 } 2149 }
2131 2150
2132 return result.toString(); 2151 return result.toString();
2133 } 2152 }
2134 2153
2135 bool Internals::cursorUpdatePending() const 2154 bool Internals::cursorUpdatePending() const
2136 { 2155 {
2156 if (!frame())
2157 return false;
2158
2137 return frame()->eventHandler().cursorUpdatePending(); 2159 return frame()->eventHandler().cursorUpdatePending();
2138 } 2160 }
2139 2161
2140 DOMArrayBuffer* Internals::serializeObject(PassRefPtr<SerializedScriptValue> val ue) const 2162 DOMArrayBuffer* Internals::serializeObject(PassRefPtr<SerializedScriptValue> val ue) const
2141 { 2163 {
2142 String stringValue = value->toWireString(); 2164 String stringValue = value->toWireString();
2143 DOMArrayBuffer* buffer = DOMArrayBuffer::createUninitialized(stringValue.len gth(), sizeof(UChar)); 2165 DOMArrayBuffer* buffer = DOMArrayBuffer::createUninitialized(stringValue.len gth(), sizeof(UChar));
2144 stringValue.copyTo(static_cast<UChar*>(buffer->data()), 0, stringValue.lengt h()); 2166 stringValue.copyTo(static_cast<UChar*>(buffer->data()), 0, stringValue.lengt h());
2145 return buffer; 2167 return buffer;
2146 } 2168 }
2147 2169
2148 PassRefPtr<SerializedScriptValue> Internals::deserializeBuffer(DOMArrayBuffer* b uffer) const 2170 PassRefPtr<SerializedScriptValue> Internals::deserializeBuffer(DOMArrayBuffer* b uffer) const
2149 { 2171 {
2150 String value(static_cast<const UChar*>(buffer->data()), buffer->byteLength() / sizeof(UChar)); 2172 String value(static_cast<const UChar*>(buffer->data()), buffer->byteLength() / sizeof(UChar));
2151 return SerializedScriptValue::create(value); 2173 return SerializedScriptValue::create(value);
2152 } 2174 }
2153 2175
2154 void Internals::forceReload(bool bypassCache) 2176 void Internals::forceReload(bool bypassCache)
2155 { 2177 {
2178 if (!frame())
2179 return;
2180
2156 frame()->reload(bypassCache ? FrameLoadTypeReloadBypassingCache : FrameLoadT ypeReload, ClientRedirectPolicy::NotClientRedirect); 2181 frame()->reload(bypassCache ? FrameLoadTypeReloadBypassingCache : FrameLoadT ypeReload, ClientRedirectPolicy::NotClientRedirect);
2157 } 2182 }
2158 2183
2159 ClientRect* Internals::selectionBounds(ExceptionState& exceptionState) 2184 ClientRect* Internals::selectionBounds(ExceptionState& exceptionState)
2160 { 2185 {
2161 Document* document = contextDocument(); 2186 Document* document = contextDocument();
2162 if (!document || !document->frame()) { 2187 if (!document || !document->frame()) {
2163 exceptionState.throwDOMException(InvalidAccessError, document ? "The doc ument's frame cannot be retrieved." : "No context document can be obtained."); 2188 exceptionState.throwDOMException(InvalidAccessError, document ? "The doc ument's frame cannot be retrieved." : "No context document can be obtained.");
2164 return nullptr; 2189 return nullptr;
2165 } 2190 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 if (document->layoutViewItem().isNull()) { 2273 if (document->layoutViewItem().isNull()) {
2249 exceptionState.throwDOMException(InvalidAccessError, "The document provi ded is invalid."); 2274 exceptionState.throwDOMException(InvalidAccessError, "The document provi ded is invalid.");
2250 return; 2275 return;
2251 } 2276 }
2252 2277
2253 document->frame()->view()->updateAllLifecyclePhases(); 2278 document->frame()->view()->updateAllLifecyclePhases();
2254 } 2279 }
2255 2280
2256 void Internals::setZoomFactor(float factor) 2281 void Internals::setZoomFactor(float factor)
2257 { 2282 {
2283 if (!frame())
2284 return;
2285
2258 frame()->setPageZoomFactor(factor); 2286 frame()->setPageZoomFactor(factor);
2259 } 2287 }
2260 2288
2261 void Internals::setShouldRevealPassword(Element* element, bool reveal, Exception State& exceptionState) 2289 void Internals::setShouldRevealPassword(Element* element, bool reveal, Exception State& exceptionState)
2262 { 2290 {
2263 ASSERT(element); 2291 ASSERT(element);
2264 if (!isHTMLInputElement(element)) { 2292 if (!isHTMLInputElement(element)) {
2265 exceptionState.throwDOMException(InvalidNodeTypeError, "The element prov ided is not an INPUT."); 2293 exceptionState.throwDOMException(InvalidNodeTypeError, "The element prov ided is not an INPUT.");
2266 return; 2294 return;
2267 } 2295 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 { 2393 {
2366 if (!node || !node->layoutObject()) 2394 if (!node || !node->layoutObject())
2367 return String(); 2395 return String();
2368 blink::WebPoint point(x, y); 2396 blink::WebPoint point(x, y);
2369 SurroundingText surroundingText(createVisiblePosition(node->layoutObject()-> positionForPoint(static_cast<IntPoint>(point))).deepEquivalent().parentAnchoredE quivalent(), maxLength); 2397 SurroundingText surroundingText(createVisiblePosition(node->layoutObject()-> positionForPoint(static_cast<IntPoint>(point))).deepEquivalent().parentAnchoredE quivalent(), maxLength);
2370 return surroundingText.content(); 2398 return surroundingText.content();
2371 } 2399 }
2372 2400
2373 void Internals::setFocused(bool focused) 2401 void Internals::setFocused(bool focused)
2374 { 2402 {
2403 if (!frame())
2404 return;
2405
2375 frame()->page()->focusController().setFocused(focused); 2406 frame()->page()->focusController().setFocused(focused);
2376 } 2407 }
2377 2408
2378 void Internals::setInitialFocus(bool reverse) 2409 void Internals::setInitialFocus(bool reverse)
2379 { 2410 {
2411 if (!frame())
2412 return;
2413
2380 frame()->document()->clearFocusedElement(); 2414 frame()->document()->clearFocusedElement();
2381 frame()->page()->focusController().setInitialFocus(reverse ? WebFocusTypeBac kward : WebFocusTypeForward); 2415 frame()->page()->focusController().setInitialFocus(reverse ? WebFocusTypeBac kward : WebFocusTypeForward);
2382 } 2416 }
2383 2417
2384 bool Internals::ignoreLayoutWithPendingStylesheets(Document* document) 2418 bool Internals::ignoreLayoutWithPendingStylesheets(Document* document)
2385 { 2419 {
2386 ASSERT(document); 2420 ASSERT(document);
2387 return document->ignoreLayoutWithPendingStylesheets(); 2421 return document->ignoreLayoutWithPendingStylesheets();
2388 } 2422 }
2389 2423
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2446 scrollState->setScrollChain(scrollChain); 2480 scrollState->setScrollChain(scrollChain);
2447 } 2481 }
2448 2482
2449 void Internals::forceBlinkGCWithoutV8GC() 2483 void Internals::forceBlinkGCWithoutV8GC()
2450 { 2484 {
2451 ThreadState::current()->setGCState(ThreadState::FullGCScheduled); 2485 ThreadState::current()->setGCState(ThreadState::FullGCScheduled);
2452 } 2486 }
2453 2487
2454 String Internals::selectedHTMLForClipboard() 2488 String Internals::selectedHTMLForClipboard()
2455 { 2489 {
2490 if (!frame())
2491 return String();
2492
2456 return frame()->selection().selectedHTMLForClipboard(); 2493 return frame()->selection().selectedHTMLForClipboard();
2457 } 2494 }
2458 2495
2459 String Internals::selectedTextForClipboard() 2496 String Internals::selectedTextForClipboard()
2460 { 2497 {
2498 if (!frame())
2499 return String();
2500
2461 return frame()->selection().selectedTextForClipboard(); 2501 return frame()->selection().selectedTextForClipboard();
2462 } 2502 }
2463 2503
2464 void Internals::setVisualViewportOffset(int x, int y) 2504 void Internals::setVisualViewportOffset(int x, int y)
2465 { 2505 {
2506 if (!frame())
2507 return;
2508
2466 frame()->host()->visualViewport().setLocation(FloatPoint(x, y)); 2509 frame()->host()->visualViewport().setLocation(FloatPoint(x, y));
2467 } 2510 }
2468 2511
2469 int Internals::visualViewportHeight() 2512 int Internals::visualViewportHeight()
2470 { 2513 {
2514 if (!frame())
2515 return 0;
2516
2471 return expandedIntSize(frame()->host()->visualViewport().visibleRect().size( )).height(); 2517 return expandedIntSize(frame()->host()->visualViewport().visibleRect().size( )).height();
2472 } 2518 }
2473 2519
2474 int Internals::visualViewportWidth() 2520 int Internals::visualViewportWidth()
2475 { 2521 {
2522 if (!frame())
2523 return 0;
2524
2476 return expandedIntSize(frame()->host()->visualViewport().visibleRect().size( )).width(); 2525 return expandedIntSize(frame()->host()->visualViewport().visibleRect().size( )).width();
2477 } 2526 }
2478 2527
2479 double Internals::visualViewportScrollX() 2528 double Internals::visualViewportScrollX()
2480 { 2529 {
2530 if (!frame())
2531 return 0;
2532
2481 return frame()->view()->getScrollableArea()->scrollPositionDouble().x(); 2533 return frame()->view()->getScrollableArea()->scrollPositionDouble().x();
2482 } 2534 }
2483 2535
2484 double Internals::visualViewportScrollY() 2536 double Internals::visualViewportScrollY()
2485 { 2537 {
2538 if (!frame())
2539 return 0;
2540
2486 return frame()->view()->getScrollableArea()->scrollPositionDouble().y(); 2541 return frame()->view()->getScrollableArea()->scrollPositionDouble().y();
2487 } 2542 }
2488 2543
2489 ValueIterable<int>::IterationSource* Internals::startIteration(ScriptState*, Exc eptionState&) 2544 ValueIterable<int>::IterationSource* Internals::startIteration(ScriptState*, Exc eptionState&)
2490 { 2545 {
2491 return new InternalsIterationSource(); 2546 return new InternalsIterationSource();
2492 } 2547 }
2493 2548
2494 bool Internals::isUseCounted(Document* document, int useCounterId) 2549 bool Internals::isUseCounted(Document* document, int useCounterId)
2495 { 2550 {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2575 } 2630 }
2576 2631
2577 String Internals::getProgrammaticScrollAnimationState(Node* node) const 2632 String Internals::getProgrammaticScrollAnimationState(Node* node) const
2578 { 2633 {
2579 if (ScrollableArea* scrollableArea = scrollableAreaForNode(node)) 2634 if (ScrollableArea* scrollableArea = scrollableAreaForNode(node))
2580 return scrollableArea->programmaticScrollAnimator().runStateAsText(); 2635 return scrollableArea->programmaticScrollAnimator().runStateAsText();
2581 return String(); 2636 return String();
2582 } 2637 }
2583 2638
2584 } // namespace blink 2639 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698