OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 #include "core/html/HTMLImageElement.h" | 130 #include "core/html/HTMLImageElement.h" |
131 #include "core/html/HTMLInputElement.h" | 131 #include "core/html/HTMLInputElement.h" |
132 #include "core/html/HTMLLinkElement.h" | 132 #include "core/html/HTMLLinkElement.h" |
133 #include "core/html/PluginDocument.h" | 133 #include "core/html/PluginDocument.h" |
134 #include "core/input/EventHandler.h" | 134 #include "core/input/EventHandler.h" |
135 #include "core/inspector/ConsoleMessage.h" | 135 #include "core/inspector/ConsoleMessage.h" |
136 #include "core/layout/HitTestResult.h" | 136 #include "core/layout/HitTestResult.h" |
137 #include "core/layout/LayoutBox.h" | 137 #include "core/layout/LayoutBox.h" |
138 #include "core/layout/LayoutObject.h" | 138 #include "core/layout/LayoutObject.h" |
139 #include "core/layout/LayoutPart.h" | 139 #include "core/layout/LayoutPart.h" |
140 #include "core/layout/LayoutTreeAsText.h" | |
141 #include "core/layout/LayoutView.h" | 140 #include "core/layout/LayoutView.h" |
142 #include "core/style/StyleInheritedData.h" | 141 #include "core/style/StyleInheritedData.h" |
143 #include "core/loader/DocumentLoader.h" | 142 #include "core/loader/DocumentLoader.h" |
144 #include "core/loader/FrameLoadRequest.h" | 143 #include "core/loader/FrameLoadRequest.h" |
145 #include "core/loader/FrameLoader.h" | 144 #include "core/loader/FrameLoader.h" |
146 #include "core/loader/HistoryItem.h" | 145 #include "core/loader/HistoryItem.h" |
147 #include "core/loader/MixedContentChecker.h" | 146 #include "core/loader/MixedContentChecker.h" |
148 #include "core/loader/NavigationScheduler.h" | 147 #include "core/loader/NavigationScheduler.h" |
149 #include "core/page/FocusController.h" | 148 #include "core/page/FocusController.h" |
150 #include "core/page/FrameTree.h" | 149 #include "core/page/FrameTree.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 #include "web/WebRemoteFrameImpl.h" | 237 #include "web/WebRemoteFrameImpl.h" |
239 #include "web/WebViewImpl.h" | 238 #include "web/WebViewImpl.h" |
240 #include "wtf/CurrentTime.h" | 239 #include "wtf/CurrentTime.h" |
241 #include "wtf/HashMap.h" | 240 #include "wtf/HashMap.h" |
242 #include <algorithm> | 241 #include <algorithm> |
243 | 242 |
244 namespace blink { | 243 namespace blink { |
245 | 244 |
246 static int frameCount = 0; | 245 static int frameCount = 0; |
247 | 246 |
248 static void frameContentAsPlainText(size_t maxChars, LocalFrame* frame, StringBu
ilder& output) | |
249 { | |
250 Document* document = frame->document(); | |
251 if (!document) | |
252 return; | |
253 | |
254 if (!frame->view()) | |
255 return; | |
256 | |
257 // Select the document body. | |
258 if (document->body()) { | |
259 const EphemeralRange range = EphemeralRange::rangeOfContents(*document->
body()); | |
260 | |
261 // The text iterator will walk nodes giving us text. This is similar to | |
262 // the plainText() function in core/editing/TextIterator.h, but we imple
ment the maximum | |
263 // size and also copy the results directly into a wstring, avoiding the | |
264 // string conversion. | |
265 for (TextIterator it(range.startPosition(), range.endPosition()); !it.at
End(); it.advance()) { | |
266 it.text().appendTextToStringBuilder(output, 0, maxChars - output.len
gth()); | |
267 if (output.length() >= maxChars) | |
268 return; // Filled up the buffer. | |
269 } | |
270 } | |
271 | |
272 // The separator between frames when the frames are converted to plain text. | |
273 const LChar frameSeparator[] = { '\n', '\n' }; | |
274 const size_t frameSeparatorLength = WTF_ARRAY_LENGTH(frameSeparator); | |
275 | |
276 // Recursively walk the children. | |
277 const FrameTree& frameTree = frame->tree(); | |
278 for (Frame* curChild = frameTree.firstChild(); curChild; curChild = curChild
->tree().nextSibling()) { | |
279 if (!curChild->isLocalFrame()) | |
280 continue; | |
281 LocalFrame* curLocalChild = toLocalFrame(curChild); | |
282 // Ignore the text of non-visible frames. | |
283 LayoutView* contentLayoutObject = curLocalChild->contentLayoutObject(); | |
284 LayoutPart* ownerLayoutObject = curLocalChild->ownerLayoutObject(); | |
285 if (!contentLayoutObject || !contentLayoutObject->size().width() || !con
tentLayoutObject->size().height() | |
286 || (contentLayoutObject->location().x() + contentLayoutObject->size(
).width() <= 0) || (contentLayoutObject->location().y() + contentLayoutObject->s
ize().height() <= 0) | |
287 || (ownerLayoutObject && ownerLayoutObject->style() && ownerLayoutOb
ject->style()->visibility() != VISIBLE)) { | |
288 continue; | |
289 } | |
290 | |
291 // Make sure the frame separator won't fill up the buffer, and give up i
f | |
292 // it will. The danger is if the separator will make the buffer longer t
han | |
293 // maxChars. This will cause the computation above: | |
294 // maxChars - output->size() | |
295 // to be a negative number which will crash when the subframe is added. | |
296 if (output.length() >= maxChars - frameSeparatorLength) | |
297 return; | |
298 | |
299 output.append(frameSeparator, frameSeparatorLength); | |
300 frameContentAsPlainText(maxChars, curLocalChild, output); | |
301 if (output.length() >= maxChars) | |
302 return; // Filled up the buffer. | |
303 } | |
304 } | |
305 | |
306 static WillBeHeapVector<ScriptSourceCode> createSourcesVector(const WebScriptSou
rce* sourcesIn, unsigned numSources) | 247 static WillBeHeapVector<ScriptSourceCode> createSourcesVector(const WebScriptSou
rce* sourcesIn, unsigned numSources) |
307 { | 248 { |
308 WillBeHeapVector<ScriptSourceCode> sources; | 249 WillBeHeapVector<ScriptSourceCode> sources; |
309 sources.append(sourcesIn, numSources); | 250 sources.append(sourcesIn, numSources); |
310 return sources; | 251 return sources; |
311 } | 252 } |
312 | 253 |
313 WebPluginContainerImpl* WebLocalFrameImpl::pluginContainerFromFrame(LocalFrame*
frame) | 254 WebPluginContainerImpl* WebLocalFrameImpl::pluginContainerFromFrame(LocalFrame*
frame) |
314 { | 255 { |
315 if (!frame) | 256 if (!frame) |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 frame()->document()->pageSizeAndMarginsInPixels(pageIndex, size, marginTop,
marginRight, marginBottom, marginLeft); | 1387 frame()->document()->pageSizeAndMarginsInPixels(pageIndex, size, marginTop,
marginRight, marginBottom, marginLeft); |
1447 pageSize = size; | 1388 pageSize = size; |
1448 } | 1389 } |
1449 | 1390 |
1450 WebString WebLocalFrameImpl::pageProperty(const WebString& propertyName, int pag
eIndex) | 1391 WebString WebLocalFrameImpl::pageProperty(const WebString& propertyName, int pag
eIndex) |
1451 { | 1392 { |
1452 ASSERT(m_printContext); | 1393 ASSERT(m_printContext); |
1453 return m_printContext->pageProperty(frame(), propertyName.utf8().data(), pag
eIndex); | 1394 return m_printContext->pageProperty(frame(), propertyName.utf8().data(), pag
eIndex); |
1454 } | 1395 } |
1455 | 1396 |
1456 WebString WebLocalFrameImpl::contentAsText(size_t maxChars) const | |
1457 { | |
1458 if (!frame()) | |
1459 return WebString(); | |
1460 StringBuilder text; | |
1461 frameContentAsPlainText(maxChars, frame(), text); | |
1462 return text.toString(); | |
1463 } | |
1464 | |
1465 WebString WebLocalFrameImpl::contentAsMarkup() const | |
1466 { | |
1467 if (!frame()) | |
1468 return WebString(); | |
1469 return createMarkup(frame()->document()); | |
1470 } | |
1471 | |
1472 WebString WebLocalFrameImpl::layoutTreeAsText(LayoutAsTextControls toShow) const | |
1473 { | |
1474 LayoutAsTextBehavior behavior = LayoutAsTextShowAllLayers; | |
1475 | |
1476 if (toShow & LayoutAsTextWithLineTrees) | |
1477 behavior |= LayoutAsTextShowLineTrees; | |
1478 | |
1479 if (toShow & LayoutAsTextDebug) | |
1480 behavior |= LayoutAsTextShowCompositedLayers | LayoutAsTextShowAddresses
| LayoutAsTextShowIDAndClass | LayoutAsTextShowLayerNesting; | |
1481 | |
1482 if (toShow & LayoutAsTextPrinting) | |
1483 behavior |= LayoutAsTextPrintingMode; | |
1484 | |
1485 return externalRepresentation(frame(), behavior); | |
1486 } | |
1487 | |
1488 void WebLocalFrameImpl::registerTestInterface(const WebString& name, WebTestInte
rfaceFactory* factory) | 1397 void WebLocalFrameImpl::registerTestInterface(const WebString& name, WebTestInte
rfaceFactory* factory) |
1489 { | 1398 { |
1490 m_testInterfaces.set(name, adoptPtr(factory)); | 1399 m_testInterfaces.set(name, adoptPtr(factory)); |
1491 } | 1400 } |
1492 | 1401 |
1493 v8::Local<v8::Value> WebLocalFrameImpl::createTestInterface(const AtomicString&
name) | 1402 v8::Local<v8::Value> WebLocalFrameImpl::createTestInterface(const AtomicString&
name) |
1494 { | 1403 { |
1495 if (WebTestInterfaceFactory* factory = m_testInterfaces.get(name)) { | 1404 if (WebTestInterfaceFactory* factory = m_testInterfaces.get(name)) { |
1496 ScriptState* scriptState = ScriptState::forMainWorld(frame()); | 1405 ScriptState* scriptState = ScriptState::forMainWorld(frame()); |
1497 ASSERT(scriptState->contextIsValid()); | 1406 ASSERT(scriptState->contextIsValid()); |
1498 v8::EscapableHandleScope handleScope(scriptState->isolate()); | 1407 v8::EscapableHandleScope handleScope(scriptState->isolate()); |
1499 ScriptState::Scope scope(scriptState); | 1408 ScriptState::Scope scope(scriptState); |
1500 return handleScope.Escape(factory->createInstance(scriptState->context()
)); | 1409 return handleScope.Escape(factory->createInstance(scriptState->context()
)); |
1501 } | 1410 } |
1502 return v8::Local<v8::Value>(); | 1411 return v8::Local<v8::Value>(); |
1503 } | 1412 } |
1504 | 1413 |
1505 WebString WebLocalFrameImpl::markerTextForListItem(const WebElement& webElement)
const | |
1506 { | |
1507 return blink::markerTextForListItem(const_cast<Element*>(webElement.constUnw
rap<Element>())); | |
1508 } | |
1509 | |
1510 void WebLocalFrameImpl::printPagesWithBoundaries(WebCanvas* canvas, const WebSiz
e& pageSizeInPixels) | 1414 void WebLocalFrameImpl::printPagesWithBoundaries(WebCanvas* canvas, const WebSiz
e& pageSizeInPixels) |
1511 { | 1415 { |
1512 ASSERT(m_printContext); | 1416 ASSERT(m_printContext); |
1513 | 1417 |
1514 m_printContext->spoolAllPagesWithBoundaries(canvas, FloatSize(pageSizeInPixe
ls.width, pageSizeInPixels.height)); | 1418 m_printContext->spoolAllPagesWithBoundaries(canvas, FloatSize(pageSizeInPixe
ls.width, pageSizeInPixels.height)); |
1515 } | 1419 } |
1516 | 1420 |
1517 WebRect WebLocalFrameImpl::selectionBoundsRect() const | 1421 WebRect WebLocalFrameImpl::selectionBoundsRect() const |
1518 { | 1422 { |
1519 return hasSelection() ? WebRect(IntRect(frame()->selection().bounds())) : We
bRect(); | 1423 return hasSelection() ? WebRect(IntRect(frame()->selection().bounds())) : We
bRect(); |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2257 return WebSandboxFlags::None; | 2161 return WebSandboxFlags::None; |
2258 return static_cast<WebSandboxFlags>(frame()->loader().effectiveSandboxFlags(
)); | 2162 return static_cast<WebSandboxFlags>(frame()->loader().effectiveSandboxFlags(
)); |
2259 } | 2163 } |
2260 | 2164 |
2261 void WebLocalFrameImpl::forceSandboxFlags(WebSandboxFlags flags) | 2165 void WebLocalFrameImpl::forceSandboxFlags(WebSandboxFlags flags) |
2262 { | 2166 { |
2263 frame()->loader().forceSandboxFlags(static_cast<SandboxFlags>(flags)); | 2167 frame()->loader().forceSandboxFlags(static_cast<SandboxFlags>(flags)); |
2264 } | 2168 } |
2265 | 2169 |
2266 } // namespace blink | 2170 } // namespace blink |
OLD | NEW |