Skip to content

Commit

Permalink
Share TabChild code, part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeshkova committed Mar 11, 2014
1 parent 6f5a915 commit f3d1e65
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 306 deletions.
60 changes: 30 additions & 30 deletions dom/ipc/TabChild.cpp
Expand Up @@ -235,7 +235,7 @@ TabChild::PreloadSlowThings()
NS_LITERAL_STRING("chrome://global/content/preload.js"),
true);

nsCOMPtr<nsIDocShell> docShell = do_GetInterface(tab->mWebNav);
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(tab->WebNavigation());
if (nsIPresShell* presShell = docShell->GetPresShell()) {
// Initialize and do an initial reflow of the about:blank
// PresShell to let it preload some things for us.
Expand Down Expand Up @@ -445,7 +445,7 @@ TabChild::OnLocationChange(nsIWebProgress* aWebProgress,
}

nsCOMPtr<nsIDOMDocument> domDoc;
mWebNav->GetDocument(getter_AddRefs(domDoc));
WebNavigation()->GetDocument(getter_AddRefs(domDoc));
if (!domDoc || !SameCOMIdentity(domDoc, progressDoc)) {
return NS_OK;
}
Expand Down Expand Up @@ -538,7 +538,7 @@ TabChild::HandlePossibleViewportChange()
}

nsCOMPtr<nsIDOMDocument> domDoc;
mWebNav->GetDocument(getter_AddRefs(domDoc));
WebNavigation()->GetDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> document(do_QueryInterface(domDoc));

nsCOMPtr<nsIDOMWindowUtils> utils(GetDOMWindowUtils());
Expand Down Expand Up @@ -699,10 +699,10 @@ TabChild::Init()
mWebNav = do_QueryInterface(webBrowser);
NS_ASSERTION(mWebNav, "nsWebBrowser doesn't implement nsIWebNavigation?");

nsCOMPtr<nsIDocShellTreeItem> docShellItem(do_QueryInterface(mWebNav));
nsCOMPtr<nsIDocShellTreeItem> docShellItem(do_QueryInterface(WebNavigation()));
docShellItem->SetItemType(nsIDocShellTreeItem::typeContentWrapper);

nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(mWebNav);
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(WebNavigation());
if (!baseWindow) {
NS_ERROR("mWebNav doesn't QI to nsIBaseWindow");
return NS_ERROR_FAILURE;
Expand Down Expand Up @@ -737,12 +737,12 @@ TabChild::Init()
"DNS prefetching enable step.");
}

nsCOMPtr<nsIDocShell> docShell = do_GetInterface(mWebNav);
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(WebNavigation());
MOZ_ASSERT(docShell);

docShell->SetAffectPrivateSessionLifetime(
mChromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_LIFETIME);
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(mWebNav);
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(WebNavigation());
MOZ_ASSERT(loadContext);
loadContext->SetPrivateBrowsing(
mChromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW);
Expand All @@ -759,7 +759,7 @@ TabChild::Init()
void
TabChild::NotifyTabContextUpdated()
{
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(mWebNav);
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(WebNavigation());
MOZ_ASSERT(docShell);

if (docShell) {
Expand Down Expand Up @@ -1023,7 +1023,7 @@ TabChild::ProvideWindow(nsIDOMWindow* aParent, uint32_t aChromeFlags,

*aWindowIsNew = true;
nsCOMPtr<nsIDOMWindow> win =
do_GetInterface(static_cast<TabChild*>(newChild)->mWebNav);
do_GetInterface(static_cast<TabChild*>(newChild)->WebNavigation());
win.forget(aReturn);
return NS_OK;
}
Expand Down Expand Up @@ -1077,15 +1077,15 @@ TabChild::BrowserFrameProvideWindow(nsIDOMWindow* aOpener,
// pretty bogus; see bug 763602.
newChild->DoFakeShow();

nsCOMPtr<nsIDOMWindow> win = do_GetInterface(newChild->mWebNav);
nsCOMPtr<nsIDOMWindow> win = do_GetInterface(newChild->WebNavigation());
win.forget(aReturn);
return NS_OK;
}

already_AddRefed<nsIDOMWindowUtils>
TabChild::GetDOMWindowUtils()
{
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(mWebNav);
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(WebNavigation());
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(window);
return utils.forget();
}
Expand All @@ -1094,7 +1094,7 @@ already_AddRefed<nsIDocument>
TabChild::GetDocument()
{
nsCOMPtr<nsIDOMDocument> domDoc;
mWebNav->GetDocument(getter_AddRefs(domDoc));
WebNavigation()->GetDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
return doc.forget();
}
Expand Down Expand Up @@ -1193,7 +1193,7 @@ TabChild:: SendPContentPermissionRequestConstructor(PContentPermissionRequestChi
void
TabChild::DestroyWindow()
{
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(mWebNav);
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(WebNavigation());
if (baseWindow)
baseWindow->Destroy();

Expand Down Expand Up @@ -1232,7 +1232,7 @@ TabChild::~TabChild()
{
DestroyWindow();

nsCOMPtr<nsIWebBrowser> webBrowser = do_QueryInterface(mWebNav);
nsCOMPtr<nsIWebBrowser> webBrowser = do_QueryInterface(WebNavigation());
if (webBrowser) {
webBrowser->SetContainerWindow(nullptr);
}
Expand Down Expand Up @@ -1294,12 +1294,12 @@ TabChild::RecvLoadURL(const nsCString& uri)
{
SetProcessNameToAppName();

nsresult rv = mWebNav->LoadURI(NS_ConvertUTF8toUTF16(uri).get(),
nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
nsIWebNavigation::LOAD_FLAGS_DISALLOW_INHERIT_OWNER,
nullptr, nullptr, nullptr);
nsresult rv = WebNavigation()->LoadURI(NS_ConvertUTF8toUTF16(uri).get(),
nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
nsIWebNavigation::LOAD_FLAGS_DISALLOW_INHERIT_OWNER,
nullptr, nullptr, nullptr);
if (NS_FAILED(rv)) {
NS_WARNING("mWebNav->LoadURI failed. Eating exception, what else can I do?");
NS_WARNING("WebNavigation()->LoadURI failed. Eating exception, what else can I do?");
}

#ifdef MOZ_CRASHREPORTER
Expand Down Expand Up @@ -1468,9 +1468,9 @@ TabChild::RecvShow(const nsIntSize& size)
return true;
}

nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(mWebNav);
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(WebNavigation());
if (!baseWindow) {
NS_ERROR("mWebNav doesn't QI to nsIBaseWindow");
NS_ERROR("WebNavigation() doesn't QI to nsIBaseWindow");
return false;
}

Expand Down Expand Up @@ -1508,7 +1508,7 @@ TabChild::RecvUpdateDimensions(const nsRect& rect, const nsIntSize& size, const
mWidget->Resize(0, 0, size.width, size.height,
true);

nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(mWebNav);
nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(WebNavigation());
baseWin->SetPositionAndSize(0, 0, size.width, size.height,
true);

Expand Down Expand Up @@ -1752,14 +1752,14 @@ TabChild::RecvNotifyTransformEnd(const ViewID& aViewId)
bool
TabChild::RecvActivate()
{
nsCOMPtr<nsIWebBrowserFocus> browser = do_QueryInterface(mWebNav);
nsCOMPtr<nsIWebBrowserFocus> browser = do_QueryInterface(WebNavigation());
browser->Activate();
return true;
}

bool TabChild::RecvDeactivate()
{
nsCOMPtr<nsIWebBrowserFocus> browser = do_QueryInterface(mWebNav);
nsCOMPtr<nsIWebBrowserFocus> browser = do_QueryInterface(WebNavigation());
browser->Deactivate();
return true;
}
Expand Down Expand Up @@ -1962,7 +1962,7 @@ TabChild::RecvRealTouchEvent(const WidgetTouchEvent& aEvent,
return true;
}

nsCOMPtr<nsPIDOMWindow> outerWindow = do_GetInterface(mWebNav);
nsCOMPtr<nsPIDOMWindow> outerWindow = do_GetInterface(WebNavigation());
nsCOMPtr<nsPIDOMWindow> innerWindow = outerWindow->GetCurrentInnerWindow();

if (!innerWindow || !innerWindow->HasTouchEventListeners()) {
Expand Down Expand Up @@ -2095,7 +2095,7 @@ TabChild::RecvPDocumentRendererConstructor(PDocumentRendererChild* actor,
{
DocumentRendererChild *render = static_cast<DocumentRendererChild *>(actor);

nsCOMPtr<nsIWebBrowser> browser = do_QueryInterface(mWebNav);
nsCOMPtr<nsIWebBrowser> browser = do_QueryInterface(WebNavigation());
if (!browser)
return true; // silently ignore
nsCOMPtr<nsIDOMWindow> window;
Expand Down Expand Up @@ -2187,7 +2187,7 @@ TabChild::DeallocPFilePickerChild(PFilePickerChild* actor)
bool
TabChild::RecvActivateFrameEvent(const nsString& aType, const bool& capture)
{
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(mWebNav);
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(WebNavigation());
NS_ENSURE_TRUE(window, true);
nsCOMPtr<EventTarget> chromeHandler =
do_QueryInterface(window->GetChromeEventHandler());
Expand Down Expand Up @@ -2308,7 +2308,7 @@ TabChild::RecvSetUpdateHitRegion(const bool& aEnabled)
bool
TabChild::RecvSetIsDocShellActive(const bool& aIsActive)
{
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(mWebNav);
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(WebNavigation());
if (docShell) {
docShell->SetIsActive(aIsActive);
}
Expand All @@ -2332,7 +2332,7 @@ bool
TabChild::InitTabChildGlobal(FrameScriptLoading aScriptLoading)
{
if (!mGlobal && !mTabChildGlobal) {
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(mWebNav);
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(WebNavigation());
NS_ENSURE_TRUE(window, false);
nsCOMPtr<EventTarget> chromeHandler =
do_QueryInterface(window->GetChromeEventHandler());
Expand Down Expand Up @@ -2644,7 +2644,7 @@ TabChild::OnHideTooltip()
return NS_OK;
}

TabChildGlobal::TabChildGlobal(TabChild* aTabChild)
TabChildGlobal::TabChildGlobal(TabChildBase* aTabChild)
: mTabChild(aTabChild)
{
}
Expand Down
22 changes: 14 additions & 8 deletions dom/ipc/TabChild.h
Expand Up @@ -48,14 +48,15 @@ namespace dom {
class TabChild;
class PContentDialogChild;
class ClonedMessageData;
class TabChildBase;

class TabChildGlobal : public nsDOMEventTargetHelper,
public nsIContentFrameMessageManager,
public nsIScriptObjectPrincipal,
public nsIGlobalObject
{
public:
TabChildGlobal(TabChild* aTabChild);
TabChildGlobal(TabChildBase* aTabChild);
void Init();
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TabChildGlobal, nsDOMEventTargetHelper)
Expand Down Expand Up @@ -131,7 +132,7 @@ class TabChildGlobal : public nsDOMEventTargetHelper,
virtual JSObject* GetGlobalJSObject() MOZ_OVERRIDE;

nsCOMPtr<nsIContentFrameMessageManager> mMessageManager;
TabChild* mTabChild;
TabChildBase* mTabChild;
};

class ContentListener MOZ_FINAL : public nsIDOMEventListener
Expand All @@ -144,8 +145,15 @@ class ContentListener MOZ_FINAL : public nsIDOMEventListener
TabChild* mTabChild;
};

class TabChildBase : public nsFrameScriptExecutor,
public ipc::MessageManagerCallback
{
public:
virtual nsIWebNavigation* WebNavigation() = 0;
nsIPrincipal* GetPrincipal() { return mPrincipal; }
};

class TabChild : public PBrowserChild,
public nsFrameScriptExecutor,
public nsIWebBrowserChrome2,
public nsIEmbeddingSiteWindow,
public nsIWebBrowserChromeFocus,
Expand All @@ -157,9 +165,9 @@ class TabChild : public PBrowserChild,
public nsIDialogCreator,
public nsITabChild,
public nsIObserver,
public ipc::MessageManagerCallback,
public TabContext,
public nsITooltipListener
public nsITooltipListener,
public TabChildBase
{
typedef mozilla::dom::ClonedMessageData ClonedMessageData;
typedef mozilla::layout::RenderFrameChild RenderFrameChild;
Expand Down Expand Up @@ -323,9 +331,7 @@ class TabChild : public PBrowserChild,
virtual bool
DeallocPOfflineCacheUpdateChild(POfflineCacheUpdateChild* offlineCacheUpdate) MOZ_OVERRIDE;

nsIWebNavigation* WebNavigation() { return mWebNav; }

nsIPrincipal* GetPrincipal() { return mPrincipal; }
virtual nsIWebNavigation* WebNavigation() MOZ_OVERRIDE { return mWebNav; }

/** Return the DPI of the widget this TabChild draws to. */
void GetDPI(float* aDPI);
Expand Down
1 change: 0 additions & 1 deletion embedding/embedlite/moz.build
Expand Up @@ -49,7 +49,6 @@ SOURCES += [
'utils/DirProvider.cpp',
'utils/EmbedLiteXulAppInfo.cpp',
'utils/EmbedLog.cpp',
'utils/EmbedTabChildGlobal.cpp',
'utils/GeckoLoader.cpp',
'utils/TabChildHelper.cpp',
'utils/WebBrowserChrome.cpp',
Expand Down

0 comments on commit f3d1e65

Please sign in to comment.