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/FrameOwner.h"
9 #include "core/frame/FrameView.h"
10 #include "core/frame/RemoteFrame.h"
11 #include "core/frame/Settings.h"
12 #include "core/page/Page.h"
13 #include "platform/heap/Handle.h"
14 #include "public/platform/WebFloatRect.h"
15 #include "public/platform/WebRect.h"
16 #include "public/web/WebDocument.h"
17 #include "public/web/WebPerformance.h"
18 #include "public/web/WebRange.h"
19 #include "web/WebLocalFrameImpl.h"
20 #include "web/WebViewImpl.h"
21 #include <v8/include/v8.h>
27 // Helper class to bridge communication for a local frame with a remote parent.
28 // Currently, it serves two purposes:
29 // 1. Allows the local frame's loader to retrieve sandbox flags associated with
30 // its owner element in another process.
31 // 2. Trigger a load event on its owner element once it finishes a load.
32 class RemoteBridgeFrameOwner : public NoBaseWillBeGarbageCollectedFinalized<RemoteBridgeFrameOwner>, public FrameOwner {
33 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(RemoteBridgeFrameOwner);
35 static PassOwnPtrWillBeRawPtr<RemoteBridgeFrameOwner> create(PassRefPtrWillBeRawPtr<WebLocalFrameImpl> frame)
37 return adoptPtrWillBeNoop(new RemoteBridgeFrameOwner(frame));
40 virtual bool isLocal() const OVERRIDE;
41 virtual SandboxFlags sandboxFlags() const OVERRIDE;
42 virtual void dispatchLoad() OVERRIDE;
44 virtual void trace(Visitor*);
47 explicit RemoteBridgeFrameOwner(PassRefPtrWillBeRawPtr<WebLocalFrameImpl>);
49 RefPtrWillBeMember<WebLocalFrameImpl> m_frame;
52 RemoteBridgeFrameOwner::RemoteBridgeFrameOwner(PassRefPtrWillBeRawPtr<WebLocalFrameImpl> frame)
57 void RemoteBridgeFrameOwner::trace(Visitor* visitor)
59 visitor->trace(m_frame);
60 FrameOwner::trace(visitor);
63 bool RemoteBridgeFrameOwner::isLocal() const
68 SandboxFlags RemoteBridgeFrameOwner::sandboxFlags() const
70 // FIXME: Implement. Most likely grab it from m_frame.
74 void RemoteBridgeFrameOwner::dispatchLoad()
76 // FIXME: Implement. Most likely goes through m_frame->client().
79 // FIXME: This is just a placeholder frame owner to supply to RemoteFrame when
80 // the parent is also a remote frame. Strictly speaking, this shouldn't be
81 // necessary, since a remote frame shouldn't ever need to communicate with a
82 // remote parent (there are no sandbox flags to retrieve in this case, nor can
83 // the RemoteFrame itself load a document). In most circumstances, the check for
84 // frame->owner() can be replaced with a check for frame->tree().parent(). Once
85 // that's done, this class can be removed.
86 class PlaceholderFrameOwner : public NoBaseWillBeGarbageCollectedFinalized<PlaceholderFrameOwner>, public FrameOwner {
87 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(PlaceholderFrameOwner);
89 virtual bool isLocal() const OVERRIDE;
90 virtual SandboxFlags sandboxFlags() const OVERRIDE;
91 virtual void dispatchLoad() OVERRIDE;
94 bool PlaceholderFrameOwner::isLocal() const
99 SandboxFlags PlaceholderFrameOwner::sandboxFlags() const
101 ASSERT_NOT_REACHED();
105 void PlaceholderFrameOwner::dispatchLoad()
107 ASSERT_NOT_REACHED();
112 WebRemoteFrame* WebRemoteFrame::create(WebRemoteFrameClient* client)
114 WebRemoteFrameImpl* frame = new WebRemoteFrameImpl(client);
118 return adoptRef(frame).leakRef();
122 WebRemoteFrameImpl::WebRemoteFrameImpl(WebRemoteFrameClient* client)
123 : m_frameClient(this)
126 , m_selfKeepAlive(this)
131 WebRemoteFrameImpl::~WebRemoteFrameImpl()
135 void WebRemoteFrameImpl::trace(Visitor* visitor)
138 visitor->trace(m_frame);
139 visitor->trace(m_ownersForChildren);
141 WebFrame::traceChildren(visitor, this);
145 bool WebRemoteFrameImpl::isWebLocalFrame() const
150 WebLocalFrame* WebRemoteFrameImpl::toWebLocalFrame()
152 ASSERT_NOT_REACHED();
156 bool WebRemoteFrameImpl::isWebRemoteFrame() const
161 WebRemoteFrame* WebRemoteFrameImpl::toWebRemoteFrame()
166 void WebRemoteFrameImpl::close()
169 m_selfKeepAlive.clear();
175 WebString WebRemoteFrameImpl::uniqueName() const
177 ASSERT_NOT_REACHED();
181 WebString WebRemoteFrameImpl::assignedName() const
183 ASSERT_NOT_REACHED();
187 void WebRemoteFrameImpl::setName(const WebString&)
189 ASSERT_NOT_REACHED();
192 WebVector<WebIconURL> WebRemoteFrameImpl::iconURLs(int iconTypesMask) const
194 ASSERT_NOT_REACHED();
195 return WebVector<WebIconURL>();
198 void WebRemoteFrameImpl::setIsRemote(bool)
200 ASSERT_NOT_REACHED();
203 void WebRemoteFrameImpl::setRemoteWebLayer(WebLayer* webLayer)
208 frame()->setRemotePlatformLayer(webLayer);
211 void WebRemoteFrameImpl::setPermissionClient(WebPermissionClient*)
213 ASSERT_NOT_REACHED();
216 void WebRemoteFrameImpl::setSharedWorkerRepositoryClient(WebSharedWorkerRepositoryClient*)
218 ASSERT_NOT_REACHED();
221 void WebRemoteFrameImpl::setCanHaveScrollbars(bool)
223 ASSERT_NOT_REACHED();
226 WebSize WebRemoteFrameImpl::scrollOffset() const
228 ASSERT_NOT_REACHED();
232 void WebRemoteFrameImpl::setScrollOffset(const WebSize&)
234 ASSERT_NOT_REACHED();
237 WebSize WebRemoteFrameImpl::minimumScrollOffset() const
239 ASSERT_NOT_REACHED();
243 WebSize WebRemoteFrameImpl::maximumScrollOffset() const
245 ASSERT_NOT_REACHED();
249 WebSize WebRemoteFrameImpl::contentsSize() const
251 ASSERT_NOT_REACHED();
255 bool WebRemoteFrameImpl::hasVisibleContent() const
257 ASSERT_NOT_REACHED();
261 WebRect WebRemoteFrameImpl::visibleContentRect() const
263 ASSERT_NOT_REACHED();
267 bool WebRemoteFrameImpl::hasHorizontalScrollbar() const
269 ASSERT_NOT_REACHED();
273 bool WebRemoteFrameImpl::hasVerticalScrollbar() const
275 ASSERT_NOT_REACHED();
279 WebView* WebRemoteFrameImpl::view() const
283 return WebViewImpl::fromPage(frame()->page());
286 WebViewImpl* WebRemoteFrameImpl::viewImpl() const
290 return WebViewImpl::fromPage(frame()->page());
293 void WebRemoteFrameImpl::removeChild(WebFrame* frame)
295 WebFrame::removeChild(frame);
296 m_ownersForChildren.remove(frame);
299 WebDocument WebRemoteFrameImpl::document() const
301 return WebDocument();
304 WebPerformance WebRemoteFrameImpl::performance() const
306 ASSERT_NOT_REACHED();
307 return WebPerformance();
310 bool WebRemoteFrameImpl::dispatchBeforeUnloadEvent()
312 ASSERT_NOT_REACHED();
316 void WebRemoteFrameImpl::dispatchUnloadEvent()
318 ASSERT_NOT_REACHED();
321 NPObject* WebRemoteFrameImpl::windowObject() const
323 ASSERT_NOT_REACHED();
327 void WebRemoteFrameImpl::bindToWindowObject(const WebString& name, NPObject*)
329 ASSERT_NOT_REACHED();
332 void WebRemoteFrameImpl::bindToWindowObject(const WebString& name, NPObject*, void*)
334 ASSERT_NOT_REACHED();
337 void WebRemoteFrameImpl::executeScript(const WebScriptSource&)
339 ASSERT_NOT_REACHED();
342 void WebRemoteFrameImpl::executeScriptInIsolatedWorld(
343 int worldID, const WebScriptSource* sources, unsigned numSources,
346 ASSERT_NOT_REACHED();
349 void WebRemoteFrameImpl::setIsolatedWorldSecurityOrigin(int worldID, const WebSecurityOrigin&)
351 ASSERT_NOT_REACHED();
354 void WebRemoteFrameImpl::setIsolatedWorldContentSecurityPolicy(int worldID, const WebString&)
356 ASSERT_NOT_REACHED();
359 void WebRemoteFrameImpl::addMessageToConsole(const WebConsoleMessage&)
361 ASSERT_NOT_REACHED();
364 void WebRemoteFrameImpl::collectGarbage()
366 ASSERT_NOT_REACHED();
369 bool WebRemoteFrameImpl::checkIfRunInsecureContent(const WebURL&) const
371 ASSERT_NOT_REACHED();
375 v8::Handle<v8::Value> WebRemoteFrameImpl::executeScriptAndReturnValue(
376 const WebScriptSource&)
378 ASSERT_NOT_REACHED();
379 return v8::Handle<v8::Value>();
382 void WebRemoteFrameImpl::executeScriptInIsolatedWorld(
383 int worldID, const WebScriptSource* sourcesIn, unsigned numSources,
384 int extensionGroup, WebVector<v8::Local<v8::Value> >* results)
386 ASSERT_NOT_REACHED();
389 v8::Handle<v8::Value> WebRemoteFrameImpl::callFunctionEvenIfScriptDisabled(
390 v8::Handle<v8::Function>,
391 v8::Handle<v8::Value>,
393 v8::Handle<v8::Value> argv[])
395 ASSERT_NOT_REACHED();
396 return v8::Handle<v8::Value>();
399 v8::Local<v8::Context> WebRemoteFrameImpl::mainWorldScriptContext() const
401 ASSERT_NOT_REACHED();
402 return v8::Local<v8::Context>();
405 void WebRemoteFrameImpl::reload(bool ignoreCache)
407 ASSERT_NOT_REACHED();
410 void WebRemoteFrameImpl::reloadWithOverrideURL(const WebURL& overrideUrl, bool ignoreCache)
412 ASSERT_NOT_REACHED();
415 void WebRemoteFrameImpl::loadRequest(const WebURLRequest&)
417 ASSERT_NOT_REACHED();
420 void WebRemoteFrameImpl::loadHistoryItem(const WebHistoryItem&, WebHistoryLoadType, WebURLRequest::CachePolicy)
422 ASSERT_NOT_REACHED();
425 void WebRemoteFrameImpl::loadData(
426 const WebData&, const WebString& mimeType, const WebString& textEncoding,
427 const WebURL& baseURL, const WebURL& unreachableURL, bool replace)
429 ASSERT_NOT_REACHED();
432 void WebRemoteFrameImpl::loadHTMLString(
433 const WebData& html, const WebURL& baseURL, const WebURL& unreachableURL,
436 ASSERT_NOT_REACHED();
439 void WebRemoteFrameImpl::stopLoading()
441 ASSERT_NOT_REACHED();
444 WebDataSource* WebRemoteFrameImpl::provisionalDataSource() const
446 ASSERT_NOT_REACHED();
450 WebDataSource* WebRemoteFrameImpl::dataSource() const
452 ASSERT_NOT_REACHED();
456 void WebRemoteFrameImpl::enableViewSourceMode(bool enable)
458 ASSERT_NOT_REACHED();
461 bool WebRemoteFrameImpl::isViewSourceModeEnabled() const
463 ASSERT_NOT_REACHED();
467 void WebRemoteFrameImpl::setReferrerForRequest(WebURLRequest&, const WebURL& referrer)
469 ASSERT_NOT_REACHED();
472 void WebRemoteFrameImpl::dispatchWillSendRequest(WebURLRequest&)
474 ASSERT_NOT_REACHED();
477 WebURLLoader* WebRemoteFrameImpl::createAssociatedURLLoader(const WebURLLoaderOptions&)
479 ASSERT_NOT_REACHED();
483 unsigned WebRemoteFrameImpl::unloadListenerCount() const
485 ASSERT_NOT_REACHED();
489 void WebRemoteFrameImpl::replaceSelection(const WebString&)
491 ASSERT_NOT_REACHED();
494 void WebRemoteFrameImpl::insertText(const WebString&)
496 ASSERT_NOT_REACHED();
499 void WebRemoteFrameImpl::setMarkedText(const WebString&, unsigned location, unsigned length)
501 ASSERT_NOT_REACHED();
504 void WebRemoteFrameImpl::unmarkText()
506 ASSERT_NOT_REACHED();
509 bool WebRemoteFrameImpl::hasMarkedText() const
511 ASSERT_NOT_REACHED();
515 WebRange WebRemoteFrameImpl::markedRange() const
517 ASSERT_NOT_REACHED();
521 bool WebRemoteFrameImpl::firstRectForCharacterRange(unsigned location, unsigned length, WebRect&) const
523 ASSERT_NOT_REACHED();
527 size_t WebRemoteFrameImpl::characterIndexForPoint(const WebPoint&) const
529 ASSERT_NOT_REACHED();
533 bool WebRemoteFrameImpl::executeCommand(const WebString&, const WebNode&)
535 ASSERT_NOT_REACHED();
539 bool WebRemoteFrameImpl::executeCommand(const WebString&, const WebString& value, const WebNode&)
541 ASSERT_NOT_REACHED();
545 bool WebRemoteFrameImpl::isCommandEnabled(const WebString&) const
547 ASSERT_NOT_REACHED();
551 void WebRemoteFrameImpl::enableContinuousSpellChecking(bool)
555 bool WebRemoteFrameImpl::isContinuousSpellCheckingEnabled() const
560 void WebRemoteFrameImpl::requestTextChecking(const WebElement&)
562 ASSERT_NOT_REACHED();
565 void WebRemoteFrameImpl::replaceMisspelledRange(const WebString&)
567 ASSERT_NOT_REACHED();
570 void WebRemoteFrameImpl::removeSpellingMarkers()
572 ASSERT_NOT_REACHED();
575 bool WebRemoteFrameImpl::hasSelection() const
577 ASSERT_NOT_REACHED();
581 WebRange WebRemoteFrameImpl::selectionRange() const
583 ASSERT_NOT_REACHED();
587 WebString WebRemoteFrameImpl::selectionAsText() const
589 ASSERT_NOT_REACHED();
593 WebString WebRemoteFrameImpl::selectionAsMarkup() const
595 ASSERT_NOT_REACHED();
599 bool WebRemoteFrameImpl::selectWordAroundCaret()
601 ASSERT_NOT_REACHED();
605 void WebRemoteFrameImpl::selectRange(const WebPoint& base, const WebPoint& extent)
607 ASSERT_NOT_REACHED();
610 void WebRemoteFrameImpl::selectRange(const WebRange&)
612 ASSERT_NOT_REACHED();
615 void WebRemoteFrameImpl::moveRangeSelection(const WebPoint& base, const WebPoint& extent)
617 ASSERT_NOT_REACHED();
620 void WebRemoteFrameImpl::moveCaretSelection(const WebPoint&)
622 ASSERT_NOT_REACHED();
625 bool WebRemoteFrameImpl::setEditableSelectionOffsets(int start, int end)
627 ASSERT_NOT_REACHED();
631 bool WebRemoteFrameImpl::setCompositionFromExistingText(int compositionStart, int compositionEnd, const WebVector<WebCompositionUnderline>& underlines)
633 ASSERT_NOT_REACHED();
637 void WebRemoteFrameImpl::extendSelectionAndDelete(int before, int after)
639 ASSERT_NOT_REACHED();
642 void WebRemoteFrameImpl::setCaretVisible(bool)
644 ASSERT_NOT_REACHED();
647 int WebRemoteFrameImpl::printBegin(const WebPrintParams&, const WebNode& constrainToNode)
649 ASSERT_NOT_REACHED();
653 float WebRemoteFrameImpl::printPage(int pageToPrint, WebCanvas*)
655 ASSERT_NOT_REACHED();
659 float WebRemoteFrameImpl::getPrintPageShrink(int page)
661 ASSERT_NOT_REACHED();
665 void WebRemoteFrameImpl::printEnd()
667 ASSERT_NOT_REACHED();
670 bool WebRemoteFrameImpl::isPrintScalingDisabledForPlugin(const WebNode&)
672 ASSERT_NOT_REACHED();
676 int WebRemoteFrameImpl::getPrintCopiesForPlugin(const WebNode&)
678 ASSERT_NOT_REACHED();
682 bool WebRemoteFrameImpl::hasCustomPageSizeStyle(int pageIndex)
684 ASSERT_NOT_REACHED();
688 bool WebRemoteFrameImpl::isPageBoxVisible(int pageIndex)
690 ASSERT_NOT_REACHED();
694 void WebRemoteFrameImpl::pageSizeAndMarginsInPixels(
702 ASSERT_NOT_REACHED();
705 WebString WebRemoteFrameImpl::pageProperty(const WebString& propertyName, int pageIndex)
707 ASSERT_NOT_REACHED();
711 void WebRemoteFrameImpl::printPagesWithBoundaries(WebCanvas*, const WebSize&)
713 ASSERT_NOT_REACHED();
716 bool WebRemoteFrameImpl::find(
717 int identifier, const WebString& searchText, const WebFindOptions&,
718 bool wrapWithinFrame, WebRect* selectionRect)
720 ASSERT_NOT_REACHED();
724 void WebRemoteFrameImpl::stopFinding(bool clearSelection)
726 ASSERT_NOT_REACHED();
729 void WebRemoteFrameImpl::scopeStringMatches(
730 int identifier, const WebString& searchText, const WebFindOptions&,
733 ASSERT_NOT_REACHED();
736 void WebRemoteFrameImpl::cancelPendingScopingEffort()
738 ASSERT_NOT_REACHED();
741 void WebRemoteFrameImpl::increaseMatchCount(int count, int identifier)
743 ASSERT_NOT_REACHED();
746 void WebRemoteFrameImpl::resetMatchCount()
748 ASSERT_NOT_REACHED();
751 int WebRemoteFrameImpl::findMatchMarkersVersion() const
753 ASSERT_NOT_REACHED();
757 WebFloatRect WebRemoteFrameImpl::activeFindMatchRect()
759 ASSERT_NOT_REACHED();
760 return WebFloatRect();
763 void WebRemoteFrameImpl::findMatchRects(WebVector<WebFloatRect>&)
765 ASSERT_NOT_REACHED();
768 int WebRemoteFrameImpl::selectNearestFindMatch(const WebFloatPoint&, WebRect* selectionRect)
770 ASSERT_NOT_REACHED();
774 void WebRemoteFrameImpl::setTickmarks(const WebVector<WebRect>&)
776 ASSERT_NOT_REACHED();
779 void WebRemoteFrameImpl::dispatchMessageEventWithOriginCheck(
780 const WebSecurityOrigin& intendedTargetOrigin,
783 ASSERT_NOT_REACHED();
786 WebString WebRemoteFrameImpl::contentAsText(size_t maxChars) const
788 ASSERT_NOT_REACHED();
792 WebString WebRemoteFrameImpl::contentAsMarkup() const
794 ASSERT_NOT_REACHED();
798 WebString WebRemoteFrameImpl::renderTreeAsText(RenderAsTextControls toShow) const
800 ASSERT_NOT_REACHED();
804 WebString WebRemoteFrameImpl::markerTextForListItem(const WebElement&) const
806 ASSERT_NOT_REACHED();
810 WebRect WebRemoteFrameImpl::selectionBoundsRect() const
812 ASSERT_NOT_REACHED();
816 bool WebRemoteFrameImpl::selectionStartHasSpellingMarkerFor(int from, int length) const
818 ASSERT_NOT_REACHED();
822 WebString WebRemoteFrameImpl::layerTreeAsText(bool showDebugInfo) const
824 ASSERT_NOT_REACHED();
828 WebLocalFrame* WebRemoteFrameImpl::createLocalChild(const WebString& name, WebFrameClient* client)
830 WebLocalFrameImpl* child = toWebLocalFrameImpl(WebLocalFrame::create(client));
831 WillBeHeapHashMap<WebFrame*, OwnPtrWillBeMember<FrameOwner> >::AddResult result =
832 m_ownersForChildren.add(child, RemoteBridgeFrameOwner::create(child));
834 // FIXME: currently this calls LocalFrame::init() on the created LocalFrame, which may
835 // result in the browser observing two navigations to about:blank (one from the initial
836 // frame creation, and one from swapping it into the remote process). FrameLoader might
837 // need a special initialization function for this case to avoid that duplicate navigation.
838 child->initializeCoreFrame(frame()->host(), result.storedValue->value.get(), name, nullAtom);
839 // Partially related with the above FIXME--the init() call may trigger JS dispatch. However,
840 // if the parent is remote, it should never be detached synchronously...
841 ASSERT(child->frame());
845 void WebRemoteFrameImpl::initializeCoreFrame(FrameHost* host, FrameOwner* owner, const AtomicString& name)
847 setCoreFrame(RemoteFrame::create(&m_frameClient, host, owner));
848 m_frame->tree().setName(name, nullAtom);
851 WebRemoteFrame* WebRemoteFrameImpl::createRemoteChild(const WebString& name, WebRemoteFrameClient* client)
853 WebRemoteFrameImpl* child = toWebRemoteFrameImpl(WebRemoteFrame::create(client));
854 WillBeHeapHashMap<WebFrame*, OwnPtrWillBeMember<FrameOwner> >::AddResult result =
855 m_ownersForChildren.add(child, adoptPtrWillBeNoop(new PlaceholderFrameOwner));
857 child->initializeCoreFrame(frame()->host(), result.storedValue->value.get(), name);
861 void WebRemoteFrameImpl::setCoreFrame(PassRefPtrWillBeRawPtr<RemoteFrame> frame)
866 WebRemoteFrameImpl* WebRemoteFrameImpl::fromFrame(RemoteFrame& frame)
870 return static_cast<RemoteFrameClient*>(frame.client())->webFrame();
873 void WebRemoteFrameImpl::initializeFromFrame(WebLocalFrame* source) const
876 WebLocalFrameImpl* localFrameImpl = toWebLocalFrameImpl(source);
877 client()->initializeChildFrame(
878 localFrameImpl->frame()->view()->frameRect(),
879 localFrameImpl->frame()->view()->visibleContentScaleFactor());