diff --git a/build/gyp_qtwebengine b/build/gyp_qtwebengine
index 322d7e62ae609ca328b5376f21b104ae6a31f271..31c7a808579e491aef7f0c5235b6360d603a7f48 100755
--- a/build/gyp_qtwebengine
+++ b/build/gyp_qtwebengine
@@ -11,6 +11,8 @@ if chrome_src:
   chrome_src = os.path.abspath(chrome_src)
 if not chrome_src or not os.path.isdir(chrome_src):
   chrome_src = os.path.join(qtwebengine_src, '3rdparty/chromium')
+  if not os.path.isdir(chrome_src):
+    chrome_src = os.path.join(qtwebengine_src, '3rdparty_upstream/chromium')
   print 'CHROMIUM_SRC_DIR not set, falling back to ' + chrome_src
 
 script_dir = os.path.abspath(os.path.join(chrome_src, 'build'))
diff --git a/build/qmake/mkspecs/features/functions.prf b/build/qmake/mkspecs/features/functions.prf
index c712912b49231ba1378eadb83a9d02f1f3b218fc..a2fdeacee8b21b99e610beaf318bcd225c158377 100644
--- a/build/qmake/mkspecs/features/functions.prf
+++ b/build/qmake/mkspecs/features/functions.prf
@@ -75,11 +75,16 @@ defineReplace(findNinja) {
   !isEmpty(CACHED_NINJA_EXECUTABLE):exists($$CACHED_NINJA_EXECUTABLE): return($$CACHED_NINJA_EXECUTABLE)
   out = $$which(ninja)
   # Try to be smart about it if we know where the chromium sources are located
-  !exists($$out): out = $$absolute_path("$$QTWEBENGINE_ROOT/3rdparty/ninja/ninja")
-  # If we still did not find ninja, then we bootstrap it.
   !exists($$out) {
-    message("bootstrapping ninja...")
-    system("python $$QTWEBENGINE_ROOT/3rdparty/ninja/bootstrap.py")
+    ninjadir = $$absolute_path("$$QTWEBENGINE_ROOT/3rdparty/ninja")
+    # We might deal with an upstream chromium build
+    !exists($$ninjadir): ninjadir = $$absolute_path("$$QTWEBENGINE_ROOT/3rdparty_upstream/ninja")
+    out = "$$ninjadir/ninja"
+    # If we still did not find ninja, then we bootstrap it.
+    !exists($$out) {
+      message("bootstrapping ninja...")
+      system("python $$ninjadir/bootstrap.py")
+    }
   }
   message("using $$out")
   cache(CACHED_NINJA_EXECUTABLE, set, out)
diff --git a/build/scripts/build_resources.py b/build/scripts/build_resources.py
index d060db1f76a62250f3cac68ac7f0bf3cb7a35ad8..1b924750f5e37035f186fa932a13dcb7a27b4eef 100755
--- a/build/scripts/build_resources.py
+++ b/build/scripts/build_resources.py
@@ -55,6 +55,8 @@ if chrome_src:
   chrome_src = os.path.abspath(chrome_src)
 if not chrome_src or not os.path.isdir(chrome_src):
   chrome_src = os.path.join(qtwebengine_src, '3rdparty/chromium')
+  if not os.path.isdir(chrome_src):
+    chrome_src = os.path.join(qtwebengine_src, '3rdparty_upstream/chromium')
   print 'CHROMIUM_SRC_DIR not set, falling back to ' + chrome_src
 
 grit_tool = os.path.join(chrome_src, 'tools/grit/grit.py')