/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */ /* vim: set sw=2 sts=2 ts=8 et tw=80 : */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "base/basictypes.h" #include "TabChild.h" #include "Layers.h" #include "ContentChild.h" #include "IndexedDBChild.h" #include "mozilla/Preferences.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/IntentionalCrash.h" #include "mozilla/docshell/OfflineCacheUpdateChild.h" #include "mozilla/dom/PContentDialogChild.h" #include "mozilla/ipc/DocumentRendererChild.h" #include "mozilla/ipc/FileDescriptorUtils.h" #include "mozilla/layers/AsyncPanZoomController.h" #include "mozilla/layers/CompositorChild.h" #include "mozilla/layers/ImageBridgeChild.h" #include "mozilla/layers/ShadowLayers.h" #include "mozilla/layout/RenderFrameChild.h" #include "mozilla/MouseEvents.h" #include "mozilla/Services.h" #include "mozilla/StaticPtr.h" #include "mozilla/TextEvents.h" #include "mozilla/TouchEvents.h" #include "mozilla/unused.h" #include "mozIApplication.h" #include "nsContentUtils.h" #include "nsCxPusher.h" #include "nsEmbedCID.h" #include "nsEventListenerManager.h" #include #ifdef MOZ_CRASHREPORTER #include "nsExceptionHandler.h" #endif #include "mozilla/dom/Element.h" #include "nsIBaseWindow.h" #include "nsICachedFileDescriptorListener.h" #include "nsIDialogParamBlock.h" #include "nsIDocumentInlines.h" #include "nsIDocShellTreeOwner.h" #include "nsIDOMEvent.h" #include "nsIDOMWindow.h" #include "nsIDOMWindowUtils.h" #include "nsIDocShell.h" #include "nsIURI.h" #include "nsIURIFixup.h" #include "nsCDefaultURIFixup.h" #include "nsIWebBrowser.h" #include "nsIWebBrowserFocus.h" #include "nsIWebBrowserSetup.h" #include "nsIWebProgress.h" #include "nsInterfaceHashtable.h" #include "nsPIDOMWindow.h" #include "nsPIWindowRoot.h" #include "nsLayoutUtils.h" #include "nsPrintfCString.h" #include "nsThreadUtils.h" #include "nsWeakReference.h" #include "PermissionMessageUtils.h" #include "PCOMContentPermissionRequestChild.h" #include "PuppetWidget.h" #include "StructuredCloneUtils.h" #include "nsViewportInfo.h" #include "JavaScriptChild.h" #include "APZCCallbackHelper.h" #include "nsILoadContext.h" #include "ipc/nsGUIEventIPC.h" #ifdef DEBUG #include "PCOMContentPermissionRequestChild.h" #endif /* DEBUG */ #define BROWSER_ELEMENT_CHILD_SCRIPT \ NS_LITERAL_STRING("chrome://global/content/BrowserElementChild.js") using namespace mozilla; using namespace mozilla::dom; using namespace mozilla::dom::ipc; using namespace mozilla::ipc; using namespace mozilla::layers; using namespace mozilla::layout; using namespace mozilla::docshell; using namespace mozilla::dom::indexedDB; using namespace mozilla::widget; using namespace mozilla::jsipc; NS_IMPL_ISUPPORTS1(ContentListener, nsIDOMEventListener) static const CSSSize kDefaultViewportSize(980, 480); static const char BROWSER_ZOOM_TO_RECT[] = "browser-zoom-to-rect"; static const char BEFORE_FIRST_PAINT[] = "before-first-paint"; static bool sCpowsEnabled = false; NS_IMETHODIMP ContentListener::HandleEvent(nsIDOMEvent* aEvent) { RemoteDOMEvent remoteEvent; remoteEvent.mEvent = do_QueryInterface(aEvent); NS_ENSURE_STATE(remoteEvent.mEvent); mTabChild->SendEvent(remoteEvent); return NS_OK; } class ContentDialogChild : public PContentDialogChild { public: virtual bool Recv__delete__(const InfallibleTArray& aIntParams, const InfallibleTArray& aStringParams); }; class TabChild::CachedFileDescriptorInfo { struct PathOnlyComparatorHelper { bool Equals(const nsAutoPtr& a, const CachedFileDescriptorInfo& b) const { return a->mPath == b.mPath; } }; struct PathAndCallbackComparatorHelper { bool Equals(const nsAutoPtr& a, const CachedFileDescriptorInfo& b) const { return a->mPath == b.mPath && a->mCallback == b.mCallback; } }; public: nsString mPath; FileDescriptor mFileDescriptor; nsCOMPtr mCallback; bool mCanceled; CachedFileDescriptorInfo(const nsAString& aPath) : mPath(aPath), mCanceled(false) { } CachedFileDescriptorInfo(const nsAString& aPath, const FileDescriptor& aFileDescriptor) : mPath(aPath), mFileDescriptor(aFileDescriptor), mCanceled(false) { } CachedFileDescriptorInfo(const nsAString& aPath, nsICachedFileDescriptorListener* aCallback) : mPath(aPath), mCallback(aCallback), mCanceled(false) { } PathOnlyComparatorHelper PathOnlyComparator() const { return PathOnlyComparatorHelper(); } PathAndCallbackComparatorHelper PathAndCallbackComparator() const { return PathAndCallbackComparatorHelper(); } void FireCallback() const { mCallback->OnCachedFileDescriptor(mPath, mFileDescriptor); } }; class TabChild::CachedFileDescriptorCallbackRunnable : public nsRunnable { typedef TabChild::CachedFileDescriptorInfo CachedFileDescriptorInfo; nsAutoPtr mInfo; public: CachedFileDescriptorCallbackRunnable(CachedFileDescriptorInfo* aInfo) : mInfo(aInfo) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aInfo); MOZ_ASSERT(!aInfo->mPath.IsEmpty()); MOZ_ASSERT(aInfo->mCallback); } void Dispatch() { MOZ_ASSERT(NS_IsMainThread()); nsresult rv = NS_DispatchToCurrentThread(this); NS_ENSURE_SUCCESS_VOID(rv); } private: NS_IMETHOD Run() { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mInfo); mInfo->FireCallback(); return NS_OK; } }; StaticRefPtr sPreallocatedTab; /*static*/ void TabChild::PreloadSlowThings() { MOZ_ASSERT(!sPreallocatedTab); nsRefPtr tab(new TabChild(ContentChild::GetSingleton(), TabContext(), /* chromeFlags */ 0)); if (!NS_SUCCEEDED(tab->Init()) || !tab->InitTabChildGlobal(DONT_LOAD_SCRIPTS)) { return; } // Just load and compile these scripts, but don't run them. tab->TryCacheLoadAndCompileScript(BROWSER_ELEMENT_CHILD_SCRIPT); // Load, compile, and run these scripts. tab->RecvLoadRemoteScript( NS_LITERAL_STRING("chrome://global/content/preload.js")); nsCOMPtr docShell = do_GetInterface(tab->mWebNav); if (nsIPresShell* presShell = docShell->GetPresShell()) { // Initialize and do an initial reflow of the about:blank // PresShell to let it preload some things for us. presShell->Initialize(0, 0); nsIDocument* doc = presShell->GetDocument(); doc->FlushPendingNotifications(Flush_Layout); // ... but after it's done, make sure it doesn't do any more // work. presShell->MakeZombie(); } sPreallocatedTab = tab; ClearOnShutdown(&sPreallocatedTab); } /*static*/ already_AddRefed TabChild::Create(ContentChild* aManager, const TabContext &aContext, uint32_t aChromeFlags) { if (sPreallocatedTab && sPreallocatedTab->mChromeFlags == aChromeFlags && aContext.IsBrowserOrApp()) { nsRefPtr child = sPreallocatedTab.get(); sPreallocatedTab = nullptr; MOZ_ASSERT(!child->mTriedBrowserInit); child->SetTabContext(aContext); child->NotifyTabContextUpdated(); return child.forget(); } nsRefPtr iframe = new TabChild(aManager, aContext, aChromeFlags); return NS_SUCCEEDED(iframe->Init()) ? iframe.forget() : nullptr; } TabChild::TabChild(ContentChild* aManager, const TabContext& aContext, uint32_t aChromeFlags) : TabContext(aContext) , mRemoteFrame(nullptr) , mManager(aManager) , mTabChildGlobal(nullptr) , mChromeFlags(aChromeFlags) , mOuterRect(0, 0, 0, 0) , mInnerSize(0, 0) , mActivePointerId(-1) , mTapHoldTimer(nullptr) , mAppPackageFileDescriptorRecved(false) , mOldViewportWidth(0.0f) , mLastBackgroundColor(NS_RGB(255, 255, 255)) , mDidFakeShow(false) , mNotified(false) , mContentDocumentIsDisplayed(false) , mTriedBrowserInit(false) , mOrientation(eScreenOrientation_PortraitPrimary) , mUpdateHitRegion(false) { } NS_IMETHODIMP TabChild::HandleEvent(nsIDOMEvent* aEvent) { nsAutoString eventType; aEvent->GetType(eventType); if (eventType.EqualsLiteral("DOMMetaAdded")) { // This meta data may or may not have been a meta viewport tag. If it was, // we should handle it immediately. HandlePossibleViewportChange(); } else if (eventType.EqualsLiteral("scroll")) { nsCOMPtr target; aEvent->GetTarget(getter_AddRefs(target)); ViewID viewId; uint32_t presShellId; nsCOMPtr content; if (nsCOMPtr doc = do_QueryInterface(target)) content = doc->GetDocumentElement(); else content = do_QueryInterface(target); nsCOMPtr utils = APZCCallbackHelper::GetDOMWindowUtils(content); utils->GetPresShellId(&presShellId); if (!nsLayoutUtils::FindIDFor(content, &viewId)) return NS_ERROR_UNEXPECTED; nsIScrollableFrame* scrollFrame = nsLayoutUtils::FindScrollableFrameFor(viewId); if (!scrollFrame) return NS_OK; CSSIntPoint scrollOffset = scrollFrame->GetScrollPositionCSSPixels(); if (viewId == mLastRootMetrics.mScrollId) { // We store the last metrics that was sent via the TabParent (This is // updated in ProcessUpdateFrame and RecvUpdateFrame). // We use this here to avoid sending APZC back a scroll event that // originally came from APZC (besides being unnecessary, the event might // be slightly out of date by the time it reaches APZC). if (RoundedToInt(mLastRootMetrics.mScrollOffset) == scrollOffset) { return NS_OK; } // Update the last scroll offset now, otherwise RecvUpdateDimensions() // might trigger a scroll to the old offset before RecvUpdateFrame() // gets a chance to update it. mLastRootMetrics.mScrollOffset = scrollOffset; } else if (viewId == mLastSubFrameMetrics.mScrollId) { if (RoundedToInt(mLastSubFrameMetrics.mScrollOffset) == scrollOffset) { return NS_OK; } mLastSubFrameMetrics.mScrollOffset = scrollOffset; } SendUpdateScrollOffset(presShellId, viewId, scrollOffset); } return NS_OK; } NS_IMETHODIMP TabChild::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData) { if (!strcmp(aTopic, BROWSER_ZOOM_TO_RECT)) { nsCOMPtr docShell(do_QueryInterface(aSubject)); nsCOMPtr tabChild(TabChild::GetFrom(docShell)); if (tabChild == this) { nsCOMPtr doc(GetDocument()); uint32_t presShellId; ViewID viewId; if (APZCCallbackHelper::GetScrollIdentifiers(doc->GetDocumentElement(), &presShellId, &viewId)) { CSSRect rect; sscanf(NS_ConvertUTF16toUTF8(aData).get(), "{\"x\":%f,\"y\":%f,\"w\":%f,\"h\":%f}", &rect.x, &rect.y, &rect.width, &rect.height); SendZoomToRect(presShellId, viewId, rect); } } } else if (!strcmp(aTopic, BEFORE_FIRST_PAINT)) { if (IsAsyncPanZoomEnabled()) { nsCOMPtr subject(do_QueryInterface(aSubject)); nsCOMPtr doc(GetDocument()); if (SameCOMIdentity(subject, doc)) { nsCOMPtr utils(GetDOMWindowUtils()); mContentDocumentIsDisplayed = true; // Reset CSS viewport and zoom to default on new page, then // calculate them properly using the actual metadata from the // page. SetCSSViewport(kDefaultViewportSize); // Calculate a really simple resolution that we probably won't // be keeping, as well as putting the scroll offset back to // the top-left of the page. mLastRootMetrics.mViewport = CSSRect(CSSPoint(), kDefaultViewportSize); mLastRootMetrics.mCompositionBounds = ScreenIntRect(ScreenIntPoint(), mInnerSize); mLastRootMetrics.mZoom = mLastRootMetrics.CalculateIntrinsicScale(); mLastRootMetrics.mDevPixelsPerCSSPixel = mWidget->GetDefaultScale(); // We use ScreenToLayerScale(1) below in order to turn the // async zoom amount into the gecko zoom amount. mLastRootMetrics.mCumulativeResolution = mLastRootMetrics.mZoom / mLastRootMetrics.mDevPixelsPerCSSPixel * ScreenToLayerScale(1); // This is the root layer, so the cumulative resolution is the same // as the resolution. mLastRootMetrics.mResolution = mLastRootMetrics.mCumulativeResolution / LayoutDeviceToParentLayerScale(1); mLastRootMetrics.mScrollOffset = CSSPoint(0, 0); utils->SetResolution(mLastRootMetrics.mResolution.scale, mLastRootMetrics.mResolution.scale); HandlePossibleViewportChange(); } } } return NS_OK; } NS_IMETHODIMP TabChild::OnStateChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, uint32_t aStateFlags, nsresult aStatus) { NS_NOTREACHED("not implemented in TabChild"); return NS_OK; } NS_IMETHODIMP TabChild::OnProgressChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, int32_t aCurSelfProgress, int32_t aMaxSelfProgress, int32_t aCurTotalProgress, int32_t aMaxTotalProgress) { NS_NOTREACHED("not implemented in TabChild"); return NS_OK; } NS_IMETHODIMP TabChild::OnLocationChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, nsIURI *aLocation, uint32_t aFlags) { if (!IsAsyncPanZoomEnabled()) { return NS_OK; } nsCOMPtr window; aWebProgress->GetDOMWindow(getter_AddRefs(window)); if (!window) { return NS_OK; } nsCOMPtr utils(do_GetInterface(window)); utils->SetIsFirstPaint(true); nsCOMPtr progressDoc; window->GetDocument(getter_AddRefs(progressDoc)); if (!progressDoc) { return NS_OK; } nsCOMPtr domDoc; mWebNav->GetDocument(getter_AddRefs(domDoc)); if (!domDoc || !SameCOMIdentity(domDoc, progressDoc)) { return NS_OK; } nsCOMPtr urifixup(do_GetService(NS_URIFIXUP_CONTRACTID)); if (!urifixup) { return NS_OK; } nsCOMPtr exposableURI; urifixup->CreateExposableURI(aLocation, getter_AddRefs(exposableURI)); if (!exposableURI) { return NS_OK; } if (!(aFlags & nsIWebProgressListener::LOCATION_CHANGE_SAME_DOCUMENT)) { mContentDocumentIsDisplayed = false; } else if (mLastURI != nullptr) { bool exposableEqualsLast, exposableEqualsNew; exposableURI->Equals(mLastURI.get(), &exposableEqualsLast); exposableURI->Equals(aLocation, &exposableEqualsNew); if (exposableEqualsLast && !exposableEqualsNew) { mContentDocumentIsDisplayed = false; } } return NS_OK; } NS_IMETHODIMP TabChild::OnStatusChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, nsresult aStatus, const PRUnichar* aMessage) { NS_NOTREACHED("not implemented in TabChild"); return NS_OK; } NS_IMETHODIMP TabChild::OnSecurityChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, uint32_t aState) { NS_NOTREACHED("not implemented in TabChild"); return NS_OK; } void TabChild::SetCSSViewport(const CSSSize& aSize) { mOldViewportWidth = aSize.width; if (mContentDocumentIsDisplayed) { nsCOMPtr utils(GetDOMWindowUtils()); utils->SetCSSViewport(aSize.width, aSize.height); } } void TabChild::HandlePossibleViewportChange() { if (!IsAsyncPanZoomEnabled()) { return; } nsCOMPtr domDoc; mWebNav->GetDocument(getter_AddRefs(domDoc)); nsCOMPtr document(do_QueryInterface(domDoc)); nsCOMPtr utils(GetDOMWindowUtils()); nsViewportInfo viewportInfo = nsContentUtils::GetViewportInfo(document, mInnerSize); uint32_t presShellId; ViewID viewId; if (APZCCallbackHelper::GetScrollIdentifiers(document->GetDocumentElement(), &presShellId, &viewId)) { SendUpdateZoomConstraints(presShellId, viewId, /* isRoot = */ true, viewportInfo.IsZoomAllowed(), viewportInfo.GetMinZoom(), viewportInfo.GetMaxZoom()); } float screenW = mInnerSize.width; float screenH = mInnerSize.height; CSSSize viewport(viewportInfo.GetSize()); // We're not being displayed in any way; don't bother doing anything because // that will just confuse future adjustments. if (!screenW || !screenH) { return; } float oldBrowserWidth = mOldViewportWidth; mLastRootMetrics.mViewport.SizeTo(viewport); if (!oldBrowserWidth) { oldBrowserWidth = kDefaultViewportSize.width; } SetCSSViewport(viewport); // If this page has not been painted yet, then this must be getting run // because a meta-viewport element was added (via the DOMMetaAdded handler). // in this case, we should not do anything that forces a reflow (see bug // 759678) such as requesting the page size or sending a viewport update. this // code will get run again in the before-first-paint handler and that point we // will run though all of it. the reason we even bother executing up to this // point on the DOMMetaAdded handler is so that scripts that use // window.innerWidth before they are painted have a correct value (bug // 771575). if (!mContentDocumentIsDisplayed) { return; } nsCOMPtr htmlDOMElement = document->GetHtmlElement(); HTMLBodyElement* bodyDOMElement = document->GetBodyElement(); int32_t htmlWidth = 0, htmlHeight = 0; if (htmlDOMElement) { htmlWidth = htmlDOMElement->ScrollWidth(); htmlHeight = htmlDOMElement->ScrollHeight(); } int32_t bodyWidth = 0, bodyHeight = 0; if (bodyDOMElement) { bodyWidth = bodyDOMElement->ScrollWidth(); bodyHeight = bodyDOMElement->ScrollHeight(); } CSSSize pageSize; if (htmlDOMElement || bodyDOMElement) { pageSize = CSSSize(std::max(htmlWidth, bodyWidth), std::max(htmlHeight, bodyHeight)); } else { // For non-HTML content (e.g. SVG), just assume page size == viewport size. pageSize = viewport; } if (!pageSize.width) { // Return early rather than divide by 0. return; } float oldScreenWidth = mLastRootMetrics.mCompositionBounds.width; if (!oldScreenWidth) { oldScreenWidth = mInnerSize.width; } FrameMetrics metrics(mLastRootMetrics); metrics.mViewport = CSSRect(CSSPoint(), viewport); metrics.mScrollableRect = CSSRect(CSSPoint(), pageSize); metrics.mCompositionBounds = ScreenIntRect(ScreenIntPoint(), mInnerSize); // This change to the zoom accounts for all types of changes I can conceive: // 1. screen size changes, CSS viewport does not (pages with no meta viewport // or a fixed size viewport) // 2. screen size changes, CSS viewport also does (pages with a device-width // viewport) // 3. screen size remains constant, but CSS viewport changes (meta viewport // tag is added or removed) // 4. neither screen size nor CSS viewport changes // // In all of these cases, we maintain how much actual content is visible // within the screen width. Note that "actual content" may be different with // respect to CSS pixels because of the CSS viewport size changing. float oldIntrinsicScale = oldScreenWidth / oldBrowserWidth; metrics.mZoom.scale *= metrics.CalculateIntrinsicScale().scale / oldIntrinsicScale; // Changing the zoom when we're not doing a first paint will get ignored // by AsyncPanZoomController and causes a blurry flash. bool isFirstPaint; nsresult rv = utils->GetIsFirstPaint(&isFirstPaint); MOZ_ASSERT(NS_SUCCEEDED(rv)); if (NS_FAILED(rv) || isFirstPaint) { // FIXME/bug 799585(?): GetViewportInfo() returns a defaultZoom of // 0.0 to mean "did not calculate a zoom". In that case, we default // it to the intrinsic scale. if (viewportInfo.GetDefaultZoom().scale < 0.01f) { viewportInfo.SetDefaultZoom(metrics.CalculateIntrinsicScale()); } CSSToScreenScale defaultZoom = viewportInfo.GetDefaultZoom(); MOZ_ASSERT(viewportInfo.GetMinZoom() <= defaultZoom && defaultZoom <= viewportInfo.GetMaxZoom()); metrics.mZoom = defaultZoom; metrics.mScrollId = viewId; } metrics.mDisplayPort = AsyncPanZoomController::CalculatePendingDisplayPort( // The page must have been refreshed in some way such as a new document or // new CSS viewport, so we know that there's no velocity, acceleration, and // we have no idea how long painting will take. metrics, gfx::Point(0.0f, 0.0f), gfx::Point(0.0f, 0.0f), 0.0); metrics.mCumulativeResolution = metrics.mZoom / metrics.mDevPixelsPerCSSPixel * ScreenToLayerScale(1); // This is the root layer, so the cumulative resolution is the same // as the resolution. metrics.mResolution = metrics.mCumulativeResolution / LayoutDeviceToParentLayerScale(1); utils->SetResolution(metrics.mResolution.scale, metrics.mResolution.scale); // Force a repaint with these metrics. This, among other things, sets the // displayport, so we start with async painting. ProcessUpdateFrame(metrics); } nsresult TabChild::Init() { nsCOMPtr webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID); if (!webBrowser) { NS_ERROR("Couldn't create a nsWebBrowser?"); return NS_ERROR_FAILURE; } webBrowser->SetContainerWindow(this); mWebNav = do_QueryInterface(webBrowser); NS_ASSERTION(mWebNav, "nsWebBrowser doesn't implement nsIWebNavigation?"); nsCOMPtr docShellItem(do_QueryInterface(mWebNav)); docShellItem->SetItemType(nsIDocShellTreeItem::typeContentWrapper); nsCOMPtr baseWindow = do_QueryInterface(mWebNav); if (!baseWindow) { NS_ERROR("mWebNav doesn't QI to nsIBaseWindow"); return NS_ERROR_FAILURE; } mWidget = nsIWidget::CreatePuppetWidget(this); if (!mWidget) { NS_ERROR("couldn't create fake widget"); return NS_ERROR_FAILURE; } mWidget->Create( nullptr, 0, // no parents nsIntRect(nsIntPoint(0, 0), nsIntSize(0, 0)), nullptr, // HandleWidgetEvent nullptr // nsDeviceContext ); baseWindow->InitWindow(0, mWidget, 0, 0, 0, 0); baseWindow->Create(); NotifyTabContextUpdated(); // IPC uses a WebBrowser object for which DNS prefetching is turned off // by default. But here we really want it, so enable it explicitly nsCOMPtr webBrowserSetup = do_QueryInterface(baseWindow); if (webBrowserSetup) { webBrowserSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_DNS_PREFETCH, true); } else { NS_WARNING("baseWindow doesn't QI to nsIWebBrowserSetup, skipping " "DNS prefetching enable step."); } nsCOMPtr docShell = do_GetInterface(mWebNav); MOZ_ASSERT(docShell); docShell->SetAffectPrivateSessionLifetime( mChromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_LIFETIME); nsCOMPtr loadContext = do_GetInterface(mWebNav); MOZ_ASSERT(loadContext); loadContext->SetPrivateBrowsing( mChromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW); nsCOMPtr webProgress = do_GetInterface(docShell); NS_ENSURE_TRUE(webProgress, NS_ERROR_FAILURE); webProgress->AddProgressListener(this, nsIWebProgress::NOTIFY_LOCATION); return NS_OK; } void TabChild::NotifyTabContextUpdated() { nsCOMPtr docShell = do_GetInterface(mWebNav); MOZ_ASSERT(docShell); if (docShell) { // nsDocShell will do the right thing if we pass NO_APP_ID or // UNKNOWN_APP_ID for aOwnOrContainingAppId. if (IsBrowserElement()) { docShell->SetIsBrowserInsideApp(BrowserOwnerAppId()); } else { docShell->SetIsApp(OwnAppId()); } } } NS_INTERFACE_MAP_BEGIN(TabChild) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome) NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome) NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome2) NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow) NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChromeFocus) NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY(nsIWindowProvider) NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener) NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) NS_INTERFACE_MAP_ENTRY(nsITabChild) NS_INTERFACE_MAP_ENTRY(nsIDialogCreator) NS_INTERFACE_MAP_ENTRY(nsIObserver) NS_INTERFACE_MAP_ENTRY(nsSupportsWeakReference) NS_INTERFACE_MAP_END NS_IMPL_ADDREF(TabChild) NS_IMPL_RELEASE(TabChild) NS_IMETHODIMP TabChild::SetStatus(uint32_t aStatusType, const PRUnichar* aStatus) { return SetStatusWithContext(aStatusType, aStatus ? static_cast(nsDependentString(aStatus)) : EmptyString(), nullptr); } NS_IMETHODIMP TabChild::GetWebBrowser(nsIWebBrowser** aWebBrowser) { NS_NOTREACHED("TabChild::GetWebBrowser not supported in TabChild"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP TabChild::SetWebBrowser(nsIWebBrowser* aWebBrowser) { NS_NOTREACHED("TabChild::SetWebBrowser not supported in TabChild"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP TabChild::GetChromeFlags(uint32_t* aChromeFlags) { *aChromeFlags = mChromeFlags; return NS_OK; } NS_IMETHODIMP TabChild::SetChromeFlags(uint32_t aChromeFlags) { NS_NOTREACHED("trying to SetChromeFlags from content process?"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP TabChild::DestroyBrowserWindow() { NS_NOTREACHED("TabChild::SetWebBrowser not supported in TabChild"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP TabChild::SizeBrowserTo(int32_t aCX, int32_t aCY) { NS_NOTREACHED("TabChild::SizeBrowserTo not supported in TabChild"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP TabChild::ShowAsModal() { NS_NOTREACHED("TabChild::ShowAsModal not supported in TabChild"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP TabChild::IsWindowModal(bool* aRetVal) { *aRetVal = false; return NS_OK; } NS_IMETHODIMP TabChild::ExitModalEventLoop(nsresult aStatus) { NS_NOTREACHED("TabChild::ExitModalEventLoop not supported in TabChild"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP TabChild::SetStatusWithContext(uint32_t aStatusType, const nsAString& aStatusText, nsISupports* aStatusContext) { // We can only send the status after the ipc machinery is set up, // mRemoteFrame is a good indicator. if (mRemoteFrame) SendSetStatus(aStatusType, nsString(aStatusText)); return NS_OK; } NS_IMETHODIMP TabChild::SetDimensions(uint32_t aFlags, int32_t aX, int32_t aY, int32_t aCx, int32_t aCy) { NS_NOTREACHED("TabChild::SetDimensions not supported in TabChild"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP TabChild::GetDimensions(uint32_t aFlags, int32_t* aX, int32_t* aY, int32_t* aCx, int32_t* aCy) { if (aX) { *aX = mOuterRect.x; } if (aY) { *aY = mOuterRect.y; } if (aCx) { *aCx = mOuterRect.width; } if (aCy) { *aCy = mOuterRect.height; } return NS_OK; } NS_IMETHODIMP TabChild::SetFocus() { NS_WARNING("TabChild::SetFocus not supported in TabChild"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP TabChild::GetVisibility(bool* aVisibility) { *aVisibility = true; return NS_OK; } NS_IMETHODIMP TabChild::SetVisibility(bool aVisibility) { // should the platform support this? Bug 666365 return NS_OK; } NS_IMETHODIMP TabChild::GetTitle(PRUnichar** aTitle) { NS_NOTREACHED("TabChild::GetTitle not supported in TabChild"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP TabChild::SetTitle(const PRUnichar* aTitle) { // JavaScript sends the "DOMTitleChanged" event to the parent // via the message manager. return NS_OK; } NS_IMETHODIMP TabChild::GetSiteWindow(void** aSiteWindow) { NS_NOTREACHED("TabChild::GetSiteWindow not supported in TabChild"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP TabChild::Blur() { NS_WARNING("TabChild::Blur not supported in TabChild"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP TabChild::FocusNextElement() { SendMoveFocus(true); return NS_OK; } NS_IMETHODIMP TabChild::FocusPrevElement() { SendMoveFocus(false); return NS_OK; } NS_IMETHODIMP TabChild::GetInterface(const nsIID & aIID, void **aSink) { // XXXbz should we restrict the set of interfaces we hand out here? // See bug 537429 return QueryInterface(aIID, aSink); } NS_IMETHODIMP TabChild::ProvideWindow(nsIDOMWindow* aParent, uint32_t aChromeFlags, bool aCalledFromJS, bool aPositionSpecified, bool aSizeSpecified, nsIURI* aURI, const nsAString& aName, const nsACString& aFeatures, bool* aWindowIsNew, nsIDOMWindow** aReturn) { *aReturn = nullptr; // If aParent is inside an