Skip to content

Commit

Permalink
Bug 1293596 (part 4) - Tweak nsIWidget::Create. r=mstange.
Browse files Browse the repository at this point in the history
They don't need to be NS_IMETHOD, but they should be MOZ_MUST_USE. Adding the
latter catches a few missing checks, which the patch adds.

The patch also gives PuppetWidget an InfallibleCreate() function, which makes
the infallibility of PuppetWidget creation clear.
  • Loading branch information
nnethercote committed Aug 18, 2016
1 parent 78199d8 commit f1348a9
Show file tree
Hide file tree
Showing 22 changed files with 110 additions and 78 deletions.
2 changes: 1 addition & 1 deletion dom/ipc/TabChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ TabChild::Init()
NS_ERROR("couldn't create fake widget");
return NS_ERROR_FAILURE;
}
mPuppetWidget->Create(
mPuppetWidget->InfallibleCreate(
nullptr, 0, // no parents
LayoutDeviceIntRect(0, 0, 0, 0),
nullptr // HandleWidgetEvent
Expand Down
4 changes: 3 additions & 1 deletion embedding/browser/nsWebBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,9 @@ nsWebBrowser::Create()
mInitInfo->cx, mInitInfo->cy);

mInternalWidget->SetWidgetListener(this);
mInternalWidget->Create(nullptr, mParentNativeWindow, bounds, &widgetInit);
rv = mInternalWidget->Create(nullptr, mParentNativeWindow, bounds,
&widgetInit);
NS_ENSURE_SUCCESS(rv, rv);
}

nsCOMPtr<nsIDocShell> docShell(
Expand Down
4 changes: 2 additions & 2 deletions gfx/tests/gtest/TestCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class MockWidget : public nsBaseWidget
return nullptr;
}

NS_IMETHOD Create(nsIWidget* aParent,
virtual nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override { return NS_OK; }
NS_IMETHOD Create(nsIWidget* aParent,
virtual nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override { return NS_OK; }
Expand Down
2 changes: 1 addition & 1 deletion widget/PluginWidgetProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ PluginWidgetProxy::~PluginWidgetProxy()
PWLOG("PluginWidgetProxy::~PluginWidgetProxy()\n");
}

NS_IMETHODIMP
nsresult
PluginWidgetProxy::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
Expand Down
8 changes: 5 additions & 3 deletions widget/PluginWidgetProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class PluginWidgetProxy final : public PuppetWidget

// nsIWidget
using PuppetWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override;
virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr)
override;
NS_IMETHOD Destroy() override;
NS_IMETHOD SetFocus(bool aRaise = false) override;
NS_IMETHOD SetParent(nsIWidget* aNewParent) override;
Expand Down
18 changes: 13 additions & 5 deletions widget/PuppetWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ PuppetWidget::~PuppetWidget()
Destroy();
}

NS_IMETHODIMP
PuppetWidget::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData)
void
PuppetWidget::InfallibleCreate(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData)
{
MOZ_ASSERT(!aNativeParent, "got a non-Puppet native parent");

Expand Down Expand Up @@ -133,7 +133,15 @@ PuppetWidget::Create(nsIWidget* aParent,
mMemoryPressureObserver = new MemoryPressureObserver(this);
obs->AddObserver(mMemoryPressureObserver, "memory-pressure", false);
}
}

nsresult
PuppetWidget::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData)
{
InfallibleCreate(aParent, aNativeParent, aRect, aInitData);
return NS_OK;
}

Expand Down
15 changes: 11 additions & 4 deletions widget/PuppetWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,18 @@ class PuppetWidget : public nsBaseWidget
public:
NS_DECL_ISUPPORTS_INHERITED

// PuppetWidget creation is infallible, hence InfallibleCreate(), which
// Create() calls.
using nsBaseWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override;
virtual nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr)
override;
void InfallibleCreate(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr);

void InitIMEState();

Expand Down
2 changes: 1 addition & 1 deletion widget/android/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ nsWindow::IsTopLevel()
mWindowType == eWindowType_invisible;
}

NS_IMETHODIMP
nsresult
nsWindow::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
Expand Down
8 changes: 4 additions & 4 deletions widget/android/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ class nsWindow : public nsBaseWidget
//

using nsBaseWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData) override;
virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData) override;
NS_IMETHOD Destroy(void) override;
NS_IMETHOD ConfigureChildren(const nsTArray<nsIWidget::Configuration>&) override;
NS_IMETHOD SetParent(nsIWidget* aNewParent) override;
Expand Down
9 changes: 5 additions & 4 deletions widget/cocoa/nsChildView.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,11 @@ class nsChildView : public nsBaseWidget
nsChildView();

// nsIWidget interface
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override;
virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr)
override;

NS_IMETHOD Destroy() override;

Expand Down
9 changes: 5 additions & 4 deletions widget/cocoa/nsChildView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,11 @@ virtual void BindAndDrawQuad(ShaderProgramOGL *aProg,
}
}

nsresult nsChildView::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData)
nsresult
nsChildView::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;

Expand Down
20 changes: 11 additions & 9 deletions widget/cocoa/nsCocoaWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,17 @@ class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSPIWIDGETCOCOA

NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override;

NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override;
virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData = nullptr)
override;

virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr)
override;

NS_IMETHOD Destroy() override;

Expand Down
18 changes: 10 additions & 8 deletions widget/cocoa/nsCocoaWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,11 @@ static bool UseNativePopupWindows()
}

// aRect here is specified in desktop pixels
nsresult nsCocoaWindow::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData)
nsresult
nsCocoaWindow::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;

Expand Down Expand Up @@ -316,10 +317,11 @@ static bool UseNativePopupWindows()
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}

nsresult nsCocoaWindow::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData)
nsresult
nsCocoaWindow::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData)
{
DesktopIntRect desktopRect =
RoundedToInt(aRect / GetDesktopToDeviceScale());
Expand Down
2 changes: 1 addition & 1 deletion widget/gonk/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ nsWindow::SynthesizeNativeTouchPoint(uint32_t aPointerId,
return NS_OK;
}

NS_IMETHODIMP
nsresult
nsWindow::Create(nsIWidget* aParent,
void* aNativeParent,
const LayoutDeviceIntRect& aRect,
Expand Down
8 changes: 4 additions & 4 deletions widget/gonk/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class nsWindow : public nsBaseWidget
static void DispatchTouchInput(mozilla::MultiTouchInput& aInput);

using nsBaseWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent,
void* aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData) override;
virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
void* aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData) override;
NS_IMETHOD Destroy(void);

NS_IMETHOD Show(bool aState);
Expand Down
8 changes: 4 additions & 4 deletions widget/gtk/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ class nsWindow : public nsBaseWidget

// nsIWidget
using nsBaseWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData) override;
virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData) override;
NS_IMETHOD Destroy(void) override;
virtual nsIWidget *GetParent() override;
virtual float GetDPI() override;
Expand Down
18 changes: 10 additions & 8 deletions widget/nsIWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,11 @@ class nsIWidget : public nsISupports
* @param aInitData data that is used for widget initialization
*
*/
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) = 0;
virtual MOZ_MUST_USE nsresult
Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) = 0;

/*
* As above, but with aRect specified in DesktopPixel units (for top-level
Expand All @@ -434,10 +435,11 @@ class nsIWidget : public nsISupports
* mapping is not straightforward or the native platform needs to use the
* desktop pixel values directly.
*/
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData = nullptr)
virtual MOZ_MUST_USE nsresult
Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData = nullptr)
{
LayoutDeviceIntRect devPixRect =
RoundedToInt(aRect * GetDesktopToDeviceScale());
Expand Down
9 changes: 5 additions & 4 deletions widget/uikit/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ class nsWindow :
// nsIWidget
//

NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override;
virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr)
override;
NS_IMETHOD Destroy() override;
NS_IMETHOD Show(bool aState) override;
NS_IMETHOD Enable(bool aState) override {
Expand Down
2 changes: 1 addition & 1 deletion widget/uikit/nsWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ - (void)drawRect:(CGRect)aRect inContext:(CGContextRef)aContext
// nsIWidget
//

NS_IMETHODIMP
nsresult
nsWindow::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
Expand Down
9 changes: 5 additions & 4 deletions widget/windows/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ class nsWindow : public nsWindowBase

// nsIWidget interface
using nsWindowBase::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override;
virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr)
override;
NS_IMETHOD Destroy() override;
NS_IMETHOD SetParent(nsIWidget *aNewParent) override;
virtual nsIWidget* GetParent(void) override;
Expand Down
4 changes: 3 additions & 1 deletion xpfe/appshell/nsAppShellService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,9 @@ nsAppShellService::CreateWindowlessBrowser(bool aIsChrome, nsIWindowlessBrowser
NS_ERROR("Couldn't create instance of PuppetWidget");
return NS_ERROR_FAILURE;
}
widget->Create(nullptr, 0, LayoutDeviceIntRect(0, 0, 0, 0), nullptr);
nsresult rv =
widget->Create(nullptr, 0, LayoutDeviceIntRect(0, 0, 0, 0), nullptr);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIBaseWindow> window = do_QueryInterface(navigation);
window->InitWindow(0, widget, 0, 0, 0, 0);
window->Create();
Expand Down
9 changes: 5 additions & 4 deletions xpfe/appshell/nsWebShellWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent,
}

mWindow->SetWidgetListener(this);
mWindow->Create((nsIWidget *)parentWidget, // Parent nsIWidget
nullptr, // Native parent widget
deskRect, // Widget dimensions
&widgetInitData); // Widget initialization data
rv = mWindow->Create((nsIWidget *)parentWidget, // Parent nsIWidget
nullptr, // Native parent widget
deskRect, // Widget dimensions
&widgetInitData); // Widget initialization data
NS_ENSURE_SUCCESS(rv, rv);

LayoutDeviceIntRect r = mWindow->GetClientBounds();
// Match the default background color of content. Important on windows
Expand Down

0 comments on commit f1348a9

Please sign in to comment.