This source file includes following definitions.
- frameContentAsPlainText
- pluginContainerFromFrame
- pluginContainerFromNode
- m_printedPageWidth
- begin
- end
- getPageShrink
- spoolPage
- spoolAllPagesWithBoundaries
- computePageRects
- pageCount
- m_printParams
- begin
- end
- getPageShrink
- computePageRects
- pageCount
- spoolPage
- DataSourceForDocLoader
- instanceCount
- frameForCurrentContext
- frameForContext
- fromFrameOwnerElement
- close
- uniqueName
- assignedName
- setName
- iconURLs
- setIsRemote
- setRemoteWebLayer
- setPermissionClient
- setSharedWorkerRepositoryClient
- scrollOffset
- minimumScrollOffset
- maximumScrollOffset
- setScrollOffset
- contentsSize
- hasVisibleContent
- visibleContentRect
- hasHorizontalScrollbar
- hasVerticalScrollbar
- view
- opener
- setOpener
- appendChild
- removeChild
- parent
- top
- previousSibling
- nextSibling
- firstChild
- lastChild
- traversePrevious
- traverseNext
- findChildByName
- document
- performance
- dispatchBeforeUnloadEvent
- dispatchUnloadEvent
- windowObject
- bindToWindowObject
- bindToWindowObject
- executeScript
- executeScriptInIsolatedWorld
- setIsolatedWorldSecurityOrigin
- setIsolatedWorldContentSecurityPolicy
- addMessageToConsole
- collectGarbage
- checkIfRunInsecureContent
- executeScriptAndReturnValue
- executeScriptInIsolatedWorld
- callFunctionEvenIfScriptDisabled
- mainWorldScriptContext
- reload
- reloadWithOverrideURL
- loadRequest
- loadHistoryItem
- loadData
- loadHTMLString
- isLoading
- stopLoading
- provisionalDataSource
- dataSource
- previousHistoryItem
- currentHistoryItem
- enableViewSourceMode
- isViewSourceModeEnabled
- setReferrerForRequest
- dispatchWillSendRequest
- createAssociatedURLLoader
- unloadListenerCount
- replaceSelection
- insertText
- setMarkedText
- unmarkText
- hasMarkedText
- markedRange
- firstRectForCharacterRange
- characterIndexForPoint
- executeCommand
- executeCommand
- isCommandEnabled
- enableContinuousSpellChecking
- isContinuousSpellCheckingEnabled
- requestTextChecking
- replaceMisspelledRange
- removeSpellingMarkers
- hasSelection
- selectionRange
- selectionAsText
- selectionAsMarkup
- selectWordAroundPosition
- selectWordAroundCaret
- selectRange
- selectRange
- moveRangeSelection
- moveCaretSelection
- setEditableSelectionOffsets
- setCompositionFromExistingText
- extendSelectionAndDelete
- setCaretVisible
- visiblePositionForWindowPoint
- focusedPluginIfInputMethodSupported
- printBegin
- getPrintPageShrink
- printPage
- printEnd
- isPrintScalingDisabledForPlugin
- hasCustomPageSizeStyle
- isPageBoxVisible
- pageSizeAndMarginsInPixels
- pageProperty
- find
- stopFinding
- scopeStringMatches
- cancelPendingScopingEffort
- increaseMatchCount
- resetMatchCount
- sendOrientationChangeEvent
- dispatchMessageEventWithOriginCheck
- findMatchMarkersVersion
- selectNearestFindMatch
- activeFindMatchRect
- findMatchRects
- setTickmarks
- contentAsText
- contentAsMarkup
- renderTreeAsText
- markerTextForListItem
- printPagesWithBoundaries
- selectionBoundsRect
- selectionStartHasSpellingMarkerFor
- layerTreeAsText
- create
- create
- m_inputEventsScaleFactorForEmulation
- setWebCoreFrame
- initializeAsMainFrame
- createChildFrame
- didChangeContentsSize
- createFrameView
- fromFrame
- fromFrameOwnerElement
- viewImpl
- dataSourceImpl
- provisionalDataSourceImpl
- setFindEndstateFocusAndSelection
- didFail
- setCanHaveScrollbars
- setInputEventsTransformForEmulation
- loadJavaScriptURL
- willDetachParent
- activeMatchFrame
- activeMatch
- ensureTextFinder
- invalidateScrollbar
- invalidateAll
#include "config.h"
#include "WebFrameImpl.h"
#include <algorithm>
#include "AssociatedURLLoader.h"
#include "CompositionUnderlineVectorBuilder.h"
#include "EventListenerWrapper.h"
#include "FindInPageCoordinates.h"
#include "HTMLNames.h"
#include "PageOverlay.h"
#include "SharedWorkerRepositoryClientImpl.h"
#include "TextFinder.h"
#include "WebConsoleMessage.h"
#include "WebDOMEvent.h"
#include "WebDOMEventListener.h"
#include "WebDataSourceImpl.h"
#include "WebDevToolsAgentPrivate.h"
#include "WebDocument.h"
#include "WebFindOptions.h"
#include "WebFormElement.h"
#include "WebFrameClient.h"
#include "WebHistoryItem.h"
#include "WebIconURL.h"
#include "WebInputElement.h"
#include "WebNode.h"
#include "WebPerformance.h"
#include "WebPlugin.h"
#include "WebPluginContainerImpl.h"
#include "WebPrintParams.h"
#include "WebRange.h"
#include "WebScriptSource.h"
#include "WebSecurityOrigin.h"
#include "WebSerializedScriptValue.h"
#include "WebViewImpl.h"
#include "bindings/v8/DOMWrapperWorld.h"
#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "bindings/v8/ScriptController.h"
#include "bindings/v8/ScriptSourceCode.h"
#include "bindings/v8/ScriptValue.h"
#include "bindings/v8/V8GCController.h"
#include "bindings/v8/V8PerIsolateData.h"
#include "core/dom/Document.h"
#include "core/dom/DocumentMarker.h"
#include "core/dom/DocumentMarkerController.h"
#include "core/dom/IconURL.h"
#include "core/dom/MessagePort.h"
#include "core/dom/Node.h"
#include "core/dom/NodeTraversal.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/editing/Editor.h"
#include "core/editing/FrameSelection.h"
#include "core/editing/InputMethodController.h"
#include "core/editing/PlainTextRange.h"
#include "core/editing/SpellChecker.h"
#include "core/editing/TextAffinity.h"
#include "core/editing/TextIterator.h"
#include "core/editing/htmlediting.h"
#include "core/editing/markup.h"
#include "core/frame/Console.h"
#include "core/frame/DOMWindow.h"
#include "core/frame/FrameView.h"
#include "core/html/HTMLCollection.h"
#include "core/html/HTMLFormElement.h"
#include "core/html/HTMLFrameElementBase.h"
#include "core/html/HTMLFrameOwnerElement.h"
#include "core/html/HTMLHeadElement.h"
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLLinkElement.h"
#include "core/html/PluginDocument.h"
#include "core/inspector/InspectorController.h"
#include "core/inspector/ScriptCallStack.h"
#include "core/loader/DocumentLoader.h"
#include "core/loader/FrameLoadRequest.h"
#include "core/loader/FrameLoader.h"
#include "core/loader/HistoryItem.h"
#include "core/loader/SubstituteData.h"
#include "core/page/Chrome.h"
#include "core/page/EventHandler.h"
#include "core/page/FocusController.h"
#include "core/page/FrameTree.h"
#include "core/page/Page.h"
#include "core/page/PrintContext.h"
#include "core/frame/Settings.h"
#include "core/rendering/HitTestResult.h"
#include "core/rendering/RenderBox.h"
#include "core/rendering/RenderFrame.h"
#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderObject.h"
#include "core/rendering/RenderTreeAsText.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/style/StyleInheritedData.h"
#include "core/timing/Performance.h"
#include "platform/TraceEvent.h"
#include "platform/UserGestureIndicator.h"
#include "platform/clipboard/ClipboardUtilities.h"
#include "platform/fonts/FontCache.h"
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/GraphicsLayerClient.h"
#include "platform/graphics/skia/SkiaUtils.h"
#include "platform/heap/Handle.h"
#include "platform/network/ResourceRequest.h"
#include "platform/scroll/ScrollbarTheme.h"
#include "platform/scroll/ScrollTypes.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/SchemeRegistry.h"
#include "platform/weborigin/SecurityPolicy.h"
#include "public/platform/Platform.h"
#include "public/platform/WebFloatPoint.h"
#include "public/platform/WebFloatRect.h"
#include "public/platform/WebLayer.h"
#include "public/platform/WebPoint.h"
#include "public/platform/WebRect.h"
#include "public/platform/WebSize.h"
#include "public/platform/WebURLError.h"
#include "public/platform/WebVector.h"
#include "wtf/CurrentTime.h"
#include "wtf/HashMap.h"
using namespace WebCore;
namespace blink {
static int frameCount = 0;
static const char webFrameActiveCount[] = "WebFrameActiveCount";
static void frameContentAsPlainText(size_t maxChars, LocalFrame* frame, StringBuilder& output)
{
Document* document = frame->document();
if (!document)
return;
if (!frame->view())
return;
document->updateLayout();
RefPtrWillBeRawPtr<Range> range(document->createRange());
TrackExceptionState exceptionState;
range->selectNodeContents(document->body(), exceptionState);
if (!exceptionState.hadException()) {
for (TextIterator it(range.get()); !it.atEnd(); it.advance()) {
it.appendTextToStringBuilder(output, 0, maxChars - output.length());
if (output.length() >= maxChars)
return;
}
}
const LChar frameSeparator[] = { '\n', '\n' };
const size_t frameSeparatorLength = WTF_ARRAY_LENGTH(frameSeparator);
const FrameTree& frameTree = frame->tree();
for (LocalFrame* curChild = frameTree.firstChild(); curChild; curChild = curChild->tree().nextSibling()) {
RenderView* contentRenderer = curChild->contentRenderer();
RenderPart* ownerRenderer = curChild->ownerRenderer();
if (!contentRenderer || !contentRenderer->width() || !contentRenderer->height()
|| (contentRenderer->x() + contentRenderer->width() <= 0) || (contentRenderer->y() + contentRenderer->height() <= 0)
|| (ownerRenderer && ownerRenderer->style() && ownerRenderer->style()->visibility() != VISIBLE)) {
continue;
}
if (output.length() >= maxChars - frameSeparatorLength)
return;
output.append(frameSeparator, frameSeparatorLength);
frameContentAsPlainText(maxChars, curChild, output);
if (output.length() >= maxChars)
return;
}
}
WebPluginContainerImpl* WebFrameImpl::pluginContainerFromFrame(LocalFrame* frame)
{
if (!frame)
return 0;
if (!frame->document() || !frame->document()->isPluginDocument())
return 0;
PluginDocument* pluginDocument = toPluginDocument(frame->document());
return toWebPluginContainerImpl(pluginDocument->pluginWidget());
}
WebPluginContainerImpl* WebFrameImpl::pluginContainerFromNode(WebCore::LocalFrame* frame, const WebNode& node)
{
WebPluginContainerImpl* pluginContainer = pluginContainerFromFrame(frame);
if (pluginContainer)
return pluginContainer;
return toWebPluginContainerImpl(node.pluginContainer());
}
class ChromePrintContext : public PrintContext {
WTF_MAKE_NONCOPYABLE(ChromePrintContext);
public:
ChromePrintContext(LocalFrame* frame)
: PrintContext(frame)
, m_printedPageWidth(0)
{
}
virtual ~ChromePrintContext() { }
virtual void begin(float width, float height)
{
ASSERT(!m_printedPageWidth);
m_printedPageWidth = width;
PrintContext::begin(m_printedPageWidth, height);
}
virtual void end()
{
PrintContext::end();
}
virtual float getPageShrink(int pageNumber) const
{
IntRect pageRect = m_pageRects[pageNumber];
return m_printedPageWidth / pageRect.width();
}
virtual float spoolPage(GraphicsContext& context, int pageNumber)
{
IntRect pageRect = m_pageRects[pageNumber];
float scale = m_printedPageWidth / pageRect.width();
context.save();
#if OS(POSIX) && !OS(MACOSX)
context.scale(WebCore::FloatSize(scale, scale));
#endif
context.translate(static_cast<float>(-pageRect.x()), static_cast<float>(-pageRect.y()));
context.clip(pageRect);
frame()->view()->paintContents(&context, pageRect);
if (context.supportsURLFragments())
outputLinkedDestinations(context, frame()->document(), pageRect);
context.restore();
return scale;
}
void spoolAllPagesWithBoundaries(GraphicsContext& graphicsContext, const FloatSize& pageSizeInPixels)
{
if (!frame()->document() || !frame()->view() || !frame()->document()->renderer())
return;
frame()->document()->updateLayout();
float pageHeight;
computePageRects(FloatRect(FloatPoint(0, 0), pageSizeInPixels), 0, 0, 1, pageHeight);
const float pageWidth = pageSizeInPixels.width();
size_t numPages = pageRects().size();
int totalHeight = numPages * (pageSizeInPixels.height() + 1) - 1;
graphicsContext.setFillColor(Color::white);
graphicsContext.fillRect(FloatRect(0, 0, pageWidth, totalHeight));
int currentHeight = 0;
for (size_t pageIndex = 0; pageIndex < numPages; pageIndex++) {
if (pageIndex > 0) {
graphicsContext.save();
graphicsContext.setStrokeColor(Color(0, 0, 255));
graphicsContext.setFillColor(Color(0, 0, 255));
graphicsContext.drawLine(IntPoint(0, currentHeight), IntPoint(pageWidth, currentHeight));
graphicsContext.restore();
}
graphicsContext.save();
graphicsContext.translate(0, currentHeight);
#if OS(WIN) || OS(MACOSX)
float scale = getPageShrink(pageIndex);
graphicsContext.scale(WebCore::FloatSize(scale, scale));
#endif
spoolPage(graphicsContext, pageIndex);
graphicsContext.restore();
currentHeight += pageSizeInPixels.height() + 1;
}
}
virtual void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight)
{
PrintContext::computePageRects(printRect, headerHeight, footerHeight, userScaleFactor, outPageHeight);
}
virtual int pageCount() const
{
return PrintContext::pageCount();
}
private:
float m_printedPageWidth;
};
class ChromePluginPrintContext : public ChromePrintContext {
public:
ChromePluginPrintContext(LocalFrame* frame, WebPluginContainerImpl* plugin, const WebPrintParams& printParams)
: ChromePrintContext(frame), m_plugin(plugin), m_pageCount(0), m_printParams(printParams)
{
}
virtual ~ChromePluginPrintContext() { }
virtual void begin(float width, float height)
{
}
virtual void end()
{
m_plugin->printEnd();
}
virtual float getPageShrink(int pageNumber) const
{
return 1.0;
}
virtual void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight)
{
m_printParams.printContentArea = IntRect(printRect);
m_pageCount = m_plugin->printBegin(m_printParams);
}
virtual int pageCount() const
{
return m_pageCount;
}
virtual float spoolPage(GraphicsContext& context, int pageNumber)
{
m_plugin->printPage(pageNumber, &context);
return 1.0;
}
private:
WebPluginContainerImpl* m_plugin;
int m_pageCount;
WebPrintParams m_printParams;
};
static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader)
{
return loader ? WebDataSourceImpl::fromDocumentLoader(loader) : 0;
}
int WebFrame::instanceCount()
{
return frameCount;
}
WebLocalFrame* WebFrame::frameForCurrentContext()
{
v8::Handle<v8::Context> context = v8::Isolate::GetCurrent()->GetCurrentContext();
if (context.IsEmpty())
return 0;
return frameForContext(context);
}
WebLocalFrame* WebFrame::frameForContext(v8::Handle<v8::Context> context)
{
return WebFrameImpl::fromFrame(toFrameIfNotDetached(context));
}
WebLocalFrame* WebFrame::fromFrameOwnerElement(const WebElement& element)
{
return WebFrameImpl::fromFrameOwnerElement(PassRefPtr<Element>(element).get());
}
void WebFrameImpl::close()
{
m_client = 0;
deref();
}
WebString WebFrameImpl::uniqueName() const
{
return frame()->tree().uniqueName();
}
WebString WebFrameImpl::assignedName() const
{
return frame()->tree().name();
}
void WebFrameImpl::setName(const WebString& name)
{
frame()->tree().setName(name);
}
WebVector<WebIconURL> WebFrameImpl::iconURLs(int iconTypesMask) const
{
if (frame()->loader().state() == FrameStateComplete)
return frame()->document()->iconURLs(iconTypesMask);
return WebVector<WebIconURL>();
}
void WebFrameImpl::setIsRemote(bool isRemote)
{
m_isRemote = isRemote;
if (isRemote)
client()->initializeChildFrame(frame()->view()->frameRect(), frame()->view()->visibleContentScaleFactor());
}
void WebFrameImpl::setRemoteWebLayer(WebLayer* webLayer)
{
if (!frame())
return;
if (frame()->remotePlatformLayer())
GraphicsLayer::unregisterContentsLayer(frame()->remotePlatformLayer());
if (webLayer)
GraphicsLayer::registerContentsLayer(webLayer);
frame()->setRemotePlatformLayer(webLayer);
frame()->ownerElement()->scheduleLayerUpdate();
}
void WebFrameImpl::setPermissionClient(WebPermissionClient* permissionClient)
{
m_permissionClient = permissionClient;
}
void WebFrameImpl::setSharedWorkerRepositoryClient(WebSharedWorkerRepositoryClient* client)
{
m_sharedWorkerRepositoryClient = SharedWorkerRepositoryClientImpl::create(client);
}
WebSize WebFrameImpl::scrollOffset() const
{
FrameView* view = frameView();
if (!view)
return WebSize();
return view->scrollOffset();
}
WebSize WebFrameImpl::minimumScrollOffset() const
{
FrameView* view = frameView();
if (!view)
return WebSize();
return toIntSize(view->minimumScrollPosition());
}
WebSize WebFrameImpl::maximumScrollOffset() const
{
FrameView* view = frameView();
if (!view)
return WebSize();
return toIntSize(view->maximumScrollPosition());
}
void WebFrameImpl::setScrollOffset(const WebSize& offset)
{
if (FrameView* view = frameView())
view->setScrollOffset(IntPoint(offset.width, offset.height));
}
WebSize WebFrameImpl::contentsSize() const
{
return frame()->view()->contentsSize();
}
bool WebFrameImpl::hasVisibleContent() const
{
return frame()->view()->visibleWidth() > 0 && frame()->view()->visibleHeight() > 0;
}
WebRect WebFrameImpl::visibleContentRect() const
{
return frame()->view()->visibleContentRect();
}
bool WebFrameImpl::hasHorizontalScrollbar() const
{
return frame() && frame()->view() && frame()->view()->horizontalScrollbar();
}
bool WebFrameImpl::hasVerticalScrollbar() const
{
return frame() && frame()->view() && frame()->view()->verticalScrollbar();
}
WebView* WebFrameImpl::view() const
{
return viewImpl();
}
WebFrame* WebFrameImpl::opener() const
{
return m_opener;
}
void WebFrameImpl::setOpener(WebFrame* opener)
{
WebFrameImpl* openerImpl = toWebFrameImpl(opener);
if (m_opener && !openerImpl && m_client)
m_client->didDisownOpener(this);
if (m_opener)
m_opener->m_openedFrames.remove(this);
if (openerImpl)
openerImpl->m_openedFrames.add(this);
m_opener = openerImpl;
ASSERT(m_frame);
if (m_frame && m_frame->document())
m_frame->document()->initSecurityContext();
}
void WebFrameImpl::appendChild(WebFrame* child)
{
WebFrameImpl* childImpl = toWebFrameImpl(child);
childImpl->m_parent = this;
WebFrameImpl* oldLast = m_lastChild;
m_lastChild = childImpl;
if (oldLast) {
childImpl->m_previousSibling = oldLast;
oldLast->m_nextSibling = childImpl;
} else {
m_firstChild = childImpl;
}
ASSERT(frame());
frame()->tree().invalidateScopedChildCount();
}
void WebFrameImpl::removeChild(WebFrame* child)
{
WebFrameImpl* childImpl = toWebFrameImpl(child);
childImpl->m_parent = 0;
if (m_firstChild == childImpl)
m_firstChild = childImpl->m_nextSibling;
else
childImpl->m_previousSibling->m_nextSibling = childImpl->m_nextSibling;
if (m_lastChild == childImpl)
m_lastChild = childImpl->m_previousSibling;
else
childImpl->m_nextSibling->m_previousSibling = childImpl->m_previousSibling;
childImpl->m_previousSibling = childImpl->m_nextSibling = 0;
ASSERT(frame());
frame()->tree().invalidateScopedChildCount();
}
WebFrame* WebFrameImpl::parent() const
{
return m_parent;
}
WebFrame* WebFrameImpl::top() const
{
WebFrameImpl* frame = const_cast<WebFrameImpl*>(this);
for (WebFrameImpl* parent = frame; parent; parent = parent->m_parent)
frame = parent;
return frame;
}
WebFrame* WebFrameImpl::previousSibling() const
{
return m_previousSibling;
}
WebFrame* WebFrameImpl::nextSibling() const
{
return m_nextSibling;
}
WebFrame* WebFrameImpl::firstChild() const
{
return m_firstChild;
}
WebFrame* WebFrameImpl::lastChild() const
{
return m_lastChild;
}
WebFrame* WebFrameImpl::traversePrevious(bool wrap) const
{
if (!frame())
return 0;
return fromFrame(frame()->tree().traversePreviousWithWrap(wrap));
}
WebFrame* WebFrameImpl::traverseNext(bool wrap) const
{
if (!frame())
return 0;
return fromFrame(frame()->tree().traverseNextWithWrap(wrap));
}
WebFrame* WebFrameImpl::findChildByName(const WebString& name) const
{
if (!frame())
return 0;
return fromFrame(frame()->tree().child(name));
}
WebDocument WebFrameImpl::document() const
{
if (!frame() || !frame()->document())
return WebDocument();
return WebDocument(frame()->document());
}
WebPerformance WebFrameImpl::performance() const
{
if (!frame())
return WebPerformance();
return WebPerformance(&frame()->domWindow()->performance());
}
bool WebFrameImpl::dispatchBeforeUnloadEvent()
{
if (!frame())
return true;
return frame()->loader().shouldClose();
}
void WebFrameImpl::dispatchUnloadEvent()
{
if (!frame())
return;
frame()->loader().closeURL();
}
NPObject* WebFrameImpl::windowObject() const
{
if (!frame())
return 0;
return frame()->script().windowScriptNPObject();
}
void WebFrameImpl::bindToWindowObject(const WebString& name, NPObject* object)
{
bindToWindowObject(name, object, 0);
}
void WebFrameImpl::bindToWindowObject(const WebString& name, NPObject* object, void*)
{
if (!frame() || !frame()->script().canExecuteScripts(NotAboutToExecuteScript))
return;
frame()->script().bindToWindowObject(frame(), String(name), object);
}
void WebFrameImpl::executeScript(const WebScriptSource& source)
{
ASSERT(frame());
TextPosition position(OrdinalNumber::fromOneBasedInt(source.startLine), OrdinalNumber::first());
frame()->script().executeScriptInMainWorld(ScriptSourceCode(source.code, source.url, position));
}
void WebFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScriptSource* sourcesIn, unsigned numSources, int extensionGroup)
{
ASSERT(frame());
RELEASE_ASSERT(worldID > 0);
RELEASE_ASSERT(worldID < EmbedderWorldIdLimit);
Vector<ScriptSourceCode> sources;
for (unsigned i = 0; i < numSources; ++i) {
TextPosition position(OrdinalNumber::fromOneBasedInt(sourcesIn[i].startLine), OrdinalNumber::first());
sources.append(ScriptSourceCode(sourcesIn[i].code, sourcesIn[i].url, position));
}
frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensionGroup, 0);
}
void WebFrameImpl::setIsolatedWorldSecurityOrigin(int worldID, const WebSecurityOrigin& securityOrigin)
{
ASSERT(frame());
DOMWrapperWorld::setIsolatedWorldSecurityOrigin(worldID, securityOrigin.get());
}
void WebFrameImpl::setIsolatedWorldContentSecurityPolicy(int worldID, const WebString& policy)
{
ASSERT(frame());
DOMWrapperWorld::setIsolatedWorldContentSecurityPolicy(worldID, policy);
}
void WebFrameImpl::addMessageToConsole(const WebConsoleMessage& message)
{
ASSERT(frame());
MessageLevel webCoreMessageLevel;
switch (message.level) {
case WebConsoleMessage::LevelDebug:
webCoreMessageLevel = DebugMessageLevel;
break;
case WebConsoleMessage::LevelLog:
webCoreMessageLevel = LogMessageLevel;
break;
case WebConsoleMessage::LevelWarning:
webCoreMessageLevel = WarningMessageLevel;
break;
case WebConsoleMessage::LevelError:
webCoreMessageLevel = ErrorMessageLevel;
break;
default:
ASSERT_NOT_REACHED();
return;
}
frame()->document()->addConsoleMessage(OtherMessageSource, webCoreMessageLevel, message.text);
}
void WebFrameImpl::collectGarbage()
{
if (!frame())
return;
if (!frame()->settings()->scriptEnabled())
return;
V8GCController::collectGarbage(v8::Isolate::GetCurrent());
}
bool WebFrameImpl::checkIfRunInsecureContent(const WebURL& url) const
{
ASSERT(frame());
return frame()->loader().mixedContentChecker()->canRunInsecureContent(frame()->document()->securityOrigin(), url);
}
v8::Handle<v8::Value> WebFrameImpl::executeScriptAndReturnValue(const WebScriptSource& source)
{
ASSERT(frame());
UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
TextPosition position(OrdinalNumber::fromOneBasedInt(source.startLine), OrdinalNumber::first());
return frame()->script().executeScriptInMainWorldAndReturnValue(ScriptSourceCode(source.code, source.url, position)).v8Value();
}
void WebFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScriptSource* sourcesIn, unsigned numSources, int extensionGroup, WebVector<v8::Local<v8::Value> >* results)
{
ASSERT(frame());
RELEASE_ASSERT(worldID > 0);
RELEASE_ASSERT(worldID < EmbedderWorldIdLimit);
Vector<ScriptSourceCode> sources;
for (unsigned i = 0; i < numSources; ++i) {
TextPosition position(OrdinalNumber::fromOneBasedInt(sourcesIn[i].startLine), OrdinalNumber::first());
sources.append(ScriptSourceCode(sourcesIn[i].code, sourcesIn[i].url, position));
}
if (results) {
Vector<ScriptValue> scriptResults;
frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensionGroup, &scriptResults);
WebVector<v8::Local<v8::Value> > v8Results(scriptResults.size());
for (unsigned i = 0; i < scriptResults.size(); i++)
v8Results[i] = v8::Local<v8::Value>::New(toIsolate(frame()), scriptResults[i].v8Value());
results->swap(v8Results);
} else {
frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensionGroup, 0);
}
}
v8::Handle<v8::Value> WebFrameImpl::callFunctionEvenIfScriptDisabled(v8::Handle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> argv[])
{
ASSERT(frame());
return frame()->script().callFunction(function, receiver, argc, argv);
}
v8::Local<v8::Context> WebFrameImpl::mainWorldScriptContext() const
{
return toV8Context(V8PerIsolateData::mainThreadIsolate(), frame(), DOMWrapperWorld::mainWorld());
}
void WebFrameImpl::reload(bool ignoreCache)
{
ASSERT(frame());
frame()->loader().reload(ignoreCache ? EndToEndReload : NormalReload);
}
void WebFrameImpl::reloadWithOverrideURL(const WebURL& overrideUrl, bool ignoreCache)
{
ASSERT(frame());
frame()->loader().reload(ignoreCache ? EndToEndReload : NormalReload, overrideUrl);
}
void WebFrameImpl::loadRequest(const WebURLRequest& request)
{
ASSERT(frame());
ASSERT(!request.isNull());
const ResourceRequest& resourceRequest = request.toResourceRequest();
if (resourceRequest.url().protocolIs("javascript")) {
loadJavaScriptURL(resourceRequest.url());
return;
}
frame()->loader().load(FrameLoadRequest(0, resourceRequest));
}
void WebFrameImpl::loadHistoryItem(const WebHistoryItem& item, WebURLRequest::CachePolicy cachePolicy)
{
ASSERT(frame());
RefPtr<HistoryItem> historyItem = PassRefPtr<HistoryItem>(item);
ASSERT(historyItem);
frame()->page()->historyController().goToItem(historyItem.get(), static_cast<ResourceRequestCachePolicy>(cachePolicy));
}
void WebFrameImpl::loadData(const WebData& data, const WebString& mimeType, const WebString& textEncoding, const WebURL& baseURL, const WebURL& unreachableURL, bool replace)
{
ASSERT(frame());
ResourceRequest request;
if (replace && !unreachableURL.isEmpty() && frame()->loader().provisionalDocumentLoader())
request = frame()->loader().provisionalDocumentLoader()->originalRequest();
request.setURL(baseURL);
FrameLoadRequest frameRequest(0, request, SubstituteData(data, mimeType, textEncoding, unreachableURL));
ASSERT(frameRequest.substituteData().isValid());
frameRequest.setLockBackForwardList(replace);
frame()->loader().load(frameRequest);
}
void WebFrameImpl::loadHTMLString(const WebData& data, const WebURL& baseURL, const WebURL& unreachableURL, bool replace)
{
ASSERT(frame());
loadData(data, WebString::fromUTF8("text/html"), WebString::fromUTF8("UTF-8"), baseURL, unreachableURL, replace);
}
bool WebFrameImpl::isLoading() const
{
if (!frame())
return false;
return frame()->loader().isLoading();
}
void WebFrameImpl::stopLoading()
{
if (!frame())
return;
frame()->loader().stopAllLoaders();
}
WebDataSource* WebFrameImpl::provisionalDataSource() const
{
ASSERT(frame());
DocumentLoader* documentLoader = frame()->loader().provisionalDocumentLoader();
if (!documentLoader)
documentLoader = frame()->loader().policyDocumentLoader();
return DataSourceForDocLoader(documentLoader);
}
WebDataSource* WebFrameImpl::dataSource() const
{
ASSERT(frame());
return DataSourceForDocLoader(frame()->loader().documentLoader());
}
WebHistoryItem WebFrameImpl::previousHistoryItem() const
{
ASSERT(frame());
return WebHistoryItem(frame()->page()->historyController().previousItemForExport());
}
WebHistoryItem WebFrameImpl::currentHistoryItem() const
{
ASSERT(frame());
if (!frame()->loader().documentLoader())
return WebHistoryItem();
frame()->loader().saveDocumentState();
return WebHistoryItem(frame()->page()->historyController().currentItemForExport());
}
void WebFrameImpl::enableViewSourceMode(bool enable)
{
if (frame())
frame()->setInViewSourceMode(enable);
}
bool WebFrameImpl::isViewSourceModeEnabled() const
{
if (!frame())
return false;
return frame()->inViewSourceMode();
}
void WebFrameImpl::setReferrerForRequest(WebURLRequest& request, const WebURL& referrerURL)
{
String referrer = referrerURL.isEmpty() ? frame()->document()->outgoingReferrer() : String(referrerURL.spec().utf16());
referrer = SecurityPolicy::generateReferrerHeader(frame()->document()->referrerPolicy(), request.url(), referrer);
if (referrer.isEmpty())
return;
request.setHTTPReferrer(referrer, static_cast<WebReferrerPolicy>(frame()->document()->referrerPolicy()));
}
void WebFrameImpl::dispatchWillSendRequest(WebURLRequest& request)
{
ResourceResponse response;
frame()->loader().client()->dispatchWillSendRequest(0, 0, request.toMutableResourceRequest(), response);
}
WebURLLoader* WebFrameImpl::createAssociatedURLLoader(const WebURLLoaderOptions& options)
{
return new AssociatedURLLoader(this, options);
}
unsigned WebFrameImpl::unloadListenerCount() const
{
return frame()->domWindow()->pendingUnloadEventListeners();
}
void WebFrameImpl::replaceSelection(const WebString& text)
{
bool selectReplacement = false;
bool smartReplace = true;
frame()->editor().replaceSelectionWithText(text, selectReplacement, smartReplace);
}
void WebFrameImpl::insertText(const WebString& text)
{
if (frame()->inputMethodController().hasComposition())
frame()->inputMethodController().confirmComposition(text);
else
frame()->editor().insertText(text, 0);
}
void WebFrameImpl::setMarkedText(const WebString& text, unsigned location, unsigned length)
{
Vector<CompositionUnderline> decorations;
frame()->inputMethodController().setComposition(text, decorations, location, length);
}
void WebFrameImpl::unmarkText()
{
frame()->inputMethodController().cancelComposition();
}
bool WebFrameImpl::hasMarkedText() const
{
return frame()->inputMethodController().hasComposition();
}
WebRange WebFrameImpl::markedRange() const
{
return frame()->inputMethodController().compositionRange();
}
bool WebFrameImpl::firstRectForCharacterRange(unsigned location, unsigned length, WebRect& rect) const
{
if ((location + length < location) && (location + length))
length = 0;
Element* editable = frame()->selection().rootEditableElementOrDocumentElement();
ASSERT(editable);
RefPtrWillBeRawPtr<Range> range = PlainTextRange(location, location + length).createRange(*editable);
if (!range)
return false;
IntRect intRect = frame()->editor().firstRectForRange(range.get());
rect = WebRect(intRect);
rect = frame()->view()->contentsToWindow(rect);
return true;
}
size_t WebFrameImpl::characterIndexForPoint(const WebPoint& webPoint) const
{
if (!frame())
return kNotFound;
IntPoint point = frame()->view()->windowToContents(webPoint);
HitTestResult result = frame()->eventHandler().hitTestResultAtPoint(point, HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::ConfusingAndOftenMisusedDisallowShadowContent);
RefPtrWillBeRawPtr<Range> range = frame()->rangeForPoint(result.roundedPointInInnerNodeFrame());
if (!range)
return kNotFound;
Element* editable = frame()->selection().rootEditableElementOrDocumentElement();
ASSERT(editable);
return PlainTextRange::create(*editable, *range.get()).start();
}
bool WebFrameImpl::executeCommand(const WebString& name, const WebNode& node)
{
ASSERT(frame());
if (name.length() <= 2)
return false;
String command = name;
command.replace(0, 1, command.substring(0, 1).upper());
if (command[command.length() - 1] == UChar(':'))
command = command.substring(0, command.length() - 1);
WebPluginContainerImpl* pluginContainer = pluginContainerFromNode(frame(), node);
if (pluginContainer && pluginContainer->executeEditCommand(name))
return true;
bool result = true;
if (command == "DeleteToEndOfParagraph") {
if (!frame()->editor().deleteWithDirection(DirectionForward, ParagraphBoundary, true, false))
frame()->editor().deleteWithDirection(DirectionForward, CharacterGranularity, true, false);
} else if (command == "Indent") {
frame()->editor().indent();
} else if (command == "Outdent") {
frame()->editor().outdent();
} else if (command == "DeleteBackward") {
result = frame()->editor().command(AtomicString("BackwardDelete")).execute();
} else if (command == "DeleteForward") {
result = frame()->editor().command(AtomicString("ForwardDelete")).execute();
} else if (command == "AdvanceToNextMisspelling") {
frame()->spellChecker().advanceToNextMisspelling(false);
} else if (command == "ToggleSpellPanel") {
frame()->spellChecker().showSpellingGuessPanel();
} else {
result = frame()->editor().command(command).execute();
}
return result;
}
bool WebFrameImpl::executeCommand(const WebString& name, const WebString& value, const WebNode& node)
{
ASSERT(frame());
String webName = name;
WebPluginContainerImpl* pluginContainer = pluginContainerFromNode(frame(), node);
if (pluginContainer && pluginContainer->executeEditCommand(name, value))
return true;
if (!frame()->editor().canEdit() && webName == "moveToBeginningOfDocument")
return viewImpl()->bubblingScroll(ScrollUp, ScrollByDocument);
if (!frame()->editor().canEdit() && webName == "moveToEndOfDocument")
return viewImpl()->bubblingScroll(ScrollDown, ScrollByDocument);
if (webName == "showGuessPanel") {
frame()->spellChecker().showSpellingGuessPanel();
return true;
}
return frame()->editor().command(webName).execute(value);
}
bool WebFrameImpl::isCommandEnabled(const WebString& name) const
{
ASSERT(frame());
return frame()->editor().command(name).isEnabled();
}
void WebFrameImpl::enableContinuousSpellChecking(bool enable)
{
if (enable == isContinuousSpellCheckingEnabled())
return;
frame()->spellChecker().toggleContinuousSpellChecking();
}
bool WebFrameImpl::isContinuousSpellCheckingEnabled() const
{
return frame()->spellChecker().isContinuousSpellCheckingEnabled();
}
void WebFrameImpl::requestTextChecking(const WebElement& webElement)
{
if (webElement.isNull())
return;
frame()->spellChecker().requestTextChecking(*webElement.constUnwrap<Element>());
}
void WebFrameImpl::replaceMisspelledRange(const WebString& text)
{
if (pluginContainerFromFrame(frame()))
return;
RefPtrWillBeRawPtr<Range> caretRange = frame()->selection().toNormalizedRange();
if (!caretRange)
return;
Vector<DocumentMarker*> markers = frame()->document()->markers().markersInRange(caretRange.get(), DocumentMarker::MisspellingMarkers());
if (markers.size() < 1 || markers[0]->startOffset() >= markers[0]->endOffset())
return;
RefPtrWillBeRawPtr<Range> markerRange = Range::create(caretRange->ownerDocument(), caretRange->startContainer(), markers[0]->startOffset(), caretRange->endContainer(), markers[0]->endOffset());
if (!markerRange)
return;
frame()->selection().setSelection(VisibleSelection(markerRange.get()), CharacterGranularity);
frame()->editor().replaceSelectionWithText(text, false, false);
}
void WebFrameImpl::removeSpellingMarkers()
{
frame()->document()->markers().removeMarkers(DocumentMarker::MisspellingMarkers());
}
bool WebFrameImpl::hasSelection() const
{
WebPluginContainerImpl* pluginContainer = pluginContainerFromFrame(frame());
if (pluginContainer)
return pluginContainer->plugin()->hasSelection();
return frame()->selection().start() != frame()->selection().end();
}
WebRange WebFrameImpl::selectionRange() const
{
return frame()->selection().toNormalizedRange();
}
WebString WebFrameImpl::selectionAsText() const
{
WebPluginContainerImpl* pluginContainer = pluginContainerFromFrame(frame());
if (pluginContainer)
return pluginContainer->plugin()->selectionAsText();
RefPtrWillBeRawPtr<Range> range = frame()->selection().toNormalizedRange();
if (!range)
return WebString();
String text = range->text();
#if OS(WIN)
replaceNewlinesWithWindowsStyleNewlines(text);
#endif
replaceNBSPWithSpace(text);
return text;
}
WebString WebFrameImpl::selectionAsMarkup() const
{
WebPluginContainerImpl* pluginContainer = pluginContainerFromFrame(frame());
if (pluginContainer)
return pluginContainer->plugin()->selectionAsMarkup();
RefPtrWillBeRawPtr<Range> range = frame()->selection().toNormalizedRange();
if (!range)
return WebString();
return createMarkup(range.get(), 0, AnnotateForInterchange, false, ResolveNonLocalURLs);
}
void WebFrameImpl::selectWordAroundPosition(LocalFrame* frame, VisiblePosition position)
{
VisibleSelection selection(position);
selection.expandUsingGranularity(WordGranularity);
TextGranularity granularity = selection.isRange() ? WordGranularity : CharacterGranularity;
frame->selection().setSelection(selection, granularity);
}
bool WebFrameImpl::selectWordAroundCaret()
{
FrameSelection& selection = frame()->selection();
ASSERT(!selection.isNone());
if (selection.isNone() || selection.isRange())
return false;
selectWordAroundPosition(frame(), selection.selection().visibleStart());
return true;
}
void WebFrameImpl::selectRange(const WebPoint& base, const WebPoint& extent)
{
moveRangeSelection(base, extent);
}
void WebFrameImpl::selectRange(const WebRange& webRange)
{
if (RefPtrWillBeRawPtr<Range> range = static_cast<PassRefPtrWillBeRawPtr<Range> >(webRange))
frame()->selection().setSelectedRange(range.get(), WebCore::VP_DEFAULT_AFFINITY, false);
}
void WebFrameImpl::moveRangeSelection(const WebPoint& base, const WebPoint& extent)
{
VisiblePosition basePosition = visiblePositionForWindowPoint(base);
VisiblePosition extentPosition = visiblePositionForWindowPoint(extent);
VisibleSelection newSelection = VisibleSelection(basePosition, extentPosition);
frame()->selection().setSelection(newSelection, CharacterGranularity);
}
void WebFrameImpl::moveCaretSelection(const WebPoint& point)
{
Element* editable = frame()->selection().rootEditableElement();
if (!editable)
return;
VisiblePosition position = visiblePositionForWindowPoint(point);
frame()->selection().moveTo(position, UserTriggered);
}
bool WebFrameImpl::setEditableSelectionOffsets(int start, int end)
{
return frame()->inputMethodController().setEditableSelectionOffsets(PlainTextRange(start, end));
}
bool WebFrameImpl::setCompositionFromExistingText(int compositionStart, int compositionEnd, const WebVector<WebCompositionUnderline>& underlines)
{
if (!frame()->editor().canEdit())
return false;
InputMethodController& inputMethodController = frame()->inputMethodController();
inputMethodController.cancelComposition();
if (compositionStart == compositionEnd)
return true;
inputMethodController.setCompositionFromExistingText(CompositionUnderlineVectorBuilder(underlines), compositionStart, compositionEnd);
return true;
}
void WebFrameImpl::extendSelectionAndDelete(int before, int after)
{
if (WebPlugin* plugin = focusedPluginIfInputMethodSupported()) {
plugin->extendSelectionAndDelete(before, after);
return;
}
frame()->inputMethodController().extendSelectionAndDelete(before, after);
}
void WebFrameImpl::setCaretVisible(bool visible)
{
frame()->selection().setCaretVisible(visible);
}
VisiblePosition WebFrameImpl::visiblePositionForWindowPoint(const WebPoint& point)
{
FloatPoint unscaledPoint(point);
unscaledPoint.scale(1 / view()->pageScaleFactor(), 1 / view()->pageScaleFactor());
HitTestRequest request = HitTestRequest::Move | HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::IgnoreClipping | HitTestRequest::ConfusingAndOftenMisusedDisallowShadowContent;
HitTestResult result(frame()->view()->windowToContents(roundedIntPoint(unscaledPoint)));
frame()->document()->renderView()->layer()->hitTest(request, result);
if (Node* node = result.targetNode())
return frame()->selection().selection().visiblePositionRespectingEditingBoundary(result.localPoint(), node);
return VisiblePosition();
}
WebPlugin* WebFrameImpl::focusedPluginIfInputMethodSupported()
{
WebPluginContainerImpl* container = WebFrameImpl::pluginContainerFromNode(frame(), WebNode(frame()->document()->focusedElement()));
if (container && container->supportsInputMethod())
return container->plugin();
return 0;
}
int WebFrameImpl::printBegin(const WebPrintParams& printParams, const WebNode& constrainToNode)
{
ASSERT(!frame()->document()->isFrameSet());
WebPluginContainerImpl* pluginContainer = 0;
if (constrainToNode.isNull()) {
pluginContainer = pluginContainerFromFrame(frame());
} else {
pluginContainer = toWebPluginContainerImpl(constrainToNode.pluginContainer());
}
if (pluginContainer && pluginContainer->supportsPaginatedPrint())
m_printContext = adoptPtr(new ChromePluginPrintContext(frame(), pluginContainer, printParams));
else
m_printContext = adoptPtr(new ChromePrintContext(frame()));
FloatRect rect(0, 0, static_cast<float>(printParams.printContentArea.width), static_cast<float>(printParams.printContentArea.height));
m_printContext->begin(rect.width(), rect.height());
float pageHeight;
m_printContext->computePageRects(rect, 0, 0, 1.0, pageHeight);
return m_printContext->pageCount();
}
float WebFrameImpl::getPrintPageShrink(int page)
{
ASSERT(m_printContext && page >= 0);
return m_printContext->getPageShrink(page);
}
float WebFrameImpl::printPage(int page, WebCanvas* canvas)
{
#if ENABLE(PRINTING)
ASSERT(m_printContext && page >= 0 && frame() && frame()->document());
GraphicsContext graphicsContext(canvas);
graphicsContext.setPrinting(true);
return m_printContext->spoolPage(graphicsContext, page);
#else
return 0;
#endif
}
void WebFrameImpl::printEnd()
{
ASSERT(m_printContext);
m_printContext->end();
m_printContext.clear();
}
bool WebFrameImpl::isPrintScalingDisabledForPlugin(const WebNode& node)
{
WebPluginContainerImpl* pluginContainer = node.isNull() ? pluginContainerFromFrame(frame()) : toWebPluginContainerImpl(node.pluginContainer());
if (!pluginContainer || !pluginContainer->supportsPaginatedPrint())
return false;
return pluginContainer->isPrintScalingDisabled();
}
bool WebFrameImpl::hasCustomPageSizeStyle(int pageIndex)
{
return frame()->document()->styleForPage(pageIndex)->pageSizeType() != PAGE_SIZE_AUTO;
}
bool WebFrameImpl::isPageBoxVisible(int pageIndex)
{
return frame()->document()->isPageBoxVisible(pageIndex);
}
void WebFrameImpl::pageSizeAndMarginsInPixels(int pageIndex, WebSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft)
{
IntSize size = pageSize;
frame()->document()->pageSizeAndMarginsInPixels(pageIndex, size, marginTop, marginRight, marginBottom, marginLeft);
pageSize = size;
}
WebString WebFrameImpl::pageProperty(const WebString& propertyName, int pageIndex)
{
ASSERT(m_printContext);
return m_printContext->pageProperty(frame(), propertyName.utf8().data(), pageIndex);
}
bool WebFrameImpl::find(int identifier, const WebString& searchText, const WebFindOptions& options, bool wrapWithinFrame, WebRect* selectionRect)
{
return ensureTextFinder().find(identifier, searchText, options, wrapWithinFrame, selectionRect);
}
void WebFrameImpl::stopFinding(bool clearSelection)
{
if (m_textFinder) {
if (!clearSelection)
setFindEndstateFocusAndSelection();
m_textFinder->stopFindingAndClearSelection();
}
}
void WebFrameImpl::scopeStringMatches(int identifier, const WebString& searchText, const WebFindOptions& options, bool reset)
{
ensureTextFinder().scopeStringMatches(identifier, searchText, options, reset);
}
void WebFrameImpl::cancelPendingScopingEffort()
{
if (m_textFinder)
m_textFinder->cancelPendingScopingEffort();
}
void WebFrameImpl::increaseMatchCount(int count, int identifier)
{
ASSERT(!parent());
ASSERT(m_textFinder);
m_textFinder->increaseMatchCount(identifier, count);
}
void WebFrameImpl::resetMatchCount()
{
ASSERT(m_textFinder);
m_textFinder->resetMatchCount();
}
void WebFrameImpl::sendOrientationChangeEvent(int orientation)
{
if (frame())
frame()->sendOrientationChangeEvent(orientation);
}
void WebFrameImpl::dispatchMessageEventWithOriginCheck(const WebSecurityOrigin& intendedTargetOrigin, const WebDOMEvent& event)
{
ASSERT(!event.isNull());
frame()->domWindow()->dispatchMessageEventWithOriginCheck(intendedTargetOrigin.get(), event, nullptr);
}
int WebFrameImpl::findMatchMarkersVersion() const
{
ASSERT(!parent());
if (m_textFinder)
return m_textFinder->findMatchMarkersVersion();
return 0;
}
int WebFrameImpl::selectNearestFindMatch(const WebFloatPoint& point, WebRect* selectionRect)
{
ASSERT(!parent());
ASSERT(m_textFinder);
return m_textFinder->selectNearestFindMatch(point, selectionRect);
}
WebFloatRect WebFrameImpl::activeFindMatchRect()
{
ASSERT(!parent());
if (m_textFinder)
return m_textFinder->activeFindMatchRect();
return WebFloatRect();
}
void WebFrameImpl::findMatchRects(WebVector<WebFloatRect>& outputRects)
{
ASSERT(!parent());
ASSERT(m_textFinder);
m_textFinder->findMatchRects(outputRects);
}
void WebFrameImpl::setTickmarks(const WebVector<WebRect>& tickmarks)
{
if (frameView()) {
Vector<IntRect> tickmarksConverted(tickmarks.size());
for (size_t i = 0; i < tickmarks.size(); ++i)
tickmarksConverted[i] = tickmarks[i];
frameView()->setTickmarks(tickmarksConverted);
invalidateScrollbar();
}
}
WebString WebFrameImpl::contentAsText(size_t maxChars) const
{
if (!frame())
return WebString();
StringBuilder text;
frameContentAsPlainText(maxChars, frame(), text);
return text.toString();
}
WebString WebFrameImpl::contentAsMarkup() const
{
if (!frame())
return WebString();
return createFullMarkup(frame()->document());
}
WebString WebFrameImpl::renderTreeAsText(RenderAsTextControls toShow) const
{
RenderAsTextBehavior behavior = RenderAsTextBehaviorNormal;
if (toShow & RenderAsTextDebug)
behavior |= RenderAsTextShowCompositedLayers | RenderAsTextShowAddresses | RenderAsTextShowIDAndClass | RenderAsTextShowLayerNesting;
if (toShow & RenderAsTextPrinting)
behavior |= RenderAsTextPrintingMode;
return externalRepresentation(frame(), behavior);
}
WebString WebFrameImpl::markerTextForListItem(const WebElement& webElement) const
{
return WebCore::markerTextForListItem(const_cast<Element*>(webElement.constUnwrap<Element>()));
}
void WebFrameImpl::printPagesWithBoundaries(WebCanvas* canvas, const WebSize& pageSizeInPixels)
{
ASSERT(m_printContext);
GraphicsContext graphicsContext(canvas);
graphicsContext.setPrinting(true);
m_printContext->spoolAllPagesWithBoundaries(graphicsContext, FloatSize(pageSizeInPixels.width, pageSizeInPixels.height));
}
WebRect WebFrameImpl::selectionBoundsRect() const
{
return hasSelection() ? WebRect(IntRect(frame()->selection().bounds(false))) : WebRect();
}
bool WebFrameImpl::selectionStartHasSpellingMarkerFor(int from, int length) const
{
if (!frame())
return false;
return frame()->spellChecker().selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
}
WebString WebFrameImpl::layerTreeAsText(bool showDebugInfo) const
{
if (!frame())
return WebString();
return WebString(frame()->layerTreeAsText(showDebugInfo ? LayerTreeIncludesDebugInfo : LayerTreeNormal));
}
WebLocalFrame* WebFrame::create(WebFrameClient* client)
{
return WebFrameImpl::create(client);
}
WebFrameImpl* WebFrameImpl::create(WebFrameClient* client)
{
return adoptRef(new WebFrameImpl(client)).leakRef();
}
WebFrameImpl::WebFrameImpl(WebFrameClient* client)
: m_frameLoaderClientImpl(this)
, m_parent(0)
, m_previousSibling(0)
, m_nextSibling(0)
, m_firstChild(0)
, m_lastChild(0)
, m_opener(0)
, m_client(client)
, m_permissionClient(0)
, m_inputEventsScaleFactorForEmulation(1)
{
blink::Platform::current()->incrementStatsCounter(webFrameActiveCount);
frameCount++;
}
WebFrameImpl::~WebFrameImpl()
{
HashSet<WebFrameImpl*>::iterator end = m_openedFrames.end();
for (HashSet<WebFrameImpl*>::iterator it = m_openedFrames.begin(); it != end; ++it)
(*it)->m_opener = 0;
blink::Platform::current()->decrementStatsCounter(webFrameActiveCount);
frameCount--;
cancelPendingScopingEffort();
}
void WebFrameImpl::setWebCoreFrame(PassRefPtr<WebCore::LocalFrame> frame)
{
m_frame = frame;
}
void WebFrameImpl::initializeAsMainFrame(WebCore::Page* page)
{
setWebCoreFrame(LocalFrame::create(&m_frameLoaderClientImpl, &page->frameHost(), 0));
m_frame->init();
}
PassRefPtr<LocalFrame> WebFrameImpl::createChildFrame(const FrameLoadRequest& request, HTMLFrameOwnerElement* ownerElement)
{
ASSERT(m_client);
WebFrameImpl* webframe = toWebFrameImpl(m_client->createChildFrame(this, request.frameName()));
if (!webframe)
return nullptr;
RefPtr<LocalFrame> childFrame = LocalFrame::create(&webframe->m_frameLoaderClientImpl, frame()->host(), ownerElement);
webframe->setWebCoreFrame(childFrame);
childFrame->tree().setName(request.frameName(), ownerElement->getAttribute(ownerElement->subResourceAttributeName()));
childFrame->init();
if (!childFrame->tree().parent())
return nullptr;
RefPtr<HistoryItem> childItem;
if (isBackForwardLoadType(frame()->loader().loadType()) && !frame()->document()->loadEventFinished()) {
childItem = PassRefPtr<HistoryItem>(webframe->client()->historyItemForNewChildFrame(webframe));
if (!childItem)
childItem = frame()->page()->historyController().itemForNewChildFrame(childFrame.get());
}
if (childItem)
childFrame->loader().loadHistoryItem(childItem.get());
else
childFrame->loader().load(FrameLoadRequest(0, request.resourceRequest(), "_self"));
if (!childFrame->tree().parent())
return nullptr;
return childFrame.release();
}
void WebFrameImpl::didChangeContentsSize(const IntSize& size)
{
if (m_textFinder && m_textFinder->totalMatchCount() > 0) {
ASSERT(!parent());
m_textFinder->increaseMarkerVersion();
}
}
void WebFrameImpl::createFrameView()
{
TRACE_EVENT0("webkit", "WebFrameImpl::createFrameView");
ASSERT(frame());
WebViewImpl* webView = viewImpl();
bool isMainFrame = webView->mainFrameImpl()->frame() == frame();
if (isMainFrame)
webView->suppressInvalidations(true);
frame()->createView(webView->size(), webView->baseBackgroundColor(), webView->isTransparent());
if (webView->shouldAutoResize() && isMainFrame)
frame()->view()->enableAutoSizeMode(true, webView->minAutoSize(), webView->maxAutoSize());
frame()->view()->setInputEventsTransformForEmulation(m_inputEventsOffsetForEmulation, m_inputEventsScaleFactorForEmulation);
if (isMainFrame)
webView->suppressInvalidations(false);
}
WebFrameImpl* WebFrameImpl::fromFrame(LocalFrame* frame)
{
if (!frame)
return 0;
FrameLoaderClient* client = frame->loader().client();
if (!client || !client->isFrameLoaderClientImpl())
return 0;
return toFrameLoaderClientImpl(client)->webFrame();
}
WebFrameImpl* WebFrameImpl::fromFrameOwnerElement(Element* element)
{
if (!isHTMLFrameElementBase(element))
return 0;
return fromFrame(toLocalFrame(toHTMLFrameElementBase(element)->contentFrame()));
}
WebViewImpl* WebFrameImpl::viewImpl() const
{
if (!frame())
return 0;
return WebViewImpl::fromPage(frame()->page());
}
WebDataSourceImpl* WebFrameImpl::dataSourceImpl() const
{
return static_cast<WebDataSourceImpl*>(dataSource());
}
WebDataSourceImpl* WebFrameImpl::provisionalDataSourceImpl() const
{
return static_cast<WebDataSourceImpl*>(provisionalDataSource());
}
void WebFrameImpl::setFindEndstateFocusAndSelection()
{
WebFrameImpl* mainFrameImpl = viewImpl()->mainFrameImpl();
if (this != mainFrameImpl->activeMatchFrame())
return;
if (Range* activeMatch = m_textFinder->activeMatch()) {
VisibleSelection selection(frame()->selection().selection());
if (!selection.isNone())
return;
Node* node = activeMatch->firstNode();
if (node && node->isInShadowTree()) {
if (Node* host = node->shadowHost()) {
if (isHTMLInputElement(*host) || isHTMLTextAreaElement(*host))
node = host;
}
}
for (; node; node = node->parentNode()) {
if (!node->isElementNode())
continue;
Element* element = toElement(node);
if (element->isFocusable()) {
frame()->selection().setSelection(VisibleSelection(activeMatch));
frame()->document()->setFocusedElement(element);
return;
}
}
node = activeMatch->firstNode();
for (; node && node != activeMatch->pastLastNode(); node = NodeTraversal::next(*node)) {
if (!node->isElementNode())
continue;
Element* element = toElement(node);
if (element->isFocusable()) {
frame()->document()->setFocusedElement(element);
return;
}
}
frame()->selection().setSelection(VisibleSelection(activeMatch));
frame()->document()->setFocusedElement(nullptr);
m_textFinder->resetActiveMatch();
}
}
void WebFrameImpl::didFail(const ResourceError& error, bool wasProvisional)
{
if (!client())
return;
WebURLError webError = error;
if (wasProvisional)
client()->didFailProvisionalLoad(this, webError);
else
client()->didFailLoad(this, webError);
}
void WebFrameImpl::setCanHaveScrollbars(bool canHaveScrollbars)
{
frame()->view()->setCanHaveScrollbars(canHaveScrollbars);
}
void WebFrameImpl::setInputEventsTransformForEmulation(const IntSize& offset, float contentScaleFactor)
{
m_inputEventsOffsetForEmulation = offset;
m_inputEventsScaleFactorForEmulation = contentScaleFactor;
if (frame()->view())
frame()->view()->setInputEventsTransformForEmulation(m_inputEventsOffsetForEmulation, m_inputEventsScaleFactorForEmulation);
}
void WebFrameImpl::loadJavaScriptURL(const KURL& url)
{
if (!frame()->document() || !frame()->page())
return;
RefPtr<Document> ownerDocument(frame()->document());
if (SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs(frame()->document()->url().protocol()))
return;
String script = decodeURLEscapeSequences(url.string().substring(strlen("javascript:")));
UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
ScriptValue result = frame()->script().executeScriptInMainWorldAndReturnValue(ScriptSourceCode(script));
String scriptResult;
if (!result.getString(scriptResult))
return;
if (!frame()->navigationScheduler().locationChangePending())
frame()->document()->loader()->replaceDocument(scriptResult, ownerDocument.get());
}
void WebFrameImpl::willDetachParent()
{
if (m_textFinder && m_textFinder->scopingInProgress()) {
m_textFinder->flushCurrentScoping();
m_textFinder->cancelPendingScopingEffort();
}
}
WebFrameImpl* WebFrameImpl::activeMatchFrame() const
{
ASSERT(!parent());
if (m_textFinder)
return m_textFinder->activeMatchFrame();
return 0;
}
WebCore::Range* WebFrameImpl::activeMatch() const
{
if (m_textFinder)
return m_textFinder->activeMatch();
return 0;
}
TextFinder& WebFrameImpl::ensureTextFinder()
{
if (!m_textFinder)
m_textFinder = TextFinder::create(*this);
return *m_textFinder;
}
void WebFrameImpl::invalidateScrollbar() const
{
ASSERT(frame() && frame()->view());
FrameView* view = frame()->view();
Scrollbar* scrollbar = view->verticalScrollbar();
if (scrollbar)
scrollbar->invalidate();
}
void WebFrameImpl::invalidateAll() const
{
ASSERT(frame() && frame()->view());
FrameView* view = frame()->view();
view->invalidateRect(view->frameRect());
invalidateScrollbar();
}
}