Bug 852428 part 1. Make CreateViewForFrame infallible. r=dholbert
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 19 Mar 2013 21:47:47 -0400
changeset 125525 c95e4dbd6dafa13412e2287933dace9af09e0abb
parent 125524 e91747bb94c6c0ebefed6de3b3660b0387ad745f
child 125526 6a5bf6934ba8f7778194d7610771f07328fed301
push id24989
push userbzbarsky@mozilla.com
push dateWed, 20 Mar 2013 01:48:20 +0000
treeherdermozilla-inbound@a1237c5af4aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs852428
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 852428 part 1. Make CreateViewForFrame infallible. r=dholbert
layout/generic/nsContainerFrame.cpp
layout/generic/nsContainerFrame.h
layout/generic/nsSubDocumentFrame.cpp
view/public/nsViewManager.h
view/src/nsViewManager.cpp
--- a/layout/generic/nsContainerFrame.cpp
+++ b/layout/generic/nsContainerFrame.cpp
@@ -425,40 +425,38 @@ ReparentFrameViewTo(nsIFrame*       aFra
                             aNewParentView, aOldParentView);
       }
     }
   }
 
   return NS_OK;
 }
 
-nsresult
+void
 nsContainerFrame::CreateViewForFrame(nsIFrame* aFrame,
                                      bool aForce)
 {
   if (aFrame->HasView()) {
-    return NS_OK;
+    return;
   }
 
   // If we don't yet have a view, see if we need a view
   if (!aForce && !aFrame->NeedsView()) {
     // don't need a view
-    return NS_OK;
+    return;
   }
 
   nsView* parentView = aFrame->GetParent()->GetClosestView();
   NS_ASSERTION(parentView, "no parent with view");
 
   nsViewManager* viewManager = parentView->GetViewManager();
   NS_ASSERTION(viewManager, "null view manager");
 
   // Create a view
   nsView* view = viewManager->CreateView(aFrame->GetRect(), parentView);
-  if (!view)
-    return NS_ERROR_OUT_OF_MEMORY;
 
   SyncFrameViewProperties(aFrame->PresContext(), aFrame, nullptr, view);
 
   nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(parentView, aFrame);
   // we insert this view 'above' the insertBefore view, unless insertBefore is null,
   // in which case we want to call with aAbove == false to insert at the beginning
   // in document order
   viewManager->InsertChild(parentView, view, insertBefore, insertBefore != nullptr);
@@ -474,17 +472,16 @@ nsContainerFrame::CreateViewForFrame(nsI
   ReparentFrameViewTo(aFrame, viewManager, view, parentView);
 
   // Remember our view
   aFrame->SetView(view);
 
   NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
                ("nsContainerFrame::CreateViewForFrame: frame=%p view=%p",
                 aFrame));
-  return NS_OK;
 }
 
 /**
  * Position the view associated with |aKidFrame|, if there is one. A
  * container frame should call this method after positioning a frame,
  * but before |Reflow|.
  */
 void
--- a/layout/generic/nsContainerFrame.h
+++ b/layout/generic/nsContainerFrame.h
@@ -108,18 +108,18 @@ public:
   virtual void DeleteNextInFlowChild(nsPresContext* aPresContext,
                                      nsIFrame*      aNextInFlow,
                                      bool           aDeletingEmptyFrames);
 
   /**
    * Helper method to wrap views around frames. Used by containers
    * under special circumstances (can be used by leaf frames as well)
    */
-  static nsresult CreateViewForFrame(nsIFrame* aFrame,
-                                     bool aForce);
+  static void CreateViewForFrame(nsIFrame* aFrame,
+                                 bool aForce);
 
   // Positions the frame's view based on the frame's origin
   static void PositionFrameView(nsIFrame* aKidFrame);
 
   static nsresult ReparentFrameView(nsPresContext* aPresContext,
                                     nsIFrame*       aChildFrame,
                                     nsIFrame*       aOldParentFrame,
                                     nsIFrame*       aNewParentFrame);
--- a/layout/generic/nsSubDocumentFrame.cpp
+++ b/layout/generic/nsSubDocumentFrame.cpp
@@ -133,18 +133,17 @@ nsSubDocumentFrame::Init(nsIContent*    
   // OuterFrame but we wait for the normal view creation path in
   // nsCSSFrameConstructor, then we will lose because the inner view's
   // parent will already have been set to some outer view (e.g., the
   // canvas) when it really needs to have this frame's view as its
   // parent. So, create this frame's view right away, whether we
   // really need it or not, and the inner view will get it as the
   // parent.
   if (!HasView()) {
-    rv = nsContainerFrame::CreateViewForFrame(this, true);
-    NS_ENSURE_SUCCESS(rv, rv);
+    nsContainerFrame::CreateViewForFrame(this, true);
   }
   EnsureInnerView();
 
   // Set the primary frame now so that nsDocumentViewer::FindContainerView
   // called from within EndSwapDocShellsForViews below can find it if needed.
   aContent->SetPrimaryFrame(this);
 
   // If we have a detached subdoc's root view on our frame loader, re-insert
--- a/view/public/nsViewManager.h
+++ b/view/public/nsViewManager.h
@@ -45,17 +45,17 @@ public:
    * @param aBounds initial bounds for view
    *        XXX We should eliminate this parameter; you can set the bounds after CreateView
    * @param aParent intended parent for view. this is not actually set in the
    *        nsView through this method. it is only used by the initialization
    *        code to walk up the view tree, if necessary, to find resources.
    *        XXX We should eliminate this parameter!
    * @param aVisibilityFlag initial visibility state of view
    *        XXX We should eliminate this parameter; you can set it after CreateView
-   * @result The new view
+   * @result The new view.  Never null.
    */
   nsView* CreateView(const nsRect& aBounds,
                      const nsView* aParent,
                      nsViewVisibility aVisibilityFlag = nsViewVisibility_kShow);
 
   /**
    * Get the root of the view tree.
    * @result the root view
--- a/view/src/nsViewManager.cpp
+++ b/view/src/nsViewManager.cpp
@@ -125,22 +125,20 @@ nsViewManager::Init(nsDeviceContext* aCo
 }
 
 nsView*
 nsViewManager::CreateView(const nsRect& aBounds,
                           const nsView* aParent,
                           nsViewVisibility aVisibilityFlag)
 {
   nsView *v = new nsView(this, aVisibilityFlag);
-  if (v) {
-    v->SetParent(const_cast<nsView*>(aParent));
-    v->SetPosition(aBounds.x, aBounds.y);
-    nsRect dim(0, 0, aBounds.width, aBounds.height);
-    v->SetDimensions(dim, false);
-  }
+  v->SetParent(const_cast<nsView*>(aParent));
+  v->SetPosition(aBounds.x, aBounds.y);
+  nsRect dim(0, 0, aBounds.width, aBounds.height);
+  v->SetDimensions(dim, false);
   return v;
 }
 
 void
 nsViewManager::SetRootView(nsView *aView)
 {
   NS_PRECONDITION(!aView || aView->GetViewManager() == this,
                   "Unexpected viewmanager on root view");