1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "web/WebRemoteFrameImpl.h"
8 #include "core/frame/FrameView.h"
9 #include "core/frame/RemoteFrame.h"
10 #include "core/frame/Settings.h"
11 #include "core/page/Page.h"
12 #include "platform/heap/Handle.h"
13 #include "public/platform/WebFloatRect.h"
14 #include "public/platform/WebRect.h"
15 #include "public/web/WebDocument.h"
16 #include "public/web/WebPerformance.h"
17 #include "public/web/WebRange.h"
18 #include "public/web/WebTreeScopeType.h"
19 #include "web/RemoteBridgeFrameOwner.h"
20 #include "web/WebViewImpl.h"
21 #include <v8/include/v8.h>
25 WebRemoteFrame
* WebRemoteFrame::create(WebTreeScopeType scope
, WebRemoteFrameClient
* client
)
27 return WebRemoteFrameImpl::create(scope
, client
);
30 WebRemoteFrame
* WebRemoteFrameImpl::create(WebTreeScopeType scope
, WebRemoteFrameClient
* client
)
32 WebRemoteFrameImpl
* frame
= new WebRemoteFrameImpl(scope
, client
);
36 return adoptRef(frame
).leakRef();
40 WebRemoteFrameImpl::~WebRemoteFrameImpl()
45 DEFINE_TRACE(WebRemoteFrameImpl
)
47 visitor
->trace(m_frameClient
);
48 visitor
->trace(m_frame
);
49 visitor
->trace(m_ownersForChildren
);
50 visitor
->template registerWeakMembers
<WebFrame
, &WebFrame::clearWeakFrames
>(this);
51 WebFrame::traceFrames(visitor
, this);
55 bool WebRemoteFrameImpl::isWebLocalFrame() const
60 WebLocalFrame
* WebRemoteFrameImpl::toWebLocalFrame()
66 bool WebRemoteFrameImpl::isWebRemoteFrame() const
71 WebRemoteFrame
* WebRemoteFrameImpl::toWebRemoteFrame()
76 void WebRemoteFrameImpl::close()
79 m_selfKeepAlive
.clear();
85 WebString
WebRemoteFrameImpl::uniqueName() const
91 WebString
WebRemoteFrameImpl::assignedName() const
97 void WebRemoteFrameImpl::setName(const WebString
&)
102 WebVector
<WebIconURL
> WebRemoteFrameImpl::iconURLs(int iconTypesMask
) const
104 ASSERT_NOT_REACHED();
105 return WebVector
<WebIconURL
>();
108 void WebRemoteFrameImpl::setRemoteWebLayer(WebLayer
* webLayer
)
113 frame()->setRemotePlatformLayer(webLayer
);
116 void WebRemoteFrameImpl::setSharedWorkerRepositoryClient(WebSharedWorkerRepositoryClient
*)
118 ASSERT_NOT_REACHED();
121 void WebRemoteFrameImpl::setCanHaveScrollbars(bool)
123 ASSERT_NOT_REACHED();
126 WebSize
WebRemoteFrameImpl::scrollOffset() const
128 ASSERT_NOT_REACHED();
132 void WebRemoteFrameImpl::setScrollOffset(const WebSize
&)
134 ASSERT_NOT_REACHED();
137 WebSize
WebRemoteFrameImpl::contentsSize() const
139 ASSERT_NOT_REACHED();
143 bool WebRemoteFrameImpl::hasVisibleContent() const
145 ASSERT_NOT_REACHED();
149 WebRect
WebRemoteFrameImpl::visibleContentRect() const
151 ASSERT_NOT_REACHED();
155 bool WebRemoteFrameImpl::hasHorizontalScrollbar() const
157 ASSERT_NOT_REACHED();
161 bool WebRemoteFrameImpl::hasVerticalScrollbar() const
163 ASSERT_NOT_REACHED();
167 WebView
* WebRemoteFrameImpl::view() const
171 return WebViewImpl::fromPage(frame()->page());
174 void WebRemoteFrameImpl::removeChild(WebFrame
* frame
)
176 WebFrame::removeChild(frame
);
177 m_ownersForChildren
.remove(frame
);
180 WebDocument
WebRemoteFrameImpl::document() const
182 // TODO(dcheng): this should also ASSERT_NOT_REACHED, but a lot of
183 // code tries to access the document of a remote frame at the moment.
184 return WebDocument();
187 WebPerformance
WebRemoteFrameImpl::performance() const
189 ASSERT_NOT_REACHED();
190 return WebPerformance();
193 bool WebRemoteFrameImpl::dispatchBeforeUnloadEvent()
195 ASSERT_NOT_REACHED();
199 void WebRemoteFrameImpl::dispatchUnloadEvent()
201 ASSERT_NOT_REACHED();
204 NPObject
* WebRemoteFrameImpl::windowObject() const
206 ASSERT_NOT_REACHED();
210 void WebRemoteFrameImpl::bindToWindowObject(const WebString
& name
, NPObject
*)
212 ASSERT_NOT_REACHED();
215 void WebRemoteFrameImpl::bindToWindowObject(const WebString
& name
, NPObject
*, void*)
217 ASSERT_NOT_REACHED();
220 void WebRemoteFrameImpl::executeScript(const WebScriptSource
&)
222 ASSERT_NOT_REACHED();
225 void WebRemoteFrameImpl::executeScriptInIsolatedWorld(
226 int worldID
, const WebScriptSource
* sources
, unsigned numSources
,
229 ASSERT_NOT_REACHED();
232 void WebRemoteFrameImpl::setIsolatedWorldSecurityOrigin(int worldID
, const WebSecurityOrigin
&)
234 ASSERT_NOT_REACHED();
237 void WebRemoteFrameImpl::setIsolatedWorldContentSecurityPolicy(int worldID
, const WebString
&)
239 ASSERT_NOT_REACHED();
242 void WebRemoteFrameImpl::addMessageToConsole(const WebConsoleMessage
&)
244 ASSERT_NOT_REACHED();
247 void WebRemoteFrameImpl::collectGarbage()
249 ASSERT_NOT_REACHED();
252 bool WebRemoteFrameImpl::checkIfRunInsecureContent(const WebURL
&) const
254 ASSERT_NOT_REACHED();
258 v8::Local
<v8::Value
> WebRemoteFrameImpl::executeScriptAndReturnValue(
259 const WebScriptSource
&)
261 ASSERT_NOT_REACHED();
262 return v8::Local
<v8::Value
>();
265 void WebRemoteFrameImpl::executeScriptInIsolatedWorld(
266 int worldID
, const WebScriptSource
* sourcesIn
, unsigned numSources
,
267 int extensionGroup
, WebVector
<v8::Local
<v8::Value
>>* results
)
269 ASSERT_NOT_REACHED();
272 v8::Local
<v8::Value
> WebRemoteFrameImpl::callFunctionEvenIfScriptDisabled(
273 v8::Local
<v8::Function
>,
274 v8::Local
<v8::Value
>,
276 v8::Local
<v8::Value
> argv
[])
278 ASSERT_NOT_REACHED();
279 return v8::Local
<v8::Value
>();
282 v8::Local
<v8::Context
> WebRemoteFrameImpl::mainWorldScriptContext() const
284 ASSERT_NOT_REACHED();
285 return v8::Local
<v8::Context
>();
288 v8::Local
<v8::Context
> WebRemoteFrameImpl::deprecatedMainWorldScriptContext() const
290 return toV8Context(frame(), DOMWrapperWorld::mainWorld());
293 void WebRemoteFrameImpl::reload(bool ignoreCache
)
295 ASSERT_NOT_REACHED();
298 void WebRemoteFrameImpl::reloadWithOverrideURL(const WebURL
& overrideUrl
, bool ignoreCache
)
300 ASSERT_NOT_REACHED();
303 void WebRemoteFrameImpl::loadRequest(const WebURLRequest
&)
305 ASSERT_NOT_REACHED();
308 void WebRemoteFrameImpl::loadHistoryItem(const WebHistoryItem
&, WebHistoryLoadType
, WebURLRequest::CachePolicy
)
310 ASSERT_NOT_REACHED();
313 void WebRemoteFrameImpl::loadData(
314 const WebData
&, const WebString
& mimeType
, const WebString
& textEncoding
,
315 const WebURL
& baseURL
, const WebURL
& unreachableURL
, bool replace
)
317 ASSERT_NOT_REACHED();
320 void WebRemoteFrameImpl::loadHTMLString(
321 const WebData
& html
, const WebURL
& baseURL
, const WebURL
& unreachableURL
,
324 ASSERT_NOT_REACHED();
327 void WebRemoteFrameImpl::stopLoading()
329 // TODO(dcheng,japhet): Calling this method should stop loads
330 // in all subframes, both remote and local.
333 WebDataSource
* WebRemoteFrameImpl::provisionalDataSource() const
335 ASSERT_NOT_REACHED();
339 WebDataSource
* WebRemoteFrameImpl::dataSource() const
341 ASSERT_NOT_REACHED();
345 void WebRemoteFrameImpl::enableViewSourceMode(bool enable
)
347 ASSERT_NOT_REACHED();
350 bool WebRemoteFrameImpl::isViewSourceModeEnabled() const
352 ASSERT_NOT_REACHED();
356 void WebRemoteFrameImpl::setReferrerForRequest(WebURLRequest
&, const WebURL
& referrer
)
358 ASSERT_NOT_REACHED();
361 void WebRemoteFrameImpl::dispatchWillSendRequest(WebURLRequest
&)
363 ASSERT_NOT_REACHED();
366 WebURLLoader
* WebRemoteFrameImpl::createAssociatedURLLoader(const WebURLLoaderOptions
&)
368 ASSERT_NOT_REACHED();
372 unsigned WebRemoteFrameImpl::unloadListenerCount() const
374 ASSERT_NOT_REACHED();
378 void WebRemoteFrameImpl::replaceSelection(const WebString
&)
380 ASSERT_NOT_REACHED();
383 void WebRemoteFrameImpl::insertText(const WebString
&)
385 ASSERT_NOT_REACHED();
388 void WebRemoteFrameImpl::setMarkedText(const WebString
&, unsigned location
, unsigned length
)
390 ASSERT_NOT_REACHED();
393 void WebRemoteFrameImpl::unmarkText()
395 ASSERT_NOT_REACHED();
398 bool WebRemoteFrameImpl::hasMarkedText() const
400 ASSERT_NOT_REACHED();
404 WebRange
WebRemoteFrameImpl::markedRange() const
406 ASSERT_NOT_REACHED();
410 bool WebRemoteFrameImpl::firstRectForCharacterRange(unsigned location
, unsigned length
, WebRect
&) const
412 ASSERT_NOT_REACHED();
416 size_t WebRemoteFrameImpl::characterIndexForPoint(const WebPoint
&) const
418 ASSERT_NOT_REACHED();
422 bool WebRemoteFrameImpl::executeCommand(const WebString
&, const WebNode
&)
424 ASSERT_NOT_REACHED();
428 bool WebRemoteFrameImpl::executeCommand(const WebString
&, const WebString
& value
, const WebNode
&)
430 ASSERT_NOT_REACHED();
434 bool WebRemoteFrameImpl::isCommandEnabled(const WebString
&) const
436 ASSERT_NOT_REACHED();
440 void WebRemoteFrameImpl::enableContinuousSpellChecking(bool)
444 bool WebRemoteFrameImpl::isContinuousSpellCheckingEnabled() const
449 void WebRemoteFrameImpl::requestTextChecking(const WebElement
&)
451 ASSERT_NOT_REACHED();
454 void WebRemoteFrameImpl::replaceMisspelledRange(const WebString
&)
456 ASSERT_NOT_REACHED();
459 void WebRemoteFrameImpl::removeSpellingMarkers()
461 ASSERT_NOT_REACHED();
464 bool WebRemoteFrameImpl::hasSelection() const
466 ASSERT_NOT_REACHED();
470 WebRange
WebRemoteFrameImpl::selectionRange() const
472 ASSERT_NOT_REACHED();
476 WebString
WebRemoteFrameImpl::selectionAsText() const
478 ASSERT_NOT_REACHED();
482 WebString
WebRemoteFrameImpl::selectionAsMarkup() const
484 ASSERT_NOT_REACHED();
488 bool WebRemoteFrameImpl::selectWordAroundCaret()
490 ASSERT_NOT_REACHED();
494 void WebRemoteFrameImpl::selectRange(const WebPoint
& base
, const WebPoint
& extent
)
496 ASSERT_NOT_REACHED();
499 void WebRemoteFrameImpl::selectRange(const WebRange
&)
501 ASSERT_NOT_REACHED();
504 void WebRemoteFrameImpl::moveRangeSelection(const WebPoint
& base
, const WebPoint
& extent
, WebFrame::TextGranularity granularity
)
506 ASSERT_NOT_REACHED();
509 void WebRemoteFrameImpl::moveCaretSelection(const WebPoint
&)
511 ASSERT_NOT_REACHED();
514 bool WebRemoteFrameImpl::setEditableSelectionOffsets(int start
, int end
)
516 ASSERT_NOT_REACHED();
520 bool WebRemoteFrameImpl::setCompositionFromExistingText(int compositionStart
, int compositionEnd
, const WebVector
<WebCompositionUnderline
>& underlines
)
522 ASSERT_NOT_REACHED();
526 void WebRemoteFrameImpl::extendSelectionAndDelete(int before
, int after
)
528 ASSERT_NOT_REACHED();
531 void WebRemoteFrameImpl::setCaretVisible(bool)
533 ASSERT_NOT_REACHED();
536 int WebRemoteFrameImpl::printBegin(const WebPrintParams
&, const WebNode
& constrainToNode
)
538 ASSERT_NOT_REACHED();
542 float WebRemoteFrameImpl::printPage(int pageToPrint
, WebCanvas
*)
544 ASSERT_NOT_REACHED();
548 float WebRemoteFrameImpl::getPrintPageShrink(int page
)
550 ASSERT_NOT_REACHED();
554 void WebRemoteFrameImpl::printEnd()
556 ASSERT_NOT_REACHED();
559 bool WebRemoteFrameImpl::isPrintScalingDisabledForPlugin(const WebNode
&)
561 ASSERT_NOT_REACHED();
565 bool WebRemoteFrameImpl::hasCustomPageSizeStyle(int pageIndex
)
567 ASSERT_NOT_REACHED();
571 bool WebRemoteFrameImpl::isPageBoxVisible(int pageIndex
)
573 ASSERT_NOT_REACHED();
577 void WebRemoteFrameImpl::pageSizeAndMarginsInPixels(
585 ASSERT_NOT_REACHED();
588 WebString
WebRemoteFrameImpl::pageProperty(const WebString
& propertyName
, int pageIndex
)
590 ASSERT_NOT_REACHED();
594 void WebRemoteFrameImpl::printPagesWithBoundaries(WebCanvas
*, const WebSize
&)
596 ASSERT_NOT_REACHED();
599 bool WebRemoteFrameImpl::find(
600 int identifier
, const WebString
& searchText
, const WebFindOptions
&,
601 bool wrapWithinFrame
, WebRect
* selectionRect
)
603 ASSERT_NOT_REACHED();
607 void WebRemoteFrameImpl::stopFinding(bool clearSelection
)
609 ASSERT_NOT_REACHED();
612 void WebRemoteFrameImpl::scopeStringMatches(
613 int identifier
, const WebString
& searchText
, const WebFindOptions
&,
616 ASSERT_NOT_REACHED();
619 void WebRemoteFrameImpl::cancelPendingScopingEffort()
621 ASSERT_NOT_REACHED();
624 void WebRemoteFrameImpl::increaseMatchCount(int count
, int identifier
)
626 ASSERT_NOT_REACHED();
629 void WebRemoteFrameImpl::resetMatchCount()
631 ASSERT_NOT_REACHED();
634 int WebRemoteFrameImpl::findMatchMarkersVersion() const
636 ASSERT_NOT_REACHED();
640 WebFloatRect
WebRemoteFrameImpl::activeFindMatchRect()
642 ASSERT_NOT_REACHED();
643 return WebFloatRect();
646 void WebRemoteFrameImpl::findMatchRects(WebVector
<WebFloatRect
>&)
648 ASSERT_NOT_REACHED();
651 int WebRemoteFrameImpl::selectNearestFindMatch(const WebFloatPoint
&, WebRect
* selectionRect
)
653 ASSERT_NOT_REACHED();
657 void WebRemoteFrameImpl::setTickmarks(const WebVector
<WebRect
>&)
659 ASSERT_NOT_REACHED();
662 void WebRemoteFrameImpl::dispatchMessageEventWithOriginCheck(
663 const WebSecurityOrigin
& intendedTargetOrigin
,
666 ASSERT_NOT_REACHED();
669 WebString
WebRemoteFrameImpl::contentAsText(size_t maxChars
) const
671 ASSERT_NOT_REACHED();
675 WebString
WebRemoteFrameImpl::contentAsMarkup() const
677 ASSERT_NOT_REACHED();
681 WebString
WebRemoteFrameImpl::layoutTreeAsText(LayoutAsTextControls toShow
) const
683 ASSERT_NOT_REACHED();
687 WebString
WebRemoteFrameImpl::markerTextForListItem(const WebElement
&) const
689 ASSERT_NOT_REACHED();
693 WebRect
WebRemoteFrameImpl::selectionBoundsRect() const
695 ASSERT_NOT_REACHED();
699 bool WebRemoteFrameImpl::selectionStartHasSpellingMarkerFor(int from
, int length
) const
701 ASSERT_NOT_REACHED();
705 WebString
WebRemoteFrameImpl::layerTreeAsText(bool showDebugInfo
) const
707 ASSERT_NOT_REACHED();
711 WebLocalFrame
* WebRemoteFrameImpl::createLocalChild(WebTreeScopeType scope
, const WebString
& name
, WebSandboxFlags sandboxFlags
, WebFrameClient
* client
, WebFrame
* previousSibling
)
713 WebLocalFrameImpl
* child
= toWebLocalFrameImpl(WebLocalFrame::create(scope
, client
));
714 WillBeHeapHashMap
<WebFrame
*, OwnPtrWillBeMember
<FrameOwner
>>::AddResult result
=
715 m_ownersForChildren
.add(child
, RemoteBridgeFrameOwner::create(child
, static_cast<SandboxFlags
>(sandboxFlags
)));
716 insertAfter(child
, previousSibling
);
717 // FIXME: currently this calls LocalFrame::init() on the created LocalFrame, which may
718 // result in the browser observing two navigations to about:blank (one from the initial
719 // frame creation, and one from swapping it into the remote process). FrameLoader might
720 // need a special initialization function for this case to avoid that duplicate navigation.
721 child
->initializeCoreFrame(frame()->host(), result
.storedValue
->value
.get(), name
, nullAtom
);
722 // Partially related with the above FIXME--the init() call may trigger JS dispatch. However,
723 // if the parent is remote, it should never be detached synchronously...
724 ASSERT(child
->frame());
729 void WebRemoteFrameImpl::initializeCoreFrame(FrameHost
* host
, FrameOwner
* owner
, const AtomicString
& name
)
731 setCoreFrame(RemoteFrame::create(m_frameClient
.get(), host
, owner
));
732 frame()->createView();
733 m_frame
->tree().setName(name
, nullAtom
);
736 WebRemoteFrame
* WebRemoteFrameImpl::createRemoteChild(WebTreeScopeType scope
, const WebString
& name
, WebSandboxFlags sandboxFlags
, WebRemoteFrameClient
* client
)
738 WebRemoteFrameImpl
* child
= toWebRemoteFrameImpl(WebRemoteFrame::create(scope
, client
));
739 WillBeHeapHashMap
<WebFrame
*, OwnPtrWillBeMember
<FrameOwner
>>::AddResult result
=
740 m_ownersForChildren
.add(child
, RemoteBridgeFrameOwner::create(nullptr, static_cast<SandboxFlags
>(sandboxFlags
)));
742 child
->initializeCoreFrame(frame()->host(), result
.storedValue
->value
.get(), name
);
746 void WebRemoteFrameImpl::setCoreFrame(PassRefPtrWillBeRawPtr
<RemoteFrame
> frame
)
751 WebRemoteFrameImpl
* WebRemoteFrameImpl::fromFrame(RemoteFrame
& frame
)
755 return static_cast<RemoteFrameClientImpl
*>(frame
.client())->webFrame();
758 void WebRemoteFrameImpl::initializeFromFrame(WebLocalFrame
* source
) const
761 WebLocalFrameImpl
* localFrameImpl
= toWebLocalFrameImpl(source
);
763 client()->initializeChildFrame(
764 localFrameImpl
->frame()->view()->frameRect(),
765 localFrameImpl
->frame()->page()->deviceScaleFactor());
768 void WebRemoteFrameImpl::setReplicatedOrigin(const WebSecurityOrigin
& origin
) const
771 frame()->securityContext()->setReplicatedOrigin(origin
);
774 void WebRemoteFrameImpl::setReplicatedSandboxFlags(WebSandboxFlags flags
) const
777 frame()->securityContext()->enforceSandboxFlags(static_cast<SandboxFlags
>(flags
));
780 void WebRemoteFrameImpl::setReplicatedName(const WebString
& name
) const
783 frame()->tree().setName(name
, nullAtom
);
786 void WebRemoteFrameImpl::DispatchLoadEventForFrameOwner() const
788 ASSERT(frame()->owner()->isLocal());
789 frame()->owner()->dispatchLoad();
792 void WebRemoteFrameImpl::didStartLoading()
794 frame()->setIsLoading(true);
797 void WebRemoteFrameImpl::didStopLoading()
799 frame()->setIsLoading(false);
800 if (parent() && parent()->isWebLocalFrame()) {
801 WebLocalFrameImpl
* parentFrame
=
802 toWebLocalFrameImpl(parent()->toWebLocalFrame());
803 parentFrame
->frame()->loader().checkCompleted();
807 WebRemoteFrameImpl::WebRemoteFrameImpl(WebTreeScopeType scope
, WebRemoteFrameClient
* client
)
808 : WebRemoteFrame(scope
)
809 , m_frameClient(RemoteFrameClientImpl::create(this))
812 , m_selfKeepAlive(this)